GoogleMock 和 QString 参数
GoogleMock and QString argument
我正在尝试将 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()
包装每个字符串文字的情况下使用字符串参数?
这是由于 "someKey"
不是 QString,它是一个 const char[8]
,正如错误所报告的,Google 测试/模拟要求 2 类都一样。
同样,编译器不知道值 10 应该是 int32 int64、uint32 还是 uint64,同样适用。
我正在尝试将 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()
包装每个字符串文字的情况下使用字符串参数?
这是由于 "someKey"
不是 QString,它是一个 const char[8]
,正如错误所报告的,Google 测试/模拟要求 2 类都一样。
同样,编译器不知道值 10 应该是 int32 int64、uint32 还是 uint64,同样适用。