Reputation: 11
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);
}
Upvotes: 1
Views: 602
Reputation: 1
I have also encountered this problem: The operating system is Ubuntu Kernel version: 3.13.0-107 The g++ version is: 5.4.0
The reason for this problem is that compile optimization is enabled at compile time, and optimization needs to be disabled in the compile options.
g++ -00 (the first is the letter O, the second is the number 0)
Upvotes: 0