TestUtil.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #ifndef GNSSTK_TESTUTIL_HPP
40 #define GNSSTK_TESTUTIL_HPP
41 
42 #include <typeinfo>
43 #include <iostream>
44 #include <fstream>
45 #include <string>
46 #include <iomanip>
47 #include <sstream>
48 #include <cmath>
49 #include <vector>
50 #include <float.h>
51 #include "build_config.h"
52 #include "StringUtils.hpp"
53 #include "Matrix.hpp"
54 
55 // Define a TestUtil object named testFramework
56 #define TUDEF(CLASS,METHOD) gnsstk::TestUtil testFramework(CLASS, METHOD, __FILE__, __LINE__)
57 
58 // Macro to make test code look nice...
59 #define TUCSM(METHOD) testFramework.changeSourceMethod(METHOD)
60 
61 
62 // Macro to be short form of TestUtil::assert()
63 #define TUASSERT(EXPR) \
64  try \
65  { \
66  testFramework.assert(EXPR, "Assertion failure: "#EXPR, __LINE__); \
67  } \
68  catch (gnsstk::Exception &exc) \
69  { \
70  std::cerr << exc << std::endl; \
71  testFramework.assert(false, "Exception during "#EXPR, __LINE__); \
72  } \
73  catch (...) \
74  { \
75  testFramework.assert(false, "Exception during "#EXPR, __LINE__); \
76  }
77 
78 
79 // Basic macro for doing equality tests. Expects a TestUtil instance
80 // named testFramework.
81 #define TUASSERTE(TYPE,EXP,GOT) \
82  try \
83  { \
84  testFramework.assert_equals<TYPE>(EXP, GOT, __LINE__); \
85  } \
86  catch (gnsstk::Exception &exc) \
87  { \
88  std::cerr << exc << std::endl; \
89  testFramework.assert(false, \
90  "Exception evaluating " #EXP " or " #GOT, \
91  __LINE__); \
92  } \
93  catch (...) \
94  { \
95  testFramework.assert(false, \
96  "Exception evaluating " #EXP " or " #GOT, \
97  __LINE__); \
98  }
99 
100 
101 // Macro for doing equality tests of double/float values. Expects a
102 // TestUtil instance named testFramework.
103 #define TUASSERTFE(EXP,GOT) \
104  try \
105  { \
106  testFramework.assert_equals(EXP, GOT, __LINE__); \
107  } \
108  catch (gnsstk::Exception &exc) \
109  { \
110  std::cerr << exc << std::endl; \
111  testFramework.assert(false, \
112  "Exception evaluating " #EXP " or " #GOT, \
113  __LINE__); \
114  } \
115  catch (...) \
116  { \
117  testFramework.assert(false, \
118  "Exception evaluating " #EXP " or " #GOT, \
119  __LINE__); \
120  }
121 
122 
123 // Macro for doing equality tests of double/float values with a
124 // specified epsilon. Expects a TestUtil instance named
125 // testFramework.
126 #define TUASSERTFEPS(EXP,GOT,EPS) \
127  try \
128  { \
129  testFramework.assert_equals(EXP, GOT, __LINE__, "", EPS); \
130  } \
131  catch (gnsstk::Exception &exc) \
132  { \
133  std::cerr << exc << std::endl; \
134  testFramework.assert(false, \
135  "Exception evaluating " #EXP " or " #GOT, \
136  __LINE__); \
137  } \
138  catch (...) \
139  { \
140  testFramework.assert(false, \
141  "Exception evaluating " #EXP " or " #GOT, \
142  __LINE__); \
143  }
144 
145 
146 // Macro for doing equality tests of double/float values with an
147 // epsilon chosen based on the representable precision given an
148 // expected exponent. Expects a TestUtil instance named
149 // testFramework.
150 #define TUASSERTFESMRT(EXP,GOT) \
151  try \
152  { \
153  testFramework.assert_equals_fps(EXP, GOT, __LINE__, ""); \
154  } \
155  catch (gnsstk::Exception &exc) \
156  { \
157  std::cerr << exc << std::endl; \
158  testFramework.assert(false, \
159  "Exception evaluating " #EXP " or " #GOT, \
160  __LINE__); \
161  } \
162  catch (...) \
163  { \
164  testFramework.assert(false, \
165  "Exception evaluating " #EXP " or " #GOT, \
166  __LINE__); \
167  }
168 
169 // Macro for doing comparisons of test files
170 #define TUCMPFILE(F1,F2,SKIP) \
171  try \
172  { \
173  testFramework.assert_files_equal(__LINE__, F1, F2, \
174  "File mismatch: "+F1+" "+F2, \
175  SKIP); \
176  } \
177  catch (gnsstk::Exception &exc) \
178  { \
179  std::cerr << exc << std::endl; \
180  testFramework.assert(false, \
181  "Exception comparing " #F1 " and " #F2, \
182  __LINE__); \
183  } \
184  catch (...) \
185  { \
186  testFramework.assert(false, \
187  "Exception comparing " #F1 " and " #F2, \
188  __LINE__); \
189  }
190 
191 // Macro for executing a statement inside a try/catch block with PASS/FAIL.
192 // e.g. TUCATCH(object.methodShouldNotThrow());
193 #define TUCATCH(STATEMENT) \
194  try \
195  { \
196  STATEMENT; \
197  TUPASS(#STATEMENT); \
198  } \
199  catch (gnsstk::Exception &exc) \
200  { \
201  std::cerr << exc << std::endl; \
202  TUFAIL("Exception"); \
203  } \
204  catch (...) \
205  { \
206  TUFAIL("Exception"); \
207  }
208 
209 // Macro for executing a statement inside a try/catch block with PASS/FAIL.
210 // e.g. TUTHROW(object.methodShouldDefinitelyThrow());
211 #define TUTHROW(STATEMENT) \
212  try \
213  { \
214  STATEMENT; \
215  TUFAIL("Did not throw Exception"); \
216  } \
217  catch (gnsstk::Exception &exc) \
218  { \
219  TUPASS(#STATEMENT); \
220  } \
221  catch (...) \
222  { \
223  TUPASS(#STATEMENT); \
224  }
225 
226 
227 // Fail the test with a message.
228 #define TUFAIL(MSG) testFramework.assert(false, MSG, __LINE__)
229 // Pass the test with a (unprinted) message.
230 #define TUPASS(MSG) testFramework.assert(true, MSG, __LINE__)
231 // Usual return from a test function
232 #define TURETURN() return testFramework.countFails()
233 
234 namespace gnsstk
235 {
237  template<typename T>
238  std::string typeString()
239  {
240  if (typeid(T) == typeid(long double))
241  return std::string("long double");
242  else if (typeid(T) == typeid(double))
243  return std::string("double");
244  else if (typeid(T) == typeid(float))
245  return std::string("float");
246  else
247  return 0;
248  }
249 
250  //============================================================
251  // class: TestUtil
252  // purpose: TestUtil is a utility class (not parent class)
253  // for use with test classes and test methods in GNSSTk.
254  // Example: Source usage for a test method with 4 sub-tests:
255  //
256  // TUDEF("SomeClass", "SomeMethod");
257  //
258  // TUASSERTE(unsigned, 1, 2);
259  // which is equivalent to
260  // testFramework.assert( 1==2 );
261  // TUASSERTE(unsigned, 1, 1);
262  // testFramework.changeSourceMethod("SomeOtherMethod");
263  //
264  //============================================================
265  class TestUtil
266  {
267  public:
280  TestUtil( const std::string& sourceClassInput = "Unknown",
281  const std::string& sourceMethodInput = "Unknown",
282  const std::string& testFileInput = "Unknown",
283  const int& testLineInput = 0,
284  const int& verbosityInput = 1
285  );
286 
296  void assert( bool testExpression,
297  const std::string& testMsg,
298  const int lineNumber );
299 
310  template <class T>
311  void assert_equals( const T& expected,
312  const T& got,
313  int lineNumber,
314  const std::string& testMsg = std::string());
315 
329  void assert_equals( double expected,
330  double got,
331  int lineNumber,
332  const std::string& testMsg = std::string(),
333  double epsilon=-1)
334  {assert_equals_fp<double>(expected, got, lineNumber, testMsg, epsilon);}
335 
336  void assert_equals( long double expected,
337  long double got,
338  int lineNumber,
339  const std::string& testMsg = std::string(),
340  long double epsilon=-1)
341  {assert_equals_fp<double>(expected, got, lineNumber, testMsg, epsilon);}
342 
343  void assert_equals( float expected,
344  float got,
345  int lineNumber,
346  const std::string& testMsg = std::string(),
347  float epsilon=-1)
348  {assert_equals_fp<double>(expected, got, lineNumber, testMsg, epsilon);}
349 
350  template <typename T>
351  void assert_equals_fp( const T& expected,
352  const T& got,
353  int lineNumber,
354  const std::string& testMsg = std::string(),
355  T epsilon = -1);
356 
367  template <typename T>
368  void assert_equals_fps( const T& expected,
369  const T& got,
370  int lineNumber,
371  const std::string& testMsg = std::string());
372 
373 
387  template<typename T>
388  void assert_equals( const gnsstk::Matrix<T>& expected,
389  const gnsstk::Matrix<T>& got,
390  int lineNumber,
391  const std::string& testMsg = std::string(),
392  T epsilon = -1);
393  template<typename T>
394  void assert_equals( const gnsstk::Vector<T>& expected,
395  const gnsstk::Vector<T>& got,
396  int lineNumber,
397  const std::string& testMsg = std::string(),
398  T epsilon = -1);
399 
421  void assert_files_equal( int lineNumber,
422  const std::string& file1Name,
423  const std::string& file2Name,
424  const std::string& testMsg,
425  int numLinesSkip=0,
426  bool ignoreLeadingSpaces = false,
427  bool ignoreTrailingSpaces = false,
428  std::vector<std::string> ignoreRegex = std::vector<std::string>(0) );
429 
442  void assert_binary_files_equal( int lineNumber,
443  const std::string& file1Name,
444  const std::string& file2Name,
445  const std::string& testMsg,
446  unsigned long long from = 0,
447  unsigned long long to = -1);
448 
450  int countFails( void );
451 
453  int countTests( void );
454 
458  void changeSourceMethod( const std::string& newMethod );
459 
464  void setTestMessage( const std::string& testMsg );
465 
472  void setTestMessage( const std::string& testMsg, const int lineNumber );
473 
474  void setTestLine( const int lineNumber );
475 
491  bool fileEqualTest( const std::string& refFile,
492  const std::string& checkFile,
493  int numLinesSkip=0,
494  bool ignoreLeadingSpaces = false,
495  bool ignoreTrailingSpaces = false,
496  std::vector<std::string> ignoreRegex = std::vector<std::string>(0) );
497 
503  bool fileCompTest( const std::string& refFile,
504  const std::string& checkFile,
505  unsigned long long from = 0,
506  unsigned long long to = -1);
507 
508  private:
509 
510  // The following are all used as part of the output from
511  // TestUtil::print() to facilitate filtering of output that is
512  // thus printed to stdout
513 
515  std::string outputKeyword;
517  std::string sourceClass;
519  std::string sourceMethod;
521  std::string testFileName;
523  std::string testFileLine;
524 
527  std::string testMessage;
528 
530  int failBit;
534 
535  // since single test methods may contain multiple subtests.
536 
537  int testCount;
538  int subtestID;
539  int failCount;
540 
541 
542 
547  void print( void );
548 
551  void pass( void );
552 
555  void fail( void );
556 
559  void fail( const std::string& failMsg );
560 
563  void fail( const std::string& failMsg, const int lineNumber );
564 
567  void next( void );
568 
572  void undo( void );
573  }; // class TestUtil
574 
575 
576 
578  TestUtil( const std::string& sourceClassInput,
579  const std::string& sourceMethodInput,
580  const std::string& testFileInput,
581  const int& testLineInput,
582  const int& verbosityInput )
583  : outputKeyword( "GNSSTkTest" ),
584  sourceClass( sourceClassInput ),
585  sourceMethod( sourceMethodInput ),
586  testFileName( testFileInput ),
587  testFileLine( "0" ),
588  testMessage( "Developer is a lazy slacker" ),
589  failBit( 0 ),
590  verbosity( verbosityInput ),
591  testCount( 0 ),
592  subtestID( 1 ),
593  failCount( 0 )
594  {
595  // convert int to string
596  setTestLine( testLineInput );
597 
598  // strip off the path from the full-path filename
599  // so that "/home/user/test.txt" becomes "test.txt"
600  std::string file_sep = gnsstk::getFileSep();
601  testFileName = testFileName.substr(
602  testFileName.find_last_of( file_sep ) + 1 );
603  }
604 
605 
606  void TestUtil ::
607  assert( bool testExpression,
608  const std::string& testMsg,
609  const int lineNumber )
610  {
611  setTestMessage( testMsg );
612  setTestLine( lineNumber );
613 
614  if( testExpression == false )
615  {
616  fail();
617  }
618  else
619  {
620  pass();
621  }
622 
623  print();
624  next();
625  }
626 
627 
628  template <class T>
629  void TestUtil ::
630  assert_equals( const T& expected,
631  const T& got,
632  int lineNumber,
633  const std::string& testMsg)
634  {
635  std::string mess(testMsg);
636  if (testMsg.empty())
637  {
638  std::ostringstream ostr;
639  ostr << std::boolalpha << "Expected:'" << expected << "' ,But got:'"
640  << got << "'";
641  mess = ostr.str();
642  }
643  assert(expected == got, mess, lineNumber);
644  }
645 
646 
647  template<typename T>
648  void TestUtil ::
649  assert_equals_fp( const T& expected,
650  const T& got,
651  int lineNumber,
652  const std::string& testMsg,
653  T epsilon )
654  {
655  T err = std::abs(expected - got);
656  if (epsilon < 0)
657  epsilon = std::numeric_limits<T>::epsilon();
658 
659  bool good = err <= epsilon;
660  std::string mess(testMsg);
661  if (testMsg.empty())
662  {
663  std::ostringstream ostr;
664  ostr << std::setprecision(20)
665  << "abs(" << expected << " - " << got << ") = " << err;
666  if (good)
667  ostr << " <= ";
668  else
669  ostr << " > ";
670  ostr << epsilon;
671  mess = ostr.str();
672  }
673  assert(good, mess, lineNumber);
674  }
675 
676 
677  template<typename T>
678  void TestUtil ::
679  assert_equals_fps( const T& expected,
680  const T& got,
681  int lineNumber,
682  const std::string& testMsg )
683  {
684  T err = std::abs(expected - got);
685  // exp = the exponent of expected
686  int exp = 1 + (int)std::floor(std::log10(std::fabs(expected)));
687  // digs10 = the number of decimal digits representable in type T
688  int digs10 = std::numeric_limits<decltype(got+expected)>::digits10;
689  // Make a sensible epsilon based on usable number of
690  // digits exp has after the decimal.
691  double epsilon = std::pow(10, exp-digs10);
692  assert_equals_fp(expected, got, lineNumber, testMsg, epsilon);
693  }
694 
695 
696  template<typename T>
697  void TestUtil ::
699  const gnsstk::Matrix<T>& got,
700  int lineNumber,
701  const std::string& testMsg,
702  T epsilon )
703  {
704  if (epsilon < 0)
705  epsilon = std::numeric_limits<T>::epsilon();
706 
707  std::string mess(testMsg);
708  T mag = maxabs(expected - got);
709  if (testMsg.empty())
710  {
711  std::ostringstream ostr;
712  ostr << "maxabs(expected-computed) = " << mag;
713  mess = ostr.str();
714  }
715  assert_equals(T(mag) , T(0.0), lineNumber, mess, epsilon);
716  }
717 
718 
719  template<typename T>
720  void TestUtil ::
722  const gnsstk::Vector<T>& got,
723  int lineNumber,
724  const std::string& testMsg,
725  T epsilon )
726  {
727  if (epsilon < 0)
728  epsilon = std::numeric_limits<T>::epsilon();
729  std::string mess(testMsg);
730  T mag = maxabs(expected - got);
731  if (testMsg.empty())
732  {
733  std::ostringstream ostr;
734  ostr << "absmag(expected-computed) = " << mag;
735  mess = ostr.str();
736  }
737  assert_equals(T(mag) , T(0.0), lineNumber, mess, epsilon);
738  }
739 
740  void TestUtil ::
741  assert_files_equal( int lineNumber,
742  const std::string& file1Name,
743  const std::string& file2Name,
744  const std::string& testMsg,
745  int numLinesSkip,
746  bool ignoreLeadingSpaces,
747  bool ignoreTrailingSpaces,
748  std::vector<std::string> ignoreRegex )
749  {
750  bool eq = fileEqualTest(
751  file1Name, file2Name, numLinesSkip, ignoreLeadingSpaces,
752  ignoreTrailingSpaces, ignoreRegex );
753  assert(eq, testMsg, lineNumber);
754  }
755 
756 
757  void TestUtil ::
759  const std::string& file1Name,
760  const std::string& file2Name,
761  const std::string& testMsg,
762  unsigned long long from,
763  unsigned long long to)
764  {
765  bool eq = fileCompTest(file1Name, file2Name, from, to);
766  assert(eq, testMsg, lineNumber);
767  }
768 
769 
770  int TestUtil ::
771  countFails( void )
772  {
773  return( failCount );
774  }
775 
776 
777  int TestUtil ::
778  countTests( void )
779  {
780  return( testCount );
781  }
782 
783 
784  void TestUtil ::
785  changeSourceMethod( const std::string& newMethod )
786  {
787  sourceMethod = newMethod;
788  }
789 
790 
791  void TestUtil ::
792  setTestMessage( const std::string& testMsg )
793  {
794  testMessage = testMsg;
795  }
796 
797  void TestUtil ::
798  setTestMessage( const std::string& testMsg, const int lineNumber )
799  {
800  setTestMessage( testMsg );
801  setTestLine( lineNumber );
802  }
803 
804 
805  void TestUtil ::
806  setTestLine( const int lineNumber )
807  {
808  std::ostringstream conversionStringStream;
809  conversionStringStream << lineNumber;
810  testFileLine = conversionStringStream.str();
811  }
812 
813 
814  bool TestUtil ::
815  fileEqualTest( const std::string& refFile,
816  const std::string& checkFile,
817  int numLinesSkip,
818  bool ignoreLeadingSpaces,
819  bool ignoreTrailingSpaces,
820  std::vector<std::string> ignoreRegex )
821  {
822  int lineNumber = 0;
823  bool filesEqual = false;
824  std::ifstream refStream;
825  std::ifstream checkStream;
826  std::string refLine;
827  std::string checkLine;
828 
829  refStream.open( refFile.c_str() );
830  checkStream.open( checkFile.c_str() );
831 
832  // Compare each line until you reach the end of Ref
833  while( !refStream.eof() )
834  {
835  lineNumber++;
836 
837  // If we reach the end of Check, but there is
838  // more left in Ref, then they are not equal
839  if( checkStream.eof() )
840  {
841  filesEqual = false;
842  return( filesEqual );
843  }
844 
845  // get the next line and compare
846  getline( refStream, refLine );
847  getline( checkStream, checkLine );
848 
849  if (lineNumber <= numLinesSkip)
850  continue;
851 
852  if (ignoreLeadingSpaces)
853  {
854  std::size_t idx = refLine.find_first_not_of(" \t\r\n\f\v");
855  if (idx != std::string::npos)
856  refLine.erase(0,idx-1);
857  idx = checkLine.find_first_not_of(" \t\r\n\f\v");
858  if (idx != std::string::npos)
859  checkLine.erase(0,idx-1);
860  }
861  if (ignoreTrailingSpaces)
862  {
863  std::size_t idx = refLine.find_last_not_of(" \t\r\n\f\v");
864  if (idx != std::string::npos)
865  refLine.erase(idx+1);
866  else
867  refLine.clear(); // all whitespace
868  idx = checkLine.find_last_not_of(" \t\r\n\f\v");
869  if (idx != std::string::npos)
870  checkLine.erase(idx+1);
871  else
872  checkLine.clear(); // all whitespace
873  }
874  if (!ignoreRegex.empty())
875  {
876  // check for regular expressions
877  // Use a flag because break/continue in C++ doesn't
878  // allow you to skip multiple levels.
879  bool ignore = false;
880  for (int i = 0; i < ignoreRegex.size(); i++)
881  {
882  if (gnsstk::StringUtils::isLike(refLine, ignoreRegex[i]))
883  {
884  ignore = true;
885  break;
886  }
887  }
888  if (ignore)
889  continue;
890  }
891 
892  // only fail if you find differences AFTER the skipped lines
893  if (refLine != checkLine)
894  {
895  filesEqual = false;
896  return( filesEqual );
897  }
898  }
899 
900  // If we reach the end of Ref, but there is
901  // more left in Check, then they are not equal
902  if( !checkStream.eof() )
903  {
904  filesEqual = false;
905  if (verbosity>1)
906  std::cout << "refLine:" << refLine << std::endl
907  << "checkLine:" << checkLine << std::endl;
908  return( filesEqual );
909  }
910  else
911  {
912  filesEqual = true;
913  return( filesEqual );
914  }
915  }
916 
917 
918  bool TestUtil ::
919  fileCompTest( const std::string& refFile,
920  const std::string& checkFile,
921  unsigned long long from,
922  unsigned long long to)
923  {
924  static const unsigned bufsize = 4096;
925  unsigned readsize = bufsize;
926  bool done = false;
927  std::vector<char> refBuf(bufsize, 0), checkBuf(bufsize, 0);
928  std::ifstream ref(refFile.c_str()), check(checkFile.c_str());
929  if (!ref || !check)
930  {
931  return false; // missing or inaccessible file
932  }
933  // get the file sizes
934  unsigned long long refSize, checkSize, curPos;
935  ref.seekg(0, std::ios_base::end);
936  refSize = ref.tellg();
937  check.seekg(0, std::ios_base::end);
938  checkSize = check.tellg();
939  if (refSize != checkSize)
940  {
941  return false; // files not the same size
942  }
943  // set our limit to the smaller of the file size and "to"
944  to = std::min(to, refSize);
945  if (!ref.seekg(from, std::ios_base::beg))
946  {
947  return false; // seek failure, usually file too short
948  }
949  if (!check.seekg(from, std::ios_base::beg))
950  {
951  return false; // seek failure, usually file too short
952  }
953 
954  while (!done)
955  {
956  curPos = ref.tellg();
957  // stop where requested
958  if (((curPos + readsize) > to) || (curPos > refSize))
959  {
960  readsize = 1+(to - curPos);
961  done = true;
962  }
963  ref.read(&refBuf[0], readsize);
964  check.read(&checkBuf[0], readsize);
965  if (refBuf != checkBuf)
966  {
967  return false;
968  }
969  }
970  return true;
971  }
972 
973 
974  void TestUtil ::
975  print( void )
976  {
977  // print test summary description and result to stdout
978  if( failBit==1 && verbosity >=1 )
979  {
980  std::cout
981  << outputKeyword << ", "
982  << "Class=" << sourceClass << ", "
983  << "Method=" << sourceMethod << ", "
984  << "testFile=" << testFileName << ", "
985  << "testLine=" << testFileLine << ", "
986  << "subtest=" << subtestID << ", "
987  << "failBit=" << failBit << ", "
988  << "testMsg=" << testMessage
989  << std::endl; // implicit conversion from int to string
990  }
991  else
992  {
993  std::cout
994  << outputKeyword << ", "
995  << "Class=" << sourceClass << ", "
996  << "Method=" << sourceMethod << ", "
997  << "testFile=" << testFileName << ", "
998  << "testLine=" << testFileLine << ", "
999  << "subtest=" << subtestID << ", "
1000  << "failBit=" << failBit
1001  << std::endl; // implicit conversion from int to string
1002  }
1003  }
1004 
1005 
1006  void TestUtil ::
1007  pass( void )
1008  {
1009  failBit = 0;
1010  testCount++;
1011  }
1012 
1013 
1014  void TestUtil ::
1015  fail( void )
1016  {
1017  failBit = 1;
1018  failCount++;
1019  testCount++;
1020  }
1021 
1022 
1023  void TestUtil ::
1024  fail( const std::string& failMsg )
1025  {
1026  setTestMessage( failMsg );
1027  fail();
1028  }
1029 
1030 
1031  void TestUtil ::
1032  fail( const std::string& failMsg, const int lineNumber )
1033  {
1034  setTestMessage( failMsg );
1035  setTestLine( lineNumber );
1036  fail();
1037  }
1038 
1039 
1040  void TestUtil ::
1041  next( void )
1042  {
1043  // increment subtest counter/ID
1044  subtestID = countTests() + 1;
1045 
1046  // reset fail parameters for next/new subtest
1047  failBit = 0;
1048  testMessage = "Developer is a lazy slacker";
1049  }
1050 
1051 
1052  void TestUtil ::
1053  undo( void )
1054  {
1055  if( failBit==1 )
1056  {
1057  failBit = 0;
1058  failCount--;
1059  testCount--;
1060  }
1061  else
1062  {
1063  failBit = 0;
1064  testCount--;
1065  }
1066  next();
1067  }
1068 }
1069 
1070 #endif // GNSSTK_TESTUTIL_HPP
gnsstk::TestUtil::fail
void fail(void)
Definition: TestUtil.hpp:1015
gnsstk::TestUtil::testMessage
std::string testMessage
Definition: TestUtil.hpp:527
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
gnsstk::TestUtil::setTestMessage
void setTestMessage(const std::string &testMsg)
Definition: TestUtil.hpp:792
gnsstk::typeString
std::string typeString()
Definition: TestUtil.hpp:238
StringUtils.hpp
gnsstk::TestUtil::assert_equals
void assert_equals(double expected, double got, int lineNumber, const std::string &testMsg=std::string(), double epsilon=-1)
Definition: TestUtil.hpp:329
gnsstk::TestUtil::undo
void undo(void)
Definition: TestUtil.hpp:1053
gnsstk::TestUtil::sourceMethod
std::string sourceMethod
help locate source method causing a test failure
Definition: TestUtil.hpp:519
gnsstk::TestUtil::TestUtil
TestUtil(const std::string &sourceClassInput="Unknown", const std::string &sourceMethodInput="Unknown", const std::string &testFileInput="Unknown", const int &testLineInput=0, const int &verbosityInput=1)
Definition: TestUtil.hpp:578
gnsstk::TestUtil::assert_equals_fps
void assert_equals_fps(const T &expected, const T &got, int lineNumber, const std::string &testMsg=std::string())
Definition: TestUtil.hpp:679
gnsstk::TestUtil::failBit
int failBit
store the result of a test (0=pass, 1=fail)
Definition: TestUtil.hpp:530
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::TestUtil::assert_files_equal
void assert_files_equal(int lineNumber, const std::string &file1Name, const std::string &file2Name, const std::string &testMsg, int numLinesSkip=0, bool ignoreLeadingSpaces=false, bool ignoreTrailingSpaces=false, std::vector< std::string > ignoreRegex=std::vector< std::string >(0))
Definition: TestUtil.hpp:741
gnsstk::TestUtil::failCount
int failCount
Count of tests that have failed.
Definition: TestUtil.hpp:539
gnsstk::maxabs
T maxabs(const SparseMatrix< T > &SM)
Maximum absolute value - return 0 if empty.
Definition: SparseMatrix.hpp:927
gnsstk::TestUtil::assert_equals
void assert_equals(const T &expected, const T &got, int lineNumber, const std::string &testMsg=std::string())
Definition: TestUtil.hpp:630
gnsstk::TestUtil::changeSourceMethod
void changeSourceMethod(const std::string &newMethod)
Definition: TestUtil.hpp:785
gnsstk::Matrix
Definition: Matrix.hpp:72
gnsstk::TestUtil::assert_equals
void assert_equals(float expected, float got, int lineNumber, const std::string &testMsg=std::string(), float epsilon=-1)
Definition: TestUtil.hpp:343
example4.err
err
Definition: example4.py:126
gnsstk::min
T min(const SparseMatrix< T > &SM)
Maximum element - return 0 if empty.
Definition: SparseMatrix.hpp:858
gnsstk::TestUtil::sourceClass
std::string sourceClass
help locate source class causing a test failure
Definition: TestUtil.hpp:517
gnsstk::TestUtil::print
void print(void)
Definition: TestUtil.hpp:975
gnsstk::TestUtil::setTestLine
void setTestLine(const int lineNumber)
Definition: TestUtil.hpp:806
gnsstk::TestUtil::pass
void pass(void)
Definition: TestUtil.hpp:1007
file_sep
string file_sep
Definition: Rinex3Obs_FromScratch_T.cpp:52
gnsstk::TestUtil::assert_equals
void assert_equals(long double expected, long double got, int lineNumber, const std::string &testMsg=std::string(), long double epsilon=-1)
Definition: TestUtil.hpp:336
gnsstk::Vector
Definition: Vector.hpp:67
gnsstk::TestUtil::testCount
int testCount
Count of tests that have been run.
Definition: TestUtil.hpp:537
gnsstk::TestUtil::testFileName
std::string testFileName
help locate test file that discovered a failure
Definition: TestUtil.hpp:521
gnsstk::StringUtils::isLike
bool isLike(const std::string &s, const std::string &aPattern, const char zeroOrMore=' *', const char oneOrMore='+', const char anyChar='.')
Definition: StringUtils.hpp:948
gnsstk::TestUtil::countTests
int countTests(void)
Definition: TestUtil.hpp:778
gnsstk::TestUtil::assert_binary_files_equal
void assert_binary_files_equal(int lineNumber, const std::string &file1Name, const std::string &file2Name, const std::string &testMsg, unsigned long long from=0, unsigned long long to=-1)
Definition: TestUtil.hpp:758
gnsstk::TestUtil::assert_equals_fp
void assert_equals_fp(const T &expected, const T &got, int lineNumber, const std::string &testMsg=std::string(), T epsilon=-1)
Definition: TestUtil.hpp:649
gnsstk::TestUtil::next
void next(void)
Definition: TestUtil.hpp:1041
gnsstk::TestUtil::fileEqualTest
bool fileEqualTest(const std::string &refFile, const std::string &checkFile, int numLinesSkip=0, bool ignoreLeadingSpaces=false, bool ignoreTrailingSpaces=false, std::vector< std::string > ignoreRegex=std::vector< std::string >(0))
Definition: TestUtil.hpp:815
Matrix.hpp
gnsstk::TestUtil::subtestID
int subtestID
ID of the current sub-test, used in TestUtil::print()
Definition: TestUtil.hpp:538
gnsstk::TestUtil::fileCompTest
bool fileCompTest(const std::string &refFile, const std::string &checkFile, unsigned long long from=0, unsigned long long to=-1)
Definition: TestUtil.hpp:919
gnsstk::TestUtil::testFileLine
std::string testFileLine
help locate test line where the failure occured
Definition: TestUtil.hpp:523
gnsstk::TestUtil
Definition: TestUtil.hpp:265
gnsstk::TestUtil::outputKeyword
std::string outputKeyword
Identifies a stdout line as a test record from this class.
Definition: TestUtil.hpp:515
gnsstk::TestUtil::verbosity
int verbosity
Definition: TestUtil.hpp:533


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:42