45 #include <OpenMS/OpenMSConfig.h> 46 #include <OpenMS/config.h> 58 #define stdcout std::cout 74 validate(
const std::vector<std::string>& file_names);
77 std::string OPENMS_DLLAPI
81 inline bool OPENMS_DLLAPI
88 inline bool OPENMS_DLLAPI
95 inline bool OPENMS_DLLAPI
102 inline bool OPENMS_DLLAPI
109 inline bool OPENMS_DLLAPI
116 template <
typename T>
130 const char* number_1_stringified,
131 bool number_1_is_realtype,
Int number_1_written_digits,
132 long double number_2,
const char* number_2_stringified,
133 bool ,
Int number_2_written_digits);
148 const std::string& string_1,
149 const char* string_1_stringified,
150 const std::string& string_2,
151 const char* string_2_stringified);
156 const std::string& string_1,
157 const char* string_1_stringified,
158 const std::string& string_2,
159 const char* string_2_stringified);
168 const std::string& filename_2);
187 void OPENMS_DLLAPI
mainInit(
const char* version,
const char* class_name,
int argc,
const char* argv0);
198 void OPENMS_DLLAPI
filesEqual(
int line,
const char* filename,
const char* templatename,
const char* filename_stringified,
const char* templatename_stringified);
206 const std::string& whitelist);
215 extern OPENMS_DLLAPI
double ratio;
224 extern OPENMS_DLLAPI
double absdiff;
230 extern OPENMS_DLLAPI
int verbose;
236 extern OPENMS_DLLAPI
bool test;
251 extern OPENMS_DLLAPI std::string
test_name;
269 extern OPENMS_DLLAPI std::ifstream
infile;
293 extern OPENMS_DLLAPI
bool newline;
295 template <
typename T1,
typename T2>
297 testEqual(
const char* ,
int line,
const T1& expression_1,
298 const char* expression_1_stringified,
299 const T2& expression_2,
300 const char* expression_2_stringified)
304 this_test = bool(expression_1 == T1(expression_2));
312 stdcout <<
" + line " << line <<
": TEST_EQUAL(" 313 << expression_1_stringified <<
',' 314 << expression_2_stringified <<
"): got '" << expression_1
315 <<
"', expected '" << expression_2 <<
"'\n";
320 stdcout <<
" - line " << line <<
": TEST_EQUAL(" 321 << expression_1_stringified <<
',' 322 << expression_2_stringified <<
"): got '" << expression_1
323 <<
"', expected '" << expression_2 <<
"'\n";
329 void testTrue(
const char* ,
int line,
const bool expression_1,
const char* expression_1_stringified)
341 stdcout <<
" + line " << line <<
": TEST_TRUE(" << expression_1_stringified <<
"): ok\n";
346 stdcout <<
" - line " << line <<
": TEST_TRUE(" << expression_1_stringified <<
"): failed\n";
352 void testFalse(
const char* ,
int line,
const bool expression_1,
const char* expression_1_stringified)
364 stdcout <<
" + line " << line <<
": TEST_FALSE(" << expression_1_stringified <<
"): ok\n";
369 stdcout <<
" - line " << line <<
": TEST_FALSE(" << expression_1_stringified <<
"): failed\n";
375 template <
typename T1,
typename T2>
378 const char* expression_1_stringified,
379 const T2& expression_2,
380 const char* expression_2_stringified)
384 this_test = !(expression_1 == T1(expression_2));
392 stdcout <<
" + line " << line <<
": TEST_NOT_EQUAL(" 393 << expression_1_stringified <<
',' 394 << expression_2_stringified <<
"): got '" << expression_1
395 <<
"', forbidden is '" << expression_2 <<
"'\n";
400 stdcout <<
" - line " << line <<
": TEST_NOT_EQUAL(" 401 << expression_1_stringified <<
',' 402 << expression_2_stringified <<
"): got '" << expression_1
403 <<
"', forbidden is '" << expression_2 <<
"'\n";
474 #define START_TEST(class_name, version) \ 475 int main(int argc, char** argv) \ 477 TEST::mainInit(version, #class_name, argc, argv[0]); \ 496 TEST::printLastException(stdcout); \ 498 return TEST::endTestPostProcess(stdcout); \ 523 #define START_SECTION(name_of_test) \ 525 TEST::newline = false; \ 526 TEST::test_name = # name_of_test; \ 527 TEST::test_count = 0; \ 528 TEST::start_section_line = __LINE__; \ 529 stdcout << "checking " << TEST::test_name << " ... " << std::flush; \ 560 #define END_SECTION \ 566 TEST::printLastException(stdcout);\ 568 TEST::endSectionPostProcess(stdcout, __LINE__); 592 #define TEST_EQUAL(a, b) TEST::testEqual(__FILE__, __LINE__, (a), (# a), (b), (# b)); 603 #define TEST_TRUE(a) TEST::testTrue(__FILE__, __LINE__, (a), (#a)); 614 #define TEST_FALSE(a) TEST::testFalse(__FILE__, __LINE__, (a), (#a)); 628 #define TEST_NOT_EQUAL(a, b) TEST::testNotEqual(__FILE__, __LINE__, (a), (# a), (b), (# b)); 642 #define TEST_STRING_EQUAL(a, b) TEST::testStringEqual(__FILE__, __LINE__, (a), (# a), (b), (# b)); 658 #define TEST_FILE_EQUAL(filename, templatename) \ 660 TEST::filesEqual(__LINE__, filename, templatename, #filename, #templatename); \ 678 #define TEST_REAL_SIMILAR(a, b) TEST::testRealSimilar(__FILE__, __LINE__, (a), (# a), TEST::isRealType(a), writtenDigits(a), (b), (# b), TEST::isRealType(b), writtenDigits(b)); 695 #define TEST_STRING_SIMILAR(a, b) TEST::testStringSimilar(__FILE__, __LINE__, (a), (# a), (b), (# b)); 711 #define TEST_FILE_SIMILAR(a, b) \ 713 ++TEST::test_count; \ 714 TEST::test_line = __LINE__; \ 715 TEST::this_test = TEST::isFileSimilar((a), (b)); \ 716 TEST::test = TEST::test && TEST::this_test; \ 718 TEST::initialNewline(); \ 719 if (TEST::this_test) \ 721 if (TEST::verbose > 1) \ 723 stdcout << " + line " << __LINE__ \ 724 << ": TEST_FILE_SIMILAR(" # a "," # b "): absolute: " \ 725 << precisionWrapper(TEST::absdiff) \ 727 << precisionWrapper(TEST::absdiff_max_allowed) \ 729 << precisionWrapper(TEST::ratio) \ 731 << precisionWrapper(TEST::ratio_max_allowed) \ 733 stdcout << "message: \n"; \ 734 stdcout << TEST::fuzzy_message; \ 739 stdcout << " - line " << TEST::test_line << \ 740 ": TEST_FILE_SIMILAR(" # a "," # b ") ... -\n"; \ 741 stdcout << "message: \n"; \ 742 stdcout << TEST::fuzzy_message; \ 743 TEST::failed_lines_list.push_back(TEST::test_line); \ 760 #define TOLERANCE_RELATIVE(a) \ 761 TEST::ratio_max_allowed = (a); \ 763 TEST::initialNewline(); \ 764 if (TEST::verbose > 1) \ 766 stdcout << " + line " << __LINE__ << \ 767 ": TOLERANCE_RELATIVE(" << TEST::ratio_max_allowed << \ 768 ") (\"" # a "\")\n"; \ 783 #define TOLERANCE_ABSOLUTE(a) \ 784 TEST::absdiff_max_allowed = (a); \ 786 TEST::initialNewline(); \ 787 if (TEST::verbose > 1) \ 789 stdcout << " + line " << __LINE__ << \ 790 ": TOLERANCE_ABSOLUTE(" << TEST::absdiff_max_allowed << \ 791 ") (\"" # a "\")\n"; \ 800 #define WHITELIST(a) TEST::setWhitelist(__FILE__, __LINE__, (a)); 814 #define TEST_EXCEPTION(exception_type, command) \ 816 ++TEST::test_count; \ 817 TEST::test_line = __LINE__; \ 818 TEST::exception = 0; \ 823 catch (exception_type&) \ 825 TEST::exception = 1; \ 827 catch (::OpenMS::Exception::BaseException& e) \ 829 TEST::exception = 2; \ 830 TEST::exception_name = e.getName(); \ 834 TEST::exception = 3; \ 836 TEST::this_test = (TEST::exception == 1); \ 837 TEST::test = TEST::test && TEST::this_test; \ 840 TEST::initialNewline(); \ 841 switch (TEST::exception) \ 844 stdcout << " - line " << TEST::test_line << \ 845 ": TEST_EXCEPTION(" # exception_type "," # command \ 846 "): no exception thrown!\n"; \ 847 TEST::failed_lines_list.push_back(TEST::test_line); \ 850 if (TEST::verbose > 1) \ 852 stdcout << " + line " << TEST::test_line << \ 853 ": TEST_EXCEPTION(" # exception_type "," # command \ 858 stdcout << " - line " << TEST::test_line << \ 859 ": TEST_EXCEPTION(" # exception_type "," # command \ 860 "): wrong exception thrown! \"" \ 861 << TEST::exception_name << "\"\n"; \ 862 TEST::failed_lines_list.push_back(TEST::test_line); \ 865 stdcout << " - line " << TEST::test_line << \ 866 ": TEST_EXCEPTION(" # exception_type "," # command \ 867 "): wrong exception thrown!\n"; \ 868 TEST::failed_lines_list.push_back(TEST::test_line); \ 885 #ifdef OPENMS_ASSERTIONS 886 #define TEST_PRECONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Precondition, command); 888 #define TEST_PRECONDITION_VIOLATED(command) STATUS("TEST_PRECONDITION_VIOLATED(" # command ") - skipped"); 902 #ifdef OPENMS_ASSERTIONS 903 #define TEST_POSTCONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Postcondition, command); 905 #define TEST_POSTCONDITION_VIOLATED(command) STATUS("TEST_POSTCONDITION_VIOLATED(" # command ") - skipped"); 925 #define TEST_EXCEPTION_WITH_MESSAGE(exception_type, command, message) \ 927 ++TEST::test_count; \ 928 TEST::test_line = __LINE__; \ 929 TEST::exception = 0; \ 934 catch (exception_type& et) \ 936 if (std::string(et.what()) != std::string(message)) \ 938 TEST::exception = 4; \ 939 TEST::exception_message = et.what(); \ 941 else TEST::exception = 1; \ 943 catch (::OpenMS::Exception::BaseException& e) \ 945 TEST::exception = 2; \ 946 TEST::exception_name = e.getName(); \ 950 TEST::exception = 3; \ 952 TEST::this_test = (TEST::exception == 1); \ 953 TEST::test = TEST::test && TEST::this_test; \ 956 TEST::initialNewline(); \ 957 switch (TEST::exception) \ 960 stdcout << " - line " << TEST::test_line << \ 961 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \ 962 "): no exception thrown!\n"; \ 963 TEST::failed_lines_list.push_back(TEST::test_line); \ 966 if (TEST::verbose > 1) \ 969 stdcout << " + line " << TEST::test_line << \ 970 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \ 975 stdcout << " - line " << TEST::test_line << \ 976 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \ 977 "): wrong exception thrown! \"" << \ 978 TEST::exception_name << "\"\n"; \ 979 TEST::failed_lines_list.push_back(TEST::test_line); \ 982 stdcout << " - line " << TEST::test_line << \ 983 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \ 984 "): wrong exception thrown!\n"; \ 985 TEST::failed_lines_list.push_back(TEST::test_line); \ 988 stdcout << " - line " << TEST::test_line << \ 989 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \ 990 "): exception has wrong message: got '" << \ 991 TEST::exception_message << \ 993 (message) << "'\n"; \ 994 TEST::failed_lines_list.push_back(TEST::test_line); \ 1015 #define NEW_TMP_FILE(filename) \ 1017 filename = TEST::tmpFileName(__FILE__, __LINE__); \ 1018 TEST::tmp_file_list.push_back(filename); \ 1020 TEST::initialNewline(); \ 1021 stdcout << " creating new temporary filename '" \ 1036 #define ABORT_IF(condition) \ 1040 TEST::test_line = __LINE__; \ 1041 TEST::this_test = false; \ 1042 TEST::test = TEST::test && TEST::this_test; \ 1043 TEST::failed_lines_list.push_back(TEST::test_line); \ 1044 TEST::initialNewline(); \ 1045 stdcout << " - line " << TEST::test_line << \ 1046 ": ABORT_IF(" # condition "): TEST ABORTED\n"; \ 1068 #define STATUS(message) \ 1070 TEST::initialNewline(); \ 1071 stdcout << " line " \ 1087 #define ADD_MESSAGE(message) \ 1088 TEST::add_message = message; 1099 #define NOT_TESTABLE \ 1100 TEST::test_count = 1; double absdiff_max_allowed
Maximum absolute difference of numbers allowed, see TOLERANCE_ABSOLUTE.
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 testFalse(const char *, int line, const bool expression_1, const char *expression_1_stringified)
Definition: ClassTest.h:352
int test_count
Counter for the number of elementary tests within the current subsection.
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 testTrue(const char *, int line, const bool expression_1, const char *expression_1_stringified)
Definition: ClassTest.h:329
std::ifstream templatefile
Template (correct) file used by TEST_FILE_EQUAL.
std::string exception_name
(Used by various macros. Stores the "name" of the exception, if applicable.)
bool newline
(Flags whether a new line is in place, depending on context and verbosity setting. Used by initialNewline() and some macros.)
bool this_test
Status of last elementary test.
std::ifstream infile
Questionable file tested by TEST_FILE_EQUAL.
int start_section_line
Line where current subsection started.
std::vector< std::string > tmp_file_list
List of tmp file names (these will be cleaned up, see NEW_TMP_FILE)
void setWhitelist(const char *const, const int line, const std::string &whitelist)
set the whitelist_
std::string add_message
See ADD_MESSAGE.
double ratio_max
Maximum ratio of numbers observed so far, see TOLERANCE_RELATIVE.
void removeTempFiles()
removed all temporary files created with the NEW_TMP_FILE macro
void testEqual(const char *, int line, const T1 &expression_1, const char *expression_1_stringified, const T2 &expression_2, const char *expression_2_stringified)
Definition: ClassTest.h:297
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::string tmpFileName(const std::string &file, int line)
Creates a temporary file name from the test name and the line.
char line_buffer[65536]
(A buffer for one line from a file. Used by TEST_FILE_EQUAL.)
bool isRealType(float)
This overload returns true; float is a floating point type.
Definition: ClassTest.h:82
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:58
int endTestPostProcess(std::ostream &out)
#define stdcout
Provide a point of redirection for testing the test macros, see ClassTest_test.cpp.
Definition: ClassTest.h:58
std::string exception_message
(Used by various macros. Stores the "message" of the exception, if applicable.)
bool equal_files
(A variable used by TEST_FILE_EQUAL)
void testNotEqual(const char *, int line, const T1 &expression_1, const char *expression_1_stringified, const T2 &expression_2, const char *expression_2_stringified)
Definition: ClassTest.h:377
int exception
(Used by various macros. Indicates a rough category of the exception being caught.)
double ratio
Recent ratio of numbers, see TOLERANCE_RELATIVE.
const char * version_string
Version string supplied with START_TEST.
bool all_tests
Status of the whole test.
int test_line
Line of current elementary test.
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.
void initialNewline()
make sure we have a newline before results from first subtest
std::string test_name
Name of current subsection.
std::vector< UInt > failed_lines_list
List of all failed lines for summary at the end of the test.
Namespace for class tests.
Definition: ClassTest.h:66
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 ...
bool isRealSimilar(long double number_1, long double number_2)
used by testRealSimilar()
double absdiff
Recent absolute difference of numbers, see TOLERANCE_ABSOLUTE.
void endSectionPostProcess(std::ostream &out, const int line)
bool isFileSimilar(const std::string &filename_1, const std::string &filename_2)
Compare files using absdiff_max_allowed and ratio_max_allowed.
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:54
bool test
Status of the current subsection.
void printLastException(std::ostream &out)
int Int
Signed integer type.
Definition: Types.h:102
double absdiff_max
Maximum difference of numbers observed so far, see TOLERANCE_ABSOLUTE.
bool validate(const std::vector< std::string > &file_names)
Validates the given files against the XML schema (if available)
int verbose
Verbosity level ( "-v" is 1 and "-V" is 2 )
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 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 ...
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;.
double ratio_max_allowed
Maximum ratio of numbers allowed, see TOLERANCE_RELATIVE.