TestBase.h File Reference
#include <WString.h>
#include <debug_progmem.h>
Include dependency graph for TestBase.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  TestBase
 Base class supporting verification for test assertions. More...
 
struct  TestBase::TestParam
 Contains details for test verification. More...
 

Macros

#define TEST_ASSERT(result)
 Check a test result. More...
 
Internal check macros
#define INTERNAL_CHECK(expr, verbose)   INTERNAL_CHECK2(expr, expr, verbose)
 
#define INTERNAL_CHECK2(res, expr, verbose)
 
#define INTERNAL_CHECK_EQ(a, b, verbose)
 
#define INTERNAL_CHECK_NEQ(a, b, verbose)
 
Check an expression, print message for success or failure (verbose)
#define CHECK(expr)   INTERNAL_CHECK(expr, false)
 Check expression evaluates to true. More...
 
#define CHECK2(res, expr)   INTERNAL_CHECK2(res, expr, false)
 Provide separate test result and expression. More...
 
#define CHECK_EQ(a, b)   INTERNAL_CHECK_EQ(a, b, false)
 Check two values are the same. More...
 
#define CHECK_NEQ(a, b)   INTERNAL_CHECK_NEQ(a, b, false)
 Check two values are not the same. More...
 
Check an expression, but only print message on failure
#define REQUIRE(expr)   INTERNAL_CHECK(expr, true)
 Check expression evaluates to true. More...
 
#define REQUIRE2(res, expr)   INTERNAL_CHECK2(res, expr, true)
 Provide separate test result and expression. More...
 
#define REQUIRE_EQ(a, b)   INTERNAL_CHECK_EQ(a, b, true)
 Check two values are the same. More...
 
#define REQUIRE_NEQ(a, b)   INTERNAL_CHECK_NEQ(a, b, true)
 Check two values are not the same. More...
 

Macro Definition Documentation

◆ CHECK

#define CHECK (   expr)    INTERNAL_CHECK(expr, false)

Check expression evaluates to true.

Parameters
expr

◆ CHECK2

#define CHECK2 (   res,
  expr 
)    INTERNAL_CHECK2(res, expr, false)

Provide separate test result and expression.

Parameters
resResult of test
exprExpression to display

◆ CHECK_EQ

#define CHECK_EQ (   a,
 
)    INTERNAL_CHECK_EQ(a, b, false)

Check two values are the same.

Parameters
a
b

◆ CHECK_NEQ

#define CHECK_NEQ (   a,
 
)    INTERNAL_CHECK_NEQ(a, b, false)

Check two values are not the same.

Parameters
a
b

◆ INTERNAL_CHECK

#define INTERNAL_CHECK (   expr,
  verbose 
)    INTERNAL_CHECK2(expr, expr, verbose)

◆ INTERNAL_CHECK2

#define INTERNAL_CHECK2 (   res,
  expr,
  verbose 
)
Value:
do { \
PSTR_ARRAY(tmpExprStr, #expr); \
if(!testVerify(bool(res), TestParam{tmpExprStr, nullptr, nullptr, verbose})) { \
TEST_ASSERT(false); \
} \
} while(0)

◆ INTERNAL_CHECK_EQ

#define INTERNAL_CHECK_EQ (   a,
  b,
  verbose 
)
Value:
do { \
PSTR_ARRAY(tmpExprStr, #a " == " #b); \
const auto value_a = a; \
const decltype(value_a) value_b = b; \
if(!test_verify(value_a == value_b, tmpExprStr, value_a, value_b, verbose)) { \
TEST_ASSERT(false); \
} \
} while(0)

◆ INTERNAL_CHECK_NEQ

#define INTERNAL_CHECK_NEQ (   a,
  b,
  verbose 
)
Value:
do { \
PSTR_ARRAY(tmpExprStr, #a " != " #b); \
const auto value_a = a; \
const decltype(value_a) value_b = b; \
if(!test_verify(value_a != value_b, tmpExprStr, value_a, value_b, verbose)) { \
TEST_ASSERT(false); \
} \
} while(0)

◆ REQUIRE

#define REQUIRE (   expr)    INTERNAL_CHECK(expr, true)

Check expression evaluates to true.

Parameters
expr

◆ REQUIRE2

#define REQUIRE2 (   res,
  expr 
)    INTERNAL_CHECK2(res, expr, true)

Provide separate test result and expression.

Parameters
resResult of test
exprExpression to display

◆ REQUIRE_EQ

#define REQUIRE_EQ (   a,
 
)    INTERNAL_CHECK_EQ(a, b, true)

Check two values are the same.

Parameters
a
b

◆ REQUIRE_NEQ

#define REQUIRE_NEQ (   a,
 
)    INTERNAL_CHECK_NEQ(a, b, true)

Check two values are not the same.

Parameters
a
b

◆ TEST_ASSERT

#define TEST_ASSERT (   result)
Value:
if(!(result)) { \
fail(__PRETTY_FUNCTION__); \
assert(false); \
}

Check a test result.

Parameters
resulttrue if test was successful, false on failure
Note
Failure generates an assertion so when run in the host emulator the process fails.