20#include <OpenMS/OpenMSConfig.h>
21#include <OpenMS/config.h>
37#define stdcout std::cout
53 validate(
const std::vector<std::string>& file_names);
56 std::string OPENMS_DLLAPI
60 inline bool OPENMS_DLLAPI
67 inline bool OPENMS_DLLAPI
74 inline bool OPENMS_DLLAPI
81 inline bool OPENMS_DLLAPI
88 inline bool OPENMS_DLLAPI
109 const char* number_1_stringified,
110 bool number_1_is_realtype,
Int number_1_written_digits,
111 long double number_2,
const char* number_2_stringified,
112 bool ,
Int number_2_written_digits);
127 const std::string& string_1,
128 const char* string_1_stringified,
129 const std::string& string_2,
130 const char* string_2_stringified);
135 const std::string& string_1,
136 const char* string_1_stringified,
137 const std::string& string_2,
138 const char* string_2_stringified);
147 const std::string& filename_2);
166 void OPENMS_DLLAPI
mainInit(
const char* version,
const char* class_name,
int argc,
const char* argv0);
177 void OPENMS_DLLAPI
filesEqual(
int line,
const char* filename,
const char* templatename,
const char* filename_stringified,
const char* templatename_stringified);
185 const std::string& whitelist);
194 extern OPENMS_DLLAPI
double ratio;
203 extern OPENMS_DLLAPI
double absdiff;
209 extern OPENMS_DLLAPI
int verbose;
215 extern OPENMS_DLLAPI
bool test;
230 extern OPENMS_DLLAPI std::string
test_name;
248 extern OPENMS_DLLAPI std::ifstream
infile;
272 extern OPENMS_DLLAPI
bool newline;
274 template <
typename T1,
typename T2>
276 testEqual(
const char* ,
int line,
const T1& expression_1,
277 const char* expression_1_stringified,
278 const T2& expression_2,
279 const char* expression_2_stringified)
287 if constexpr (std::is_same_v<T1, std::string>)
293 this_test = bool(expression_1 == T1(expression_2));
300 stdcout <<
' ' << (
this_test ?
'+' :
'-') <<
" line " << line <<
" : TEST_EQUAL(" << expression_1_stringified <<
','
301 << expression_2_stringified <<
"): got '";
304 if constexpr (std::is_same_v<std::remove_cv_t<T1>,
XMLCh*> || std::is_same_v<std::remove_cv_t<T2>,
XMLCh*>)
306 stdcout << (expression_1 ==
nullptr ?
"(null)" :
"(XMLCh*)") <<
"', expected '"
307 << (expression_2 ==
nullptr ?
"(null)" :
"(XMLCh*)") <<
"'\n";
309 else if constexpr (std::is_enum_v<T1> && std::is_enum_v<T2>)
311 stdcout << static_cast<int>(expression_1) <<
"', expected '" <<
static_cast<int>(expression_2) <<
"'\n";
315 stdcout << expression_1 <<
"', expected '" << expression_2 <<
"'\n";
325 void testTrue(
const char* ,
int line,
const bool expression_1,
const char* expression_1_stringified)
337 stdcout <<
" + line " << line <<
": TEST_TRUE(" << expression_1_stringified <<
"): ok\n";
342 stdcout <<
" - line " << line <<
": TEST_TRUE(" << expression_1_stringified <<
"): failed\n";
348 void testFalse(
const char* ,
int line,
const bool expression_1,
const char* expression_1_stringified)
360 stdcout <<
" + line " << line <<
": TEST_FALSE(" << expression_1_stringified <<
"): ok\n";
365 stdcout <<
" - line " << line <<
": TEST_FALSE(" << expression_1_stringified <<
"): failed\n";
371 template <
typename T1,
typename T2>
374 const char* expression_1_stringified,
375 const T2& expression_2,
376 const char* expression_2_stringified)
380 this_test = !(expression_1 == T1(expression_2));
386 stdcout <<
' ' << (
this_test ?
'+' :
'-') <<
" line " << line <<
" : TEST_NOT_EQUAL(" << expression_1_stringified <<
','
387 << expression_2_stringified <<
"): got '";
388 if constexpr (std::is_enum_v<T1> && std::is_enum_v<T2>)
390 stdcout << static_cast<int>(expression_1) <<
"', forbidden is '" <<
static_cast<int>(expression_2) <<
"'\n";
392 else {
stdcout << expression_1 <<
"', expected '" << expression_2 <<
"'\n"; }
466#define START_TEST(class_name, version) \
467 int main(int argc, char** argv) \
469 TEST::mainInit(version, #class_name, argc, argv[0]); \
488 TEST::printLastException(stdcout); \
490 return TEST::endTestPostProcess(stdcout); \
515#define START_SECTION(name_of_test) \
517 TEST::newline = false; \
518 TEST::test_name = # name_of_test; \
519 TEST::test_count = 0; \
520 TEST::start_section_line = __LINE__; \
521 stdcout << "checking " << TEST::test_name << " ... " << std::flush; \
558 TEST::printLastException(stdcout);\
560 TEST::endSectionPostProcess(stdcout, __LINE__);
584#define TEST_EQUAL(a, b) TEST::testEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
595#define TEST_TRUE(a) TEST::testTrue(__FILE__, __LINE__, (a), (#a));
606#define TEST_FALSE(a) TEST::testFalse(__FILE__, __LINE__, (a), (#a));
620#define TEST_NOT_EQUAL(a, b) TEST::testNotEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
634#define TEST_STRING_EQUAL(a, b) TEST::testStringEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
650#define TEST_FILE_EQUAL(filename, templatename) \
652 TEST::filesEqual(__LINE__, filename, templatename, #filename, #templatename); \
670#define TEST_REAL_SIMILAR(a, b) TEST::testRealSimilar(__FILE__, __LINE__, (a), (# a), TEST::isRealType(a), writtenDigits(a), (b), (# b), TEST::isRealType(b), writtenDigits(b));
687#define TEST_STRING_SIMILAR(a, b) TEST::testStringSimilar(__FILE__, __LINE__, (a), (# a), (b), (# b));
703#define TEST_FILE_SIMILAR(a, b) \
705 ++TEST::test_count; \
706 TEST::test_line = __LINE__; \
707 TEST::this_test = TEST::isFileSimilar((a), (b)); \
708 TEST::test = TEST::test && TEST::this_test; \
710 TEST::initialNewline(); \
711 if (TEST::this_test) \
713 if (TEST::verbose > 1) \
715 stdcout << " + line " << __LINE__ \
716 << ": TEST_FILE_SIMILAR(" # a "," # b "): absolute: " \
717 << precisionWrapper(TEST::absdiff) \
719 << precisionWrapper(TEST::absdiff_max_allowed) \
721 << precisionWrapper(TEST::ratio) \
723 << precisionWrapper(TEST::ratio_max_allowed) \
725 stdcout << "message: \n"; \
726 stdcout << TEST::fuzzy_message; \
731 stdcout << " - line " << TEST::test_line << \
732 ": TEST_FILE_SIMILAR(" # a "," # b ") ... -\n"; \
733 stdcout << "message: \n"; \
734 stdcout << TEST::fuzzy_message; \
735 TEST::failed_lines_list.push_back(TEST::test_line); \
752#define TOLERANCE_RELATIVE(a) \
753 TEST::ratio_max_allowed = (a); \
755 TEST::initialNewline(); \
756 if (TEST::verbose > 1) \
758 stdcout << " + line " << __LINE__ << \
759 ": TOLERANCE_RELATIVE(" << TEST::ratio_max_allowed << \
760 ") (\"" # a "\")\n"; \
775#define TOLERANCE_ABSOLUTE(a) \
776 TEST::absdiff_max_allowed = (a); \
778 TEST::initialNewline(); \
779 if (TEST::verbose > 1) \
781 stdcout << " + line " << __LINE__ << \
782 ": TOLERANCE_ABSOLUTE(" << TEST::absdiff_max_allowed << \
783 ") (\"" # a "\")\n"; \
792#define WHITELIST(a) TEST::setWhitelist(__FILE__, __LINE__, (a));
806#define TEST_EXCEPTION(exception_type, command) \
808 ++TEST::test_count; \
809 TEST::test_line = __LINE__; \
810 TEST::exception = 0; \
815 catch (exception_type&) \
817 TEST::exception = 1; \
819 catch (::OpenMS::Exception::BaseException& e) \
821 TEST::exception = 2; \
822 TEST::exception_name = e.getName(); \
824 catch (const std::exception& e) \
826 TEST::exception = 3; \
827 TEST::exception_name = e.what(); \
831 TEST::exception = 4; \
833 TEST::this_test = (TEST::exception == 1); \
834 TEST::test = TEST::test && TEST::this_test; \
836 TEST::initialNewline(); \
837 switch (TEST::exception) \
840 stdcout << " - line " << TEST::test_line << \
841 ": TEST_EXCEPTION(" # exception_type "," # command \
842 "): no exception thrown!\n"; \
843 TEST::failed_lines_list.push_back(TEST::test_line); \
846 if (TEST::verbose > 1) \
848 stdcout << " + line " << TEST::test_line << \
849 ": TEST_EXCEPTION(" # exception_type "," # command \
854 stdcout << " - line " << TEST::test_line << \
855 ": TEST_EXCEPTION(" # exception_type "," # command \
856 "): wrong exception thrown! \"" \
857 << TEST::exception_name << "\"\n"; \
858 TEST::failed_lines_list.push_back(TEST::test_line); \
861 stdcout << " - line " << TEST::test_line << \
862 ": TEST_EXCEPTION(" # exception_type "," # command \
863 "): wrong exception thrown! \"" \
864 << TEST::exception_name << "\"\n"; \
865 TEST::failed_lines_list.push_back(TEST::test_line); \
868 stdcout << " - line " << TEST::test_line << \
869 ": TEST_EXCEPTION(" # exception_type "," # command \
870 "): wrong exception thrown!\n"; \
871 TEST::failed_lines_list.push_back(TEST::test_line); \
888#ifdef OPENMS_ASSERTIONS
889#define TEST_PRECONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Precondition, command);
891#define TEST_PRECONDITION_VIOLATED(command) STATUS("TEST_PRECONDITION_VIOLATED(" # command ") - skipped");
905#ifdef OPENMS_ASSERTIONS
906#define TEST_POSTCONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Postcondition, command);
908#define TEST_POSTCONDITION_VIOLATED(command) STATUS("TEST_POSTCONDITION_VIOLATED(" # command ") - skipped");
928#define TEST_EXCEPTION_WITH_MESSAGE(exception_type, command, message) \
930 ++TEST::test_count; \
931 TEST::test_line = __LINE__; \
932 TEST::exception = 0; \
937 catch (exception_type& et) \
939 if (std::string(et.what()) != std::string(message)) \
941 TEST::exception = 4; \
942 TEST::exception_message = et.what(); \
944 else TEST::exception = 1; \
946 catch (::OpenMS::Exception::BaseException& e) \
948 TEST::exception = 2; \
949 TEST::exception_name = e.getName(); \
953 TEST::exception = 3; \
955 TEST::this_test = (TEST::exception == 1); \
956 TEST::test = TEST::test && TEST::this_test; \
959 TEST::initialNewline(); \
960 switch (TEST::exception) \
963 stdcout << " - line " << TEST::test_line << \
964 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
965 "): no exception thrown!\n"; \
966 TEST::failed_lines_list.push_back(TEST::test_line); \
969 if (TEST::verbose > 1) \
972 stdcout << " + line " << TEST::test_line << \
973 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
978 stdcout << " - line " << TEST::test_line << \
979 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
980 "): wrong exception thrown! \"" << \
981 TEST::exception_name << "\"\n"; \
982 TEST::failed_lines_list.push_back(TEST::test_line); \
985 stdcout << " - line " << TEST::test_line << \
986 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
987 "): wrong exception thrown!\n"; \
988 TEST::failed_lines_list.push_back(TEST::test_line); \
991 stdcout << " - line " << TEST::test_line << \
992 ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
993 "): exception has wrong message: got '" << \
994 TEST::exception_message << \
996 (message) << "'\n"; \
997 TEST::failed_lines_list.push_back(TEST::test_line); \
1016#define NEW_TMP_FILE_EXT(filename, extension) filename = TEST::createTmpFileName(__FILE__, __LINE__, extension);
1019#define NEW_TMP_FILE(filename) filename = TEST::createTmpFileName(__FILE__, __LINE__);
1029#define ABORT_IF(condition) \
1033 TEST::test_line = __LINE__; \
1034 TEST::this_test = false; \
1035 TEST::test = TEST::test && TEST::this_test; \
1036 TEST::failed_lines_list.push_back(TEST::test_line); \
1037 TEST::initialNewline(); \
1038 stdcout << " - line " << TEST::test_line << \
1039 ": ABORT_IF(" # condition "): TEST ABORTED\n"; \
1061#define STATUS(message) \
1063 TEST::initialNewline(); \
1064 stdcout << " line " \
1080#define ADD_MESSAGE(message) \
1081 TEST::add_message = message;
1092#define NOT_TESTABLE \
1093 TEST::test_count = 1;
char16_t XMLCh
Definition ClassTest.h:30
#define stdcout
Provide a point of redirection for testing the test macros, see ClassTest_test.cpp.
Definition ClassTest.h:37
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition DataValue.h:32
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition ParamValue.h:31
int Int
Signed integer type.
Definition Types.h:72
Namespace for class tests.
Definition ClassTest.h:46
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 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:276
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:348
bool isRealSimilar(long double number_1, long double number_2)
used by testRealSimilar()
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 validate(const std::vector< std::string > &file_names)
Validates the given files against the XML schema (if available)
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.
std::string fuzzy_message
Last message from a fuzzy comparison. Written by isRealSimilar(), testStringSimilar(),...
bool isRealType(float)
This overload returns true; float is a floating point type.
Definition ClassTest.h:61
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 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:373
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.
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.)
std::vector< UInt > failed_lines_list
List of all failed lines for summary at the end of the test.
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:325
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)
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_
std::string toStr(int i)
Definition StringUtils.h:257
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19