ArduinoUnit 2.0
 All Classes Files Functions Variables Macros
Classes | Macros | Functions
ArduinoUnit.h File Reference
#include <stdint.h>
#include <Print.h>
#include <utility/FakeStream.h>
#include <utility/MemoryFree.h>

Go to the source code of this file.

Classes

class  Test
 
class  TestOnce
 

Macros

#define ARDUINO_UNIT_MAJOR_VERSION   2
 This is defined to manage the API transition to 2.X.
 
#define ARDUINO_UNIT_MINOR_VERSION   0
 This is defined to manage the API transition to 2.X.
 
#define TEST_VERBOSITY_TESTS_SUMMARY   0x01
 Verbosity mask for overall summary (default). More...
 
#define TEST_VERBOSITY_TESTS_FAILED   0x02
 Verbosity mask for failed test summary (default). More...
 
#define TEST_VERBOSITY_TESTS_PASSED   0x04
 Verbosity mask for passed test summary (default). More...
 
#define TEST_VERBOSITY_TESTS_SKIPPED   0x08
 Verbosity mask for skipped test summary (default). More...
 
#define TEST_VERBOSITY_TESTS_ALL   0x0F
 Verbosity mask for resolved (skip, pass, or fail) test summary (default). More...
 
#define TEST_VERBOSITY_ASSERTIONS_FAILED   0x10
 Verbosity mask for failed assertions (default). More...
 
#define TEST_VERBOSITY_ASSERTIONS_PASSED   0x20
 Verbosity mask for passed assertions (default off). More...
 
#define TEST_VERBOSITY_ASSERTIONS_ALL   0x30
 Verbosity mask for all assertions (default fail). More...
 
#define TEST_VERBOSITY_ALL   0x3F
 
#define TEST_VERBOSITY_NONE   0x00
 
#define TEST_MAX_VERBOSITY   TEST_VERBOSITY_ALL
 
#define TEST_VERBOSITY_EXISTS(OF)   ((TEST_MAX_VERBOSITY & TEST_VERBOSITY_ ## OF) != 0)
 Check if given verbosity exists. (advanced) More...
 
#define TEST_VERBOSITY_ALLOWED(OF)   (TEST_VERBOSITY_EXISTS(OF) && ((Test::max_verbosity & TEST_VERBOSITY_ ## OF) != 0))
 Check if given verbosity exists. (advanced) More...
 
#define TEST_VERBOSITY_REQUIRED(OF)   (TEST_VERBOSITY_ALLOWED(OF) && ((Test::min_verbosity & TEST_VERBOSITY_ ## OF) != 0))
 Check if given verbosity is required. (advanced) More...
 
#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)))))
 Check if given verbosity is appropriate. (advanced) More...
 
#define test(name)   struct test_ ## name : TestOnce { test_ ## name() : TestOnce(F(#name)) {}; void once(); } test_ ## name ## _instance; void test_ ## name :: once()
 
#define externTest(name)   struct test_ ## name : TestOnce { test_ ## name(); void once(); }; extern test_##name test_##name##_instance
 
#define testing(name)   struct test_ ## name : Test { test_ ## name() : Test(F(#name)) {}; void loop(); } test_ ## name ## _instance; void test_ ## name :: loop()
 
#define externTesting(name)   struct test_ ## name : Test { test_ ## name(); void loop(); }; extern test_##name test_##name##_instance
 
#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;
 
#define assertEqual(arg1, arg2)   assertOp(arg1,isEqual,"==",arg2)
 
#define assertNotEqual(arg1, arg2)   assertOp(arg1,isNotEqual,"!=",arg2)
 
#define assertLess(arg1, arg2)   assertOp(arg1,isLess,"<",arg2)
 
#define assertMore(arg1, arg2)   assertOp(arg1,isMore,">",arg2)
 
#define assertLessOrEqual(arg1, arg2)   assertOp(arg1,isLessOrEqual,"<=",arg2)
 
#define assertMoreOrEqual(arg1, arg2)   assertOp(arg1,isMoreOrEqual,">=",arg2)
 
#define assertTrue(arg)   assertEqual(arg,true)
 
#define assertFalse(arg)   assertEqual(arg,false)
 
#define checkTestDone(name)   (test_##name##_instance.state >= Test::DONE_SKIP)
 
#define checkTestNotDone(name)   (test_##name##_instance.state < Test::DONE_SKIP)
 
