OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 VM_ASSERT_H_ | 5 #ifndef VM_ASSERT_H_ |
6 #define VM_ASSERT_H_ | 6 #define VM_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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 template<typename E, typename A> | 42 template<typename E, typename A> |
43 void NotEquals(const E& not_expected, const A& actual); | 43 void NotEquals(const E& not_expected, const A& actual); |
44 | 44 |
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); |
| 53 |
| 54 template<typename E, typename A> |
52 void LessThan(const E& left, const A& right); | 55 void LessThan(const E& left, const A& right); |
53 | 56 |
54 template<typename E, typename A> | 57 template<typename E, typename A> |
55 void LessEqual(const E& left, const A& right); | 58 void LessEqual(const E& left, const A& right); |
56 | 59 |
57 template<typename E, typename A> | 60 template<typename E, typename A> |
58 void GreaterThan(const E& left, const A& right); | 61 void GreaterThan(const E& left, const A& right); |
59 | 62 |
60 template<typename E, typename A> | 63 template<typename E, typename A> |
61 void GreaterEqual(const E& left, const A& right); | 64 void GreaterEqual(const E& left, const A& right); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 std::stringstream ess, ass; | 136 std::stringstream ess, ass; |
134 ess << expected; | 137 ess << expected; |
135 ass << actual; | 138 ass << actual; |
136 std::string es = ess.str(), as = ass.str(); | 139 std::string es = ess.str(), as = ass.str(); |
137 if (as == es) return; | 140 if (as == es) return; |
138 Fail("expected: <\"%s\"> but was: <\"%s\">", es.c_str(), as.c_str()); | 141 Fail("expected: <\"%s\"> but was: <\"%s\">", es.c_str(), as.c_str()); |
139 } | 142 } |
140 | 143 |
141 | 144 |
142 template<typename E, typename A> | 145 template<typename E, typename A> |
| 146 void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) { |
| 147 std::stringstream ess, ass; |
| 148 ess << needle; |
| 149 ass << haystack; |
| 150 std::string es = ess.str(), as = ass.str(); |
| 151 if (as.find(es) != std::string::npos) return; |
| 152 Fail("expected <\"%s\"> to be a substring of <\"%s\">", |
| 153 es.c_str(), as.c_str()); |
| 154 } |
| 155 |
| 156 |
| 157 template<typename E, typename A> |
143 void DynamicAssertionHelper::LessThan(const E& left, const A& right) { | 158 void DynamicAssertionHelper::LessThan(const E& left, const A& right) { |
144 if (left < right) return; | 159 if (left < right) return; |
145 std::stringstream ess, ass; | 160 std::stringstream ess, ass; |
146 ess << left; | 161 ess << left; |
147 ass << right; | 162 ass << right; |
148 std::string es = ess.str(), as = ass.str(); | 163 std::string es = ess.str(), as = ass.str(); |
149 Fail("expected: %s < %s", es.c_str(), as.c_str()); | 164 Fail("expected: %s < %s", es.c_str(), as.c_str()); |
150 } | 165 } |
151 | 166 |
152 | 167 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 256 |
242 #define EXPECT_NE(not_expected, actual) \ | 257 #define EXPECT_NE(not_expected, actual) \ |
243 dart::Expect(__FILE__, __LINE__).NotEquals((not_expected), (actual)) | 258 dart::Expect(__FILE__, __LINE__).NotEquals((not_expected), (actual)) |
244 | 259 |
245 #define EXPECT_FLOAT_EQ(expected, actual, tol) \ | 260 #define EXPECT_FLOAT_EQ(expected, actual, tol) \ |
246 dart::Expect(__FILE__, __LINE__).FloatEquals((expected), (actual), (tol)) | 261 dart::Expect(__FILE__, __LINE__).FloatEquals((expected), (actual), (tol)) |
247 | 262 |
248 #define EXPECT_STREQ(expected, actual) \ | 263 #define EXPECT_STREQ(expected, actual) \ |
249 dart::Expect(__FILE__, __LINE__).StringEquals((expected), (actual)) | 264 dart::Expect(__FILE__, __LINE__).StringEquals((expected), (actual)) |
250 | 265 |
| 266 #define EXPECT_SUBSTRING(needle, haystack) \ |
| 267 dart::Expect(__FILE__, __LINE__).IsSubstring((needle), (haystack)) |
| 268 |
251 #define EXPECT_LT(left, right) \ | 269 #define EXPECT_LT(left, right) \ |
252 dart::Expect(__FILE__, __LINE__).LessThan((left), (right)) | 270 dart::Expect(__FILE__, __LINE__).LessThan((left), (right)) |
253 | 271 |
254 #define EXPECT_LE(left, right) \ | 272 #define EXPECT_LE(left, right) \ |
255 dart::Expect(__FILE__, __LINE__).LessEqual((left), (right)) | 273 dart::Expect(__FILE__, __LINE__).LessEqual((left), (right)) |
256 | 274 |
257 #define EXPECT_GT(left, right) \ | 275 #define EXPECT_GT(left, right) \ |
258 dart::Expect(__FILE__, __LINE__).GreaterThan((left), (right)) | 276 dart::Expect(__FILE__, __LINE__).GreaterThan((left), (right)) |
259 | 277 |
260 #define EXPECT_GE(left, right) \ | 278 #define EXPECT_GE(left, right) \ |
261 dart::Expect(__FILE__, __LINE__).GreaterEqual((left), (right)) | 279 dart::Expect(__FILE__, __LINE__).GreaterEqual((left), (right)) |
262 #endif | 280 #endif |
263 | 281 |
264 // TODO(iposva): provide a better way to get extra info on an EXPECT | 282 // TODO(iposva): provide a better way to get extra info on an EXPECT |
265 // fail - you suggested EXPECT_EQ(expected, actual, msg_format, | 283 // fail - you suggested EXPECT_EQ(expected, actual, msg_format, |
266 // parameters_for_msg...), I quite like the google3 method | 284 // parameters_for_msg...), I quite like the google3 method |
267 // EXPECT_EQ(a, b) << "more stuff here...". (benl). | 285 // EXPECT_EQ(a, b) << "more stuff here...". (benl). |
268 | 286 |
269 #define WARN(error) \ | 287 #define WARN(error) \ |
270 dart::Expect(__FILE__, __LINE__).Fail("%s", error) | 288 dart::Expect(__FILE__, __LINE__).Fail("%s", error) |
271 | 289 |
272 #define WARN1(format, p1) \ | 290 #define WARN1(format, p1) \ |
273 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) | 291 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) |
274 | 292 |
275 #define WARN2(format, p1, p2) \ | 293 #define WARN2(format, p1, p2) \ |
276 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) | 294 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) |
277 | 295 |
278 #endif // VM_ASSERT_H_ | 296 #endif // VM_ASSERT_H_ |
OLD | NEW |