28 #include "Assertion.h" 32 using namespace internal;
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) {
53 printer->print(
"Assertion ");
54 printer->print(ok ?
"passed" :
"failed");
55 printer->print(
": (");
58 printer->print(opName);
63 printer->print(
", file ");
65 printer->print(
", line ");
67 printer->println(
'.');
73 void printAssertionMessage(Print* printer,
bool ok,
const char* file,
74 uint16_t line,
bool lhs,
const char *opName,
bool rhs) {
77 printer->print(
"Assertion ");
78 printer->print(ok ?
"passed" :
"failed");
79 printer->print(
": (");
80 printer->print(lhs ?
"true" :
"false");
82 printer->print(opName);
84 printer->print(rhs ?
"true" :
"false");
86 printer->print(
", file ");
88 printer->print(
", line ");
90 printer->println(
'.');
97 void printAssertionBoolMessage(Print* printer,
bool ok,
const char* file,
98 uint16_t line,
bool arg,
bool value) {
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(
'.');
121 bool Assertion::assertionBool(
const char* file, uint16_t line,
bool arg,
123 if (isDone())
return false;
124 bool ok = (arg == value);
125 if (isOutputEnabled(ok)) {
133 bool Assertion::assertion(
const char* file, uint16_t line,
bool lhs,
134 const char* opName,
bool (*op)(
bool lhs,
bool rhs),
136 if (isDone())
return false;
137 bool ok = op(lhs, rhs);
138 if (isOutputEnabled(ok)) {
146 bool Assertion::assertion(
const char* file, uint16_t line,
char lhs,
147 const char* opName,
bool (*op)(
char lhs,
char rhs),
149 if (isDone())
return false;
150 bool ok = op(lhs, rhs);
151 if (isOutputEnabled(ok)) {
159 bool Assertion::assertion(
const char* file, uint16_t line,
int lhs,
160 const char* opName,
bool (*op)(
int lhs,
int rhs),
162 if (isDone())
return false;
163 bool ok = op(lhs, rhs);
164 if (isOutputEnabled(ok)) {
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),
175 if (isDone())
return false;
176 bool ok = op(lhs, rhs);
177 if (isOutputEnabled(ok)) {
185 bool Assertion::assertion(
const char* file, uint16_t line,
long lhs,
186 const char* opName,
bool (*op)(
long lhs,
long rhs),
188 if (isDone())
return false;
189 bool ok = op(lhs, rhs);
190 if (isOutputEnabled(ok)) {
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),
201 if (isDone())
return false;
202 bool ok = op(lhs, rhs);
203 if (isOutputEnabled(ok)) {
211 bool Assertion::assertion(
const char* file, uint16_t line,
double lhs,
212 const char* opName,
bool (*op)(
double lhs,
double rhs),
214 if (isDone())
return false;
215 bool ok = op(lhs, rhs);
216 if (isOutputEnabled(ok)) {
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),
227 if (isDone())
return false;
228 bool ok = op(lhs, rhs);
229 if (isOutputEnabled(ok)) {
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),
240 if (isDone())
return false;
241 bool ok = op(lhs, rhs);
242 if (isOutputEnabled(ok)) {
250 bool Assertion::assertion(
const char* file, uint16_t line,
const char* lhs,
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)) {
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),
267 if (isDone())
return false;
268 bool ok = op(lhs, rhs);
269 if (isOutputEnabled(ok)) {
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),
280 if (isDone())
return false;
281 bool ok = op(lhs, rhs);
282 if (isOutputEnabled(ok)) {
290 bool Assertion::assertion(
const char* file, uint16_t line,
const String& lhs,
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)) {
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),
308 if (isDone())
return false;
309 bool ok = op(lhs, rhs);
310 if (isOutputEnabled(ok)) {
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),
322 if (isDone())
return false;
323 bool ok = op(lhs, rhs);
324 if (isOutputEnabled(ok)) {
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)) {
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) {
364 printer->print(
"Assertion ");
365 printer->print(ok ?
"passed" :
"failed");
366 printer->print(
": (");
367 printer->print(lhsString);
370 printer->print(
") ");
371 printer->print(opName);
372 printer->print(
" (");
373 printer->print(rhsString);
378 printer->print(
", file ");
379 printer->print(file);
380 printer->print(
", line ");
381 printer->print(line);
382 printer->println(
'.');
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) {
393 printer->print(
"Assertion ");
394 printer->print(ok ?
"passed" :
"failed");
395 printer->print(
": (");
396 printer->print(lhsString);
398 printer->print(lhs ?
"true" :
"false");
399 printer->print(
") ");
400 printer->print(opName);
401 printer->print(
" (");
402 printer->print(rhsString);
404 printer->print(rhs ?
"true" :
"false");
406 printer->print(
", file ");
407 printer->print(file);
408 printer->print(
", line ");
409 printer->print(line);
410 printer->println(
'.');
417 void printAssertionBoolMessageVerbose(Print* printer,
bool ok,
const char* file,
418 uint16_t line,
bool arg,
const __FlashStringHelper* argString,
bool value) {
421 printer->print(
"Assertion ");
422 printer->print(ok ?
"passed" :
"failed");
423 printer->print(
": (");
424 printer->print(argString);
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(
'.');
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)) {
444 arg, argString, value);
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)) {
458 lhs, lhsString, opName, rhs, rhsString);
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)) {
472 lhs, lhsString, opName, rhs, rhsString);
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)) {
486 lhs, lhsString, opName, rhs, rhsString);
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)) {
500 lhs, lhsString, opName, rhs, rhsString);
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)) {
514 lhs, lhsString, opName, rhs, rhsString);
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)) {
528 lhs, lhsString, opName, rhs, rhsString);
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)) {
542 lhs, lhsString, opName, rhs, rhsString);
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)) {
556 lhs, lhsString, opName, rhs, rhsString);
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)) {
570 lhs, lhsString, opName, rhs, rhsString);
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)) {
584 lhs, lhsString, opName, rhs, rhsString);
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)) {
598 lhs, lhsString, opName, rhs, rhsString);
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)) {
612 lhs, lhsString, opName, rhs, rhsString);
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)) {
626 lhs, lhsString, opName, rhs, rhsString);
632 bool Assertion::assertionVerbose(
const char* file, uint16_t line,
633 const __FlashStringHelper* lhs,
const __FlashStringHelper* lhsString,
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)) {
641 lhs, lhsString, opName, rhs, rhsString);
647 bool Assertion::assertionVerbose(
const char* file, uint16_t line,
648 const __FlashStringHelper* lhs,
const __FlashStringHelper* lhsString,
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)) {
656 lhs, lhsString, opName, rhs, rhsString);
662 bool Assertion::assertionVerbose(
const char* file, uint16_t line,
663 const __FlashStringHelper* lhs,
const __FlashStringHelper* lhsString,
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)) {
671 lhs, lhsString, opName, rhs, rhsString);
bool isOutputEnabled(bool ok)
Returns true if an assertion message should be printed.
static const uint8_t kAssertionPassed
Print assertXxx() passed message.
static Print * getPrinter()
Get the output printer used by the various assertion() methods and the TestRunner.
static const uint8_t kAssertionFailed
Print assertXxx() failed message.
Various macros to smooth over the differences among the various platforms with regards to their suppo...