stdex
Additional custom or not Standard C++ covered algorithms
Loading...
Searching...
No Matches
compat.hpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023 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
16namespace 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 inline void AreEqual(const T& a, const T& b)
32 {
33 if (!(a == b))
34 throw std::runtime_error("not equal");
35 }
36
37 inline void AreEqual(const char* a, const char* b)
38 {
39 if (strcmp(a, b) != 0)
40 throw std::runtime_error("not equal");
41 }
42
43 inline void AreEqual(const wchar_t* a, const wchar_t* b)
44 {
45 if (wcscmp(a, b) != 0)
46 throw std::runtime_error("not equal");
47 }
48
49 template <class T>
50 inline void AreNotEqual(const T& a, const T& b)
51 {
52 if (a == b)
53 throw std::runtime_error("equal");
54 }
55
56 inline void AreNotEqual(const char* a, const char* b)
57 {
58 if (strcmp(a, b) == 0)
59 throw std::runtime_error("equal");
60 }
61
62 inline void AreNotEqual(const wchar_t* a, const wchar_t* b)
63 {
64 if (wcscmp(a, b) == 0)
65 throw std::runtime_error("equal");
66 }
67
68 template <class E, typename F>
69 inline void ExpectException(F functor)
70 {
71 try { functor(); }
72 catch (const E&) { return; }
73 catch (...) { throw std::runtime_error("unexpected exception"); }
74 throw std::runtime_error("exception not thrown");
75 }
76}
77#endif