OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef PLATFORM_ASSERT_H_ | 5 #ifndef PLATFORM_ASSERT_H_ |
6 #define PLATFORM_ASSERT_H_ | 6 #define PLATFORM_ASSERT_H_ |
7 | 7 |
8 // TODO(5411406): include sstream for now, once we have a Utils::toString() | 8 // TODO(5411406): include sstream for now, once we have a Utils::toString() |
9 // implemented for all the primitive types we can replace the usage of | 9 // implemented for all the primitive types we can replace the usage of |
10 // sstream by Utils::toString() | 10 // sstream by Utils::toString() |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 template<typename E, typename A, typename T> | 45 template<typename E, typename A, typename T> |
46 void FloatEquals(const E& expected, const A& actual, const T& tol); | 46 void FloatEquals(const E& expected, const A& actual, const T& tol); |
47 | 47 |
48 template<typename E, typename A> | 48 template<typename E, typename A> |
49 void StringEquals(const E& expected, const A& actual); | 49 void StringEquals(const E& expected, const A& actual); |
50 | 50 |
51 template<typename E, typename A> | 51 template<typename E, typename A> |
52 void IsSubstring(const E& needle, const A& haystack); | 52 void IsSubstring(const E& needle, const A& haystack); |
53 | 53 |
54 template<typename E, typename A> | 54 template<typename E, typename A> |
| 55 void IsNotSubstring(const E& needle, const A& haystack); |
| 56 |
| 57 template<typename E, typename A> |
55 void LessThan(const E& left, const A& right); | 58 void LessThan(const E& left, const A& right); |
56 | 59 |
57 template<typename E, typename A> | 60 template<typename E, typename A> |
58 void LessEqual(const E& left, const A& right); | 61 void LessEqual(const E& left, const A& right); |
59 | 62 |
60 template<typename E, typename A> | 63 template<typename E, typename A> |
61 void GreaterThan(const E& left, const A& right); | 64 void GreaterThan(const E& left, const A& right); |
62 | 65 |
63 template<typename E, typename A> | 66 template<typename E, typename A> |
64 void GreaterEqual(const E& left, const A& right); | 67 void GreaterEqual(const E& left, const A& right); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 ess << needle; | 154 ess << needle; |
152 ass << haystack; | 155 ass << haystack; |
153 std::string es = ess.str(), as = ass.str(); | 156 std::string es = ess.str(), as = ass.str(); |
154 if (as.find(es) != std::string::npos) return; | 157 if (as.find(es) != std::string::npos) return; |
155 Fail("expected <\"%s\"> to be a substring of <\"%s\">", | 158 Fail("expected <\"%s\"> to be a substring of <\"%s\">", |
156 es.c_str(), as.c_str()); | 159 es.c_str(), as.c_str()); |
157 } | 160 } |
158 | 161 |
159 | 162 |
160 template<typename E, typename A> | 163 template<typename E, typename A> |
| 164 void DynamicAssertionHelper::IsNotSubstring(const E& needle, |
| 165 const A& haystack) { |
| 166 std::stringstream ess, ass; |
| 167 ess << needle; |
| 168 ass << haystack; |
| 169 std::string es = ess.str(), as = ass.str(); |
| 170 if (as.find(es) == std::string::npos) return; |
| 171 Fail("expected <\"%s\"> to not be a substring of <\"%s\">", |
| 172 es.c_str(), as.c_str()); |
| 173 } |
| 174 |
| 175 |
| 176 template<typename E, typename A> |
161 void DynamicAssertionHelper::LessThan(const E& left, const A& right) { | 177 void DynamicAssertionHelper::LessThan(const E& left, const A& right) { |
162 if (left < right) return; | 178 if (left < right) return; |
163 std::stringstream ess, ass; | 179 std::stringstream ess, ass; |
164 ess << left; | 180 ess << left; |
165 ass << right; | 181 ass << right; |
166 std::string es = ess.str(), as = ass.str(); | 182 std::string es = ess.str(), as = ass.str(); |
167 Fail("expected: %s < %s", es.c_str(), as.c_str()); | 183 Fail("expected: %s < %s", es.c_str(), as.c_str()); |
168 } | 184 } |
169 | 185 |
170 | 186 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 285 |
270 #define EXPECT_FLOAT_EQ(expected, actual, tol) \ | 286 #define EXPECT_FLOAT_EQ(expected, actual, tol) \ |
271 dart::Expect(__FILE__, __LINE__).FloatEquals((expected), (actual), (tol)) | 287 dart::Expect(__FILE__, __LINE__).FloatEquals((expected), (actual), (tol)) |
272 | 288 |
273 #define EXPECT_STREQ(expected, actual) \ | 289 #define EXPECT_STREQ(expected, actual) \ |
274 dart::Expect(__FILE__, __LINE__).StringEquals((expected), (actual)) | 290 dart::Expect(__FILE__, __LINE__).StringEquals((expected), (actual)) |
275 | 291 |
276 #define EXPECT_SUBSTRING(needle, haystack) \ | 292 #define EXPECT_SUBSTRING(needle, haystack) \ |
277 dart::Expect(__FILE__, __LINE__).IsSubstring((needle), (haystack)) | 293 dart::Expect(__FILE__, __LINE__).IsSubstring((needle), (haystack)) |
278 | 294 |
| 295 #define EXPECT_NOTSUBSTRING(needle, haystack) \ |
| 296 dart::Expect(__FILE__, __LINE__).IsNotSubstring((needle), (haystack)) |
| 297 |
279 #define EXPECT_LT(left, right) \ | 298 #define EXPECT_LT(left, right) \ |
280 dart::Expect(__FILE__, __LINE__).LessThan((left), (right)) | 299 dart::Expect(__FILE__, __LINE__).LessThan((left), (right)) |
281 | 300 |
282 #define EXPECT_LE(left, right) \ | 301 #define EXPECT_LE(left, right) \ |
283 dart::Expect(__FILE__, __LINE__).LessEqual((left), (right)) | 302 dart::Expect(__FILE__, __LINE__).LessEqual((left), (right)) |
284 | 303 |
285 #define EXPECT_GT(left, right) \ | 304 #define EXPECT_GT(left, right) \ |
286 dart::Expect(__FILE__, __LINE__).GreaterThan((left), (right)) | 305 dart::Expect(__FILE__, __LINE__).GreaterThan((left), (right)) |
287 | 306 |
288 #define EXPECT_GE(left, right) \ | 307 #define EXPECT_GE(left, right) \ |
(...skipping 11 matching lines...) Expand all Loading... |
300 #define WARN(error) \ | 319 #define WARN(error) \ |
301 dart::Expect(__FILE__, __LINE__).Fail("%s", error) | 320 dart::Expect(__FILE__, __LINE__).Fail("%s", error) |
302 | 321 |
303 #define WARN1(format, p1) \ | 322 #define WARN1(format, p1) \ |
304 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) | 323 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) |
305 | 324 |
306 #define WARN2(format, p1, p2) \ | 325 #define WARN2(format, p1, p2) \ |
307 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) | 326 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) |
308 | 327 |
309 #endif // PLATFORM_ASSERT_H_ | 328 #endif // PLATFORM_ASSERT_H_ |
OLD | NEW |