Crinit -- Configurable Rootfs Init
utest-crinit-task-add.c File Reference

(2023-10-16, commit: 49337e0)

Implementation of the crinitClientTaskAdd() unit test group. More...

#include "utest-crinit-task-add.h"
#include "rtimcmd.h"
#include "unit_test.h"
Include dependency graph for utest-crinit-task-add.c:

Functions

int crinitStoreRtimCmd (const uintmax_t value, const uintmax_t context)
 
int crinitStoreRtimCmdContext (const uintmax_t value, const uintmax_t context)
 
int crinitCheckRtimCmd (const uintmax_t value, const uintmax_t context)
 
int main (void)
 

Detailed Description

Implementation of the crinitClientTaskAdd() unit test group.

Function Documentation

◆ crinitCheckRtimCmd()

int crinitCheckRtimCmd ( const uintmax_t  value,
const uintmax_t  context 
)

Cmocka check function comparing the argument value with the given context.

This function is used to check a pointer value passed to a mock function. It uses the pointer value previously saved by crinitStoreRtimCmd(). This has to be done this way, as the arguments to expect_check() are evaluated at test setup before the function under test runs, but the by-reference pointer is only known at runtime.

Example usage: crinitRtimCmd_t *crinitBuildRtimArgCmd; expect_check(__wrap_crinitXfer, cmd, crinitCheckRtimCmd, &crinitBuildRtimArgCmd);

◆ crinitStoreRtimCmd()

int crinitStoreRtimCmd ( const uintmax_t  value,
const uintmax_t  context 
)

Cmocka check function storing the argument value.

This function is used to mock a by reference return value that would be written to a pointer. In order to later check the same pointer is used for other calls, this can be used as an expect_check() function that does not actually check the parameter, but saves a copy of the pointer.

The parameter types of this function match the Cmocka interface, but will be casted internally as if they were: int crinitStoreRtimCmd(const crinitRtimCmd_t *value, const crinitRtimCmd_t **context);

Example usage: crinitRtimCmd_t *crinitBuildRtimArgCmd; expect_check(__wrap_crinitBuildRtimCmd, c, crinitStoreRtimCmd, &crinitBuildRtimArgCmd);

◆ crinitStoreRtimCmdContext()

int crinitStoreRtimCmdContext ( const uintmax_t  value,
const uintmax_t  context 
)

Cmocka check function storing the argument value and setting a mocked value.

This function is used to mock a by-reference return value by writing a mocked value to the given a pointer. In order to later check the same pointer is used for other calls, this can be used as an expect_check() function that does not actually check the parameter, but saves a copy of the pointer and writes a mocked value to the pointed object.

The parameter types of this function match the Cmocka interface, but will be casted internally as if they were: int crinitStoreRtimCmd(const crinitRtimCmd_t *value, const crinitStoreRtimCmdArgs *context);

The context is a casted pointer to a crinitStoreRtimCmdArgs. The argument value will be written to the context->ptr member, while the member context->value will be placed into the object pointed to by value.

Example usage: crinitRtimCmd_t *crinitXferArgRes; char *crinitXferArgResOKArgs[1] = { CRINIT_RTIMCMD_RES_OK }; crinitRtimCmd_t crinitXferArgResOK = { .op = CRINIT_RTIMCMD_R_ADDTASK, .argc = 1, .args = crinitXferArgResOKArgs }; struct crinitStoreRtimCmdArgs crinitXferArgResContext = { &crinitXferArgRes, &crinitXferArgResOK, }; expect_check(__wrap_crinitXfer, res, crinitStoreRtimCmdContext, &crinitXferArgResContext);

◆ main()

int main ( void  )

Runs the unit test group for crinitClientTaskAdd using the cmocka API.