There's no built-in support for that, but you should be able to do it
by using googlemock constructs creatively.
> to test an interface to some real hardware and part of my interface
> definition is a maximum timeout period.
>
> Can I write:
> EXPECT_CALL(foo, Bar(_))
> .TimeOut(100); // in ms
Here's one idea:
ACTION_P(TimeOut, ms) {
ASSERT_LE(GetElapsedTime(), ms);
}
...
EXPECT_CALL(foo, Bar(_)).WillOnce(TimeOut(100));
>
> Thanks,
>
> Alexis
>
>
>
--
Zhanyong
To be precise, the test will fail if you get the callback and the time
it takes to get the callback is >= 100 ms.
If it takes 500 ms to get the backback, the test will take 500 ms to fail.
If you want a hard time-out, you can do something like:
sleep(100);
Mock::VerifyAndClearExpectations(&foo);
>
> Alexis
>
> On Jun 23, 12:06 pm, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
--
Zhanyong
>
> Thanks,
>
> Alexis
>
>
>
--
Zhanyong
A matcher should be a pure function of its input (i.e. given the same
value, it should always yield the same result, no matter when it is
invoked). WithinTimeout() depends on a mutable global state (the
time), and thus is not a valid matcher. I wouldn't recommend it as
googlemock depends on matchers being stateless - we probably should
document this somewhere.
> You get a slightly more meaningful error message in this case.
>
>>
>> >
>> > Thanks,
>> >
>> > Alexis
>> >
>> >
>> >
>>
>>
>>
>> --
>> Zhanyong
>
>
--
Zhanyong
http://code.google.com/p/googlemock/issues/detail?id=55 tracks this.
>
>> You get a slightly more meaningful error message in this case.
>>
>>>
>>> >
>>> > Thanks,
>>> >
>>> > Alexis
>>> >
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Zhanyong
>>
>>
>
>
>
> --
> Zhanyong
>
--
Zhanyong