Reputation: 1435
I'm trying to get the hang of Google Mocks but I've hit a snag trying to mock non-virtual methods. I have a Socket class that I want to mock. It has a non-virtual method called "write" that takes to arguments:
class Socket {
public:
int write(const unsigned char* buffer, size_t bufferLength) const;
}
So I create a Mock class as specified cook book:
class MockSocket {
public:
MOCK_CONST_METHOD0(write, int(const unsigned char* data, size_t dataLength));
};
But this doesn't compile. It generates the following errors:
error: size of array ‘this_method_does_not_take_0_arguments’ is negative
error: no matching function for call to ‘testing::internal::FunctionMocker<int ()(const unsigned char*, size_t)>::Invoke()’
error: no matching function for call to ‘testing::internal::FunctionMocker<int ()(const unsigned char*, size_t)>::With()’
Could someone tell me why??
Thanks.
Upvotes: 1
Views: 739
Reputation: 1435
Okay, didn't mix my coffee strong enough this morning. Figured out the problem. Was using the wrong macro. This works:
class MockSocket {
public:
MOCK_CONST_METHOD2(foo, int(const unsigned char* buffer, size_t len));
};
Upvotes: 2