When I build the mockcpp lib mockcpp.lib in MSVC format and build my unit test project in MSVC, it works well.
When I specify the CMake generator for the mockcpp to Unix Makefile, specify native compilers to cygwin64/bin/gcc.exe and cygwin64/bin/g++.exe and set -DMOCKCPP_XUNIT=gtest -DMOCKCPP_XUNIT_HOME=googletest-release/googletest, I get the libmockcpp.a after build the mockcpp.
But when I build my unit test project in gcc, the mock function does not work at all. I use GDB to debug it and find it still run into the mult_num function which I mocked.
Is there any macro or other option should be add when use gcc to compile mockcpp?
Thanks.
The sample test code:
#include <gtest/gtest.h>
#include <mockcpp/mokc.h>
int add_num(int a, int b)
{
return a + b;
}
int mult_num(int a, int b)
{
return a * b;
}
int add_mult(int a, int b)
{
int sum = add_num(a,b);
if (sum == mult_num(a,b))
{
return 0;
}
else
{
return 1;
}
}
TEST(add_mult, test001)
{
int ret;
MOCKER(mult_num)
.expects(once())
.will(returnValue(-1));
ret = add_mult(2, 2);
EXPECT_EQ(1, ret);
}