#define checkTestPass(name)   (test_##name##_instance.state == Test::DONE_PASS)
 
#define checkTestNotPass(name)   (test_##name##_instance.state != Test::DONE_PASS)
 
#define checkTestFail(name)   (test_##name##_instance.state == Test::DONE_FAIL)
 
#define checkTestNotFail(name)   (test_##name##_instance.state != Test::DONE_FAIL)
 
#define checkTestSkip(name)   (test_##name##_instance.state == Test::DONE_SKIP)
 
#define checkTestNotSkip(name)   (test_##name##_instance.state != Test::DONE_SKIP)
 
#define assertTestDone(name)   assertMoreOrEqual(test_##name##_instance.state,Test::DONE_SKIP)
 
#define assertTestNotDone(name)   assertLess(test_##name##_instance.state,Test::DONE_SKIP)
 
#define assertTestPass(name)   assertEqual(test_##name##_instance.state,Test::DONE_PASS)
 
#define assertTestNotPass(name)   assertNotEqual(test_##name##_instance.state,Test::DONE_PASS)
 
#define assertTestFail(name)   assertEqual(test_##name##_instance.state,Test::DONE_FAIL)
 
#define assertTestNotFail(name)   assertNotEqual(test_##name##_instance.state,Test::DONE_FAIL)
 
#define assertTestSkip(name)   assertEqual(test_##name##_instance.state,Test::DONE_SKIP)
 
#define assertTestNotSkip(name)   assertNotEqual(test_##name##_instance.state,Test::DONE_SKIP)
 

Functions

template<typename T >
bool isEqual (const T &a, const T &b)
 
template<typename T >
bool isNotEqual (const T &a, const T &b)
 
template<typename T >
bool isLess (const T &a, const T &b)
 
template<typename T >
bool isMore (const T &a, const T &b)
 
template<typename T >
bool isLessOrEqual (const T &a, const T &b)
 
template<typename T >
bool isMoreOrEqual (const T &a, const T &b)
 
template<>
bool isLess< const char * > (const char *const &a, const char *const &b)
 
template<>
bool isLessOrEqual< const char * > (const char *const &a, const char *const &b)
 
template<>
bool isEqual< const char * > (const char *const &a, const char *const &b)
 
template<>
bool isNotEqual< const char * > (const char *const &a, const char *const &b)
 
template<>
bool isMore< const char * > (const char *const &a, const char *const &b)
 
template<>
bool isMoreOrEqual< const char * > (const char *const &a, const char *const &b)
 

Macro Definition Documentation

#define assertEqual (   arg1,
  arg2 
)    assertOp(arg1,isEqual,"==",arg2)

macro generates optional output and calls fail() followed by a return if false.

#define assertFalse (   arg)    assertEqual(arg,false)

macro generates optional output and calls fail() followed by a return if false.

#define assertLess (   arg1,
  arg2 
)    assertOp(arg1,isLess,"<",arg2)

macro generates optional output and calls fail() followed by a return if false.

#define assertLessOrEqual (   arg1,
  arg2 
)    assertOp(arg1,isLessOrEqual,"<=",arg2)

macro generates optional output and calls fail() followed by a return if false.

#define assertMore (   arg1,
  arg2 
)    assertOp(arg1,isMore,">",arg2)

macro generates optional output and calls fail() followed by a return if false.

#define assertMoreOrEqual (   arg1,
  arg2 
)    assertOp(arg1,isMoreOrEqual,">=",arg2)

macro generates optional output and calls fail() followed by a return if false.

#define assertNotEqual (   arg1,
  arg2 
)    assertOp(arg1,isNotEqual,"!=",arg2)

macro generates optional output and calls fail() followed by a return if false.

#define assertTestDone (   name)    assertMoreOrEqual(test_##name##_instance.state,Test::DONE_SKIP)

macro generates optional output and calls fail() followed by a return if false.

#define assertTestFail (   name)    assertEqual(test_##name##_instance.state,Test::DONE_FAIL)

macro generates optional output and calls fail() followed by a return if false.

#define assertTestNotDone (   name)    assertLess(test_##name##_instance.state,Test::DONE_SKIP)

macro generates optional output and calls fail() followed by a return if false.

#define assertTestNotFail (   name)    assertNotEqual(test_##name##_instance.state,Test::DONE_FAIL)

macro generates optional output and calls fail() followed by a return if false.

#define assertTestNotPass (   name)    assertNotEqual(test_##name##_instance.state,Test::DONE_PASS)

