| 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() |
| 11 #if defined(TESTING) | 11 #if defined(TESTING) |
| 12 #include <sstream> | 12 #include <sstream> |
| 13 #include <string> | 13 #include <string> |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 #include "platform/globals.h" | 16 #include "platform/globals.h" |
| 17 #include "platform/memory_sanitizer.h" | 17 #include "platform/memory_sanitizer.h" |
| 18 | 18 |
| 19 #if !defined(DEBUG) && !defined(NDEBUG) | 19 #if !defined(DEBUG) && !defined(NDEBUG) |
| 20 #error neither DEBUG nor NDEBUG defined | 20 #error neither DEBUG nor NDEBUG defined |
| 21 #elif defined(DEBUG) && defined(NDEBUG) | 21 #elif defined(DEBUG) && defined(NDEBUG) |
| 22 #error both DEBUG and NDEBUG defined | 22 #error both DEBUG and NDEBUG defined |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace dart { | 25 namespace dart { |
| 26 | 26 |
| 27 class DynamicAssertionHelper { | 27 class DynamicAssertionHelper { |
| 28 public: | 28 public: |
| 29 enum Kind { | 29 enum Kind { ASSERT, EXPECT }; |
| 30 ASSERT, | |
| 31 EXPECT | |
| 32 }; | |
| 33 | 30 |
| 34 DynamicAssertionHelper(const char* file, int line, Kind kind) | 31 DynamicAssertionHelper(const char* file, int line, Kind kind) |
| 35 : file_(file), line_(line), kind_(kind) { } | 32 : file_(file), line_(line), kind_(kind) {} |
| 36 | 33 |
| 37 void Fail(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 34 void Fail(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 38 | 35 |
| 39 static bool failed() { return failed_; } | 36 static bool failed() { return failed_; } |
| 40 | 37 |
| 41 #if defined(TESTING) | 38 #if defined(TESTING) |
| 42 template<typename E, typename A> | 39 template <typename E, typename A> |
| 43 void Equals(const E& expected, const A& actual); | 40 void Equals(const E& expected, const A& actual); |
| 44 | 41 |
| 45 template<typename E, typename A> | 42 template <typename E, typename A> |
| 46 void NotEquals(const E& not_expected, const A& actual); | 43 void NotEquals(const E& not_expected, const A& actual); |
| 47 | 44 |
| 48 template<typename E, typename A, typename T> | 45 template <typename E, typename A, typename T> |
| 49 void FloatEquals(const E& expected, const A& actual, const T& tol); | 46 void FloatEquals(const E& expected, const A& actual, const T& tol); |
| 50 | 47 |
| 51 template<typename E, typename A> | 48 template <typename E, typename A> |
| 52 void StringEquals(const E& expected, const A& actual); | 49 void StringEquals(const E& expected, const A& actual); |
| 53 | 50 |
| 54 template<typename E, typename A> | 51 template <typename E, typename A> |
| 55 void IsSubstring(const E& needle, const A& haystack); | 52 void IsSubstring(const E& needle, const A& haystack); |
| 56 | 53 |
| 57 template<typename E, typename A> | 54 template <typename E, typename A> |
| 58 void IsNotSubstring(const E& needle, const A& haystack); | 55 void IsNotSubstring(const E& needle, const A& haystack); |
| 59 | 56 |
| 60 template<typename E, typename A> | 57 template <typename E, typename A> |
| 61 void LessThan(const E& left, const A& right); | 58 void LessThan(const E& left, const A& right); |
| 62 | 59 |
| 63 template<typename E, typename A> | 60 template <typename E, typename A> |
| 64 void LessEqual(const E& left, const A& right); | 61 void LessEqual(const E& left, const A& right); |
| 65 | 62 |
| 66 template<typename E, typename A> | 63 template <typename E, typename A> |
| 67 void GreaterThan(const E& left, const A& right); | 64 void GreaterThan(const E& left, const A& right); |
| 68 | 65 |
| 69 template<typename E, typename A> | 66 template <typename E, typename A> |
| 70 void GreaterEqual(const E& left, const A& right); | 67 void GreaterEqual(const E& left, const A& right); |
| 71 #endif | 68 #endif |
| 72 | 69 |
| 73 template<typename T> | 70 template <typename T> |
| 74 T NotNull(const T p); | 71 T NotNull(const T p); |
| 75 | 72 |
| 76 private: | 73 private: |
| 77 static bool failed_; | 74 static bool failed_; |
| 78 | 75 |
| 79 const char* const file_; | 76 const char* const file_; |
| 80 const int line_; | 77 const int line_; |
| 81 const Kind kind_; | 78 const Kind kind_; |
| 82 | 79 |
| 83 DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicAssertionHelper); | 80 DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicAssertionHelper); |
| 84 }; | 81 }; |
| 85 | 82 |
| 86 | 83 |
| 87 class Assert: public DynamicAssertionHelper { | 84 class Assert : public DynamicAssertionHelper { |
| 88 public: | 85 public: |
| 89 Assert(const char* file, int line) | 86 Assert(const char* file, int line) |
| 90 : DynamicAssertionHelper(file, line, ASSERT) { } | 87 : DynamicAssertionHelper(file, line, ASSERT) {} |
| 91 }; | 88 }; |
| 92 | 89 |
| 93 | 90 |
| 94 class Expect: public DynamicAssertionHelper { | 91 class Expect : public DynamicAssertionHelper { |
| 95 public: | 92 public: |
| 96 Expect(const char* file, int line) | 93 Expect(const char* file, int line) |
| 97 : DynamicAssertionHelper(file, line, EXPECT) { } | 94 : DynamicAssertionHelper(file, line, EXPECT) {} |
| 98 }; | 95 }; |
| 99 | 96 |
| 100 | 97 |
| 101 #if defined(TESTING) | 98 #if defined(TESTING) |
| 102 // Only allow the expensive (with respect to code size) assertions | 99 // Only allow the expensive (with respect to code size) assertions |
| 103 // in testing code. | 100 // in testing code. |
| 104 template<typename E, typename A> | 101 template <typename E, typename A> |
| 105 void DynamicAssertionHelper::Equals(const E& expected, const A& actual) { | 102 void DynamicAssertionHelper::Equals(const E& expected, const A& actual) { |
| 106 if (actual == expected) return; | 103 if (actual == expected) return; |
| 107 std::ostringstream ess, ass; | 104 std::ostringstream ess, ass; |
| 108 ess << expected; | 105 ess << expected; |
| 109 ass << actual; | 106 ass << actual; |
| 110 std::string es = ess.str(), as = ass.str(); | 107 std::string es = ess.str(), as = ass.str(); |
| 111 Fail("expected: <%s> but was: <%s>", es.c_str(), as.c_str()); | 108 Fail("expected: <%s> but was: <%s>", es.c_str(), as.c_str()); |
| 112 } | 109 } |
| 113 | 110 |
| 114 | 111 |
| 115 template<typename E, typename A> | 112 template <typename E, typename A> |
| 116 void DynamicAssertionHelper::NotEquals(const E& not_expected, | 113 void DynamicAssertionHelper::NotEquals(const E& not_expected, const A& actual) { |
| 117 const A& actual) { | |
| 118 if (actual != not_expected) return; | 114 if (actual != not_expected) return; |
| 119 std::ostringstream ness; | 115 std::ostringstream ness; |
| 120 ness << not_expected; | 116 ness << not_expected; |
| 121 std::string nes = ness.str(); | 117 std::string nes = ness.str(); |
| 122 Fail("did not expect: <%s>", nes.c_str()); | 118 Fail("did not expect: <%s>", nes.c_str()); |
| 123 } | 119 } |
| 124 | 120 |
| 125 | 121 |
| 126 template<typename E, typename A, typename T> | 122 template <typename E, typename A, typename T> |
| 127 void DynamicAssertionHelper::FloatEquals(const E& expected, | 123 void DynamicAssertionHelper::FloatEquals(const E& expected, |
| 128 const A& actual, | 124 const A& actual, |
| 129 const T& tol) { | 125 const T& tol) { |
| 130 if (((expected - tol) <= actual) && (actual <= (expected + tol))) { | 126 if (((expected - tol) <= actual) && (actual <= (expected + tol))) { |
| 131 return; | 127 return; |
| 132 } | 128 } |
| 133 std::ostringstream ess, ass, tolss; | 129 std::ostringstream ess, ass, tolss; |
| 134 ess << expected; | 130 ess << expected; |
| 135 ass << actual; | 131 ass << actual; |
| 136 tolss << tol; | 132 tolss << tol; |
| 137 std::string es = ess.str(), as = ass.str(), tols = tolss.str(); | 133 std::string es = ess.str(), as = ass.str(), tols = tolss.str(); |
| 138 Fail("expected: <%s> but was: <%s> (tolerance: <%s>)", | 134 Fail("expected: <%s> but was: <%s> (tolerance: <%s>)", es.c_str(), as.c_str(), |
| 139 es.c_str(), | |
| 140 as.c_str(), | |
| 141 tols.c_str()); | 135 tols.c_str()); |
| 142 } | 136 } |
| 143 | 137 |
| 144 | 138 |
| 145 template<typename E, typename A> | 139 template <typename E, typename A> |
| 146 NO_SANITIZE_MEMORY | 140 NO_SANITIZE_MEMORY void DynamicAssertionHelper::StringEquals(const E& expected, |
| 147 void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) { | 141 const A& actual) { |
| 148 std::ostringstream ess, ass; | 142 std::ostringstream ess, ass; |
| 149 ess << expected; | 143 ess << expected; |
| 150 ass << actual; | 144 ass << actual; |
| 151 std::string es = ess.str(), as = ass.str(); | 145 std::string es = ess.str(), as = ass.str(); |
| 152 if (as == es) return; | 146 if (as == es) return; |
| 153 Fail("expected:\n<\"%s\">\nbut was:\n<\"%s\">", es.c_str(), as.c_str()); | 147 Fail("expected:\n<\"%s\">\nbut was:\n<\"%s\">", es.c_str(), as.c_str()); |
| 154 } | 148 } |
| 155 | 149 |
| 156 | 150 |
| 157 template<typename E, typename A> | 151 template <typename E, typename A> |
| 158 NO_SANITIZE_MEMORY | 152 NO_SANITIZE_MEMORY void DynamicAssertionHelper::IsSubstring(const E& needle, |
| 159 void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) { | 153 const A& haystack) { |
| 160 std::ostringstream ess, ass; | 154 std::ostringstream ess, ass; |
| 161 ess << needle; | 155 ess << needle; |
| 162 ass << haystack; | 156 ass << haystack; |
| 163 std::string es = ess.str(), as = ass.str(); | 157 std::string es = ess.str(), as = ass.str(); |
| 164 if (as.find(es) != std::string::npos) return; | 158 if (as.find(es) != std::string::npos) return; |
| 165 Fail("expected <\"%s\"> to be a substring of <\"%s\">", | 159 Fail("expected <\"%s\"> to be a substring of <\"%s\">", es.c_str(), |
| 166 es.c_str(), as.c_str()); | 160 as.c_str()); |
| 167 } | 161 } |
| 168 | 162 |
| 169 | 163 |
| 170 template<typename E, typename A> | 164 template <typename E, typename A> |
| 171 NO_SANITIZE_MEMORY | 165 NO_SANITIZE_MEMORY void DynamicAssertionHelper::IsNotSubstring( |
| 172 void DynamicAssertionHelper::IsNotSubstring(const E& needle, | 166 const E& needle, |
| 173 const A& haystack) { | 167 const A& haystack) { |
| 174 std::ostringstream ess, ass; | 168 std::ostringstream ess, ass; |
| 175 ess << needle; | 169 ess << needle; |
| 176 ass << haystack; | 170 ass << haystack; |
| 177 std::string es = ess.str(), as = ass.str(); | 171 std::string es = ess.str(), as = ass.str(); |
| 178 if (as.find(es) == std::string::npos) return; | 172 if (as.find(es) == std::string::npos) return; |
| 179 Fail("expected <\"%s\"> to not be a substring of <\"%s\">", | 173 Fail("expected <\"%s\"> to not be a substring of <\"%s\">", es.c_str(), |
| 180 es.c_str(), as.c_str()); | 174 as.c_str()); |
| 181 } | 175 } |
| 182 | 176 |
| 183 | 177 |
| 184 template<typename E, typename A> | 178 template <typename E, typename A> |
| 185 void DynamicAssertionHelper::LessThan(const E& left, const A& right) { | 179 void DynamicAssertionHelper::LessThan(const E& left, const A& right) { |
| 186 if (left < right) return; | 180 if (left < right) return; |
| 187 std::ostringstream ess, ass; | 181 std::ostringstream ess, ass; |
| 188 ess << left; | 182 ess << left; |
| 189 ass << right; | 183 ass << right; |
| 190 std::string es = ess.str(), as = ass.str(); | 184 std::string es = ess.str(), as = ass.str(); |
| 191 Fail("expected: %s < %s", es.c_str(), as.c_str()); | 185 Fail("expected: %s < %s", es.c_str(), as.c_str()); |
| 192 } | 186 } |
| 193 | 187 |
| 194 | 188 |
| 195 template<typename E, typename A> | 189 template <typename E, typename A> |
| 196 void DynamicAssertionHelper::LessEqual(const E& left, const A& right) { | 190 void DynamicAssertionHelper::LessEqual(const E& left, const A& right) { |
| 197 if (left <= right) return; | 191 if (left <= right) return; |
| 198 std::ostringstream ess, ass; | 192 std::ostringstream ess, ass; |
| 199 ess << left; | 193 ess << left; |
| 200 ass << right; | 194 ass << right; |
| 201 std::string es = ess.str(), as = ass.str(); | 195 std::string es = ess.str(), as = ass.str(); |
| 202 Fail("expected: %s <= %s", es.c_str(), as.c_str()); | 196 Fail("expected: %s <= %s", es.c_str(), as.c_str()); |
| 203 } | 197 } |
| 204 | 198 |
| 205 | 199 |
| 206 template<typename E, typename A> | 200 template <typename E, typename A> |
| 207 void DynamicAssertionHelper::GreaterThan(const E& left, const A& right) { | 201 void DynamicAssertionHelper::GreaterThan(const E& left, const A& right) { |
| 208 if (left > right) return; | 202 if (left > right) return; |
| 209 std::ostringstream ess, ass; | 203 std::ostringstream ess, ass; |
| 210 ess << left; | 204 ess << left; |
| 211 ass << right; | 205 ass << right; |
| 212 std::string es = ess.str(), as = ass.str(); | 206 std::string es = ess.str(), as = ass.str(); |
| 213 Fail("expected: %s > %s", es.c_str(), as.c_str()); | 207 Fail("expected: %s > %s", es.c_str(), as.c_str()); |
| 214 } | 208 } |
| 215 | 209 |
| 216 | 210 |
| 217 template<typename E, typename A> | 211 template <typename E, typename A> |
| 218 void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) { | 212 void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) { |
| 219 if (left >= right) return; | 213 if (left >= right) return; |
| 220 std::ostringstream ess, ass; | 214 std::ostringstream ess, ass; |
| 221 ess << left; | 215 ess << left; |
| 222 ass << right; | 216 ass << right; |
| 223 std::string es = ess.str(), as = ass.str(); | 217 std::string es = ess.str(), as = ass.str(); |
| 224 Fail("expected: %s >= %s", es.c_str(), as.c_str()); | 218 Fail("expected: %s >= %s", es.c_str(), as.c_str()); |
| 225 } | 219 } |
| 226 #endif | 220 #endif |
| 227 | 221 |
| 228 | 222 |
| 229 template<typename T> | 223 template <typename T> |
| 230 T DynamicAssertionHelper::NotNull(const T p) { | 224 T DynamicAssertionHelper::NotNull(const T p) { |
| 231 if (p != NULL) return p; | 225 if (p != NULL) return p; |
| 232 Fail("expected: not NULL, found NULL"); | 226 Fail("expected: not NULL, found NULL"); |
| 233 return NULL; | 227 return NULL; |
| 234 } | 228 } |
| 235 | 229 |
| 236 } // namespace dart | 230 } // namespace dart |
| 237 | 231 |
| 238 | 232 |
| 239 #define FATAL(error) \ | 233 #define FATAL(error) dart::Assert(__FILE__, __LINE__).Fail("%s", error) |
| 240 dart::Assert(__FILE__, __LINE__).Fail("%s", error) | |
| 241 | 234 |
| 242 #define FATAL1(format, p1) \ | 235 #define FATAL1(format, p1) dart::Assert(__FILE__, __LINE__).Fail(format, (p1)) |
| 243 dart::Assert(__FILE__, __LINE__).Fail(format, (p1)) | |
| 244 | 236 |
| 245 #define FATAL2(format, p1, p2) \ | 237 #define FATAL2(format, p1, p2) \ |
| 246 dart::Assert(__FILE__, __LINE__).Fail(format, (p1), (p2)) | 238 dart::Assert(__FILE__, __LINE__).Fail(format, (p1), (p2)) |
| 247 | 239 |
| 248 #define FATAL3(format, p1, p2, p3) \ | 240 #define FATAL3(format, p1, p2, p3) \ |
| 249 dart::Assert(__FILE__, __LINE__).Fail(format, (p1), (p2), (p3)) | 241 dart::Assert(__FILE__, __LINE__).Fail(format, (p1), (p2), (p3)) |
| 250 | 242 |
| 251 #define UNIMPLEMENTED() \ | 243 #define UNIMPLEMENTED() FATAL("unimplemented code") |
| 252 FATAL("unimplemented code") | |
| 253 | 244 |
| 254 #define UNREACHABLE() \ | 245 #define UNREACHABLE() FATAL("unreachable code") |
| 255 FATAL("unreachable code") | |
| 256 | 246 |
| 257 #define OUT_OF_MEMORY() \ | 247 #define OUT_OF_MEMORY() FATAL("Out of memory.") |
| 258 FATAL("Out of memory.") | |
| 259 | 248 |
| 260 | 249 |
| 261 #if defined(DEBUG) | 250 #if defined(DEBUG) |
| 262 // DEBUG binaries use assertions in the code. | 251 // DEBUG binaries use assertions in the code. |
| 263 // Note: We wrap the if statement in a do-while so that we get a compile | 252 // Note: We wrap the if statement in a do-while so that we get a compile |
| 264 // error if there is no semicolon after ASSERT(condition). This | 253 // error if there is no semicolon after ASSERT(condition). This |
| 265 // ensures that we get the same behavior on DEBUG and RELEASE builds. | 254 // ensures that we get the same behavior on DEBUG and RELEASE builds. |
| 266 | 255 |
| 267 #define ASSERT(cond) \ | 256 #define ASSERT(cond) \ |
| 268 do { \ | 257 do { \ |
| 269 if (!(cond)) dart::Assert(__FILE__, __LINE__).Fail("expected: %s", #cond); \ | 258 if (!(cond)) dart::Assert(__FILE__, __LINE__).Fail("expected: %s", #cond); \ |
| 270 } while (false) | 259 } while (false) |
| 271 | 260 |
| 272 // DEBUG_ASSERT allows identifiers in condition to be undeclared in release | 261 // DEBUG_ASSERT allows identifiers in condition to be undeclared in release |
| 273 // mode. | 262 // mode. |
| 274 #define DEBUG_ASSERT(cond) ASSERT(cond) | 263 #define DEBUG_ASSERT(cond) ASSERT(cond) |
| 275 | 264 |
| 276 // Returns 'ptr'; useful for initializer lists: | 265 // Returns 'ptr'; useful for initializer lists: |
| 277 // class Foo { Foo(int* ptr) : ptr_(ASSERT_NOTNULL(ptr)) ... | 266 // class Foo { Foo(int* ptr) : ptr_(ASSERT_NOTNULL(ptr)) ... |
| 278 #define ASSERT_NOTNULL(ptr) \ | 267 #define ASSERT_NOTNULL(ptr) dart::Assert(__FILE__, __LINE__).NotNull((ptr)) |
| 279 dart::Assert(__FILE__, __LINE__).NotNull((ptr)) | |
| 280 | 268 |
| 281 #else // if defined(DEBUG) | 269 #else // if defined(DEBUG) |
| 282 | 270 |
| 283 // In order to avoid variable unused warnings for code that only uses | 271 // In order to avoid variable unused warnings for code that only uses |
| 284 // a variable in an ASSERT or EXPECT, we make sure to use the macro | 272 // a variable in an ASSERT or EXPECT, we make sure to use the macro |
| 285 // argument. | 273 // argument. |
| 286 #define ASSERT(condition) do {} while (false && (condition)) | 274 #define ASSERT(condition) \ |
| 275 do { \ |
| 276 } while (false && (condition)) |
| 287 | 277 |
| 288 #define DEBUG_ASSERT(cond) | 278 #define DEBUG_ASSERT(cond) |
| 289 | 279 |
| 290 #define ASSERT_NOTNULL(ptr) (ptr) | 280 #define ASSERT_NOTNULL(ptr) (ptr) |
| 291 | 281 |
| 292 #endif // if defined(DEBUG) | 282 #endif // if defined(DEBUG) |
| 293 | 283 |
| 294 | 284 |
| 295 #define RELEASE_ASSERT(cond) \ | 285 #define RELEASE_ASSERT(cond) \ |
| 296 do { \ | 286 do { \ |
| 297 if (!(cond)) dart::Assert(__FILE__, __LINE__).Fail("expected: %s", #cond); \ | 287 if (!(cond)) dart::Assert(__FILE__, __LINE__).Fail("expected: %s", #cond); \ |
| 298 } while (false) | 288 } while (false) |
| 299 | 289 |
| 300 | 290 |
| 301 // The COMPILE_ASSERT macro can be used to verify that a compile time | 291 // The COMPILE_ASSERT macro can be used to verify that a compile time |
| 302 // 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 |
| 303 // size of a static array: | 293 // size of a static array: |
| 304 // | 294 // |
| 305 // COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES); | 295 // COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES); |
| 306 // | 296 // |
| 307 // 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: |
| 308 // | 298 // |
| 309 // COMPILE_ASSERT(sizeof(foo) < 128); | 299 // COMPILE_ASSERT(sizeof(foo) < 128); |
| 310 // | 300 // |
| 311 | 301 |
| 312 template <bool> | 302 template <bool> |
| 313 struct CompileAssert { | 303 struct CompileAssert {}; |
| 314 }; | |
| 315 // Macro to concatenate two tokens. The helper is need to proper expansion | 304 // Macro to concatenate two tokens. The helper is need to proper expansion |
| 316 // in case an argument is a macro itself. | 305 // in case an argument is a macro itself. |
| 317 #if !defined(COMPILE_ASSERT) | 306 #if !defined(COMPILE_ASSERT) |
| 318 #define COMPILE_ASSERT_JOIN(a, b) COMPILE_ASSERT_JOIN_HELPER(a, b) | 307 #define COMPILE_ASSERT_JOIN(a, b) COMPILE_ASSERT_JOIN_HELPER(a, b) |
| 319 #define COMPILE_ASSERT_JOIN_HELPER(a, b) a##b | 308 #define COMPILE_ASSERT_JOIN_HELPER(a, b) a##b |
| 320 #define COMPILE_ASSERT(expr) \ | 309 #define COMPILE_ASSERT(expr) \ |
| 321 DART_UNUSED typedef CompileAssert<(static_cast<bool>(expr))> \ | 310 DART_UNUSED typedef CompileAssert<(static_cast<bool>(expr))> \ |
| 322 COMPILE_ASSERT_JOIN(CompileAssertTypeDef, __LINE__)[static_cast<bool>(expr) \ | 311 COMPILE_ASSERT_JOIN(CompileAssertTypeDef, \ |
| 323 ? 1 : -1] | 312 __LINE__)[static_cast<bool>(expr) ? 1 : -1] |
| 324 #endif // !defined(COMPILE_ASSERT) | 313 #endif // !defined(COMPILE_ASSERT) |
| 325 | 314 |
| 326 #if defined(TESTING) | 315 #if defined(TESTING) |
| 327 | 316 |
| 328 // EXPECT and FAIL are equivalent to ASSERT and FATAL except that they do not | 317 // EXPECT and FAIL are equivalent to ASSERT and FATAL except that they do not |
| 329 // cause early termination of the unit test. This allows testing to proceed | 318 // cause early termination of the unit test. This allows testing to proceed |
| 330 // further to be able to report other failures before reporting the overall | 319 // further to be able to report other failures before reporting the overall |
| 331 // unit tests as failing. | 320 // unit tests as failing. |
| 332 | 321 |
| 333 #define EXPECT(condition) \ | 322 #define EXPECT(condition) \ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 358 | 347 |
| 359 #define EXPECT_LE(left, right) \ | 348 #define EXPECT_LE(left, right) \ |
| 360 dart::Expect(__FILE__, __LINE__).LessEqual((left), (right)) | 349 dart::Expect(__FILE__, __LINE__).LessEqual((left), (right)) |
| 361 | 350 |
| 362 #define EXPECT_GT(left, right) \ | 351 #define EXPECT_GT(left, right) \ |
| 363 dart::Expect(__FILE__, __LINE__).GreaterThan((left), (right)) | 352 dart::Expect(__FILE__, __LINE__).GreaterThan((left), (right)) |
| 364 | 353 |
| 365 #define EXPECT_GE(left, right) \ | 354 #define EXPECT_GE(left, right) \ |
| 366 dart::Expect(__FILE__, __LINE__).GreaterEqual((left), (right)) | 355 dart::Expect(__FILE__, __LINE__).GreaterEqual((left), (right)) |
| 367 | 356 |
| 368 #define EXPECT_NOTNULL(ptr) \ | 357 #define EXPECT_NOTNULL(ptr) dart::Expect(__FILE__, __LINE__).NotNull((ptr)) |
| 369 dart::Expect(__FILE__, __LINE__).NotNull((ptr)) | |
| 370 | 358 |
| 371 #define FAIL(error) \ | 359 #define FAIL(error) dart::Expect(__FILE__, __LINE__).Fail("%s", error) |
| 372 dart::Expect(__FILE__, __LINE__).Fail("%s", error) | |
| 373 | 360 |
| 374 #define FAIL1(format, p1) \ | 361 #define FAIL1(format, p1) dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) |
| 375 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) | |
| 376 | 362 |
| 377 #define FAIL2(format, p1, p2) \ | 363 #define FAIL2(format, p1, p2) \ |
| 378 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) | 364 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) |
| 379 | 365 |
| 380 #endif // defined(TESTING) | 366 #endif // defined(TESTING) |
| 381 | 367 |
| 382 #endif // RUNTIME_PLATFORM_ASSERT_H_ | 368 #endif // RUNTIME_PLATFORM_ASSERT_H_ |
| OLD | NEW |