c - Cmocka: checking a structure passed as a parameter -


let's declare c struct called foo, has int field called bar , char * called baz.

how use cmocka expect_ , check_expected macros check structure passed correct , both fields have expected values? if there example in documentation, missed it.


[update] perhaps can use expect_check()? can't find example :-(

use expect_memory(...) , check_expected(...):

example:

i assume have function under test fut calls subfunction subfunc. struct looks this:

typedef struct foo_s {   int bar;   int baz; } foo; 

in test driving function this:

void test(void **state) {    foo myfoo = {      .bar = 42,      .baz = 13,    };    expect_memory(subfunc, param, &myfoo, sozeof(foo));     fut(); } 

and subfucntions this:

void subfunc(foo *param){    check_expected(param); } 

Comments