macro generates optional output and calls fail() followed by a return if false.

#define assertTestNotSkip (   name)    assertNotEqual(test_##name##_instance.state,Test::DONE_SKIP)

macro generates optional output and calls fail() followed by a return if false.

#define assertTestPass (   name)    assertEqual(test_##name##_instance.state,Test::DONE_PASS)

macro generates optional output and calls fail() followed by a return if false.

#define assertTestSkip (   name)    assertEqual(test_##name##_instance.state,Test::DONE_SKIP)

macro generates optional output and calls fail() followed by a return if false.

#define assertTrue (   arg)    assertEqual(arg,true)

macro generates optional output and calls fail() followed by a return if false.

#define checkTestFail (   name)    (test_##name##_instance.state == Test::DONE_FAIL)

check condition only

#define checkTestNotDone (   name)    (test_##name##_instance.state < Test::DONE_SKIP)

check condition only

#define checkTestNotFail (   name)    (test_##name##_instance.state != Test::DONE_FAIL)

check condition only

#define checkTestNotPass (   name)    (test_##name##_instance.state != Test::DONE_PASS)

check condition only

#define checkTestNotSkip (   name)    (test_##name##_instance.state != Test::DONE_SKIP)

check condition only

#define checkTestPass (   name)    (test_##name##_instance.state == Test::DONE_PASS)

check condition only

#define checkTestSkip (   name)    (test_##name##_instance.state == Test::DONE_SKIP)

check condition only

#define externTest (   name)    struct test_ ## name : TestOnce { test_ ## name(); void once(); }; extern test_##name test_##name##_instance
Create an extern reference to a test-once test defined elsewhere.

This is only necessary if you use assertTestXXXX when the test is in another file (or defined after the assertion on it).

#define externTesting (   name)    struct test_ ## name : Test { test_ ## name(); void loop(); }; extern test_##name test_##name##_instance
Create an extern reference to a test-until-skip-pass-or-fail defined

elsewhere. This is only necessary if you use assertTestXXXX when the test is in another file (or defined after the assertion on it).

#define test (   name)    struct test_ ## name : TestOnce { test_ ## name() : TestOnce(F(#name)) {}; void once(); } test_ ## name ## _instance; void test_ ## name :: once()

Create a test-once test, usually checked with assertXXXX. The test is assumed to pass unless failed or skipped.

#define TEST_MAX_VERBOSITY   TEST_VERBOSITY_ALL

Define what output code is included in the in the library (default TEST_VERBOSITY_ALL).

Clearing a mask in TEST_MAX_VERBOSITY eliminates the code related to that kind of output. Change this only to save PROGMEM space.

#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)))))

Check if given verbosity is appropriate. (advanced)

This would only rarely be useful in custom assertions.

#define TEST_VERBOSITY_ALL   0x3F

This is the default value for TEST_MAX_VERBOSITY, and Test::max_verbosity is this, so no output is globally suppressed.

#define TEST_VERBOSITY_ALLOWED (   OF)    (TEST_VERBOSITY_EXISTS(OF) && ((Test::max_verbosity & TEST_VERBOSITY_ ## OF) != 0))

Check if given verbosity exists. (advanced)

This is used to mask out code that would never be executed due to a cleared flag in TEST_MAX_VERBOSITY. It is used in, for example:

#if TEST_VERBOSITY_EXISTS(TESTS_SKIPPED)
   maybe output something
#endif

This would only rarely be useful in custom assertions.Check if given verbosity is allowed. (advanced)

This would only rarely be useful in custom assertions.

#define TEST_VERBOSITY_ASSERTIONS_ALL   0x30

Verbosity mask for all assertions (default fail).

Verbosity mask for a 1-line summary of failed assertions of the form:

FILE:LINE:1 (pass|fail) assert (NAME1=VALUE1) OP (NAME2=VALUE2)
#define TEST_VERBOSITY_ASSERTIONS_FAILED   0x10

Verbosity mask for failed assertions (default).

Verbosity mask for a 1-line summary of failed assertions of the form:

FILE:LINE:1 fail assert (NAME1=VALUE1) OP (NAME2=VALUE2)
#define TEST_VERBOSITY_ASSERTIONS_PASSED   0x20

Verbosity mask for passed assertions (default off).

Verbosity mask for a 1-line summary of passed assertions of the form:

