8#include "Arp/System/Core/TypeName.hxx"
9#include "Arp/System/Core/format_cast.hxx"
10#include "Arp/System/Commons/Io/File.hpp"
11#include <boost/test/unit_test.hpp>
14namespace Arp {
namespace System {
namespace Commons {
namespace Testing
25 static void AreEqual(
const void* expected,
const void* actual);
26 static void AreEqual(
const char* expected,
const char* actual);
27 static void AreEqual(
const char* expected,
const String& actual);
28 static void AreEqual(
const String& expected,
const char* actual);
29 static void AreEqual(
char expected,
char actual);
30 static void AreEqual(
unsigned char expected,
unsigned char actual);
31 static void AreEqual(
float expected,
float actual,
float epsilon);
32 static void AreEqual(
double expected,
double actual,
double epsilon);
33 template<
typename... Args>
34 static void AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args);
35 template<
typename... Args>
36 static void AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args);
37 template<
class T1,
class T2>
38 static void AreEqual(
const T1& expected,
const T2& actual);
39 template<
class T1,
class T2,
typename... Args>
40 static void AreEqual(
const T1& expected,
const T2& actual,
const char* message,
const Args& ... args);
41 template<
class T1,
class T2>
42 static void AreEqual(T1* expected, T2* actual);
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);
51 template<
class T1,
class T2>
52 static void AreNotEqual(
const T1& notExpected,
const T2& actual);
53 template<
class T1,
class T2,
typename... Args>
54 static void AreNotEqual(
const T1& notExpected,
const T2& actual,
const char* message,
const Args& ... args);
57 template<
typename ... Args>
58 static void Error(
const char* message,
const Args& ... args);
59 template<
typename ... Args>
60 static void Fail(
const char* message,
const Args& ... args);
63 template<
class Predicate>
64 static void IsTrue(Predicate predicate);
65 template<
class Predicate,
typename... Args>
66 static void IsTrue(Predicate predicate,
const char* message,
const Args& ... args);
69 template<
class Predicate>
70 static void IsFalse(Predicate predicate);
71 template<
class Predicate,
typename... Args>
72 static void IsFalse(Predicate predicate,
const char* message,
const Args& ... args);
76 static void IsNull(T* pValue);
77 template<
class T,
typename... Args>
78 static void IsNull(T* pValue,
const char* message,
const Args& ... args);
82 static void IsNotNull(T* pValue);
83 template<
class T,
typename... Args>
84 static void IsNotNull(T* pValue,
const char* message,
const Args& ... args);
87 static void IsEmpty(
const String& s);
88 template<
typename... Args>
89 static void IsEmpty(
const String& s,
const char* message,
const Args& ... args);
92 static void IsNotEmpty(
const String& s);
93 template<
typename... Args>
94 static void IsNotEmpty(
const String& s,
const char* message,
const Args& ... args);
97 static void Exists(
const String& path);
98 template<
typename... Args>
99 static void Exists(
const String& path,
const char* message,
const Args& ... args);
102 static void NotExists(
const String& path);
103 template<
typename... Args>
104 static void NotExists(
const String& path,
const char* message,
const Args& ... args);
107 template<
class TExpected,
class T>
108 static void IsInstanceOfType(
const T& instance);
109 template<
class TExpected,
class T,
typename... Args>
110 static void IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args);
111 template<
class TExpected,
class T>
113 template<
class TExpected,
class T,
typename... Args>
114 static void IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args);
117 template<
class TExpected,
class T>
118 static void IsNotInstanceOfType(
const T& instance);
119 template<
class TExpected,
class T,
typename... Args>
120 static void IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args);
121 template<
class TExpected,
class T>
122 static void IsNotInstanceOfType(
const T* pInstance);
123 template<
class TExpected,
class T,
typename... Args>
124 static void IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args);
127 template<
typename TException,
typename TFunction>
128 static void Throws(TFunction&& func);
129 template<
typename TException,
typename TFunction>
130 static void Throws(
const char* message, TFunction&& func);
133 static void CheckInternal(
bool predicate,
const char* message);
134 static void ErrorInternal(
const char* message);
135 static void FailInternal(
const char* message);
138 static const char*
const areEqualDefaultMessage;
139 static const char*
const areEqualDefaultMessageIntegersInHex;
140 static const char*
const areNotEqualDefaultMessage;
141 static const char*
const isTrueDefaultMessage;
142 static const char*
const isFalseDefaultMessage;
143 static const char*
const isNullDefaultMessage;
144 static const char*
const isNotNullDefaultMessage;
145 static const char*
const isEmptyDefaultMessage;
146 static const char*
const isNotEmptyDefaultMessage;
147 static const char*
const existsDefaultMessage;
148 static const char*
const notExistsDefaultMessage;
149 static const char*
const isInstanceOfTypeDefaultMessage;
150 static const char*
const isNotInstanceOfTypeDefaultMessage;
151 static const char*
const throwsNotDefaultMessage;
152 static const char*
const throwsWrongTypeOfExceptionDefaultMessage;
159inline void Assert::AreEqual(
const void* expected,
const void* actual)
161 return Assert::AreEqual(expected, actual, areEqualDefaultMessageIntegersInHex, expected, actual);
164inline void Assert::AreEqual(
const char* expected,
const char* actual)
166 if (expected ==
nullptr && actual ==
nullptr)
170 if (expected ==
nullptr && actual !=
nullptr)
172 Assert::Fail(areEqualDefaultMessage,
"", actual);
175 if (expected !=
nullptr && actual ==
nullptr)
177 Assert::Fail(areEqualDefaultMessage, expected,
"");
180 Assert::CheckInternal(String(expected) == actual,
String::Format(areEqualDefaultMessage, expected, actual));
183inline void Assert::AreEqual(
const char* expected,
const String& actual)
185 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
188inline void Assert::AreEqual(
const String& expected,
const char* actual)
190 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
193inline void Assert::AreEqual(
char expected,
char actual)
195 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, format_cast(expected), format_cast(actual)));
198inline void Assert::AreEqual(
unsigned char expected,
unsigned char actual)
200 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex, format_cast(expected), format_cast(actual)));
203inline void Assert::AreEqual(
float expected,
float actual,
float epsilon)
205 if (std::abs(actual - expected) > std::abs(epsilon))
207 Assert::FailInternal(
String::Format(areEqualDefaultMessage, expected, actual));
211inline void Assert::AreEqual(
double expected,
double actual,
double epsilon)
213 if (std::abs(actual - expected) > std::abs(epsilon))
215 Assert::FailInternal(
String::Format(areEqualDefaultMessage, expected, actual));
219template<
typename... Args>
220inline void Assert::AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
222 if (std::abs(actual - expected) > std::abs(epsilon))
224 Assert::FailInternal(
String::Format(message, format_cast(args)...));
228template<
typename... Args>
229inline void Assert::AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ...args)
231 if (std::abs(actual - expected) > std::abs(epsilon))
233 Assert::FailInternal(
String::Format(message, format_cast(args)...));
237template<
class T1,
class T2>
238inline void Assert::AreEqual(
const T1& expected,
const T2& actual)
240 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, format_cast(expected), format_cast(actual)));
243template<
class T1,
class T2,
typename... Args>
244inline void Assert::AreEqual(
const T1& expected,
const T2& actual,
const char* message,
const Args& ... args)
246 Assert::CheckInternal(expected == actual,
String::Format(message, format_cast(args)...));
249template<
class T1,
class T2>
250inline void Assert::AreEqual(T1* expected, T2* actual)
252 Assert::AreEqual(
static_cast<const void*
>(expected),
static_cast<const void*
>(actual));
256inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon)
258 if (std::abs(actual - expected) <= std::abs(epsilon))
260 Assert::FailInternal(
String::Format(areNotEqualDefaultMessage, expected, actual));
264inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon)
266 if (std::abs(actual - expected) <= std::abs(epsilon))
268 Assert::FailInternal(
String::Format(areNotEqualDefaultMessage, expected, actual));
272template<
typename... Args>
273inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
275 if (std::abs(actual - expected) <= std::abs(epsilon))
277 Assert::FailInternal(
String::Format(message, format_cast(args)...));
281template<
typename... Args>
282inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
284 if (std::abs(actual - expected) <= std::abs(epsilon))
286 Assert::FailInternal(
String::Format(message, format_cast(args)...));
290template<
class T1,
class T2>
291inline void Assert::AreNotEqual(
const T1& notExpected,
const T2& actual)
293 Assert::CheckInternal(notExpected != actual,
String::Format(areNotEqualDefaultMessage, format_cast(notExpected), format_cast(actual)));
296template<
class T1,
class T2,
typename... Args>
297inline void Assert::AreNotEqual(
const T1& notExpected,
const T2& actual,
const char* message,
const Args& ... args)
299 Assert::CheckInternal(notExpected != actual,
String::Format(message, format_cast(args)...));
303template<
typename... Args>
304inline void Assert::Error(
const char* message,
const Args& ... args)
306 Assert::ErrorInternal(
String::Format(message, format_cast(args)...));
310template<
typename... Args>
311inline void Assert::Fail(
const char* message,
const Args& ... args)
313 Assert::FailInternal(
String::Format(message, format_cast(args)...));
317template<
class Predicate>
318inline void Assert::IsTrue(Predicate predicate)
320 Assert::CheckInternal(predicate ?
true :
false, isTrueDefaultMessage);
323template<
class Predicate,
typename... Args>
324inline void Assert::IsTrue(Predicate predicate,
const char* message,
const Args& ... args)
326 Assert::CheckInternal(predicate ?
true :
false,
String::Format(message, format_cast(args)...));
330template<
class Predicate>
331inline void Assert::IsFalse(Predicate predicate)
333 Assert::CheckInternal(predicate ?
false :
true, isFalseDefaultMessage);
336template<
class Predicate,
typename... Args>
337inline void Assert::IsFalse(Predicate predicate,
const char* message,
const Args& ... args)
339 Assert::CheckInternal(predicate ?
false :
true,
String::Format(message, format_cast(args)...));
344inline void Assert::IsNull(T* pValue)
346 Assert::CheckInternal(pValue ==
nullptr, isNullDefaultMessage);
349template<
class T,
typename... Args>
350inline void Assert::IsNull(T* pValue,
const char* message,
const Args& ... args)
352 Assert::CheckInternal(pValue ==
nullptr,
String::Format(message, format_cast(args)...));
357inline void Assert::IsNotNull(T* pValue)
359 Assert::CheckInternal(pValue !=
nullptr, isNotNullDefaultMessage);
362template<
class T,
typename... Args>
363inline void Assert::IsNotNull(T* pValue,
const char* message,
const Args& ... args)
365 Assert::CheckInternal(pValue !=
nullptr,
String::Format(message, format_cast(args)...));
369inline void Assert::IsEmpty(
const String& s)
371 Assert::CheckInternal(s.IsEmpty(), isEmptyDefaultMessage);
374template<
typename... Args>
375inline void Assert::IsEmpty(
const String& s,
const char* message,
const Args& ... args)
377 Assert::CheckInternal(s.IsEmpty(),
String::Format(message, format_cast(args)...));
381inline void Assert::IsNotEmpty(
const String& s)
383 Assert::CheckInternal(!s.IsEmpty(), isNotEmptyDefaultMessage);
386template<
typename... Args>
387inline void Assert::IsNotEmpty(
const String& s,
const char* message,
const Args& ... args)
389 Assert::CheckInternal(!s.IsEmpty(),
String::Format(message, format_cast(args)...));
393inline void Assert::Exists(
const String& path)
398template<
typename... Args>
399inline void Assert::Exists(
const String& path,
const char* message,
const Args& ... args)
405inline void Assert::NotExists(
const String& path)
410template<
typename... Args>
411inline void Assert::NotExists(
const String& path,
const char* message,
const Args& ... args)
417template<
class TExpected,
class T>
418inline void Assert::IsInstanceOfType(
const T& instance)
420 if (!Arp::IsInstanceOfType<TExpected>(instance))
426template<
class TExpected,
class T,
typename... Args>
427inline void Assert::IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
429 if (!Arp::IsInstanceOfType<TExpected>(instance))
431 Assert::FailInternal(
String::Format(message, format_cast(args)...));
435template<
class TExpected,
class T>
436inline void Assert::IsInstanceOfType(
const T* pInstance)
438 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
440 Assert::FailInternal(
String::Format(isInstanceOfTypeDefaultMessage, TypeName<TExpected>()));
444template<
class TExpected,
class T,
typename... Args>
445inline void Assert::IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
447 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
449 Assert::FailInternal(
String::Format(message, format_cast(args)...));
454template<
class TExpected,
class T>
455inline void Assert::IsNotInstanceOfType(
const T& instance)
457 if (Arp::IsInstanceOfType<TExpected>(instance))
459 Assert::FailInternal(
String::Format(isNotInstanceOfTypeDefaultMessage, TypeName<TExpected>()));
463template<
class TExpected,
class T,
typename... Args>
464inline void Assert::IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
466 if (Arp::IsInstanceOfType<TExpected>(instance))
468 Assert::FailInternal(
String::Format(message, format_cast(args)...));
472template<
class TExpected,
class T>
473inline void Assert::IsNotInstanceOfType(
const T* pInstance)
475 if (Arp::IsInstanceOfType<TExpected>(pInstance))
477 Assert::FailInternal(
String::Format(isNotInstanceOfTypeDefaultMessage, TypeName<TExpected>()));
481template<
class TExpected,
class T,
typename... Args>
482inline void Assert::IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
484 if (IsInstanceOfType<TExpected>(pInstance))
486 Assert::FailInternal(
String::Format(message, format_cast(args)...));
491template<
typename TException,
typename TFunction>
492inline void Assert::Throws(TFunction&& func)
494 Assert::Throws<TException>(
nullptr, std::forward<TFunction>(func));
497#pragma warning (disable:4715)
499template<
typename TException,
typename TFunction>
500inline void Assert::Throws(
const char* message, TFunction&& func)
506 catch (
const TException&)
513 if (message ==
nullptr)
515 Assert::FailInternal(throwsWrongTypeOfExceptionDefaultMessage);
519 Assert::FailInternal(message);
523 if (message ==
nullptr)
525 Assert::FailInternal(
String::Format(throwsNotDefaultMessage, TypeName<TException>()));
529 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:19
This (meta programming) class provides the C++ typename of the as template argument passed type.
Definition: TypeName.hxx:67
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:1493
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
Root namespace for the PLCnext API