OpenMS/source/TEST
.
On successful operation the test program will print out the message "PASSED", otherwise "FAILED".
If called with the -v option, the test program prints verbose information about individual tests.
If called with the -V option, the test program prints even more verbose information for every subtest.
Defines | |
#define | PRECISION(a) |
Define the precision for floating point comparisons. | |
#define | START_TEST(class_name, version) |
Create the test header for a certain class. | |
#define | END_TEST |
Termination of test program. | |
#define | CHECK(name_of_test) |
Declare subtest name. | |
#define | STATUS(message) |
Print a status message. | |
#define | OK STATUS("ok") |
Shorthand for STATUS("ok"). | |
#define | RESULT |
Check subtest result. | |
#define | NEW_TMP_FILE(filename) |
Create a temporary filename. | |
#define | TEST_REAL_EQUAL(a, b) |
Floating point equality macro. | |
#define | TEST_STRING_EQUAL(a, b) |
String equality macro. | |
#define | TEST_EQUAL(a, b) |
Generic equality macro. | |
#define | TEST_NOT_EQUAL(a, b) |
Generic inequality macro. | |
#define | TEST_EXCEPTION(exception_type, command) |
Exception test macro. | |
#define | NOT_TESTABLE |
Macro that suppresses the warning issued when no subtests are performed. | |
#define | TEST_EXCEPTION_WITH_MESSAGE(exception_type, command, message) |
Exception test macro (with test for exception message). | |
#define | ABORT_IF(condition) |
Skip remainder of subtest. | |
#define | TEST_FILE(filename, templatename) |
File comparison macro. |
#define ABORT_IF | ( | condition | ) |
Skip remainder of subtest.
If the condition is not fulfilled, the remainder of the test is skipped. The status (whether it fails or passes) remains unchanged.
#define CHECK | ( | name_of_test | ) |
Declare subtest name.
This macro is used to declare the name of a subtest. If you want to check e.g. the setName method of a class, insert a line CHECK(setName) in your test program. If the test program is called in verbose mode, this leads to the name of the subtest being printed on execution.
This macro also opens a try
block to catch any unexpected exceptions thrown in the course of a subtest. To catch wanted exceptions (i.e. to check for exceptions that are the expected result of some command) use the TEST_EXCEPTION macro. The try
block opened by CHECK is closed in RESULT, so these two macros have to be balanced.
#define END_TEST |
Termination of test program.
This macro implements the correct termination of the test program and should therefore be the last macro to call. It determines the exit code based on all previously run subtests and prints out the message "PASSED" or "FAILED". This macro also closes the global try
block opened by START_TEST and contains the related catch
clauses. If an exception is caught here, the test program fails.
#define NEW_TMP_FILE | ( | filename | ) |
Create a temporary filename.
This macro assigns a new temporary filename to the string variable given as its argument. The filename is created using the filename of the test and the line number where this macro is invoked, for example 'Matrix_test.C' might create a temporary file 'Matrix_test_268.tmp' if NEW_TMP_FILE is used in line 268. All temporary files are deleted if END_TEST is called.
filename | string will contain the filename on completion of the macro |
#define NOT_TESTABLE |
Macro that suppresses the warning issued when no subtests are performed.
Please use this macro only if the method cannot be tested at all or cannot be tested properly on its own. In the later case, the method must however be tested in tests of related methods.
#define OK STATUS("ok") |
Shorthand for STATUS("ok").
#define PRECISION | ( | a | ) |
Define the precision for floating point comparisons.
The macro TEST_REAL_EQUAL checks whether the floating point number returned by the subtest is close to the expected result by comparing the absolute value of the difference of the two values to PRECISION.
The default value is $10^{-6}$. It is possible to redefine precision in the test program by calling this macro with the new value.
#define RESULT |
Check subtest result.
Each elementary test macro updates an internal variable (TEST, defined by START_TEST ) that holds the state of the current subtest.
RESULT prints whether the subtest has failed or passed in verbose mode and updates the internal variables TEST::all_tests that describes the state of the whole class test. TEST::all_tests is initialized to be true. If any elementary test fails, TEST::test becomes false. At the time of the next call to RESULT, TEST::all_tests will be set to false, if TEST::test is false. One failed elementary test leads therefore to a failed subtest, which leads to a failed class test.
This macro closes the try
block opened by CHECK, so CHECK and RESULT have to be balanced, or some ugly compile-time errors may occur. RESULT first tries to catch all OpenMS
exceptions (i.e. exceptions derived from Exception::Base). If this fails, it tries to catch any exception. After the exception is thrown, the execution will continue with the next subtest, the current subtest will be marked as failed (as is the whole test program).
#define START_TEST | ( | class_name, | |||
version | ) |
Create the test header for a certain class.
This macro defines the start of the test program for a given classname. The classname is printed together with some information when calling the test program with any arguments (except for -v
or -V
).
This macro should be the first to call in a test program. It introduces a global try
block to catch any unwanted exceptions. If any of these exceptions occurs, all tests failed. Exceptions defined by OpenMS (i.e. exception classes derived from Exception::Base) provide some additional information that is evaluated by the END_TEST macro. The END_TEST macro also closes the try
block. This try
block should never catch an exception! All exceptions that are thrown due to some malfunction in one of the member functions should be caught by the try
block created by CHECK and RESULT.
#define STATUS | ( | message | ) |
Value:
if (TEST::verbose > 1) \ { \ if (!TEST::newline) \ { \ TEST::newline = true; \ std::cout << std::endl; \ } \ std::cout << " status (line " << __LINE__ << "): " \ << message << std::endl; \ }
If tests require longer preparations, STATUS may be used to print some intermediated progress messages. STATUS uses cout
to print these messages (in verbose mode only). The given stream expression message
is prefixed by the string status:
and terminated with a newline. All valid operations on a stream may be performed in message
.
Example: STATUS("just calculated x = " << setprecision(10) << x )
#define TEST_EQUAL | ( | a, | |||
b | ) |
Generic equality macro.
This macro uses the operator == to check its two arguments for equality. Besides handling some internal stuff, it basically evaluates #((a) == (b))#.
Remember that operator == has to be defined somehow for the two argument types.
a | value/object to test | |
b | expected value |
#define TEST_EXCEPTION | ( | exception_type, | |||
command | ) |
Exception test macro.
This macro checks if a given type of exception occured while executing the given command. Example:
exception_type | the exception-class | |
command | any general C++ or OpenMS-specific command |
#define TEST_EXCEPTION_WITH_MESSAGE | ( | exception_type, | |||
command, | |||||
message | ) |
Exception test macro (with test for exception message).
This macro checks if a given type of exception occured while executing the given command and additionally tests for the message of the exception. Example:
exception_type | the exception-class | |
command | any general C++ or OpenMS-specific command | |
message | the message the exception should give |
#define TEST_FILE | ( | filename, | |||
templatename | ) |
File comparison macro.
This macro is used to test file operations. It compares the file with name filename
against a template file templatename
. Corresponding lines of the two files have to be identical.
This macro evaluates its arguments once or twice, depending on verbosity settings.
#define TEST_NOT_EQUAL | ( | a, | |||
b | ) |
Generic inequality macro.
This macro checks for inequality as TEST_EQUAL tests for equality. The only difference between the two macros is that TEST_NOT_EQUAL evaluates #!((a) == (b))#.
a | value/object to test | |
b | forbidden value |
#define TEST_REAL_EQUAL | ( | a, | |||
b | ) |
Floating point equality macro.
Checks whether the absolute value of the difference of the two floating point values a and b is less or equal to the value defined by PRECISION.
a | floating point value to test | |
b | expected value |
#define TEST_STRING_EQUAL | ( | a, | |||
b | ) |
String equality macro.
Both arguments are converted to std::string and tested for equality. (That is, we check whether (std::string(a) == std::string(b))
holds.)
a | value to test | |
b | expected value |
Generated Tue Apr 1 15:36:40 2008 -- using doxygen 1.5.4 | OpenMS / TOPP 1.1 |