안녕하세요. Unit 테스트 작성중에 어려움에 봉착하여 답을 구하고자 합니다.
만약 아래와 같이 구조체가 주어진 경우..
in uni_test.c
struct inputs
{
typeA *in_1;
typeB *in_2;
...
typeN *in_n;
}
inputs struct_in;
struct outputs
{
typeA out_1;
typeB out_2;
...
typeN out_n;
}
outputs *struct_out;
구조체의 멤버들 간에 연결되어 있습니다.
void elab()
{
struct_out = (outputs *)malloc(sizeof(outputs));
struct_in.in_1 = &struct_out->out_1;
struct_in.in_2 = &struct_out->out_2;
....
struct_in.in_n = &struct_out->out_n;
}
테스트를 위해서 구조체들을 백업하고 테스트 코드를 수행한 후 복원을 하기 위해
inputs 구조체를 deep copy 해두어야 하는데...
변수가 굉장히 많아서 이를 한번에 해주는
함수를 구현해 주어야 하는데 쉽지가 않군요..
혹시 아시는 분 조언 바랍니다.
(단, cpp가 아니라 template을 사용하지 못합니다. 하지만, 별도의 cpp 코드로 template 구현후
extern "c"를 이용해 구조체를 넘겨받아서 사용할 수도 있습니다.)
가령, 아래와 같이 테스트 코드를 짠 경우
call init_test();
call test1();
call clean_test();
void init_test()
{
원본 구조체를 백업해둔다.
(포인터 멤버들을 가지는 구조체는 멤버를 메모리 할당하고, 그외에는 memcpy 해둠)
}
void test1()
{
*outputs.out_1 = 특정 값 입력;
emulation()
unit assertion check (struct_out->out_n 결과 확인)
}
void clean_test()
{
원본 구조체를 복원한다.
(메모리 할당된 멤버를 free)
}
그럼 조언 부탁드립니다.
|