Testing Delayed Actions with GTest

Testing Delayed Actions with GTest



I have scenario template like :


// this function is called as timer callback
void funcToBeCalled ();

Timer t;
void
push_data ()

if (t.isRunning ())

return;

t.start (oneshot = true);


//TestCase
EXPECT_CALL(mockObj,funcToBeCalled).Times(1);
push_data ();
push_data ();
push_data ();



Purpose is when push_data() is called n times in time period t it will be bound to timer callback so only once funcToBeCalled() is called all push_data request after t time is ignored.
The above case is a prototype version and tests are succesfull.You can assume that mock setup is correct.


funcToBeCalled()



But I want to have a test case like :


#define TIMER_TIMEOUT 10
bool funcToBeCalled ();


Timer t;
void
push_data ()

if (t.isRunning ())

return;

t.start (TIMER_TIMEOUT, oneshot = true);




// TestCase
SharedSignal msgnal;
EXPECT_CALL (mockObj,
funcToBeCalled).Times (2).
WillOnce (Return (true)).WillOnce (SetSignal (msgnal));
push_data ();
push_data ();
push_data ();

Sleep (TIMER_TIMEOUT);
push_data ();
push_data ();
push_data ();

msgnal.wait (5 * TIMER_TIMEOUT);



Sleep ensures that first time window is expired second call to funcToBeCalled() should be made.


funcToBeCalled()



I do not want to use verify Mock::VerifyAndClearExpectations it does not simulate one long time window,instead it simulates two time windows from scratch.


Mock::VerifyAndClearExpectations



How can I achieve this test case with Google Test Framework?




0



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)