AUnit  1.1
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 template <typename A>
115 void printAssertionNearMessage(Print* printer, bool ok, const char* file,
116  uint16_t line, const A& lhs, const A& rhs, const char* opName,
117  const A& error) {
118  printer->print("Assertion ");
119  printer->print(ok ? "passed" : "failed");
120  printer->print(": |(");
121  printer->print(lhs);
122  printer->print(") - (");
123  printer->print(rhs);
124  printer->print(")| ");
125  printer->print(opName);
126  printer->print(" (");
127  printer->print(error);
128  printer->print(')');
129  printer->print(", file ");
130  printer->print(file);
131  printer->print(", line ");
132  printer->print(line);
133  printer->println('.');
134 }
135 
136 } // namespace
137 
139  return (ok && isVerbosity(Verbosity::kAssertionPassed)) ||
140  (!ok && isVerbosity(Verbosity::kAssertionFailed));
141 }
142 
143 bool Assertion::assertionBool(const char* file, uint16_t line, bool arg,
144  bool value) {
145  if (isDone()) return false;
146  bool ok = (arg == value);
147  if (isOutputEnabled(ok)) {
148  printAssertionBoolMessage(Printer::getPrinter(), ok, file, line,
149  arg, value);
150  }
151  setPassOrFail(ok);
152  return ok;
153 }
154 
155 bool Assertion::assertion(const char* file, uint16_t line, bool lhs,
156  const char* opName, bool (*op)(bool lhs, bool rhs),
157  bool rhs) {
158  if (isDone()) return false;
159  bool ok = op(lhs, rhs);
160  if (isOutputEnabled(ok)) {
161  printAssertionMessage(Printer::getPrinter(), ok, file, line,
162  lhs, opName, rhs);
163  }
164  setPassOrFail(ok);
165  return ok;
166 }
167 
168 bool Assertion::assertion(const char* file, uint16_t line, char lhs,
169  const char* opName, bool (*op)(char lhs, char rhs),
170  char rhs) {
171  if (isDone()) return false;
172  bool ok = op(lhs, rhs);
173  if (isOutputEnabled(ok)) {
174  printAssertionMessage(Printer::getPrinter(), ok, file, line,
175  lhs, opName, rhs);
176  }
177  setPassOrFail(ok);
178  return ok;
179 }
180 
181 bool Assertion::assertion(const char* file, uint16_t line, int lhs,
182  const char* opName, bool (*op)(int lhs, int rhs),
183  int rhs) {
184  if (isDone()) return false;
185  bool ok = op(lhs, rhs);
186  if (isOutputEnabled(ok)) {
187  printAssertionMessage(Printer::getPrinter(), ok, file, line,
188  lhs, opName, rhs);
189  }
190  setPassOrFail(ok);
191  return ok;
192 }
193 
194 bool Assertion::assertion(const char* file, uint16_t line, unsigned int lhs,
195  const char* opName, bool (*op)(unsigned int lhs, unsigned int rhs),
196  unsigned int rhs) {
197  if (isDone()) return false;
198  bool ok = op(lhs, rhs);
199  if (isOutputEnabled(ok)) {
200  printAssertionMessage(Printer::getPrinter(), ok, file, line,
201  lhs, opName, rhs);
202  }
203  setPassOrFail(ok);
204  return ok;
205 }
206 
207 bool Assertion::assertion(const char* file, uint16_t line, long lhs,
208  const char* opName, bool (*op)(long lhs, long rhs),
209  long rhs) {
210  if (isDone()) return false;
211  bool ok = op(lhs, rhs);
212  if (isOutputEnabled(ok)) {
213  printAssertionMessage(Printer::getPrinter(), ok, file, line,
214  lhs, opName, rhs);
215  }
216  setPassOrFail(ok);
217  return ok;
218 }
219 
220 bool Assertion::assertion(const char* file, uint16_t line, unsigned long lhs,
221  const char* opName, bool (*op)(unsigned long lhs, unsigned long rhs),
222  unsigned long rhs) {
223  if (isDone()) return false;
224  bool ok = op(lhs, rhs);
225  if (isOutputEnabled(ok)) {
226  printAssertionMessage(Printer::getPrinter(), ok, file, line,
227  lhs, opName, rhs);
228  }
229  setPassOrFail(ok);
230  return ok;
231 }
232 
233 bool Assertion::assertion(const char* file, uint16_t line, double lhs,
234  const char* opName, bool (*op)(double lhs, double rhs),
235  double rhs) {
236  if (isDone()) return false;
237  bool ok = op(lhs, rhs);
238  if (isOutputEnabled(ok)) {
239  printAssertionMessage(Printer::getPrinter(), ok, file, line,
240  lhs, opName, rhs);
241  }
242  setPassOrFail(ok);
243  return ok;
244 }
245 
246 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
247  const char* opName, bool (*op)(const char* lhs, const char* rhs),
248  const char* rhs) {
249  if (isDone()) return false;
250  bool ok = op(lhs, rhs);
251  if (isOutputEnabled(ok)) {
252  printAssertionMessage(Printer::getPrinter(), ok, file, line,
253  lhs, opName, rhs);
254  }
255  setPassOrFail(ok);
256  return ok;
257 }
258 
259 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
260  const char* opName, bool (*op)(const char* lhs, const String& rhs),
261  const String& rhs) {
262  if (isDone()) return false;
263  bool ok = op(lhs, rhs);
264  if (isOutputEnabled(ok)) {
265  printAssertionMessage(Printer::getPrinter(), ok, file, line,
266  lhs, opName, rhs);
267  }
268  setPassOrFail(ok);
269  return ok;
270 }
271 
272 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
273  const char* opName,
274  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
275  const __FlashStringHelper* rhs) {
276  if (isDone()) return false;
277  bool ok = op(lhs, rhs);
278  if (isOutputEnabled(ok)) {
279  printAssertionMessage(Printer::getPrinter(), ok, file, line,
280  lhs, opName, rhs);
281  }
282  setPassOrFail(ok);
283  return ok;
284 }
285 
286 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
287  const char* opName, bool (*op)(const String& lhs, const char* rhs),
288  const char* rhs) {
289  if (isDone()) return false;
290  bool ok = op(lhs, rhs);
291  if (isOutputEnabled(ok)) {
292  printAssertionMessage(Printer::getPrinter(), ok, file, line,
293  lhs, opName, rhs);
294  }
295  setPassOrFail(ok);
296  return ok;
297 }
298 
299 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
300  const char* opName, bool (*op)(const String& lhs, const String& rhs),
301  const String& rhs) {
302  if (isDone()) return false;
303  bool ok = op(lhs, rhs);
304  if (isOutputEnabled(ok)) {
305  printAssertionMessage(Printer::getPrinter(), ok, file, line,
306  lhs, opName, rhs);
307  }
308  setPassOrFail(ok);
309  return ok;
310 }
311 
312 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
313  const char* opName,
314  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
315  const __FlashStringHelper* rhs) {
316  if (isDone()) return false;
317  bool ok = op(lhs, rhs);
318  if (isOutputEnabled(ok)) {
319  printAssertionMessage(Printer::getPrinter(), ok, file, line,
320  lhs, opName, rhs);
321  }
322  setPassOrFail(ok);
323  return ok;
324 }
325 
326 bool Assertion::assertion(const char* file, uint16_t line,
327  const __FlashStringHelper* lhs, const char* opName,
328  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
329  const char* rhs) {
330  if (isDone()) return false;
331  bool ok = op(lhs, rhs);
332  if (isOutputEnabled(ok)) {
333  printAssertionMessage(Printer::getPrinter(), ok, file, line,
334  lhs, opName, rhs);
335  }
336  setPassOrFail(ok);
337  return ok;
338 }
339 
340 bool Assertion::assertion(const char* file, uint16_t line,
341  const __FlashStringHelper* lhs, const char* opName,
342  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
343  const String& rhs) {
344  if (isDone()) return false;
345  bool ok = op(lhs, rhs);
346  if (isOutputEnabled(ok)) {
347  printAssertionMessage(Printer::getPrinter(), ok, file, line,
348  lhs, opName, rhs);
349  }
350  setPassOrFail(ok);
351  return ok;
352 }
353 
354 bool Assertion::assertion(const char* file, uint16_t line,
355  const __FlashStringHelper* lhs, const char* opName,
356  bool (*op)(const __FlashStringHelper* lhs, const __FlashStringHelper* rhs),
357  const __FlashStringHelper* rhs) {
358  if (isDone()) return false;
359  bool ok = op(lhs, rhs);
360  if (isOutputEnabled(ok)) {
361  printAssertionMessage(Printer::getPrinter(), ok, file, line,
362  lhs, opName, rhs);
363  }
364  setPassOrFail(ok);
365  return ok;
366 }
367 
368 bool Assertion::assertionNear(const char* file, uint16_t line,
369  int lhs, int rhs, int error, const char* opName,
370  bool (*opNear)(int lhs, int rhs, int error)) {
371  if (isDone()) return false;
372  bool ok = opNear(lhs, rhs, error);
373  if (isOutputEnabled(ok)) {
374  printAssertionNearMessage(Printer::getPrinter(), ok, file, line,
375  lhs, rhs, opName, error);
376  }
377  setPassOrFail(ok);
378  return ok;
379 }
380 
381 bool Assertion::assertionNear(const char* file, uint16_t line,
382  unsigned int lhs, unsigned int rhs, unsigned int error, const char* opName,
383  bool (*opNear)(unsigned int lhs, unsigned int rhs, unsigned int error)) {
384  if (isDone()) return false;
385  bool ok = opNear(lhs, rhs, error);
386  if (isOutputEnabled(ok)) {
387  printAssertionNearMessage(Printer::getPrinter(), ok, file, line,
388  lhs, rhs, opName, error);
389  }
390  setPassOrFail(ok);
391  return ok;
392 }
393 
394 bool Assertion::assertionNear(const char* file, uint16_t line,
395  long lhs, long rhs, long error, const char* opName,
396  bool (*opNear)(long lhs, long rhs, long error)) {
397  if (isDone()) return false;
398  bool ok = opNear(lhs, rhs, error);
399  if (isOutputEnabled(ok)) {
400  printAssertionNearMessage(Printer::getPrinter(), ok, file, line,
401  lhs, rhs, opName, error);
402  }
403  setPassOrFail(ok);
404  return ok;
405 }
406 
407 bool Assertion::assertionNear(const char* file, uint16_t line,
408  unsigned long lhs, unsigned long rhs, unsigned long error,
409  const char* opName,
410  bool (*opNear)(unsigned long lhs, unsigned long rhs, unsigned long error)) {
411  if (isDone()) return false;
412  bool ok = opNear(lhs, rhs, error);
413  if (isOutputEnabled(ok)) {
414  printAssertionNearMessage(Printer::getPrinter(), ok, file, line,
415  lhs, rhs, opName, error);
416  }
417  setPassOrFail(ok);
418  return ok;
419 }
420 
421 bool Assertion::assertionNear(const char* file, uint16_t line,
422  double lhs, double rhs, double error, const char* opName,
423  bool (*opNear)(double lhs, double rhs, double error)) {
424  if (isDone()) return false;
425  bool ok = opNear(lhs, rhs, error);
426  if (isOutputEnabled(ok)) {
427  printAssertionNearMessage(Printer::getPrinter(), ok, file, line,
428  lhs, rhs, opName, error);
429  }
430  setPassOrFail(ok);
431  return ok;
432 }
433 
434 //---------------------------------------------------------------------------
435 
436 namespace internal {
437 
438 // Verbose versions of above which accept the string arguments of the
439 // assertXxx() macros, so that the error messages are more verbose.
440 //
441 // Prints something like the following:
442 // Assertion failed: (x=5) == (y=6), file Test.ino, line 820.
443 // Assertion passed: (x=6) == (y=6), file Test.ino, line 820.
444 template <typename A, typename B>
445 void printAssertionMessageVerbose(Print* printer, bool ok, const char* file,
446  uint16_t line, const A& lhs, const __FlashStringHelper* lhsString,
447  const char* opName, const B& rhs, const __FlashStringHelper* rhsString) {
448 
449  // Don't use F() strings here because flash memory strings are not deduped by
450  // the compiler, so each template instantiation of this method causes a
451  // duplication of all the strings below. See
452  // https://github.com/mmurdoch/arduinounit/issues/70
453  // for more info.
454  printer->print("Assertion ");
455  printer->print(ok ? "passed" : "failed");
456  printer->print(": (");
457  printer->print(lhsString);
458  printer->print('=');
459  printer->print(lhs);
460  printer->print(") ");
461  printer->print(opName);
462  printer->print(" (");
463  printer->print(rhsString);
464  printer->print('=');
465  printer->print(rhs);
466  printer->print(')');
467  // reuse string in MataAssertion::printAssertionTestStatusMessage()
468  printer->print(", file ");
469  printer->print(file);
470  printer->print(", line ");
471  printer->print(line);
472  printer->println('.');
473 }
474 
475 // Special version of (bool, bool) because Arduino Print.h converts
476 // bool into int, which prints out "(1) == (0)", which isn't as useful.
477 // This prints "(x=true) == (y=false)".
478 void printAssertionMessageVerbose(Print* printer, bool ok, const char* file,
479  uint16_t line, bool lhs, const __FlashStringHelper* lhsString,
480  const char* opName, bool rhs, const __FlashStringHelper* rhsString) {
481 
482  // Don't use F() strings here. Same reason as above.
483  printer->print("Assertion ");
484  printer->print(ok ? "passed" : "failed");
485  printer->print(": (");
486  printer->print(lhsString);
487  printer->print('=');
488  printer->print(lhs ? "true" : "false");
489  printer->print(") ");
490  printer->print(opName);
491  printer->print(" (");
492  printer->print(rhsString);
493  printer->print('=');
494  printer->print(rhs ? "true" : "false");
495  printer->print(')');
496  printer->print(", file ");
497  printer->print(file);
498  printer->print(", line ");
499  printer->print(line);
500  printer->println('.');
501 }
502 
503 // Special version for assertTrue(arg) and assertFalse(arg).
504 // Prints:
505 // "Assertion passed/failed: (x=arg) is true"
506 // "Assertion passed/failed: (x=arg) is false"
507 void printAssertionBoolMessageVerbose(Print* printer, bool ok, const char* file,
508  uint16_t line, bool arg, const __FlashStringHelper* argString, bool value) {
509 
510  // Don't use F() strings here. Same reason as above.
511  printer->print("Assertion ");
512  printer->print(ok ? "passed" : "failed");
513  printer->print(": (");
514  printer->print(argString);
515  printer->print('=');
516  printer->print(arg ? "true" : "false");
517  printer->print(") is ");
518  printer->print(value ? "true" : "false");
519  printer->print(", file ");
520  printer->print(file);
521  printer->print(", line ");
522  printer->print(line);
523  printer->println('.');
524 }
525 
526 template <typename A>
527 void printAssertionNearMessageVerbose(Print* printer, bool ok, const char* file,
528  uint16_t line, const A& lhs, const __FlashStringHelper* lhsString,
529  const A& rhs, const __FlashStringHelper* rhsString,
530  const char* opName,
531  const A& error, const __FlashStringHelper* errorString) {
532  printer->print("Assertion ");
533  printer->print(ok ? "passed" : "failed");
534  printer->print(": |(");
535  printer->print(lhsString);
536  printer->print('=');
537  printer->print(lhs);
538  printer->print(") - (");
539  printer->print(rhsString);
540  printer->print('=');
541  printer->print(rhs);
542  printer->print(")| ");
543  printer->print(opName);
544  printer->print(" (");
545  printer->print(errorString);
546  printer->print('=');
547  printer->print(error);
548  printer->print(')');
549  printer->print(", file ");
550  printer->print(file);
551  printer->print(", line ");
552  printer->print(line);
553  printer->println('.');
554 }
555 
556 } // namespace
557 
558 bool Assertion::assertionBoolVerbose(const char* file, uint16_t line, bool arg,
559  const __FlashStringHelper* argString, bool value) {
560  if (isDone()) return false;
561  bool ok = (arg == value);
562  if (isOutputEnabled(ok)) {
563  printAssertionBoolMessageVerbose(Printer::getPrinter(), ok, file, line,
564  arg, argString, value);
565  }
566  setPassOrFail(ok);
567  return ok;
568 }
569 
570 bool Assertion::assertionVerbose(const char* file, uint16_t line, bool lhs,
571  const __FlashStringHelper* lhsString, const char* opName,
572  bool (*op)(bool lhs, bool rhs), bool rhs,
573  const __FlashStringHelper* rhsString) {
574  if (isDone()) return false;
575  bool ok = op(lhs, rhs);
576  if (isOutputEnabled(ok)) {
577  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
578  lhs, lhsString, opName, rhs, rhsString);
579  }
580  setPassOrFail(ok);
581  return ok;
582 }
583 
584 bool Assertion::assertionVerbose(const char* file, uint16_t line, char lhs,
585  const __FlashStringHelper* lhsString, const char* opName,
586  bool (*op)(char lhs, char rhs), char rhs,
587  const __FlashStringHelper* rhsString) {
588  if (isDone()) return false;
589  bool ok = op(lhs, rhs);
590  if (isOutputEnabled(ok)) {
591  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
592  lhs, lhsString, opName, rhs, rhsString);
593  }
594  setPassOrFail(ok);
595  return ok;
596 }
597 
598 bool Assertion::assertionVerbose(const char* file, uint16_t line, int lhs,
599  const __FlashStringHelper* lhsString, const char* opName,
600  bool (*op)(int lhs, int rhs), int rhs,
601  const __FlashStringHelper* rhsString) {
602  if (isDone()) return false;
603  bool ok = op(lhs, rhs);
604  if (isOutputEnabled(ok)) {
605  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
606  lhs, lhsString, opName, rhs, rhsString);
607  }
608  setPassOrFail(ok);
609  return ok;
610 }
611 
612 bool Assertion::assertionVerbose(const char* file, uint16_t line,
613  unsigned int lhs, const __FlashStringHelper* lhsString, const char* opName,
614  bool (*op)(unsigned int lhs, unsigned int rhs),
615  unsigned int rhs, const __FlashStringHelper* rhsString) {
616  if (isDone()) return false;
617  bool ok = op(lhs, rhs);
618  if (isOutputEnabled(ok)) {
619  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
620  lhs, lhsString, opName, rhs, rhsString);
621  }
622  setPassOrFail(ok);
623  return ok;
624 }
625 
626 bool Assertion::assertionVerbose(const char* file, uint16_t line, long lhs,
627  const __FlashStringHelper* lhsString, const char* opName,
628  bool (*op)(long lhs, long rhs), long rhs,
629  const __FlashStringHelper* rhsString) {
630  if (isDone()) return false;
631  bool ok = op(lhs, rhs);
632  if (isOutputEnabled(ok)) {
633  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
634  lhs, lhsString, opName, rhs, rhsString);
635  }
636  setPassOrFail(ok);
637  return ok;
638 }
639 
640 bool Assertion::assertionVerbose(const char* file, uint16_t line,
641  unsigned long lhs, const __FlashStringHelper* lhsString, const char* opName,
642  bool (*op)(unsigned long lhs, unsigned long rhs),
643  unsigned long rhs, const __FlashStringHelper* rhsString) {
644  if (isDone()) return false;
645  bool ok = op(lhs, rhs);
646  if (isOutputEnabled(ok)) {
647  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
648  lhs, lhsString, opName, rhs, rhsString);
649  }
650  setPassOrFail(ok);
651  return ok;
652 }
653 
654 bool Assertion::assertionVerbose(const char* file, uint16_t line, double lhs,
655  const __FlashStringHelper* lhsString, const char* opName,
656  bool (*op)(double lhs, double rhs), double rhs,
657  const __FlashStringHelper* rhsString) {
658  if (isDone()) return false;
659  bool ok = op(lhs, rhs);
660  if (isOutputEnabled(ok)) {
661  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
662  lhs, lhsString, opName, rhs, rhsString);
663  }
664  setPassOrFail(ok);
665  return ok;
666 }
667 
668 bool Assertion::assertionVerbose(const char* file, uint16_t line,
669  const char* lhs, const __FlashStringHelper* lhsString, const char* opName,
670  bool (*op)(const char* lhs, const char* rhs),
671  const char* rhs, const __FlashStringHelper* rhsString) {
672  if (isDone()) return false;
673  bool ok = op(lhs, rhs);
674  if (isOutputEnabled(ok)) {
675  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
676  lhs, lhsString, opName, rhs, rhsString);
677  }
678  setPassOrFail(ok);
679  return ok;
680 }
681 
682 bool Assertion::assertionVerbose(const char* file, uint16_t line,
683  const char* lhs, const __FlashStringHelper* lhsString,
684  const char* opName, bool (*op)(const char* lhs, const String& rhs),
685  const String& rhs, const __FlashStringHelper* rhsString) {
686  if (isDone()) return false;
687  bool ok = op(lhs, rhs);
688  if (isOutputEnabled(ok)) {
689  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
690  lhs, lhsString, opName, rhs, rhsString);
691  }
692  setPassOrFail(ok);
693  return ok;
694 }
695 
696 bool Assertion::assertionVerbose(const char* file, uint16_t line,
697  const char* lhs, const __FlashStringHelper* lhsString, const char* opName,
698  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
699  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
700  if (isDone()) return false;
701  bool ok = op(lhs, rhs);
702  if (isOutputEnabled(ok)) {
703  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
704  lhs, lhsString, opName, rhs, rhsString);
705  }
706  setPassOrFail(ok);
707  return ok;
708 }
709 
710 bool Assertion::assertionVerbose(const char* file, uint16_t line,
711  const String& lhs, const __FlashStringHelper* lhsString, const char* opName,
712  bool (*op)(const String& lhs, const char* rhs),
713  const char* rhs, const __FlashStringHelper* rhsString) {
714  if (isDone()) return false;
715  bool ok = op(lhs, rhs);
716  if (isOutputEnabled(ok)) {
717  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
718  lhs, lhsString, opName, rhs, rhsString);
719  }
720  setPassOrFail(ok);
721  return ok;
722 }
723 
724 bool Assertion::assertionVerbose(const char* file, uint16_t line,
725  const String& lhs, const __FlashStringHelper* lhsString, const char* opName,
726  bool (*op)(const String& lhs, const String& rhs),
727  const String& rhs, const __FlashStringHelper* rhsString) {
728  if (isDone()) return false;
729  bool ok = op(lhs, rhs);
730  if (isOutputEnabled(ok)) {
731  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
732  lhs, lhsString, opName, rhs, rhsString);
733  }
734  setPassOrFail(ok);
735  return ok;
736 }
737 
738 bool Assertion::assertionVerbose(const char* file, uint16_t line,
739  const String& lhs, const __FlashStringHelper* lhsString, const char* opName,
740  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
741  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
742  if (isDone()) return false;
743  bool ok = op(lhs, rhs);
744  if (isOutputEnabled(ok)) {
745  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
746  lhs, lhsString, opName, rhs, rhsString);
747  }
748  setPassOrFail(ok);
749  return ok;
750 }
751 
752 bool Assertion::assertionVerbose(const char* file, uint16_t line,
753  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
754  const char* opName,
755  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
756  const char* rhs, const __FlashStringHelper* rhsString) {
757  if (isDone()) return false;
758  bool ok = op(lhs, rhs);
759  if (isOutputEnabled(ok)) {
760  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
761  lhs, lhsString, opName, rhs, rhsString);
762  }
763  setPassOrFail(ok);
764  return ok;
765 }
766 
767 bool Assertion::assertionVerbose(const char* file, uint16_t line,
768  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
769  const char* opName,
770  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
771  const String& rhs, const __FlashStringHelper* rhsString) {
772  if (isDone()) return false;
773  bool ok = op(lhs, rhs);
774  if (isOutputEnabled(ok)) {
775  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
776  lhs, lhsString, opName, rhs, rhsString);
777  }
778  setPassOrFail(ok);
779  return ok;
780 }
781 
782 bool Assertion::assertionVerbose(const char* file, uint16_t line,
783  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
784  const char* opName,
785  bool (*op)(const __FlashStringHelper* lhs, const __FlashStringHelper* rhs),
786  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
787  if (isDone()) return false;
788  bool ok = op(lhs, rhs);
789  if (isOutputEnabled(ok)) {
790  printAssertionMessageVerbose(Printer::getPrinter(), ok, file, line,
791  lhs, lhsString, opName, rhs, rhsString);
792  }
793  setPassOrFail(ok);
794  return ok;
795 }
796 
797 bool Assertion::assertionNearVerbose(const char* file, uint16_t line,
798  int lhs, const __FlashStringHelper* lhsString,
799  int rhs, const __FlashStringHelper* rhsString,
800  int error, const __FlashStringHelper* errorString,
801  const char* opName,
802  bool (*opNear)(int lhs, int rhs, int error)) {
803  if (isDone()) return false;
804  bool ok = opNear(lhs, rhs, error);
805  if (isOutputEnabled(ok)) {
806  printAssertionNearMessageVerbose(Printer::getPrinter(), ok, file, line,
807  lhs, lhsString, rhs, rhsString, opName, error, errorString);
808  }
809  setPassOrFail(ok);
810  return ok;
811 }
812 
813 bool Assertion::assertionNearVerbose(const char* file, uint16_t line,
814  unsigned int lhs, const __FlashStringHelper* lhsString,
815  unsigned int rhs, const __FlashStringHelper* rhsString,
816  unsigned int error, const __FlashStringHelper* errorString,
817  const char* opName,
818  bool (*opNear)(unsigned int lhs, unsigned int rhs, unsigned int error)) {
819  if (isDone()) return false;
820  bool ok = opNear(lhs, rhs, error);
821  if (isOutputEnabled(ok)) {
822  printAssertionNearMessageVerbose(Printer::getPrinter(), ok, file, line,
823  lhs, lhsString, rhs, rhsString, opName, error, errorString);
824  }
825  setPassOrFail(ok);
826  return ok;
827 }
828 
829 bool Assertion::assertionNearVerbose(const char* file, uint16_t line,
830  long lhs, const __FlashStringHelper* lhsString,
831  long rhs, const __FlashStringHelper* rhsString,
832  long error, const __FlashStringHelper* errorString,
833  const char* opName,
834  bool (*opNear)(long lhs, long rhs, long error)) {
835  if (isDone()) return false;
836  bool ok = opNear(lhs, rhs, error);
837  if (isOutputEnabled(ok)) {
838  printAssertionNearMessageVerbose(Printer::getPrinter(), ok, file, line,
839  lhs, lhsString, rhs, rhsString, opName, error, errorString);
840  }
841  setPassOrFail(ok);
842  return ok;
843 }
844 
845 bool Assertion::assertionNearVerbose(const char* file, uint16_t line,
846  unsigned long lhs, const __FlashStringHelper* lhsString,
847  unsigned long rhs, const __FlashStringHelper* rhsString,
848  unsigned long error, const __FlashStringHelper* errorString,
849  const char* opName,
850  bool (*opNear)(unsigned long lhs, unsigned long rhs, unsigned long error)) {
851  if (isDone()) return false;
852  bool ok = opNear(lhs, rhs, error);
853  if (isOutputEnabled(ok)) {
854  printAssertionNearMessageVerbose(Printer::getPrinter(), ok, file, line,
855  lhs, lhsString, rhs, rhsString, opName, error, errorString);
856  }
857  setPassOrFail(ok);
858  return ok;
859 }
860 
861 bool Assertion::assertionNearVerbose(const char* file, uint16_t line,
862  double lhs, const __FlashStringHelper* lhsString,
863  double rhs, const __FlashStringHelper* rhsString,
864  double error, const __FlashStringHelper* errorString,
865  const char* opName,
866  bool (*opNear)(double lhs, double rhs, double error)) {
867  if (isDone()) return false;
868  bool ok = opNear(lhs, rhs, error);
869  if (isOutputEnabled(ok)) {
870  printAssertionNearMessageVerbose(Printer::getPrinter(), ok, file, line,
871  lhs, lhsString, rhs, rhsString, opName, error, errorString);
872  }
873  setPassOrFail(ok);
874  return ok;
875 }
876 
877 }
bool isOutputEnabled(bool ok)
Returns true if an assertion message should be printed.
Definition: Assertion.cpp:138
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...