| 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 RUNTIME_PLATFORM_ASSERT_H_ | 5 #ifndef RUNTIME_PLATFORM_ASSERT_H_ |
| 6 #define RUNTIME_PLATFORM_ASSERT_H_ | 6 #define RUNTIME_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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // expression is true. For example, you could use it to verify the | 292 // expression is true. For example, you could use it to verify the |
| 293 // size of a static array: | 293 // size of a static array: |
| 294 // | 294 // |
| 295 // COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES); | 295 // COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES); |
| 296 // | 296 // |
| 297 // or to make sure a struct is smaller than a certain size: | 297 // or to make sure a struct is smaller than a certain size: |
| 298 // | 298 // |
| 299 // COMPILE_ASSERT(sizeof(foo) < 128); | 299 // COMPILE_ASSERT(sizeof(foo) < 128); |
| 300 // | 300 // |
| 301 | 301 |
| 302 namespace dart { |
| 303 |
| 302 template <bool> | 304 template <bool> |
| 303 struct CompileAssert {}; | 305 struct CompileAssert {}; |
| 304 // Macro to concatenate two tokens. The helper is need to proper expansion | 306 // Macro to concatenate two tokens. The helper is need to proper expansion |
| 305 // in case an argument is a macro itself. | 307 // in case an argument is a macro itself. |
| 306 #if !defined(COMPILE_ASSERT) | 308 #if !defined(COMPILE_ASSERT) |
| 307 #define COMPILE_ASSERT_JOIN(a, b) COMPILE_ASSERT_JOIN_HELPER(a, b) | 309 #define COMPILE_ASSERT_JOIN(a, b) COMPILE_ASSERT_JOIN_HELPER(a, b) |
| 308 #define COMPILE_ASSERT_JOIN_HELPER(a, b) a##b | 310 #define COMPILE_ASSERT_JOIN_HELPER(a, b) a##b |
| 309 #define COMPILE_ASSERT(expr) \ | 311 #define COMPILE_ASSERT(expr) \ |
| 310 DART_UNUSED typedef CompileAssert<(static_cast<bool>(expr))> \ | 312 DART_UNUSED typedef CompileAssert<(static_cast<bool>(expr))> \ |
| 311 COMPILE_ASSERT_JOIN(CompileAssertTypeDef, \ | 313 COMPILE_ASSERT_JOIN(CompileAssertTypeDef, \ |
| 312 __LINE__)[static_cast<bool>(expr) ? 1 : -1] | 314 __LINE__)[static_cast<bool>(expr) ? 1 : -1] |
| 313 #endif // !defined(COMPILE_ASSERT) | 315 #endif // !defined(COMPILE_ASSERT) |
| 314 | 316 |
| 317 } // namespace dart |
| 315 #if defined(TESTING) | 318 #if defined(TESTING) |
| 316 | 319 |
| 317 // EXPECT and FAIL are equivalent to ASSERT and FATAL except that they do not | 320 // EXPECT and FAIL are equivalent to ASSERT and FATAL except that they do not |
| 318 // cause early termination of the unit test. This allows testing to proceed | 321 // cause early termination of the unit test. This allows testing to proceed |
| 319 // further to be able to report other failures before reporting the overall | 322 // further to be able to report other failures before reporting the overall |
| 320 // unit tests as failing. | 323 // unit tests as failing. |
| 321 | 324 |
| 322 #define EXPECT(condition) \ | 325 #define EXPECT(condition) \ |
| 323 if (!(condition)) { \ | 326 if (!(condition)) { \ |
| 324 dart::Expect(__FILE__, __LINE__).Fail("expected: %s", #condition); \ | 327 dart::Expect(__FILE__, __LINE__).Fail("expected: %s", #condition); \ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 #define FAIL(error) dart::Expect(__FILE__, __LINE__).Fail("%s", error) | 362 #define FAIL(error) dart::Expect(__FILE__, __LINE__).Fail("%s", error) |
| 360 | 363 |
| 361 #define FAIL1(format, p1) dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) | 364 #define FAIL1(format, p1) dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) |
| 362 | 365 |
| 363 #define FAIL2(format, p1, p2) \ | 366 #define FAIL2(format, p1, p2) \ |
| 364 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) | 367 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) |
| 365 | 368 |
| 366 #endif // defined(TESTING) | 369 #endif // defined(TESTING) |
| 367 | 370 |
| 368 #endif // RUNTIME_PLATFORM_ASSERT_H_ | 371 #endif // RUNTIME_PLATFORM_ASSERT_H_ |
| OLD | NEW |