我正在尝试掌握 Google Mocks 的窍门,但在尝试模拟非虚拟方法时遇到了障碍。我有一个要模拟的 Socket 类。它有一个名为“write”的非虚拟方法,它接受参数:
class Socket {
public:
int write(const unsigned char* buffer, size_t bufferLength) const;
}
所以我创建了一个模拟类作为指定的食谱:
class MockSocket {
public:
MOCK_CONST_METHOD0(write, int(const unsigned char* data, size_t dataLength));
};
但这不会编译。它会产生以下错误:
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()’
谁能告诉我为什么??
谢谢。