8 #include "Arp/System/Core/TypeName.hxx" 9 #include "boost/test/unit_test.hpp" 10 #include "Arp/System/Commons/Io/File.hpp" 14 namespace Arp {
namespace System {
namespace Commons {
namespace Testing
27 static void AreEqual(
const void* expected,
const void* actual);
28 static void AreEqual(
const char* expected,
const char* actual);
29 static void AreEqual(
const char* expected,
const String& actual);
30 static void AreEqual(
const String& expected,
const char* actual);
31 static void AreEqual(
char expected,
char actual);
32 static void AreEqual(
unsigned char expected,
unsigned char actual);
33 static void AreEqual(
float expected,
float actual,
float epsilon);
34 static void AreEqual(
double expected,
double actual,
double epsilon);
35 template<
typename... Args>
36 static void AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args);
37 template<
typename... Args>
38 static void AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args);
40 static void AreEqual(
const T& expected,
const T& actual);
41 template<
class T,
typename... Args>
42 static void AreEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args);
45 static void AreNotEqual(
float notExpected,
float actual,
float epsilon);
46 static void AreNotEqual(
double notExpected,
double actual,
double epsilon);
47 template<
typename... Args>
48 static void AreNotEqual(
float notExpected,
float actual,
float epsilon,
const char* message,
const Args& ... args);
49 template<
typename... Args>
50 static void AreNotEqual(
double notExpected,
double actual,
double epsilon,
const char* message,
const Args& ... args);
52 static void AreNotEqual(
const T& notExpected,
const T& actual);
53 template<
class T,
typename... Args>
54 static void AreNotEqual(
const T& notExpected,
const T& actual,
const char* message,
const Args& ... args);
57 template<
typename ... Args>
58 static void Fail(
const char* message,
const Args& ... args);
61 template<
class Predicate>
62 static void IsTrue(Predicate predicate);
63 template<
class Predicate,
typename... Args>
64 static void IsTrue(Predicate predicate,
const char* message,
const Args& ... args);
67 template<
class Predicate>
68 static void IsFalse(Predicate predicate);
69 template<
class Predicate,
typename... Args>
70 static void IsFalse(Predicate predicate,
const char* message,
const Args& ... args);
74 static void IsNull(T* pValue);
75 template<
class T,
typename... Args>
76 static void IsNull(T* pValue,
const char* message,
const Args& ... args);
80 static void IsNotNull(T* pValue);
81 template<
class T,
typename... Args>
82 static void IsNotNull(T* pValue,
const char* message,
const Args& ... args);
85 static void IsEmpty(
const String& s);
86 template<
typename... Args>
87 static void IsEmpty(
const String& s,
const char* message,
const Args& ... args);
90 static void IsNotEmpty(
const String& s);
91 template<
typename... Args>
92 static void IsNotEmpty(
const String& s,
const char* message,
const Args& ... args);
95 static void Exists(
const String& path);
96 template<
typename... Args>
97 static void Exists(
const String& path,
const char* message,
const Args& ... args);
100 static void NotExists(
const String& path);
101 template<
typename... Args>
102 static void NotExists(
const String& path,
const char* message,
const Args& ... args);
105 template<
class TExpected,
class T>
106 static void IsInstanceOfType(
const T& instance);
107 template<
class TExpected,
class T,
typename... Args>
108 static void IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args);
109 template<
class TExpected,
class T>
110 static void IsInstanceOfType(
const T* pInstance);
111 template<
class TExpected,
class T,
typename... Args>
112 static void IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args);
115 template<
class TExpected,
class T>
116 static void IsNotInstanceOfType(
const T& instance);
117 template<
class TExpected,
class T,
typename... Args>
118 static void IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args);
119 template<
class TExpected,
class T>
120 static void IsNotInstanceOfType(
const T* pInstance);
121 template<
class TExpected,
class T,
typename... Args>
122 static void IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args);
125 template<
typename TException,
typename TFunction>
126 static void Throws(TFunction&& func);
127 template<
typename TException,
typename TFunction>
128 static void Throws(
const char* message, TFunction&& func);
131 static const char*
const areEqualDefaultMessage;
132 static const char*
const areEqualDefaultMessageIntegersInHex;
133 static const char*
const areNotEqualDefaultMessage;
134 static const char*
const isTrueDefaultMessage;
135 static const char*
const isFalseDefaultMessage;
136 static const char*
const isNullDefaultMessage;
137 static const char*
const isNotNullDefaultMessage;
138 static const char*
const isEmptyDefaultMessage;
139 static const char*
const isNotEmptyDefaultMessage;
140 static const char*
const existsDefaultMessage;
141 static const char*
const notExistsDefaultMessage;
142 static const char*
const isInstanceOfTypeDefaultMessage;
143 static const char*
const isNotInstanceOfTypeDefaultMessage;
144 static const char*
const throwsNotDefaultMessage;
145 static const char*
const throwsWrongTypeOfExceptionDefaultMessage;
152 inline void Assert::AreEqual(
const void* expected,
const void* actual)
154 if (expected ==
nullptr && actual ==
nullptr)
158 if (expected ==
nullptr && actual !=
nullptr)
160 Assert::Fail(areEqualDefaultMessageIntegersInHex, 0, actual);
163 if (expected !=
nullptr && actual ==
nullptr)
165 Assert::Fail(areEqualDefaultMessage, expected, 0);
168 BOOST_CHECK_MESSAGE(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, expected, actual));
171 inline void Assert::AreEqual(
const char* expected,
const char* actual)
173 if (expected ==
nullptr && actual ==
nullptr)
177 if (expected ==
nullptr && actual !=
nullptr)
179 Assert::Fail(areEqualDefaultMessage,
"", actual);
182 if (expected !=
nullptr && actual ==
nullptr)
184 Assert::Fail(areEqualDefaultMessage, expected,
"");
187 BOOST_CHECK_MESSAGE(
String(expected) == actual,
String::Format(areEqualDefaultMessage, expected, actual));
190 inline void Assert::AreEqual(
const char* expected,
const String& actual)
192 BOOST_CHECK_MESSAGE(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
195 inline void Assert::AreEqual(
const String& expected,
const char* actual)
197 BOOST_CHECK_MESSAGE(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
200 inline void Assert::AreEqual(
char expected,
char actual)
202 BOOST_CHECK_MESSAGE(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, static_cast<int>(expected), static_cast<int>(actual)));
205 inline void Assert::AreEqual(
unsigned char expected,
unsigned char actual)
207 BOOST_CHECK_MESSAGE(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, static_cast<int>(expected), static_cast<int>(actual)));
210 inline void Assert::AreEqual(
float expected,
float actual,
float epsilon)
212 if (std::abs(actual - expected) > std::abs(epsilon))
214 BOOST_FAIL(
String::Format(areEqualDefaultMessage, expected, actual));
218 inline void Assert::AreEqual(
double expected,
double actual,
double epsilon)
220 if (std::abs(actual - expected) > std::abs(epsilon))
222 BOOST_FAIL(
String::Format(areEqualDefaultMessage, expected, actual));
226 template<
typename... Args>
227 inline void Assert::AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
229 if (std::abs(actual - expected) > std::abs(epsilon))
235 template<
typename... Args>
236 inline void Assert::AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
238 if (std::abs(actual - expected) > std::abs(epsilon))
245 inline void Assert::AreEqual(
const T& expected,
const T& actual)
247 BOOST_CHECK_MESSAGE(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
250 template<
class T,
typename... Args>
251 inline void Assert::AreEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args)
253 BOOST_CHECK_MESSAGE(expected == actual,
String::Format(message, args...));
257 inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon)
259 if (std::abs(actual - expected) <= std::abs(epsilon))
261 BOOST_FAIL(
String::Format(areNotEqualDefaultMessage, expected, actual));
265 inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon)
267 if (std::abs(actual - expected) <= std::abs(epsilon))
269 BOOST_FAIL(
String::Format(areNotEqualDefaultMessage, expected, actual));
273 template<
typename... Args>
274 inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
276 if (std::abs(actual - expected) <= std::abs(epsilon))
282 template<
typename... Args>
283 inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
285 if (std::abs(actual - expected) <= std::abs(epsilon))
292 inline void Assert::AreNotEqual(
const T& expected,
const T& actual)
294 BOOST_CHECK_MESSAGE(expected != actual,
String::Format(areNotEqualDefaultMessage, expected, actual));
297 template<
class T,
typename... Args>
298 inline void Assert::AreNotEqual(
const T& expected,
const T& actual,
const char* message,
const Args& ... args)
300 BOOST_CHECK_MESSAGE(expected != actual,
String::Format(message, args...));
304 template<
typename... Args>
305 inline void Assert::Fail(
const char* message,
const Args& ... args)
311 template<
class Predicate>
312 inline void Assert::IsTrue(Predicate predicate)
314 BOOST_CHECK_MESSAGE(predicate, isTrueDefaultMessage);
317 template<
class Predicate,
typename... Args>
318 inline void Assert::IsTrue(Predicate predicate,
const char* message,
const Args& ... args)
324 template<
class Predicate>
325 inline void Assert::IsFalse(Predicate predicate)
327 BOOST_CHECK_MESSAGE(!predicate, isFalseDefaultMessage);
330 template<
class Predicate,
typename... Args>
331 inline void Assert::IsFalse(Predicate predicate,
const char* message,
const Args& ... args)
333 BOOST_CHECK_MESSAGE(!predicate,
String::Format(message, args...));
338 inline void Assert::IsNull(T* pValue)
340 BOOST_CHECK_MESSAGE(pValue ==
nullptr, isNullDefaultMessage);
343 template<
class T,
typename... Args>
344 inline void Assert::IsNull(T* pValue,
const char* message,
const Args& ... args)
346 BOOST_CHECK_MESSAGE(pValue ==
nullptr,
String::Format(message, args...));
351 inline void Assert::IsNotNull(T* pValue)
353 BOOST_CHECK_MESSAGE(pValue !=
nullptr, isNotNullDefaultMessage);
356 template<
class T,
typename... Args>
357 inline void Assert::IsNotNull(T* pValue,
const char* message,
const Args& ... args)
359 BOOST_CHECK_MESSAGE(pValue !=
nullptr,
String::Format(message, args...));
363 inline void Assert::IsEmpty(
const String& s)
365 BOOST_CHECK_MESSAGE(s.
IsEmpty(), isEmptyDefaultMessage);
368 template<
typename... Args>
369 inline void Assert::IsEmpty(
const String& s,
const char* message,
const Args& ... args)
375 inline void Assert::IsNotEmpty(
const String& s)
377 BOOST_CHECK_MESSAGE(!s.
IsEmpty(), isNotEmptyDefaultMessage);
380 template<
typename... Args>
381 inline void Assert::IsNotEmpty(
const String& s,
const char* message,
const Args& ... args)
387 inline void Assert::Exists(
const String& path)
392 template<
typename... Args>
393 inline void Assert::Exists(
const String& path,
const char* message,
const Args& ... args)
399 inline void Assert::NotExists(
const String& path)
404 template<
typename... Args>
405 inline void Assert::NotExists(
const String& path,
const char* message,
const Args& ... args)
411 template<
class TExpected,
class T>
412 inline void Assert::IsInstanceOfType(
const T& instance)
414 if (!Arp::IsInstanceOfType<TExpected>(instance))
420 template<
class TExpected,
class T,
typename... Args>
421 inline void Assert::IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
423 if (!Arp::IsInstanceOfType<TExpected>(instance))
429 template<
class TExpected,
class T>
430 inline void Assert::IsInstanceOfType(
const T* pInstance)
432 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
438 template<
class TExpected,
class T,
typename... Args>
439 inline void Assert::IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
441 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
448 template<
class TExpected,
class T>
449 inline void Assert::IsNotInstanceOfType(
const T& instance)
451 if (Arp::IsInstanceOfType<TExpected>(instance))
457 template<
class TExpected,
class T,
typename... Args>
458 inline void Assert::IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
460 if (Arp::IsInstanceOfType<TExpected>(instance))
466 template<
class TExpected,
class T>
467 inline void Assert::IsNotInstanceOfType(
const T* pInstance)
469 if (Arp::IsInstanceOfType<TExpected>(pInstance))
475 template<
class TExpected,
class T,
typename... Args>
476 inline void Assert::IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
478 if (IsInstanceOfType<TExpected>(pInstance))
485 template<
typename TException,
typename TFunction>
486 inline void Assert::Throws(TFunction&& func)
488 Assert::Throws<TException>(
nullptr, std::forward<TFunction>(func));
491 #pragma warning (disable:4715) 493 template<
typename TException,
typename TFunction>
494 inline void Assert::Throws(
const char* message, TFunction&& func)
500 catch (
const TException&)
507 if (message ==
nullptr)
509 BOOST_FAIL(throwsWrongTypeOfExceptionDefaultMessage);
517 if (message ==
nullptr)
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:1099
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:1482
Root namespace for the PLCnext API
Static assertion class for easy use in unit tests.
Definition: Assert.hpp:18
System components used by the System, Device, Plc or Io domains.