![]() |
OpenMS
|
Namespace for class tests. More...
Namespaces | |
| namespace | detail |
Classes | |
| struct | PrecisionWrapped |
| Stream wrapper printing a floating point value with full precision. More... | |
Typedefs | |
| using | ExceptionTranslator = bool(*)(std::string &description) |
| Translator producing a description of the currently handled exception. | |
Functions | |
| std::string | createTmpFileName (const std::string &file, int line, const std::string &extension="") |
| Creates a temporary file name from the test name and the line with the specified extension. | |
| void | testRealSimilar (const char *file, int line, long double number_1, const char *number_1_stringified, bool number_1_is_realtype, int number_1_written_digits, long double number_2, const char *number_2_stringified, bool, int number_2_written_digits) |
| Compare floating point numbers using absdiff_max_allowed and ratio_max_allowed. | |
| bool | isRealSimilar (long double number_1, long double number_2) |
| used by testRealSimilar() | |
| void | testStringSimilar (const char *file, int line, const std::string &string_1, const char *string_1_stringified, const std::string &string_2, const char *string_2_stringified) |
| Compare strings using absdiff_max_allowed and ratio_max_allowed. | |
| void | testStringEqual (const char *file, int line, const std::string &string_1, const char *string_1_stringified, const std::string &string_2, const char *string_2_stringified) |
| used by TEST_STRING_EQUAL | |
| bool | isFileSimilar (const std::string &filename_1, const std::string &filename_2) |
| Compare files using absdiff_max_allowed and ratio_max_allowed. | |
| void | initialNewline () |
| make sure we have a newline before results from first subtest | |
| void | printWithPrefix (const std::string &text, const int marked=-1) |
| print the text, each line gets a prefix, the marked line number gets a special prefix | |
| void | mainInit (const char *version, const char *class_name, int argc, const char *argv0) |
| Set up some classtest variables as obtained from the 'START_TEST' macro and check that no additional arguments were passed to the test executable. | |
| void | filesEqual (int line, const char *filename, const char *templatename, const char *filename_stringified, const char *templatename_stringified) |
| Test if two files are exactly equal (used in TEST_FILE_EQUAL macro) | |
| void | removeTempFiles () |
| removed all temporary files created with the NEW_TMP_FILE macro | |
| void | setWhitelist (const char *const, const int line, const std::string &whitelist) |
| set the whitelist_ | |
| template<typename T1 , typename T2 > | |
| void | testEqual (const char *, int line, const T1 &expression_1, const char *expression_1_stringified, const T2 &expression_2, const char *expression_2_stringified) |
| void | testTrue (const char *, int line, const bool expression_1, const char *expression_1_stringified) |
| void | testFalse (const char *, int line, const bool expression_1, const char *expression_1_stringified) |
| template<typename T1 , typename T2 > | |
| void | testNotEqual (const char *, int line, const T1 &expression_1, const char *expression_1_stringified, const T2 &expression_2, const char *expression_2_stringified) |
| void | registerExceptionTranslator (ExceptionTranslator translator) |
| Register an exception translator (idempotent; bounded, first-come first-served). | |
| bool | preconditionTestsEnabled () |
| void | setPreconditionTestsEnabled (bool enabled) |
| See preconditionTestsEnabled(). | |
| std::string | describeCaughtException () |
| void | printLastException (std::ostream &out) |
| int | endTestPostProcess (std::ostream &out) |
| void | endSectionPostProcess (std::ostream &out, const int line) |
| template<typename T > | |
| constexpr int | writtenDigits (const T &=T()) |
| Decimal digits to print for a value in TEST_REAL_SIMILAR reports. | |
| template<typename T > | |
| constexpr bool | isRealType (const T &) |
| Whether TEST_REAL_SIMILAR may convert a value of this type to double. | |
| template<typename FloatingPointType > | |
| PrecisionWrapped< FloatingPointType > | precisionWrapper (const FloatingPointType value) |
| template<typename FloatingPointType > | |
| std::ostream & | operator<< (std::ostream &os, const PrecisionWrapped< FloatingPointType > &p) |
| bool | validateTmpFiles (const std::vector< std::string > &file_names) |
| Validates the given files against their XML schema (if one applies). | |
Variables | |
| double | ratio_max_allowed |
| Maximum ratio of numbers allowed, see TOLERANCE_RELATIVE. | |
| double | ratio_max |
| Maximum ratio of numbers observed so far, see TOLERANCE_RELATIVE. | |
| double | ratio |
| Recent ratio of numbers, see TOLERANCE_RELATIVE. | |
| double | absdiff_max_allowed |
| Maximum absolute difference of numbers allowed, see TOLERANCE_ABSOLUTE. | |
| double | absdiff_max |
| Maximum difference of numbers observed so far, see TOLERANCE_ABSOLUTE. | |
| double | absdiff |
| Recent absolute difference of numbers, see TOLERANCE_ABSOLUTE. | |
| int | line_num_1_max |
| int | line_num_2_max |
| int | verbose |
| Verbosity level ( "-v" is 1 and "-V" is 2 ) | |
| bool | all_tests |
| Status of the whole test. | |
| bool | test |
| Status of the current subsection. | |
| bool | this_test |
| Status of last elementary test. | |
| int | exception |
| (Used by various macros. Indicates a rough category of the exception being caught.) | |
| std::string | exception_name |
| (Used by various macros. Stores the "name" of the exception, if applicable.) | |
| std::string | exception_message |
| (Used by various macros. Stores the "message" of the exception, if applicable.) | |
| std::string | test_name |
| Name of current subsection. | |
| int | start_section_line |
| Line where current subsection started. | |
| int | test_line |
| Line of current elementary test. | |
| const char * | version_string |
| Version string supplied with START_TEST. | |
| std::vector< std::string > | tmp_file_list |
| List of tmp file names (these will be cleaned up, see NEW_TMP_FILE) | |
| std::vector< unsigned int > | failed_lines_list |
| List of all failed lines for summary at the end of the test. | |
| std::ifstream | infile |
| Questionable file tested by TEST_FILE_EQUAL. | |
| std::ifstream | templatefile |
| Template (correct) file used by TEST_FILE_EQUAL. | |
| bool | equal_files |
| (A variable used by TEST_FILE_EQUAL) | |
| char | line_buffer [65536] |
| (A buffer for one line from a file. Used by TEST_FILE_EQUAL.) | |
| int | test_count |
| Counter for the number of elementary tests within the current subsection. | |
| std::string | add_message |
| See ADD_MESSAGE. | |
| std::string | fuzzy_message |
| Last message from a fuzzy comparison. Written by isRealSimilar(), testStringSimilar(), isFileSimilar(). Read by TEST_REAL_SIMILAR, TEST_STRING_SIMILAR, TEST_FILE_SIMILAR;. | |
| bool | newline |
| (Flags whether a new line is in place, depending on context and verbosity setting. Used by initialNewline() and some macros.) | |
Namespace for class tests.
| struct OpenMS::Internal::ClassTest::PrecisionWrapped |
Stream wrapper printing a floating point value with full precision.
The framework's own version of OpenMS::precisionWrapper (OpenMS/CONCEPT/PrecisionWrapper.h): printing goes through detail::toString, i.e. the same format as StringUtils::toStr(x, true). Used by TEST_FILE_SIMILAR's report.
| Class Members | ||
|---|---|---|
| FloatingPointType | value | |
| using ExceptionTranslator = bool (*)(std::string& description) |
Translator producing a description of the currently handled exception.
Called with an exception being handled (rethrow it with throw; internally). If the translator recognizes the type, it writes a one-line description (e.g. name, origin, message) into description and returns true; otherwise it returns false and must leave description alone.
The framework itself knows only std::exception. Test projects register translators for their library's exception hierarchy – see src/tests/class_tests/source/OpenMSTestSupport.cpp – which is how failure reports show OpenMS exception names without the framework depending on libOpenMS. (Same design as Catch2's exception translators.)
| std::string createTmpFileName | ( | const std::string & | file, |
| int | line, | ||
| const std::string & | extension = "" |
||
| ) |
Creates a temporary file name from the test name and the line with the specified extension.
| std::string describeCaughtException | ( | ) |
Describe the exception currently being handled: registered translators first, then std::exception's what(), then a generic fallback.
| void endSectionPostProcess | ( | std::ostream & | out, |
| const int | line | ||
| ) |
| int endTestPostProcess | ( | std::ostream & | out | ) |
| void filesEqual | ( | int | line, |
| const char * | filename, | ||
| const char * | templatename, | ||
| const char * | filename_stringified, | ||
| const char * | templatename_stringified | ||
| ) |
Test if two files are exactly equal (used in TEST_FILE_EQUAL macro)
| [in] | line | The line where the macro was called (for reporting) |
| [in] | filename | The temp file |
| [in] | templatename | The ground truth file |
| [in] | filename_stringified | The expression used as the first macro argument |
| [in] | templatename_stringified | The expression used as the second macro argument |
| void initialNewline | ( | ) |
make sure we have a newline before results from first subtest
Referenced by testEqual(), testFalse(), testNotEqual(), and testTrue().
| bool isFileSimilar | ( | const std::string & | filename_1, |
| const std::string & | filename_2 | ||
| ) |
Compare files using absdiff_max_allowed and ratio_max_allowed.
Side effects: Updates absdiff, ratio, fuzzy_message, line_num_1_max and line_num_2_max.
| bool isRealSimilar | ( | long double | number_1, |
| long double | number_2 | ||
| ) |
used by testRealSimilar()
|
constexpr |
Whether TEST_REAL_SIMILAR may convert a value of this type to double.
True for floating-point and class types implicitly convertible to double (DataValue, ParamValue); anything else is rejected at runtime, as before.
References OpenMS::C.
| void mainInit | ( | const char * | version, |
| const char * | class_name, | ||
| int | argc, | ||
| const char * | argv0 | ||
| ) |
Set up some classtest variables as obtained from the 'START_TEST' macro and check that no additional arguments were passed to the test executable.
| [in] | version | A version string, obtained from 'START_TEST(FuzzyStringComparator, "<VERSION>")' |
| [in] | class_name | The class under test (used for error messages etc), obtained from 'START_TEST(FuzzyStringComparator, "<VERSION>")' |
| [in] | argc | The number of arguments to the main() function of the class test (must be 1; test will quit otherwise) |
| [in] | argv0 | Name of the executable (for debug output) |
|
inline |
|
inline |
| bool preconditionTestsEnabled | ( | ) |
Whether TEST_PRECONDITION/POSTCONDITION_VIOLATED actually run their command. Off by default; the test-support TU of the library under test enables it when the library was built with its precondition checks active (OPENMS_ASSERTIONS), so the expectation always matches the library's real behavior.
| void printLastException | ( | std::ostream & | out | ) |
| void printWithPrefix | ( | const std::string & | text, |
| const int | marked = -1 |
||
| ) |
print the text, each line gets a prefix, the marked line number gets a special prefix
| void registerExceptionTranslator | ( | ExceptionTranslator | translator | ) |
Register an exception translator (idempotent; bounded, first-come first-served).
| void removeTempFiles | ( | ) |
removed all temporary files created with the NEW_TMP_FILE macro
| void setPreconditionTestsEnabled | ( | bool | enabled | ) |
| void setWhitelist | ( | const char * const | , |
| const int | line, | ||
| const std::string & | whitelist | ||
| ) |
set the whitelist_
| void testEqual | ( | const char * | , |
| int | line, | ||
| const T1 & | expression_1, | ||
| const char * | expression_1_stringified, | ||
| const T2 & | expression_2, | ||
| const char * | expression_2_stringified | ||
| ) |
|
inline |
References failed_lines_list, initialNewline(), stdcout, test, test_count, test_line, this_test, and verbose.
| void testNotEqual | ( | const char * | , |
| int | line, | ||
| const T1 & | expression_1, | ||
| const char * | expression_1_stringified, | ||
| const T2 & | expression_2, | ||
| const char * | expression_2_stringified | ||
| ) |
References failed_lines_list, initialNewline(), OpenMS::Internal::ClassTest::detail::printValue(), stdcout, test, test_count, test_line, this_test, and verbose.
| void testRealSimilar | ( | const char * | file, |
| int | line, | ||
| long double | number_1, | ||
| const char * | number_1_stringified, | ||
| bool | number_1_is_realtype, | ||
| int | number_1_written_digits, | ||
| long double | number_2, | ||
| const char * | number_2_stringified, | ||
| bool | , | ||
| int | number_2_written_digits | ||
| ) |
Compare floating point numbers using absdiff_max_allowed and ratio_max_allowed.
Side effects: Updates fuzzy_message.
| void testStringEqual | ( | const char * | file, |
| int | line, | ||
| const std::string & | string_1, | ||
| const char * | string_1_stringified, | ||
| const std::string & | string_2, | ||
| const char * | string_2_stringified | ||
| ) |
used by TEST_STRING_EQUAL
| void testStringSimilar | ( | const char * | file, |
| int | line, | ||
| const std::string & | string_1, | ||
| const char * | string_1_stringified, | ||
| const std::string & | string_2, | ||
| const char * | string_2_stringified | ||
| ) |
Compare strings using absdiff_max_allowed and ratio_max_allowed.
This is called by the TEST_STRING_SIMILAR macro.
Side effects: Updates absdiff, ratio, fuzzy_message, line_num_1_max and line_num_2_max.
|
inline |
References failed_lines_list, initialNewline(), stdcout, test, test_count, test_line, this_test, and verbose.
|
constexpr |
Decimal digits to print for a value in TEST_REAL_SIMILAR reports.
Framework copy of OpenMS::writtenDigits; class types convertible to double (DataValue, ParamValue) print like a double. Diverges from the old version in report precision only (never pass/fail): ParamValue prints at 15 not 6, and long/unsigned long use their own digits10 not int's.
References OpenMS::C.
|
extern |
Recent absolute difference of numbers, see TOLERANCE_ABSOLUTE.
|
extern |
Maximum difference of numbers observed so far, see TOLERANCE_ABSOLUTE.
|
extern |
Maximum absolute difference of numbers allowed, see TOLERANCE_ABSOLUTE.
|
extern |
See ADD_MESSAGE.
|
extern |
Status of the whole test.
|
extern |
(A variable used by TEST_FILE_EQUAL)
|
extern |
(Used by various macros. Indicates a rough category of the exception being caught.)
|
extern |
(Used by various macros. Stores the "message" of the exception, if applicable.)
|
extern |
(Used by various macros. Stores the "name" of the exception, if applicable.)
|
extern |
List of all failed lines for summary at the end of the test.
Referenced by testEqual(), testFalse(), testNotEqual(), and testTrue().
|
extern |
Last message from a fuzzy comparison. Written by isRealSimilar(), testStringSimilar(), isFileSimilar(). Read by TEST_REAL_SIMILAR, TEST_STRING_SIMILAR, TEST_FILE_SIMILAR;.
|
extern |
Questionable file tested by TEST_FILE_EQUAL.
|
extern |
(A buffer for one line from a file. Used by TEST_FILE_EQUAL.)
|
extern |
|
extern |
|
extern |
(Flags whether a new line is in place, depending on context and verbosity setting. Used by initialNewline() and some macros.)
|
extern |
Recent ratio of numbers, see TOLERANCE_RELATIVE.
|
extern |
Maximum ratio of numbers observed so far, see TOLERANCE_RELATIVE.
|
extern |
Maximum ratio of numbers allowed, see TOLERANCE_RELATIVE.
|
extern |
Line where current subsection started.
|
extern |
Template (correct) file used by TEST_FILE_EQUAL.
|
extern |
Status of the current subsection.
Referenced by testEqual(), testFalse(), testNotEqual(), and testTrue().
|
extern |
Counter for the number of elementary tests within the current subsection.
Referenced by testEqual(), testFalse(), testNotEqual(), and testTrue().
|
extern |
Line of current elementary test.
Referenced by testEqual(), testFalse(), testNotEqual(), and testTrue().
|
extern |
Name of current subsection.
|
extern |
Status of last elementary test.
Referenced by testEqual(), testFalse(), testNotEqual(), and testTrue().
|
extern |
List of tmp file names (these will be cleaned up, see NEW_TMP_FILE)
|
extern |
Verbosity level ( "-v" is 1 and "-V" is 2 )
Referenced by testEqual(), testFalse(), testNotEqual(), and testTrue().
|
extern |
Version string supplied with START_TEST.