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

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

Issue 10828317: Use output-only string streams instead of input-output string streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | runtime/platform/assert.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 : DynamicAssertionHelper(file, line, EXPECT) { } 92 : DynamicAssertionHelper(file, line, EXPECT) { }
93 }; 93 };
94 94
95 95
96 #if defined(TESTING) 96 #if defined(TESTING)
97 // Only allow the expensive (with respect to code size) assertions 97 // Only allow the expensive (with respect to code size) assertions
98 // in testing code. 98 // in testing code.
99 template<typename E, typename A> 99 template<typename E, typename A>
100 void DynamicAssertionHelper::Equals(const E& expected, const A& actual) { 100 void DynamicAssertionHelper::Equals(const E& expected, const A& actual) {
101 if (actual == expected) return; 101 if (actual == expected) return;
102 std::stringstream ess, ass; 102 std::ostringstream ess, ass;
103 ess << expected; 103 ess << expected;
104 ass << actual; 104 ass << actual;
105 std::string es = ess.str(), as = ass.str(); 105 std::string es = ess.str(), as = ass.str();
106 Fail("expected: <%s> but was: <%s>", es.c_str(), as.c_str()); 106 Fail("expected: <%s> but was: <%s>", es.c_str(), as.c_str());
107 } 107 }
108 108
109 109
110 template<typename E, typename A> 110 template<typename E, typename A>
111 void DynamicAssertionHelper::NotEquals(const E& not_expected, 111 void DynamicAssertionHelper::NotEquals(const E& not_expected,
112 const A& actual) { 112 const A& actual) {
113 if (actual != not_expected) return; 113 if (actual != not_expected) return;
114 std::stringstream ness; 114 std::ostringstream ness;
115 ness << not_expected; 115 ness << not_expected;
116 std::string nes = ness.str(); 116 std::string nes = ness.str();
117 Fail("did not expect: <%s>", nes.c_str()); 117 Fail("did not expect: <%s>", nes.c_str());
118 } 118 }
119 119
120 120
121 template<typename E, typename A, typename T> 121 template<typename E, typename A, typename T>
122 void DynamicAssertionHelper::FloatEquals(const E& expected, 122 void DynamicAssertionHelper::FloatEquals(const E& expected,
123 const A& actual, 123 const A& actual,
124 const T& tol) { 124 const T& tol) {
125 if (((expected - tol) <= actual) && (actual <= (expected + tol))) { 125 if (((expected - tol) <= actual) && (actual <= (expected + tol))) {
126 return; 126 return;
127 } 127 }
128 std::stringstream ess, ass, tolss; 128 std::ostringstream ess, ass, tolss;
129 ess << expected; 129 ess << expected;
130 ass << actual; 130 ass << actual;
131 tolss << tol; 131 tolss << tol;
132 std::string es = ess.str(), as = ass.str(), tols = tolss.str(); 132 std::string es = ess.str(), as = ass.str(), tols = tolss.str();
133 Fail("expected: <%s> but was: <%s> (tolerance: <%s>)", 133 Fail("expected: <%s> but was: <%s> (tolerance: <%s>)",
134 es.c_str(), 134 es.c_str(),
135 as.c_str(), 135 as.c_str(),
136 tols.c_str()); 136 tols.c_str());
137 } 137 }
138 138
139 139
140 template<typename E, typename A> 140 template<typename E, typename A>
141 void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) { 141 void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) {
142 std::stringstream ess, ass; 142 std::ostringstream ess, ass;
143 ess << expected; 143 ess << expected;
144 ass << actual; 144 ass << actual;
145 std::string es = ess.str(), as = ass.str(); 145 std::string es = ess.str(), as = ass.str();
146 if (as == es) return; 146 if (as == es) return;
147 Fail("expected: <\"%s\"> but was: <\"%s\">", es.c_str(), as.c_str()); 147 Fail("expected: <\"%s\"> but was: <\"%s\">", es.c_str(), as.c_str());
148 } 148 }
149 149
150 150
151 template<typename E, typename A> 151 template<typename E, typename A>
152 void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) { 152 void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) {
153 std::stringstream ess, ass; 153 std::ostringstream ess, ass;
154 ess << needle; 154 ess << needle;
155 ass << haystack; 155 ass << haystack;
156 std::string es = ess.str(), as = ass.str(); 156 std::string es = ess.str(), as = ass.str();
157 if (as.find(es) != std::string::npos) return; 157 if (as.find(es) != std::string::npos) return;
158 Fail("expected <\"%s\"> to be a substring of <\"%s\">", 158 Fail("expected <\"%s\"> to be a substring of <\"%s\">",
159 es.c_str(), as.c_str()); 159 es.c_str(), as.c_str());
160 } 160 }
161 161
162 162
163 template<typename E, typename A> 163 template<typename E, typename A>
164 void DynamicAssertionHelper::IsNotSubstring(const E& needle, 164 void DynamicAssertionHelper::IsNotSubstring(const E& needle,
165 const A& haystack) { 165 const A& haystack) {
166 std::stringstream ess, ass; 166 std::ostringstream ess, ass;
167 ess << needle; 167 ess << needle;
168 ass << haystack; 168 ass << haystack;
169 std::string es = ess.str(), as = ass.str(); 169 std::string es = ess.str(), as = ass.str();
170 if (as.find(es) == std::string::npos) return; 170 if (as.find(es) == std::string::npos) return;
171 Fail("expected <\"%s\"> to not be a substring of <\"%s\">", 171 Fail("expected <\"%s\"> to not be a substring of <\"%s\">",
172 es.c_str(), as.c_str()); 172 es.c_str(), as.c_str());
173 } 173 }
174 174
175 175
176 template<typename E, typename A> 176 template<typename E, typename A>
177 void DynamicAssertionHelper::LessThan(const E& left, const A& right) { 177 void DynamicAssertionHelper::LessThan(const E& left, const A& right) {
178 if (left < right) return; 178 if (left < right) return;
179 std::stringstream ess, ass; 179 std::ostringstream ess, ass;
180 ess << left; 180 ess << left;
181 ass << right; 181 ass << right;
182 std::string es = ess.str(), as = ass.str(); 182 std::string es = ess.str(), as = ass.str();
183 Fail("expected: %s < %s", es.c_str(), as.c_str()); 183 Fail("expected: %s < %s", es.c_str(), as.c_str());
184 } 184 }
185 185
186 186
187 template<typename E, typename A> 187 template<typename E, typename A>
188 void DynamicAssertionHelper::LessEqual(const E& left, const A& right) { 188 void DynamicAssertionHelper::LessEqual(const E& left, const A& right) {
189 if (left <= right) return; 189 if (left <= right) return;
190 std::stringstream ess, ass; 190 std::ostringstream ess, ass;
191 ess << left; 191 ess << left;
192 ass << right; 192 ass << right;
193 std::string es = ess.str(), as = ass.str(); 193 std::string es = ess.str(), as = ass.str();
194 Fail("expected: %s <= %s", es.c_str(), as.c_str()); 194 Fail("expected: %s <= %s", es.c_str(), as.c_str());
195 } 195 }
196 196
197 197
198 template<typename E, typename A> 198 template<typename E, typename A>
199 void DynamicAssertionHelper::GreaterThan(const E& left, const A& right) { 199 void DynamicAssertionHelper::GreaterThan(const E& left, const A& right) {
200 if (left > right) return; 200 if (left > right) return;
201 std::stringstream ess, ass; 201 std::ostringstream ess, ass;
202 ess << left; 202 ess << left;
203 ass << right; 203 ass << right;
204 std::string es = ess.str(), as = ass.str(); 204 std::string es = ess.str(), as = ass.str();
205 Fail("expected: %s > %s", es.c_str(), as.c_str()); 205 Fail("expected: %s > %s", es.c_str(), as.c_str());
206 } 206 }
207 207
208 208
209 template<typename E, typename A> 209 template<typename E, typename A>
210 void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) { 210 void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) {
211 if (left >= right) return; 211 if (left >= right) return;
212 std::stringstream ess, ass; 212 std::ostringstream ess, ass;
213 ess << left; 213 ess << left;
214 ass << right; 214 ass << right;
215 std::string es = ess.str(), as = ass.str(); 215 std::string es = ess.str(), as = ass.str();
216 Fail("expected: %s >= %s", es.c_str(), as.c_str()); 216 Fail("expected: %s >= %s", es.c_str(), as.c_str());
217 } 217 }
218 218
219 219
220 template<typename T> 220 template<typename T>
221 void DynamicAssertionHelper::NotNull(const T p) { 221 void DynamicAssertionHelper::NotNull(const T p) {
222 if (p != NULL) return; 222 if (p != NULL) return;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 #define WARN(error) \ 342 #define WARN(error) \
343 dart::Expect(__FILE__, __LINE__).Fail("%s", error) 343 dart::Expect(__FILE__, __LINE__).Fail("%s", error)
344 344
345 #define WARN1(format, p1) \ 345 #define WARN1(format, p1) \
346 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) 346 dart::Expect(__FILE__, __LINE__).Fail(format, (p1))
347 347
348 #define WARN2(format, p1, p2) \ 348 #define WARN2(format, p1, p2) \
349 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) 349 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2))
350 350
351 #endif // PLATFORM_ASSERT_H_ 351 #endif // PLATFORM_ASSERT_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/platform/assert.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698