Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to resolve unnamed structures/unions are undefined when running unit tests?

uname
uname Posts: 6

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

  • Bogdan Czwartkowski
    Bogdan Czwartkowski Posts: 163 admin
    edited October 2022

    @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.

  • uname
    uname Posts: 6
    edited October 2022

    @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!

  • Bogdan Czwartkowski
    Bogdan Czwartkowski Posts: 163 admin
    edited October 2022

    @uname ,
    many thanks for the update and sharing your solution!