AUnit  0.5.2
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 namespace {
33 
34 // This can be a template function because it is accessed only through the
35 // various assertXxx() methods. Those assertXxx() methods are explicitly
36 // overloaded for the various types that we want to support.
37 //
38 // Prints something like the following:
39 // Assertion failed: (5) == (6), file Test.ino, line 820.
40 // Assertion passed: (6) == (6), file Test.ino, line 820.
41 template <typename A, typename B>
42 void printAssertionMessage(bool ok, const char* file, uint16_t line,
43  const A& lhs, const char *opName, const B& rhs) {
44 
45  // Don't use F() strings here because flash memory strings are not deduped by
46  // the compiler, so each template instantiation of this method causes a
47  // duplication of all the strings below. See
48  // https://github.com/mmurdoch/arduinounit/issues/70
49  // for more info. Normal (const char*) strings will be deduped by the
50  // compiler/linker.
51  Print* printer = Printer::getPrinter();
52  printer->print("Assertion ");
53  printer->print(ok ? "passed" : "failed");
54  printer->print(": (");
55  printer->print(lhs);
56  printer->print(") ");
57  printer->print(opName);
58  printer->print(" (");
59  printer->print(rhs);
60  printer->print(')');
61  // reuse string in MataAssertion::printAssertionTestStatusMessage()
62  printer->print(", file ");
63  printer->print(file);
64  printer->print(", line ");
65  printer->print(line);
66  printer->println('.');
67 }
68 
69 // Special version of (bool, bool) because Arduino Print.h converts
70 // bool into int, which prints out "(1) == (0)", which isn't as useful.
71 // This prints "(true) == (false)".
72 void printAssertionMessage(bool ok, const char* file, uint16_t line,
73  bool lhs, const char *opName, bool rhs) {
74 
75  // Don't use F() strings here. Same reason as above.
76  Print* printer = Printer::getPrinter();
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(bool ok, const char* file, uint16_t line,
98  bool arg, bool value) {
99 
100  // Don't use F() strings here. Same reason as above.
101  Print* printer = Printer::getPrinter();
102  printer->print("Assertion ");
103  printer->print(ok ? "passed" : "failed");
104  printer->print(": (");
105  printer->print(arg ? "true" : "false");
106  printer->print(") is ");
107  printer->print(value ? "true" : "false");
108  printer->print(", file ");
109  printer->print(file);
110  printer->print(", line ");
111  printer->print(line);
112  printer->println('.');
113 }
114 
115 } // namespace
116 
118  return (ok && isVerbosity(Verbosity::kAssertionPassed)) ||
120 }
121 
122 bool Assertion::assertionBool(const char* file, uint16_t line, bool arg,
123  bool value) {
124  if (isDone()) return false;
125  bool ok = (arg == value);
126  if (isOutputEnabled(ok)) {
127  printAssertionBoolMessage(ok, file, line, 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(ok, file, line, lhs, opName, rhs);
140  }
141  setPassOrFail(ok);
142  return ok;
143 }
144 
145 bool Assertion::assertion(const char* file, uint16_t line, char lhs,
146  const char* opName, bool (*op)(char lhs, char rhs),
147  char rhs) {
148  if (isDone()) return false;
149  bool ok = op(lhs, rhs);
150  if (isOutputEnabled(ok)) {
151  printAssertionMessage(ok, file, line, lhs, opName, rhs);
152  }
153  setPassOrFail(ok);
154  return ok;
155 }
156 
157 bool Assertion::assertion(const char* file, uint16_t line, int lhs,
158  const char* opName, bool (*op)(int lhs, int rhs),
159  int rhs) {
160  if (isDone()) return false;
161  bool ok = op(lhs, rhs);
162  if (isOutputEnabled(ok)) {
163  printAssertionMessage(ok, file, line, lhs, opName, rhs);
164  }
165  setPassOrFail(ok);
166  return ok;
167 }
168 
169 bool Assertion::assertion(const char* file, uint16_t line, unsigned int lhs,
170  const char* opName, bool (*op)(unsigned int lhs, unsigned int rhs),
171  unsigned int rhs) {
172  if (isDone()) return false;
173  bool ok = op(lhs, rhs);
174  if (isOutputEnabled(ok)) {
175  printAssertionMessage(ok, file, line, lhs, opName, rhs);
176  }
177  setPassOrFail(ok);
178  return ok;
179 }
180 
181 bool Assertion::assertion(const char* file, uint16_t line, long lhs,
182  const char* opName, bool (*op)(long lhs, long rhs),
183  long rhs) {
184  if (isDone()) return false;
185  bool ok = op(lhs, rhs);
186  if (isOutputEnabled(ok)) {
187  printAssertionMessage(ok, file, line, lhs, opName, rhs);
188  }
189  setPassOrFail(ok);
190  return ok;
191 }
192 
193 bool Assertion::assertion(const char* file, uint16_t line, unsigned long lhs,
194  const char* opName, bool (*op)(unsigned long lhs, unsigned long rhs),
195  unsigned long rhs) {
196  if (isDone()) return false;
197  bool ok = op(lhs, rhs);
198  if (isOutputEnabled(ok)) {
199  printAssertionMessage(ok, file, line, lhs, opName, rhs);
200  }
201  setPassOrFail(ok);
202  return ok;
203 }
204 
205 bool Assertion::assertion(const char* file, uint16_t line, double lhs,
206  const char* opName, bool (*op)(double lhs, double rhs),
207  double rhs) {
208  if (isDone()) return false;
209  bool ok = op(lhs, rhs);
210  if (isOutputEnabled(ok)) {
211  printAssertionMessage(ok, file, line, lhs, opName, rhs);
212  }
213  setPassOrFail(ok);
214  return ok;
215 }
216 
217 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
218  const char* opName, bool (*op)(const char* lhs, const char* rhs),
219  const char* rhs) {
220  if (isDone()) return false;
221  bool ok = op(lhs, rhs);
222  if (isOutputEnabled(ok)) {
223  printAssertionMessage(ok, file, line, lhs, opName, rhs);
224  }
225  setPassOrFail(ok);
226  return ok;
227 }
228 
229 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
230  const char *opName, bool (*op)(const char* lhs, const String& rhs),
231  const String& rhs) {
232  if (isDone()) return false;
233  bool ok = op(lhs, rhs);
234  if (isOutputEnabled(ok)) {
235  printAssertionMessage(ok, file, line, lhs, opName, rhs);
236  }
237  setPassOrFail(ok);
238  return ok;
239 }
240 
241 bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
242  const char *opName,
243  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
244  const __FlashStringHelper* rhs) {
245  if (isDone()) return false;
246  bool ok = op(lhs, rhs);
247  if (isOutputEnabled(ok)) {
248  printAssertionMessage(ok, file, line, lhs, opName, rhs);
249  }
250  setPassOrFail(ok);
251  return ok;
252 }
253 
254 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
255  const char *opName, bool (*op)(const String& lhs, const char* rhs),
256  const char* rhs) {
257  if (isDone()) return false;
258  bool ok = op(lhs, rhs);
259  if (isOutputEnabled(ok)) {
260  printAssertionMessage(ok, file, line, lhs, opName, rhs);
261  }
262  setPassOrFail(ok);
263  return ok;
264 }
265 
266 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
267  const char *opName, bool (*op)(const String& lhs, const String& rhs),
268  const String& rhs) {
269  if (isDone()) return false;
270  bool ok = op(lhs, rhs);
271  if (isOutputEnabled(ok)) {
272  printAssertionMessage(ok, file, line, lhs, opName, rhs);
273  }
274  setPassOrFail(ok);
275  return ok;
276 }
277 
278 bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
279  const char *opName,
280  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
281  const __FlashStringHelper* rhs) {
282  if (isDone()) return false;
283  bool ok = op(lhs, rhs);
284  if (isOutputEnabled(ok)) {
285  printAssertionMessage(ok, file, line, lhs, opName, rhs);
286  }
287  setPassOrFail(ok);
288  return ok;
289 }
290 
291 bool Assertion::assertion(const char* file, uint16_t line,
292  const __FlashStringHelper* lhs, const char *opName,
293  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
294  const char* rhs) {
295  if (isDone()) return false;
296  bool ok = op(lhs, rhs);
297  if (isOutputEnabled(ok)) {
298  printAssertionMessage(ok, file, line, 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 String& rhs),
307  const String& rhs) {
308  if (isDone()) return false;
309  bool ok = op(lhs, rhs);
310  if (isOutputEnabled(ok)) {
311  printAssertionMessage(ok, file, line, lhs, opName, rhs);
312  }
313  setPassOrFail(ok);
314  return ok;
315 }
316 
317 bool Assertion::assertion(const char* file, uint16_t line,
318  const __FlashStringHelper* lhs, const char *opName,
319  bool (*op)(const __FlashStringHelper* lhs, const __FlashStringHelper* rhs),
320  const __FlashStringHelper* rhs) {
321  if (isDone()) return false;
322  bool ok = op(lhs, rhs);
323  if (isOutputEnabled(ok)) {
324  printAssertionMessage(ok, file, line, lhs, opName, rhs);
325  }
326  setPassOrFail(ok);
327  return ok;
328 }
329 
330 namespace {
331 
332 // Verbose versions of above which accept the string arguments of the
333 // assertXxx() macros, so that the error messages are more verbose.
334 //
335 // Prints something like the following:
336 // Assertion failed: (x=5) == (y=6), file Test.ino, line 820.
337 // Assertion passed: (x=6) == (y=6), file Test.ino, line 820.
338 template <typename A, typename B>
339 void printAssertionMessageVerbose(bool ok, const char* file,
340  uint16_t line, const A& lhs, const __FlashStringHelper* lhsString,
341  const char *opName, const B& rhs, const __FlashStringHelper* rhsString) {
342 
343  // Don't use F() strings here because flash memory strings are not deduped by
344  // the compiler, so each template instantiation of this method causes a
345  // duplication of all the strings below. See
346  // https://github.com/mmurdoch/arduinounit/issues/70
347  // for more info.
348  Print* printer = Printer::getPrinter();
349  printer->print("Assertion ");
350  printer->print(ok ? "passed" : "failed");
351  printer->print(": (");
352  printer->print(lhsString);
353  printer->print('=');
354  printer->print(lhs);
355  printer->print(") ");
356  printer->print(opName);
357  printer->print(" (");
358  printer->print(rhsString);
359  printer->print('=');
360  printer->print(rhs);
361  printer->print(')');
362  // reuse string in MataAssertion::printAssertionTestStatusMessage()
363  printer->print(", file ");
364  printer->print(file);
365  printer->print(", line ");
366  printer->print(line);
367  printer->println('.');
368 }
369 
370 // Special version of (bool, bool) because Arduino Print.h converts
371 // bool into int, which prints out "(1) == (0)", which isn't as useful.
372 // This prints "(x=true) == (y=false)".
373 void printAssertionMessageVerbose(bool ok, const char* file,
374  uint16_t line, bool lhs, const __FlashStringHelper* lhsString,
375  const char *opName, bool rhs, const __FlashStringHelper* rhsString) {
376 
377  // Don't use F() strings here. Same reason as above.
378  Print* printer = Printer::getPrinter();
379  printer->print("Assertion ");
380  printer->print(ok ? "passed" : "failed");
381  printer->print(": (");
382  printer->print(lhsString);
383  printer->print('=');
384  printer->print(lhs ? "true" : "false");
385  printer->print(") ");
386  printer->print(opName);
387  printer->print(" (");
388  printer->print(rhsString);
389  printer->print('=');
390  printer->print(rhs ? "true" : "false");
391  printer->print(')');
392  printer->print(", file ");
393  printer->print(file);
394  printer->print(", line ");
395  printer->print(line);
396  printer->println('.');
397 }
398 
399 // Special version for assertTrue(arg) and assertFalse(arg).
400 // Prints:
401 // "Assertion passed/failed: (x=arg) is true"
402 // "Assertion passed/failed: (x=arg) is false"
403 void printAssertionBoolMessageVerbose(bool ok, const char* file,
404  uint16_t line, bool arg, const __FlashStringHelper* argString, bool value) {
405 
406  // Don't use F() strings here. Same reason as above.
407  Print* printer = Printer::getPrinter();
408  printer->print("Assertion ");
409  printer->print(ok ? "passed" : "failed");
410  printer->print(": (");
411  printer->print(argString);
412  printer->print('=');
413  printer->print(arg ? "true" : "false");
414  printer->print(") is ");
415  printer->print(value ? "true" : "false");
416  printer->print(", file ");
417  printer->print(file);
418  printer->print(", line ");
419  printer->print(line);
420  printer->println('.');
421 }
422 
423 } // namespace
424 
425 bool Assertion::assertionBoolVerbose(const char* file, uint16_t line, bool arg,
426  const __FlashStringHelper* argString, bool value) {
427  if (isDone()) return false;
428  bool ok = (arg == value);
429  if (isOutputEnabled(ok)) {
430  printAssertionBoolMessageVerbose(ok, file, line, arg, argString, value);
431  }
432  setPassOrFail(ok);
433  return ok;
434 }
435 
436 bool Assertion::assertionVerbose(const char* file, uint16_t line, bool lhs,
437  const __FlashStringHelper* lhsString, const char* opName,
438  bool (*op)(bool lhs, bool rhs), bool rhs,
439  const __FlashStringHelper* rhsString) {
440  if (isDone()) return false;
441  bool ok = op(lhs, rhs);
442  if (isOutputEnabled(ok)) {
443  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
444  rhsString);
445  }
446  setPassOrFail(ok);
447  return ok;
448 }
449 
450 bool Assertion::assertionVerbose(const char* file, uint16_t line, char lhs,
451  const __FlashStringHelper* lhsString, const char* opName,
452  bool (*op)(char lhs, char rhs), char rhs,
453  const __FlashStringHelper* rhsString) {
454  if (isDone()) return false;
455  bool ok = op(lhs, rhs);
456  if (isOutputEnabled(ok)) {
457  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
458  rhsString);
459  }
460  setPassOrFail(ok);
461  return ok;
462 }
463 
464 bool Assertion::assertionVerbose(const char* file, uint16_t line, int lhs,
465  const __FlashStringHelper* lhsString, const char* opName,
466  bool (*op)(int lhs, int rhs), int rhs,
467  const __FlashStringHelper* rhsString) {
468  if (isDone()) return false;
469  bool ok = op(lhs, rhs);
470  if (isOutputEnabled(ok)) {
471  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
472  rhsString);
473  }
474  setPassOrFail(ok);
475  return ok;
476 }
477 
478 bool Assertion::assertionVerbose(const char* file, uint16_t line,
479  unsigned int lhs, const __FlashStringHelper* lhsString, const char* opName,
480  bool (*op)(unsigned int lhs, unsigned int rhs),
481  unsigned int rhs, const __FlashStringHelper* rhsString) {
482  if (isDone()) return false;
483  bool ok = op(lhs, rhs);
484  if (isOutputEnabled(ok)) {
485  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
486  rhsString);
487  }
488  setPassOrFail(ok);
489  return ok;
490 }
491 
492 bool Assertion::assertionVerbose(const char* file, uint16_t line, long lhs,
493  const __FlashStringHelper* lhsString, const char* opName,
494  bool (*op)(long lhs, long rhs), long rhs,
495  const __FlashStringHelper* rhsString) {
496  if (isDone()) return false;
497  bool ok = op(lhs, rhs);
498  if (isOutputEnabled(ok)) {
499  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
500  rhsString);
501  }
502  setPassOrFail(ok);
503  return ok;
504 }
505 
506 bool Assertion::assertionVerbose(const char* file, uint16_t line,
507  unsigned long lhs, const __FlashStringHelper* lhsString, const char* opName,
508  bool (*op)(unsigned long lhs, unsigned long rhs),
509  unsigned long rhs, const __FlashStringHelper* rhsString) {
510  if (isDone()) return false;
511  bool ok = op(lhs, rhs);
512  if (isOutputEnabled(ok)) {
513  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
514  rhsString);
515  }
516  setPassOrFail(ok);
517  return ok;
518 }
519 
520 bool Assertion::assertionVerbose(const char* file, uint16_t line, double lhs,
521  const __FlashStringHelper* lhsString, const char* opName,
522  bool (*op)(double lhs, double rhs), double rhs,
523  const __FlashStringHelper* rhsString) {
524  if (isDone()) return false;
525  bool ok = op(lhs, rhs);
526  if (isOutputEnabled(ok)) {
527  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
528  rhsString);
529  }
530  setPassOrFail(ok);
531  return ok;
532 }
533 
534 bool Assertion::assertionVerbose(const char* file, uint16_t line,
535  const char* lhs, const __FlashStringHelper* lhsString, const char* opName,
536  bool (*op)(const char* lhs, const char* rhs),
537  const char* rhs, const __FlashStringHelper* rhsString) {
538  if (isDone()) return false;
539  bool ok = op(lhs, rhs);
540  if (isOutputEnabled(ok)) {
541  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
542  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,
550  const char *opName, bool (*op)(const char* lhs, const String& rhs),
551  const String& rhs, const __FlashStringHelper* rhsString) {
552  if (isDone()) return false;
553  bool ok = op(lhs, rhs);
554  if (isOutputEnabled(ok)) {
555  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
556  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, const char *opName,
564  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
565  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
566  if (isDone()) return false;
567  bool ok = op(lhs, rhs);
568  if (isOutputEnabled(ok)) {
569  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
570  rhsString);
571  }
572  setPassOrFail(ok);
573  return ok;
574 }
575 
576 bool Assertion::assertionVerbose(const char* file, uint16_t line,
577  const String& lhs, const __FlashStringHelper* lhsString, const char *opName,
578  bool (*op)(const String& lhs, const char* rhs),
579  const char* rhs, const __FlashStringHelper* rhsString) {
580  if (isDone()) return false;
581  bool ok = op(lhs, rhs);
582  if (isOutputEnabled(ok)) {
583  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
584  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 String& rhs),
593  const String& rhs, const __FlashStringHelper* rhsString) {
594  if (isDone()) return false;
595  bool ok = op(lhs, rhs);
596  if (isOutputEnabled(ok)) {
597  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
598  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 __FlashStringHelper* rhs),
607  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
608  if (isDone()) return false;
609  bool ok = op(lhs, rhs);
610  if (isOutputEnabled(ok)) {
611  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
612  rhsString);
613  }
614  setPassOrFail(ok);
615  return ok;
616 }
617 
618 bool Assertion::assertionVerbose(const char* file, uint16_t line,
619  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
620  const char *opName,
621  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
622  const char* rhs, const __FlashStringHelper* rhsString) {
623  if (isDone()) return false;
624  bool ok = op(lhs, rhs);
625  if (isOutputEnabled(ok)) {
626  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
627  rhsString);
628  }
629  setPassOrFail(ok);
630  return ok;
631 }
632 
633 bool Assertion::assertionVerbose(const char* file, uint16_t line,
634  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
635  const char *opName,
636  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
637  const String& rhs, const __FlashStringHelper* rhsString) {
638  if (isDone()) return false;
639  bool ok = op(lhs, rhs);
640  if (isOutputEnabled(ok)) {
641  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
642  rhsString);
643  }
644  setPassOrFail(ok);
645  return ok;
646 }
647 
648 bool Assertion::assertionVerbose(const char* file, uint16_t line,
649  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
650  const char *opName,
651  bool (*op)(const __FlashStringHelper* lhs, const __FlashStringHelper* rhs),
652  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString) {
653  if (isDone()) return false;
654  bool ok = op(lhs, rhs);
655  if (isOutputEnabled(ok)) {
656  printAssertionMessageVerbose(ok, file, line, lhs, lhsString, opName, rhs,
657  rhsString);
658  }
659  setPassOrFail(ok);
660  return ok;
661 }
662 
663 }
void setPassOrFail(bool ok)
Set the status to Passed or Failed depending on ok.
Definition: Test.cpp:50
bool isOutputEnabled(bool ok)
Returns true if an assertion message should be printed.
Definition: Assertion.cpp:117
bool isVerbosity(uint8_t verbosity)
Determine if any of the given verbosity is enabled.
Definition: Test.h:275
static const uint8_t kAssertionPassed
Print assertXxx() passed message.
Definition: Verbosity.h:40
bool isDone()
Return true if test has been asserted.
Definition: Test.h:196
static Print * getPrinter()
Get the output printer used by the various assertion() methods and the TestRunner.
Definition: Printer.h:52
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...