Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the oposite of EXPECT_CALL?

I have some expectations like EXPECT_CALL (...)

EXPECT_CALL(t1, foo()).Times(1);

I want to create the oposite. I expect that a certain function won't be executed.

What is the method I should use? Something like EXPECT_NOT_CALL (...) ?

like image 526
waas1919 Avatar asked Dec 25 '22 16:12

waas1919


1 Answers

In GTest something similar to EXPECT_NOT_CALL doesn't exist however, there are several options to receive this behaviour:

1.Create a StrictMock. In StrictMock any unexpected called cause a failure.

2.Use .Times(0):

EXPECT_CALL(t1, foo()).Times(0);

In this option you use the count mechanism however, it checks if the value is 0.(so any call leads a failure...)

3.Use method 2 and create a Macro:

#define EXPECT_NOT_CALL(a,b)     EXPECT_CALL(a, b).Times(0);
like image 116
Old Fox Avatar answered Dec 28 '22 11:12

Old Fox