Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: runtime/vm/assert.h

Issue 8297004: Allow embedders to provide custom message delivery for an isolate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 21 matching lines...) Expand all
32 32
33 DynamicAssertionHelper(const char* file, int line, Kind kind) 33 DynamicAssertionHelper(const char* file, int line, Kind kind)
34 : file_(file), line_(line), kind_(kind) { } 34 : file_(file), line_(line), kind_(kind) { }
35 35
36 void Fail(const char* format, ...); 36 void Fail(const char* format, ...);
37 37
38 #if defined(TESTING) 38 #if defined(TESTING)
39 template<typename E, typename A> 39 template<typename E, typename A>
40 void Equals(const E& expected, const A& actual); 40 void Equals(const E& expected, const A& actual);
41 41
42 template<typename E, typename A>
43 void NotEquals(const E& not_expected, const A& actual);
44
42 template<typename E, typename A, typename T> 45 template<typename E, typename A, typename T>
43 void FloatEquals(const E& expected, const A& actual, const T& tol); 46 void FloatEquals(const E& expected, const A& actual, const T& tol);
44 47
45 template<typename E, typename A> 48 template<typename E, typename A>
46 void StringEquals(const E& expected, const A& actual); 49 void StringEquals(const E& expected, const A& actual);
47 50
48 template<typename E, typename A> 51 template<typename E, typename A>
49 void LessThan(const E& left, const A& right); 52 void LessThan(const E& left, const A& right);
50 53
51 template<typename E, typename A> 54 template<typename E, typename A>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 void DynamicAssertionHelper::Equals(const E& expected, const A& actual) { 91 void DynamicAssertionHelper::Equals(const E& expected, const A& actual) {
89 if (actual == expected) return; 92 if (actual == expected) return;
90 std::stringstream ess, ass; 93 std::stringstream ess, ass;
91 ess << expected; 94 ess << expected;
92 ass << actual; 95 ass << actual;
93 std::string es = ess.str(), as = ass.str(); 96 std::string es = ess.str(), as = ass.str();
94 Fail("expected: <%s> but was: <%s>", es.c_str(), as.c_str()); 97 Fail("expected: <%s> but was: <%s>", es.c_str(), as.c_str());
95 } 98 }
96 99
97 100
101 template<typename E, typename A>
102 void DynamicAssertionHelper::NotEquals(const E& not_expected,
103 const A& actual) {
104 if (actual != not_expected) return;
105 std::stringstream ness;
106 ness << not_expected;
107 std::string nes = ness.str();
108 Fail("did not expect: <%s>", nes.c_str());
109 }
110
111
98 template<typename E, typename A, typename T> 112 template<typename E, typename A, typename T>
99 void DynamicAssertionHelper::FloatEquals(const E& expected, 113 void DynamicAssertionHelper::FloatEquals(const E& expected,
100 const A& actual, 114 const A& actual,
101 const T& tol) { 115 const T& tol) {
102 if (((expected - tol) <= actual) && (actual <= (expected + tol))) { 116 if (((expected - tol) <= actual) && (actual <= (expected + tol))) {
103 return; 117 return;
104 } 118 }
105 std::stringstream ess, ass, tolss; 119 std::stringstream ess, ass, tolss;
106 ess << expected; 120 ess << expected;
107 ass << actual; 121 ass << actual;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 232
219 #if defined(TESTING) 233 #if defined(TESTING)
220 #define EXPECT(condition) \ 234 #define EXPECT(condition) \
221 if (!(condition)) { \ 235 if (!(condition)) { \
222 dart::Expect(__FILE__, __LINE__).Fail("expected: %s", #condition); \ 236 dart::Expect(__FILE__, __LINE__).Fail("expected: %s", #condition); \
223 } 237 }
224 238
225 #define EXPECT_EQ(expected, actual) \ 239 #define EXPECT_EQ(expected, actual) \
226 dart::Expect(__FILE__, __LINE__).Equals((expected), (actual)) 240 dart::Expect(__FILE__, __LINE__).Equals((expected), (actual))
227 241
242 #define EXPECT_NE(not_expected, actual) \
243 dart::Expect(__FILE__, __LINE__).NotEquals((not_expected), (actual))
244
228 #define EXPECT_FLOAT_EQ(expected, actual, tol) \ 245 #define EXPECT_FLOAT_EQ(expected, actual, tol) \
229 dart::Expect(__FILE__, __LINE__).FloatEquals((expected), (actual), (tol)) 246 dart::Expect(__FILE__, __LINE__).FloatEquals((expected), (actual), (tol))
230 247
231 #define EXPECT_STREQ(expected, actual) \ 248 #define EXPECT_STREQ(expected, actual) \
232 dart::Expect(__FILE__, __LINE__).StringEquals((expected), (actual)) 249 dart::Expect(__FILE__, __LINE__).StringEquals((expected), (actual))
233 250
234 #define EXPECT_LT(left, right) \ 251 #define EXPECT_LT(left, right) \
235 dart::Expect(__FILE__, __LINE__).LessThan((left), (right)) 252 dart::Expect(__FILE__, __LINE__).LessThan((left), (right))
236 253
237 #define EXPECT_LE(left, right) \ 254 #define EXPECT_LE(left, right) \
(...skipping 14 matching lines...) Expand all
252 #define WARN(error) \ 269 #define WARN(error) \
253 dart::Expect(__FILE__, __LINE__).Fail("%s", error) 270 dart::Expect(__FILE__, __LINE__).Fail("%s", error)
254 271
255 #define WARN1(format, p1) \ 272 #define WARN1(format, p1) \
256 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) 273 dart::Expect(__FILE__, __LINE__).Fail(format, (p1))
257 274
258 #define WARN2(format, p1, p2) \ 275 #define WARN2(format, p1, p2) \
259 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) 276 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2))
260 277
261 #endif // VM_ASSERT_H_ 278 #endif // VM_ASSERT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698