OpenMS  2.7.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  stdcout << " + line " << line << ": TEST_EQUAL("
311  << expression_1_stringified << ','
312  << expression_2_stringified << "): got '" << expression_1
313  << "', expected '" << expression_2 << "'\n";
314  }
315  else
316  {
317  stdcout << " - line " << line << ": TEST_EQUAL("
318  << expression_1_stringified << ','
319  << expression_2_stringified << "): got '" << expression_1
320  << "', expected '" << expression_2 << "'\n";
321  failed_lines_list.push_back(line);
322  }
323  }
324  }
325 
326  template <typename T1, typename T2>
327  void
328  testNotEqual(const char* /*file*/, int line, const T1& expression_1,
329  const char* expression_1_stringified,
330  const T2& expression_2,
331  const char* expression_2_stringified)
332  {
333  ++test_count;
334  test_line = line;
335  this_test = !(expression_1 == T1(expression_2));
336  test = test && this_test;
337  {
338  initialNewline();
339  if (this_test)
340  {
341  stdcout << " + line " << line << ": TEST_NOT_EQUAL("
342  << expression_1_stringified << ','
343  << expression_2_stringified << "): got '" << expression_1
344  << "', forbidden is '" << expression_2 << "'\n";
345  }
346  else
347  {
348  stdcout << " - line " << line << ": TEST_NOT_EQUAL("
349  << expression_1_stringified << ','
350  << expression_2_stringified << "): got '" << expression_1
351  << "', forbidden is '" << expression_2 << "'\n";
352  failed_lines_list.push_back(line);
353  }
354  }
355  }
356 
357  }
358  }
359 }
360 
361 // A namespace alias - apparently these cannot be documented using doxygen (?)
363 
388 
389 //@name test and subtest
391 
416 #define START_TEST(class_name, version) \
417  int main(int argc, char** argv) \
418  { \
419  TEST::mainInit(version, #class_name, argc, argv[0]); \
420  try {
421 
433 #define END_TEST \
434  /* global try block */ \
435  } \
436  catch (::OpenMS::Exception::BaseException& e) \
437  { \
438  TEST::this_test = false; \
439  TEST::test = false; \
440  TEST::all_tests = false; \
441  { \
442  TEST::initialNewline(); \
443  stdcout << "Error: Caught unexpected OpenMS exception of type '" \
444  << e.getName() \
445  << "'"; \
446  if ((e.getLine() > 0) && std::strcmp(e.getFile(), "")) \
447  { \
448  stdcout << " thrown in line " << e.getLine() << " of file '" << e.getFile() \
449  << "' in function '" << e.getFunction() << "'"; \
450  } \
451  stdcout << " - Message: " << e.what() << std::endl; \
452  } \
453  } \
454  /* catch std:: exceptions */ \
455  catch (std::exception& e) \
456  { \
457  TEST::this_test = false; \
458  TEST::test = false; \
459  TEST::all_tests = false; \
460  { \
461  TEST::initialNewline(); \
462  stdcout << "Error: Caught unexpected std::exception\n"; \
463  stdcout << " - Message: " << e.what() << std::endl; \
464  } \
465  } \
466  /* catch all other exceptions */ \
467  catch (...) \
468  { \
469  TEST::this_test = false; \
470  TEST::test = false; \
471  TEST::all_tests = false; \
472  { \
473  TEST::initialNewline(); \
474  stdcout << "Error: Caught unidentified and unexpected exception - No message." \
475  << std::endl; \
476  } \
477  } \
478  /* check validity of temporary files if known */ \
479  if (!TEST::validate(TEST::tmp_file_list)) \
480  { \
481  TEST::all_tests = false; \
482  } \
483  /* check for exit code */ \
484  if (!TEST::all_tests) \
485  { \
486  stdcout << "FAILED" << std::endl; \
487  if (TEST::add_message != "") stdcout << "Message: " \
488  << TEST::add_message \
489  << std::endl; \
490  stdcout << "Failed lines: "; \
491  for (OpenMS::Size i = 0; i < TEST::failed_lines_list.size(); ++i) \
492  { \
493  stdcout << TEST::failed_lines_list[i] << " "; \
494  } \
495  stdcout << std::endl; \
496  return 1; \
497  } \
498  else \
499  { \
500  /* remove temporary files*/ \
501  TEST::removeTempFiles(); \
502  stdcout << "PASSED"; \
503  if (TEST::add_message != "") stdcout << " (" << TEST::add_message << ")"; \
504  stdcout << std::endl; \
505  return 0; \
506  } \
507  }
508 
531 #define START_SECTION(name_of_test) \
532  TEST::test = true; \
533  TEST::newline = false; \
534  TEST::test_name = # name_of_test; \
535  TEST::test_count = 0; \
536  TEST::start_section_line = __LINE__; \
537  stdcout << "checking " << TEST::test_name << " ... " << std::flush; \
538  try \
539  { \
540  while (true) \
541  {
542 
568 #define END_SECTION \
569  break; \
570  } \
571  } \
572  catch (::OpenMS::Exception::BaseException& e) \
573  { \
574  TEST::this_test = false; \
575  TEST::test = false; \
576  TEST::all_tests = false; \
577  { \
578  TEST::initialNewline(); \
579  stdcout << "Error: Caught unexpected exception of type '" << e.getName() << "'"; \
580  if ((e.getLine() > 0) && (std::strcmp(e.getFile(), "") != 0)) \
581  { \
582  stdcout << " thrown in line " << e.getLine() << " of file '" << e.getFile() \
583  << "' in function '" << e.getFunction() << "'"; \
584  } \
585  stdcout << " - Message: " << e.what() << std::endl; \
586  } \
587  } \
588  /* catch std:: exceptions */ \
589  catch (std::exception& e) \
590  { \
591  TEST::this_test = false; \
592  TEST::test = false; \
593  TEST::all_tests = false; \
594  { \
595  TEST::initialNewline(); \
596  stdcout << "Error: Caught std::exception" << std::endl; \
597  stdcout << " - Message: " << e.what() << std::endl; \
598  } \
599  } \
600  /* catch all other exceptions */ \
601  catch (...) \
602  { \
603  TEST::this_test = false; \
604  TEST::test = false; \
605  TEST::all_tests = false; \
606  { \
607  TEST::initialNewline(); \
608  stdcout << "Error: Caught unidentified and unexpected exception - No message." \
609  << std::endl; \
610  } \
611  } \
612  TEST::all_tests = TEST::all_tests && TEST::test; \
613  { \
614  if (TEST::test) \
615  { \
616  stdcout << ": passed\n"; \
617  } \
618  else \
619  { \
620  stdcout << ": failed\n"; \
621  } \
622  } \
623  /* issue a warning if no tests were performed (unless in destructor)*/ \
624  if (TEST::test_count == 0) \
625  { \
626  if (OpenMS::String(TEST::test_name).has('~')) \
627  stdcout << "Warning: no subtests performed in '" \
628  << TEST::test_name \
629  << "' (line " \
630  << __LINE__ \
631  << ")!\n"; \
632  } \
633  stdcout << std::endl;
634 
636 
656 #define TEST_EQUAL(a, b) TEST::testEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
657 
669 #define TEST_NOT_EQUAL(a, b) TEST::testNotEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
670 
683 #define TEST_STRING_EQUAL(a, b) TEST::testStringEqual(__FILE__, __LINE__, (a), (# a), (b), (# b));
684 
699 #define TEST_FILE_EQUAL(filename, templatename) \
700  { \
701  TEST::filesEqual(__LINE__, filename, templatename, #filename, #templatename); \
702  }
703 
719 #define TEST_REAL_SIMILAR(a, b) TEST::testRealSimilar(__FILE__, __LINE__, (a), (# a), TEST::isRealType(a), writtenDigits(a), (b), (# b), TEST::isRealType(b), writtenDigits(b));
720 
736 #define TEST_STRING_SIMILAR(a, b) TEST::testStringSimilar(__FILE__, __LINE__, (a), (# a), (b), (# b));
737 
752 #define TEST_FILE_SIMILAR(a, b) \
753  { \
754  ++TEST::test_count; \
755  TEST::test_line = __LINE__; \
756  TEST::this_test = TEST::isFileSimilar((a), (b)); \
757  TEST::test = TEST::test && TEST::this_test; \
758  { \
759  TEST::initialNewline(); \
760  if (TEST::this_test) \
761  { \
762  stdcout << " + line " << __LINE__ \
763  << ": TEST_FILE_SIMILAR(" # a "," # b "): absolute: " \
764  << precisionWrapper(TEST::absdiff) \
765  << " (" \
766  << precisionWrapper(TEST::absdiff_max_allowed) \
767  << "), relative: " \
768  << precisionWrapper(TEST::ratio) \
769  << " (" \
770  << precisionWrapper(TEST::ratio_max_allowed) \
771  << ")\n"; \
772  stdcout << "message: \n"; \
773  stdcout << TEST::fuzzy_message; \
774  } \
775  else \
776  { \
777  stdcout << " - line " << TEST::test_line << \
778  ": TEST_FILE_SIMILAR(" # a "," # b ") ... -\n"; \
779  stdcout << "message: \n"; \
780  stdcout << TEST::fuzzy_message; \
781  TEST::failed_lines_list.push_back(TEST::test_line); \
782  } \
783  } \
784  }
785 
798 #define TOLERANCE_RELATIVE(a) \
799  TEST::ratio_max_allowed = (a); \
800  { \
801  TEST::initialNewline(); \
802  stdcout << " + line " << __LINE__ << \
803  ": TOLERANCE_RELATIVE(" << TEST::ratio_max_allowed << \
804  ") (\"" # a "\")\n"; \
805  }
806 
818 #define TOLERANCE_ABSOLUTE(a) \
819  TEST::absdiff_max_allowed = (a); \
820  { \
821  TEST::initialNewline(); \
822  stdcout << " + line " << __LINE__ << \
823  ": TOLERANCE_ABSOLUTE(" << TEST::absdiff_max_allowed << \
824  ") (\"" # a "\")\n"; \
825  }
826 
832 #define WHITELIST(a) TEST::setWhitelist(__FILE__, __LINE__, (a));
833 
846 #define TEST_EXCEPTION(exception_type, command) \
847  { \
848  ++TEST::test_count; \
849  TEST::test_line = __LINE__; \
850  TEST::exception = 0; \
851  try \
852  { \
853  command; \
854  } \
855  catch (exception_type&) \
856  { \
857  TEST::exception = 1; \
858  } \
859  catch (::OpenMS::Exception::BaseException& e) \
860  { \
861  TEST::exception = 2; \
862  TEST::exception_name = e.getName(); \
863  } \
864  catch (...) \
865  { \
866  TEST::exception = 3; \
867  } \
868  TEST::this_test = (TEST::exception == 1); \
869  TEST::test = TEST::test && TEST::this_test; \
870  \
871  { \
872  TEST::initialNewline(); \
873  switch (TEST::exception) \
874  { \
875  case 0: \
876  stdcout << " - line " << TEST::test_line << \
877  ": TEST_EXCEPTION(" # exception_type "," # command \
878  "): no exception thrown!\n"; \
879  TEST::failed_lines_list.push_back(TEST::test_line); \
880  break; \
881  case 1: \
882  stdcout << " + line " << TEST::test_line << \
883  ": TEST_EXCEPTION(" # exception_type "," # command \
884  "): OK\n"; \
885  break; \
886  case 2: \
887  stdcout << " - line " << TEST::test_line << \
888  ": TEST_EXCEPTION(" # exception_type "," # command \
889  "): wrong exception thrown! \"" \
890  << TEST::exception_name << "\"\n"; \
891  TEST::failed_lines_list.push_back(TEST::test_line); \
892  break; \
893  case 3: \
894  stdcout << " - line " << TEST::test_line << \
895  ": TEST_EXCEPTION(" # exception_type "," # command \
896  "): wrong exception thrown!\n"; \
897  TEST::failed_lines_list.push_back(TEST::test_line); \
898  break; \
899  } \
900  } \
901  }
902 
914 #ifdef OPENMS_ASSERTIONS
915 #define TEST_PRECONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Precondition, command);
916 #else
917 #define TEST_PRECONDITION_VIOLATED(command) STATUS("TEST_PRECONDITION_VIOLATED(" # command ") - skipped");
918 #endif
919 
931 #ifdef OPENMS_ASSERTIONS
932 #define TEST_POSTCONDITION_VIOLATED(command) TEST_EXCEPTION(Exception::Postcondition, command);
933 #else
934 #define TEST_POSTCONDITION_VIOLATED(command) STATUS("TEST_POSTCONDITION_VIOLATED(" # command ") - skipped");
935 #endif
936 
937 
954 #define TEST_EXCEPTION_WITH_MESSAGE(exception_type, command, message) \
955  { \
956  ++TEST::test_count; \
957  TEST::test_line = __LINE__; \
958  TEST::exception = 0; \
959  try \
960  { \
961  command; \
962  } \
963  catch (exception_type& et) \
964  { \
965  if (std::string(et.what()) != std::string(message)) \
966  { \
967  TEST::exception = 4; \
968  TEST::exception_message = et.what(); \
969  } \
970  else TEST::exception = 1; \
971  } \
972  catch (::OpenMS::Exception::BaseException& e) \
973  { \
974  TEST::exception = 2; \
975  TEST::exception_name = e.getName(); \
976  } \
977  catch (...) \
978  { \
979  TEST::exception = 3; \
980  } \
981  TEST::this_test = (TEST::exception == 1); \
982  TEST::test = TEST::test && TEST::this_test; \
983  \
984  { \
985  TEST::initialNewline(); \
986  switch (TEST::exception) \
987  { \
988  case 0: \
989  stdcout << " - line " << TEST::test_line << \
990  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
991  "): no exception thrown!\n"; \
992  TEST::failed_lines_list.push_back(TEST::test_line); \
993  break; \
994  case 1: \
995  /* this is actually what we want to get: */ \
996  stdcout << " + line " << TEST::test_line << \
997  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
998  "): OK\n"; \
999  break; \
1000  case 2: \
1001  stdcout << " - line " << TEST::test_line << \
1002  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1003  "): wrong exception thrown! \"" << \
1004  TEST::exception_name << "\"\n"; \
1005  TEST::failed_lines_list.push_back(TEST::test_line); \
1006  break; \
1007  case 3: \
1008  stdcout << " - line " << TEST::test_line << \
1009  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1010  "): wrong exception thrown!\n"; \
1011  TEST::failed_lines_list.push_back(TEST::test_line); \
1012  break; \
1013  case 4: \
1014  stdcout << " - line " << TEST::test_line << \
1015  ": TEST_EXCEPTION_WITH_MESSAGE(" # exception_type "," # command ", " # message \
1016  "): exception has wrong message: got '" << \
1017  TEST::exception_message << \
1018  "', expected '" << \
1019  (message) << "'\n"; \
1020  TEST::failed_lines_list.push_back(TEST::test_line); \
1021  break; \
1022  } \
1023  } \
1024  }
1025 
1041 #define NEW_TMP_FILE(filename) \
1042  { \
1043  filename = TEST::tmpFileName(__FILE__, __LINE__); \
1044  TEST::tmp_file_list.push_back(filename); \
1045  { \
1046  TEST::initialNewline(); \
1047  stdcout << " creating new temporary filename '" \
1048  << filename \
1049  << "' (line " \
1050  << __LINE__ \
1051  << ")\n"; \
1052  } \
1053  }
1054 
1062 #define ABORT_IF(condition) \
1063  if (condition) \
1064  { \
1065  { \
1066  TEST::test_line = __LINE__; \
1067  TEST::this_test = false; \
1068  TEST::test = TEST::test && TEST::this_test; \
1069  TEST::failed_lines_list.push_back(TEST::test_line); \
1070  TEST::initialNewline(); \
1071  stdcout << " - line " << TEST::test_line << \
1072  ": ABORT_IF(" # condition "): TEST ABORTED\n"; \
1073  } \
1074  break; \
1075  }
1076 
1094 #define STATUS(message) \
1095  { \
1096  TEST::initialNewline(); \
1097  stdcout << " line " \
1098  << __LINE__ \
1099  << ": status: " \
1100  << message \
1101  << "\n"; \
1102  }
1103 
1113 #define ADD_MESSAGE(message) \
1114  TEST::add_message = message;
1115 
1125 #define NOT_TESTABLE \
1126  TEST::test_count = 1;
1127 
1129 
#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:53
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:328
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