-
Notifications
You must be signed in to change notification settings - Fork 2
/
Platform.Interfaces.Tests.cpp
164 lines (133 loc) · 4.82 KB
/
Platform.Interfaces.Tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <gtest/gtest.h>
#include <Platform.Interfaces.h>
namespace Platform::Interfaces::Tests
{
TEST(CompileTests, ICounter)
{
struct EmptyCounter
{
int Count() { return {}; }
};
// You can use
static_assert(ICounter<EmptyCounter, int>);
// to avoid mismatching the interface at compile time
struct EmptyCounterInt
{
int Count(int argument) { return {}; }
};
static_assert(ICounter<EmptyCounterInt, int, int>);
{
ICounter<int> auto counter = EmptyCounter{};
ASSERT_TRUE((ICounter<EmptyCounter, int>));
ASSERT_FALSE((ICounter<EmptyCounter, float>));
}
{
ICounter<int, int> auto counter = EmptyCounterInt{};
ASSERT_TRUE((ICounter<EmptyCounterInt, int, int>));
ASSERT_TRUE((ICounter<EmptyCounterInt, int, float>));
ASSERT_FALSE((ICounter<EmptyCounterInt, float, int>));
ASSERT_FALSE((ICounter<EmptyCounterInt, float, float>));
}
}
TEST(CompileTests, ICriterionMatcher)
{
struct EmptyCriterionMatcher
{
bool IsMatched(int argument) { return {}; }
};
static_assert(ICriterionMatcher<EmptyCriterionMatcher, int>);
{
ICriterionMatcher<int> auto criterionMatcher = EmptyCriterionMatcher{};
ASSERT_TRUE((ICriterionMatcher<EmptyCriterionMatcher, int>));
ASSERT_TRUE((ICriterionMatcher<EmptyCriterionMatcher, float>));
}
}
TEST(CompileTests, IFactory)
{
struct EmptyIntFactory
{
int Create() { return {}; }
};
static_assert(IFactory<EmptyIntFactory, int>);
{
IFactory<int> auto factory = EmptyIntFactory{};
ASSERT_TRUE((IFactory<EmptyIntFactory, int>));
ASSERT_FALSE((IFactory<EmptyIntFactory, float>));
}
}
TEST(CompileTests, IProperties)
{
struct EmptyProperties
{
void SetValue(std::string object, int argument, std::byte value) {}
std::byte GetValue(const std::string& object, int argument) { return std::byte{}; }
};
static_assert(IProperties<EmptyProperties, std::string, int, std::byte>);
{
IProperties<std::string, int, std::byte> auto properties = EmptyProperties{};
ASSERT_TRUE((IProperties<EmptyProperties, std::string, int, std::byte>));
ASSERT_TRUE((IProperties<EmptyProperties, std::string&, int, std::byte>));
ASSERT_TRUE((IProperties<EmptyProperties, const std::string&, int, std::byte>));
}
}
TEST(CompileTests, IProvider)
{
struct EmptyProvider
{
std::byte Get() { return std::byte{}; }
};
static_assert(IProvider<EmptyProvider, std::byte>);
struct EmptyIntProvider
{
std::byte Get(int argument) { return std::byte{}; }
};
static_assert(IProvider<EmptyIntProvider, std::byte, int>);
{
IProvider<std::byte> auto provider = EmptyProvider{};
ASSERT_TRUE((IProvider<EmptyProvider, std::byte>));
}
{
IProvider<std::byte, int> auto provider = EmptyIntProvider{};
ASSERT_TRUE((IProvider<EmptyIntProvider, std::byte, int>));
ASSERT_TRUE((IProvider<EmptyIntProvider, std::byte, float>));
}
}
TEST(CompileTests, ISetter)
{
struct EmptySetter
{
void Set(std::byte value) { }
};
static_assert(ISetter<EmptySetter, std::byte>);
struct EmptyIntSetter
{
void Set(int argument, std::byte value) { }
};
static_assert(ISetter<EmptyIntSetter, std::byte, int>);
{
ISetter<std::byte> auto provider = EmptySetter{};
ASSERT_TRUE((ISetter<EmptySetter, std::byte>));
}
{
ISetter<std::byte, int> auto provider = EmptyIntSetter{};
ASSERT_TRUE((ISetter<EmptyIntSetter, std::byte, int>));
ASSERT_TRUE((ISetter<EmptyIntSetter, std::byte, float>));
}
}
TEST(CompileTests, IProperty)
{
struct EmptyProperty
{
void Set(std::string& object, std::byte value) { }
std::byte Get(std::string& object) { return {}; }
};
// TODO can be use in concepts TObject& instead of TObject
static_assert(IProperty<EmptyProperty, std::string&, std::byte>);
{
IProperty<std::string&, std::byte> auto provider = EmptyProperty{};
ASSERT_TRUE((IProperty<EmptyProperty, std::string&, std::byte>));
ASSERT_TRUE((IProvider<EmptyProperty, std::byte, std::string&>));
ASSERT_TRUE((ISetter<EmptyProperty, std::byte, std::string&>));
}
}
}