1

Google Mocks のコツをつかもうとしていますが、非仮想メソッドをモックしようとして問題が発生しました。モックしたい Socket クラスがあります。引数を取る「書き込み」と呼ばれる非仮想メソッドがあります。

class Socket {
public:
    int write(const unsigned char* buffer, size_t bufferLength) const;
}

そこで、指定されたクック ブックとして Mock クラスを作成します。

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()’

誰かが理由を教えてもらえますか??

ありがとう。

4

1 に答える 1

2

さて、今朝はコーヒーの濃さが足りませんでした。問題を理解しました。間違ったマクロを使用していました。これは機能します:

class MockSocket {
public:
    MOCK_CONST_METHOD2(foo, int(const unsigned char* buffer, size_t len));
};
于 2013-08-15T17:24:13.723 に答える