Defines | |
| #define | cpl_assert(bool) |
| Evaluate an expression and return if it fails. | |
| #define | cpl_test(bool) |
| Evaluate an expression and increment an internal counter if zero. | |
| #define | cpl_test_init(REPORT, LEVEL) cpl_test_init_macro(__FILE__, REPORT, LEVEL) |
| Initialize CPL + CPL messaging + unit test. | |
| #define | cpl_test_leq(value, tolerance) cpl_test_leq_macro(value, tolerance, cpl_func, __FILE__, __LINE__) |
| Evaluate A <= B and increment an internal counter if it is not true. | |
| #define | cpl_test_zero(zero) |
| Evaluate an expression and increment an internal counter if non-zero. | |
Functions | |
| int | cpl_test_end (int nfail) |
| Finalize CPL and unit-testing environment and report any failures. | |
#include "cpl_test.h"
| #define cpl_assert | ( | bool | ) |
Value:
do { \ /* Evaluate bool just once */ \ const cpl_boolean cpl_assert_ok = (bool) ? CPL_TRUE : CPL_FALSE; \ cpl_test(cpl_assert_ok); \ if (cpl_assert_ok == CPL_FALSE) return cpl_test_end(1); \ } while (0)
| bool | The (boolean) expression to evaluate, side-effects are allowed |
int main (void) { cpl_test_init(CPL_MSG_WARNING); cpl_test(myfunc(&p)); cpl_assert(p != NULL); return cpl_test_end(0); }
| #define cpl_test | ( | bool | ) |
Value:
cpl_test_macro((int)(bool), CPL_TRUE, #bool, \ cpl_func, __FILE__, __LINE__)
| bool | The expression to evaluate, side-effects are allowed |
cpl_test(myfunc()); // myfunc() is expected to return non-zero
| #define cpl_test_init | ( | REPORT, | |||
| LEVEL | ) | cpl_test_init_macro(__FILE__, REPORT, LEVEL) |
Initialize CPL + CPL messaging + unit test.
| REPORT | The email address for the error message e.g. PACKAGE_BUGREPORT | |
| LEVEL | The default messaging level, e.g. CPL_MSG_WARNING |
| #define cpl_test_leq | ( | value, | |||
| tolerance | ) | cpl_test_leq_macro(value, tolerance, cpl_func, __FILE__, __LINE__) |
Evaluate A <= B and increment an internal counter if it is not true.
| value | The number to test | |
| tolerance | The upper limit to compare against |
cpl_test_leq(fabs(myfunc(&p)), DBL_EPSILON); cpl_test(p != NULL);
| #define cpl_test_zero | ( | zero | ) |
Value:
cpl_test_macro((int)(zero), CPL_FALSE, #zero, \
cpl_func, __FILE__, __LINE__)
| zero | The numerical expression to evaluate, side-effects are allowed |
cpl_test_zero(myfunc()); // myfunc() is expected to return zero
| int cpl_test_end | ( | int | nfail | ) |
Finalize CPL and unit-testing environment and report any failures.
| nfail | The number of failures counted apart from cpl_test() et al. |
Example of usage:
int main (void) { cpl_test_init(CPL_MSG_WARNING); cpl_test(myfunc(&p)); cpl_test(p != NULL); return cpl_test_end(0); }
1.5.1