FILE:LINE:1 pass assert (NAME1=VALUE1) OP (NAME2=VALUE2)
#define TEST_VERBOSITY_EXISTS (   OF)    ((TEST_MAX_VERBOSITY & TEST_VERBOSITY_ ## OF) != 0)

Check if given verbosity exists. (advanced)

This is used to mask out code that would never be executed due to a cleared flag in TEST_MAX_VERBOSITY. It is used in, for example:

#if TEST_VERBOSITY_EXISTS(TESTS_SKIPPED)
   maybe output something
#endif

This would only rarely be useful in custom assertions.

#define TEST_VERBOSITY_NONE   0x00

Verbosity mask for no verbostiy. The default value of Test::min_verbosity asks that failed assertions and test summaries be generated (TEST_VERBOSITY_TESTS_ALL|TEST_VERBOSITY_ASSERTIONS_FAILED).

#define TEST_VERBOSITY_REQUIRED (   OF)    (TEST_VERBOSITY_ALLOWED(OF) && ((Test::min_verbosity & TEST_VERBOSITY_ ## OF) != 0))

Check if given verbosity is required. (advanced)

This would only rarely be useful in custom assertions.

#define TEST_VERBOSITY_TESTS_ALL   0x0F

Verbosity mask for resolved (skip, pass, or fail) test summary (default).

Verbosity mask for a 1-line summary of a resolved test of the form:

test NAME (passed|failed|skipped).

This summary happens once the given test resolves (pass, fail, or skip).

#define TEST_VERBOSITY_TESTS_FAILED   0x02

Verbosity mask for failed test summary (default).

Verbosity mask for a 1-line summary of a failed test of the form:

test NAME failed.

This summary happens once the given test resolves (pass, fail, or skip).

#define TEST_VERBOSITY_TESTS_PASSED   0x04

Verbosity mask for passed test summary (default).

Verbosity mask for a 1-line summary of a passed test of the form:

test NAME passed.

This summary happens once the given test resolves (pass, fail, or skip).

#define TEST_VERBOSITY_TESTS_SKIPPED   0x08

Verbosity mask for skipped test summary (default).

Verbosity mask for a 1-line summary of a skipped test of the form:

test NAME skipped.

This summary happens once the given test resolves (pass, fail, or skip).

#define TEST_VERBOSITY_TESTS_SUMMARY   0x01

Verbosity mask for overall summary (default).

Verbosity mask for a 1-line summary of the form:

test summary: P passed, F failed, and S skipped out of T test(s).

This summary happens once all the tests have been resolved (pass, fail or skip).

#define testing (   name)    struct test_ ## name : Test { test_ ## name() : Test(F(#name)) {}; void loop(); } test_ ## name ## _instance; void test_ ## name :: loop()
Create an extern reference to a test-until-skip-pass-or-fail test

defined elsewhere.

This is only necessary if you use assertTestXXXX when the test is in another file (or defined after the assertion on it).

Function Documentation

template<typename T >
bool isEqual ( const T &  a,
const T &  b 
)

Template binary operator== to assist with assertions

template<>
bool isEqual< const char * > ( const char *const &  a,
const char *const &  b 
)

Template specialization for asserting const char * types

template<typename T >
bool isLess ( const T &  a,
const T &  b 
)

Template binary operator< to assist with assertions

template<>
bool isLess< const char * > ( const char *const &  a,
const char *const &  b 
)

Template specialization for asserting const char * types

template<typename T >
bool isLessOrEqual ( const T &  a,
const T &  b 
)

Template binary operator<= to assist with assertions

template<>
bool isLessOrEqual< const char * > ( const char *const &  a,
const char *const &  b 
)

Template specialization for asserting const char * types

template<typename T >
bool isMore ( const T &  a,
const T &  b 
)

Template binary operator> to assist with assertions

template<>
bool isMore< const char * > ( const char *const &  a,
const char *const &  b 
)

Template specialization for asserting const char * types

template<typename T >
bool isMoreOrEqual ( const T &  a,
const T &  b 
)

Template binary operator>= to assist with assertions

template<>
bool isMoreOrEqual< const char * > ( const char *const &  a,
const char *const &  b 
)

Template specialization for asserting const char * types

template<typename T >
bool isNotEqual ( const T &  a,
const T &  b 
)

Template binary operator!= to assist with assertions

template<>
bool isNotEqual< const char * > ( const char *const &  a,
const char *const &  b 
)

Template specialization for asserting const char * types