29 #include "Assertion.h"
31 #if ! defined(ARDUINO_ARCH_STM32)
37 using namespace internal;
48 template <
typename A,
typename B>
49 void printAssertionMessage(
65 printer->print(
"Assertion ");
66 printer->print(ok ?
"passed" :
"failed");
67 printer->print(
": (");
70 printer->print(opName);
75 printer->print(
", file ");
77 printer->print(
", line ");
79 printer->println(
'.');
85 void printAssertionMessage(
96 printer->print(
"Assertion ");
97 printer->print(ok ?
"passed" :
"failed");
98 printer->print(
": (");
99 printer->print(lhs ?
"true" :
"false");
100 printer->print(
") ");
101 printer->print(opName);
102 printer->print(
" (");
103 printer->print(rhs ?
"true" :
"false");
105 printer->print(
", file ");
106 printer->print(file);
107 printer->print(
", line ");
108 printer->print(line);
109 printer->println(
'.');
112 #if ! defined(ARDUINO_ARCH_STM32)
115 void printAssertionMessage(
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->print(
", file ");
136 printer->print(file);
137 printer->print(
", line ");
138 printer->print(line);
139 printer->println(
'.');
144 void printAssertionMessage(
149 unsigned long long& lhs,
151 unsigned long long& rhs
155 printer->print(
"Assertion ");
156 printer->print(ok ?
"passed" :
"failed");
157 printer->print(
": (");
158 print64(*printer, lhs);
159 printer->print(
") ");
160 printer->print(opName);
161 printer->print(
" (");
162 print64(*printer, rhs);
164 printer->print(
", file ");
165 printer->print(file);
166 printer->print(
", line ");
167 printer->print(line);
168 printer->println(
'.');
171 #endif // ARDUINO_ARCH_STM32
174 void printAssertionMessage(
188 printer->print(
"Assertion ");
189 printer->print(ok ?
"passed" :
"failed");
190 printer->print(
": (0x");
191 printer->print((
unsigned long) lhs, HEX);
192 printer->print(
") ");
193 printer->print(opName);
194 printer->print(
" (0x");
195 printer->print((
unsigned long) rhs, HEX);
197 printer->print(
", file ");
198 printer->print(file);
199 printer->print(
", line ");
200 printer->print(line);
201 printer->println(
'.');
208 void printAssertionBoolMessage(
218 printer->print(
"Assertion ");
219 printer->print(ok ?
"passed" :
"failed");
220 printer->print(
": (");
221 printer->print(arg ?
"true" :
"false");
222 printer->print(
") is ");
223 printer->print(value ?
"true" :
"false");
224 printer->print(
", file ");
225 printer->print(file);
226 printer->print(
", line ");
227 printer->print(line);
228 printer->println(
'.');
231 template <
typename A>
232 void printAssertionNearMessage(
242 printer->print(
"Assertion ");
243 printer->print(ok ?
"passed" :
"failed");
244 printer->print(
": |(");
246 printer->print(
") - (");
248 printer->print(
")| ");
249 printer->print(opName);
250 printer->print(
" (");
251 printer->print(error);
253 printer->print(
", file ");
254 printer->print(file);
255 printer->print(
", line ");
256 printer->print(line);
257 printer->println(
'.');
273 if (isDone())
return false;
274 bool ok = (arg == value);
275 if (isOutputEnabled(ok)) {
288 bool (*op)(
bool lhs,
bool rhs),
291 if (isDone())
return false;
292 bool ok = op(lhs, rhs);
293 if (isOutputEnabled(ok)) {
306 bool (*op)(
char lhs,
char rhs),
309 if (isDone())
return false;
310 bool ok = op(lhs, rhs);
311 if (isOutputEnabled(ok)) {
324 bool (*op)(
int lhs,
int rhs),
327 if (isDone())
return false;
328 bool ok = op(lhs, rhs);
329 if (isOutputEnabled(ok)) {
342 bool (*op)(
unsigned int lhs,
unsigned int rhs),
345 if (isDone())
return false;
346 bool ok = op(lhs, rhs);
347 if (isOutputEnabled(ok)) {
360 bool (*op)(
long lhs,
long rhs),
363 if (isDone())
return false;
364 bool ok = op(lhs, rhs);
365 if (isOutputEnabled(ok)) {
378 bool (*op)(
unsigned long lhs,
unsigned long rhs),
381 if (isDone())
return false;
382 bool ok = op(lhs, rhs);
383 if (isOutputEnabled(ok)) {
396 bool (*op)(
long long lhs,
long long rhs),
399 if (isDone())
return false;
400 bool ok = op(lhs, rhs);
401 if (isOutputEnabled(ok)) {
412 unsigned long long lhs,
414 bool (*op)(
unsigned long long lhs,
unsigned long long rhs),
415 unsigned long long rhs
417 if (isDone())
return false;
418 bool ok = op(lhs, rhs);
419 if (isOutputEnabled(ok)) {
432 bool (*op)(
double lhs,
double rhs),
435 if (isDone())
return false;
436 bool ok = op(lhs, rhs);
437 if (isOutputEnabled(ok)) {
450 bool (*op)(
const void* lhs,
const void* rhs),
453 if (isDone())
return false;
454 bool ok = op(lhs, rhs);
455 if (isOutputEnabled(ok)) {
468 bool (*op)(
const char* lhs,
const char* rhs),
471 if (isDone())
return false;
472 bool ok = op(lhs, rhs);
473 if (isOutputEnabled(ok)) {
486 bool (*op)(
const char* lhs,
const String& rhs),
489 if (isDone())
return false;
490 bool ok = op(lhs, rhs);
491 if (isOutputEnabled(ok)) {
504 bool (*op)(
const char* lhs,
const __FlashStringHelper* rhs),
505 const __FlashStringHelper* rhs
507 if (isDone())
return false;
508 bool ok = op(lhs, rhs);
509 if (isOutputEnabled(ok)) {
522 bool (*op)(
const String& lhs,
const char* rhs),
525 if (isDone())
return false;
526 bool ok = op(lhs, rhs);
527 if (isOutputEnabled(ok)) {
540 bool (*op)(
const String& lhs,
const String& rhs),
543 if (isDone())
return false;
544 bool ok = op(lhs, rhs);
545 if (isOutputEnabled(ok)) {
558 bool (*op)(
const String& lhs,
const __FlashStringHelper* rhs),
559 const __FlashStringHelper* rhs
561 if (isDone())
return false;
562 bool ok = op(lhs, rhs);
563 if (isOutputEnabled(ok)) {
574 const __FlashStringHelper* lhs,
576 bool (*op)(
const __FlashStringHelper* lhs,
const char* rhs),
579 if (isDone())
return false;
580 bool ok = op(lhs, rhs);
581 if (isOutputEnabled(ok)) {
592 const __FlashStringHelper* lhs,
594 bool (*op)(
const __FlashStringHelper* lhs,
const String& rhs),
597 if (isDone())
return false;
598 bool ok = op(lhs, rhs);
599 if (isOutputEnabled(ok)) {
610 const __FlashStringHelper* lhs,
612 bool (*op)(
const __FlashStringHelper* lhs,
const __FlashStringHelper* rhs),
613 const __FlashStringHelper* rhs
615 if (isDone())
return false;
616 bool ok = op(lhs, rhs);
617 if (isOutputEnabled(ok)) {
632 bool (*opNear)(
int lhs,
int rhs,
int error)
634 if (isDone())
return false;
635 bool ok = opNear(lhs, rhs, error);
636 if (isOutputEnabled(ok)) {
638 lhs, rhs, opName, error);
651 bool (*opNear)(
unsigned int lhs,
unsigned int rhs,
unsigned int error)
653 if (isDone())
return false;
654 bool ok = opNear(lhs, rhs, error);
655 if (isOutputEnabled(ok)) {
657 lhs, rhs, opName, error);
670 bool (*opNear)(
long lhs,
long rhs,
long error)
672 if (isDone())
return false;
673 bool ok = opNear(lhs, rhs, error);
674 if (isOutputEnabled(ok)) {
676 lhs, rhs, opName, error);
689 bool (*opNear)(
unsigned long lhs,
unsigned long rhs,
unsigned long error)
691 if (isDone())
return false;
692 bool ok = opNear(lhs, rhs, error);
693 if (isOutputEnabled(ok)) {
695 lhs, rhs, opName, error);
708 bool (*opNear)(
double lhs,
double rhs,
double error)
710 if (isDone())
return false;
711 bool ok = opNear(lhs, rhs, error);
712 if (isOutputEnabled(ok)) {
714 lhs, rhs, opName, error);
730 template <
typename A,
typename B>
731 void printAssertionMessageVerbose(
737 const __FlashStringHelper* lhsString,
740 const __FlashStringHelper* rhsString
748 printer->print(
"Assertion ");
749 printer->print(ok ?
"passed" :
"failed");
750 printer->print(
": (");
751 printer->print(lhsString);
754 printer->print(
") ");
755 printer->print(opName);
756 printer->print(
" (");
757 printer->print(rhsString);
762 printer->print(
", file ");
763 printer->print(file);
764 printer->print(
", line ");
765 printer->print(line);
766 printer->println(
'.');
772 void printAssertionMessageVerbose(
778 const __FlashStringHelper* lhsString,
781 const __FlashStringHelper* rhsString
785 printer->print(
"Assertion ");
786 printer->print(ok ?
"passed" :
"failed");
787 printer->print(
": (");
788 printer->print(lhsString);
790 printer->print(lhs ?
"true" :
"false");
791 printer->print(
") ");
792 printer->print(opName);
793 printer->print(
" (");
794 printer->print(rhsString);
796 printer->print(rhs ?
"true" :
"false");
798 printer->print(
", file ");
799 printer->print(file);
800 printer->print(
", line ");
801 printer->print(line);
802 printer->println(
'.');
805 #if ! defined(ARDUINO_ARCH_STM32)
808 void printAssertionMessageVerbose(
814 const __FlashStringHelper* lhsString,
817 const __FlashStringHelper* rhsString
821 printer->print(
"Assertion ");
822 printer->print(ok ?
"passed" :
"failed");
823 printer->print(
": (");
824 printer->print(lhsString);
826 print64(*printer, lhs);
827 printer->print(
") ");
828 printer->print(opName);
829 printer->print(
" (");
830 printer->print(rhsString);
832 print64(*printer, rhs);
834 printer->print(
", file ");
835 printer->print(file);
836 printer->print(
", line ");
837 printer->print(line);
838 printer->println(
'.');
843 void printAssertionMessageVerbose(
848 unsigned long long& lhs,
849 const __FlashStringHelper* lhsString,
851 unsigned long long& rhs,
852 const __FlashStringHelper* rhsString
856 printer->print(
"Assertion ");
857 printer->print(ok ?
"passed" :
"failed");
858 printer->print(
": (");
859 printer->print(lhsString);
861 print64(*printer, lhs);
862 printer->print(
") ");
863 printer->print(opName);
864 printer->print(
" (");
865 printer->print(rhsString);
867 print64(*printer, rhs);
869 printer->print(
", file ");
870 printer->print(file);
871 printer->print(
", line ");
872 printer->print(line);
873 printer->println(
'.');
876 #endif // ARDUINO_ARCH_STM32
879 void printAssertionMessageVerbose(
885 const __FlashStringHelper* lhsString,
888 const __FlashStringHelper* rhsString
895 printer->print(
"Assertion ");
896 printer->print(ok ?
"passed" :
"failed");
897 printer->print(
": (");
898 printer->print(lhsString);
899 printer->print(
"=0x");
900 printer->print((
unsigned long) lhs, HEX);
901 printer->print(
") ");
902 printer->print(opName);
903 printer->print(
" (");
904 printer->print(rhsString);
905 printer->print(
"=0x");
906 printer->print((
unsigned long) rhs, HEX);
908 printer->print(
", file ");
909 printer->print(file);
910 printer->print(
", line ");
911 printer->print(line);
912 printer->println(
'.');
919 void printAssertionBoolMessageVerbose(
925 const __FlashStringHelper* argString,
930 printer->print(
"Assertion ");
931 printer->print(ok ?
"passed" :
"failed");
932 printer->print(
": (");
933 printer->print(argString);
935 printer->print(arg ?
"true" :
"false");
936 printer->print(
") is ");
937 printer->print(value ?
"true" :
"false");
938 printer->print(
", file ");
939 printer->print(file);
940 printer->print(
", line ");
941 printer->print(line);
942 printer->println(
'.');
945 template <
typename A>
946 void printAssertionNearMessageVerbose(
952 const __FlashStringHelper* lhsString,
954 const __FlashStringHelper* rhsString,
957 const __FlashStringHelper* errorString
959 printer->print(
"Assertion ");
960 printer->print(ok ?
"passed" :
"failed");
961 printer->print(
": |(");
962 printer->print(lhsString);
965 printer->print(
") - (");
966 printer->print(rhsString);
969 printer->print(
")| ");
970 printer->print(opName);
971 printer->print(
" (");
972 printer->print(errorString);
974 printer->print(error);
976 printer->print(
", file ");
977 printer->print(file);
978 printer->print(
", line ");
979 printer->print(line);
980 printer->println(
'.');
989 const __FlashStringHelper* argString,
992 if (isDone())
return false;
993 bool ok = (arg == value);
994 if (isOutputEnabled(ok)) {
996 arg, argString, value);
1006 const __FlashStringHelper* lhsString,
1008 bool (*op)(
bool lhs,
bool rhs),
1010 const __FlashStringHelper* rhsString
1012 if (isDone())
return false;
1013 bool ok = op(lhs, rhs);
1014 if (isOutputEnabled(ok)) {
1016 lhs, lhsString, opName, rhs, rhsString);
1026 const __FlashStringHelper* lhsString,
1028 bool (*op)(
char lhs,
char rhs),
1030 const __FlashStringHelper* rhsString
1032 if (isDone())
return false;
1033 bool ok = op(lhs, rhs);
1034 if (isOutputEnabled(ok)) {
1036 lhs, lhsString, opName, rhs, rhsString);
1046 const __FlashStringHelper* lhsString,
1048 bool (*op)(
int lhs,
int rhs),
1050 const __FlashStringHelper* rhsString
1052 if (isDone())
return false;
1053 bool ok = op(lhs, rhs);
1054 if (isOutputEnabled(ok)) {
1056 lhs, lhsString, opName, rhs, rhsString);
1066 const __FlashStringHelper* lhsString,
1068 bool (*op)(
unsigned int lhs,
unsigned int rhs),
1070 const __FlashStringHelper* rhsString
1072 if (isDone())
return false;
1073 bool ok = op(lhs, rhs);
1074 if (isOutputEnabled(ok)) {
1076 lhs, lhsString, opName, rhs, rhsString);
1086 const __FlashStringHelper* lhsString,
1088 bool (*op)(
long lhs,
long rhs),
1090 const __FlashStringHelper* rhsString
1092 if (isDone())
return false;
1093 bool ok = op(lhs, rhs);
1094 if (isOutputEnabled(ok)) {
1096 lhs, lhsString, opName, rhs, rhsString);
1106 const __FlashStringHelper* lhsString,
1108 bool (*op)(
unsigned long lhs,
unsigned long rhs),
1110 const __FlashStringHelper* rhsString
1112 if (isDone())
return false;
1113 bool ok = op(lhs, rhs);
1114 if (isOutputEnabled(ok)) {
1116 lhs, lhsString, opName, rhs, rhsString);
1126 const __FlashStringHelper* lhsString,
1128 bool (*op)(
long long lhs,
long long rhs),
1130 const __FlashStringHelper* rhsString
1132 if (isDone())
return false;
1133 bool ok = op(lhs, rhs);
1134 if (isOutputEnabled(ok)) {
1136 lhs, lhsString, opName, rhs, rhsString);
1145 unsigned long long lhs,
1146 const __FlashStringHelper* lhsString,
1148 bool (*op)(
unsigned long long lhs,
unsigned long long rhs),
1149 unsigned long long rhs,
1150 const __FlashStringHelper* rhsString
1152 if (isDone())
return false;
1153 bool ok = op(lhs, rhs);
1154 if (isOutputEnabled(ok)) {
1156 lhs, lhsString, opName, rhs, rhsString);
1166 const __FlashStringHelper* lhsString,
1168 bool (*op)(
double lhs,
double rhs),
1170 const __FlashStringHelper* rhsString
1172 if (isDone())
return false;
1173 bool ok = op(lhs, rhs);
1174 if (isOutputEnabled(ok)) {
1176 lhs, lhsString, opName, rhs, rhsString);
1186 const __FlashStringHelper* lhsString,
1188 bool (*op)(
const void* lhs,
const void* rhs),
1190 const __FlashStringHelper* rhsString
1192 if (isDone())
return false;
1193 bool ok = op(lhs, rhs);
1194 if (isOutputEnabled(ok)) {
1196 lhs, lhsString, opName, rhs, rhsString);
1206 const __FlashStringHelper* lhsString,
1208 bool (*op)(
const char* lhs,
const char* rhs),
1210 const __FlashStringHelper* rhsString
1212 if (isDone())
return false;
1213 bool ok = op(lhs, rhs);
1214 if (isOutputEnabled(ok)) {
1216 lhs, lhsString, opName, rhs, rhsString);
1226 const __FlashStringHelper* lhsString,
1228 bool (*op)(
const char* lhs,
const String& rhs),
1230 const __FlashStringHelper* rhsString
1232 if (isDone())
return false;
1233 bool ok = op(lhs, rhs);
1234 if (isOutputEnabled(ok)) {
1236 lhs, lhsString, opName, rhs, rhsString);
1246 const __FlashStringHelper* lhsString,
1248 bool (*op)(
const char* lhs,
const __FlashStringHelper* rhs),
1249 const __FlashStringHelper* rhs,
1250 const __FlashStringHelper* rhsString
1252 if (isDone())
return false;
1253 bool ok = op(lhs, rhs);
1254 if (isOutputEnabled(ok)) {
1256 lhs, lhsString, opName, rhs, rhsString);
1266 const __FlashStringHelper* lhsString,
1268 bool (*op)(
const String& lhs,
const char* rhs),
1270 const __FlashStringHelper* rhsString
1272 if (isDone())
return false;
1273 bool ok = op(lhs, rhs);
1274 if (isOutputEnabled(ok)) {
1276 lhs, lhsString, opName, rhs, rhsString);
1286 const __FlashStringHelper* lhsString,
1288 bool (*op)(
const String& lhs,
const String& rhs),
1290 const __FlashStringHelper* rhsString
1292 if (isDone())
return false;
1293 bool ok = op(lhs, rhs);
1294 if (isOutputEnabled(ok)) {
1296 lhs, lhsString, opName, rhs, rhsString);
1306 const __FlashStringHelper* lhsString,
1308 bool (*op)(
const String& lhs,
const __FlashStringHelper* rhs),
1309 const __FlashStringHelper* rhs,
1310 const __FlashStringHelper* rhsString
1312 if (isDone())
return false;
1313 bool ok = op(lhs, rhs);
1314 if (isOutputEnabled(ok)) {
1316 lhs, lhsString, opName, rhs, rhsString);
1325 const __FlashStringHelper* lhs,
1326 const __FlashStringHelper* lhsString,
1328 bool (*op)(
const __FlashStringHelper* lhs,
1331 const __FlashStringHelper* rhsString
1333 if (isDone())
return false;
1334 bool ok = op(lhs, rhs);
1335 if (isOutputEnabled(ok)) {
1337 lhs, lhsString, opName, rhs, rhsString);
1346 const __FlashStringHelper* lhs,
1347 const __FlashStringHelper* lhsString,
1349 bool (*op)(
const __FlashStringHelper* lhs,
const String& rhs),
1351 const __FlashStringHelper* rhsString
1353 if (isDone())
return false;
1354 bool ok = op(lhs, rhs);
1355 if (isOutputEnabled(ok)) {
1357 lhs, lhsString, opName, rhs, rhsString);
1366 const __FlashStringHelper* lhs,
1367 const __FlashStringHelper* lhsString,
1369 bool (*op)(
const __FlashStringHelper* lhs,
const __FlashStringHelper* rhs),
1370 const __FlashStringHelper* rhs,
1371 const __FlashStringHelper* rhsString
1373 if (isDone())
return false;
1374 bool ok = op(lhs, rhs);
1375 if (isOutputEnabled(ok)) {
1377 lhs, lhsString, opName, rhs, rhsString);
1387 const __FlashStringHelper* lhsString,
1389 const __FlashStringHelper* rhsString,
1391 const __FlashStringHelper* errorString,
1393 bool (*opNear)(
int lhs,
int rhs,
int error)
1395 if (isDone())
return false;
1396 bool ok = opNear(lhs, rhs, error);
1397 if (isOutputEnabled(ok)) {
1399 lhs, lhsString, rhs, rhsString, opName, error, errorString);
1409 const __FlashStringHelper* lhsString,
1411 const __FlashStringHelper* rhsString,
1413 const __FlashStringHelper* errorString,
1415 bool (*opNear)(
unsigned int lhs,
unsigned int rhs,
unsigned int error)
1417 if (isDone())
return false;
1418 bool ok = opNear(lhs, rhs, error);
1419 if (isOutputEnabled(ok)) {
1421 lhs, lhsString, rhs, rhsString, opName, error, errorString);
1431 const __FlashStringHelper* lhsString,
1433 const __FlashStringHelper* rhsString,
1435 const __FlashStringHelper* errorString,
1437 bool (*opNear)(
long lhs,
long rhs,
long error)
1439 if (isDone())
return false;
1440 bool ok = opNear(lhs, rhs, error);
1441 if (isOutputEnabled(ok)) {
1443 lhs, lhsString, rhs, rhsString, opName, error, errorString);
1453 const __FlashStringHelper* lhsString,
1455 const __FlashStringHelper* rhsString,
1456 unsigned long error,
1457 const __FlashStringHelper* errorString,
1459 bool (*opNear)(
unsigned long lhs,
unsigned long rhs,
unsigned long error)
1461 if (isDone())
return false;
1462 bool ok = opNear(lhs, rhs, error);
1463 if (isOutputEnabled(ok)) {
1465 lhs, lhsString, rhs, rhsString, opName, error, errorString);
1475 const __FlashStringHelper* lhsString,
1477 const __FlashStringHelper* rhsString,
1479 const __FlashStringHelper* errorString,
1481 bool (*opNear)(
double lhs,
double rhs,
double error)
1483 if (isDone())
return false;
1484 bool ok = opNear(lhs, rhs, error);
1485 if (isOutputEnabled(ok)) {
1487 lhs, lhsString, rhs, rhsString, opName, error, errorString);