30#define stdcout std::cout
56 const char* number_1_stringified,
57 bool number_1_is_realtype,
int number_1_written_digits,
58 long double number_2,
const char* number_2_stringified,
59 bool ,
int number_2_written_digits);
74 const std::string& string_1,
75 const char* string_1_stringified,
76 const std::string& string_2,
77 const char* string_2_stringified);
82 const std::string& string_1,
83 const char* string_1_stringified,
84 const std::string& string_2,
85 const char* string_2_stringified);
94 const std::string& filename_2);
113 void mainInit(
const char* version,
const char* class_name,
int argc,
const char* argv0);
124 void filesEqual(
int line,
const char* filename,
const char* templatename,
const char* filename_stringified,
const char* templatename_stringified);
132 const std::string& whitelist);
195 extern std::ifstream
infile;
221 template <
typename T1,
typename T2>
223 testEqual(
const char* ,
int line,
const T1& expression_1,
224 const char* expression_1_stringified,
225 const T2& expression_2,
226 const char* expression_2_stringified)
235 if constexpr (std::is_same_v<T1, std::string>)
241 this_test = bool(expression_1 == T1(expression_2));
248 stdcout <<
' ' << (
this_test ?
'+' :
'-') <<
" line " << line <<
" : TEST_EQUAL(" << expression_1_stringified <<
','
249 << expression_2_stringified <<
"): got '";
252 if constexpr (std::is_same_v<std::remove_cv_t<T1>,
char16_t*> || std::is_same_v<std::remove_cv_t<T2>,
char16_t*>)
254 stdcout << (expression_1 ==
nullptr ?
"(null)" :
"(char16_t*)") <<
"', expected '"
255 << (expression_2 ==
nullptr ?
"(null)" :
"(char16_t*)") <<
"'\n";
257 else if constexpr (std::is_enum_v<T1> && std::is_enum_v<T2>)
259 stdcout << static_cast<int>(expression_1) <<
"', expected '" <<
static_cast<int>(expression_2) <<
"'\n";
276 inline void testTrue(
const char* ,
int line,
const bool expression_1,
const char* expression_1_stringified)
288 stdcout <<
" + line " << line <<
": TEST_TRUE(" << expression_1_stringified <<
"): ok\n";
293 stdcout <<
" - line " << line <<
": TEST_TRUE(" << expression_1_stringified <<
"): failed\n";
299 inline void testFalse(
const char* ,
int line,
const bool expression_1,
const char* expression_1_stringified)
311 stdcout <<
" + line " << line <<
": TEST_FALSE(" << expression_1_stringified <<
"): ok\n";
316 stdcout <<
" - line " << line <<
": TEST_FALSE(" << expression_1_stringified <<
"): failed\n";
322 template <
typename T1,
typename T2>
325 const char* expression_1_stringified,
326 const T2& expression_2,
327 const char* expression_2_stringified)
331 this_test = !(expression_1 == T1(expression_2));
337 stdcout <<
' ' << (
this_test ?
'+' :
'-') <<
" line " << line <<
" : TEST_NOT_EQUAL(" << expression_1_stringified <<
','
338 << expression_2_stringified <<
"): got '";
339 if constexpr (std::is_enum_v<T1> && std::is_enum_v<T2>)
341 stdcout << static_cast<int>(expression_1) <<
"', forbidden is '" <<
static_cast<int>(expression_2) <<
"'\n";
346 stdcout <<
"', forbidden is '";
486#define START_TEST(class_name, version) \
487 int main(int argc, char** argv) \
489 TEST::mainInit(version, #class_name, argc, argv[0]); \
508 TEST::printLastException(stdcout); \
510 return TEST::endTestPostProcess(stdcout); \
534#define START_SECTION(name_of_test) \
536 TEST::newline = false; \
537 TEST::test_name = # name_of_test; \
538 TEST::test_count = 0; \
539 TEST::start_section_line = __LINE__; \
540 stdcout << "checking " << TEST::test_name << " ... " << std::flush; \
577 TEST::printLastException(stdcout);\
579 TEST::endSectionPostProcess(stdcout, __LINE__);
601#define TEST_EQUAL(a, b) TEST::testEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
612#define TEST_TRUE(a) TEST::testTrue(__FILE__, __LINE__, (a), (#a));
623#define TEST_FALSE(a) TEST::testFalse(__FILE__, __LINE__, (a), (#a));
637#define TEST_NOT_EQUAL(a, b) TEST::testNotEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
651#define TEST_STRING_EQUAL(a, b) TEST::testStringEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
667#define TEST_FILE_EQUAL(filename, templatename) \
669 TEST::filesEqual(__LINE__, filename, templatename, #filename, #templatename); \
687#define TEST_REAL_SIMILAR(a, b) TEST::testRealSimilar(__FILE__, __LINE__, (a), (# a), TEST::isRealType(a), TEST::writtenDigits(a), (b), (# b), TEST::isRealType(b), TEST::writtenDigits(b));
704#define TEST_STRING_SIMILAR(a, b) TEST::testStringSimilar(__FILE__, __LINE__, (a), (# a), (b), (# b));
720#define TEST_FILE_SIMILAR(a, b) \
722 ++TEST::test_count; \
723 TEST::test_line = __LINE__; \
724 TEST::this_test = TEST::isFileSimilar((a), (b)); \
725 TEST::test = TEST::test && TEST::this_test; \
727 TEST::initialNewline(); \
728 if (TEST::this_test) \
730 if (TEST::verbose > 1) \
732 stdcout << " + line " << __LINE__ \
733 << ": TEST_FILE_SIMILAR(" # a "," # b "): absolute: " \
734 << TEST::precisionWrapper(TEST::absdiff) \
736 << TEST::precisionWrapper(TEST::absdiff_max_allowed) \
738 << TEST::precisionWrapper(TEST::ratio) \
740 << TEST::precisionWrapper(TEST::ratio_max_allowed) \
742 stdcout << "message: \n"; \
743 stdcout << TEST::fuzzy_message; \
748 stdcout << " - line " << TEST::test_line << \
749 ": TEST_FILE_SIMILAR(" # a "," # b ") ... -\n"; \
750 stdcout << "message: \n"; \
751 stdcout << TEST::fuzzy_message; \
752 TEST::failed_lines_list.push_back(TEST::test_line); \
769#define TOLERANCE_RELATIVE(a) \
770 TEST::ratio_max_allowed = (a); \
772 TEST::initialNewline(); \
773 if (TEST::verbose > 1) \
775 stdcout << " + line " << __LINE__ << \
776 ": TOLERANCE_RELATIVE(" << TEST::ratio_max_allowed << \
777 ") (\"" # a "\")\n"; \
792#define TOLERANCE_ABSOLUTE(a) \
793 TEST::absdiff_max_allowed = (a); \
795 TEST::initialNewline(); \
796 if (TEST::verbose > 1) \
798 stdcout << " + line " << __LINE__ << \
799 ": TOLERANCE_ABSOLUTE(" << TEST::absdiff_max_allowed << \
800 ") (\"" # a "\")\n"; \
809#define WHITELIST(a) TEST::setWhitelist(__FILE__, __LINE__, (a));
823#define TEST_EXCEPTION(exception_type, command) \
825 ++TEST::test_count; \
826 TEST::test_line = __LINE__; \
827 TEST::exception = 0; \
832 catch (exception_type&) \
834 TEST::exception = 1; \
840 TEST::exception = 2; \
841 TEST::exception_name = TEST::describeCaughtException(); \
843 TEST::this_test = (TEST::exception == 1); \
844 TEST::test = TEST::test && TEST::this_test; \
846 TEST::initialNewline(); \
847 switch (TEST::exception) \
850 stdcout << " - line " << TEST::test_line << \
851 ": TEST_EXCEPTION(" # exception_type "," # command \
852 "): no exception thrown!\n"; \
853 TEST::failed_lines_list.push_back(TEST::test_line); \
856 if (TEST::verbose > 1) \
858 stdcout << " + line " << TEST::test_line << \
859 ": TEST_EXCEPTION(" # exception_type "," # command \
864 stdcout << " - line " << TEST::test_line << \
865 ": TEST_EXCEPTION(" # exception_type "," # command \
866 "): wrong exception thrown! \"" \
867 << TEST::exception_name << "\"\n"; \
868 TEST::failed_lines_list.push_back(TEST::test_line); \
887#define TEST_PRECONDITION_VIOLATED(command) \
889 if (TEST::preconditionTestsEnabled()) \
891 TEST_EXCEPTION(Exception::Precondition, command); \
895 STATUS("TEST_PRECONDITION_VIOLATED(" # command ") - skipped"); \
910#define TEST_POSTCONDITION_VIOLATED(command) \
912 if (TEST::preconditionTestsEnabled()) \
914 TEST_EXCEPTION(Exception::Postcondition, command); \
918 STATUS("TEST_POSTCONDITION_VIOLATED(" # command ") - skipped"); \
939#define TEST_EXCEPTION_WITH_MESSAGE(exception_type, command, message) \
941 ++TEST::test_count; \
942 TEST::test_line = __LINE__; \
943 TEST::exception = 0; \
948 catch (exception_type& et) \
950 if (std::string(et.what()) != std::string(message)) \
952 TEST::exception = 4; \
953 TEST::exception_message = et.what(); \
955 else TEST::exception = 1; \
959 TEST::exception = 2; \
960 TEST::exception_name = TEST::describeCaughtException(); \
962 TEST::this_test = (TEST::exception == 1); \
963 TEST::test = TEST::test && TEST::this_test; \
966 TEST::initialNewline(); \
967 switch (TEST::exception) \
970 stdcout << " - line " << TEST::test_line << \
971 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
972 "): no exception thrown!\n"; \
973 TEST::failed_lines_list.push_back(TEST::test_line); \
976 if (TEST::verbose > 1) \
979 stdcout << " + line " << TEST::test_line << \
980 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
985 stdcout << " - line " << TEST::test_line << \
986 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
987 "): wrong exception thrown! \"" << \
988 TEST::exception_name << "\"\n"; \
989 TEST::failed_lines_list.push_back(TEST::test_line); \
992 stdcout << " - line " << TEST::test_line << \
993 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
994 "): exception has wrong message: got '" << \
995 TEST::exception_message << \
997 (message) << "'\n"; \
998 TEST::failed_lines_list.push_back(TEST::test_line); \
1017#define NEW_TMP_FILE_EXT(filename, extension) filename = TEST::createTmpFileName(__FILE__, __LINE__, extension);
1020#define NEW_TMP_FILE(filename) filename = TEST::createTmpFileName(__FILE__, __LINE__);
1030#define ABORT_IF(condition) \
1034 TEST::test_line = __LINE__; \
1035 TEST::this_test = false; \
1036 TEST::test = TEST::test && TEST::this_test; \
1037 TEST::failed_lines_list.push_back(TEST::test_line); \
1038 TEST::initialNewline(); \
1039 stdcout << " - line " << TEST::test_line << \
1040 ": ABORT_IF(" # condition "): TEST ABORTED\n"; \
1062#define STATUS(message) \
1064 TEST::initialNewline(); \
1065 stdcout << " line " \
1081#define ADD_MESSAGE(message) \
1082 TEST::add_message = message;
1093#define NOT_TESTABLE \
1094 TEST::test_count = 1;
#define stdcout
Provide a point of redirection for testing the test macros, see ClassTest_test.cpp.
Definition ClassTest.h:30
std::string toString(const std::string &s)
Definition ClassTestUtils.h:222
void printValue(std::ostream &os, const T &v)
Definition ClassTestUtils.h:268
Namespace for class tests.
Definition ClassTest.h:39
double ratio_max
Maximum ratio of numbers observed so far, see TOLERANCE_RELATIVE.
int verbose
Verbosity level ( "-v" is 1 and "-V" is 2 )
void setPreconditionTestsEnabled(bool enabled)
See preconditionTestsEnabled().
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:223
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 testFalse(const char *, int line, const bool expression_1, const char *expression_1_stringified)
Definition ClassTest.h:299
bool isRealSimilar(long double number_1, long double number_2)
used by testRealSimilar()
bool(*)(std::string &description) ExceptionTranslator
Translator producing a description of the currently handled exception.
Definition ClassTest.h:373
int test_line
Line of current elementary test.
double absdiff
Recent absolute difference of numbers, see TOLERANCE_ABSOLUTE.
char line_buffer[65536]
(A buffer for one line from a file. Used by TEST_FILE_EQUAL.)
std::string add_message
See ADD_MESSAGE.
void endSectionPostProcess(std::ostream &out, const int line)
bool preconditionTestsEnabled()
std::string fuzzy_message
Last message from a fuzzy comparison. Written by isRealSimilar(), testStringSimilar(),...
void initialNewline()
make sure we have a newline before results from first subtest
bool all_tests
Status of the whole test.
std::string exception_message
(Used by various macros. Stores the "message" of the exception, if applicable.)
std::string test_name
Name of current subsection.
void registerExceptionTranslator(ExceptionTranslator translator)
Register an exception translator (idempotent; bounded, first-come first-served).
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 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:324
double absdiff_max
Maximum difference of numbers observed so far, see TOLERANCE_ABSOLUTE.
bool newline
(Flags whether a new line is in place, depending on context and verbosity setting....
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)
bool test
Status of the current subsection.
double absdiff_max_allowed
Maximum absolute difference of numbers allowed, see TOLERANCE_ABSOLUTE.
std::string describeCaughtException()
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
const char * version_string
Version string supplied with START_TEST.
std::ifstream infile
Questionable file tested by TEST_FILE_EQUAL.
int endTestPostProcess(std::ostream &out)
std::string exception_name
(Used by various macros. Stores the "name" of the exception, if applicable.)
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 ...
double ratio
Recent ratio of numbers, see TOLERANCE_RELATIVE.
void removeTempFiles()
removed all temporary files created with the NEW_TMP_FILE macro
std::vector< std::string > tmp_file_list
List of tmp file names (these will be cleaned up, see NEW_TMP_FILE)
bool isFileSimilar(const std::string &filename_1, const std::string &filename_2)
Compare files using absdiff_max_allowed and ratio_max_allowed.
bool this_test
Status of last elementary test.
void printLastException(std::ostream &out)
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::ifstream templatefile
Template (correct) file used by TEST_FILE_EQUAL.
void testTrue(const char *, int line, const bool expression_1, const char *expression_1_stringified)
Definition ClassTest.h:276
double ratio_max_allowed
Maximum ratio of numbers allowed, see TOLERANCE_RELATIVE.
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
bool equal_files
(A variable used by TEST_FILE_EQUAL)
std::vector< unsigned int > failed_lines_list
List of all failed lines for summary at the end of the test.
int start_section_line
Line where current subsection started.
int exception
(Used by various macros. Indicates a rough category of the exception being caught....
void setWhitelist(const char *const, const int line, const std::string &whitelist)
set the whitelist_
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19