Question

I am trying to write unit tests for some legacy code written in C. The problem I encounter is that I regularly have to redefine structs used in the real code, in order to use them in the stub code.

For example, let's say this is the header file with the function I want to stub:

typedef struct {
    int value;
    int type;
    int format;
} some_struct_t;

int some_function(some_struct_t *pStruct);

In the stub code I will have to redefine some_struct_t so that it is visible in the stub implementation and the unit tests.

In practice structs are much bigger than this example. Is there any way to avoid this duplication?

No correct solution

OTHER TIPS

Can you try declaring the struct definition is some header file and import that file in test ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top