문제

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