我在 Google Group 上问过这个问题,但我想我会在这里得到更快的回复。
我正在尝试使用Google 的 Mocking 框架来测试我的代码。我也在使用他们的测试框架。我正在用VC9编译。我在匹配 MFC\ATL CStrings 的参数时遇到问题。GMock 说对象不相等,它似乎正在评估指针地址。我试图模拟的方法的结构如下:
void myMethod(const CString & key, const CString & value);
因此:
MOCK_METHOD2(myMethod, void(const CString & key , const CString &
value);
在设定我的期望时,我正在做以下比较:
CString szKey = _T("Some key");
CString szValue = _T("Some value");
EXPECT_CALL(myMock, myMethod(Eq(szKey), Eq(szValue))).WillOnce(Return
(true));
我尝试了许多不同的匹配器组合,例如:
EXPECT_CALL(myMock, myMethod(StrCaseEq(_T("Some Key")), StrCaseEq(_T
(""Some value)))).WillOnce(Return(true));
EXPECT_CALL(myMock, myMethod(TypedEq<const CString &>(szKey),
TypedEq<const CString &>(szValue))).WillOnce(Return(true));
EXPECT_CALL(myMock, myMethod(TypedEq<const CString &>(szKey),
TypedEq<const CString &>(szValue))).WillOnce(Return(true));
上述任何调用都产生了相同的结果。还有其他人遇到这个问题吗?
这是输出:
Google Mock 尝试了以下 2 个期望,但没有一个匹配:
:80: tried expectation #0
Expected arg #1: is equal to 006D430C pointing to "Some value"
Actual: 4-byte object <A8EF 1102>
Expected: to be called once
Actual: never called - unsatisfied and active
:83: tried expectation #1
Expected arg #1: is equal to (ignoring case) ""
Actual: 4-byte object <A8EF 1102>
Expected arg #2: is equal to (ignoring case) "Some value"
Actual: 4-byte object <C0EE 1102>
Expected: to be called once
Actual: never called - unsatisfied and active
亚当