AGX Dynamics  2.35.0.1
agxUnit.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXUNIT_AGXUNIT_H
18 #define AGXUNIT_AGXUNIT_H
19 
20 #include <agx/config/AGX_USE_UNIT_TESTS.h>
21 #if AGX_USE_UNIT_TESTS()
22 
23 #include <typeinfo>
24 
25 #include <agx/agxPhysics_export.h>
26 #include <agxUnit/SourceCodeInfo.h>
27 
28 #include <agx/Math.h>
29 #include <sstream>
30 #include <agxUnit/unitAssert.h>
31 
32 namespace agxIO
33 {
34  class ArgumentParser;
35 }
36 
41 namespace agxUnit
42 {
43  class AGXPHYSICS_EXPORT UnitTestManager// : agx::Singleton
44  {
45  public:
46  UnitTestManager();
47 
48  static UnitTestManager *instance();
49 
50  void shutdown();
51 
52  void parseArgs( agxIO::ArgumentParser* arguments );
53  void parseArgs(int& argc, char **argv );
54 
56  bool reportError( const AssertMessage &message, const SourceCodeInfo& info );
57 
58  void setEnable( bool flag ) { m_enable = flag; }
59  bool getEnable( ) const { return m_enable; }
60 
61  void setDoOnlyFastTests( bool flag ) { m_doOnlyFastTests = flag; }
62  bool getDoOnlyFastTests( ) const { return m_doOnlyFastTests; }
63 
64  void setPassOnExceptions( bool flag ) { m_passOnExceptions = flag; }
65  bool getPassOnExceptions( ) const { return m_passOnExceptions; }
66 
67  ~UnitTestManager();
68 
69  //SINGLETON_CLASSNAME_METHOD();
70 
71 
72  protected:
73 
74 
75  bool m_enable;
76  bool m_doOnlyFastTests;
77  bool m_passOnExceptions;
78  };
79 
80  template <class T>
81  struct agxAssertion_utils
82  {
83 
84 
85  static bool equal(const T& a, const T&b)
86  {
87  return (a == b);
88  }
89 
90  static agx::String toString( const T& x )
91  {
92  std::ostringstream ost;
93  ost << x;
94  return ost.str();
95  }
96  };
97 
98 
107  template <>
108  struct agxAssertion_utils<double>
109  {
110  static bool equal(double a, double b)
111  {
112  return (a == b);
113  }
114 
115  static agx::String toString( double x )
116  {
117  std::ostringstream str;
118 
119 #ifdef DBL_DIG
120  const int precision = DBL_DIG;
121 #else
122  const int precision = 15;
123 #endif
124  str.precision( precision );
125  str << x;
126  return str.str();
127  }
128  };
129 
130  template <typename T>
131  void agxAssertEquals( const T& expected,
132  const T& actual,
133  SourceCodeInfo info,
134  const agx::String &message = "" )
135  {
136  if ( !agxAssertion_utils<T>::equal(expected, actual ))
137  {
138  Assert::failNotEqual( agxAssertion_utils<T>::toString(expected),
139  agxAssertion_utils<T>::toString(actual),
140  info,
141  message );
142  }
143  }
144 
150  void AGXPHYSICS_EXPORT agxAssertDoubleNotEquals( double expected,
151  double actual,
152  double delta,
153  SourceCodeInfo sourceLine,
154  const agx::String &message );
155 
156 
162  void AGXPHYSICS_EXPORT agxAssertDoubleEquals( double expected,
163  double actual,
164  double delta,
165  SourceCodeInfo sourceLine,
166  const agx::String &message );
167 
168 } // agxUnit namespace
169 
170 #else
171 #endif // AGX_USE_UNIT_TESTS()
172 
173 #endif // AGXUNIT_AGXUNIT_H
#define AGXPHYSICS_EXPORT
A small argument parser class.
The agxIO namespace contains classes for reading, writing and finding files.
Definition: Material.h:42
void AGXPHYSICS_EXPORT shutdown()
Shutdown agx.