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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 #else // if defined(DEBUG) | 262 #else // if defined(DEBUG) |
263 | 263 |
264 // In order to avoid variable unused warnings for code that only uses | 264 // In order to avoid variable unused warnings for code that only uses |
265 // a variable in an ASSERT or EXPECT, we make sure to use the macro | 265 // a variable in an ASSERT or EXPECT, we make sure to use the macro |
266 // argument. | 266 // argument. |
267 #define ASSERT(condition) do {} while (false && (condition)) | 267 #define ASSERT(condition) do {} while (false && (condition)) |
268 | 268 |
269 #define DEBUG_ASSERT(cond) | 269 #define DEBUG_ASSERT(cond) |
270 | 270 |
| 271 // The COMPILE_ASSERT macro can be used to verify that a compile time |
| 272 // expression is true. For example, you could use it to verify the |
| 273 // size of a static array: |
| 274 // |
| 275 // COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES, |
| 276 // content_type_names_incorrect_size); |
| 277 // |
| 278 // or to make sure a struct is smaller than a certain size: |
| 279 // |
| 280 // COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); |
| 281 // |
| 282 // The second argument to the macro is the name of the variable. If |
| 283 // the expression is false, most compilers will issue a warning/error |
| 284 // containing the name of the variable. |
| 285 |
| 286 template <bool> |
| 287 struct CompileAssert { |
| 288 }; |
| 289 |
| 290 #define COMPILE_ASSERT(expr, msg) \ |
| 291 typedef CompileAssert<(static_cast<bool>(expr))> \ |
| 292 msg[static_cast<bool>(expr) ? 1 : -1] |
| 293 |
271 #endif // if defined(DEBUG) | 294 #endif // if defined(DEBUG) |
272 | 295 |
273 | 296 |
274 #if defined(TESTING) | 297 #if defined(TESTING) |
275 #define EXPECT(condition) \ | 298 #define EXPECT(condition) \ |
276 if (!(condition)) { \ | 299 if (!(condition)) { \ |
277 dart::Expect(__FILE__, __LINE__).Fail("expected: %s", #condition); \ | 300 dart::Expect(__FILE__, __LINE__).Fail("expected: %s", #condition); \ |
278 } | 301 } |
279 | 302 |
280 #define EXPECT_EQ(expected, actual) \ | 303 #define EXPECT_EQ(expected, actual) \ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 #define WARN(error) \ | 342 #define WARN(error) \ |
320 dart::Expect(__FILE__, __LINE__).Fail("%s", error) | 343 dart::Expect(__FILE__, __LINE__).Fail("%s", error) |
321 | 344 |
322 #define WARN1(format, p1) \ | 345 #define WARN1(format, p1) \ |
323 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) | 346 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) |
324 | 347 |
325 #define WARN2(format, p1, p2) \ | 348 #define WARN2(format, p1, p2) \ |
326 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) | 349 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) |
327 | 350 |
328 #endif // PLATFORM_ASSERT_H_ | 351 #endif // PLATFORM_ASSERT_H_ |
OLD | NEW |