| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 void LessThan(const E& left, const A& right); | 55 void LessThan(const E& left, const A& right); |
| 56 | 56 |
| 57 template<typename E, typename A> | 57 template<typename E, typename A> |
| 58 void LessEqual(const E& left, const A& right); | 58 void LessEqual(const E& left, const A& right); |
| 59 | 59 |
| 60 template<typename E, typename A> | 60 template<typename E, typename A> |
| 61 void GreaterThan(const E& left, const A& right); | 61 void GreaterThan(const E& left, const A& right); |
| 62 | 62 |
| 63 template<typename E, typename A> | 63 template<typename E, typename A> |
| 64 void GreaterEqual(const E& left, const A& right); | 64 void GreaterEqual(const E& left, const A& right); |
| 65 |
| 66 template<typename T> |
| 67 void NotNull(const T p); |
| 65 #endif | 68 #endif |
| 66 | 69 |
| 67 private: | 70 private: |
| 68 const char* const file_; | 71 const char* const file_; |
| 69 const int line_; | 72 const int line_; |
| 70 const Kind kind_; | 73 const Kind kind_; |
| 71 | 74 |
| 72 DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicAssertionHelper); | 75 DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicAssertionHelper); |
| 73 }; | 76 }; |
| 74 | 77 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 192 |
| 190 template<typename E, typename A> | 193 template<typename E, typename A> |
| 191 void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) { | 194 void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) { |
| 192 if (left >= right) return; | 195 if (left >= right) return; |
| 193 std::stringstream ess, ass; | 196 std::stringstream ess, ass; |
| 194 ess << left; | 197 ess << left; |
| 195 ass << right; | 198 ass << right; |
| 196 std::string es = ess.str(), as = ass.str(); | 199 std::string es = ess.str(), as = ass.str(); |
| 197 Fail("expected: %s >= %s", es.c_str(), as.c_str()); | 200 Fail("expected: %s >= %s", es.c_str(), as.c_str()); |
| 198 } | 201 } |
| 202 |
| 203 |
| 204 template<typename T> |
| 205 void DynamicAssertionHelper::NotNull(const T p) { |
| 206 if (p != NULL) return; |
| 207 Fail("expected: not NULL, found NULL"); |
| 208 } |
| 199 #endif | 209 #endif |
| 200 | 210 |
| 201 } // namespace dart | 211 } // namespace dart |
| 202 | 212 |
| 203 | 213 |
| 204 #define FATAL(error) \ | 214 #define FATAL(error) \ |
| 205 dart::Assert(__FILE__, __LINE__).Fail("%s", error) | 215 dart::Assert(__FILE__, __LINE__).Fail("%s", error) |
| 206 | 216 |
| 207 #define FATAL1(format, p1) \ | 217 #define FATAL1(format, p1) \ |
| 208 dart::Assert(__FILE__, __LINE__).Fail(format, (p1)) | 218 dart::Assert(__FILE__, __LINE__).Fail(format, (p1)) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 dart::Expect(__FILE__, __LINE__).LessThan((left), (right)) | 280 dart::Expect(__FILE__, __LINE__).LessThan((left), (right)) |
| 271 | 281 |
| 272 #define EXPECT_LE(left, right) \ | 282 #define EXPECT_LE(left, right) \ |
| 273 dart::Expect(__FILE__, __LINE__).LessEqual((left), (right)) | 283 dart::Expect(__FILE__, __LINE__).LessEqual((left), (right)) |
| 274 | 284 |
| 275 #define EXPECT_GT(left, right) \ | 285 #define EXPECT_GT(left, right) \ |
| 276 dart::Expect(__FILE__, __LINE__).GreaterThan((left), (right)) | 286 dart::Expect(__FILE__, __LINE__).GreaterThan((left), (right)) |
| 277 | 287 |
| 278 #define EXPECT_GE(left, right) \ | 288 #define EXPECT_GE(left, right) \ |
| 279 dart::Expect(__FILE__, __LINE__).GreaterEqual((left), (right)) | 289 dart::Expect(__FILE__, __LINE__).GreaterEqual((left), (right)) |
| 290 |
| 291 #define EXPECT_NOTNULL(ptr) \ |
| 292 dart::Expect(__FILE__, __LINE__).NotNull((ptr)) |
| 280 #endif | 293 #endif |
| 281 | 294 |
| 282 // TODO(iposva): provide a better way to get extra info on an EXPECT | 295 // TODO(iposva): provide a better way to get extra info on an EXPECT |
| 283 // fail - you suggested EXPECT_EQ(expected, actual, msg_format, | 296 // fail - you suggested EXPECT_EQ(expected, actual, msg_format, |
| 284 // parameters_for_msg...), I quite like the google3 method | 297 // parameters_for_msg...), I quite like the google3 method |
| 285 // EXPECT_EQ(a, b) << "more stuff here...". (benl). | 298 // EXPECT_EQ(a, b) << "more stuff here...". (benl). |
| 286 | 299 |
| 287 #define WARN(error) \ | 300 #define WARN(error) \ |
| 288 dart::Expect(__FILE__, __LINE__).Fail("%s", error) | 301 dart::Expect(__FILE__, __LINE__).Fail("%s", error) |
| 289 | 302 |
| 290 #define WARN1(format, p1) \ | 303 #define WARN1(format, p1) \ |
| 291 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) | 304 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) |
| 292 | 305 |
| 293 #define WARN2(format, p1, p2) \ | 306 #define WARN2(format, p1, p2) \ |
| 294 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) | 307 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) |
| 295 | 308 |
| 296 #endif // PLATFORM_ASSERT_H_ | 309 #endif // PLATFORM_ASSERT_H_ |
| OLD | NEW |