AUnit  0.5.3
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
Assertion.cpp
1 /*
2 MIT License
3 
4 Copyright (c) 2018 Brian T. Park
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #include <Arduino.h> // definition of Print
26 #include "Flash.h"
27 #include "Printer.h"
28 #include "Assertion.h"
29 
30 namespace aunit {
31 
32 using namespace internal;
33 
34 namespace internal {
35 
36 // This can be a template function because it is accessed only through the
37 // various assertXxx() methods. Those assertXxx() methods are explicitly
38 // overloaded for the various types that we want to support.
39 //
40 // Prints something like the following:
41 // Assertion failed: (5) == (6), file Test.ino, line 820.
42 // Assertion passed: (6) == (6), file Test.ino, line 820.
43 template <typename A, typename B>
44 void printAssertionMessage(Print* printer, bool ok, const char* file,
45  uint16_t line, const A& lhs, const char *opName, const B& rhs) {
46 
47  // Don't use F() strings here because flash memory strings are not deduped by
48  // the compiler, so each template instantiation of this method causes a
49  // duplication of all the strings below. See
50  // https://github.com/mmurdoch/arduinounit/issues/70
51  // for more info. Normal (const char*) strings will be deduped by the
52  // compiler/linker.
53  printer->print("Assertion ");
54  printer->print(ok ? "passed" : "failed");
55  printer->print(": (");
56  printer->print(lhs);
57  printer->print(") ");
58  printer->print(opName);
59  printer->print(" (");
60  printer->print(rhs);
61  printer->print(')');
62  // reuse string in MataAssertion::printAssertionTestStatusMessage()
63  printer->print(", file ");
64  printer->print(file);
65  printer->print(", line ");
66  printer->print(line);
67  printer->println('.');
68 }
69 
70 // Special version of (bool, bool) because Arduino Print.h converts
71 // bool into int, which prints out "(1) == (0)", which isn't as useful.
72 // This prints "(true) == (false)".
73 void printAssertionMessage(Print* printer, bool ok, const char* file,
74  uint16_t line, bool lhs, const char *opName, bool rhs) {
75 
76  // Don't use F() strings here. Same reason as above.
77  printer->print("Assertion ");
78  printer->print(ok ? "passed" : "failed");
79  printer->print(": (");
80  printer->print(lhs ? "true" : "false");
81  printer->print(") ");
82  printer->print(opName);
83  printer->print(" (");
84  printer->print(rhs ? "true" : "false");
85  printer->print(')');
86  printer->print(", file ");
87  printer->print(file);
88  printer->print(", line ");
89  printer->print(line);
90  printer->println('.');
91 }
92 
93 // Special version for assertTrue(arg) and assertFalse(arg).
94 // Prints:
95 // "Assertion passed/failed: (arg) is true"
96 // "Assertion passed/failed: (arg) is false"
97 void printAssertionBoolMessage(Print* printer, bool ok, const char* file,
98  uint16_t line, bool arg, bool value) {
99 
100  // Don't use F() strings here. Same reason as above.
101  printer->print("Assertion ");
102  printer->print(ok ? "passed" : "failed");
103  printer->print(": (");
104  printer->print(arg ? "true" : "false");
105  printer->print(") is ");
106  printer->print(value ? "true" : "false");
107  printer->print(", file ");
108  printer->print(file);
109  printer->print(", line ");
110  printer->print(line);
111  printer->println('.');
112 }
113 
114 } // namespace
115 
117  return (ok && isVerbosity(Verbosity::kAssertionPassed)) ||
118  (!ok && isVerbosity(Verbosity::kAssertionFailed));
119 }
120 
121 bool Assertion::assertionBool(const char* file, uint16_t line, bool arg,
122  bool value) {
123  if (isDone()) return false;
124  bool ok = (arg == value);
125  if (isOutputEnabled(ok)) {
126  printAssertionBoolMessage(Printer::getPrinter(), ok, file, line,
127  arg, value);
128  }
129  setPassOrFail(ok);
130  return ok;
131 }
132 
133 bool Assertion::assertion(const char* file, uint16_t line, bool lhs,
134  const char* opName, bool (*op)(bool lhs, bool rhs),
135  bool rhs) {
136  if (isDone()) return false;
137  bool ok = op(lhs, rhs);
138  if (isOutputEnabled(ok)) {
139  printAssertionMessage(Printer::getPrinter(), ok, file, line,
140  lhs, opName, rhs);
141  }
142  setPassOrFail(ok);
143  return ok;
144 }
145 
146 bool Assertion::assertion(const char* file, uint16_t line, char lhs,
147  const char* opName, bool (*op)(char lhs, char rhs),
148  char rhs) {
149  if (isDone()) return false;
150  bool ok = op(lhs, rhs);
151  if (isOutputEnabled(ok)) {
152  printAssertionMessage(Printer::getPrinter(), ok, file, line,
153  lhs, opName, rhs);
154  }
155  setPassOrFail(ok);
156  return ok;
157 }
158 
159 bool Assertion::assertion(const char* file, uint16_t line, int lhs,
160  const char* opName, bool (*op)(int lhs, int rhs),
161  int rhs) {
162  if (isDone()) return false;
163  bool ok = op(lhs, rhs);
164  if (isOutputEnabled(ok)) {
165  printAssertionMessage(Printer::getPrinter(), ok, file, line,
166  lhs, opName, rhs);
167  }
168  setPassOrFail(ok);
169  return ok;
170 }
171 
172 bool Assertion::assertion(const char* file, uint16_t line, unsigned int lhs,
173  const char* opName, bool (*op)(unsigned int lhs, unsigned int rhs),
174  unsigned int rhs) {
175  if (isDone()) return false;
176  bool ok = op(lhs, rhs);
177  if (isOutputEnabled(ok)) {
178  printAssertionMessage(Printer::getPrinter(), ok, file, line,
179  lhs, opName, rhs);
180  }
181  setPassOrFail(ok);
182  return ok;
183 }
184 
185 bool Assertion::assertion(const char* file, uint16_t line, long lhs,
186  const char* opName, bool (*op)(long lhs, long rhs),
187  long rhs) {
188  if (isDone()) return false;
189  bool ok = op(lhs, rhs);
190  if (isOutputEnabled(ok)) {
191  printAssertionMessage(Printer::getPrinter(), ok, file, line,
192  lhs, opName, rhs);
193  }
194  setPassOrFail(ok);
195  return ok;
196 }
197 
198 bool Assertion::assertion(const char* file, uint16_t line, unsigned long lhs,
199  const char* opName, bool (*op)(unsigned long lhs, unsigned long rhs),
200  unsigned long rhs) {
201  if (isDone()) return false;
202  bool ok = op(lhs, rhs);
203  if (isOutputEnabled(ok)) {
204  printAssertionMessage(Printer::getPrinter(), ok, file, line,
205  lhs, opName, rhs);
206  }
207  setPassOrFail(ok);
208  return ok;
209 }
210 
211 bool Assertion::assertion(const char* file, uint16_t line, double lhs,
212  const char* opName, bool (*op)(double lhs, double rhs),
213  double rhs) {
214  if (isDone()) return false;
215  bool ok = op(lhs, rhs);
216  if (isOutputEnabled(ok)) {
217  printAssertionMessage(Printer::getPrinter(), ok, file, line,
218  lhs, opName, rhs);
219  }
220  setPassOrFail(ok);
221  return ok;
222 }
223 
224 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
225  const char* opName, bool (*op)(const char* lhs, const char* rhs),
226  const char* rhs) {
227  if (isDone()) return false;
228  bool ok = op(lhs, rhs);
229  if (isOutputEnabled(ok)) {
230  printAssertionMessage(Printer::getPrinter(), ok, file, line,
231  lhs, opName, rhs);
232  }
233  setPassOrFail(ok);
234  return ok;
235 }
236 
237 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
238  const char *opName, bool (*op)(const char* lhs, const String& rhs),
239  const String& rhs) {
240  if (isDone()) return false;
241  bool ok = op(lhs, rhs);
242  if (isOutputEnabled(ok)) {
243  printAssertionMessage(Printer::getPrinter(), ok, file, line,
244  lhs, opName, rhs);
245  }
246  setPassOrFail(ok);
247  return ok;
248 }
249 
250 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
251  const char *opName,
252  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
253  const __FlashStringHelper* rhs) {
254  if (isDone()) return false;
255  bool ok = op(lhs, rhs);
256  if (isOutputEnabled(ok)) {
257  printAssertionMessage(Printer::getPrinter(), ok, file, line,
258  lhs, opName, rhs);
259  }
260  setPassOrFail(ok);
261  return ok;
262 }
263 
264 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
265  const char *opName, bool (*op)(const String& lhs, const char* rhs),
266  const char* rhs) {
267  if (isDone()) return false;
268  bool ok = op(lhs, rhs);
269  if (isOutputEnabled(ok)) {
270  printAssertionMessage(Printer::getPrinter(), ok, file, line,
271  lhs, opName, rhs);
272  }
273  setPassOrFail(ok);
274  return ok;
275 }
276 
277 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
278  const char *opName, bool (*op)(const String& lhs, const String& rhs),
279  const String& rhs) {
280  if (isDone()) return false;
281  bool ok = op(lhs, rhs);
282  if (isOutputEnabled(ok)) {
283  printAssertionMessage(Printer::getPrinter(), ok, file, line,
284  lhs, opName, rhs);
285  }
286  setPassOrFail(ok);
287  return ok;
288 }
289 
290 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
291  const char *opName,
292  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
293  const __FlashStringHelper* rhs) {
294  if (isDone()) return false;
295  bool ok = op(lhs, rhs);
296  if (isOutputEnabled(ok)) {
297  printAssertionMessage(Printer::getPrinter(), ok, file, line,
298  lhs, opName, rhs);
299  }
300  setPassOrFail(ok);
301  return ok;
302 }
303 
304 bool Assertion::assertion(const char* file, uint16_t line,
305  const __FlashStringHelper* lhs, const char *opName,
306  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
307  const char* rhs) {
308  if (isDone()) return false;
309  bool ok = op(lhs, rhs);
310  if (isOutputEnabled(ok)) {
311  printAssertionMessage(Printer::getPrinter(), ok, file, line,
312  lhs, opName, rhs);
313  }
314  setPassOrFail(ok);
315  return ok;
316 }
317 
318 bool Assertion::assertion(const char* file, uint16_t line,
319  const __FlashStringHelper* lhs, const char *opName,
320  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
321  const String& rhs) {
322  if (isDone()) return false;
323  bool ok = op(lhs, rhs);
324  if (isOutputEnabled(ok)) {
325  printAssertionMessage(Printer::getPrinter(), ok, file, line,
326  lhs, opName, rhs);
327  }
328  setPassOrFail(ok);
329  return ok;
330 }
331 
332 bool Assertion::assertion(const char* file, uint16_t line,
333  const __FlashStringHelper* lhs, const char *opName,
334  bool (*op)(const __FlashStringHelper* lhs, const __FlashStringHelper* rhs),
335  const __FlashStringHelper* rhs) {
336  if (isDone()) return false;
337  bool ok = op(lhs, rhs);
338  if (isOutputEnabled(ok)) {
339  printAssertionMessage(Printer::getPrinter(), ok, file, line,
340  lhs, opName, rhs);
341  }
342  setPassOrFail(ok);
343  return ok;
344 }
345 
346 namespace internal {
347 
348 // Verbose versions of above which accept the string arguments of the
349 // assertXxx() macros, so that the error messages are more verbose.
350 //
351 // Prints something like the following:
352 // Assertion failed: (x=5) == (y=6), file Test.ino, line 820.
353 // Assertion passed: (x=6) == (y=6), file Test.ino, line 820.
354 template <typename A, typename B>
355 void printAssertionMessageVerbose(Print* printer, bool ok, const char* file,
356  uint16_t line, const A& lhs, const __FlashStringHelper* lhsString,
357  const char *opName, const B& rhs, const __FlashStringHelper* rhsString) {
358 
359  // Don't use F() strings here because flash memory strings are not deduped by
360  // the compiler, so each template instantiation of this method causes a
361  // duplication of all the strings below. See
362  // https://github.com/mmurdoch/arduinounit/issues/70
363  // for more info.
364  printer->print("Assertion ");
365  printer->print(ok ? "passed" : "failed");
366  printer->print(": (");
367  printer->print(lhsString);
368  printer->print('=');
369  printer->print(lhs);
370  printer->print(") ");
371  printer->print(opName);
372  printer->print(" (");
373  printer->print(rhsString);
374  printer->print('=');
375  printer->print(rhs);
376  printer->print(')');
377  // reuse string in MataAssertion::printAssertionTestStatusMessage()
378  printer->print(", file ");
379  printer->print(file);
380  printer->print(", line ");
381  printer->print(line);
382  printer->println('.');
383 }
384 
385 // Special version of (bool, bool) because Arduino Print.h converts
386 // bool into int, which prints out "(1) == (0)", which isn't as useful.
387 // This prints "(x=true) == (y=false)".
388 void printAssertionMessageVerbose(Print* printer, bool ok, const char* file,
389  uint16_t line, bool lhs, const __FlashStringHelper* lhsString,
390  const char *opName, bool rhs, const __FlashStringHelper* rhsString) {
391 
392  // Don't use F() strings here. Same reason as above.
393  printer->print("Assertion ");
394  printer->print(ok ? "passed" : "failed");
395  printer->print(": (");
396  printer->print(lhsString);
397  printer->print('=');
398  printer->print(lhs ? "true" : "false");
399  printer->print(") ");
400  printer->print(opName);
401  printer->print(" (");
402  printer->print(rhsString);
403  printer->print('=');
404  printer->print(rhs ? "true" : "false");
405  printer->print(')');
406  printer->print(", file ");
407  printer->print(file);
408  printer->print(", line ");
409  printer->print(line);
410  printer->println('.');
411 }
412 
413 // Special version for assertTrue(arg) and assertFalse(arg).
414 // Prints:
415 // "Assertion passed/failed: (x=arg) is true"
416 // "Assertion passed/failed: (x=arg) is false"
417 void printAssertionBoolMessageVerbose(Print* printer, bool ok, const char* file,
418  uint16_t line, bool arg, const __FlashStringHelper* argString, bool value) {
419 
420  // Don't use F() strings here. Same reason as above.
421  printer->print("Assertion ");
422  printer->print(ok ? "passed" : "failed");
423  printer->print(": (");
424  printer->print(argString);
425  printer->print('=');
426  printer->print(arg ? "true" : "false");
427  printer->print(") is ");
428  printer->print(value ? "true" : "false");
429  printer->print(", file ");
430  printer->print(file);
431  printer->print(", line ");
432  printer->print(line);
433  printer->println('.');
434 }
435 
436 } // namespace
437 
438 bool Assertion::assertionBoolVerbose(const char* file, uint16_t line, bool arg,
439  const __FlashStringHelper* argString, bool value) {
440  if (isDone()) return false;
441  bool ok = (arg == value);
442  if (isOutputEnabled(ok)) {
443  printAssertionBoolMessageVerbose(Printer::getPrinter(), ok, file, line,
444  arg, argString, value);
445  }
446  setPassOrFail(ok);
447  return ok;
448 }
449 
450 bool Assertion::assertionVerbose(const char* file, uint16_t line, bool lhs,
451  const __FlashStringHelper* lhsString, const char* opName,
452  bool (*op)(bool lhs, bool rhs), bool rhs,
453  const __FlashStringHelper* rhsString) {
454  if (isDone()) return false;
455  bool ok = op(lhs, rhs);
456  if (isOutputEnabled(ok)) {
457  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
458  lhs, lhsString, opName, rhs, rhsString);
459  }
460  setPassOrFail(ok);
461  return ok;
462 }
463 
464 bool Assertion::assertionVerbose(const char* file, uint16_t line, char lhs,
465  const __FlashStringHelper* lhsString, const char* opName,
466  bool (*op)(char lhs, char rhs), char rhs,
467  const __FlashStringHelper* rhsString) {
468  if (isDone()) return false;
469  bool ok = op(lhs, rhs);
470  if (isOutputEnabled(ok)) {
471  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
472  lhs, lhsString, opName, rhs, rhsString);
473  }
474  setPassOrFail(ok);
475  return ok;
476 }
477 
478 bool Assertion::assertionVerbose(const char* file, uint16_t line, int lhs,
479  const __FlashStringHelper* lhsString, const char* opName,
480  bool (*op)(int lhs, int rhs), int rhs,
481  const __FlashStringHelper* rhsString) {
482  if (isDone()) return false;
483  bool ok = op(lhs, rhs);
484  if (isOutputEnabled(ok)) {
485  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
486  lhs, lhsString, opName, rhs, rhsString);
487  }
488  setPassOrFail(ok);
489  return ok;
490 }
491 
492 bool Assertion::assertionVerbose(const char* file, uint16_t line,
493  unsigned int lhs, const __FlashStringHelper* lhsString, const char* opName,
494  bool (*op)(unsigned int lhs, unsigned int rhs),
495  unsigned int rhs, const __FlashStringHelper* rhsString) {
496  if (isDone()) return false;
497  bool ok = op(lhs, rhs);
498  if (isOutputEnabled(ok)) {
499  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
500  lhs, lhsString, opName, rhs, rhsString);
501  }
502  setPassOrFail(ok);
503  return ok;
504 }
505 
506 bool Assertion::assertionVerbose(const char* file, uint16_t line, long lhs,
507  const __FlashStringHelper* lhsString, const char* opName,
508  bool (*op)(long lhs, long rhs), long rhs,
509  const __FlashStringHelper* rhsString) {
510  if (isDone()) return false;
511  bool ok = op(lhs, rhs);
512  if (isOutputEnabled(ok)) {
513  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
514  lhs, lhsString, opName, rhs, rhsString);
515  }
516  setPassOrFail(ok);
517  return ok;
518 }
519 
520 bool Assertion::assertionVerbose(const char* file, uint16_t line,
521  unsigned long lhs, const __FlashStringHelper* lhsString, const char* opName,
522  bool (*op)(unsigned long lhs, unsigned long rhs),
523  unsigned long rhs, const __FlashStringHelper* rhsString) {
524  if (isDone()) return false;
525  bool ok = op(lhs, rhs);
526  if (isOutputEnabled(ok)) {
527  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
528  lhs, lhsString, opName, rhs, rhsString);
529  }
530  setPassOrFail(ok);
531  return ok;
532 }
533 
534 bool Assertion::assertionVerbose(const char* file, uint16_t line, double lhs,
535  const __FlashStringHelper* lhsString, const char* opName,
536  bool (*op)(double lhs, double rhs), double rhs,
537  const __FlashStringHelper* rhsString) {
538  if (isDone()) return false;
539  bool ok = op(lhs, rhs);
540  if (isOutputEnabled(ok)) {
541  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
542  lhs, lhsString, opName, rhs, rhsString);
543  }
544  setPassOrFail(ok);
545  return ok;
546 }
547 
548 bool Assertion::assertionVerbose(const char* file, uint16_t line,
549  const char* lhs, const __FlashStringHelper* lhsString, const char* opName,
550  bool (*op)(const char* lhs, const char* rhs),
551  const char* rhs, const __FlashStringHelper* rhsString) {
552  if (isDone()) return false;
553  bool ok = op(lhs, rhs);
554  if (isOutputEnabled(ok)) {
555  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
556  lhs, lhsString, opName, rhs, rhsString);
557  }
558  setPassOrFail(ok);
559  return ok;
560 }
561 
562 bool Assertion::assertionVerbose(const char* file, uint16_t line,
563  const char* lhs, const __FlashStringHelper* lhsString,
564  const char *opName, bool (*op)(const char* lhs, const String& rhs),
565  const String& rhs, const __FlashStringHelper* rhsString) {
566  if (isDone()) return false;
567  bool ok = op(lhs, rhs);
568  if (isOutputEnabled(ok)) {
569  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
570  lhs, lhsString, opName, rhs, rhsString);
571  }
572  setPassOrFail(ok);
573  return ok;
574 }
575 
576 bool Assertion::assertionVerbose(const char* file, uint16_t line,
577  const char* lhs, const __FlashStringHelper* lhsString, const char *opName,
578  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
579  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
580  if (isDone()) return false;
581  bool ok = op(lhs, rhs);
582  if (isOutputEnabled(ok)) {
583  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
584  lhs, lhsString, opName, rhs, rhsString);
585  }
586  setPassOrFail(ok);
587  return ok;
588 }
589 
590 bool Assertion::assertionVerbose(const char* file, uint16_t line,
591  const String& lhs, const __FlashStringHelper* lhsString, const char *opName,
592  bool (*op)(const String& lhs, const char* rhs),
593  const char* rhs, const __FlashStringHelper* rhsString) {
594  if (isDone()) return false;
595  bool ok = op(lhs, rhs);
596  if (isOutputEnabled(ok)) {
597  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
598  lhs, lhsString, opName, rhs, rhsString);
599  }
600  setPassOrFail(ok);
601  return ok;
602 }
603 
604 bool Assertion::assertionVerbose(const char* file, uint16_t line,
605  const String& lhs, const __FlashStringHelper* lhsString, const char *opName,
606  bool (*op)(const String& lhs, const String& rhs),
607  const String& rhs, const __FlashStringHelper* rhsString) {
608  if (isDone()) return false;
609  bool ok = op(lhs, rhs);
610  if (isOutputEnabled(ok)) {
611  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
612  lhs, lhsString, opName, rhs, rhsString);
613  }
614  setPassOrFail(ok);
615  return ok;
616 }
617 
618 bool Assertion::assertionVerbose(const char* file, uint16_t line,
619  const String& lhs, const __FlashStringHelper* lhsString, const char *opName,
620  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
621  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
622  if (isDone()) return false;
623  bool ok = op(lhs, rhs);
624  if (isOutputEnabled(ok)) {
625  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
626  lhs, lhsString, opName, rhs, rhsString);
627  }
628  setPassOrFail(ok);
629  return ok;
630 }
631 
632 bool Assertion::assertionVerbose(const char* file, uint16_t line,
633  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
634  const char *opName,
635  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
636  const char* rhs, const __FlashStringHelper* rhsString) {
637  if (isDone()) return false;
638  bool ok = op(lhs, rhs);
639  if (isOutputEnabled(ok)) {
640  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
641  lhs, lhsString, opName, rhs, rhsString);
642  }
643  setPassOrFail(ok);
644  return ok;
645 }
646 
647 bool Assertion::assertionVerbose(const char* file, uint16_t line,
648  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
649  const char *opName,
650  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
651  const String& rhs, const __FlashStringHelper* rhsString) {
652  if (isDone()) return false;
653  bool ok = op(lhs, rhs);
654  if (isOutputEnabled(ok)) {
655  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
656  lhs, lhsString, opName, rhs, rhsString);
657  }
658  setPassOrFail(ok);
659  return ok;
660 }
661 
662 bool Assertion::assertionVerbose(const char* file, uint16_t line,
663  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
664  const char *opName,
665  bool (*op)(const __FlashStringHelper* lhs, const __FlashStringHelper* rhs),
666  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
667  if (isDone()) return false;
668  bool ok = op(lhs, rhs);
669  if (isOutputEnabled(ok)) {
670  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
671  lhs, lhsString, opName, rhs, rhsString);
672  }
673  setPassOrFail(ok);
674  return ok;
675 }
676 
677 }
bool isOutputEnabled(bool ok)
Returns true if an assertion message should be printed.
Definition: Assertion.cpp:116
static const uint8_t kAssertionPassed
Print assertXxx() passed message.
Definition: Verbosity.h:40
static Print * getPrinter()
Get the output printer used by the various assertion() methods and the TestRunner.
Definition: Printer.h:48
static const uint8_t kAssertionFailed
Print assertXxx() failed message.
Definition: Verbosity.h:43
Various macros to smooth over the differences among the various platforms with regards to their suppo...