I am trying to write a test case in c using cmocka library.My testcase is testing a function which then internally calls a function from a 3rd party library (cannot modify the library).This function return NULL value when application is not up and running,so i want to mock the return value for this 3rd party library function.How can i achieve this?
I have tried using will_return function of cmocka to get desired return value,but it does not work
void third_party_func()
{
return mock();
}
void my_func_to_be_tested()
{
int ret;
ret = third_party_func();
return ret;
}
void test_do_mytest(void ** state)
{
(void) state;
int ret;
will_return(third_party_func,1);
ret = my_func_to_be_tested();
assert_int_equal(1,ret);
}
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_do_mytest),
};
int main(void)
{
return cmocka_run_group_tests(tests, NULL, NULL);
}
I get compilation error that multiple definition for third_party_func().How to handle such case?
I want to get desired value as return value for my third party func.