CppTest  Version 2.0.0
Macros
cpptest-assert.h File Reference
#include <sstream>

Go to the source code of this file.

Macros

#define TEST_FAIL(msg)
 
#define TEST_ASSERT(expr)
 
#define TEST_ASSERT_MSG(expr, msg)
 
#define TEST_ASSERT_EQUALS(expected, got)
 
#define TEST_ASSERT_EQUALS_OBJ(expected, got)
 
#define TEST_ASSERT_EQUALS_MSG(expected, got, msg)
 
#define TEST_ASSERT_DELTA(a, b, delta)
 
#define TEST_ASSERT_DELTA_MSG(a, b, delta, msg)
 
#define TEST_THROWS(expr, x)
 
#define TEST_THROWS_MSG(expr, x, msg)
 
#define TEST_THROWS_ANYTHING(expr)
 
#define TEST_THROWS_ANYTHING_MSG(expr, msg)
 
#define TEST_THROWS_NOTHING(expr)
 
#define TEST_THROWS_NOTHING_MSG(expr, msg)
 

Macro Definition Documentation

◆ TEST_FAIL

#define TEST_FAIL (   msg)

Unconditional failure.

Used in conjunction with Test::Suite.

Parameters
msgProvided message.
Example:
void MySuite::test()
{
// ...
switch (flag)
{
// handling valid cases ...
default:
TEST_FAIL("This should not happen")
}
}

For a description of all asserts, see Available asserts.

◆ TEST_ASSERT

#define TEST_ASSERT (   expr)

Verify an expression and issues an assertment if it fails.

Used in conjunction with Test::Suite.

Parameters
exprExpression to test.
See also
TEST_ASSERT_MSG(expr, msg)
Example:
void MySuite::test()
{
int i;
// ...
TEST_ASSERT(i == 13)
}

For a description of all asserts, see Available asserts.

◆ TEST_ASSERT_MSG

#define TEST_ASSERT_MSG (   expr,
  msg 
)

Verify an expression and issues an assertment if it fails.

Used in conjunction with Test::Suite.

Parameters
exprExpression to test.
msgUser message.
See also
TEST_ASSERT(expr)

For a description of all asserts, see Available asserts.

◆ TEST_ASSERT_EQUALS

#define TEST_ASSERT_EQUALS (   expected,
  got 
)

Verify that two expressions are equal, issues an assertment if it fails. Requires the output operator (<<) to be defined for both expected and got.

If the output operator is not available, you should use TEST_ASSERT_EQUALS_OBJ(expected, got).

Used in conjunction with Test::Suite.

Parameters
expectedExpected value.
gotValue to test against expected value.
See also
TEST_ASSERT_EQUALS_MSG(expected, got, msg)
TEST_ASSERT_EQUALS_OBJ(expected, got)

For a description of all asserts, see Available asserts.

◆ TEST_ASSERT_EQUALS_OBJ

#define TEST_ASSERT_EQUALS_OBJ (   expected,
  got 
)

Verify that two expressions are equal, issues an assertment if it fails.

If the output operator is defined for the objects being compared you should use TEST_ASSERT_EQUALS(expected, got) instead for more useful failure messages.

Used in conjunction with Test::Suite.

Parameters
expectedExpected value.
gotValue to test against expected value.
See also
TEST_ASSERT_EQUALS(expected, got)
TEST_ASSERT_EQUALS_MSG(expected, got, msg)

For a description of all asserts, see Available asserts.

◆ TEST_ASSERT_EQUALS_MSG

#define TEST_ASSERT_EQUALS_MSG (   expected,
  got,
  msg 
)

Verify that two expressions are equal, issues an assertment if it fails. The output operator (<<) must be defined for the object under test. If the output operator is not available, you should use TEST_ASSERT_EQUALS_OBJ(expected, got) instead.

Used in conjunction with Test::Suite.

Parameters
expectedExpected value.
gotValue to test against expected value.
msgUser message to print out on failure.
See also
TEST_ASSERT_EQUALS(expected, got)
TEST_ASSERT_EQUALS_OBJ(expected, got)

For a description of all asserts, see Available asserts.

◆ TEST_ASSERT_DELTA

#define TEST_ASSERT_DELTA (   a,
  b,
  delta 
)

Verify that two expressions are equal up to a constant, issues an assertment if it fails.

Used in conjunction with Test::Suite.

Parameters
aFirst expression to test.
bSecond expression to test.
deltaConstant.
See also
TEST_ASSERT_DELTA_MSG(a, b, delta, msg)

For a description of all asserts, see Available asserts.

◆ TEST_ASSERT_DELTA_MSG

#define TEST_ASSERT_DELTA_MSG (   a,
  b,
  delta,
  msg 
)

Verify that two expressions are equal up to a constant, issues an assertment if it fails.

Used in conjunction with Test::Suite.

Parameters
aFirst expression to test.
bSecond expression to test.
deltaConstant.
msgUser message.
See also
TEST_ASSERT_DELTA(a, b, delta)

For a description of all asserts, see Available asserts.

◆ TEST_THROWS

#define TEST_THROWS (   expr,
 
)

Verify an expression and expects an exception in return. An assertment is issued if the exception is not thrown.

Used in conjunction with Test::Suite.

Parameters
exprExpression to test.
xExpected exception.
See also
TEST_THROWS_MSG(expr, x, msg)

For a description of all asserts, see Available asserts.

◆ TEST_THROWS_MSG

#define TEST_THROWS_MSG (   expr,
  x,
  msg 
)

Verify an expression and expects an exception in return. An assertment is issued if the exception is not thrown.

Used in conjunction with Test::Suite.

Parameters
exprExpression to test.
xExpected exception.
msgUser message.
See also
TEST_THROWS(expr, x)

For a description of all asserts, see Available asserts.

◆ TEST_THROWS_ANYTHING

#define TEST_THROWS_ANYTHING (   expr)

Verify an expression and expects any exception in return. An assertment is issued if no exception is thrown.

Used in conjunction with Test::Suite.

Parameters
exprExpression to test.
See also
TEST_THROWS_ANYTHING_MSG(expr, msg)

For a description of all asserts, see Available asserts.

◆ TEST_THROWS_ANYTHING_MSG

#define TEST_THROWS_ANYTHING_MSG (   expr,
  msg 
)

Verify an expression and expects any exception in return. An assertment is issued if no exception is thrown.

Used in conjunction with Test::Suite.

Parameters
exprExpression to test.
msgUser message.
See also
TEST_THROWS_ANYTHING(expr)

For a description of all asserts, see Available asserts.

◆ TEST_THROWS_NOTHING

#define TEST_THROWS_NOTHING (   expr)

Verify an expression and expects no exception in return. An assertment is issued if any exception is thrown.

Used in conjunction with Test::Suite.

Parameters
exprExpression to test.
See also
TEST_THROWS_NOTHING_MSG(expr, msg)

For a description of all asserts, see Available asserts.

◆ TEST_THROWS_NOTHING_MSG

#define TEST_THROWS_NOTHING_MSG (   expr,
  msg 
)

Verify an expression and expects no exception in return. An assertment is issued if any exception is thrown.

Used in conjunction with Test::Suite.

Parameters
exprExpression to test.
msgUser message.
See also
TEST_THROWS_NOTHING(expr)

For a description of all asserts, see Available asserts.