How do I repeatedly expect a call sequence?

I am writing a test to check the sequence of calls in an image processing thread. The relevant part of the test code is as follows:

Sequence s1, s2; ... EXPECT_CALL(*mMockVideoSource, getFrame()).InSequence(s2).WillRepeatedly(Return(mFakeBuffer)); EXPECT_CALL(*mMockProcessor, processFrame(_,_)).InSequence(s2).WillRepeatedly(Return(0)); EXPECT_CALL(*mMockVideoSource, releaseFrame(_)).Times(AnyNumber()).InSequence(s2); ... 

In this case, the sequence of calls is extremely important. getFrame() , processFrame() and releaseFrame() should be called in that order. Unfortunately, the above code does not actually do what I want. The above code will allow getFrame() be called several times before calling processFrame() , and calling getFrame() after releaseFrame() is considered an error, as it interrupts the sequence.

Can a certain sequence of calls be expected to recur? I don’t care how many times the sequence is executed if the functions are called in order: receive, process, release, receive, process, release ...

+6
source share
1 answer

You can create a side effect when calling your layout ( https://code.google.com/p/googlemock/wiki/CookBook#Combining_Actions ) and some kind of global state such as "lastAction".

The side action will look like this:

 void checkSequenceCorrectness(ActionType currAction) { if (currAction == PROCESS_FRAME) EXPECT_EQ(GET_FRAME, lastAction); (more ifs) ... lastAction = currAction; } 

You can bind it to moker with:

 EXPECT_CALL(*mMockProcessor, processFrame(_,_)) .WillRepeatedly(DoAll Return(0), Invoke(checkSequenceCorrectness(PROCESS_FRAME))); 
+4
source

Source: https://habr.com/ru/post/969922/


All Articles