AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
agxUnit.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
27
28#include <agx/Math.h>
29#include <agx/Vec3.h>
30#include <sstream>
31#include <agxUnit/unitAssert.h>
32
33namespace agxIO
34{
35 class ArgumentParser;
36}
37
42namespace agxUnit
43{
44 class AGXPHYSICS_EXPORT UnitTestManager// : agx::Singleton
45 {
46 public:
47 UnitTestManager();
48
49 static UnitTestManager *instance();
50
51 void shutdown();
52
53 void parseArgs( agxIO::ArgumentParser* arguments );
54 void parseArgs(int& argc, char **argv );
55
57 bool reportError( const AssertMessage &message, const SourceCodeInfo& info );
58
59 void setEnable( bool flag ) { m_enable = flag; }
60 bool getEnable( ) const { return m_enable; }
61
62 bool getIsDeterminismTest() const { return m_determinismTest; }
63
64 void setDoOnlyFastTests( bool flag ) { m_doOnlyFastTests = flag; }
65 bool getDoOnlyFastTests( ) const { return m_doOnlyFastTests; }
66
67 void setPassOnExceptions( bool flag ) { m_passOnExceptions = flag; }
68 bool getPassOnExceptions( ) const { return m_passOnExceptions; }
69
70 ~UnitTestManager();
71
72 //SINGLETON_CLASSNAME_METHOD();
73
74
75 protected:
76
77
78 bool m_enable;
79 bool m_doOnlyFastTests;
80 bool m_passOnExceptions;
81 bool m_determinismTest;
82 };
83
84 template <class T>
85 struct agxAssertion_utils
86 {
87
88
89 static bool equal(const T& a, const T&b)
90 {
91 return (a == b);
92 }
93
94 static agx::String toString( const T& x )
95 {
96 std::ostringstream ost;
97 ost << x;
98 return ost.str();
99 }
100 };
101
102
111 template <>
112 struct agxAssertion_utils<double>
113 {
114 static bool equal(double a, double b)
115 {
116 return (a == b);
117 }
118
119 static agx::String toString( double x )
120 {
121 std::ostringstream str;
122
123#ifdef DBL_DIG
124 const int precision = DBL_DIG;
125#else
126 const int precision = 15;
127#endif
128 str.precision( precision );
129 str << x;
130 return str.str();
131 }
132 };
133
134 template <typename T>
135 void agxAssertEquals( const T& expected,
136 const T& actual,
137 SourceCodeInfo info,
138 const agx::String &message = "" )
139 {
140 if ( !agxAssertion_utils<T>::equal(expected, actual ))
141 {
142 Assert::failNotEqual( agxAssertion_utils<T>::toString(expected),
143 agxAssertion_utils<T>::toString(actual),
144 info,
145 message );
146 }
147 }
148
154 void AGXPHYSICS_EXPORT agxAssertDoubleNotEquals( double expected,
155 double actual,
156 double delta,
157 SourceCodeInfo sourceLine,
158 const agx::String &message );
159
160
166 void AGXPHYSICS_EXPORT agxAssertDoubleEquals( double expected,
167 double actual,
168 double delta,
169 SourceCodeInfo sourceLine,
170 const agx::String &message );
171
172
179 void AGXPHYSICS_EXPORT agxAssertVec3sEqual(
180 const agx::Vec3& expected,
181 const agx::Vec3& actual,
182 double delta,
183 SourceCodeInfo sourceInfo,
184 const agx::String& message);
185
192 void AGXPHYSICS_EXPORT agxAssertVec3sNotEqual(
193 const agx::Vec3& expected,
194 const agx::Vec3& actual,
195 double delta,
196 SourceCodeInfo sourceInfo,
197 const agx::String& message);
198} // agxUnit namespace
199
200#else
201#endif // AGX_USE_UNIT_TESTS()
202
203#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 of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...