#include "AceUnitAnnotations.h"
#include <setjmp.h>
#include "AceUnitAssert.h"
#include "AceUnitData.h"
Go to the source code of this file.
Data Structures | |
struct | AssertionId_t |
AssertionId_t specifies an assertion failure within a test case. More... | |
struct | AssertionError_t |
Assertion Error. More... | |
struct | TestSuite_t |
A Suite is a loose collection of test cases. More... | |
struct | TestFixture_t |
A Fixture is a collection of test cases sharing the same before, after, beforeClass and afterClass methods. More... | |
Defines | |
#define | ACEUNIT_H 1 |
Include shield to protect the header file from being included more than once. | |
#define | ACEUNIT_C_MODE ACEUNIT_C_MODE_C89 |
#define | ACEUNIT_C_MODE_C99_INCLUDES 1 |
Value for ACEUNIT_C_MODE for including C99 standard header files. | |
#define | ACEUNIT_C_MODE_C89 2 |
Value for ACEUNIT_C_MODE for using AceUnit's own replacement definitions. | |
#define | ACEUNIT_C_MODE_PROPRIETARY 3 |
Value for ACEUNIT_C_MODE for providing proprietary replacement definitions by the user. | |
#define | bool int |
Replacement for stdbool.h bool in case stdbool.h is not available. | |
#define | true 1 |
Replacement for stdbool.h true in case stdbool.h is not available. | |
#define | false 0 |
Replacement for stdbool.h false in case stdbool.h is not available. | |
#define | __bool_true_false_are_defined 1 |
Replacement for stdbool.h __bool_true_false_are_defined in case stdbool.h is not available. | |
#define | NULL ((void *) 0) |
Replacement for stddef.h NULL in case stddef.h is not available. | |
#define | ACEUNIT_ASSERTION_STYLE_RETURN 1 |
Value for ACEUNIT_ASSERTION_STYLE for using return for assertions to abort test cases. | |
#define | ACEUNIT_ASSERTION_STYLE_ASSERT 2 |
Value for ACEUNIT_ASSERTION_STYLE for using assert for assertions to abort test cases. | |
#define | ACEUNIT_ASSERTION_STYLE_ABORT 3 |
Value for ACEUNIT_ASSERTION_STYLE for using abort() for assertions to abort. | |
#define | ACEUNIT_ASSERTION_STYLE_LONGJMP 4 |
Value for ACEUNIT_ASSERTION_STYLE for using longjmp() for assertions to abort. | |
#define | ACEUNIT_ASSERTION_STYLE_CUSTOM 5 |
Value for ACEUNIT_ASSERTION_STYLE for using custom assertion aborts. | |
#define | ACEUNIT_ASSERTION_STYLE ACEUNIT_ASSERTION_STYLE_LONGJMP |
Determines the style of assertions to use. | |
#define | ACEUNIT_ABORT longjmp(runnerData->jmpBuf, 1) |
Code for aborting a test case in case of an assertion. | |
#define | NO_TEST ((AceTestId_t) 0) |
Special value for AceTestId_t that specifies no test. | |
#define | ALL_TESTS ((AceTestId_t) -1) |
Special value for AceTestId_t that specifies all tests. | |
#define | TestCaseId_NULL 0 |
The value for something of type TestCaseId_t for denoting no testcase. | |
#define | newAssertionError(message) { AssertionId_t assertion = { __LINE__, message }; recordError(A_FIXTURE_ID, assertion); } ACEUNIT_ABORT |
Creates a new assertion error. | |
Typedefs | |
typedef signed char | int8_t |
Replacement for stdint.h int8_t in case stdint.h is not available. | |
typedef signed short int | int16_t |
Replacement for stdint.h int16_t in case stdint.h is not available. | |
typedef signed long int | int32_t |
Replacement for stdint.h int32_t in case stdint.h is not available. | |
typedef unsigned char | uint8_t |
Replacement for stdint.h uint8_t in case stdint.h is not available. | |
typedef unsigned short int | uint16_t |
Replacement for stdint.h uint16_t in case stdint.h is not available. | |
typedef unsigned long int | uint32_t |
Replacement for stdint.h uint32_t in case stdint.h is not available. | |
typedef long unsigned int | size_t |
Replacement for stddef.h size_t in case stddef.h is not available. | |
typedef uint16_t | AceTestId_t |
TestId_t specifies a test. | |
typedef uint16_t | AceGroupId_t |
GroupId_t specifies a group. | |
typedef AceTestId_t | SuiteId_t |
SuiteId_t specifies a test suite. | |
typedef SuiteId_t | FixtureId_t |
FixtureId_t specifies a test fixture. | |
typedef AceTestId_t | TestCaseId_t |
TestCaseId_t specifies a test case. | |
typedef int | linenumber_t |
The type to use for line numbers. | |
typedef void(* | testMethod_t )(void) |
Method signature for annotated test methods. | |
Functions | |
void | recordError (const FixtureId_t fixtureId, const AssertionId_t assertionId) |
Records an error. | |
void | runFixture (const TestFixture_t *const fixture, AceGroupId_t group) |
Runs all test cases from a test fixture. | |
void | runSuite (const TestSuite_t *const suite, AceGroupId_t group) |
Runs all test cases from a test suite. |
You do not need to include this header file in a fixture. The generated header file for your fixture will automatically include it.
The following options are supported:
ACEUNIT_EMBEDDED
uint16_t
instead of char*
. Memory consumption in embedded mode is significantly reduced. Some non-vital features are not available in embedded mode. TODO: describe which features are not available in embedded mode. ACEUNIT_C_MODE
ACEUNIT_C_MODE_C99_INCLUDES
(default in a C99 environment) <stdint.h>
and <stddef.h>
to define required symbols like uint16_t
or NULL
. ACEUNIT_C_MODE_C89
(default in a C89 environment) ACEUNIT_C_MODE_PROPRIETARY
uint16_t
or NULL
are provided by header files already included by the user before the AceUnit header files. Note: this replaces ACEUNIT_INTERNAL_ISO_TYPES and ACEUNIT_SKIP_ISO_DEFINES from previous versions of AceUnit.
Note: If you do not set this macro, AceUnit will make the decision itself. The default is to assume ACEUNIT_C_MODE_C99_INCLUDES for a C99 environment, ACEUNIT_C_MODE_C89 otherwise.
ACEUNIT_STATIC_ANNOTATIONS
static
keyword. That way you have easy and flexible control whether or not test methods are static. Declaring test methods as static has a significant advantage. You will be able to use the same name in different fixtures and still build and run them all together. For logging, it is not required that test methods have unique names. Logging will always also include the associated fixture (e.g. filename + line number). So you will always uniquely identify which test case filed, even if the names of the test cases are not unique.
However, there are debuggers which will cause head ache if you try to debug functions which are static. Some tool chains (compilers / linkers) will not emit proper debug information for functions which are static.
The pros and cons for static test methods are both very significant. Whether or not you want to use static depends on your environment. Because of that, we've left the choice to you.
But we've prepared everything for you. Toggling between these two options is as simple as (not) defining this macro. Of course, toggling static off will only be that simple in the real world if the test method names are unique across all fixtures that you link together.
If you're unsure, a rule of thumb is define either ACEUNIT_EMBEDDED
or ACEUNIT_STATIC_ANNOTATIONS
but not both.
ACEUNIT_CODE_INCLUDE
Of course you could just modify the AceUnit source code to include the section information. But it is not recommended to modify the AceUnit source code because it will cause extra work for you if you want to upgrade to a newer version of AceUnit. Therefore we tried to design AceUnit in a way that you shouldn't need to modify AceUnit's source code to get AceUnit running in your environment.
ACEUNIT_DATA_INCLUDE
Of course you could just modify the AceUnit source code to include the section information. But it is not recommended to modify the AceUnit source code because it will cause extra work for you if you want to upgrade to a newer version of AceUnit. Therefore we tried to design AceUnit in a way that you shouldn't need to modify AceUnit's source code to get AceUnit running in your environment.
ACEUNIT_DATA_ON_STACK
ACEUNIT_SUITES
ACEUNIT_PRE_BEFORECLASS
ACEUNIT_POST_BEFORECLASS
ACEUNIT_PRE_BEFORE
ACEUNIT_POST_BEFORE
ACEUNIT_PRE_TEST
ACEUNIT_POST_TEST
ACEUNIT_PRE_AFTER
ACEUNIT_POST_AFTER
ACEUNIT_PRE_AFTERCLASS
ACEUNIT_POST_AFTERCLASS
ACEUNIT_RUNNERDATA_EXTENSION
ACEUNIT_CONFIG_FILE
ACEUNIT_SETJMP_INCLUDE
<setjmp.h>
, define this macro. The macro then must evaluate to a valid include file. ACEUNIT_SKIP_SETJMP_INCLUDE
ACEUNIT_LOOP
A_Loop
annotation support. A_Loop
support is independent of the generator. You may turn A_Loop
support on and off during compile time without having to rerun the generator. ACEUNIT_EXPLICIT_MESSAGES
ACEUNIT_EXPLICIT_MESSAGES_INLINE_BUFFER
short int
to be 16 bit and long int
to be 32 bit. Especially about the second assumption AceUnit could be wrong.short int
or int
. For sure lint will find something to complain about if you let AceUnit define its own types instead of providing consistent types from your compilation environment.#define __bool_true_false_are_defined 1 |
Replacement for stdbool.h __bool_true_false_are_defined in case stdbool.h is not available.
#define ACEUNIT_ABORT longjmp(runnerData->jmpBuf, 1) |
Code for aborting a test case in case of an assertion.
#define ACEUNIT_ASSERTION_STYLE ACEUNIT_ASSERTION_STYLE_LONGJMP |
Determines the style of assertions to use.
Defaults to ACEUNIT_ASSERTION_STYLE_CUSTOM if ACEUNIT_CUSTOM_ASSERT is defined. Defaults to ACEUNIT_ASSERTION_STYLE_LONGJMP otherwise.
#define ACEUNIT_ASSERTION_STYLE_ABORT 3 |
Value for ACEUNIT_ASSERTION_STYLE for using abort()
for assertions to abort.
It will use stdlib.h
from ISO C.
abort()
and therefore exit the test program. Normal logging is useless in conjunction with this assertion style.#define ACEUNIT_ASSERTION_STYLE_ASSERT 2 |
Value for ACEUNIT_ASSERTION_STYLE for using assert
for assertions to abort test cases.
It will use assert.h
from ISO C. Because of that do not define NDEBUG
.
NDEBUG
with this assertion style, assertions will not work as expected. The test case will not be aborted. If another assertion occurs it will overwrite the previous assertion even before the assertion is logged. Therefore you MUST NOT define NDEBUG
with this assertion style.assert()
and therefore exit the test program. Normal logging is useless in conjunction with this assertion style. This assertion style is especially useful for debugging when assert()
is useful in your debugging environment.#define ACEUNIT_ASSERTION_STYLE_CUSTOM 5 |
Value for ACEUNIT_ASSERTION_STYLE for using custom assertion aborts.
If you use this for ACEUNIT_ASSERTION_STYLE, you also MUST define the macro ACEUNIT_CUSTOM_ASSERT to the code you want to use to make assertions abort test cases.
#define ACEUNIT_ASSERTION_STYLE_LONGJMP 4 |
Value for ACEUNIT_ASSERTION_STYLE for using longjmp()
for assertions to abort.
It will use setjmp.h
from ISO C.
This is the preferred assertion style and therefore default for AceUnit.
#define ACEUNIT_ASSERTION_STYLE_RETURN 1 |
Value for ACEUNIT_ASSERTION_STYLE for using return
for assertions to abort test cases.
This is primarily meant for embedded systems where everything should be as small and simple as possible. It is also currently used by AceUnit when AceUnit tests itself.
#define ACEUNIT_C_MODE_C89 2 |
Value for ACEUNIT_C_MODE for using AceUnit's own replacement definitions.
#define ACEUNIT_C_MODE_C99_INCLUDES 1 |
Value for ACEUNIT_C_MODE for including C99 standard header files.
#define ACEUNIT_C_MODE_PROPRIETARY 3 |
Value for ACEUNIT_C_MODE for providing proprietary replacement definitions by the user.
#define ACEUNIT_H 1 |
Include shield to protect the header file from being included more than once.
#define ALL_TESTS ((AceTestId_t) -1) |
Special value for AceTestId_t that specifies all tests.
The value is all bits set. This value can be used in AceTestId_t values.
#define bool int |
Replacement for stdbool.h bool in case stdbool.h is not available.
#define false 0 |
Replacement for stdbool.h false in case stdbool.h is not available.
#define newAssertionError | ( | message | ) | { AssertionId_t assertion = { __LINE__, message }; recordError(A_FIXTURE_ID, assertion); } ACEUNIT_ABORT |
Creates a new assertion error.
message | Message to create. |
#define NO_TEST ((AceTestId_t) 0) |
Special value for AceTestId_t that specifies no test.
The value is zero. This value can be used to terminate vectors of AceTestId_t values.
#define NULL ((void *) 0) |
Replacement for stddef.h NULL in case stddef.h is not available.
#define TestCaseId_NULL 0 |
The value for something of type TestCaseId_t for denoting no testcase.
#define true 1 |
Replacement for stdbool.h true in case stdbool.h is not available.
typedef uint16_t AceGroupId_t |
GroupId_t specifies a group.
typedef uint16_t AceTestId_t |
TestId_t specifies a test.
typedef SuiteId_t FixtureId_t |
FixtureId_t specifies a test fixture.
On embedded systems, this is a 16 bit quantity that uniquely identifies the test fixture. On normal systems, this is the filename of fixture.
typedef signed short int int16_t |
Replacement for stdint.h int16_t in case stdint.h is not available.
typedef signed long int int32_t |
Replacement for stdint.h int32_t in case stdint.h is not available.
typedef signed char int8_t |
Replacement for stdint.h int8_t in case stdint.h is not available.
typedef int linenumber_t |
The type to use for line numbers.
typedef long unsigned int size_t |
Replacement for stddef.h size_t in case stddef.h is not available.
typedef AceTestId_t SuiteId_t |
SuiteId_t specifies a test suite.
On embedded systems, this is a 16 bit quantity that uniquely identifies the test suite. On normal systems, this is the directory name of the suite.
typedef AceTestId_t TestCaseId_t |
TestCaseId_t specifies a test case.
On embedded systems, this is a 16 bit quantity that uniquely identifies the test case within its fixture. On normal systems, this is the function name of the test case.
typedef void(* testMethod_t)(void) |
typedef unsigned short int uint16_t |
Replacement for stdint.h uint16_t in case stdint.h is not available.
typedef unsigned long int uint32_t |
Replacement for stdint.h uint32_t in case stdint.h is not available.
typedef unsigned char uint8_t |
Replacement for stdint.h uint8_t in case stdint.h is not available.
void recordError | ( | const FixtureId_t | fixtureId, | |
const AssertionId_t | assertionId | |||
) |
Records an error.
fixtureId | Id of the fixture that contained the test case with the failed assertion. | |
assertionId | Id of the assertion that failed. |
void runFixture | ( | const TestFixture_t *const | fixture, | |
AceGroupId_t | group | |||
) |
Runs all test cases from a test fixture.
fixture | Test fixture to run. | |
group | Group to run. This parameter is only available if ACEUNIT_GROUP is defined. |
void runSuite | ( | const TestSuite_t *const | suite, | |
AceGroupId_t | group | |||
) |
Runs all test cases from a test suite.
suite | Test suite to run. | |
group | Group to run. This parameter is only available if ACEUNIT_GROUP is defined. |