stdex
Additional custom or not Standard C++ covered algorithms
Loading...
Searching...
No Matches
UnitTests
compat.hpp
1
/*
2
SPDX-License-Identifier: MIT
3
Copyright © 2023-2024 Amebis
4
*/
5
6
#pragma once
7
8
#if defined(_WIN32)
9
#include <CppUnitTest.h>
10
#elif defined(__APPLE__)
11
#include <stdexcept>
12
13
#define TEST_CLASS(name) class name
14
#define TEST_METHOD(name) static void name()
15
16
namespace
Assert
17
{
18
inline
void
IsTrue(
bool
c)
19
{
20
if
(!c)
21
throw
std::runtime_error(
"not true"
);
22
}
23
24
inline
void
IsFalse(
bool
c)
25
{
26
if
(c)
27
throw
std::runtime_error(
"not false"
);
28
}
29
30
template
<
class
T>
31
void
AreEqual(
const
T& a,
const
T& b)
32
{
33
if
(!(a == b))
34
throw
std::runtime_error(
"not equal"
);
35
}
36
37
template
<
class
T,
size_t
N>
38
void
AreEqual(
const
T (&a)[N],
const
T (&b)[N])
39
{
40
for
(
size_t
i = 0; i < N; ++i)
41
if
(!(a[i] == b[i]))
42
throw
std::runtime_error(
"not equal"
);
43
}
44
45
inline
void
AreEqual(
const
char
* a,
const
char
* b)
46
{
47
if
(strcmp(a, b) != 0)
48
throw
std::runtime_error(
"not equal"
);
49
}
50
51
inline
void
AreEqual(
const
wchar_t
* a,
const
wchar_t
* b)
52
{
53
if
(wcscmp(a, b) != 0)
54
throw
std::runtime_error(
"not equal"
);
55
}
56
57
template
<
class
T>
58
void
AreNotEqual(
const
T& a,
const
T& b)
59
{
60
if
(a == b)
61
throw
std::runtime_error(
"equal"
);
62
}
63
64
inline
void
AreNotEqual(
const
char
* a,
const
char
* b)
65
{
66
if
(strcmp(a, b) == 0)
67
throw
std::runtime_error(
"equal"
);
68
}
69
70
inline
void
AreNotEqual(
const
wchar_t
* a,
const
wchar_t
* b)
71
{
72
if
(wcscmp(a, b) == 0)
73
throw
std::runtime_error(
"equal"
);
74
}
75
76
template
<
class
E,
typename
F>
77
void
ExpectException(F functor)
78
{
79
try
{ functor(); }
80
catch
(
const
E&) {
return
; }
81
catch
(...) {
throw
std::runtime_error(
"unexpected exception"
); }
82
throw
std::runtime_error(
"exception not thrown"
);
83
}
84
}
85
#endif
Generated on Fri Feb 23 2024 15:48:21 for stdex by
1.10.0