Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: webrtc/base/gunit.h

Issue 1530003004: Cleanup use of "do { ... } while (0)". (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 // the expression in the XXXX_WAIT macros below, since that causes problems 28 // the expression in the XXXX_WAIT macros below, since that causes problems
29 // when the expression is only true the first time you check it. 29 // when the expression is only true the first time you check it.
30 #define WAIT_(ex, timeout, res) \ 30 #define WAIT_(ex, timeout, res) \
31 do { \ 31 do { \
32 uint32_t start = rtc::Time(); \ 32 uint32_t start = rtc::Time(); \
33 res = (ex); \ 33 res = (ex); \
34 while (!res && rtc::Time() < start + timeout) { \ 34 while (!res && rtc::Time() < start + timeout) { \
35 rtc::Thread::Current()->ProcessMessages(1); \ 35 rtc::Thread::Current()->ProcessMessages(1); \
36 res = (ex); \ 36 res = (ex); \
37 } \ 37 } \
38 } while (0); 38 } while (0)
39 39
40 // The typical EXPECT_XXXX and ASSERT_XXXXs, but done until true or a timeout. 40 // The typical EXPECT_XXXX and ASSERT_XXXXs, but done until true or a timeout.
41 #define EXPECT_TRUE_WAIT(ex, timeout) \ 41 #define EXPECT_TRUE_WAIT(ex, timeout) \
42 do { \ 42 do { \
43 bool res; \ 43 bool res; \
44 WAIT_(ex, timeout, res); \ 44 WAIT_(ex, timeout, res); \
45 if (!res) EXPECT_TRUE(ex); \ 45 if (!res) EXPECT_TRUE(ex); \
46 } while (0); 46 } while (0)
47 47
48 #define EXPECT_EQ_WAIT(v1, v2, timeout) \ 48 #define EXPECT_EQ_WAIT(v1, v2, timeout) \
49 do { \ 49 do { \
50 bool res; \ 50 bool res; \
51 WAIT_(v1 == v2, timeout, res); \ 51 WAIT_(v1 == v2, timeout, res); \
52 if (!res) EXPECT_EQ(v1, v2); \ 52 if (!res) EXPECT_EQ(v1, v2); \
53 } while (0); 53 } while (0)
54 54
55 #define ASSERT_TRUE_WAIT(ex, timeout) \ 55 #define ASSERT_TRUE_WAIT(ex, timeout) \
56 do { \ 56 do { \
57 bool res; \ 57 bool res; \
58 WAIT_(ex, timeout, res); \ 58 WAIT_(ex, timeout, res); \
59 if (!res) ASSERT_TRUE(ex); \ 59 if (!res) ASSERT_TRUE(ex); \
60 } while (0); 60 } while (0)
61 61
62 #define ASSERT_EQ_WAIT(v1, v2, timeout) \ 62 #define ASSERT_EQ_WAIT(v1, v2, timeout) \
63 do { \ 63 do { \
64 bool res; \ 64 bool res; \
65 WAIT_(v1 == v2, timeout, res); \ 65 WAIT_(v1 == v2, timeout, res); \
66 if (!res) ASSERT_EQ(v1, v2); \ 66 if (!res) ASSERT_EQ(v1, v2); \
67 } while (0); 67 } while (0)
68 68
69 // Version with a "soft" timeout and a margin. This logs if the timeout is 69 // Version with a "soft" timeout and a margin. This logs if the timeout is
70 // exceeded, but it only fails if the expression still isn't true after the 70 // exceeded, but it only fails if the expression still isn't true after the
71 // margin time passes. 71 // margin time passes.
72 #define EXPECT_TRUE_WAIT_MARGIN(ex, timeout, margin) \ 72 #define EXPECT_TRUE_WAIT_MARGIN(ex, timeout, margin) \
73 do { \ 73 do { \
74 bool res; \ 74 bool res; \
75 WAIT_(ex, timeout, res); \ 75 WAIT_(ex, timeout, res); \
76 if (res) { \ 76 if (res) { \
77 break; \ 77 break; \
78 } \ 78 } \
79 LOG(LS_WARNING) << "Expression " << #ex << " still not true after " << \ 79 LOG(LS_WARNING) << "Expression " << #ex << " still not true after " << \
80 timeout << "ms; waiting an additional " << margin << "ms"; \ 80 timeout << "ms; waiting an additional " << margin << "ms"; \
81 WAIT_(ex, margin, res); \ 81 WAIT_(ex, margin, res); \
82 if (!res) { \ 82 if (!res) { \
83 EXPECT_TRUE(ex); \ 83 EXPECT_TRUE(ex); \
84 } \ 84 } \
85 } while (0); 85 } while (0)
86 86
87 #endif // WEBRTC_BASE_GUNIT_H_ 87 #endif // WEBRTC_BASE_GUNIT_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698