我在继承的项目中有一个与此类似的测试
std::string value("test string");
const char * buffer = value.c_str();
EXPECT_CALL(object, foo(_,_,buffer, buffer.size(), _)).WillOnce(Return(0));
bar(value);
缓冲区是一个指向数据字符串的 char * 。我插入了像对象这样的虚拟值,只是为了关注似乎在使用 EXPECT_CALL 时出现的问题。在此 EXPECT_CALL 之后,将调用方法 bar,该方法将原始字符串值作为参数,然后在该方法中使用从原始字符串值构建的缓冲区调用 foo。
此测试在该项目的 Mac 版本上有效,但在 Windows 版本上失败。它似乎正在比较两个 char 指针的指针地址(预期的和实际的),然后失败,因为它们不同。方法 foo 肯定是在 bar 中调用的。
如果此测试方法 (EXPECT_CALL) 比较指针地址而不是该指针处的数据,那么测试在 Mac 上是否也会失败?
有人熟悉使用 EXPECT_CALL 和指针时 Mac 和 Windows 之间的明显区别吗?
我看到的错误
unknown file: error:
Unexpected mock function call - returning default value.
Function call: foo(NULL, 1, 0000000001CAAE78 pointing to "test string", 11,_)
Returns: 0
Google Mock tried the following 1 expectation, but it didn't match:
test.cpp(235): EXPECT_CALL(object, foo(_,_,buffer,buffer.size(),_)...
Expected arg #2: is equal to 0000000001CAAF78 pointing to "test string"
Actual: 0000000001CAAE78 pointing to "test string"
Expected: to be called once
Actual: never called - unsatisfied and active
test.cpp(235): error: Actual function call count doesn't match EXPECT_CALL(object, foo(_,_,buffer, buffer.size(), _)...
Expected: to be called once
我修改了这个错误只是为了反映我的例子。
预先感谢您的帮助。