Contiki 3.x
|
A tool for unit testing Contiki software.More...
#include "sys/rtimer.h"
Go to the source code of this file.
Data Structures | |
struct | unit_test |
The unit_test structure describes the results of a unit test. More... | |
Macros | |
#define | UNIT_TEST_REGISTER(name, descr) static unit_test_t unit_test_##name = {descr, __FILE__, unit_test_success, 0, 0, 0} |
Register a unit test. More... | |
#define | UNIT_TEST(name) static void unit_test_function_##name(unit_test_t *utp) |
Define a unit test. More... | |
#define | UNIT_TEST_BEGIN() |
Mark the starting point of the unit test function. | |
#define | UNIT_TEST_END() |
Mark the ending point of the unit test function. | |
#define | UNIT_TEST_PRINT_REPORT(name) UNIT_TEST_PRINT_FUNCTION(&unit_test_##name) |
Print a report of the execution of a unit test. More... | |
#define | UNIT_TEST_RUN(name) |
Execute a unit test and print a report on the results. More... | |
#define | UNIT_TEST_SUCCEED() |
Report that a unit test succeeded. More... | |
#define | UNIT_TEST_FAIL() |
Report that a unit test failed. More... | |
#define | UNIT_TEST_ASSERT(expr) |
Report failure if an expression is false. More... | |
#define | UNIT_TEST_RESULT(name) (unit_test_##name.result) |
Obtain the result of a certain unit test. More... | |
Typedefs | |
typedef struct unit_test | unit_test_t |
The unit_test structure describes the results of a unit test. More... | |
Functions | |
void | unit_test_print_report (const unit_test_t *utp) |
Print the results of a unit test. More... | |
A tool for unit testing Contiki software.
Definition in file unit-test.h.
#define UNIT_TEST | ( | name | ) | static void unit_test_function_##name(unit_test_t *utp) |
Define a unit test.
This macro defines the function that will be executed when conducting a unit test. The name that is passed as a parameter must have been registered with the UNIT_TEST_REGISTER() macro.
The function defined by this macro must start with a call to the UNIT_TEST_BEGIN() macro, and end with a call to the UNIT_TEST_END() macro.
The standard test function template produced by this macro will ensure that the unit test keeps track of the result, the time taken to execute (in rtimer ticks), and the exit point of the test. The latter corresponds to the line number at which the test was determined to be a success or failure.
name | The name of the unit test. |
Definition at line 91 of file unit-test.h.
#define UNIT_TEST_ASSERT | ( | expr | ) |
Report failure if an expression is false.
expr | The expression to evaluate. |
Definition at line 170 of file unit-test.h.
#define UNIT_TEST_FAIL | ( | ) |
Report that a unit test failed.
This macro is used to signal that a unit test failed to execute. The line number at which this macro was called is stored in the unit test descriptor.
Definition at line 159 of file unit-test.h.
#define UNIT_TEST_PRINT_REPORT | ( | name | ) | UNIT_TEST_PRINT_FUNCTION(&unit_test_##name) |
Print a report of the execution of a unit test.
name | The name of the unit test. |
Definition at line 123 of file unit-test.h.
#define UNIT_TEST_REGISTER | ( | name, | |
descr | |||
) | static unit_test_t unit_test_##name = {descr, __FILE__, unit_test_success, 0, 0, 0} |
Register a unit test.
This macro allocates unit test descriptor, which is a structure of type unit_test_t. The descriptor contains information about a unit test, and the results from the last execution of the test.
name | The name of the unit test. |
descr | A string that briefly describes the unit test. |
Definition at line 70 of file unit-test.h.
#define UNIT_TEST_RESULT | ( | name | ) | (unit_test_##name.result) |
Obtain the result of a certain unit test.
If the unit test has not yet been executed, this macro returns unit_test_failed. Otherwise it returns the result of the last execution of the unit test.
name | The name of the unit test. |
Definition at line 185 of file unit-test.h.
#define UNIT_TEST_RUN | ( | name | ) |
Execute a unit test and print a report on the results.
name | The name of the unit test. |
Definition at line 130 of file unit-test.h.
#define UNIT_TEST_SUCCEED | ( | ) |
Report that a unit test succeeded.
This macro is useful for writing tests that can succeed earlier than the last execution point of the test, which is specified by a call to the UNIT_TEST_END() macro.
Tests can usually be written without calls to UNIT_TEST_SUCCEED(), since it is implicitly called at the end of the test—unless UNIT_TEST_FAIL() has been called.
Definition at line 147 of file unit-test.h.
typedef struct unit_test unit_test_t |
The unit_test structure describes the results of a unit test.
Each registered unit test statically allocates an object of this type.
void unit_test_print_report | ( | const unit_test_t * | utp | ) |
Print the results of a unit test.
utp | The unit test descriptor. |
Definition at line 48 of file unit-test.c.