Description
When UnitTestBot generates tests for structs with fields of function pointer type, these fields are initialized with generated stubs. But stubs are not generated for internal structs stored by pointers, so undeclared stubs are used.
Example
typedef int (*some_func)();
struct InnerStruct {
some_func func;
int func_id;
};
struct MainStruct {
struct InnerStruct* inner;
};
int process_struct_with_func_pointer(struct MainStruct* str) {
if (str && str->inner && str->inner->func_id != 0) {
return 1;
}
return 0;
}
To Reproduce
Steps to reproduce the behavior:
- Copy example above to your project
- Generate tests for function
process_struct_with_func_pointer
- Try to run generated tests
Expected behavior
Tests are supposed to be executed successfully.
Actual behavior
An error test is generated with information about errors.
Generated test
TEST(regression, process_struct_with_func_pointer_test2)
{
struct MainStruct str = {
.inner = NULL
};
struct InnerStruct utbotInnerVar1 = {
.func = InnerStruct_func_stub,
.func_id = 255
};
str.inner = (struct InnerStruct*) &utbotInnerVar1;
int actual = process_struct_with_func_pointer(&str);
EXPECT_EQ(1, actual);
struct MainStruct expected_str = {
.inner = NULL
};
}
Logs
/home/utbot/UTBotCpp/integration-tests/c-example/utbot_tests/makefiles/lib/structures/structs/../../../../../utbot_tests/lib/structures/structs/complex_structs_dot_c_test.cpp:19:17: error: use of undeclared identifier 'InnerStruct_func_stub'
.func = InnerStruct_func_stub,
^
/home/utbot/UTBotCpp/integration-tests/c-example/utbot_tests/makefiles/lib/structures/structs/../../../../../utbot_tests/lib/structures/structs/complex_structs_dot_c_test.cpp:38:17: error: use of undeclared identifier 'InnerStruct_func_stub'
.func = InnerStruct_func_stub,
^
2 errors generated.
Description
When UnitTestBot generates tests for structs with fields of function pointer type, these fields are initialized with generated stubs. But stubs are not generated for internal structs stored by pointers, so undeclared stubs are used.
Example
To Reproduce
Steps to reproduce the behavior:
process_struct_with_func_pointerExpected behavior
Tests are supposed to be executed successfully.
Actual behavior
An error test is generated with information about errors.
Generated test
Logs