I'm trying to mock the libusb C interface based on the answer here: https://stackoverflow.com/a/41640864/1752391
The tests run just fine if I actually call the expected functions, but when the function call is commented out, the test shows an error (call count doesn't match) but the final result of the test is OK.
I found some info about testing with static objects can cause this, bit in mathandi's answer only the pointer is static, and the object is destroyed in the TestFixture's destructor. Also tried creating and destroying the object inside the TEST_F function, but it didn't help.
This is might be a GMock bug, but I highly doubt it. Here's some code to replicate this:
class Context {
libusb_context* context;
public:
Context() {
// Function call is commented out, should cause an error
// libusb_init(&context);
}
...
}
And the test:
TEST_F(LibusbTests, contextConstructTest) {
EXPECT_CALL(*libusbMock, libusb_init(Ne(nullptr)))
.WillOnce(Return(0));
EXPECT_NO_THROW({ Libusb::Context(); });
}
I didn't include the other necessary code needed for testing C free function, but my libusbMock pointer is the same as mathandi's _bcm2835libMock pointer.
Has anyone an idea what did I missed?