我在我继承的项目中有一个测试,看起来与此类似
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
我修改了这个错误只是为了反映我的例子。
预先感谢您的帮助。