Customizable and memory-efficient assertions for embedded systems. More...
Go to the source code of this file.
Macros | |
#define | Q_DEFINE_THIS_FILE static char_t const Q_this_module_[] = __FILE__; |
Define the file name (with __FILE__ ) for assertions in this file. More... | |
#define | Q_DEFINE_THIS_MODULE(name_) static char_t const Q_this_module_[] = name_; |
Define the user-specified module name for assertions in this file. More... | |
#define | Q_ASSERT(test_) |
General purpose assertion. More... | |
#define | Q_ASSERT_ID(id_, test_) |
General purpose assertion with user-specified assertion-id. More... | |
#define | Q_ALLEGE(test_) Q_ASSERT(test_) |
General purpose assertion that always evaluates the test_ expression. More... | |
#define | Q_ALLEGE_ID(id_, test_) Q_ASSERT_ID((id_), (test_)) |
General purpose assertion with user-specified assertion-id that always evaluates the test_ expression. More... | |
#define | Q_ERROR() Q_onAssert(&Q_this_module_[0], __LINE__) |
Assertion for a wrong path through the code. More... | |
#define | Q_ERROR_ID(id_) Q_onAssert(&Q_this_module_[0], (id_)) |
Assertion with user-specified assertion-id for a wrong path. More... | |
#define | Q_NORETURN void |
no-return function specifier More... | |
#define | Q_REQUIRE(test_) Q_ASSERT(test_) |
Assertion for checking preconditions. More... | |
#define | Q_REQUIRE_ID(id_, test_) Q_ASSERT_ID((id_), (test_)) |
Assertion for checking preconditions with user-specified assertion-id. More... | |
#define | Q_ENSURE(test_) Q_ASSERT(test_) |
Assertion for checking postconditions. More... | |
#define | Q_ENSURE_ID(id_, test_) Q_ASSERT_ID((id_), (test_)) |
Assertion for checking postconditions with user-specified assertion-id. More... | |
#define | Q_INVARIANT(test_) Q_ASSERT(test_) |
Assertion for checking invariants. More... | |
#define | Q_INVARIANT_ID(id_, test_) Q_ASSERT_ID((id_), (test_)) |
Assertion for checking invariants with user-specified assertion-id. More... | |
#define | Q_ASSERT_STATIC(test_) extern int_t Q_assert_static[(test_) ? 1 : -1] |
Static (compile-time) assertion. More... | |
#define | Q_ASSERT_COMPILE(test_) Q_ASSERT_STATIC(test_) |
#define | Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U])) |
Helper macro to calculate static dimension of a 1-dim array_ . More... | |
Typedefs | |
typedef char | char_t |
typedef for character strings. More... | |
typedef int | int_t |
typedef for assertions-ids and line numbers in assertions. More... | |
Functions | |
Q_NORETURN | Q_onAssert (char_t const *const module, int_t const location) |
Callback function invoked in case of any assertion failure. More... | |
Customizable and memory-efficient assertions for embedded systems.
Definition in file qassert.h.
#define Q_DEFINE_THIS_FILE static char_t const Q_this_module_[] = __FILE__; |
Define the file name (with __FILE__
) for assertions in this file.
__FILE__
. However, please note that, depending on the compiler, the __FILE__
macro might contain the whole path name to the file, which might be inconvenient to log assertions. #define Q_DEFINE_THIS_MODULE | ( | name_ | ) | static char_t const Q_this_module_[] = name_; |
Define the user-specified module name for assertions in this file.
name_
instead of __FILE__
to precisely control the name of the module.[in] | name_ | string constant representing the module name |
#define Q_ASSERT | ( | test_ | ) |
General purpose assertion.
test_
parameter is TRUE. Calls the Q_onAssert() callback if the test_
expression evaluates to FALSE. This macro identifies the assertion location within the file by means of the standard __LINE__
macro.[in] | test_ | Boolean expression |
test_
is not evaluated if assertions are disabled with the Q_NASSERT switch. #define Q_ASSERT_ID | ( | id_, | |
test_ | |||
) |
General purpose assertion with user-specified assertion-id.
test_
parameter is TRUE. Calls the Q_onAssert() callback if the test_
evaluates to FALSE. This assertion takes the user-supplied parameter id_
to identify the location of this assertion within the file. This avoids the volatility of using line numbers, which change whenever a line of code is added or removed upstream from the assertion.[in] | id_ | ID number (unique within the module) of the assertion |
[in] | test_ | Boolean expression |
test_
expression is not evaluated if assertions are disabled with the Q_NASSERT switch. #define Q_ALLEGE | ( | test_ | ) | Q_ASSERT(test_) |
General purpose assertion that always evaluates the test_
expression.
test_
expression even when assertions are disabled with the Q_NASSERT macro. However, when the Q_NASSERT macro is defined, the Q_onAssert() callback is not called, even if test_
evaluates to FALSE.[in] | test_ | Boolean expression (always evaluated) |
#define Q_ALLEGE_ID | ( | id_, | |
test_ | |||
) | Q_ASSERT_ID((id_), (test_)) |
General purpose assertion with user-specified assertion-id that always evaluates the test_
expression.
test_
expression even when assertions are disabled with the Q_NASSERT macro. However, when the Q_NASSERT macro is defined, the Q_onAssert() callback is not called, even if test_
evaluates to FALSE.[in] | id_ | ID number (unique within the module) of the assertion |
[in] | test_ | Boolean expression |
#define Q_ERROR | ( | ) | Q_onAssert(&Q_this_module_[0], __LINE__) |
Assertion for a wrong path through the code.
#define Q_ERROR_ID | ( | id_ | ) | Q_onAssert(&Q_this_module_[0], (id_)) |
Assertion with user-specified assertion-id for a wrong path.
id_
to identify the location of this assertion within the file. This avoids the volatility of using line numbers, which change whenever a line of code is added or removed upstream from the assertion.[in] | id_ | ID number (unique within the module) of the assertion |
#define Q_REQUIRE | ( | test_ | ) | Q_ASSERT(test_) |
#define Q_REQUIRE_ID | ( | id_, | |
test_ | |||
) | Q_ASSERT_ID((id_), (test_)) |
Assertion for checking preconditions with user-specified assertion-id.
[in] | id_ | ID number (unique within the module) of the assertion |
[in] | test_ | Boolean expression |
#define Q_ENSURE | ( | test_ | ) | Q_ASSERT(test_) |
#define Q_ENSURE_ID | ( | id_, | |
test_ | |||
) | Q_ASSERT_ID((id_), (test_)) |
Assertion for checking postconditions with user-specified assertion-id.
[in] | id_ | ID number (unique within the module) of the assertion |
[in] | test_ | Boolean expression |
#define Q_INVARIANT | ( | test_ | ) | Q_ASSERT(test_) |
#define Q_INVARIANT_ID | ( | id_, | |
test_ | |||
) | Q_ASSERT_ID((id_), (test_)) |
Assertion for checking invariants with user-specified assertion-id.
[in] | id_ | ID number (unique within the module) of the assertion |
[in] | test_ | Boolean expression |
#define Q_ASSERT_STATIC | ( | test_ | ) | extern int_t Q_assert_static[(test_) ? 1 : -1] |
Static (compile-time) assertion.
test_
evaluates to FALSE. The macro exploits the fact that in C/C++ a dimension of an array cannot be negative. The compile-time assertion has no runtime side effects.[in] | test_ | Compile-time Boolean expression |
#define Q_ASSERT_COMPILE | ( | test_ | ) | Q_ASSERT_STATIC(test_) |
#define Q_DIM | ( | array_ | ) | (sizeof(array_) / sizeof((array_)[0U])) |
typedef char char_t |
typedef for character strings.
typedef int int_t |
Q_NORETURN Q_onAssert | ( | char_t const *const | module, |
int_t const | location | ||
) |
Callback function invoked in case of any assertion failure.
[in] | module | name of the file/module in which the assertion failed (constant, zero-terminated C string) |
[in] | location | location of the assertion within the module. This could be a line number or a user-specified ID-number. |
Called by the following macros: Q_ASSERT, Q_REQUIRE, Q_ENSURE, Q_ERROR, Q_ALLEGE as well as Q_ASSERT_ID, Q_REQUIRE_ID, Q_ENSURE_ID, Q_ERROR_ID, and Q_ALLEGE_ID.
Definition at line 412 of file qutest.cpp.