1. How to stub the system API or existed functions in CPPUTEST project?
A. Firstly, you need to add "-Wl,--allow-multiple-definition" to CPPUTEST_CPPFLAGS to avoid multiple-definition's problem.
CPPUTEST_CPPFLAGS += -Wl,--allow-multiple-definition
Note: this parameter involved safe problem , it just use for stub.c file...
B. Secondly, compiling stub.c should earlier than src file.
SRC_DIRS = \
stubs\
src
You can try to stub the same name of functions in stub.c now.
Source file: src/hello.c
#include "hello.h"
int exe_cmd(const char* cmd)
{
....................
return system(cmd);
}
Stub file: stub/stub.c
#include "CppUTestExt/MockSupport_c.h"
int exe_cmd(const char* cmd)
{
do your expectation.....
}
A. Firstly, you need to add "-Wl,--allow-multiple-definition" to CPPUTEST_CPPFLAGS to avoid multiple-definition's problem.
CPPUTEST_CPPFLAGS += -Wl,--allow-multiple-definition
Note: this parameter involved safe problem , it just use for stub.c file...
B. Secondly, compiling stub.c should earlier than src file.
SRC_DIRS = \
stubs\
src
You can try to stub the same name of functions in stub.c now.
Source file: src/hello.c
#include "hello.h"
int exe_cmd(const char* cmd)
{
....................
return system(cmd);
}
Stub file: stub/stub.c
#include "CppUTestExt/MockSupport_c.h"
int exe_cmd(const char* cmd)
{
do your expectation.....
}