我试图写模拟为包含三个重载方法的类,即:GMock - 与ON_CALL返回默认值重载方法
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using ::testing::_;
using ::testing::Return;
using ::testing::A;
using ::testing::ByRef;
using ::testing::Ref;
using ::testing::TypedEq;
struct Foo {
int fooMethod(const int& intParam) { return 0; }
int fooMethod(const float& floatParam) { return 0; }
int fooMethod(const std::string& stringParam) { return 0; }
};
struct FooMock {
FooMock() {
ON_CALL(*this, fooMethod(_)).WillByDefault(Return(-1));
}
MOCK_METHOD1(fooMethod, int(const int& intParam));
MOCK_METHOD1(fooMethod, int(const float& floatParam));
MOCK_METHOD1(fooMethod, int(const std::string& stringParam));
};
但是这给出了一个错误:
error: call of overloaded ‘gmock_fooMethod(const testing::internal::AnythingMatcher&)’ is ambiguous
我也尝试了TypedEq()而不是“_”,但它给出了更多的晦涩的错误。我检查了GMock常见问题,维基和我没有找到解决方案 - 我怎样才能返回默认值与ON_CALL重载的方法?
BR, 卢卡斯
TX34,弗雷泽 - 谢谢! – lgromanowski 2013-05-22 09:01:00