OpenMS  3.0.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-2022.
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
172  initialNewline();
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  void testTrue(const char* /*file*/, int line, const bool expression_1, const char* expression_1_stringified)
330  {
331  ++test_count;
332  test_line = line;
333  this_test = expression_1;
334  test = test && this_test;
335  {
336  initialNewline();
337  if (this_test)
338  {
339  if (verbose > 1)
340  {
341  stdcout << " + line " << line << ": TEST_TRUE(" << expression_1_stringified << "): ok\n";
342  }
343  }
344  else
345  {
346  stdcout << " - line " << line << ": TEST_TRUE(" << expression_1_stringified << "): failed\n";
347  failed_lines_list.push_back(line);
348  }
349  }
350  }
351 
352  void testFalse(const char* /*file*/, int line, const bool expression_1, const char* expression_1_stringified)
353  {
354  ++test_count;
355  test_line = line;
356  this_test = !expression_1;
357  test = test && this_test;
358  {
359  initialNewline();
360  if (this_test)
361  {
362  if (verbose > 1)
363  {
364  stdcout << " + line " << line << ": TEST_FALSE(" << expression_1_stringified << "): ok\n";
365  }
366  }
367  else
368  {
369  stdcout << " - line " << line << ": TEST_FALSE(" << expression_1_stringified << "): failed\n";
370  failed_lines_list.push_back(line);
371  }
372  }
373  }
374 
375  template <typename T1, typename T2>
376  void
377  testNotEqual(const char* /*file*/, int line, const T1& expression_1,
378  const char* expression_1_stringified,
379  const T2& expression_2,
380  const char* expression_2_stringified)
381  {
382  ++test_count;
383  test_line = line;
384  this_test = !(expression_1 == T1(expression_2));
385  test = test && this_test;
386  {
387  initialNewline();
388  if (this_test)
389  {
390  if (verbose > 1)
391  {
392  stdcout << " + line " << line << ": TEST_NOT_EQUAL("
393  << expression_1_stringified << ','
394  << expression_2_stringified << "): got '" << expression_1
395  << "', forbidden is '" << expression_2 << "'\n";
396  }
397  }
398  else
399  {
400  stdcout << " - line " << line << ": TEST_NOT_EQUAL("
401  << expression_1_stringified << ','
402  << expression_2_stringified << "): got '" << expression_1
403  << "', forbidden is '" << expression_2 << "'\n";
404  failed_lines_list.push_back(line);
405  }
406  }
407  }
408 
409  }
410  }
411 }
412 
413 // A namespace alias - apparently these cannot be documented using doxygen (?)
415 
440 
441 //@name test and subtest
443 
468 #define START_TEST(class_name, version) \
469  int main(int argc, char** argv) \
470  { \
471  TEST::mainInit(version, #class_name, argc, argv[0]); \
472  try {
473 
485 #define END_TEST \
486  /* global try block */ \
487  } \
488  catch (::OpenMS::Exception::BaseException& e) \
489  { \
490  TEST::this_test = false; \
491  TEST::test = false; \
492  TEST::all_tests = false; \
493  { \
494  TEST::initialNewline(); \
495  stdcout << "Error: Caught unexpected OpenMS exception of type '" \
496  << e.getName() \
497  << "'"; \
498  if ((e.getLine() > 0) && std::strcmp(e.getFile(), "")) \
499  { \
500  stdcout << " thrown in line " << e.getLine() << " of file '" << e.getFile() \
501  << "' in function '" << e.getFunction() << "'"; \
502  } \
503  stdcout << " - Message: " << e.what() << std::endl; \
504  } \
505  } \
506  /* catch std:: exceptions */ \
507  catch (std::exception& e) \
508  { \
509  TEST::this_test = false; \
510  TEST::test = false; \
511  TEST::all_tests = false; \
512  { \
513  TEST::initialNewline(); \
514  stdcout << "Error: Caught unexpected std::exception\n"; \
515  stdcout << " - Message: " << e.what() << std::endl; \
516  } \
517  } \
518  /* catch all other exceptions */ \
519  catch (...) \
520  { \
521  TEST::this_test = false; \
522  TEST::test = false; \
523  TEST::all_tests = false; \
524  { \
525  TEST::initialNewline(); \
526  stdcout << "Error: Caught unidentified and unexpected exception - No message." \
527  << std::endl; \
528  } \
529  } \
530  /* check validity of temporary files if known */ \
531  if (!TEST::validate(TEST::tmp_file_list)) \
532  { \
533  TEST::all_tests = false; \
534  } \
535  if (TEST::verbose == 0) \
536  { \
537  stdcout << "Output of successful tests were suppressed. Set the environment variable 'OPENMS_TEST_VERBOSE=True' to enable them." << std::endl; \
538  } \
539  /* check for exit code */ \
540  if (!TEST::all_tests) \
541  { \
542  stdcout << "FAILED" << std::endl; \
543  if (TEST::add_message != "") stdcout << "Message: " \
544  << TEST::add_message \
545  << std::endl; \
546  stdcout << "Failed lines: "; \
547  for (OpenMS::Size i = 0; i < TEST::failed_lines_list.size(); ++i) \
548  { \
549  stdcout << TEST::failed_lines_list[i] << " "; \
550  } \
551  stdcout << std::endl; \
552  return 1; \
553  } \
554  else \
555  { \
556  /* remove temporary files*/ \
557  TEST::removeTempFiles(); \
558  stdcout << "PASSED"; \
559  if (TEST::add_message != "") stdcout << " (" << TEST::add_message << ")"; \
560  stdcout << std::endl; \
561  return 0; \
562  } \
563  }
564 
587 #define START_SECTION(name_of_test) \
588  TEST::test = true; \
589  TEST::newline = false; \
590  TEST::test_name = # name_of_test; \
591  TEST::test_count = 0; \
592  TEST::start_section_line = __LINE__; \
593  stdcout << "checking " << TEST::test_name << " ... " << std::flush; \
594  try \
595  { \
596  while (true) \
597  {
598 
624 #define END_SECTION \
625  break; \
626  } \
627  } \
628  catch (::OpenMS::Exception::BaseException& e) \
629  { \
630  TEST::this_test = false; \
631  TEST::test = false; \
632  TEST::all_tests = false; \
633  { \
634  TEST::initialNewline(); \
635  stdcout << "Error: Caught unexpected exception of type '" << e.getName() << "'"; \
636  if ((e.getLine() > 0) && (std::strcmp(e.getFile(), "") != 0)) \
637  { \
638  stdcout << " thrown in line " << e.getLine() << " of file '" << e.getFile() \
639  << "' in function '" << e.getFunction() << "'"; \
640  } \
641  stdcout << " - Message: " << e.what() << std::endl; \
642  } \
643  } \
644  /* catch std:: exceptions */ \
645  catch (std::exception& e) \
646  { \
647  TEST::this_test = false; \
648  TEST::test = false; \
649  TEST::all_tests = false; \
650  { \
651  TEST::initialNewline(); \
652  stdcout << "Error: Caught std::exception" << std::endl; \
653  stdcout << " - Message: " << e.what() << std::endl; \
654  } \
655  } \
656  /* catch all other exceptions */ \
657  catch (...) \
658  { \
659  TEST::this_test = false; \
660  TEST::test = false; \
661  TEST::all_tests = false; \
662  { \
663  TEST::initialNewline(); \
664  stdcout << "Error: Caught unidentified and unexpected exception - No message." \
665  << std::endl; \
666  } \
667  } \
668  TEST::all_tests = TEST::all_tests && TEST::test; \
669  { \
670  if (TEST::test) \
671  { \
672  stdcout << ": passed\n"; \
673  } \
674  else \
675  { \
676  stdcout << ": failed\n"; \
677  } \
678  } \
679  /* issue a warning if no tests were performed (unless in destructor)*/ \
680  if (TEST::test_count == 0) \
681  { \
682  if (OpenMS::String(TEST::test_name).has('~')) \
683  stdcout << "Warning: no subtests performed in '" \
684  << TEST::test_name \
685  << "' (line " \
686  << __LINE__ \
687  << ")!\n"; \
688  } \
689  stdcout << std::endl;
690 
692 
712 #define TEST_EQUAL(a, b) TEST::testEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
713 
723 #define TEST_TRUE(a) TEST::testTrue(__FILE__, __LINE__, (a), (#a));
724 
734 #define TEST_FALSE(a) TEST::testFalse(__FILE__, __LINE__, (a), (#a));
735 
736 
748 #define TEST_NOT_EQUAL(a, b) TEST::testNotEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
749 
762 #define TEST_STRING_EQUAL(a, b) TEST::testStringEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
763 
778 #define TEST_FILE_EQUAL(filename, templatename) \
779  { \
780  TEST::filesEqual(__LINE__, filename, templatename, #filename, #templatename); \
781  }
782 
798 #define TEST_REAL_SIMILAR(a, b) TEST::testRealSimilar(__FILE__, __LINE__, (a), (# a), TEST::isRealType(a), writtenDigits(a), (b), (# b), TEST::isRealType(b), writtenDigits(b));
799 
815 #define TEST_STRING_SIMILAR(a, b) TEST::testStringSimilar(__FILE__, __LINE__, (a), (# a), (b), (# b));
816 
831 #define TEST_FILE_SIMILAR(a, b) \
832  { \
833  ++TEST::test_count; \
834  TEST::test_line = __LINE__; \
835  TEST::this_test = TEST::isFileSimilar((a), (b)); \
836  TEST::test = TEST::test && TEST::this_test; \
837  { \
838  TEST::initialNewline(); \
839  if (TEST::this_test) \
840  { \
841  if (TEST::verbose > 1) \
842  { \
843  stdcout << " + line " << __LINE__ \
844  << ": TEST_FILE_SIMILAR(" # a "," # b "): absolute: " \
845  << precisionWrapper(TEST::absdiff) \
846  << " (" \
847  << precisionWrapper(TEST::absdiff_max_allowed) \
848  << "), relative: " \
849  << precisionWrapper(TEST::ratio) \
850  << " (" \
851  << precisionWrapper(TEST::ratio_max_allowed) \
852  << ")\n"; \
853  stdcout << "message: \n"; \
854  stdcout << TEST::fuzzy_message; \
855  } \
856  } \
857  else \
858  { \
859  stdcout << " - line " << TEST::test_line << \
860  ": TEST_FILE_SIMILAR(" # a "," # b ") ... -\n"; \
861  stdcout << "message: \n"; \
862  stdcout << TEST::fuzzy_message; \
863  TEST::failed_lines_list.push_back(TEST::test_line); \
864  } \
865  } \
866  }
867 
880 #define TOLERANCE_RELATIVE(a) \
881  TEST::ratio_max_allowed = (a); \
882  { \
883  TEST::initialNewline(); \
884  if (TEST::verbose > 1) \
885  { \
886  stdcout << " + line " << __LINE__ << \
887  ": TOLERANCE_RELATIVE(" << TEST::ratio_max_allowed << \
888  ") (\"" # a "\")\n"; \
889  } \
890  }
891 
903 #define TOLERANCE_ABSOLUTE(a) \
904  TEST::absdiff_max_allowed = (a); \
905  { \
906  TEST::initialNewline(); \
907  if (TEST::verbose > 1) \
908  { \
909  stdcout << " + line " << __LINE__ << \
910  ": TOLERANCE_ABSOLUTE(" << TEST::absdiff_max_allowed << \
911  ") (\"" # a "\")\n"; \
912  } \
913  }
914 
920 #define WHITELIST(a) TEST::setWhitelist(__FILE__, __LINE__, (a));
921 
934 #define TEST_EXCEPTION(exception_type, command) \
935  { \
936  ++TEST::test_count; \
937  TEST::test_line = __LINE__; \
938  TEST::exception = 0; \
939  try \
940  { \
941  command; \
942  } \
943  catch (exception_type&) \
944  { \
945  TEST::exception = 1; \
946  } \
947  catch (::OpenMS::Exception::BaseException& e) \
948  { \
949  TEST::exception = 2; \
950  TEST::exception_name = e.getName(); \
951  } \
952  catch (...) \
953  { \
954  TEST::exception = 3; \
955  } \
956  TEST::this_test = (TEST::exception == 1); \
957  TEST::test = TEST::test && TEST::this_test; \
958  \
959  { \
960  TEST::initialNewline(); \
961  switch (TEST::exception) \
962  { \
963  case 0: \
964  stdcout << " - line " << TEST::test_line << \
965  ": TEST_EXCEPTION(" # exception_type "," # command \
966  "): no exception thrown!\n"; \
967  TEST::failed_lines_list.push_back(TEST::test_line); \
968  break; \
969  case 1: \
970  if (TEST::verbose > 1) \
971  { \
972  stdcout << " + line " << TEST::test_line << \
973  ": TEST_EXCEPTION(" # exception_type "," # command \
974  "): OK\n"; \
975  } \
976  break; \
977  case 2: \
978  stdcout << " - line " << TEST::test_line << \
979  ": TEST_EXCEPTION(" # exception_type "," # command \
980  "): wrong exception thrown! \"" \
981  << TEST::exception_name << "\"\n"; \
982  TEST::failed_lines_list.push_back(TEST::test_line); \
983  break; \
984  case 3: \
985  stdcout << " - line " << TEST::test_line << \
986  ": TEST_EXCEPTION(" # exception_type "," # command \
987  "): wrong exception thrown!\n"; \
988  TEST::failed_lines_list.push_back(TEST::test_line); \
989  break; \
990  } \
991  } \
992  }
993 
1005 #ifdef OPENMS_ASSERTIONS
1006 #define TEST_PRECONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Precondition, command);
1007 #else
1008 #define TEST_PRECONDITION_VIOLATED(command) STATUS("TEST_PRECONDITION_VIOLATED(" # command ") - skipped");
1009 #endif
1010 
1022 #ifdef OPENMS_ASSERTIONS
1023 #define TEST_POSTCONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Postcondition, command);
1024 #else
1025 #define TEST_POSTCONDITION_VIOLATED(command) STATUS("TEST_POSTCONDITION_VIOLATED(" # command ") - skipped");
1026 #endif
1027 
1028 
1045 #define TEST_EXCEPTION_WITH_MESSAGE(exception_type, command, message) \
1046  { \
1047  ++TEST::test_count; \
1048  TEST::test_line = __LINE__; \
1049  TEST::exception = 0; \
1050  try \
1051  { \
1052  command; \
1053  } \
1054  catch (exception_type& et) \
1055  { \
1056  if (std::string(et.what()) != std::string(message)) \
1057  { \
1058  TEST::exception = 4; \
1059  TEST::exception_message = et.what(); \
1060  } \
1061  else TEST::exception = 1; \
1062  } \
1063  catch (::OpenMS::Exception::BaseException& e) \
1064  { \
1065  TEST::exception = 2; \
1066  TEST::exception_name = e.getName(); \
1067  } \
1068  catch (...) \
1069  { \
1070  TEST::exception = 3; \
1071  } \
1072  TEST::this_test = (TEST::exception == 1); \
1073  TEST::test = TEST::test && TEST::this_test; \
1074  \
1075  { \
1076  TEST::initialNewline(); \
1077  switch (TEST::exception) \
1078  { \
1079  case 0: \
1080  stdcout << " - line " << TEST::test_line << \
1081  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1082  "): no exception thrown!\n"; \
1083  TEST::failed_lines_list.push_back(TEST::test_line); \
1084  break; \
1085  case 1: \
1086  if (TEST::verbose > 1) \
1087  { \
1088  /* this is actually what we want to get: */ \
1089  stdcout << " + line " << TEST::test_line << \
1090  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1091  "): OK\n"; \
1092  break; \
1093  } \
1094  case 2: \
1095  stdcout << " - line " << TEST::test_line << \
1096  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1097  "): wrong exception thrown! \"" << \
1098  TEST::exception_name << "\"\n"; \
1099  TEST::failed_lines_list.push_back(TEST::test_line); \
1100  break; \
1101  case 3: \
1102  stdcout << " - line " << TEST::test_line << \
1103  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1104  "): wrong exception thrown!\n"; \
1105  TEST::failed_lines_list.push_back(TEST::test_line); \
1106  break; \
1107  case 4: \
1108  stdcout << " - line " << TEST::test_line << \
1109  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1110  "): exception has wrong message: got '" << \
1111  TEST::exception_message << \
1112  "', expected '" << \
1113  (message) << "'\n"; \
1114  TEST::failed_lines_list.push_back(TEST::test_line); \
1115  break; \
1116  } \
1117  } \
1118  }
1119 
1135 #define NEW_TMP_FILE(filename) \
1136  { \
1137  filename = TEST::tmpFileName(__FILE__, __LINE__); \
1138  TEST::tmp_file_list.push_back(filename); \
1139  { \
1140  TEST::initialNewline(); \
1141  stdcout << " creating new temporary filename '" \
1142  << filename \
1143  << "' (line " \
1144  << __LINE__ \
1145  << ")\n"; \
1146  } \
1147  }
1148 
1156 #define ABORT_IF(condition) \
1157  if (condition) \
1158  { \
1159  { \
1160  TEST::test_line = __LINE__; \
1161  TEST::this_test = false; \
1162  TEST::test = TEST::test && TEST::this_test; \
1163  TEST::failed_lines_list.push_back(TEST::test_line); \
1164  TEST::initialNewline(); \
1165  stdcout << " - line " << TEST::test_line << \
1166  ": ABORT_IF(" # condition "): TEST ABORTED\n"; \
1167  } \
1168  break; \
1169  }
1170 
1188 #define STATUS(message) \
1189  { \
1190  TEST::initialNewline(); \
1191  stdcout << " line " \
1192  << __LINE__ \
1193  << ": status: " \
1194  << message \
1195  << "\n"; \
1196  }
1197 
1207 #define ADD_MESSAGE(message) \
1208  TEST::add_message = message;
1209 
1219 #define NOT_TESTABLE \
1220  TEST::test_count = 1;
1221 
OpenMS::Internal::ClassTest::this_test
bool this_test
Status of last elementary test.
MacrosTest.h
OpenMS::Internal::ClassTest::removeTempFiles
void removeTempFiles()
removed all temporary files created with the NEW_TMP_FILE macro
OpenMS::Internal::ClassTest::isRealType
bool isRealType(float)
This overload returns true; float is a floating point type.
Definition: ClassTest.h:82
OpenMS::Internal::ClassTest::validate
bool validate(const std::vector< std::string > &file_names)
Validates the given files against the XML schema (if available)
OpenMS::Internal::ClassTest::isFileSimilar
bool isFileSimilar(const std::string &filename_1, const std::string &filename_2)
Compare files using absdiff_max_allowed and ratio_max_allowed.
OpenMS::Internal::ClassTest::testStringEqual
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
Types.h
PrecisionWrapper.h
OpenMS::Internal::ClassTest::line_buffer
char line_buffer[65536]
(A buffer for one line from a file. Used by TEST_FILE_EQUAL.)
OpenMS::Internal::ClassTest::absdiff_max
double absdiff_max
Maximum difference of numbers observed so far, see TOLERANCE_ABSOLUTE.
OpenMS::Internal::ClassTest::ratio_max_allowed
double ratio_max_allowed
Maximum ratio of numbers allowed, see TOLERANCE_RELATIVE.
OpenMS::Internal::ClassTest::filesEqual
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)
OpenMS::Internal::ClassTest::fuzzy_message
std::string fuzzy_message
Last message from a fuzzy comparison. Written by isRealSimilar(), testStringSimilar(),...
OpenMS::Internal::ClassTest::ratio
double ratio
Recent ratio of numbers, see TOLERANCE_RELATIVE.
OpenMS::Internal::ClassTest::templatefile
std::ifstream templatefile
Template (correct) file used by TEST_FILE_EQUAL.
OpenMS::Internal::ClassTest::exception
int exception
(Used by various macros. Indicates a rough category of the exception being caught....
OpenMS::ParamValue
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:54
OpenMS::Internal::ClassTest::testStringSimilar
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.
OpenMS::Internal::ClassTest::newline
bool newline
(Flags whether a new line is in place, depending on context and verbosity setting....
OpenMS::Internal::ClassTest::exception_name
std::string exception_name
(Used by various macros. Stores the "name" of the exception, if applicable.)
OpenMS::Internal::ClassTest::start_section_line
int start_section_line
Line where current subsection started.
OpenMS::Internal::ClassTest::line_num_2_max
int line_num_2_max
OpenMS::Internal::ClassTest::testNotEqual
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
OpenMS::Int
int Int
Signed integer type.
Definition: Types.h:102
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::Internal::ClassTest::add_message
std::string add_message
See ADD_MESSAGE.
OpenMS::Internal::ClassTest::testRealSimilar
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.
OpenMS::DataValue
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:58
OpenMS::Internal::ClassTest::tmp_file_list
std::vector< std::string > tmp_file_list
List of tmp file names (these will be cleaned up, see NEW_TMP_FILE)
OpenMS::Internal::ClassTest::setWhitelist
void setWhitelist(const char *const, const int line, const std::string &whitelist)
set the whitelist_
OpenMS::Internal::ClassTest::initialNewline
void initialNewline()
make sure we have a newline before results from first subtest
OpenMS::Internal::ClassTest::failed_lines_list
std::vector< UInt > failed_lines_list
List of all failed lines for summary at the end of the test.
OpenMS::Internal::ClassTest::ratio_max
double ratio_max
Maximum ratio of numbers observed so far, see TOLERANCE_RELATIVE.
OpenMS::Internal::ClassTest::absdiff
double absdiff
Recent absolute difference of numbers, see TOLERANCE_ABSOLUTE.
OpenMS::Internal::ClassTest::isRealSimilar
bool isRealSimilar(long double number_1, long double number_2)
used by testRealSimilar()
OpenMS::Internal::ClassTest::testEqual
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
OpenMS::Internal::ClassTest::tmpFileName
std::string tmpFileName(const std::string &file, int line)
Creates a temporary file name from the test name and the line.
OpenMS::Internal::ClassTest::exception_message
std::string exception_message
(Used by various macros. Stores the "message" of the exception, if applicable.)
OpenMS::Internal::ClassTest::mainInit
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 ...
OpenMS::Internal::ClassTest::equal_files
bool equal_files
(A variable used by TEST_FILE_EQUAL)
OpenMS::Internal::ClassTest::test
bool test
Status of the current subsection.
OpenMS::Internal::ClassTest::line_num_1_max
int line_num_1_max
OpenMS::Internal::ClassTest::verbose
int verbose
Verbosity level ( "-v" is 1 and "-V" is 2 )
OpenMS::Internal::ClassTest::version_string
const char * version_string
Version string supplied with START_TEST.
OpenMS::Internal::ClassTest::all_tests
bool all_tests
Status of the whole test.
OpenMS::Internal::ClassTest::absdiff_max_allowed
double absdiff_max_allowed
Maximum absolute difference of numbers allowed, see TOLERANCE_ABSOLUTE.
OpenMS::Internal::ClassTest::test_count
int test_count
Counter for the number of elementary tests within the current subsection.
DataValue.h
OpenMS::Internal::ClassTest::testFalse
void testFalse(const char *, int line, const bool expression_1, const char *expression_1_stringified)
Definition: ClassTest.h:352
stdcout
#define stdcout
Provide a point of redirection for testing the test macros, see ClassTest_test.cpp.
Definition: ClassTest.h:58
OpenMS::Internal::ClassTest::printWithPrefix
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
OpenMS::Internal::ClassTest
Namespace for class tests.
Definition: ClassTest.h:66
OpenMS::Internal::ClassTest::test_name
std::string test_name
Name of current subsection.
OpenMS::Internal::ClassTest::test_line
int test_line
Line of current elementary test.
OpenMS::Internal::ClassTest::testTrue
void testTrue(const char *, int line, const bool expression_1, const char *expression_1_stringified)
Definition: ClassTest.h:329
OpenMS::Internal::ClassTest::infile
std::ifstream infile
Questionable file tested by TEST_FILE_EQUAL.