0

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?

Chilon
  • 31
  • 4

1 Answers1

0

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

Gaurav
  • 1,549
  • 2
  • 15
  • 31
  • That requires to do some compiler tricks with the include directories, so that the .c file under testing, would include some headers(those with the struct declarations) from the original directory and some(those with the stub declarations) from the stub directory. I cannot see any better options, I will try that. – Chilon Sep 17 '13 at 12:28