29 #include "Assertion.h"
31 #if ! defined(ARDUINO_ARCH_STM32)
37 using namespace internal;
48 template <
typename A,
typename B>
49 void printAssertionMessage(
68 printer->print(
": Assertion ");
69 printer->print(ok ?
"passed" :
"failed");
70 printer->print(
": (");
73 printer->print(opName);
77 printer->println(
'.');
83 void printAssertionMessage(
97 printer->print(
": Assertion ");
98 printer->print(ok ?
"passed" :
"failed");
99 printer->print(
": (");
100 printer->print(lhs ?
"true" :
"false");
101 printer->print(
") ");
102 printer->print(opName);
103 printer->print(
" (");
104 printer->print(rhs ?
"true" :
"false");
106 printer->println(
'.');
109 #if ! defined(ARDUINO_ARCH_STM32)
112 void printAssertionMessage(
123 printer->print(file);
125 printer->print(line);
126 printer->print(
": Assertion ");
127 printer->print(ok ?
"passed" :
"failed");
128 printer->print(
": (");
129 print64(*printer, lhs);
130 printer->print(
") ");
131 printer->print(opName);
132 printer->print(
" (");
133 print64(*printer, rhs);
135 printer->println(
'.');
140 void printAssertionMessage(
145 unsigned long long& lhs,
147 unsigned long long& rhs
151 printer->print(file);
153 printer->print(line);
154 printer->print(
": Assertion ");
155 printer->print(ok ?
"passed" :
"failed");
156 printer->print(
": (");
157 print64(*printer, lhs);
158 printer->print(
") ");
159 printer->print(opName);
160 printer->print(
" (");
161 print64(*printer, rhs);
163 printer->println(
'.');
169 void printAssertionMessage(
183 printer->print(file);
185 printer->print(line);
186 printer->print(
": Assertion ");
187 printer->print(ok ?
"passed" :
"failed");
188 printer->print(
": (0x");
189 printer->print((
unsigned long) lhs, HEX);
190 printer->print(
") ");
191 printer->print(opName);
192 printer->print(
" (0x");
193 printer->print((
unsigned long) rhs, HEX);
195 printer->println(
'.');
202 void printAssertionBoolMessage(
212 printer->print(file);
214 printer->print(line);
215 printer->print(
": Assertion ");
216 printer->print(ok ?
"passed" :
"failed");
217 printer->print(
": (");
218 printer->print(arg ?
"true" :
"false");
219 printer->print(
") is ");
220 printer->print(value ?
"true" :
"false");
221 printer->println(
'.');
224 template <
typename A>
225 void printAssertionNearMessage(
235 printer->print(file);
237 printer->print(line);
238 printer->print(
": Assertion ");
239 printer->print(ok ?
"passed" :
"failed");
240 printer->print(
": |(");
242 printer->print(
") - (");
244 printer->print(
")| ");
245 printer->print(opName);
246 printer->print(
" (");
247 printer->print(error);
249 printer->println(
'.');
265 if (isDone())
return false;
266 bool ok = (arg == value);
267 if (isOutputEnabled(ok)) {
280 bool (*op)(
bool lhs,
bool rhs),
283 if (isDone())
return false;
284 bool ok = op(lhs, rhs);
285 if (isOutputEnabled(ok)) {
298 bool (*op)(
char lhs,
char rhs),
301 if (isDone())
return false;
302 bool ok = op(lhs, rhs);
303 if (isOutputEnabled(ok)) {
316 bool (*op)(
int lhs,
int rhs),
319 if (isDone())
return false;
320 bool ok = op(lhs, rhs);
321 if (isOutputEnabled(ok)) {
334 bool (*op)(
unsigned int lhs,
unsigned int rhs),
337 if (isDone())
return false;
338 bool ok = op(lhs, rhs);
339 if (isOutputEnabled(ok)) {
352 bool (*op)(
long lhs,
long rhs),
355 if (isDone())
return false;
356 bool ok = op(lhs, rhs);
357 if (isOutputEnabled(ok)) {
370 bool (*op)(
unsigned long lhs,
unsigned long rhs),
373 if (isDone())
return false;
374 bool ok = op(lhs, rhs);
375 if (isOutputEnabled(ok)) {
388 bool (*op)(
long long lhs,
long long rhs),
391 if (isDone())
return false;
392 bool ok = op(lhs, rhs);
393 if (isOutputEnabled(ok)) {
404 unsigned long long lhs,
406 bool (*op)(
unsigned long long lhs,
unsigned long long rhs),
407 unsigned long long rhs
409 if (isDone())
return false;
410 bool ok = op(lhs, rhs);
411 if (isOutputEnabled(ok)) {
424 bool (*op)(
double lhs,
double rhs),
427 if (isDone())
return false;
428 bool ok = op(lhs, rhs);
429 if (isOutputEnabled(ok)) {
442 bool (*op)(
const void* lhs,
const void* rhs),
445 if (isDone())
return false;
446 bool ok = op(lhs, rhs);
447 if (isOutputEnabled(ok)) {
460 bool (*op)(
const char* lhs,
const char* rhs),
463 if (isDone())
return false;
464 bool ok = op(lhs, rhs);
465 if (isOutputEnabled(ok)) {
478 bool (*op)(
const char* lhs,
const String& rhs),
481 if (isDone())
return false;
482 bool ok = op(lhs, rhs);
483 if (isOutputEnabled(ok)) {
496 bool (*op)(
const char* lhs,
const __FlashStringHelper* rhs),
497 const __FlashStringHelper* rhs
499 if (isDone())
return false;
500 bool ok = op(lhs, rhs);
501 if (isOutputEnabled(ok)) {
514 bool (*op)(
const String& lhs,
const char* rhs),
517 if (isDone())
return false;
518 bool ok = op(lhs, rhs);
519 if (isOutputEnabled(ok)) {
532 bool (*op)(
const String& lhs,
const String& rhs),
535 if (isDone())
return false;
536 bool ok = op(lhs, rhs);
537 if (isOutputEnabled(ok)) {
550 bool (*op)(
const String& lhs,
const __FlashStringHelper* rhs),
551 const __FlashStringHelper* rhs
553 if (isDone())
return false;
554 bool ok = op(lhs, rhs);
555 if (isOutputEnabled(ok)) {
566 const __FlashStringHelper* lhs,
568 bool (*op)(
const __FlashStringHelper* lhs,
const char* rhs),
571 if (isDone())
return false;
572 bool ok = op(lhs, rhs);
573 if (isOutputEnabled(ok)) {
584 const __FlashStringHelper* lhs,
586 bool (*op)(
const __FlashStringHelper* lhs,
const String& rhs),
589 if (isDone())
return false;
590 bool ok = op(lhs, rhs);
591 if (isOutputEnabled(ok)) {
602 const __FlashStringHelper* lhs,
604 bool (*op)(
const __FlashStringHelper* lhs,
const __FlashStringHelper* rhs),
605 const __FlashStringHelper* rhs
607 if (isDone())
return false;
608 bool ok = op(lhs, rhs);
609 if (isOutputEnabled(ok)) {
624 bool (*opNear)(
int lhs,
int rhs,
int error)
626 if (isDone())
return false;
627 bool ok = opNear(lhs, rhs, error);
628 if (isOutputEnabled(ok)) {
630 lhs, rhs, opName, error);
643 bool (*opNear)(
unsigned int lhs,
unsigned int rhs,
unsigned int error)
645 if (isDone())
return false;
646 bool ok = opNear(lhs, rhs, error);
647 if (isOutputEnabled(ok)) {
649 lhs, rhs, opName, error);
662 bool (*opNear)(
long lhs,
long rhs,
long error)
664 if (isDone())
return false;
665 bool ok = opNear(lhs, rhs, error);
666 if (isOutputEnabled(ok)) {
668 lhs, rhs, opName, error);
681 bool (*opNear)(
unsigned long lhs,
unsigned long rhs,
unsigned long error)
683 if (isDone())
return false;
684 bool ok = opNear(lhs, rhs, error);
685 if (isOutputEnabled(ok)) {
687 lhs, rhs, opName, error);
700 bool (*opNear)(
double lhs,
double rhs,
double error)
702 if (isDone())
return false;
703 bool ok = opNear(lhs, rhs, error);
704 if (isOutputEnabled(ok)) {
706 lhs, rhs, opName, error);
722 template <
typename A,
typename B>
723 void printAssertionMessageVerbose(
729 const __FlashStringHelper* lhsString,
732 const __FlashStringHelper* rhsString
740 printer->print(file);
742 printer->print(line);
743 printer->print(
": Assertion ");
744 printer->print(ok ?
"passed" :
"failed");
745 printer->print(
": (");
746 printer->print(lhsString);
749 printer->print(
") ");
750 printer->print(opName);
751 printer->print(
" (");
752 printer->print(rhsString);
756 printer->println(
'.');
762 void printAssertionMessageVerbose(
768 const __FlashStringHelper* lhsString,
771 const __FlashStringHelper* rhsString
775 printer->print(file);
777 printer->print(line);
778 printer->print(
": Assertion ");
779 printer->print(ok ?
"passed" :
"failed");
780 printer->print(
": (");
781 printer->print(lhsString);
783 printer->print(lhs ?
"true" :
"false");
784 printer->print(
") ");
785 printer->print(opName);
786 printer->print(
" (");
787 printer->print(rhsString);
789 printer->print(rhs ?
"true" :
"false");
791 printer->println(
'.');
794 #if ! defined(ARDUINO_ARCH_STM32)
797 void printAssertionMessageVerbose(
803 const __FlashStringHelper* lhsString,
806 const __FlashStringHelper* rhsString
810 printer->print(file);
812 printer->print(line);
813 printer->print(
": Assertion ");
814 printer->print(ok ?
"passed" :
"failed");
815 printer->print(
": (");
816 printer->print(lhsString);
818 print64(*printer, lhs);
819 printer->print(
") ");
820 printer->print(opName);
821 printer->print(
" (");
822 printer->print(rhsString);
824 print64(*printer, rhs);
826 printer->println(
'.');
831 void printAssertionMessageVerbose(
836 unsigned long long& lhs,
837 const __FlashStringHelper* lhsString,
839 unsigned long long& rhs,
840 const __FlashStringHelper* rhsString
844 printer->print(file);
846 printer->print(line);
847 printer->print(
": Assertion ");
848 printer->print(ok ?
"passed" :
"failed");
849 printer->print(
": (");
850 printer->print(lhsString);
852 print64(*printer, lhs);
853 printer->print(
") ");
854 printer->print(opName);
855 printer->print(
" (");
856 printer->print(rhsString);
858 print64(*printer, rhs);
860 printer->println(
'.');
866 void printAssertionMessageVerbose(
872 const __FlashStringHelper* lhsString,
875 const __FlashStringHelper* rhsString
882 printer->print(file);
884 printer->print(line);
885 printer->print(
": Assertion ");
886 printer->print(ok ?
"passed" :
"failed");
887 printer->print(
": (");
888 printer->print(lhsString);
889 printer->print(
"=0x");
890 printer->print((
unsigned long) lhs, HEX);
891 printer->print(
") ");
892 printer->print(opName);
893 printer->print(
" (");
894 printer->print(rhsString);
895 printer->print(
"=0x");
896 printer->print((
unsigned long) rhs, HEX);
898 printer->println(
'.');
905 void printAssertionBoolMessageVerbose(
911 const __FlashStringHelper* argString,
916 printer->print(file);
918 printer->print(line);
919 printer->print(
": Assertion ");
920 printer->print(ok ?
"passed" :
"failed");
921 printer->print(
": (");
922 printer->print(argString);
924 printer->print(arg ?
"true" :
"false");
925 printer->print(
") is ");
926 printer->print(value ?
"true" :
"false");
927 printer->println(
'.');
930 template <
typename A>
931 void printAssertionNearMessageVerbose(
937 const __FlashStringHelper* lhsString,
939 const __FlashStringHelper* rhsString,
942 const __FlashStringHelper* errorString
944 printer->print(file);
946 printer->print(line);
947 printer->print(
": Assertion ");
948 printer->print(ok ?
"passed" :
"failed");
949 printer->print(
": |(");
950 printer->print(lhsString);
953 printer->print(
") - (");
954 printer->print(rhsString);
957 printer->print(
")| ");
958 printer->print(opName);
959 printer->print(
" (");
960 printer->print(errorString);
962 printer->print(error);
964 printer->println(
'.');
973 const __FlashStringHelper* argString,
976 if (isDone())
return false;
977 bool ok = (arg == value);
978 if (isOutputEnabled(ok)) {
980 arg, argString, value);
990 const __FlashStringHelper* lhsString,
992 bool (*op)(
bool lhs,
bool rhs),
994 const __FlashStringHelper* rhsString
996 if (isDone())
return false;
997 bool ok = op(lhs, rhs);
998 if (isOutputEnabled(ok)) {
1000 lhs, lhsString, opName, rhs, rhsString);
1010 const __FlashStringHelper* lhsString,
1012 bool (*op)(
char lhs,
char rhs),
1014 const __FlashStringHelper* rhsString
1016 if (isDone())
return false;
1017 bool ok = op(lhs, rhs);
1018 if (isOutputEnabled(ok)) {
1020 lhs, lhsString, opName, rhs, rhsString);
1030 const __FlashStringHelper* lhsString,
1032 bool (*op)(
int lhs,
int rhs),
1034 const __FlashStringHelper* rhsString
1036 if (isDone())
return false;
1037 bool ok = op(lhs, rhs);
1038 if (isOutputEnabled(ok)) {
1040 lhs, lhsString, opName, rhs, rhsString);
1050 const __FlashStringHelper* lhsString,
1052 bool (*op)(
unsigned int lhs,
unsigned int rhs),
1054 const __FlashStringHelper* rhsString
1056 if (isDone())
return false;
1057 bool ok = op(lhs, rhs);
1058 if (isOutputEnabled(ok)) {
1060 lhs, lhsString, opName, rhs, rhsString);
1070 const __FlashStringHelper* lhsString,
1072 bool (*op)(
long lhs,
long rhs),
1074 const __FlashStringHelper* rhsString
1076 if (isDone())
return false;
1077 bool ok = op(lhs, rhs);
1078 if (isOutputEnabled(ok)) {
1080 lhs, lhsString, opName, rhs, rhsString);
1090 const __FlashStringHelper* lhsString,
1092 bool (*op)(
unsigned long lhs,
unsigned long rhs),
1094 const __FlashStringHelper* rhsString
1096 if (isDone())
return false;
1097 bool ok = op(lhs, rhs);
1098 if (isOutputEnabled(ok)) {
1100 lhs, lhsString, opName, rhs, rhsString);
1110 const __FlashStringHelper* lhsString,
1112 bool (*op)(
long long lhs,
long long rhs),
1114 const __FlashStringHelper* rhsString
1116 if (isDone())
return false;
1117 bool ok = op(lhs, rhs);
1118 if (isOutputEnabled(ok)) {
1120 lhs, lhsString, opName, rhs, rhsString);
1129 unsigned long long lhs,
1130 const __FlashStringHelper* lhsString,
1132 bool (*op)(
unsigned long long lhs,
unsigned long long rhs),
1133 unsigned long long rhs,
1134 const __FlashStringHelper* rhsString
1136 if (isDone())
return false;
1137 bool ok = op(lhs, rhs);
1138 if (isOutputEnabled(ok)) {
1140 lhs, lhsString, opName, rhs, rhsString);
1150 const __FlashStringHelper* lhsString,
1152 bool (*op)(
double lhs,
double rhs),
1154 const __FlashStringHelper* rhsString
1156 if (isDone())
return false;
1157 bool ok = op(lhs, rhs);
1158 if (isOutputEnabled(ok)) {
1160 lhs, lhsString, opName, rhs, rhsString);
1170 const __FlashStringHelper* lhsString,
1172 bool (*op)(
const void* lhs,
const void* rhs),
1174 const __FlashStringHelper* rhsString
1176 if (isDone())
return false;
1177 bool ok = op(lhs, rhs);
1178 if (isOutputEnabled(ok)) {
1180 lhs, lhsString, opName, rhs, rhsString);
1190 const __FlashStringHelper* lhsString,
1192 bool (*op)(
const char* lhs,
const char* rhs),
1194 const __FlashStringHelper* rhsString
1196 if (isDone())
return false;
1197 bool ok = op(lhs, rhs);
1198 if (isOutputEnabled(ok)) {
1200 lhs, lhsString, opName, rhs, rhsString);
1210 const __FlashStringHelper* lhsString,
1212 bool (*op)(
const char* lhs,
const String& rhs),
1214 const __FlashStringHelper* rhsString
1216 if (isDone())
return false;
1217 bool ok = op(lhs, rhs);
1218 if (isOutputEnabled(ok)) {
1220 lhs, lhsString, opName, rhs, rhsString);
1230 const __FlashStringHelper* lhsString,
1232 bool (*op)(
const char* lhs,
const __FlashStringHelper* rhs),
1233 const __FlashStringHelper* rhs,
1234 const __FlashStringHelper* rhsString
1236 if (isDone())
return false;
1237 bool ok = op(lhs, rhs);
1238 if (isOutputEnabled(ok)) {
1240 lhs, lhsString, opName, rhs, rhsString);
1250 const __FlashStringHelper* lhsString,
1252 bool (*op)(
const String& lhs,
const char* rhs),
1254 const __FlashStringHelper* rhsString
1256 if (isDone())
return false;
1257 bool ok = op(lhs, rhs);
1258 if (isOutputEnabled(ok)) {
1260 lhs, lhsString, opName, rhs, rhsString);
1270 const __FlashStringHelper* lhsString,
1272 bool (*op)(
const String& lhs,
const String& rhs),
1274 const __FlashStringHelper* rhsString
1276 if (isDone())
return false;
1277 bool ok = op(lhs, rhs);
1278 if (isOutputEnabled(ok)) {
1280 lhs, lhsString, opName, rhs, rhsString);
1290 const __FlashStringHelper* lhsString,
1292 bool (*op)(
const String& lhs,
const __FlashStringHelper* rhs),
1293 const __FlashStringHelper* rhs,
1294 const __FlashStringHelper* rhsString
1296 if (isDone())
return false;
1297 bool ok = op(lhs, rhs);
1298 if (isOutputEnabled(ok)) {
1300 lhs, lhsString, opName, rhs, rhsString);
1309 const __FlashStringHelper* lhs,
1310 const __FlashStringHelper* lhsString,
1312 bool (*op)(
const __FlashStringHelper* lhs,
1315 const __FlashStringHelper* rhsString
1317 if (isDone())
return false;
1318 bool ok = op(lhs, rhs);
1319 if (isOutputEnabled(ok)) {
1321 lhs, lhsString, opName, rhs, rhsString);
1330 const __FlashStringHelper* lhs,
1331 const __FlashStringHelper* lhsString,
1333 bool (*op)(
const __FlashStringHelper* lhs,
const String& rhs),
1335 const __FlashStringHelper* rhsString
1337 if (isDone())
return false;
1338 bool ok = op(lhs, rhs);
1339 if (isOutputEnabled(ok)) {
1341 lhs, lhsString, opName, rhs, rhsString);
1350 const __FlashStringHelper* lhs,
1351 const __FlashStringHelper* lhsString,
1353 bool (*op)(
const __FlashStringHelper* lhs,
const __FlashStringHelper* rhs),
1354 const __FlashStringHelper* rhs,
1355 const __FlashStringHelper* rhsString
1357 if (isDone())
return false;
1358 bool ok = op(lhs, rhs);
1359 if (isOutputEnabled(ok)) {
1361 lhs, lhsString, opName, rhs, rhsString);
1371 const __FlashStringHelper* lhsString,
1373 const __FlashStringHelper* rhsString,
1375 const __FlashStringHelper* errorString,
1377 bool (*opNear)(
int lhs,
int rhs,
int error)
1379 if (isDone())
return false;
1380 bool ok = opNear(lhs, rhs, error);
1381 if (isOutputEnabled(ok)) {
1383 lhs, lhsString, rhs, rhsString, opName, error, errorString);
1393 const __FlashStringHelper* lhsString,
1395 const __FlashStringHelper* rhsString,
1397 const __FlashStringHelper* errorString,
1399 bool (*opNear)(
unsigned int lhs,
unsigned int rhs,
unsigned int error)
1401 if (isDone())
return false;
1402 bool ok = opNear(lhs, rhs, error);
1403 if (isOutputEnabled(ok)) {
1405 lhs, lhsString, rhs, rhsString, opName, error, errorString);
1415 const __FlashStringHelper* lhsString,
1417 const __FlashStringHelper* rhsString,
1419 const __FlashStringHelper* errorString,
1421 bool (*opNear)(
long lhs,
long rhs,
long error)
1423 if (isDone())
return false;
1424 bool ok = opNear(lhs, rhs, error);
1425 if (isOutputEnabled(ok)) {
1427 lhs, lhsString, rhs, rhsString, opName, error, errorString);
1437 const __FlashStringHelper* lhsString,
1439 const __FlashStringHelper* rhsString,
1440 unsigned long error,
1441 const __FlashStringHelper* errorString,
1443 bool (*opNear)(
unsigned long lhs,
unsigned long rhs,
unsigned long error)
1445 if (isDone())
return false;
1446 bool ok = opNear(lhs, rhs, error);
1447 if (isOutputEnabled(ok)) {
1449 lhs, lhsString, rhs, rhsString, opName, error, errorString);
1459 const __FlashStringHelper* lhsString,
1461 const __FlashStringHelper* rhsString,
1463 const __FlashStringHelper* errorString,
1465 bool (*opNear)(
double lhs,
double rhs,
double error)
1467 if (isDone())
return false;
1468 bool ok = opNear(lhs, rhs, error);
1469 if (isOutputEnabled(ok)) {
1471 lhs, lhsString, rhs, rhsString, opName, error, errorString);
Various macros to smooth over the differences among the various platforms with regards to their suppo...
bool assertionBool(const char *file, uint16_t line, bool arg, bool value)
Used by assertTrue() and assertFalse().
bool assertionBoolVerbose(const char *file, uint16_t line, bool arg, const __FlashStringHelper *argString, bool value)
Used by assertTrue() and assertFalse().
bool assertion(const char *file, uint16_t line, bool lhs, const char *opName, bool(*op)(bool lhs, bool rhs), bool rhs)
Used by assertXxx(bool, bool).
bool assertionNearVerbose(const char *file, uint16_t line, int lhs, const __FlashStringHelper *lhsString, int rhs, const __FlashStringHelper *rhsString, int error, const __FlashStringHelper *errorString, const char *opName, bool(*compareNear)(int lhs, int rhs, int error))
Used by assertNear(int, int).
bool isOutputEnabled(bool ok) const
Returns true if an assertion message should be printed.
bool assertionVerbose(const char *file, uint16_t line, bool lhs, const __FlashStringHelper *lhsString, const char *opName, bool(*op)(bool lhs, bool rhs), bool rhs, const __FlashStringHelper *rhsString)
Used by assertEqual(bool, bool).
bool assertionNear(const char *file, uint16_t line, int lhs, int rhs, int error, const char *opName, bool(*compareNear)(int lhs, int rhs, int error))
Used by assertNear(int, int).
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.
static const uint8_t kAssertionPassed
Print assertXxx() passed message.
Helper routines to print 'long long' and 'unsigned long long' because the Print::print() methods in P...