Common Pipeline Library Reference
7.2.2
|
|
#define | cpl_test(bool) |
| Evaluate an expression and increment an internal counter if zero. More...
|
|
#define | cpl_test_abs(first, second, tolerance) |
| Test if two numerical expressions are within a given absolute tolerance. More...
|
|
#define | cpl_test_abs_complex(first, second, tolerance) |
| Test if two complex expressions are within a given absolute tolerance. More...
|
|
#define | cpl_test_array_abs(first, second, tolerance) |
| Test if two numerical arrays are identical within a given (absolute) tolerance. More...
|
|
#define | cpl_test_assert(bool) |
| Evaluate an expression and terminate the process if it fails. More...
|
|
#define | cpl_test_eq(first, second) |
| Test if two integer expressions are equal. More...
|
|
#define | cpl_test_eq_error(first, second) |
| Test if two error expressions are equal and reset the CPL error code. More...
|
|
#define | cpl_test_eq_mask(first, second) |
| Test if two CPL masks are equal. More...
|
|
#define | cpl_test_eq_ptr(first, second) |
| Test if two pointer expressions are equal. More...
|
|
#define | cpl_test_eq_string(first, second) |
| Test if two strings are equal. More...
|
|
#define | cpl_test_error(error) |
| Test and reset the CPL error code. More...
|
|
#define | cpl_test_errorstate(errorstate) |
| Test and if necessary reset the CPL errorstate. More...
|
|
#define | cpl_test_fits(fitsfile) |
| Test if a file is valid FITS using an external verification utility. More...
|
|
#define | cpl_test_image_abs(first, second, tolerance) |
| Test if two images are identical within a given (absolute) tolerance. More...
|
|
#define | cpl_test_image_rel(first, second, tolerance) |
| Test if two images are identical within a given (relative) tolerance. More...
|
|
#define | cpl_test_imagelist_abs(first, second, tolerance) |
| Test if two imagelists are identical within a given (absolute) tolerance. More...
|
|
#define | cpl_test_init(REPORT, LEVEL) |
| Initialize CPL + CPL messaging + unit test. More...
|
|
#define | cpl_test_leq(value, tolerance) |
| Evaluate A <= B and increment an internal counter if it is not true. More...
|
|
#define | cpl_test_lt(value, tolerance) |
| Evaluate A < B and increment an internal counter if it is not true. More...
|
|
#define | cpl_test_matrix_abs(first, second, tolerance) |
| Test if two matrices are identical within a given (absolute) tolerance. More...
|
|
#define | cpl_test_memory_is_empty() |
| Test if the memory system is empty. More...
|
|
#define | cpl_test_noneq(first, second) |
| Test if two integer expressions are not equal. More...
|
|
#define | cpl_test_noneq_ptr(first, second) |
| Test if two pointer expressions are not equal. More...
|
|
#define | cpl_test_noneq_string(first, second) |
| Test if two strings are not equal. More...
|
|
#define | cpl_test_nonnull(pointer) |
| Test if a pointer is non-NULL. More...
|
|
#define | cpl_test_null(pointer) |
| Test if a pointer is NULL and update an internal counter on failure. More...
|
|
#define | cpl_test_polynomial_abs(first, second, tolerance) |
| Test if two polynomials are identical within a given (absolute) tolerance. More...
|
|
#define | cpl_test_rel(first, second, tolerance) |
| Test if two numerical expressions are within a given relative tolerance. More...
|
|
#define | cpl_test_vector_abs(first, second, tolerance) |
| Test if two vectors are identical within a given (absolute) tolerance. More...
|
|
#define | cpl_test_zero(zero) |
| Evaluate an expression and increment an internal counter if non-zero. More...
|
|
This module provides various functions for unit testing.
- Synopsis:
-
◆ cpl_test
Evaluate an expression and increment an internal counter if zero.
- Parameters
-
bool | The expression to evaluate, side-effects are allowed |
- Note
- A zero value of the expression is a failure, other values are not
- Returns
- void
- See also
- cpl_test_init()
- Note
- This macro should be used for unit tests
Example of usage:
◆ cpl_test_abs
#define cpl_test_abs |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two numerical expressions are within a given absolute tolerance.
- Parameters
-
first | The first value in the comparison, side-effects are allowed |
second | The second value in the comparison, side-effects are allowed |
tolerance | A non-negative tolerance |
- Note
- If the tolerance is negative, the test will always fail
- See also
- cpl_test()
Example of usage:
◆ cpl_test_abs_complex
#define cpl_test_abs_complex |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two complex expressions are within a given absolute tolerance.
- Parameters
-
first | The first value in the comparison, side-effects are allowed |
second | The second value in the comparison, side-effects are allowed |
tolerance | A non-negative tolerance |
- Note
- If the tolerance is negative, the test will always fail
- See also
- cpl_test()
Example of usage:
◆ cpl_test_array_abs
#define cpl_test_array_abs |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two numerical arrays are identical within a given (absolute) tolerance.
- Parameters
-
first | The first array in the comparison |
second | The second array of identical size in the comparison |
tolerance | A non-negative tolerance |
- Returns
- void
- See also
- cpl_test_abs()
- Note
- The test will fail if one or both the arrays are NULL or of a non-numerical type
◆ cpl_test_assert
#define cpl_test_assert |
( |
|
bool | ) |
|
Evaluate an expression and terminate the process if it fails.
- Parameters
-
bool | The (boolean) expression to evaluate, side-effects are allowed |
- Note
- A zero value of the expression is a failure, other values are not
- Returns
- void
- See also
- cpl_test()
- Note
- This macro should be used for unit tests that cannot continue after a failure.
Example of usage:
◆ cpl_test_eq
#define cpl_test_eq |
( |
|
first, |
|
|
|
second |
|
) |
| |
Test if two integer expressions are equal.
- Parameters
-
first | The first value in the comparison, side-effects are allowed |
second | The second value in the comparison, side-effects are allowed |
- See also
- cpl_test()
- Returns
- void
Example of usage:
For comparison of floating point values, see cpl_test_abs() and cpl_test_rel().
◆ cpl_test_eq_error
#define cpl_test_eq_error |
( |
|
first, |
|
|
|
second |
|
) |
| |
Test if two error expressions are equal and reset the CPL error code.
- Parameters
-
first | The first value in the comparison |
second | The second value in the comparison |
- See also
- cpl_test_error
- Note
- If the two CPL error expressions are equal they will also be tested against the current CPL error code. After the test(s), the CPL errorstate is reset.
Example of usage:
◆ cpl_test_eq_mask
#define cpl_test_eq_mask |
( |
|
first, |
|
|
|
second |
|
) |
| |
Test if two CPL masks are equal.
- Parameters
-
first | The first mask or NULL of the comparison |
second | The second mask or NULL of the comparison |
- Note
- One or two NULL pointer(s) is considered a failure.
Example of usage:
◆ cpl_test_eq_ptr
#define cpl_test_eq_ptr |
( |
|
first, |
|
|
|
second |
|
) |
| |
Test if two pointer expressions are equal.
- Parameters
-
first | The first value in the comparison, side-effects are allowed |
second | The second value in the comparison, side-effects are allowed |
- See also
- cpl_test_eq()
- Returns
- void
Example of usage:
◆ cpl_test_eq_string
#define cpl_test_eq_string |
( |
|
first, |
|
|
|
second |
|
) |
| |
Test if two strings are equal.
- Parameters
-
first | The first string or NULL of the comparison |
second | The second string or NULL of the comparison |
- Note
- One or two NULL pointer(s) is considered a failure.
Example of usage:
◆ cpl_test_error
#define cpl_test_error |
( |
|
error | ) |
|
Test and reset the CPL error code.
- Parameters
-
error | The expected CPL error code (incl. CPL_ERROR_NONE) |
- See also
- cpl_test()
- Note
- After the test, the CPL errorstate is reset
- Returns
- void
Example of usage:
◆ cpl_test_errorstate
#define cpl_test_errorstate |
( |
|
errorstate | ) |
|
Test and if necessary reset the CPL errorstate.
- Parameters
-
errorstate | The expected CPL errorstate |
- See also
- cpl_test()
- Note
- After the test, the CPL errorstate is set to the provided state
- Returns
- void
This function is useful for verifying that a successful call to a function does not modify any pre-existing errors.
Example of usage:
◆ cpl_test_fits
#define cpl_test_fits |
( |
|
fitsfile | ) |
|
Test if a file is valid FITS using an external verification utility.
- Parameters
-
fitsfile | The file to verify, NULL causes failure |
- Note
- The external verification utility is specified with the environemt variable CPL_TEST_FITS, if is not set the test will pass on any non-NULL file.
Example of usage:
export CPL_TEST_FITS=/usr/local/bin/fitsverify
◆ cpl_test_image_abs
#define cpl_test_image_abs |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two images are identical within a given (absolute) tolerance.
- Parameters
-
first | The first image in the comparison |
second | The second image of identical size in the comparison |
tolerance | A non-negative tolerance |
- Returns
- void
- See also
- cpl_test_abs()
- Note
- The test will fail if one or both the images are NULL
◆ cpl_test_image_rel
#define cpl_test_image_rel |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two images are identical within a given (relative) tolerance.
- Parameters
-
first | The first image in the comparison |
second | The second image of identical size in the comparison |
tolerance | A non-negative tolerance |
- Returns
- void
- See also
- cpl_test_rel()
- Note
- The test will fail if one or both the images are NULL
For each pixel position the two values x, y must pass the test: |x - y| <= tol * min(|x|, |y|). This definition is chosen since it is commutative and meaningful also for zero-valued pixels.
◆ cpl_test_imagelist_abs
#define cpl_test_imagelist_abs |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two imagelists are identical within a given (absolute) tolerance.
- Parameters
-
first | The first imagelist in the comparison |
second | The second imagelist of identical size in the comparison |
tolerance | A non-negative tolerance |
- Returns
- void
- See also
- cpl_test_image_abs()
- Note
- The test will fail if one or both the imagelists are NULL
◆ cpl_test_init
#define cpl_test_init |
( |
|
REPORT, |
|
|
|
LEVEL |
|
) |
| |
Initialize CPL + CPL messaging + unit test.
- Parameters
-
REPORT | The email address for the error message e.g. PACKAGE_BUGREPORT |
LEVEL | The default messaging level, e.g. CPL_MSG_WARNING |
- Returns
- void
- See also
- cpl_init()
- Note
- This macro should be used at the beginning of main() of a unit test instead of cpl_init() and before any other CPL function call.
◆ cpl_test_leq
#define cpl_test_leq |
( |
|
value, |
|
|
|
tolerance |
|
) |
| |
Evaluate A <= B and increment an internal counter if it is not true.
- Parameters
-
value | The number to test |
tolerance | The upper limit to compare against |
- Returns
- void
- See also
- cpl_test_init()
- Note
- This macro should be used for unit tests
Example of usage:
◆ cpl_test_lt
#define cpl_test_lt |
( |
|
value, |
|
|
|
tolerance |
|
) |
| |
Evaluate A < B and increment an internal counter if it is not true.
- Parameters
-
value | The number to test |
tolerance | The upper limit to compare against |
- Returns
- void
- See also
- cpl_test_init()
- Note
- This macro should be used for unit tests
Example of usage:
◆ cpl_test_matrix_abs
#define cpl_test_matrix_abs |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two matrices are identical within a given (absolute) tolerance.
- Parameters
-
first | The first matrix in the comparison |
second | The second matrix of identical size in the comparison |
tolerance | A non-negative tolerance |
- Returns
- void
- See also
- cpl_test_abs()
- Note
- The test will fail if one or both the matrices are NULL
◆ cpl_test_memory_is_empty
#define cpl_test_memory_is_empty |
( |
| ) |
|
◆ cpl_test_noneq
#define cpl_test_noneq |
( |
|
first, |
|
|
|
second |
|
) |
| |
Test if two integer expressions are not equal.
- Parameters
-
first | The first value in the comparison, side-effects are allowed |
second | The second value in the comparison, side-effects are allowed |
- See also
- cpl_test_eq()
- Returns
- void
Example of usage:
◆ cpl_test_noneq_ptr
#define cpl_test_noneq_ptr |
( |
|
first, |
|
|
|
second |
|
) |
| |
Test if two pointer expressions are not equal.
- Parameters
-
first | The first value in the comparison, side-effects are allowed |
second | The second value in the comparison, side-effects are allowed |
- See also
- cpl_test_eq_ptr()
- Returns
- void
Example of usage:
◆ cpl_test_noneq_string
#define cpl_test_noneq_string |
( |
|
first, |
|
|
|
second |
|
) |
| |
Test if two strings are not equal.
- Parameters
-
first | The first string or NULL of the comparison |
second | The second string or NULL of the comparison |
- Note
- One or two NULL pointer(s) is considered a failure.
Example of usage:
◆ cpl_test_nonnull
#define cpl_test_nonnull |
( |
|
pointer | ) |
|
Test if a pointer is non-NULL.
- Parameters
-
pointer | The pointer to check, side-effects are allowed |
- See also
- cpl_test_nonnull()
- Returns
- void
Example of usage:
◆ cpl_test_null
#define cpl_test_null |
( |
|
pointer | ) |
|
Test if a pointer is NULL and update an internal counter on failure.
- Parameters
-
pointer | The NULL-pointer to check, side-effects are allowed |
- See also
- cpl_test()
- Returns
- void
Example of usage:
◆ cpl_test_polynomial_abs
#define cpl_test_polynomial_abs |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two polynomials are identical within a given (absolute) tolerance.
- Parameters
-
first | The first polynomial in the comparison |
second | The second polynomial in the comparison |
tolerance | A non-negative tolerance |
- Returns
- void
- See also
- cpl_test_abs(), cpl_polynomial_compare()
- Note
- The test will fail if one or both the polynomials are NULL
◆ cpl_test_rel
#define cpl_test_rel |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two numerical expressions are within a given relative tolerance.
- Parameters
-
first | The first value in the comparison, side-effects are allowed |
second | The second value in the comparison, side-effects are allowed |
tolerance | A non-negative tolerance |
- Note
- If the tolerance is negative or if one but not both of the two values is zero, the test will always fail. If both values are zero, the test will succeed for any non-negative tolerance. The test is commutative in the two values.
- See also
- cpl_test()
The test is carried out by comparing the absolute value of the difference abs (first - second) to the product of the tolerance and the minimum of the absolute value of the two values, tolerance * min(abs(first), abs(second)) (The test is implemented like this to avoid division with a number that may be zero.
Example of usage:
◆ cpl_test_vector_abs
#define cpl_test_vector_abs |
( |
|
first, |
|
|
|
second, |
|
|
|
tolerance |
|
) |
| |
Test if two vectors are identical within a given (absolute) tolerance.
- Parameters
-
first | The first vector in the comparison |
second | The second vector of identical size in the comparison |
tolerance | A non-negative tolerance |
- Returns
- void
- See also
- cpl_test_abs()
- Note
- The test will fail if one or both the vectors are NULL
◆ cpl_test_zero
#define cpl_test_zero |
( |
|
zero | ) |
|
Evaluate an expression and increment an internal counter if non-zero.
- Parameters
-
zero | The numerical expression to evaluate, side-effects are allowed |
- Note
- A zero value of the expression is a success, other values are not
- Returns
- void
- See also
- cpl_test()
- Note
- This macro should be used for unit tests
Example of usage:
◆ cpl_test_end()
Finalize CPL and unit-testing environment and report any failures.
- Parameters
-
nfail | The number of failures counted apart from cpl_test() et al. |
- Returns
- EXIT_SUCCESS iff the CPL errorstate is clean
- Note
- This function should be used for the final return from a unit test
- See also
- cpl_test_init()
nfail should normally be zero, but may be set to a positive number when it is necessary to ensure a failure. nfail should only be negative in the unit test of the unit-test functions themselves.
Example of usage:
◆ cpl_test_get_bytes_image()
size_t cpl_test_get_bytes_image |
( |
const cpl_image * |
self | ) |
|
◆ cpl_test_get_bytes_imagelist()
size_t cpl_test_get_bytes_imagelist |
( |
const cpl_imagelist * |
self | ) |
|
◆ cpl_test_get_bytes_matrix()
size_t cpl_test_get_bytes_matrix |
( |
const cpl_matrix * |
self | ) |
|
◆ cpl_test_get_bytes_vector()
size_t cpl_test_get_bytes_vector |
( |
const cpl_vector * |
self | ) |
|
Get the amount of storage [bytes] for the CPL object.
- Parameters
-
- Returns
- The size in bytes
- Note
- Passing NULL is allowed and will return zero
Example of usage:
int my_benchmark (void)
{
double walltime, tstop;
myfunc(mydata);
walltime = tstop - tstart;
if (walltime > 0.0) {
(double)storage/walltime);
}
}
References cpl_vector_get_size().
◆ cpl_test_get_failed()
Get the number of failed CPL tests.
- Returns
- The count of failed tests
- See also
- cpl_test_get_tested()
Example of usage:
void my_tester (void)
{
}
}
◆ cpl_test_get_tested()
◆ cpl_test_get_walltime()
double cpl_test_get_walltime |
( |
void |
| ) |
|
Get the process wall-clock time, when available.
- Returns
- The process wall-clock time in seconds.
- Note
- Will always return 0 if clock_gettime() and gettimeofday() are unavailable or failing
- See also
- clock_gettime(), gettimeofday()
Example of usage:
int my_benchmark (void)
{
double walltime, tstop;
myfunc();
walltime = tstop - tstart;
cpl_msg_info(cpl_func,
"The call took %g seconds of wall-clock time",
walltime);
}
#define cpl_test_error(error)
Test and reset the CPL error code.
Definition: cpl_test.h:258
#define cpl_test_noneq(first, second)
Test if two integer expressions are not equal.
Definition: cpl_test.h:364
size_t cpl_test_get_bytes_vector(const cpl_vector *self)
Get the amount of storage [bytes] for the CPL object.
Definition: cpl_test.c:365
cpl_errorstate cpl_errorstate_get(void)
Get the CPL errorstate.
Definition: cpl_errorstate.c:192
#define cpl_test_errorstate(errorstate)
Test and if necessary reset the CPL errorstate.
Definition: cpl_test.h:221
#define cpl_test_rel(first, second, tolerance)
Test if two numerical expressions are within a given relative tolerance.
Definition: cpl_test.h:921
#define cpl_test_assert(bool)
Evaluate an expression and terminate the process if it fails.
Definition: cpl_test.h:984
#define cpl_test_eq_string(first, second)
Test if two strings are equal.
Definition: cpl_test.h:456
#define cpl_test_leq(value, tolerance)
Evaluate A <= B and increment an internal counter if it is not true.
Definition: cpl_test.h:586
cpl_size cpl_test_get_failed(void)
Get the number of failed CPL tests.
Definition: cpl_test.c:326
int cpl_test_end(cpl_size nfail)
Finalize CPL and unit-testing environment and report any failures.
Definition: cpl_test.c:2713
#define cpl_test_fits(fitsfile)
Test if a file is valid FITS using an external verification utility.
Definition: cpl_test.h:525
@ CPL_ERROR_NULL_INPUT
Definition: cpl_error.h:420
#define cpl_test_init(REPORT, LEVEL)
Initialize CPL + CPL messaging + unit test.
Definition: cpl_test.h:66
#define cpl_test_noneq_ptr(first, second)
Test if two pointer expressions are not equal.
Definition: cpl_test.h:425
#define cpl_test_lt(value, tolerance)
Evaluate A < B and increment an internal counter if it is not true.
Definition: cpl_test.h:617
#define cpl_test_eq(first, second)
Test if two integer expressions are equal.
Definition: cpl_test.h:333
#define cpl_test_abs(first, second, tolerance)
Test if two numerical expressions are within a given absolute tolerance.
Definition: cpl_test.h:648
#define cpl_test_eq_ptr(first, second)
Test if two pointer expressions are equal.
Definition: cpl_test.h:395
#define cpl_test_null(pointer)
Test if a pointer is NULL and update an internal counter on failure.
Definition: cpl_test.h:150
#define cpl_test_eq_mask(first, second)
Test if two CPL masks are equal.
Definition: cpl_test.h:554
enum _cpl_error_code_ cpl_error_code
The cpl_error_code type definition.
Definition: cpl_error.h:453
#define cpl_test_abs_complex(first, second, tolerance)
Test if two complex expressions are within a given absolute tolerance.
Definition: cpl_test.h:680
#define cpl_test_noneq_string(first, second)
Test if two strings are not equal.
Definition: cpl_test.h:487
#define cpl_test(bool)
Evaluate an expression and increment an internal counter if zero.
Definition: cpl_test.h:89
@ CPL_ERROR_EOL
Definition: cpl_error.h:442
long long cpl_size
The type used for sizes and indices in CPL.
Definition: cpl_type.h:210
void cpl_msg_info(const char *component, const char *format,...)
Display an information message.
Definition: cpl_msg.c:1661
#define cpl_test_nonnull(pointer)
Test if a pointer is non-NULL.
Definition: cpl_test.h:180
#define cpl_test_eq_error(first, second)
Test if two error expressions are equal and reset the CPL error code.
Definition: cpl_test.h:299
double cpl_test_get_walltime(void)
Get the process wall-clock time, when available.
Definition: cpl_test.c:248
#define cpl_test_zero(zero)
Evaluate an expression and increment an internal counter if non-zero.
Definition: cpl_test.h:120
#define cpl_error_set(function, code)
Set CPL error code, function name, source file and line number where an error occurred.
Definition: cpl_error.h:257
@ CPL_ERROR_NONE
Definition: cpl_error.h:396