googletest - How to set an EXPECT_CALL to function being called after a specific time? -


i'm setting expectations (using gtest , gmock) on functions, like:

expect_call(mockedtimer, expired()).times(1); 

how can set expectation like:

"expect function executed in 100ms" ?

probably easiest way set timer measures how long takes expired() invoked, , add test assertion duration 100ms.

in context of test, this:

void startstopwatch(); void stopstopwarch(); unsigned getstopwatchresult();  test(timertest, timerexpiresin100ms) {      // set mocktimer, etc.     expect_call(mockedtimer, expired()).willonce(invoke(&stopstopwatch));     startstopwatch();     // test logic, waits until expired() called, goes here     assert_eq(100u, getstopwatchresult()); } 

this rough, of course, idea.

let me know if helpful. on editorial note, in general, tests rely on specific timing (i.e. rely on event occuring within specific time frame) rather unreliable. unless there's very reason 100ms constraint, might worthwhile re-think test logic :)


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -