32#define stdcout std::cout
58 const char* number_1_stringified,
59 bool number_1_is_realtype,
int number_1_written_digits,
60 long double number_2,
const char* number_2_stringified,
61 bool ,
int number_2_written_digits);
76 const std::string& string_1,
77 const char* string_1_stringified,
78 const std::string& string_2,
79 const char* string_2_stringified);
84 const std::string& string_1,
85 const char* string_1_stringified,
86 const std::string& string_2,
87 const char* string_2_stringified);
96 const std::string& filename_2);
115 void mainInit(
const char* version,
const char* class_name,
int argc,
const char* argv0);
126 void filesEqual(
int line,
const char* filename,
const char* templatename,
const char* filename_stringified,
const char* templatename_stringified);
134 const std::string& whitelist);
197 extern std::ifstream
infile;
223 template <
typename T1,
typename T2>
225 testEqual(
const char* ,
int line,
const T1& expression_1,
226 const char* expression_1_stringified,
227 const T2& expression_2,
228 const char* expression_2_stringified)
237 if constexpr (std::is_same_v<T1, std::string>)
243 this_test = bool(expression_1 == T1(expression_2));
250 stdcout <<
' ' << (
this_test ?
'+' :
'-') <<
" line " << line <<
" : TEST_EQUAL(" << expression_1_stringified <<
','
251 << expression_2_stringified <<
"): got '";
254 if constexpr (std::is_same_v<std::remove_cv_t<T1>,
XMLCh*> || std::is_same_v<std::remove_cv_t<T2>,
XMLCh*>)
256 stdcout << (expression_1 ==
nullptr ?
"(null)" :
"(XMLCh*)") <<
"', expected '"
257 << (expression_2 ==
nullptr ?
"(null)" :
"(XMLCh*)") <<
"'\n";
259 else if constexpr (std::is_enum_v<T1> && std::is_enum_v<T2>)
261 stdcout << static_cast<int>(expression_1) <<
"', expected '" <<
static_cast<int>(expression_2) <<
"'\n";
278 inline void testTrue(
const char* ,
int line,
const bool expression_1,
const char* expression_1_stringified)
290 stdcout <<
" + line " << line <<
": TEST_TRUE(" << expression_1_stringified <<
"): ok\n";
295 stdcout <<
" - line " << line <<
": TEST_TRUE(" << expression_1_stringified <<
"): failed\n";
301 inline void testFalse(
const char* ,
int line,
const bool expression_1,
const char* expression_1_stringified)
313 stdcout <<
" + line " << line <<
": TEST_FALSE(" << expression_1_stringified <<
"): ok\n";
318 stdcout <<
" - line " << line <<
": TEST_FALSE(" << expression_1_stringified <<
"): failed\n";
324 template <
typename T1,
typename T2>
327 const char* expression_1_stringified,
328 const T2& expression_2,
329 const char* expression_2_stringified)
333 this_test = !(expression_1 == T1(expression_2));
339 stdcout <<
' ' << (
this_test ?
'+' :
'-') <<
" line " << line <<
" : TEST_NOT_EQUAL(" << expression_1_stringified <<
','
340 << expression_2_stringified <<
"): got '";
341 if constexpr (std::is_enum_v<T1> && std::is_enum_v<T2>)
343 stdcout << static_cast<int>(expression_1) <<
"', forbidden is '" <<
static_cast<int>(expression_2) <<
"'\n";
348 stdcout <<
"', forbidden is '";
488#define START_TEST(class_name, version) \
489 int main(int argc, char** argv) \
491 TEST::mainInit(version, #class_name, argc, argv[0]); \
510 TEST::printLastException(stdcout); \
512 return TEST::endTestPostProcess(stdcout); \
536#define START_SECTION(name_of_test) \
538 TEST::newline = false; \
539 TEST::test_name = # name_of_test; \
540 TEST::test_count = 0; \
541 TEST::start_section_line = __LINE__; \
542 stdcout << "checking " << TEST::test_name << " ... " << std::flush; \
579 TEST::printLastException(stdcout);\
581 TEST::endSectionPostProcess(stdcout, __LINE__);
603#define TEST_EQUAL(a, b) TEST::testEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
614#define TEST_TRUE(a) TEST::testTrue(__FILE__, __LINE__, (a), (#a));
625#define TEST_FALSE(a) TEST::testFalse(__FILE__, __LINE__, (a), (#a));
639#define TEST_NOT_EQUAL(a, b) TEST::testNotEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
653#define TEST_STRING_EQUAL(a, b) TEST::testStringEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
669#define TEST_FILE_EQUAL(filename, templatename) \
671 TEST::filesEqual(__LINE__, filename, templatename, #filename, #templatename); \
689#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));
706#define TEST_STRING_SIMILAR(a, b) TEST::testStringSimilar(__FILE__, __LINE__, (a), (# a), (b), (# b));
722#define TEST_FILE_SIMILAR(a, b) \
724 ++TEST::test_count; \
725 TEST::test_line = __LINE__; \
726 TEST::this_test = TEST::isFileSimilar((a), (b)); \
727 TEST::test = TEST::test && TEST::this_test; \
729 TEST::initialNewline(); \
730 if (TEST::this_test) \
732 if (TEST::verbose > 1) \
734 stdcout << " + line " << __LINE__ \
735 << ": TEST_FILE_SIMILAR(" # a "," # b "): absolute: " \
736 << TEST::precisionWrapper(TEST::absdiff) \
738 << TEST::precisionWrapper(TEST::absdiff_max_allowed) \
740 << TEST::precisionWrapper(TEST::ratio) \
742 << TEST::precisionWrapper(TEST::ratio_max_allowed) \
744 stdcout << "message: \n"; \
745 stdcout << TEST::fuzzy_message; \
750 stdcout << " - line " << TEST::test_line << \
751 ": TEST_FILE_SIMILAR(" # a "," # b ") ... -\n"; \
752 stdcout << "message: \n"; \
753 stdcout << TEST::fuzzy_message; \
754 TEST::failed_lines_list.push_back(TEST::test_line); \
771#define TOLERANCE_RELATIVE(a) \
772 TEST::ratio_max_allowed = (a); \
774 TEST::initialNewline(); \
775 if (TEST::verbose > 1) \
777 stdcout << " + line " << __LINE__ << \
778 ": TOLERANCE_RELATIVE(" << TEST::ratio_max_allowed << \
779 ") (\"" # a "\")\n"; \
794#define TOLERANCE_ABSOLUTE(a) \
795 TEST::absdiff_max_allowed = (a); \
797 TEST::initialNewline(); \
798 if (TEST::verbose > 1) \
800 stdcout << " + line " << __LINE__ << \
801 ": TOLERANCE_ABSOLUTE(" << TEST::absdiff_max_allowed << \
802 ") (\"" # a "\")\n"; \
811#define WHITELIST(a) TEST::setWhitelist(__FILE__, __LINE__, (a));
825#define TEST_EXCEPTION(exception_type, command) \
827 ++TEST::test_count; \
828 TEST::test_line = __LINE__; \
829 TEST::exception = 0; \
834 catch (exception_type&) \
836 TEST::exception = 1; \
842 TEST::exception = 2; \
843 TEST::exception_name = TEST::describeCaughtException(); \
845 TEST::this_test = (TEST::exception == 1); \
846 TEST::test = TEST::test && TEST::this_test; \
848 TEST::initialNewline(); \
849 switch (TEST::exception) \
852 stdcout << " - line " << TEST::test_line << \
853 ": TEST_EXCEPTION(" # exception_type "," # command \
854 "): no exception thrown!\n"; \
855 TEST::failed_lines_list.push_back(TEST::test_line); \
858 if (TEST::verbose > 1) \
860 stdcout << " + line " << TEST::test_line << \
861 ": TEST_EXCEPTION(" # exception_type "," # command \
866 stdcout << " - line " << TEST::test_line << \
867 ": TEST_EXCEPTION(" # exception_type "," # command \
868 "): wrong exception thrown! \"" \
869 << TEST::exception_name << "\"\n"; \
870 TEST::failed_lines_list.push_back(TEST::test_line); \
889#define TEST_PRECONDITION_VIOLATED(command) \
891 if (TEST::preconditionTestsEnabled()) \
893 TEST_EXCEPTION(Exception::Precondition, command); \
897 STATUS("TEST_PRECONDITION_VIOLATED(" # command ") - skipped"); \
912#define TEST_POSTCONDITION_VIOLATED(command) \
914 if (TEST::preconditionTestsEnabled()) \
916 TEST_EXCEPTION(Exception::Postcondition, command); \
920 STATUS("TEST_POSTCONDITION_VIOLATED(" # command ") - skipped"); \
941#define TEST_EXCEPTION_WITH_MESSAGE(exception_type, command, message) \
943 ++TEST::test_count; \
944 TEST::test_line = __LINE__; \
945 TEST::exception = 0; \
950 catch (exception_type& et) \
952 if (std::string(et.what()) != std::string(message)) \
954 TEST::exception = 4; \
955 TEST::exception_message = et.what(); \
957 else TEST::exception = 1; \
961 TEST::exception = 2; \
962 TEST::exception_name = TEST::describeCaughtException(); \
964 TEST::this_test = (TEST::exception == 1); \
965 TEST::test = TEST::test && TEST::this_test; \
968 TEST::initialNewline(); \
969 switch (TEST::exception) \
972 stdcout << " - line " << TEST::test_line << \
973 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
974 "): no exception thrown!\n"; \
975 TEST::failed_lines_list.push_back(TEST::test_line); \
978 if (TEST::verbose > 1) \
981 stdcout << " + line " << TEST::test_line << \
982 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
987 stdcout << " - line " << TEST::test_line << \
988 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
989 "): wrong exception thrown! \"" << \
990 TEST::exception_name << "\"\n"; \
991 TEST::failed_lines_list.push_back(TEST::test_line); \
994 stdcout << " - line " << TEST::test_line << \
995 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
996 "): exception has wrong message: got '" << \
997 TEST::exception_message << \
999 (message) << "'\n"; \
1000 TEST::failed_lines_list.push_back(TEST::test_line); \
1019#define NEW_TMP_FILE_EXT(filename, extension) filename = TEST::createTmpFileName(__FILE__, __LINE__, extension);
1022#define NEW_TMP_FILE(filename) filename = TEST::createTmpFileName(__FILE__, __LINE__);
1032#define ABORT_IF(condition) \
1036 TEST::test_line = __LINE__; \
1037 TEST::this_test = false; \
1038 TEST::test = TEST::test && TEST::this_test; \
1039 TEST::failed_lines_list.push_back(TEST::test_line); \
1040 TEST::initialNewline(); \
1041 stdcout << " - line " << TEST::test_line << \
1042 ": ABORT_IF(" # condition "): TEST ABORTED\n"; \
1064#define STATUS(message) \
1066 TEST::initialNewline(); \
1067 stdcout << " line " \
1083#define ADD_MESSAGE(message) \
1084 TEST::add_message = message;
1095#define NOT_TESTABLE \
1096 TEST::test_count = 1;
char16_t XMLCh
Definition ClassTest.h:25
#define stdcout
Provide a point of redirection for testing the test macros, see ClassTest_test.cpp.
Definition ClassTest.h:32
std::string toString(const std::string &s)
Definition ClassTestUtils.h:222
void printValue(std::ostream &os, const T &v)
Definition ClassTestUtils.h:259
Namespace for class tests.
Definition ClassTest.h:41
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:225
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:301
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:375
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:326
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:278
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