Atto
1.4.0
The microscopic C test framework
|
Atto - the microscopic C unit test framework. More...
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stddef.h>
Go to the source code of this file.
Macros | |
#define | ATTO_VERSION "1.4.0" |
Semantic version of this file and framework. | |
#define | ATTO_FLOAT_EQ_ABSTOL (1e-5f) |
Absolute tolerance when comparing two single-precision floating point value for approximate-equality using atto_fapprox(). More... | |
#define | ATTO_DOUBLE_EQ_ABSTOL (1e-8) |
Absolute tolerance when comparing two double-precision floating point value for approximate-equality using atto_dapprox(). More... | |
#define | atto_report() |
Prints a brief report message providing the point where this report is and the amount of successes and failures at this point. More... | |
#define | atto_assert(expression) |
Verifies if the given boolean expression is true. More... | |
#define | atto_true(x) atto_assert(x) |
Verifies if the given boolean expression is true. More... | |
#define | atto_false(x) atto_assert(!(x)) |
Verifies if the given boolean expression is false. More... | |
#define | atto_eq(a, b) atto_assert((a) == (b)) |
Verifies if the two arguments are exactly equal. More... | |
#define | atto_neq(a, b) atto_assert((a) != (b)) |
Verifies if the two arguments are not equal. More... | |
#define | atto_gt(a, b) atto_assert((a) > (b)) |
Verifies if the first argument is strictly Greater Than the second. More... | |
#define | atto_ge(a, b) atto_assert((a) >= (b)) |
Verifies if the first argument is Greater or Equal to the second. More... | |
#define | atto_lt(a, b) atto_assert((a) < (b)) |
Verifies if the first argument is strictly Less Than the second. More... | |
#define | atto_le(a, b) atto_assert((a) <= (b)) |
Verifies if the first argument is Less or Equal to the second. More... | |
#define | atto_fdelta(a, b, delta) atto_assert(fabsf((a) - (b)) <= fabsf(delta)) |
Verifies if two single-precision floating point values are within a given absolute tolerance from each other. More... | |
#define | atto_fapprox(a, b) atto_fdelta((a), (b), ATTO_FLOAT_EQ_ABSTOL) |
Verifies if two single-precision floating point values are within a fixed absolute tolerance ATTO_FLOAT_EQ_ABSTOL from each other. More... | |
#define | atto_ddelta(a, b, delta) atto_assert(fabs((a) - (b)) <= fabs(delta)) |
Verifies if two double-precision floating point values are within a given absolute tolerance from each other. More... | |
#define | atto_dapprox(a, b) atto_ddelta((a), (b), ATTO_DOUBLE_EQ_ABSTOL) |
Verifies if two double-precision floating point values are within a fixed absolute tolerance ATTO_DOUBLE_EQ_ABSTOL from each other. More... | |
#define | atto_nan(value) atto_assert(isnan(value)) |
Verifies that the floating point value is Not a Number (NaN). More... | |
#define | atto_inf(value) atto_assert(isinf(value)) |
Verifies that the floating point value is infinity, either positive or negative. More... | |
#define | atto_plusinf(value) atto_assert((isinf(value)) && ((value) > 0)) |
Verifies that the floating point value is positive infinity. More... | |
#define | atto_minusinf(value) atto_assert((isinf(value)) && ((value) < 0)) |
Verifies that the floating point value is negative infinity. More... | |
#define | atto_finite(value) atto_assert(isfinite(value)) |
Verifies that the floating point value is finite, thus not NaN or +/- infinity. More... | |
#define | atto_notfinite(value) atto_assert(!isfinite(value)) |
Verifies that the floating point value is not finite, thus either NaN or +/- infinity. More... | |
#define | atto_flag(value, mask) atto_assert(((value) & (mask))) |
Verifies if the bits of the value specified by a bit mask are set to 1. More... | |
#define | atto_noflag(value, mask) atto_assert(((value) & (mask)) == 0) |
Verifies if the bits of the value specified by a bit mask are set to 0. More... | |
#define | atto_streq(a, b, maxlen) atto_assert(strncmp((a), (b), (maxlen)) == 0) |
Verifies if two strings are equal up to a given length or until the shortest string terminates. More... | |
#define | atto_memeq(a, b, len) atto_assert(memcmp((a), (b), len) == 0) |
Verifies if two memory sections are equal up to a given length. More... | |
#define | atto_memneq(a, b, len) atto_assert(memcmp((a), (b), len) != 0) |
Verifies if two memory sections are different within the given length. More... | |
#define | atto_zeros(x, len) |
Verifies if a memory section is filled with just zeros. More... | |
#define | atto_nzeros(x, len) |
Verifies if a memory section is not completely filled with zeros (there is at least one non-zero byte). More... | |
#define | atto_fail() atto_assert(0) |
Forces a failure of the test case, stopping it and reporting on standard output. | |
Variables | |
char | atto_at_least_one_fail |
Boolean indicating if all tests passed successfully (when 0) or not. More... | |
size_t | atto_counter_assert_failures |
Counter of all Atto assertion macro calls that failed the check. More... | |
size_t | atto_counter_assert_passes |
Counter of all Atto assertion macro calls that passed the check. More... | |
Atto - the microscopic C unit test framework.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define ATTO_FLOAT_EQ_ABSTOL (1e-5f) |
Absolute tolerance when comparing two single-precision floating point value for approximate-equality using atto_fapprox().
If the difference between the two float values is bigger than this tolerance, the assertion fails.
#define ATTO_DOUBLE_EQ_ABSTOL (1e-8) |
Absolute tolerance when comparing two double-precision floating point value for approximate-equality using atto_dapprox().
If the difference between the two double values is bigger than this tolerance, the assertion fails.
#define atto_report | ( | ) |
Prints a brief report message providing the point where this report is and the amount of successes and failures at this point.
Particularly useful to call it at the end of the test runner executable or after a certain group of test cases to verify that progress through the test suite is happening. In case of sudden crashes of the test suite, multiple of these reports may be added to aid debugging in understanding where the issue arisees.
#define atto_assert | ( | expression | ) |
Verifies if the given boolean expression is true.
Otherwise stops the test case immediately and reports the failing file, function and line number on standard output.
It's the most generic macro offered by Atto. If you need something more specific, try using the other macros instead.
The do-while(0)
construct allows to write multi-line macros.
If your system does not support printf()
, replace it with something else in this file! For example a transmit()
function to communicate the result to other devices.
Example:
#define atto_true | ( | x | ) | atto_assert(x) |
Verifies if the given boolean expression is true.
Just a rename of atto_assert() for consistency with atto_false().
#define atto_false | ( | x | ) | atto_assert(!(x)) |
Verifies if the given boolean expression is false.
Otherwise stops the test case immediately and reports the failing file, function and line number on standard output.
Example:
#define atto_eq | ( | a, | |
b | |||
) | atto_assert((a) == (b)) |
Verifies if the two arguments are exactly equal.
Otherwise stops the test case immediately and reports the failing file, function and line number on standard output.
It is recommended to use this macro instead of calling atto_assert(a == b)
to avoid mistyping the equality comparison operator ==
into the assignment operator =
.
Example:
#define atto_neq | ( | a, | |
b | |||
) | atto_assert((a) != (b)) |
Verifies if the two arguments are not equal.
Otherwise stops the test case immediately and reports the failing file, function and line number on standard output.
Example:
#define atto_gt | ( | a, | |
b | |||
) | atto_assert((a) > (b)) |
Verifies if the first argument is strictly Greater Than the second.
Otherwise stops the test case immediately and reports the failing file, function and line number on standard output.
Example:
#define atto_ge | ( | a, | |
b | |||
) | atto_assert((a) >= (b)) |
Verifies if the first argument is Greater or Equal to the second.
Otherwise stops the test case immediately and reports the failing file, function and line number on standard output.
Example:
#define atto_lt | ( | a, | |
b | |||
) | atto_assert((a) < (b)) |
Verifies if the first argument is strictly Less Than the second.
Otherwise stops the test case immediately and reports the failing file, function and line number on standard output.
Example:
#define atto_le | ( | a, | |
b | |||
) | atto_assert((a) <= (b)) |
Verifies if the first argument is Less or Equal to the second.
Otherwise stops the test case immediately and reports the failing file, function and line number on standard output.
Example:
#define atto_fdelta | ( | a, | |
b, | |||
delta | |||
) | atto_assert(fabsf((a) - (b)) <= fabsf(delta)) |
Verifies if two single-precision floating point values are within a given absolute tolerance from each other.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_fapprox | ( | a, | |
b | |||
) | atto_fdelta((a), (b), ATTO_FLOAT_EQ_ABSTOL) |
Verifies if two single-precision floating point values are within a fixed absolute tolerance ATTO_FLOAT_EQ_ABSTOL from each other.
Useful to check for almost-equality but ignoring minor rounding errors.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_ddelta | ( | a, | |
b, | |||
delta | |||
) | atto_assert(fabs((a) - (b)) <= fabs(delta)) |
Verifies if two double-precision floating point values are within a given absolute tolerance from each other.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_dapprox | ( | a, | |
b | |||
) | atto_ddelta((a), (b), ATTO_DOUBLE_EQ_ABSTOL) |
Verifies if two double-precision floating point values are within a fixed absolute tolerance ATTO_DOUBLE_EQ_ABSTOL from each other.
Useful to check for almost-equality but ignoring minor rounding errors.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_nan | ( | value | ) | atto_assert(isnan(value)) |
Verifies that the floating point value is Not a Number (NaN).
Otherwise stops the test case and reports on standard output.
Example:
#define atto_inf | ( | value | ) | atto_assert(isinf(value)) |
Verifies that the floating point value is infinity, either positive or negative.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_plusinf | ( | value | ) | atto_assert((isinf(value)) && ((value) > 0)) |
Verifies that the floating point value is positive infinity.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_minusinf | ( | value | ) | atto_assert((isinf(value)) && ((value) < 0)) |
Verifies that the floating point value is negative infinity.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_finite | ( | value | ) | atto_assert(isfinite(value)) |
Verifies that the floating point value is finite, thus not NaN or +/- infinity.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_notfinite | ( | value | ) | atto_assert(!isfinite(value)) |
Verifies that the floating point value is not finite, thus either NaN or +/- infinity.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_flag | ( | value, | |
mask | |||
) | atto_assert(((value) & (mask))) |
Verifies if the bits of the value specified by a bit mask are set to 1.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_noflag | ( | value, | |
mask | |||
) | atto_assert(((value) & (mask)) == 0) |
Verifies if the bits of the value specified by a bit mask are set to 0.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_streq | ( | a, | |
b, | |||
maxlen | |||
) | atto_assert(strncmp((a), (b), (maxlen)) == 0) |
Verifies if two strings are equal up to a given length or until the shortest string terminates.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_memeq | ( | a, | |
b, | |||
len | |||
) | atto_assert(memcmp((a), (b), len) == 0) |
Verifies if two memory sections are equal up to a given length.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_memneq | ( | a, | |
b, | |||
len | |||
) | atto_assert(memcmp((a), (b), len) != 0) |
Verifies if two memory sections are different within the given length.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_zeros | ( | x, | |
len | |||
) |
Verifies if a memory section is filled with just zeros.
Useful to check whether a memory location has been cleared.
Otherwise stops the test case and reports on standard output.
Example:
#define atto_nzeros | ( | x, | |
len | |||
) |
Verifies if a memory section is not completely filled with zeros (there is at least one non-zero byte).
Useful to check whether a memory location has been initialised to non-zero values, especially for random strings or data from an outside source we don't know the exact format of.
Otherwise stops the test case and reports on standard output.
Example:
|
extern |
Boolean indicating if all tests passed successfully (when 0) or not.
Useful as a value to return from the main function of the test executable, so that the test executable returns non-zero in case at least one test failed.
|
extern |
Counter of all Atto assertion macro calls that failed the check.
The user should not change this value, but may freely read it. Useful to inspect the amount of errors (which should be 0) for changes during different launches of the test suite.
|
extern |
Counter of all Atto assertion macro calls that passed the check.
The user should not change this value, but may freely read it. Useful to inspect the amount of passes for changes during different launches of the test suite.