universe@390: universe@390: universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:universe@390: |
universe@390: ucx
universe@390:
universe@390: UAP Common Extensions
universe@390: |
universe@390:
UCX Test Framework. universe@390: More...
universe@390:#include "ucx.h"
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
Go to the source code of this file.
universe@390:universe@390: Data Structures | |
struct | UcxTestList |
Structure for the internal list of test cases. More... | |
struct | UcxTestSuite |
A test suite containing multiple test cases. More... | |
universe@390: Macros | |
#define | __FUNCTION__ __func__ |
Alias for the __func__ preprocessor macro. More... | |
#define | UCX_TEST(name) void name(UcxTestSuite* _suite_,FILE *_output_) |
Macro for a UcxTest function header. More... | |
#define | UCX_TEST_BEGIN |
Marks the begin of a test. More... | |
#define | UCX_TEST_ASSERT(condition, message) |
Checks a test assertion. More... | |
#define | UCX_TEST_SUBROUTINE(name, ...) |
Macro for a test subroutine function header. More... | |
#define | UCX_TEST_CALL_SUBROUTINE(name, ...) name(_suite_,_output_,_env_,__VA_ARGS__); |
Macro for calling a test subroutine. More... | |
#define | UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;} |
Marks the end of a test. More... | |
universe@390: Typedefs | |
typedef struct UcxTestSuite | UcxTestSuite |
Type for the UcxTestSuite. More... | |
typedef void(* | UcxTest) (UcxTestSuite *, FILE *) |
Pointer to a test function. More... | |
typedef struct UcxTestList | UcxTestList |
Type for the internal list of test cases. More... | |
universe@390: Functions | |
UcxTestSuite * | ucx_test_suite_new () |
Creates a new test suite. More... | |
void | ucx_test_suite_free (UcxTestSuite *suite) |
Destroys a test suite. More... | |
int | ucx_test_register (UcxTestSuite *suite, UcxTest test) |
Registers a test function with the specified test suite. More... | |
void | ucx_test_run (UcxTestSuite *suite, FILE *outstream) |
Runs a test suite and writes the test log to the specified stream. More... | |
UCX Test Framework.
universe@390:Usage of this test framework:
universe@390:**** IN HEADER FILE: ****
universe@390:universe@390: UCX_TEST(function_name); universe@390: UCX_TEST_SUBROUTINE(subroutine_name, paramlist); // optional universe@390:
**** IN SOURCE FILE: ****
universe@390: UCX_TEST_SUBROUTINE(subroutine_name, paramlist) { universe@390: // tests with UCX_TEST_ASSERT() universe@390: }
UCX_TEST(function_name) { universe@390: // memory allocation and other stuff here universe@390: UCX_TEST_BEGIN universe@390: // tests with UCX_TEST_ASSERT() and/or universe@390: // calls with UCX_TEST_CALL_SUBROUTINE() here universe@390: UCX_TEST_END universe@390: // cleanup of memory here universe@390: } universe@390:
Note: if a test fails, a longjump is performed back to the UCX_TEST_BEGIN macro!
universe@390:Attention: Do not call own functions within a test, that use UCX_TEST_ASSERT() macros and are not defined by using UCX_TEST_SUBROUTINE().
universe@390: universe@390:#define __FUNCTION__ __func__ | universe@390:
Alias for the __func__
preprocessor macro.
Some compilers use __func__
and others use FUNCTION. We use FUNCTION so we define it for those compilers which use __func__
.
#define UCX_TEST | universe@390:( | universe@390:universe@390: | name | ) | universe@390:void name(UcxTestSuite* _suite_,FILE *_output_) | universe@390:
#define UCX_TEST_ASSERT | universe@390:( | universe@390:universe@390: | condition, | universe@390:
universe@390: | universe@390: | universe@390: | message | universe@390:
universe@390: | ) | universe@390:universe@390: |
Checks a test assertion.
universe@390:If the assertion is correct, the test carries on. If the assertion is not correct, the specified message (terminated by a dot and a line break) is written to the test suites output stream.
condition | the condition to check |
message | the message that shall be printed out on failure |
#define UCX_TEST_BEGIN | universe@390:
Marks the begin of a test.
universe@390:Note: Any UCX_TEST_ASSERT() calls must be performed after UCX_TEST_BEGIN.
universe@390:#define UCX_TEST_CALL_SUBROUTINE | universe@390:( | universe@390:universe@390: | name, | universe@390:
universe@390: | universe@390: | universe@390: | ... | universe@390:
universe@390: | ) | universe@390:name(_suite_,_output_,_env_,__VA_ARGS__); | universe@390:
Macro for calling a test subroutine.
universe@390:Subroutines declared with UCX_TEST_SUBROUTINE() can be called by using this macro.
universe@390:Note: You may only call subroutines within a UCX_TEST_BEGIN- UCX_TEST_END-block.
universe@390:name | the name of the subroutine |
... | the argument list |
#define UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;} | universe@390:
Marks the end of a test.
universe@390:Note: Any UCX_TEST_ASSERT() calls must be performed before UCX_TEST_END.
universe@390:#define UCX_TEST_SUBROUTINE | universe@390:( | universe@390:universe@390: | name, | universe@390:
universe@390: | universe@390: | universe@390: | ... | universe@390:
universe@390: | ) | universe@390:universe@390: |
Macro for a test subroutine function header.
universe@390:Use this to declare and/or define a subroutine that can be called by using UCX_TEST_CALL_SUBROUTINE().
universe@390:name | the name of the subroutine |
... | the parameter list |
typedef void(* UcxTest) (UcxTestSuite *, FILE *) | universe@390:
Pointer to a test function.
universe@390: universe@390:typedef struct UcxTestList UcxTestList | universe@390:
Type for the internal list of test cases.
universe@390: universe@390:typedef struct UcxTestSuite UcxTestSuite | universe@390:
Type for the UcxTestSuite.
universe@390: universe@390:int ucx_test_register | universe@390:( | universe@390:UcxTestSuite * | universe@390:suite, | universe@390:
universe@390: | universe@390: | UcxTest | universe@390:test | universe@390:
universe@390: | ) | universe@390:universe@390: |
Registers a test function with the specified test suite.
universe@390:suite | the suite, the test function shall be added to |
test | the test function to register |
EXIT_SUCCESS
on success or EXIT_FAILURE
on failure void ucx_test_run | universe@390:( | universe@390:UcxTestSuite * | universe@390:suite, | universe@390:
universe@390: | universe@390: | FILE * | universe@390:outstream | universe@390:
universe@390: | ) | universe@390:universe@390: |
Runs a test suite and writes the test log to the specified stream.
universe@390:suite | the test suite to run |
outstream | the stream the log shall be written to |
void ucx_test_suite_free | universe@390:( | universe@390:UcxTestSuite * | universe@390:suite | ) | universe@390:universe@390: |
Destroys a test suite.
universe@390:suite | the test suite to destroy |
UcxTestSuite* ucx_test_suite_new | universe@390:( | universe@390:) | universe@390:universe@390: |
Creates a new test suite.
universe@390: