| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 << (timeout) << "ms; waiting an additional " << margin \ | 85 << (timeout) << "ms; waiting an additional " << margin \ |
| 86 << "ms"; \ | 86 << "ms"; \ |
| 87 WAIT_(ex, margin, res); \ | 87 WAIT_(ex, margin, res); \ |
| 88 if (!res) { \ | 88 if (!res) { \ |
| 89 EXPECT_TRUE(ex); \ | 89 EXPECT_TRUE(ex); \ |
| 90 } \ | 90 } \ |
| 91 } while (0) | 91 } while (0) |
| 92 | 92 |
| 93 // Wait until "ex" is true, or "timeout" expires, using fake clock where | 93 // Wait until "ex" is true, or "timeout" expires, using fake clock where |
| 94 // messages are processed every millisecond. | 94 // messages are processed every millisecond. |
| 95 #define SIMULATED_WAIT(ex, timeout, clock) \ | 95 #define SIMULATED_WAIT(ex, timeout, clock) \ |
| 96 for (int64_t start = rtc::TimeMillis(); \ | 96 for (int64_t start = rtc::TimeMillis(); \ |
| 97 !(ex) && rtc::TimeMillis() < start + (timeout);) { \ | 97 !(ex) && rtc::TimeMillis() < start + (timeout);) { \ |
| 98 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1)); \ | 98 (clock).AdvanceTime(rtc::TimeDelta::FromMilliseconds(1)); \ |
| 99 } | 99 } |
| 100 | 100 |
| 101 // This returns the result of the test in res, so that we don't re-evaluate | 101 // This returns the result of the test in res, so that we don't re-evaluate |
| 102 // the expression in the XXXX_WAIT macros below, since that causes problems | 102 // the expression in the XXXX_WAIT macros below, since that causes problems |
| 103 // when the expression is only true the first time you check it. | 103 // when the expression is only true the first time you check it. |
| 104 #define SIMULATED_WAIT_(ex, timeout, res, clock) \ | 104 #define SIMULATED_WAIT_(ex, timeout, res, clock) \ |
| 105 do { \ | 105 do { \ |
| 106 int64_t start = rtc::TimeMillis(); \ | 106 int64_t start = rtc::TimeMillis(); \ |
| 107 res = (ex); \ | 107 res = (ex); \ |
| 108 while (!res && rtc::TimeMillis() < start + (timeout)) { \ | 108 while (!res && rtc::TimeMillis() < start + (timeout)) { \ |
| 109 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1)); \ | 109 (clock).AdvanceTime(rtc::TimeDelta::FromMilliseconds(1)); \ |
| 110 res = (ex); \ | 110 res = (ex); \ |
| 111 } \ | 111 } \ |
| 112 } while (0) | 112 } while (0) |
| 113 | 113 |
| 114 // The typical EXPECT_XXXX, but done until true or a timeout with a fake clock. | 114 // The typical EXPECT_XXXX, but done until true or a timeout with a fake clock. |
| 115 #define EXPECT_TRUE_SIMULATED_WAIT(ex, timeout, clock) \ | 115 #define EXPECT_TRUE_SIMULATED_WAIT(ex, timeout, clock) \ |
| 116 do { \ | 116 do { \ |
| 117 bool res; \ | 117 bool res; \ |
| 118 SIMULATED_WAIT_(ex, timeout, res, clock); \ | 118 SIMULATED_WAIT_(ex, timeout, res, clock); \ |
| 119 if (!res) { \ | 119 if (!res) { \ |
| 120 EXPECT_TRUE(ex); \ | 120 EXPECT_TRUE(ex); \ |
| 121 } \ | 121 } \ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 140 | 140 |
| 141 #define ASSERT_EQ_SIMULATED_WAIT(v1, v2, timeout, clock) \ | 141 #define ASSERT_EQ_SIMULATED_WAIT(v1, v2, timeout, clock) \ |
| 142 do { \ | 142 do { \ |
| 143 bool res; \ | 143 bool res; \ |
| 144 SIMULATED_WAIT_(v1 == v2, timeout, res, clock); \ | 144 SIMULATED_WAIT_(v1 == v2, timeout, res, clock); \ |
| 145 if (!res) \ | 145 if (!res) \ |
| 146 ASSERT_EQ(v1, v2); \ | 146 ASSERT_EQ(v1, v2); \ |
| 147 } while (0) | 147 } while (0) |
| 148 | 148 |
| 149 #endif // WEBRTC_BASE_GUNIT_H_ | 149 #endif // WEBRTC_BASE_GUNIT_H_ |
| OLD | NEW |