|
ctest
|
#include <stdlib.h>Macros | |
| #define | CTEST_FIXTURE(name, type, setup_func, teardown_func) |
| #define | CTEST_ADD_TEST_F(fixture_name, test) |
| #define | CTEST_SUITE(name, setup_func, teardown_func) |
| #define | CTEST_ADD_TEST_S(suite_name, test) |
| #define | CTEST_PASS_TEST() |
| #define | CTEST_FAIL_TEST() |
| #define | CTEST_ADD_TEST(test_func) |
| #define | CTEST_EXPECT_TRUE(EXP) |
| #define | CTEST_EXPECT_FALSE(EXP) |
| #define | CTEST_EXPECT_INT_EQ(EXP, VAL) |
| #define | CTEST_EXPECT_INT_LT(EXP, VAL) |
| #define | CTEST_EXPECT_INT_GT(EXP, VAL) |
| #define | CTEST_EXPECT_FLOAT_EQ(EXP, VAL) |
| #define | CTEST_EXPECT_PTR_EQ(EXPECTED, ACTUAL) |
| #define | CTEST_EXPECT_PTR_NEQ(PTR1, PTR2) |
| #define | CTEST_EXPECT_PTR_NULL(PTR) |
| #define | CTEST_EXPECT_PTR_NOT_NULL(EXP) |
| #define | CTEST_ASSERT_TRUE(EXP) |
| #define | CTEST_ASSERT_FALSE(EXP) |
| #define | CTEST_ASSERT_INT_EQ(EXP, VAL) |
| #define | CTEST_ASSERT_INT_LT(EXP, VAL) |
| #define | CTEST_ASSERT_INT_GT(EXP, VAL) |
| #define | CTEST_ASSERT_FLOAT_EQ(EXP, VAL) |
| #define | CTEST_ASSERT_PTR_EQ(EXPECTED, ACTUAL) |
| #define | CTEST_ASSERT_PTR_NEQ(PTR1, PTR2) |
| #define | CTEST_ASSERT_PTR_NULL(PTR) |
| #define | CTEST_ASSERT_PTR_NOT_NULL(PTR) |
Typedefs | |
| typedef void(* | ctest_test_func) () |
| typedef void(* | ctest_suite_func) () |
Functions | |
| void | ctest_init () |
| void | ctest_destroy () |
| void | ctest_config_set_filter (const char *filter_str) |
| int | ctest_run () |
| #define CTEST_ADD_TEST | ( | test_func | ) |
Adds a test function to the system. The test function being added should have a signature matching ctest_test_func
| suite_name | The function that will be added. Note that for filtering purposes, the test name in the system will be the same as the added function's name. |
| #define CTEST_ADD_TEST_F | ( | fixture_name, | |
| test | |||
| ) |
Adds a fixture test to the system. A Fixture tests runs after the appropriate setup method has been called and receives a freshly allocated and initialized test data structure. If a test is being added to a fixture whose type is T, the test should take a single parameter of T*. After the test returns, the fixture's teardown method will be called on the structure that was passed to the test.
| fixture_name | The name of the fixture that this test will be added to. |
| test | name of the function serving as the test method to be added to the system. Note that for filtering purposes, the test name in the system will be <fixture_name>.<test> |
| #define CTEST_ADD_TEST_S | ( | suite_name, | |
| test | |||
| ) |
Adds a suite test to the system A suite test runs in between the setup and teardown functions defined by the suite it is a part of. The test function being added should have a signature matching ctest_test_func
| suite_name | The name of the suite this test will be added to. |
| test | name of the function serving as the test method to be added to the system. Note that for filtering purposes, the test name in the system will be <suite_name>.<test> |
| #define CTEST_ASSERT_FALSE | ( | EXP | ) |
Asserts that an expression evaluates to false. If it does not, the currently running test is marked as failed and the current function will return. The expression is false if it evaluates to zero.
| EXP | The expression to test. |
| #define CTEST_ASSERT_FLOAT_EQ | ( | EXP, | |
| VAL | |||
| ) |
Asserts that an expression evaluates to an expected floating point value. If it does not, the currently running test is marked as failed and the current function will return. Note this test performs a strict equality check.
| EXP | The expression to test. |
| VAL | the expected float value. |
| #define CTEST_ASSERT_INT_EQ | ( | EXP, | |
| VAL | |||
| ) |
Asserts that an expression evaluates to an expected integer value. If it does not, the currently running test is marked as failed and the current function will return.
| EXP | The expression to test. |
| VAL | the expected integer value. |
| #define CTEST_ASSERT_INT_GT | ( | EXP, | |
| VAL | |||
| ) |
Asserts that an expression evaluates to greater than an expected integer value. If it does not, the currently running test is marked as failed and the current function will return.
| EXP | The expression to test. |
| VAL | the expected integer value that EXP should be greater than. |
| #define CTEST_ASSERT_INT_LT | ( | EXP, | |
| VAL | |||
| ) |
Asserts that an expression evaluates to less than an expected integer value. If it does not, the currently running test is marked as failed and the current function will return.
| EXP | The expression to test. |
| VAL | the expected integer value that EXP should be less than. |
| #define CTEST_ASSERT_PTR_EQ | ( | EXPECTED, | |
| ACTUAL | |||
| ) |
Asserts two pointers are equal. If they are not, the currently running test is marked as failed and the current function will return.
| EXPECTED | The expected value of the pointer. |
| ACTUAL | The actual value of the pointer. |
| #define CTEST_ASSERT_PTR_NEQ | ( | PTR1, | |
| PTR2 | |||
| ) |
Asserts two pointers are not equal. If they are equal, the currently running test is marked as failed and the current function will return.
| PTR1 | The first pointer. |
| PTR2 | The second pointer. |
| #define CTEST_ASSERT_PTR_NOT_NULL | ( | PTR | ) |
Asserts that a pointer is not NULL. If it is, the currently running test is marked as failed and the current function will return.
| PTR | The pointer to test. |
| #define CTEST_ASSERT_PTR_NULL | ( | PTR | ) |
Asserts that a pointer is NULL. If it is not, the currently running test is marked as failed and the current function will return.
| PTR | The pointer to test. |
| #define CTEST_ASSERT_TRUE | ( | EXP | ) |
Asserts that an expression evaluates to true. If it does not, the currently running test is marked as failed and the current function will return. The expression is true if it evaluates to a non-zero value.
| EXP | The expression to test. |
| #define CTEST_EXPECT_FALSE | ( | EXP | ) |
Tests that an expression evaluates to false. If it does not, the currently running test is marked as failed. The expression is false if it evaluates to zero.
| EXP | The expression to test. |
| #define CTEST_EXPECT_FLOAT_EQ | ( | EXP, | |
| VAL | |||
| ) |
Tests that an expression evaluates to an expected floating point value. If it does not, the currently running test is marked as failed. Note this test performs a strict equality check.
| EXP | The expression to test. |
| VAL | the expected float value. |
| #define CTEST_EXPECT_INT_EQ | ( | EXP, | |
| VAL | |||
| ) |
Tests that an expression evaluates to an expected integer value. If it does not, the currently running test is marked as failed.
| EXP | The expression to test. |
| VAL | the expected integer value. |
| #define CTEST_EXPECT_INT_GT | ( | EXP, | |
| VAL | |||
| ) |
Tests that an expression evaluates to greater than an expected integer value. If it does not, the currently running test is marked as failed.
| EXP | The expression to test. |
| VAL | the expected integer value that EXP should be greater than. |
| #define CTEST_EXPECT_INT_LT | ( | EXP, | |
| VAL | |||
| ) |
Tests that an expression evaluates to less than an expected integer value. If it does not, the currently running test is marked as failed.
| EXP | The expression to test. |
| VAL | the expected integer value that EXP should be less than. |
| #define CTEST_EXPECT_PTR_EQ | ( | EXPECTED, | |
| ACTUAL | |||
| ) |
Tests two pointers are equal. If they are not, the currently running test is marked as failed.
| EXPECTED | The expected value of the pointer. |
| ACTUAL | The actual value of the pointer. |
| #define CTEST_EXPECT_PTR_NEQ | ( | PTR1, | |
| PTR2 | |||
| ) |
Tests two pointers are not equal. If they are equal, the currently running test is marked as failed.
| PTR1 | The first pointer. |
| PTR2 | The second pointer. |
| #define CTEST_EXPECT_PTR_NOT_NULL | ( | EXP | ) |
Tests that a pointer is not NULL. If it is, the currently running test is marked as failed.
| PTR | The pointer to test. |
| #define CTEST_EXPECT_PTR_NULL | ( | PTR | ) |
Tests that a pointer is NULL. If it is not, the currently running test is marked as failed.
| PTR | The pointer to test. |
| #define CTEST_EXPECT_TRUE | ( | EXP | ) |
Tests that an expression evaluates to true. If it does not, the currently running test is marked as failed. The expression is true if it evaluates to a non-zero value.
| EXP | The expression to test. |
| #define CTEST_FAIL_TEST | ( | ) |
Unconditionally fails the current test.
| #define CTEST_FIXTURE | ( | name, | |
| type, | |||
| setup_func, | |||
| teardown_func | |||
| ) |
Defines a new text fixture. A test fixture is useful for tests which require non trivial setup and tear down as well as operating on non global data. The system will allocate a test data struct, as well as call the appropriate setup and teardown methods for each test that uses the fixture. For a test to use a fixture with type T. It's function signature should have one parameter of type T*. A test fixture is also a good way to avoid using global data in all of your tests.
| name | The name of the test fixture. Each fixture name must be unique. |
| type | The type name of the struct which contains the fixture data. A new struct will be allocated and used for each test in the fixture |
| setup_func | The name of a function which will be called before each fixture test. This function will receive a pointer to a freshly allocated struct of the type named by the name parameter. This function should initialize the members of the fixture struct to default values. |
| teardown_func | The name of a function which will be called after each fixture test. This function will recieve a pointer to a struct of the type named by the name parameter. This function should free all resources used by the object, but not the object itself. |
| #define CTEST_PASS_TEST | ( | ) |
Unconditionally passes the current test. Assert and expect macros that fail after this method is called will not affect the status of the test.
| #define CTEST_SUITE | ( | name, | |
| setup_func, | |||
| teardown_func | |||
| ) |
Defines a new test suite. A test suite is useful for tests which require non trivial setup and tear down but do not need any test specific data, or use global data. The system will call the appropriate setup and teardown methods for each test that is in the suite.
| name | the name of this suite. Each Suite name must be unique. |
| setup_func | The name of a function which will be called before each test in this suite. This function should have a signature matching ctest_suite_func |
| teardown_func | The name of a function which will be called after each test in this suite. This function should have a signature matching ctest_suite_func |
| typedef void(* ctest_suite_func) () |
Function definition for a suite setup or teardown function. A suite setup function is called before each test in a suite. A suite teardown function is called after each test in a suite.
| typedef void(* ctest_test_func) () |
Callback for a function test. A function test does not require any parameters and does not need assoicated setup or teardown functionality.
| void ctest_config_set_filter | ( | const char * | filter_str | ) |
Sets the filter string which is used to determine which tests should be run. When a filter is active, a test will only be ran if its name begins with at least one active filter. Multiple filters may be specified as a ';' separated list. Calling this method multiple times will clear out any previously set filters.
| filter_str | list of filters to apply to all tests. Multiple filters are spearated by ';'. |
| void ctest_destroy | ( | ) |
Releases all resources used by the testing library. After calling this methid, ctest_init should be called again before any subsequent called to library methods.
| void ctest_init | ( | ) |
Initializes the testting framework. This method should be called once before any other library function.
| int ctest_run | ( | ) |
Runs all tests.
1.8.13