MacroReference

Documentation

This is a list of all the macros available in tests.h. If you inspect the file yourself, you'll notice that the macros are simple and easily extendible. (Todo: sort these out.)



START_TESTS() and END_TESTS()
These start and end the actual testing program. They are like your int main(void). They are required.

START_TEST(string) and END_TEST()
These start and end each test in the program. string should be a normal C string describing the test.

START_SUITE(identifier) and END_SUITE()
These start and end each test suite in the program. identifier should be a normal C identifier. Suites are represented in terms of functions. For more information, see UsingSuites.

DEFINE_SUITE(identifier)
Using this macro, you can use this to supply the declaration of the suite. You can place this in header files, etc. There aren't any requirements for defining individual tests.

SUITE(identifier)
This runs an actual suite. It's basically a function call to a suite declared by DEFINE_SUITE and/or defined by START_SUITE. This is placed anywhere within the START_TESTS block.

TEST(string)
This modifies the failed assertion text to a certain string. If the following test(s) fail, this string will be printed out instead of any default. Optional.

ASSERT(test)
The basic assertion. If the test specified in test fails (i.e. returns false), then the test fails. Otherwise, it passes. There are lots of other helper functions to assist you in writing tests:

ASSERT_EQUALS(a, b) (v0.2+)
ASSERT_GREATER(a, b) (v0.25+)
ASSERT_LESSTHAN(a, b) (v0.25+)
ASSERT_GREATER_EQUAL(a, b) (v0.25+)
ASSERT_LESSTHAN_EQUAL(a, b) (v0.25+)
ASSERT_NOT_EQUALS(a, b) (v0.3+)
Assert that two values are equal to (==), greater than (>), less than (<), greater than or equal (>=), less than or equal (<=), or not equal (!=), respectively.

ASSERT_EQ(a, b) (v0.25+)
ASSERT_GT(a, b) (v0.25+)
ASSERT_LT(a, b) (v0.25+)
ASSERT_GE(a, b) (v0.25+)
ASSERT_LE(a, b) (v0.25+)
ASSERT_NE(a, b) (v0.25+)
Helper functions for the above assertions: equal to (==), greater than (>), less than (<), greater than or equal (>=), less than or equal (<=), and not equal (!=).

ASSERT_EQUALS_FLOAT(a, b)
Asserts that floating point values a and b can be considered equal (their difference is below a threshold value, called the epsilon). By default, the epsilon is set to 0.01%.

ASSERT_NOT_EQUALS_FLOAT(a, b) (v0.3+)
Asserts that floating point values a and b can not be considered equal.

ABS(n)
Absolute value of n.

FLOAT_EQUALS(a, b) (v0.25+)
Returns true if floating point values a and b can be considered equal (their difference is below a threshold value, called the epsilon). By default, the epsilon is set to 0.1%.

SET_EPSILON(n)
SET_EPSILON_DEFAULT()
Sets the epsilon for floating point number operations to another value, or resets it back to the default. "0.001" means that a and b are equal if (a - b) < epsilon or (a - b) <= abs(b x epsilon). The default epsilon value is 0.0001 (0.01%).

TESTS_BREAK() (v0.25+)
Breaks execution of the entire test suite, but allows execution to continue for the rest of the testing project. If a test fails, this macro is automatically called if TESTS_BREAK_ON_FAILURE is defined.

TESTS_HALT() (v0.25+)
Breaks execution of ALL test suites. If a test fails, this macro is automatically called if TESTS_EXIT_ON_FAILURE is defined.

FAIL() (v0.25+)
Asserts an automatic failure, but does not print out the failure.

START_SUITE_WRAPPER(name) (v0.3+)
Used internally to make test suites exectuable (when TEST_INDIVIDUAL is defined).

Powered by Wiki! and
SourceForge.net Logo