質問

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?

正しい解決策はありません

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top