How to resolve unnamed structures/unions are undefined when running unit tests?
I have something like this in my header file which is included to project.
extern struct { uint32_t a; uint16_t b; } ex_var;
ex_var is used in the functions which I am trying to test. When I am trying to run unit tests using Built In configuration I receive:
undefined reference to `ex_var'
In stub view I can find this structure:
struct unnamed ex_var | N/A | N/A.
I cannot generate stub by right clicking on it as all options are inactive except "Generate Auto Stub" which does literally nothing.
Any ideas how to deal with it? Thanks.
Answers
-
@uname ,
C/C++test stubs functionality will be able to generate stub functions, but it will not stub variables. Since the above is a variable declaration, you will need to provide ex_var definition somehow. You can:
1. define this variable in a test suite, or
2. provide an external library or object file that contains the definition and add it to C/C++test Build Settings in project properties.0 -
@Bogdan Czwartkowski
My teammate solved this by defining all unamed structures and unions in separate file. Like this./** User stub definition for variable: struct name_of_undefined */ EXTERN_C_LINKAGE_START extern typeof(name_of_undefined) name_of_undefined; typeof(name_of_undefined) CppTest_Variable_Auto_Stub_name_of_undefined; EXTERN_C_LINKAGE_END
Thanks!
1 -
@uname ,
many thanks for the update and sharing your solution!1