8 #include "Arp/System/Core/TypeName.hxx" 9 #include "Arp/System/Commons/Io/File.hpp" 10 #include <boost/test/unit_test.hpp> 13 namespace Arp {
namespace System {
namespace Commons {
namespace Testing
26 static void AreEqual(
const void* expected,
const void* actual);
27 static void AreEqual(
const char* expected,
const char* actual);
28 static void AreEqual(
const char* expected,
const String& actual);
29 static void AreEqual(
const String& expected,
const char* actual);
30 static void AreEqual(
char expected,
char actual);
31 static void AreEqual(
unsigned char expected,
unsigned char actual);
32 static void AreEqual(
float expected,
float actual,
float epsilon);
33 static void AreEqual(
double expected,
double actual,
double epsilon);
34 template<
typename... Args>
35 static void AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args);
36 template<
typename... Args>
37 static void AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args);
39 static void AreEqual(
const T& expected,
const T& actual);
40 template<
class T,
typename... Args>
41 static void AreEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args);
44 static void AreNotEqual(
float notExpected,
float actual,
float epsilon);
45 static void AreNotEqual(
double notExpected,
double actual,
double epsilon);
46 template<
typename... Args>
47 static void AreNotEqual(
float notExpected,
float actual,
float epsilon,
const char* message,
const Args& ... args);
48 template<
typename... Args>
49 static void AreNotEqual(
double notExpected,
double actual,
double epsilon,
const char* message,
const Args& ... args);
51 static void AreNotEqual(
const T& notExpected,
const T& actual);
52 template<
class T,
typename... Args>
53 static void AreNotEqual(
const T& notExpected,
const T& actual,
const char* message,
const Args& ... args);
56 template<
typename ... Args>
57 static void Fail(
const char* message,
const Args& ... args);
60 template<
class Predicate>
61 static void IsTrue(Predicate predicate);
62 template<
class Predicate,
typename... Args>
63 static void IsTrue(Predicate predicate,
const char* message,
const Args& ... args);
66 template<
class Predicate>
67 static void IsFalse(Predicate predicate);
68 template<
class Predicate,
typename... Args>
69 static void IsFalse(Predicate predicate,
const char* message,
const Args& ... args);
73 static void IsNull(T* pValue);
74 template<
class T,
typename... Args>
75 static void IsNull(T* pValue,
const char* message,
const Args& ... args);
79 static void IsNotNull(T* pValue);
80 template<
class T,
typename... Args>
81 static void IsNotNull(T* pValue,
const char* message,
const Args& ... args);
84 static void IsEmpty(
const String& s);
85 template<
typename... Args>
86 static void IsEmpty(
const String& s,
const char* message,
const Args& ... args);
89 static void IsNotEmpty(
const String& s);
90 template<
typename... Args>
91 static void IsNotEmpty(
const String& s,
const char* message,
const Args& ... args);
94 static void Exists(
const String& path);
95 template<
typename... Args>
96 static void Exists(
const String& path,
const char* message,
const Args& ... args);
99 static void NotExists(
const String& path);
100 template<
typename... Args>
101 static void NotExists(
const String& path,
const char* message,
const Args& ... args);
104 template<
class TExpected,
class T>
105 static void IsInstanceOfType(
const T& instance);
106 template<
class TExpected,
class T,
typename... Args>
107 static void IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args);
108 template<
class TExpected,
class T>
109 static void IsInstanceOfType(
const T* pInstance);
110 template<
class TExpected,
class T,
typename... Args>
111 static void IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args);
114 template<
class TExpected,
class T>
115 static void IsNotInstanceOfType(
const T& instance);
116 template<
class TExpected,
class T,
typename... Args>
117 static void IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args);
118 template<
class TExpected,
class T>
119 static void IsNotInstanceOfType(
const T* pInstance);
120 template<
class TExpected,
class T,
typename... Args>
121 static void IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args);
124 template<
typename TException,
typename TFunction>
125 static void Throws(TFunction&& func);
126 template<
typename TException,
typename TFunction>
127 static void Throws(
const char* message, TFunction&& func);
130 static void CheckInternal(
bool predicate,
const char* message);
131 static void FailInternal(
const char* message);
134 static const char*
const areEqualDefaultMessage;
135 static const char*
const areEqualDefaultMessageIntegersInHex;
136 static const char*
const areNotEqualDefaultMessage;
137 static const char*
const isTrueDefaultMessage;
138 static const char*
const isFalseDefaultMessage;
139 static const char*
const isNullDefaultMessage;
140 static const char*
const isNotNullDefaultMessage;
141 static const char*
const isEmptyDefaultMessage;
142 static const char*
const isNotEmptyDefaultMessage;
143 static const char*
const existsDefaultMessage;
144 static const char*
const notExistsDefaultMessage;
145 static const char*
const isInstanceOfTypeDefaultMessage;
146 static const char*
const isNotInstanceOfTypeDefaultMessage;
147 static const char*
const throwsNotDefaultMessage;
148 static const char*
const throwsWrongTypeOfExceptionDefaultMessage;
155 inline void Assert::AreEqual(
const void* expected,
const void* actual)
157 if (expected ==
nullptr && actual ==
nullptr)
161 if (expected ==
nullptr && actual !=
nullptr)
163 Assert::Fail(areEqualDefaultMessageIntegersInHex, 0, actual);
166 if (expected !=
nullptr && actual ==
nullptr)
168 Assert::Fail(areEqualDefaultMessage, expected, 0);
171 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, expected, actual));
174 inline void Assert::AreEqual(
const char* expected,
const char* actual)
176 if (expected ==
nullptr && actual ==
nullptr)
180 if (expected ==
nullptr && actual !=
nullptr)
182 Assert::Fail(areEqualDefaultMessage,
"", actual);
185 if (expected !=
nullptr && actual ==
nullptr)
187 Assert::Fail(areEqualDefaultMessage, expected,
"");
190 Assert::CheckInternal(
String(expected) == actual,
String::Format(areEqualDefaultMessage, expected, actual));
193 inline void Assert::AreEqual(
const char* expected,
const String& actual)
195 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
198 inline void Assert::AreEqual(
const String& expected,
const char* actual)
200 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
203 inline void Assert::AreEqual(
char expected,
char actual)
205 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, static_cast<int>(expected), static_cast<int>(actual)));
208 inline void Assert::AreEqual(
unsigned char expected,
unsigned char actual)
210 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, static_cast<int>(expected), static_cast<int>(actual)));
213 inline void Assert::AreEqual(
float expected,
float actual,
float epsilon)
215 if (std::abs(actual - expected) > std::abs(epsilon))
217 Assert::FailInternal(
String::Format(areEqualDefaultMessage, expected, actual));
221 inline void Assert::AreEqual(
double expected,
double actual,
double epsilon)
223 if (std::abs(actual - expected) > std::abs(epsilon))
225 Assert::FailInternal(
String::Format(areEqualDefaultMessage, expected, actual));
229 template<
typename... Args>
230 inline void Assert::AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
232 if (std::abs(actual - expected) > std::abs(epsilon))
238 template<
typename... Args>
239 inline void Assert::AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
241 if (std::abs(actual - expected) > std::abs(epsilon))
248 inline void Assert::AreEqual(
const T& expected,
const T& actual)
250 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
253 template<
class T,
typename... Args>
254 inline void Assert::AreEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args)
256 Assert::CheckInternal(expected == actual,
String::Format(message, args...));
260 inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon)
262 if (std::abs(actual - expected) <= std::abs(epsilon))
264 Assert::FailInternal(
String::Format(areNotEqualDefaultMessage, expected, actual));
268 inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon)
270 if (std::abs(actual - expected) <= std::abs(epsilon))
272 Assert::FailInternal(
String::Format(areNotEqualDefaultMessage, expected, actual));
276 template<
typename... Args>
277 inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
279 if (std::abs(actual - expected) <= std::abs(epsilon))
285 template<
typename... Args>
286 inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
288 if (std::abs(actual - expected) <= std::abs(epsilon))
295 inline void Assert::AreNotEqual(
const T& expected,
const T& actual)
297 Assert::CheckInternal(expected != actual,
String::Format(areNotEqualDefaultMessage, expected, actual));
300 template<
class T,
typename... Args>
301 inline void Assert::AreNotEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args)
303 Assert::CheckInternal(expected != actual,
String::Format(message, args...));
307 template<
typename... Args>
308 inline void Assert::Fail(
const char* message,
const Args& ... args)
314 template<
class Predicate>
315 inline void Assert::IsTrue(Predicate predicate)
317 Assert::CheckInternal(predicate ?
true :
false, isTrueDefaultMessage);
320 template<
class Predicate,
typename... Args>
321 inline void Assert::IsTrue(Predicate predicate,
const char* message,
const Args& ... args)
323 Assert::CheckInternal(predicate ?
true :
false,
String::Format(message, args...));
327 template<
class Predicate>
328 inline void Assert::IsFalse(Predicate predicate)
330 Assert::CheckInternal(predicate ?
false :
true, isFalseDefaultMessage);
333 template<
class Predicate,
typename... Args>
334 inline void Assert::IsFalse(Predicate predicate,
const char* message,
const Args& ... args)
336 Assert::CheckInternal(predicate ?
false :
true,
String::Format(message, args...));
341 inline void Assert::IsNull(T* pValue)
343 Assert::CheckInternal(pValue ==
nullptr, isNullDefaultMessage);
346 template<
class T,
typename... Args>
347 inline void Assert::IsNull(T* pValue,
const char* message,
const Args& ... args)
349 Assert::CheckInternal(pValue ==
nullptr,
String::Format(message, args...));
354 inline void Assert::IsNotNull(T* pValue)
356 Assert::CheckInternal(pValue !=
nullptr, isNotNullDefaultMessage);
359 template<
class T,
typename... Args>
360 inline void Assert::IsNotNull(T* pValue,
const char* message,
const Args& ... args)
362 Assert::CheckInternal(pValue !=
nullptr,
String::Format(message, args...));
366 inline void Assert::IsEmpty(
const String& s)
368 Assert::CheckInternal(s.
IsEmpty(), isEmptyDefaultMessage);
371 template<
typename... Args>
372 inline void Assert::IsEmpty(
const String& s,
const char* message,
const Args& ... args)
378 inline void Assert::IsNotEmpty(
const String& s)
380 Assert::CheckInternal(!s.
IsEmpty(), isNotEmptyDefaultMessage);
383 template<
typename... Args>
384 inline void Assert::IsNotEmpty(
const String& s,
const char* message,
const Args& ... args)
390 inline void Assert::Exists(
const String& path)
395 template<
typename... Args>
396 inline void Assert::Exists(
const String& path,
const char* message,
const Args& ... args)
402 inline void Assert::NotExists(
const String& path)
407 template<
typename... Args>
408 inline void Assert::NotExists(
const String& path,
const char* message,
const Args& ... args)
414 template<
class TExpected,
class T>
415 inline void Assert::IsInstanceOfType(
const T& instance)
417 if (!Arp::IsInstanceOfType<TExpected>(instance))
423 template<
class TExpected,
class T,
typename... Args>
424 inline void Assert::IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
426 if (!Arp::IsInstanceOfType<TExpected>(instance))
432 template<
class TExpected,
class T>
433 inline void Assert::IsInstanceOfType(
const T* pInstance)
435 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
441 template<
class TExpected,
class T,
typename... Args>
442 inline void Assert::IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
444 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
451 template<
class TExpected,
class T>
452 inline void Assert::IsNotInstanceOfType(
const T& instance)
454 if (Arp::IsInstanceOfType<TExpected>(instance))
460 template<
class TExpected,
class T,
typename... Args>
461 inline void Assert::IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
463 if (Arp::IsInstanceOfType<TExpected>(instance))
469 template<
class TExpected,
class T>
470 inline void Assert::IsNotInstanceOfType(
const T* pInstance)
472 if (Arp::IsInstanceOfType<TExpected>(pInstance))
478 template<
class TExpected,
class T,
typename... Args>
479 inline void Assert::IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
481 if (IsInstanceOfType<TExpected>(pInstance))
488 template<
typename TException,
typename TFunction>
489 inline void Assert::Throws(TFunction&& func)
491 Assert::Throws<TException>(
nullptr, std::forward<TFunction>(func));
494 #pragma warning (disable:4715) 496 template<
typename TException,
typename TFunction>
497 inline void Assert::Throws(
const char* message, TFunction&& func)
503 catch (
const TException&)
510 if (message ==
nullptr)
512 Assert::FailInternal(throwsWrongTypeOfExceptionDefaultMessage);
516 Assert::FailInternal(message);
520 if (message ==
nullptr)
526 Assert::FailInternal(message);
static bool Exists(const String &path)
Checks for existence of a file.
This (meta programming) class provides the C++ typename of the as template argument passed type...
Definition: TypeName.hxx:55
bool IsEmpty() const
Determines if this string is empty.
Definition: BasicString.hxx:1074
static SelfType Format(const SelfType &format, const Args &... args)
Formats the format string using the .NET/Python syntax with the given variadic arguments.
Definition: BasicString.hxx:1457
Root namespace for the PLCnext API
Static assertion class for easy use in unit tests.
Definition: Assert.hpp:17
System components used by the System, Device, Plc or Io domains.