It sounds like you are on the right track !
Be sure you have the :ignore and :ignore_arg plugins enabled under :cmock: in your project.yml . Here's an example :
:cmock:
:mock_prefix: "mock_"
:when_no_prototypes: :warn
:enforce_strict_ordering: FALSE
:plugins:
- :ignore
- :ignore_arg
- :callback
- :array
- :return_thru_ptr
Regarding your internal function , you are correct that you can't directly test that (without some extra helpers) , but you shouldn't need to . You should just test whatever effects it has . We can go through that next if you post some more details .
Next about chickens and eggs ... You are right that you have to call Task_1sec() once for your expectations to actually fire , however , if inside your Task_1sec() you call read_temp_value more than once , you have to setup those expectations all over again . For instance , if you called it from a loop or called it again from your my_idx() function , you would have to setup new expectations for each time your code called it . This is common when using the return value to know whether or not to continue processing . For a general example :
while (read_temp_value(&temp_value) == 0)
{
// Do something with the value here
my_idx(temp_value);
}
For this case , your test would look like this :
void test_swc_module_task_pass_improved(void)
{
flag = 1; // set flag manually
// First read expectations
read_temp_value_ExpectAndReturn(0, 0); // return status 0 (OK) the first time
read_temp_value_IgnoreArg_temp_value(); // ignore pointer arg
read_temp_value_ReturnThruPtr_temp_value(60); // return a value because status 0
// Second read expectations
read_temp_value_ExpectAndReturn(0, 1); // return status 1 (BUSY) the second time
read_temp_value_IgnoreArg_temp_value(); // still ignore pointer arg
task_1sec(); // one call makes multiple read calls internally
// check more results here
}
So , for troubleshooting ideas :
1 . How many tests do you have ? I'm assuming just one right now .
2 . What is the full list of #includes that you are using ? It is possible that either you are accidentally mocking Task_1sec() , some other module is getting compiled in which is calling it , or perhaps it's getting called from an init function or something like that . I would look in your code and find out every place this function is being called in order to get some ideas .
You mentioned that "it's called based on a 1 sec timer" , probably in Mediator.c , but like you said , that module shouldn't even be getting compiled or included in this test in any way .
--David