Chromium Code Reviews| Index: webrtc/base/gunit.h |
| diff --git a/webrtc/base/gunit.h b/webrtc/base/gunit.h |
| index e705322e6f827fd3dac94c2bb75a474376be977f..4df37f046e5370cd36b3f8950840c517ad612583 100644 |
| --- a/webrtc/base/gunit.h |
| +++ b/webrtc/base/gunit.h |
| @@ -11,6 +11,7 @@ |
| #ifndef WEBRTC_BASE_GUNIT_H_ |
| #define WEBRTC_BASE_GUNIT_H_ |
| +#include "webrtc/base/fakeclock.h" |
| #include "webrtc/base/logging.h" |
| #include "webrtc/base/thread.h" |
| #if defined(GTEST_RELATIVE_PATH) |
| @@ -23,7 +24,8 @@ |
| #define WAIT(ex, timeout) \ |
| for (int64_t start = rtc::TimeMillis(); \ |
| !(ex) && rtc::TimeMillis() < start + timeout;) \ |
| - rtc::Thread::Current()->ProcessMessages(1); |
| + rtc::Thread::Current()->ProcessMessages(0); \ |
| + rtc::Thread::Current()->SleepMs(1); |
|
Taylor Brandstetter
2016/06/01 15:54:58
I had to do this because if you do a "WAIT" while
|
| // This returns the result of the test in res, so that we don't re-evaluate |
| // the expression in the XXXX_WAIT macros below, since that causes problems |
| @@ -33,7 +35,8 @@ |
| int64_t start = rtc::TimeMillis(); \ |
| res = (ex); \ |
| while (!res && rtc::TimeMillis() < start + timeout) { \ |
| - rtc::Thread::Current()->ProcessMessages(1); \ |
| + rtc::Thread::Current()->ProcessMessages(0); \ |
| + rtc::Thread::Current()->SleepMs(1); \ |
| res = (ex); \ |
| } \ |
| } while (0) |
| @@ -85,4 +88,41 @@ |
| } \ |
| } while (0) |
| +// Wait until "ex" is true, or "timeout" expires, using fake clock where |
| +// messages are processed every millisecond. |
| +#define SIMULATED_WAIT(ex, clock, timeout) \ |
| + for (int64_t start = rtc::TimeMillis(); \ |
| + !(ex) && rtc::TimeMillis() < start + timeout;) \ |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1)); |
| + |
| +// This returns the result of the test in res, so that we don't re-evaluate |
| +// the expression in the XXXX_WAIT macros below, since that causes problems |
| +// when the expression is only true the first time you check it. |
| +#define SIMULATED_WAIT_(ex, clock, timeout, res) \ |
| + do { \ |
| + int64_t start = rtc::TimeMillis(); \ |
| + res = (ex); \ |
| + while (!res && rtc::TimeMillis() < start + timeout) { \ |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1)); \ |
| + res = (ex); \ |
| + } \ |
| + } while (0) |
| + |
| +// The typical EXPECT_XXXX and ASSERT_XXXXs, but done until true or a timeout. |
| +#define EXPECT_TRUE_SIMULATED_WAIT(ex, clock, timeout) \ |
| + do { \ |
| + bool res; \ |
| + SIMULATED_WAIT_(ex, clock, timeout, res); \ |
| + if (!res) \ |
| + EXPECT_TRUE(ex); \ |
| + } while (0) |
| + |
| +#define EXPECT_EQ_SIMULATED_WAIT(v1, v2, clock, timeout) \ |
| + do { \ |
| + bool res; \ |
| + SIMULATED_WAIT_(v1 == v2, clock, timeout, res); \ |
| + if (!res) \ |
| + EXPECT_EQ(v1, v2); \ |
| + } while (0) |
| + |
| #endif // WEBRTC_BASE_GUNIT_H_ |