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
24 static void AreEqual(
const void* expected,
const void* actual);
25 static void AreEqual(
const char* expected,
const char* actual);
26 static void AreEqual(
const char* expected,
const String& actual);
27 static void AreEqual(
const String& expected,
const char* actual);
28 static void AreEqual(
char expected,
char actual);
29 static void AreEqual(
unsigned char expected,
unsigned char actual);
30 static void AreEqual(
float expected,
float actual,
float epsilon);
31 static void AreEqual(
double expected,
double actual,
double epsilon);
32 template<
typename... Args>
33 static void AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args);
34 template<
typename... Args>
35 static void AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args);
37 static void AreEqual(
const T& expected,
const T& actual);
38 template<
class T,
typename... Args>
39 static void AreEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args);
42 static void AreNotEqual(
float notExpected,
float actual,
float epsilon);
43 static void AreNotEqual(
double notExpected,
double actual,
double epsilon);
44 template<
typename... Args>
45 static void AreNotEqual(
float notExpected,
float actual,
float epsilon,
const char* message,
const Args& ... args);
46 template<
typename... Args>
47 static void AreNotEqual(
double notExpected,
double actual,
double epsilon,
const char* message,
const Args& ... args);
49 static void AreNotEqual(
const T& notExpected,
const T& actual);
50 template<
class T,
typename... Args>
51 static void AreNotEqual(
const T& notExpected,
const T& actual,
const char* message,
const Args& ... args);
54 template<
typename ... Args>
55 static void Error(
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>
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 ErrorInternal(
const char* message);
132 static void FailInternal(
const char* message);
135 static const char*
const areEqualDefaultMessage;
136 static const char*
const areEqualDefaultMessageIntegersInHex;
137 static const char*
const areNotEqualDefaultMessage;
138 static const char*
const isTrueDefaultMessage;
139 static const char*
const isFalseDefaultMessage;
140 static const char*
const isNullDefaultMessage;
141 static const char*
const isNotNullDefaultMessage;
142 static const char*
const isEmptyDefaultMessage;
143 static const char*
const isNotEmptyDefaultMessage;
144 static const char*
const existsDefaultMessage;
145 static const char*
const notExistsDefaultMessage;
146 static const char*
const isInstanceOfTypeDefaultMessage;
147 static const char*
const isNotInstanceOfTypeDefaultMessage;
148 static const char*
const throwsNotDefaultMessage;
149 static const char*
const throwsWrongTypeOfExceptionDefaultMessage;
156 inline void Assert::AreEqual(
const void* expected,
const void* actual)
158 if (expected ==
nullptr && actual ==
nullptr)
162 if (expected ==
nullptr && actual !=
nullptr)
164 Assert::Fail(areEqualDefaultMessageIntegersInHex, 0, actual);
167 if (expected !=
nullptr && actual ==
nullptr)
169 Assert::Fail(areEqualDefaultMessage, expected, 0);
172 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, expected, actual));
175 inline void Assert::AreEqual(
const char* expected,
const char* actual)
177 if (expected ==
nullptr && actual ==
nullptr)
181 if (expected ==
nullptr && actual !=
nullptr)
183 Assert::Fail(areEqualDefaultMessage,
"", actual);
186 if (expected !=
nullptr && actual ==
nullptr)
188 Assert::Fail(areEqualDefaultMessage, expected,
"");
191 Assert::CheckInternal(
String(expected) == actual,
String::Format(areEqualDefaultMessage, expected, actual));
194 inline void Assert::AreEqual(
const char* expected,
const String& actual)
196 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
199 inline void Assert::AreEqual(
const String& expected,
const char* actual)
201 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
204 inline void Assert::AreEqual(
char expected,
char actual)
206 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex,
static_cast<int>(expected),
static_cast<int>(actual)));
209 inline void Assert::AreEqual(
unsigned char expected,
unsigned char actual)
211 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex,
static_cast<int>(expected),
static_cast<int>(actual)));
214 inline void Assert::AreEqual(
float expected,
float actual,
float epsilon)
216 if (std::abs(actual - expected) > std::abs(epsilon))
218 Assert::FailInternal(
String::Format(areEqualDefaultMessage, expected, actual));
222 inline void Assert::AreEqual(
double expected,
double actual,
double epsilon)
224 if (std::abs(actual - expected) > std::abs(epsilon))
226 Assert::FailInternal(
String::Format(areEqualDefaultMessage, expected, actual));
230 template<
typename... Args>
231 inline void Assert::AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
233 if (std::abs(actual - expected) > std::abs(epsilon))
239 template<
typename... Args>
240 inline void Assert::AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
242 if (std::abs(actual - expected) > std::abs(epsilon))
249 inline void Assert::AreEqual(
const T& expected,
const T& actual)
251 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
254 template<
class T,
typename... Args>
255 inline void Assert::AreEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args)
257 Assert::CheckInternal(expected == actual,
String::Format(message, args...));
261 inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon)
263 if (std::abs(actual - expected) <= std::abs(epsilon))
265 Assert::FailInternal(
String::Format(areNotEqualDefaultMessage, expected, actual));
269 inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon)
271 if (std::abs(actual - expected) <= std::abs(epsilon))
273 Assert::FailInternal(
String::Format(areNotEqualDefaultMessage, expected, actual));
277 template<
typename... Args>
278 inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
280 if (std::abs(actual - expected) <= std::abs(epsilon))
286 template<
typename... Args>
287 inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
289 if (std::abs(actual - expected) <= std::abs(epsilon))
296 inline void Assert::AreNotEqual(
const T& expected,
const T& actual)
298 Assert::CheckInternal(expected != actual,
String::Format(areNotEqualDefaultMessage, expected, actual));
301 template<
class T,
typename... Args>
302 inline void Assert::AreNotEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args)
304 Assert::CheckInternal(expected != actual,
String::Format(message, args...));
308 template<
typename... Args>
309 inline void Assert::Error(
const char* message,
const Args& ... args)
315 template<
typename... Args>
316 inline void Assert::Fail(
const char* message,
const Args& ... args)
322 template<
class Predicate>
323 inline void Assert::IsTrue(Predicate predicate)
325 Assert::CheckInternal(predicate ?
true :
false, isTrueDefaultMessage);
328 template<
class Predicate,
typename... Args>
329 inline void Assert::IsTrue(Predicate predicate,
const char* message,
const Args& ... args)
331 Assert::CheckInternal(predicate ?
true :
false,
String::Format(message, args...));
335 template<
class Predicate>
336 inline void Assert::IsFalse(Predicate predicate)
338 Assert::CheckInternal(predicate ?
false :
true, isFalseDefaultMessage);
341 template<
class Predicate,
typename... Args>
342 inline void Assert::IsFalse(Predicate predicate,
const char* message,
const Args& ... args)
344 Assert::CheckInternal(predicate ?
false :
true,
String::Format(message, args...));
349 inline void Assert::IsNull(T* pValue)
351 Assert::CheckInternal(pValue ==
nullptr, isNullDefaultMessage);
354 template<
class T,
typename... Args>
355 inline void Assert::IsNull(T* pValue,
const char* message,
const Args& ... args)
357 Assert::CheckInternal(pValue ==
nullptr,
String::Format(message, args...));
362 inline void Assert::IsNotNull(T* pValue)
364 Assert::CheckInternal(pValue !=
nullptr, isNotNullDefaultMessage);
367 template<
class T,
typename... Args>
368 inline void Assert::IsNotNull(T* pValue,
const char* message,
const Args& ... args)
370 Assert::CheckInternal(pValue !=
nullptr,
String::Format(message, args...));
374 inline void Assert::IsEmpty(
const String& s)
376 Assert::CheckInternal(s.IsEmpty(), isEmptyDefaultMessage);
379 template<
typename... Args>
380 inline void Assert::IsEmpty(
const String& s,
const char* message,
const Args& ... args)
382 Assert::CheckInternal(s.IsEmpty(),
String::Format(message, args...));
386 inline void Assert::IsNotEmpty(
const String& s)
388 Assert::CheckInternal(!s.IsEmpty(), isNotEmptyDefaultMessage);
391 template<
typename... Args>
392 inline void Assert::IsNotEmpty(
const String& s,
const char* message,
const Args& ... args)
394 Assert::CheckInternal(!s.IsEmpty(),
String::Format(message, args...));
398 inline void Assert::Exists(
const String& path)
403 template<
typename... Args>
404 inline void Assert::Exists(
const String& path,
const char* message,
const Args& ... args)
410 inline void Assert::NotExists(
const String& path)
415 template<
typename... Args>
416 inline void Assert::NotExists(
const String& path,
const char* message,
const Args& ... args)
422 template<
class TExpected,
class T>
423 inline void Assert::IsInstanceOfType(
const T& instance)
425 if (!Arp::IsInstanceOfType<TExpected>(instance))
431 template<
class TExpected,
class T,
typename... Args>
432 inline void Assert::IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
434 if (!Arp::IsInstanceOfType<TExpected>(instance))
440 template<
class TExpected,
class T>
441 inline void Assert::IsInstanceOfType(
const T* pInstance)
443 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
445 Assert::FailInternal(
String::Format(isInstanceOfTypeDefaultMessage, TypeName<TExpected>().Value));
449 template<
class TExpected,
class T,
typename... Args>
450 inline void Assert::IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
452 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
459 template<
class TExpected,
class T>
460 inline void Assert::IsNotInstanceOfType(
const T& instance)
462 if (Arp::IsInstanceOfType<TExpected>(instance))
464 Assert::FailInternal(
String::Format(isNotInstanceOfTypeDefaultMessage, TypeName<TExpected>().Value));
468 template<
class TExpected,
class T,
typename... Args>
469 inline void Assert::IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
471 if (Arp::IsInstanceOfType<TExpected>(instance))
477 template<
class TExpected,
class T>
478 inline void Assert::IsNotInstanceOfType(
const T* pInstance)
480 if (Arp::IsInstanceOfType<TExpected>(pInstance))
482 Assert::FailInternal(
String::Format(isNotInstanceOfTypeDefaultMessage, TypeName<TExpected>().Value));
486 template<
class TExpected,
class T,
typename... Args>
487 inline void Assert::IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
489 if (IsInstanceOfType<TExpected>(pInstance))
496 template<
typename TException,
typename TFunction>
497 inline void Assert::Throws(TFunction&& func)
499 Assert::Throws<TException>(
nullptr, std::forward<TFunction>(func));
502 #pragma warning (disable:4715)
504 template<
typename TException,
typename TFunction>
505 inline void Assert::Throws(
const char* message, TFunction&& func)
511 catch (
const TException&)
518 if (message ==
nullptr)
520 Assert::FailInternal(throwsWrongTypeOfExceptionDefaultMessage);
524 Assert::FailInternal(message);
528 if (message ==
nullptr)
530 Assert::FailInternal(
String::Format(throwsNotDefaultMessage, TypeName<TException>().Value));
534 Assert::FailInternal(message);
static bool Exists(const String &path)
Checks for existence of a file.
Static assertion class for easy use in unit tests.
Definition: Assert.hpp:18
This (meta programming) class provides the C++ typename of the as template argument passed type.
Definition: TypeName.hxx:56
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:1483
bool IsInstanceOfType(const TInstance &instance)
Tests if the type of the as argument passed instance is T or derived by T .
Definition: TypeDeduction.hxx:26
Arp::BasicString< char8 > String
The Arp String class.
Definition: TypeSystem.h:27
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API