12 #if ARDUINO >= 100 && ARDUINO < 103
15 #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
17 #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
21 #if defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ < 407)
25 #define PROGMEM __attribute__((section(".progmem.data")))
29 #include <utility/FakeStream.h>
30 #include <utility/MemoryFree.h>
33 #define ARDUINO_UNIT_MAJOR_VERSION 2
36 #define ARDUINO_UNIT_MINOR_VERSION 0
51 #define TEST_VERBOSITY_TESTS_SUMMARY 0x01
62 #define TEST_VERBOSITY_TESTS_FAILED 0x02
73 #define TEST_VERBOSITY_TESTS_PASSED 0x04
85 #define TEST_VERBOSITY_TESTS_SKIPPED 0x08
97 #define TEST_VERBOSITY_TESTS_ALL 0x0F
107 #define TEST_VERBOSITY_ASSERTIONS_FAILED 0x10
117 #define TEST_VERBOSITY_ASSERTIONS_PASSED 0x20
127 #define TEST_VERBOSITY_ASSERTIONS_ALL 0x30
132 #define TEST_VERBOSITY_ALL 0x3F
137 #define TEST_VERBOSITY_NONE 0x00
140 #ifndef TEST_MAX_VERBOSITY
146 #define TEST_MAX_VERBOSITY TEST_VERBOSITY_ALL
162 #define TEST_VERBOSITY_EXISTS(OF) ((TEST_MAX_VERBOSITY & TEST_VERBOSITY_ ## OF) != 0)
182 #define TEST_VERBOSITY_ALLOWED(OF) (TEST_VERBOSITY_EXISTS(OF) && ((Test::max_verbosity & TEST_VERBOSITY_ ## OF) != 0))
189 #define TEST_VERBOSITY_REQUIRED(OF) (TEST_VERBOSITY_ALLOWED(OF) && ((Test::min_verbosity & TEST_VERBOSITY_ ## OF) != 0))
196 #define TEST_VERBOSITY(OF) (TEST_VERBOSITY_ALLOWED(OF) && (((Test::min_verbosity & TEST_VERBOSITY_ ## OF ) != 0) || (((Test::current != 0) && ((Test::current->verbosity & TEST_VERBOSITY_ ## OF) != 0)))))
283 class String :
public Printable {
286 String(
const char *_data);
287 String(
const __FlashStringHelper *_data);
288 void read(
void *destination, uint16_t offset, uint8_t length)
const;
289 uint16_t length()
const;
290 int8_t compare(
const Test::String &to)
const;
291 size_t printTo(Print &p)
const;
292 bool matches(
const char *pattern)
const;
301 static uint16_t passed;
302 static uint16_t failed;
303 static uint16_t skipped;
304 static uint16_t count;
323 static inline uint16_t getCurrentPassed() {
return passed; }
324 static inline uint16_t getCurrentSkipped() {
return skipped; }
325 static inline uint16_t getCurrentFailed() {
return failed; }
326 static uint16_t getCurrentCount() {
return count; }
420 virtual void setup();
423 virtual void loop() = 0;
435 static void include(
const char *pattern);
445 static void exclude(
const char *pattern);
481 template <
typename T>
482 static bool assertion(
const __FlashStringHelper *file, uint16_t line,
const __FlashStringHelper *lhss,
const T& lhs,
const __FlashStringHelper *ops,
bool (*op)(
const T& lhs,
const T& rhs),
const __FlashStringHelper *rhss,
const T& rhs) {
483 bool ok = op(lhs,rhs);
488 #if TEST_VERBOSITY_EXISTS(ASSERTIONS_PASSED)
494 #if TEST_VERBOSITY_EXISTS(ASSERTIONS_FAILED)
500 #if TEST_VERBOSITY_EXISTS(ASSERTIONS_FAILED) || TEST_VERBOSITY_EXISTS(ASSERTIONS_PASSED)
505 out->print(F(
":1: "));
506 out->print(ok ? F(
"pass") : F(
"fail"));
507 out->print(F(
" assert ("));
533 virtual void once() = 0;
537 template <
typename T>
538 bool isEqual(
const T& a,
const T& b) {
return a==b; }
541 template <
typename T>
545 template <
typename T>
546 bool isLess(
const T& a,
const T& b) {
return a < b; }
549 template <
typename T>
550 bool isMore(
const T& a,
const T& b) {
return b < a; }
553 template <
typename T>
557 template <
typename T>
561 template <>
bool isLess<const char*>(
const char*
const &a,
const char*
const &b);
564 template <>
bool isLessOrEqual<const char*>(
const char*
const &a,
const char*
const &b);
567 template <>
bool isEqual<const char*>(
const char*
const &a,
const char*
const &b);
570 template <>
bool isNotEqual<const char*>(
const char*
const &a,
const char*
const &b);
573 template <>
bool isMore<const char*>(
const char*
const &a,
const char*
const &b);
576 template <>
bool isMoreOrEqual<const char*>(
const char*
const &a,
const char*
const &b);
581 #define test(name) struct test_ ## name : TestOnce { test_ ## name() : TestOnce(F(#name)) {}; void once(); } test_ ## name ## _instance; void test_ ## name :: once()
587 #define externTest(name) struct test_ ## name : TestOnce { test_ ## name(); void once(); }; extern test_##name test_##name##_instance
594 #define testing(name) struct test_ ## name : Test { test_ ## name() : Test(F(#name)) {}; void loop(); } test_ ## name ## _instance; void test_ ## name :: loop()
599 #define externTesting(name) struct test_ ## name : Test { test_ ## name(); void loop(); }; extern test_##name test_##name##_instance
602 #define assertOp(arg1,op,op_name,arg2) if (!Test::assertion<typeof(arg2)>(F(__FILE__),__LINE__,F(#arg1),(arg1),F(op_name),op,F(#arg2),(arg2))) return;
605 #define assertEqual(arg1,arg2) assertOp(arg1,isEqual,"==",arg2)
608 #define assertNotEqual(arg1,arg2) assertOp(arg1,isNotEqual,"!=",arg2)
611 #define assertLess(arg1,arg2) assertOp(arg1,isLess,"<",arg2)
614 #define assertMore(arg1,arg2) assertOp(arg1,isMore,">",arg2)
617 #define assertLessOrEqual(arg1,arg2) assertOp(arg1,isLessOrEqual,"<=",arg2)
620 #define assertMoreOrEqual(arg1,arg2) assertOp(arg1,isMoreOrEqual,">=",arg2)
623 #define assertTrue(arg) assertEqual(arg,true)
626 #define assertFalse(arg) assertEqual(arg,false)
628 #define checkTestDone(name) (test_##name##_instance.state >= Test::DONE_SKIP)
631 #define checkTestNotDone(name) (test_##name##_instance.state < Test::DONE_SKIP)
634 #define checkTestPass(name) (test_##name##_instance.state == Test::DONE_PASS)
637 #define checkTestNotPass(name) (test_##name##_instance.state != Test::DONE_PASS)
640 #define checkTestFail(name) (test_##name##_instance.state == Test::DONE_FAIL)
643 #define checkTestNotFail(name) (test_##name##_instance.state != Test::DONE_FAIL)
646 #define checkTestSkip(name) (test_##name##_instance.state == Test::DONE_SKIP)
649 #define checkTestNotSkip(name) (test_##name##_instance.state != Test::DONE_SKIP)
652 #define assertTestDone(name) assertMoreOrEqual(test_##name##_instance.state,Test::DONE_SKIP)
654 #define assertTestNotDone(name) assertLess(test_##name##_instance.state,Test::DONE_SKIP)
657 #define assertTestPass(name) assertEqual(test_##name##_instance.state,Test::DONE_PASS)
660 #define assertTestNotPass(name) assertNotEqual(test_##name##_instance.state,Test::DONE_PASS)
663 #define assertTestFail(name) assertEqual(test_##name##_instance.state,Test::DONE_FAIL)
666 #define assertTestNotFail(name) assertNotEqual(test_##name##_instance.state,Test::DONE_FAIL)
669 #define assertTestSkip(name) assertEqual(test_##name##_instance.state,Test::DONE_SKIP)
672 #define assertTestNotSkip(name) assertNotEqual(test_##name##_instance.state,Test::DONE_SKIP)