[英]In Google Test Framework, how to expect a function call OR another function call?
How is it possible to put in logical OR two EXPECT_CALL
macros? 如何将逻辑或两个
EXPECT_CALL
宏放入? Due to external factor, my test could result in a call to on_found()
or to a function called on_not_found()
. 由于外部因素,我的测试可能导致对
on_found()
或名为on_not_found()
的函数的调用。 For my test scope is the same, because the important thing is that the search has been made. 对于我的测试范围是相同的,因为重要的是已经进行了搜索。 But I do not have access to the internal
search()
function and expect a call to that. 但是我无权访问内部
search()
函数,并且希望对此进行调用。
You can add some boolean variables to the test and make them true when on_found()
or on_not_found()
is called, and check logical OR of the variables at the end of the test. 您可以在测试中添加一些布尔变量,并在
on_found()
或on_not_found()
时使它们为true,然后在测试结束时检查变量的逻辑或。 For example, 例如,
auto onFoundCalled = false;
auto onNotFoundCalled = false;
EXPECT_CALL(mockObj, on_found())
.Times(AtMost(1)).WillRepeatedly(InvokeWithoutArgs([&onFoundCalled]
{
onFoundCalled = true;
}));
EXPECT_CALL(mockObj, on_not_found())
.Times(AtMost(1)).WillRepeatedly(InvokeWithoutArgs([&onNotFoundCalled]
{
onNotFoundCalled = true;
}));
RunSomeCode();
ASSERT_TRUE(onFoundCalled || onNotFoundCalled);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.