我正在尝试使用带有自定义字符串类型的gmock。
我有一个带有QString参数的方法,我想模拟这个方法:
MOCK_METHOD1(getValue, int(QString key));
我设定了一个期望:
EXPECT_CALL(mock, getValue("someKey"));出了一个错误:
error: no matching function for call to 'MyMock::gmock_getValue(const char[8])'
include/gmock/gmock.h:9339:20: note: in definition of macro 'GMOCK_EXPECT_CALL_IMPL_'
((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
note: in expansion of macro 'EXPECT_CALL'
...
gmock/gmock.h:9730:7: note: no known conversion for argument 3 from 'const char [6]' to 'const testing::Matcher<const QString&>&'
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \但这样做是可行的:
EXPECT_CALL(mock, getValue(QString("someKey")));如何使用字符串参数而不用QString()包装每个字符串文字?
发布于 2015-11-05 08:35:38
这是因为"someKey"不是QString,而是错误报告的const char[8],Google / Mock要求两个类是相同的。
同样,编译器不知道值10是否应该是int32 int64、uint32或uint64,同样适用。
https://stackoverflow.com/questions/33539736
复制相似问题