mockcpp
mockcpp copied to clipboard
When testing C code, the checker throws an exception. The actual parameter of the C code cannot be unique_ptr, which is the syntax of C++11.
https://github.com/sinojelly/mockcpp/blob/23fa9fbf6fe76c9603068eb1ed8d599cfd1bc228/include/mockcpp/ChainingMockHelper.h#L58
sample code:
#include "sample3.h"
static unsigned char g_data = 0;
void save_data(const Sample3 *s)
{
g_data = s->a + s->b;
}
int test(const Sample3 *s)
{
if ((s->a >= 0x80) && (s->b >= 0x80)) {
return -1;
} else {
save_data(s);
return 0;
}
}
testcase:
TEST_F(TestSuite3, T2)
{
Sample3 t = {1, 2};
MOCKER(save_data).stubs().with(eq((const Sample3*)&t));
auto ret = test(&t);
EXPECT_EQ(ret, 0);
}
test result:
[ RUN ] TestSuite3.T2
unknown file: Failure
C++ exception with description "
=====================================
Unexpected invocation: the invocation cannot be found in allowed invoking list.
Invoked: save_data((Sample3 const*)0x7fff442b0630)
Allowed:
method(save_data)
.stubs()
.invoked(0)
.with(eq(unique_ptr (Sample3 const*)0x7fff442b0630));
=====================================
" thrown in the test body.