OpenMS  2.8.0
ClassTest.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Marc Sturm, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // Avoid OpenMS includes here at all costs
38 // When the included headers are changed, *all* tests have to be recompiled!
39 // Use the ClassTest class if you need add high-level functionality.
40 // Includes in the C-file are ok...
42 #include <OpenMS/CONCEPT/Types.h>
45 #include <OpenMS/OpenMSConfig.h>
46 #include <OpenMS/config.h>
47 
48 #include <cstring>
49 #include <iostream>
50 #include <string>
51 #include <vector>
52 
53 // Empty declaration to avoid problems in case the namespace is not
54 // yet defined (e.g. TEST/ClassTest_test.cpp)
55 
57 #ifndef stdcout
58 #define stdcout std::cout
59 #endif
60 
61 namespace OpenMS
62 {
63  namespace Internal
64  {
66  namespace ClassTest
67  {
68 
73  bool OPENMS_DLLAPI
74  validate(const std::vector<std::string>& file_names);
75 
77  std::string OPENMS_DLLAPI
78  tmpFileName(const std::string& file, int line);
79 
81  inline bool OPENMS_DLLAPI
82  isRealType(float)
83  {
84  return true;
85  }
86 
88  inline bool OPENMS_DLLAPI
89  isRealType(double)
90  {
91  return true;
92  }
93 
95  inline bool OPENMS_DLLAPI
96  isRealType(long double)
97  {
98  return true;
99  }
100 
102  inline bool OPENMS_DLLAPI
104  {
105  return true;
106  }
107 
109  inline bool OPENMS_DLLAPI
111  {
112  return true;
113  }
114 
116  template <typename T>
117  inline bool
118  isRealType(const T&)
119  {
120  return false;
121  }
122 
128  void OPENMS_DLLAPI
129  testRealSimilar(const char* file, int line, long double number_1,
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 /* number_2_is_realtype */, Int number_2_written_digits);
134 
136  bool OPENMS_DLLAPI
137  isRealSimilar(long double number_1, long double number_2);
138 
146  void OPENMS_DLLAPI
147  testStringSimilar(const char* file, int line,
148  const std::string& string_1,
149  const char* string_1_stringified,
150  const std::string& string_2,
151  const char* string_2_stringified);
152 
154  void OPENMS_DLLAPI
155  testStringEqual(const char* file, int line,
156  const std::string& string_1,
157  const char* string_1_stringified,
158  const std::string& string_2,
159  const char* string_2_stringified);
160 
166  bool OPENMS_DLLAPI
167  isFileSimilar(const std::string& filename_1,
168  const std::string& filename_2);
169 
171  void OPENMS_DLLAPI
173 
175  void OPENMS_DLLAPI
176  printWithPrefix(const std::string& text, const int marked = -1);
177 
187  void OPENMS_DLLAPI mainInit(const char* version, const char* class_name, int argc, const char* argv0);
188 
198  void OPENMS_DLLAPI filesEqual(int line, const char* filename, const char* templatename, const char* filename_stringified, const char* templatename_stringified);
199 
201  void OPENMS_DLLAPI removeTempFiles();
202 
204  void OPENMS_DLLAPI
205  setWhitelist(const char* const /* file */, const int line,
206  const std::string& whitelist);
207 
209  extern OPENMS_DLLAPI double ratio_max_allowed;
210 
212  extern OPENMS_DLLAPI double ratio_max;
213 
215  extern OPENMS_DLLAPI double ratio;
216 
218  extern OPENMS_DLLAPI double absdiff_max_allowed;
219 
221  extern OPENMS_DLLAPI double absdiff_max;
222 
224  extern OPENMS_DLLAPI double absdiff;
225 
226  extern OPENMS_DLLAPI int line_num_1_max;
227  extern OPENMS_DLLAPI int line_num_2_max;
228 
230  extern OPENMS_DLLAPI int verbose;
231 
233  extern OPENMS_DLLAPI bool all_tests;
234 
236  extern OPENMS_DLLAPI bool test;
237 
239  extern OPENMS_DLLAPI bool this_test;
240 
242  extern OPENMS_DLLAPI int exception;
243 
245  extern OPENMS_DLLAPI std::string exception_name;
246 
248  extern OPENMS_DLLAPI std::string exception_message;
249 
251  extern OPENMS_DLLAPI std::string test_name;
252 
254  extern OPENMS_DLLAPI int start_section_line;
255 
257  extern OPENMS_DLLAPI int test_line;
258 
260  extern OPENMS_DLLAPI const char* version_string;
261 
263  extern OPENMS_DLLAPI std::vector<std::string> tmp_file_list;
264 
266  extern OPENMS_DLLAPI std::vector<UInt> failed_lines_list;
267 
269  extern OPENMS_DLLAPI std::ifstream infile;
270 
272  extern OPENMS_DLLAPI std::ifstream templatefile;
273 
275  extern OPENMS_DLLAPI bool equal_files;
276 
278  extern OPENMS_DLLAPI char line_buffer[65536];
279 
281  extern OPENMS_DLLAPI int test_count;
282 
284  extern OPENMS_DLLAPI std::string add_message;
285 
290  extern OPENMS_DLLAPI std::string fuzzy_message;
291 
293  extern OPENMS_DLLAPI bool newline;
294 
295  template <typename T1, typename T2>
296  void
297  testEqual(const char* /*file*/, int line, const T1& expression_1,
298  const char* expression_1_stringified,
299  const T2& expression_2,
300  const char* expression_2_stringified)
301  {
302  ++test_count;
303  test_line = line;
304  this_test = bool(expression_1 == T1(expression_2));
305  test = test && this_test;
306  {
307  initialNewline();
308  if (this_test)
309  {
310  if (verbose > 1)
311  {
312  stdcout << " + line " << line << ": TEST_EQUAL("
313  << expression_1_stringified << ','
314  << expression_2_stringified << "): got '" << expression_1
315  << "', expected '" << expression_2 << "'\n";
316  }
317  }
318  else
319  {
320  stdcout << " - line " << line << ": TEST_EQUAL("
321  << expression_1_stringified << ','
322  << expression_2_stringified << "): got '" << expression_1
323  << "', expected '" << expression_2 << "'\n";
324  failed_lines_list.push_back(line);
325  }
326  }
327  }
328 
329  template <typename T1, typename T2>
330  void
331  testNotEqual(const char* /*file*/, int line, const T1& expression_1,
332  const char* expression_1_stringified,
333  const T2& expression_2,
334  const char* expression_2_stringified)
335  {
336  ++test_count;
337  test_line = line;
338  this_test = !(expression_1 == T1(expression_2));
339  test = test && this_test;
340  {
341  initialNewline();
342  if (this_test)
343  {
344  if (verbose > 1)
345  {
346  stdcout << " + line " << line << ": TEST_NOT_EQUAL("
347  << expression_1_stringified << ','
348  << expression_2_stringified << "): got '" << expression_1
349  << "', forbidden is '" << expression_2 << "'\n";
350  }
351  }
352  else
353  {
354  stdcout << " - line " << line << ": TEST_NOT_EQUAL("
355  << expression_1_stringified << ','
356  << expression_2_stringified << "): got '" << expression_1
357  << "', forbidden is '" << expression_2 << "'\n";
358  failed_lines_list.push_back(line);
359  }
360  }
361  }
362 
363  }
364  }
365 }
366 
367 // A namespace alias - apparently these cannot be documented using doxygen (?)
369 
394 
395 //@name test and subtest
397 
422 #define START_TEST(class_name, version) \
423  int main(int argc, char** argv) \
424  { \
425  TEST::mainInit(version, #class_name, argc, argv[0]); \
426  try {
427 
439 #define END_TEST \
440  /* global try block */ \
441  } \
442  catch (::OpenMS::Exception::BaseException& e) \
443  { \
444  TEST::this_test = false; \
445  TEST::test = false; \
446  TEST::all_tests = false; \
447  { \
448  TEST::initialNewline(); \
449  stdcout << "Error: Caught unexpected OpenMS exception of type '" \
450  << e.getName() \
451  << "'"; \
452  if ((e.getLine() > 0) && std::strcmp(e.getFile(), "")) \
453  { \
454  stdcout << " thrown in line " << e.getLine() << " of file '" << e.getFile() \
455  << "' in function '" << e.getFunction() << "'"; \
456  } \
457  stdcout << " - Message: " << e.what() << std::endl; \
458  } \
459  } \
460  /* catch std:: exceptions */ \
461  catch (std::exception& e) \
462  { \
463  TEST::this_test = false; \
464  TEST::test = false; \
465  TEST::all_tests = false; \
466  { \
467  TEST::initialNewline(); \
468  stdcout << "Error: Caught unexpected std::exception\n"; \
469  stdcout << " - Message: " << e.what() << std::endl; \
470  } \
471  } \
472  /* catch all other exceptions */ \
473  catch (...) \
474  { \
475  TEST::this_test = false; \
476  TEST::test = false; \
477  TEST::all_tests = false; \
478  { \
479  TEST::initialNewline(); \
480  stdcout << "Error: Caught unidentified and unexpected exception - No message." \
481  << std::endl; \
482  } \
483  } \
484  /* check validity of temporary files if known */ \
485  if (!TEST::validate(TEST::tmp_file_list)) \
486  { \
487  TEST::all_tests = false; \
488  } \
489  if (TEST::verbose == 0) \
490  { \
491  stdcout << "Output of successful tests were suppressed. Set the environment variable 'OPENMS_TEST_VERBOSE=True' to enable them." << std::endl; \
492  } \
493  /* check for exit code */ \
494  if (!TEST::all_tests) \
495  { \
496  stdcout << "FAILED" << std::endl; \
497  if (TEST::add_message != "") stdcout << "Message: " \
498  << TEST::add_message \
499  << std::endl; \
500  stdcout << "Failed lines: "; \
501  for (OpenMS::Size i = 0; i < TEST::failed_lines_list.size(); ++i) \
502  { \
503  stdcout << TEST::failed_lines_list[i] << " "; \
504  } \
505  stdcout << std::endl; \
506  return 1; \
507  } \
508  else \
509  { \
510  /* remove temporary files*/ \
511  TEST::removeTempFiles(); \
512  stdcout << "PASSED"; \
513  if (TEST::add_message != "") stdcout << " (" << TEST::add_message << ")"; \
514  stdcout << std::endl; \
515  return 0; \
516  } \
517  }
518 
541 #define START_SECTION(name_of_test) \
542  TEST::test = true; \
543  TEST::newline = false; \
544  TEST::test_name = # name_of_test; \
545  TEST::test_count = 0; \
546  TEST::start_section_line = __LINE__; \
547  stdcout << "checking " << TEST::test_name << " ... " << std::flush; \
548  try \
549  { \
550  while (true) \
551  {
552 
578 #define END_SECTION \
579  break; \
580  } \
581  } \
582  catch (::OpenMS::Exception::BaseException& e) \
583  { \
584  TEST::this_test = false; \
585  TEST::test = false; \
586  TEST::all_tests = false; \
587  { \
588  TEST::initialNewline(); \
589  stdcout << "Error: Caught unexpected exception of type '" << e.getName() << "'"; \
590  if ((e.getLine() > 0) && (std::strcmp(e.getFile(), "") != 0)) \
591  { \
592  stdcout << " thrown in line " << e.getLine() << " of file '" << e.getFile() \
593  << "' in function '" << e.getFunction() << "'"; \
594  } \
595  stdcout << " - Message: " << e.what() << std::endl; \
596  } \
597  } \
598  /* catch std:: exceptions */ \
599  catch (std::exception& e) \
600  { \
601  TEST::this_test = false; \
602  TEST::test = false; \
603  TEST::all_tests = false; \
604  { \
605  TEST::initialNewline(); \
606  stdcout << "Error: Caught std::exception" << std::endl; \
607  stdcout << " - Message: " << e.what() << std::endl; \
608  } \
609  } \
610  /* catch all other exceptions */ \
611  catch (...) \
612  { \
613  TEST::this_test = false; \
614  TEST::test = false; \
615  TEST::all_tests = false; \
616  { \
617  TEST::initialNewline(); \
618  stdcout << "Error: Caught unidentified and unexpected exception - No message." \
619  << std::endl; \
620  } \
621  } \
622  TEST::all_tests = TEST::all_tests && TEST::test; \
623  { \
624  if (TEST::test) \
625  { \
626  stdcout << ": passed\n"; \
627  } \
628  else \
629  { \
630  stdcout << ": failed\n"; \
631  } \
632  } \
633  /* issue a warning if no tests were performed (unless in destructor)*/ \
634  if (TEST::test_count == 0) \
635  { \
636  if (OpenMS::String(TEST::test_name).has('~')) \
637  stdcout << "Warning: no subtests performed in '" \
638  << TEST::test_name \
639  << "' (line " \
640  << __LINE__ \
641  << ")!\n"; \
642  } \
643  stdcout << std::endl;
644 
646 
666 #define TEST_EQUAL(a, b) TEST::testEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
667 
679 #define TEST_NOT_EQUAL(a, b) TEST::testNotEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
680 
693 #define TEST_STRING_EQUAL(a, b) TEST::testStringEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
694 
709 #define TEST_FILE_EQUAL(filename, templatename) \
710  { \
711  TEST::filesEqual(__LINE__, filename, templatename, #filename, #templatename); \
712  }
713 
729 #define TEST_REAL_SIMILAR(a, b) TEST::testRealSimilar(__FILE__, __LINE__, (a), (# a), TEST::isRealType(a), writtenDigits(a), (b), (# b), TEST::isRealType(b), writtenDigits(b));
730 
746 #define TEST_STRING_SIMILAR(a, b) TEST::testStringSimilar(__FILE__, __LINE__, (a), (# a), (b), (# b));
747 
762 #define TEST_FILE_SIMILAR(a, b) \
763  { \
764  ++TEST::test_count; \
765  TEST::test_line = __LINE__; \
766  TEST::this_test = TEST::isFileSimilar((a), (b)); \
767  TEST::test = TEST::test && TEST::this_test; \
768  { \
769  TEST::initialNewline(); \
770  if (TEST::this_test) \
771  { \
772  if (TEST::verbose > 1) \
773  { \
774  stdcout << " + line " << __LINE__ \
775  << ": TEST_FILE_SIMILAR(" # a "," # b "): absolute: " \
776  << precisionWrapper(TEST::absdiff) \
777  << " (" \
778  << precisionWrapper(TEST::absdiff_max_allowed) \
779  << "), relative: " \
780  << precisionWrapper(TEST::ratio) \
781  << " (" \
782  << precisionWrapper(TEST::ratio_max_allowed) \
783  << ")\n"; \
784  stdcout << "message: \n"; \
785  stdcout << TEST::fuzzy_message; \
786  } \
787  } \
788  else \
789  { \
790  stdcout << " - line " << TEST::test_line << \
791  ": TEST_FILE_SIMILAR(" # a "," # b ") ... -\n"; \
792  stdcout << "message: \n"; \
793  stdcout << TEST::fuzzy_message; \
794  TEST::failed_lines_list.push_back(TEST::test_line); \
795  } \
796  } \
797  }
798 
811 #define TOLERANCE_RELATIVE(a) \
812  TEST::ratio_max_allowed = (a); \
813  { \
814  TEST::initialNewline(); \
815  if (TEST::verbose > 1) \
816  { \
817  stdcout << " + line " << __LINE__ << \
818  ": TOLERANCE_RELATIVE(" << TEST::ratio_max_allowed << \
819  ") (\"" # a "\")\n"; \
820  } \
821  }
822 
834 #define TOLERANCE_ABSOLUTE(a) \
835  TEST::absdiff_max_allowed = (a); \
836  { \
837  TEST::initialNewline(); \
838  if (TEST::verbose > 1) \
839  { \
840  stdcout << " + line " << __LINE__ << \
841  ": TOLERANCE_ABSOLUTE(" << TEST::absdiff_max_allowed << \
842  ") (\"" # a "\")\n"; \
843  } \
844  }
845 
851 #define WHITELIST(a) TEST::setWhitelist(__FILE__, __LINE__, (a));
852 
865 #define TEST_EXCEPTION(exception_type, command) \
866  { \
867  ++TEST::test_count; \
868  TEST::test_line = __LINE__; \
869  TEST::exception = 0; \
870  try \
871  { \
872  command; \
873  } \
874  catch (exception_type&) \
875  { \
876  TEST::exception = 1; \
877  } \
878  catch (::OpenMS::Exception::BaseException& e) \
879  { \
880  TEST::exception = 2; \
881  TEST::exception_name = e.getName(); \
882  } \
883  catch (...) \
884  { \
885  TEST::exception = 3; \
886  } \
887  TEST::this_test = (TEST::exception == 1); \
888  TEST::test = TEST::test && TEST::this_test; \
889  \
890  { \
891  TEST::initialNewline(); \
892  switch (TEST::exception) \
893  { \
894  case 0: \
895  stdcout << " - line " << TEST::test_line << \
896  ": TEST_EXCEPTION(" # exception_type "," # command \
897  "): no exception thrown!\n"; \
898  TEST::failed_lines_list.push_back(TEST::test_line); \
899  break; \
900  case 1: \
901  if (TEST::verbose > 1) \
902  { \
903  stdcout << " + line " << TEST::test_line << \
904  ": TEST_EXCEPTION(" # exception_type "," # command \
905  "): OK\n"; \
906  } \
907  break; \
908  case 2: \
909  stdcout << " - line " << TEST::test_line << \
910  ": TEST_EXCEPTION(" # exception_type "," # command \
911  "): wrong exception thrown! \"" \
912  << TEST::exception_name << "\"\n"; \
913  TEST::failed_lines_list.push_back(TEST::test_line); \
914  break; \
915  case 3: \
916  stdcout << " - line " << TEST::test_line << \
917  ": TEST_EXCEPTION(" # exception_type "," # command \
918  "): wrong exception thrown!\n"; \
919  TEST::failed_lines_list.push_back(TEST::test_line); \
920  break; \
921  } \
922  } \
923  }
924 
936 #ifdef OPENMS_ASSERTIONS
937 #define TEST_PRECONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Precondition, command);
938 #else
939 #define TEST_PRECONDITION_VIOLATED(command) STATUS("TEST_PRECONDITION_VIOLATED(" # command ") - skipped");
940 #endif
941 
953 #ifdef OPENMS_ASSERTIONS
954 #define TEST_POSTCONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Postcondition, command);
955 #else
956 #define TEST_POSTCONDITION_VIOLATED(command) STATUS("TEST_POSTCONDITION_VIOLATED(" # command ") - skipped");
957 #endif
958 
959 
976 #define TEST_EXCEPTION_WITH_MESSAGE(exception_type, command, message) \
977  { \
978  ++TEST::test_count; \
979  TEST::test_line = __LINE__; \
980  TEST::exception = 0; \
981  try \
982  { \
983  command; \
984  } \
985  catch (exception_type& et) \
986  { \
987  if (std::string(et.what()) != std::string(message)) \
988  { \
989  TEST::exception = 4; \
990  TEST::exception_message = et.what(); \
991  } \
992  else TEST::exception = 1; \
993  } \
994  catch (::OpenMS::Exception::BaseException& e) \
995  { \
996  TEST::exception = 2; \
997  TEST::exception_name = e.getName(); \
998  } \
999  catch (...) \
1000  { \
1001  TEST::exception = 3; \
1002  } \
1003  TEST::this_test = (TEST::exception == 1); \
1004  TEST::test = TEST::test && TEST::this_test; \
1005  \
1006  { \
1007  TEST::initialNewline(); \
1008  switch (TEST::exception) \
1009  { \
1010  case 0: \
1011  stdcout << " - line " << TEST::test_line << \
1012  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1013  "): no exception thrown!\n"; \
1014  TEST::failed_lines_list.push_back(TEST::test_line); \
1015  break; \
1016  case 1: \
1017  if (TEST::verbose > 1) \
1018  { \
1019  /* this is actually what we want to get: */ \
1020  stdcout << " + line " << TEST::test_line << \
1021  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1022  "): OK\n"; \
1023  break; \
1024  } \
1025  case 2: \
1026  stdcout << " - line " << TEST::test_line << \
1027  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1028  "): wrong exception thrown! \"" << \
1029  TEST::exception_name << "\"\n"; \
1030  TEST::failed_lines_list.push_back(TEST::test_line); \
1031  break; \
1032  case 3: \
1033  stdcout << " - line " << TEST::test_line << \
1034  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1035  "): wrong exception thrown!\n"; \
1036  TEST::failed_lines_list.push_back(TEST::test_line); \
1037  break; \
1038  case 4: \
1039  stdcout << " - line " << TEST::test_line << \
1040  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1041  "): exception has wrong message: got '" << \
1042  TEST::exception_message << \
1043  "', expected '" << \
1044  (message) << "'\n"; \
1045  TEST::failed_lines_list.push_back(TEST::test_line); \
1046  break; \
1047  } \
1048  } \
1049  }
1050 
1066 #define NEW_TMP_FILE(filename) \
1067  { \
1068  filename = TEST::tmpFileName(__FILE__, __LINE__); \
1069  TEST::tmp_file_list.push_back(filename); \
1070  { \
1071  TEST::initialNewline(); \
1072  stdcout << " creating new temporary filename '" \
1073  << filename \
1074  << "' (line " \
1075  << __LINE__ \
1076  << ")\n"; \
1077  } \
1078  }
1079 
1087 #define ABORT_IF(condition) \
1088  if (condition) \
1089  { \
1090  { \
1091  TEST::test_line = __LINE__; \
1092  TEST::this_test = false; \
1093  TEST::test = TEST::test && TEST::this_test; \
1094  TEST::failed_lines_list.push_back(TEST::test_line); \
1095  TEST::initialNewline(); \
1096  stdcout << " - line " << TEST::test_line << \
1097  ": ABORT_IF(" # condition "): TEST ABORTED\n"; \
1098  } \
1099  break; \
1100  }
1101 
1119 #define STATUS(message) \
1120  { \
1121  TEST::initialNewline(); \
1122  stdcout << " line " \
1123  << __LINE__ \
1124  << ": status: " \
1125  << message \
1126  << "\n"; \
1127  }
1128 
1138 #define ADD_MESSAGE(message) \
1139  TEST::add_message = message;
1140 
1150 #define NOT_TESTABLE \
1151  TEST::test_count = 1;
1152 
#define stdcout
Provide a point of redirection for testing the test macros, see ClassTest_test.cpp.
Definition: ClassTest.h:58
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:59
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:55
int Int
Signed integer type.
Definition: Types.h:102
Namespace for class tests.
Definition: ClassTest.h:67
double ratio_max
Maximum ratio of numbers observed so far, see TOLERANCE_RELATIVE.
int verbose
Verbosity level ( "-v" is 1 and "-V" is 2 )
int test_count
Counter for the number of elementary tests within the current subsection.
void initialNewline()
make sure we have a newline before results from first subtest
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 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
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.
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.
bool validate(const std::vector< std::string > &file_names)
Validates the given files against the XML schema (if available)
std::string fuzzy_message
Last message from a fuzzy comparison. Written by isRealSimilar(), testStringSimilar(),...
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 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 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
double absdiff_max
Maximum difference of numbers observed so far, see TOLERANCE_ABSOLUTE.
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 newline
(Flags whether a new line is in place, depending on context and verbosity setting....
std::string tmpFileName(const std::string &file, int line)
Creates a temporary file name from the test name and the line.
bool test
Status of the current subsection.
double absdiff_max_allowed
Maximum absolute difference of numbers allowed, see TOLERANCE_ABSOLUTE.
const char * version_string
Version string supplied with START_TEST.
std::ifstream infile
Questionable file tested by TEST_FILE_EQUAL.
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 removeTempFiles()
removed all temporary files created with the NEW_TMP_FILE macro
double ratio
Recent ratio of numbers, see TOLERANCE_RELATIVE.
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.
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:331
bool this_test
Status of last elementary test.
std::ifstream templatefile
Template (correct) file used by TEST_FILE_EQUAL.
double ratio_max_allowed
Maximum ratio of numbers allowed, see TOLERANCE_RELATIVE.
void setWhitelist(const char *const, const int line, const std::string &whitelist)
set the whitelist_
bool isRealType(float)
This overload returns true; float is a floating point type.
Definition: ClassTest.h:82
bool equal_files
(A variable used by TEST_FILE_EQUAL)
int start_section_line
Line where current subsection started.
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)
int exception
(Used by various macros. Indicates a rough category of the exception being caught....
bool isRealSimilar(long double number_1, long double number_2)
used by testRealSimilar()
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47