8#include "Arp/System/Core/TypeName.hxx"
9#include "Arp/System/Commons/Io/File.hpp"
10#include <boost/test/unit_test.hpp>
13namespace 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);
36 template<
class T1,
class T2>
37 static void AreEqual(
const T1& expected,
const T2& actual);
38 template<
class T1,
class T2,
typename... Args>
39 static void AreEqual(
const T1& expected,
const T2& actual,
const char* message,
const Args& ... args);
40 template<
class T1,
class T2>
41 static void AreEqual(T1* expected, T2* actual);
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);
50 template<
class T1,
class T2>
51 static void AreNotEqual(
const T1& notExpected,
const T2& actual);
52 template<
class T1,
class T2,
typename... Args>
53 static void AreNotEqual(
const T1& notExpected,
const T2& actual,
const char* message,
const Args& ... args);
56 template<
typename ... Args>
57 static void Error(
const char* message,
const Args& ... args);
58 template<
typename ... Args>
59 static void Fail(
const char* message,
const Args& ... args);
62 template<
class Predicate>
63 static void IsTrue(Predicate predicate);
64 template<
class Predicate,
typename... Args>
65 static void IsTrue(Predicate predicate,
const char* message,
const Args& ... args);
68 template<
class Predicate>
69 static void IsFalse(Predicate predicate);
70 template<
class Predicate,
typename... Args>
71 static void IsFalse(Predicate predicate,
const char* message,
const Args& ... args);
75 static void IsNull(T* pValue);
76 template<
class T,
typename... Args>
77 static void IsNull(T* pValue,
const char* message,
const Args& ... args);
81 static void IsNotNull(T* pValue);
82 template<
class T,
typename... Args>
83 static void IsNotNull(T* pValue,
const char* message,
const Args& ... args);
86 static void IsEmpty(
const String& s);
87 template<
typename... Args>
88 static void IsEmpty(
const String& s,
const char* message,
const Args& ... args);
91 static void IsNotEmpty(
const String& s);
92 template<
typename... Args>
93 static void IsNotEmpty(
const String& s,
const char* message,
const Args& ... args);
96 static void Exists(
const String& path);
97 template<
typename... Args>
98 static void Exists(
const String& path,
const char* message,
const Args& ... args);
101 static void NotExists(
const String& path);
102 template<
typename... Args>
103 static void NotExists(
const String& path,
const char* message,
const Args& ... args);
106 template<
class TExpected,
class T>
107 static void IsInstanceOfType(
const T& instance);
108 template<
class TExpected,
class T,
typename... Args>
109 static void IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args);
110 template<
class TExpected,
class T>
112 template<
class TExpected,
class T,
typename... Args>
113 static void IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args);
116 template<
class TExpected,
class T>
117 static void IsNotInstanceOfType(
const T& instance);
118 template<
class TExpected,
class T,
typename... Args>
119 static void IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args);
120 template<
class TExpected,
class T>
121 static void IsNotInstanceOfType(
const T* pInstance);
122 template<
class TExpected,
class T,
typename... Args>
123 static void IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args);
126 template<
typename TException,
typename TFunction>
127 static void Throws(TFunction&& func);
128 template<
typename TException,
typename TFunction>
129 static void Throws(
const char* message, TFunction&& func);
132 static void CheckInternal(
bool predicate,
const char* message);
133 static void ErrorInternal(
const char* message);
134 static void FailInternal(
const char* message);
137 static const char*
const areEqualDefaultMessage;
138 static const char*
const areEqualDefaultMessageIntegersInHex;
139 static const char*
const areNotEqualDefaultMessage;
140 static const char*
const isTrueDefaultMessage;
141 static const char*
const isFalseDefaultMessage;
142 static const char*
const isNullDefaultMessage;
143 static const char*
const isNotNullDefaultMessage;
144 static const char*
const isEmptyDefaultMessage;
145 static const char*
const isNotEmptyDefaultMessage;
146 static const char*
const existsDefaultMessage;
147 static const char*
const notExistsDefaultMessage;
148 static const char*
const isInstanceOfTypeDefaultMessage;
149 static const char*
const isNotInstanceOfTypeDefaultMessage;
150 static const char*
const throwsNotDefaultMessage;
151 static const char*
const throwsWrongTypeOfExceptionDefaultMessage;
158inline void Assert::AreEqual(
const void* expected,
const void* actual)
160 return Assert::AreEqual(expected, actual, areEqualDefaultMessageIntegersInHex, expected, actual);
163inline void Assert::AreEqual(
const char* expected,
const char* actual)
165 if (expected ==
nullptr && actual ==
nullptr)
169 if (expected ==
nullptr && actual !=
nullptr)
171 Assert::Fail(areEqualDefaultMessage,
"", actual);
174 if (expected !=
nullptr && actual ==
nullptr)
176 Assert::Fail(areEqualDefaultMessage, expected,
"");
179 Assert::CheckInternal(String(expected) == actual,
String::Format(areEqualDefaultMessage, expected, actual));
182inline void Assert::AreEqual(
const char* expected,
const String& actual)
184 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
187inline void Assert::AreEqual(
const String& expected,
const char* actual)
189 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
192inline void Assert::AreEqual(
char expected,
char actual)
194 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex,
static_cast<int>(expected),
static_cast<int>(actual)));
197inline void Assert::AreEqual(
unsigned char expected,
unsigned char actual)
199 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessageIntegersInHex,
static_cast<int>(expected),
static_cast<int>(actual)));
202inline void Assert::AreEqual(
float expected,
float actual,
float epsilon)
204 if (std::abs(actual - expected) > std::abs(epsilon))
206 Assert::FailInternal(
String::Format(areEqualDefaultMessage, expected, actual));
210inline void Assert::AreEqual(
double expected,
double actual,
double epsilon)
212 if (std::abs(actual - expected) > std::abs(epsilon))
214 Assert::FailInternal(
String::Format(areEqualDefaultMessage, expected, actual));
218template<
typename... Args>
219inline void Assert::AreEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
221 if (std::abs(actual - expected) > std::abs(epsilon))
227template<
typename... Args>
228inline void Assert::AreEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
230 if (std::abs(actual - expected) > std::abs(epsilon))
236template<
class T1,
class T2>
237inline void Assert::AreEqual(
const T1& expected,
const T2& actual)
239 Assert::CheckInternal(expected == actual,
String::Format(areEqualDefaultMessage, expected, actual));
242template<
class T1,
class T2,
typename... Args>
243inline void Assert::AreEqual(
const T1& expected,
const T2& actual,
const char* message,
const Args& ... args)
245 Assert::CheckInternal(expected == actual,
String::Format(message, args...));
248template<
class T1,
class T2>
249inline void Assert::AreEqual(T1* expected, T2* actual)
251 Assert::AreEqual(
static_cast<const void*
>(expected),
static_cast<const void*
>(actual));
255inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon)
257 if (std::abs(actual - expected) <= std::abs(epsilon))
259 Assert::FailInternal(
String::Format(areNotEqualDefaultMessage, expected, actual));
263inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon)
265 if (std::abs(actual - expected) <= std::abs(epsilon))
267 Assert::FailInternal(
String::Format(areNotEqualDefaultMessage, expected, actual));
271template<
typename... Args>
272inline void Assert::AreNotEqual(
float expected,
float actual,
float epsilon,
const char* message,
const Args& ... args)
274 if (std::abs(actual - expected) <= std::abs(epsilon))
280template<
typename... Args>
281inline void Assert::AreNotEqual(
double expected,
double actual,
double epsilon,
const char* message,
const Args& ... args)
283 if (std::abs(actual - expected) <= std::abs(epsilon))
289template<
class T1,
class T2>
290inline void Assert::AreNotEqual(
const T1& notExpected,
const T2& actual)
292 Assert::CheckInternal(notExpected != actual,
String::Format(areNotEqualDefaultMessage, notExpected, actual));
295template<
class T1,
class T2,
typename... Args>
296inline void Assert::AreNotEqual(
const T1& notExpected,
const T2& actual,
const char* message,
const Args& ... args)
298 Assert::CheckInternal(notExpected != actual,
String::Format(message, args...));
302template<
typename... Args>
303inline void Assert::Error(
const char* message,
const Args& ... args)
309template<
typename... Args>
310inline void Assert::Fail(
const char* message,
const Args& ... args)
316template<
class Predicate>
317inline void Assert::IsTrue(Predicate predicate)
319 Assert::CheckInternal(predicate ?
true :
false, isTrueDefaultMessage);
322template<
class Predicate,
typename... Args>
323inline void Assert::IsTrue(Predicate predicate,
const char* message,
const Args& ... args)
325 Assert::CheckInternal(predicate ?
true :
false,
String::Format(message, args...));
329template<
class Predicate>
330inline void Assert::IsFalse(Predicate predicate)
332 Assert::CheckInternal(predicate ?
false :
true, isFalseDefaultMessage);
335template<
class Predicate,
typename... Args>
336inline void Assert::IsFalse(Predicate predicate,
const char* message,
const Args& ... args)
338 Assert::CheckInternal(predicate ?
false :
true,
String::Format(message, args...));
343inline void Assert::IsNull(T* pValue)
345 Assert::CheckInternal(pValue ==
nullptr, isNullDefaultMessage);
348template<
class T,
typename... Args>
349inline void Assert::IsNull(T* pValue,
const char* message,
const Args& ... args)
351 Assert::CheckInternal(pValue ==
nullptr,
String::Format(message, args...));
356inline void Assert::IsNotNull(T* pValue)
358 Assert::CheckInternal(pValue !=
nullptr, isNotNullDefaultMessage);
361template<
class T,
typename... Args>
362inline void Assert::IsNotNull(T* pValue,
const char* message,
const Args& ... args)
364 Assert::CheckInternal(pValue !=
nullptr,
String::Format(message, args...));
368inline void Assert::IsEmpty(
const String& s)
370 Assert::CheckInternal(s.IsEmpty(), isEmptyDefaultMessage);
373template<
typename... Args>
374inline void Assert::IsEmpty(
const String& s,
const char* message,
const Args& ... args)
376 Assert::CheckInternal(s.IsEmpty(),
String::Format(message, args...));
380inline void Assert::IsNotEmpty(
const String& s)
382 Assert::CheckInternal(!s.IsEmpty(), isNotEmptyDefaultMessage);
385template<
typename... Args>
386inline void Assert::IsNotEmpty(
const String& s,
const char* message,
const Args& ... args)
388 Assert::CheckInternal(!s.IsEmpty(),
String::Format(message, args...));
392inline void Assert::Exists(
const String& path)
397template<
typename... Args>
398inline void Assert::Exists(
const String& path,
const char* message,
const Args& ... args)
404inline void Assert::NotExists(
const String& path)
409template<
typename... Args>
410inline void Assert::NotExists(
const String& path,
const char* message,
const Args& ... args)
416template<
class TExpected,
class T>
417inline void Assert::IsInstanceOfType(
const T& instance)
419 if (!Arp::IsInstanceOfType<TExpected>(instance))
425template<
class TExpected,
class T,
typename... Args>
426inline void Assert::IsInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
428 if (!Arp::IsInstanceOfType<TExpected>(instance))
434template<
class TExpected,
class T>
435inline void Assert::IsInstanceOfType(
const T* pInstance)
437 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
439 Assert::FailInternal(
String::Format(isInstanceOfTypeDefaultMessage, TypeName<TExpected>().Value));
443template<
class TExpected,
class T,
typename... Args>
444inline void Assert::IsInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
446 if (!Arp::IsInstanceOfType<TExpected>(pInstance))
453template<
class TExpected,
class T>
454inline void Assert::IsNotInstanceOfType(
const T& instance)
456 if (Arp::IsInstanceOfType<TExpected>(instance))
458 Assert::FailInternal(
String::Format(isNotInstanceOfTypeDefaultMessage, TypeName<TExpected>().Value));
462template<
class TExpected,
class T,
typename... Args>
463inline void Assert::IsNotInstanceOfType(
const T& instance,
const char* message,
const Args& ... args)
465 if (Arp::IsInstanceOfType<TExpected>(instance))
471template<
class TExpected,
class T>
472inline void Assert::IsNotInstanceOfType(
const T* pInstance)
474 if (Arp::IsInstanceOfType<TExpected>(pInstance))
476 Assert::FailInternal(
String::Format(isNotInstanceOfTypeDefaultMessage, TypeName<TExpected>().Value));
480template<
class TExpected,
class T,
typename... Args>
481inline void Assert::IsNotInstanceOfType(
const T* pInstance,
const char* message,
const Args& ... args)
483 if (IsInstanceOfType<TExpected>(pInstance))
490template<
typename TException,
typename TFunction>
491inline void Assert::Throws(TFunction&& func)
493 Assert::Throws<TException>(
nullptr, std::forward<TFunction>(func));
496#pragma warning (disable:4715)
498template<
typename TException,
typename TFunction>
499inline void Assert::Throws(
const char* message, TFunction&& func)
505 catch (
const TException&)
512 if (message ==
nullptr)
514 Assert::FailInternal(throwsWrongTypeOfExceptionDefaultMessage);
518 Assert::FailInternal(message);
522 if (message ==
nullptr)
524 Assert::FailInternal(
String::Format(throwsNotDefaultMessage, TypeName<TException>().Value));
528 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: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: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
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API