1+ #define NON_FATAL_STANDARD_RULES
2+ #include " code_library/assertions/standard_rules.hpp"
3+
4+ #include < catch2/catch.hpp>
5+
6+ #include < memory>
7+
8+ class EmptyType {};
9+
10+ class UnconstructibleType
11+ {
12+ UnconstructibleType () = delete ;
13+ UnconstructibleType (const UnconstructibleType&) = delete ;
14+ };
15+
16+ class EmptyTypeWithExplicitConstructor
17+ {
18+ public:
19+ EmptyTypeWithExplicitConstructor () {}
20+ };
21+
22+ class EmptyTypeWithExplicitNoexceptConstructor
23+ {
24+ public:
25+ EmptyTypeWithExplicitNoexceptConstructor () noexcept {}
26+ };
27+
28+ class CopyOnlyType
29+ {
30+ public:
31+ CopyOnlyType (const CopyOnlyType&) noexcept = default ;
32+ CopyOnlyType& operator =(const CopyOnlyType&) noexcept = default ;
33+ CopyOnlyType (CopyOnlyType&&) noexcept = delete ;
34+ CopyOnlyType& operator =(CopyOnlyType&&) noexcept = delete ;
35+ };
36+
37+ class MoveOnlyType
38+ {
39+ public:
40+ MoveOnlyType (const MoveOnlyType&) noexcept = delete ;
41+ MoveOnlyType& operator =(const MoveOnlyType&) noexcept = delete ;
42+ MoveOnlyType (MoveOnlyType&&) noexcept = default ;
43+ MoveOnlyType& operator =(MoveOnlyType&&) noexcept = default ;
44+ };
45+
46+ class UniquePtrType
47+ {
48+ private:
49+ std::unique_ptr<int > value_;
50+ };
51+
52+ TEST_CASE (" Standard Rules can be enforced" , " [standard_rules]" )
53+ {
54+ SECTION (" Types can be enforced to be constructible" )
55+ {
56+ CHECK (assert_is_default_constructible<EmptyType>());
57+ CHECK (assert_is_trivially_constructible<EmptyType>());
58+ CHECK (assert_is_nothrow_default_constructible<EmptyType>());
59+
60+ CHECK (!assert_is_default_constructible<UnconstructibleType>());
61+ CHECK (!assert_is_trivially_constructible<UnconstructibleType>());
62+ CHECK (!assert_is_nothrow_default_constructible<UnconstructibleType>());
63+
64+ CHECK (assert_is_default_constructible<EmptyTypeWithExplicitConstructor>());
65+ CHECK (!assert_is_trivially_constructible<EmptyTypeWithExplicitConstructor>());
66+ CHECK (!assert_is_nothrow_default_constructible<EmptyTypeWithExplicitConstructor>());
67+
68+ CHECK (assert_is_default_constructible<EmptyTypeWithExplicitNoexceptConstructor>());
69+ CHECK (!assert_is_trivially_constructible<EmptyTypeWithExplicitNoexceptConstructor>());
70+ CHECK (assert_is_nothrow_default_constructible<EmptyTypeWithExplicitNoexceptConstructor>());
71+
72+ CHECK (!assert_is_default_constructible<CopyOnlyType>());
73+ CHECK (!assert_is_trivially_constructible<CopyOnlyType>());
74+ CHECK (!assert_is_nothrow_default_constructible<CopyOnlyType>());
75+
76+ CHECK (!assert_is_default_constructible<MoveOnlyType>());
77+ CHECK (!assert_is_trivially_constructible<MoveOnlyType>());
78+ CHECK (!assert_is_nothrow_default_constructible<MoveOnlyType>());
79+
80+ CHECK (assert_is_default_constructible<UniquePtrType>());
81+ CHECK (!assert_is_trivially_constructible<UniquePtrType>());
82+ CHECK (assert_is_nothrow_default_constructible<UniquePtrType>());
83+ }
84+
85+ SECTION (" Types can be enforced to be copyable" , " [standard_rules]" )
86+ {
87+ CHECK (assert_is_copyable<EmptyType>());
88+ CHECK (assert_is_trivially_copyable<EmptyType>());
89+ CHECK (assert_is_nothrow_copyable<EmptyType>());
90+
91+ CHECK (!assert_is_copyable<UnconstructibleType>());
92+ CHECK (!assert_is_trivially_copyable<UnconstructibleType>());
93+ CHECK (!assert_is_nothrow_copyable<UnconstructibleType>());
94+
95+ CHECK (assert_is_copyable<EmptyTypeWithExplicitConstructor>());
96+ CHECK (assert_is_trivially_copyable<EmptyTypeWithExplicitConstructor>());
97+ CHECK (assert_is_nothrow_copyable<EmptyTypeWithExplicitConstructor>());
98+
99+ CHECK (assert_is_copyable<EmptyTypeWithExplicitNoexceptConstructor>());
100+ CHECK (assert_is_trivially_copyable<EmptyTypeWithExplicitNoexceptConstructor>());
101+ CHECK (assert_is_nothrow_copyable<EmptyTypeWithExplicitNoexceptConstructor>());
102+
103+ CHECK (assert_is_copyable<CopyOnlyType>());
104+ CHECK (assert_is_trivially_copyable<CopyOnlyType>());
105+ CHECK (assert_is_nothrow_copyable<CopyOnlyType>());
106+
107+ CHECK (!assert_is_copyable<MoveOnlyType>());
108+ CHECK (!assert_is_trivially_copyable<MoveOnlyType>());
109+ CHECK (!assert_is_nothrow_copyable<MoveOnlyType>());
110+
111+ CHECK (!assert_is_copyable<UniquePtrType>());
112+ CHECK (!assert_is_trivially_copyable<UniquePtrType>());
113+ CHECK (!assert_is_nothrow_copyable<UniquePtrType>());
114+ }
115+
116+ SECTION (" Types can be enforced to be moveable" , " [standard_rules]" )
117+ {
118+ CHECK (assert_is_moveable<EmptyType>());
119+ CHECK (assert_is_trivially_moveable<EmptyType>());
120+ CHECK (assert_is_nothrow_moveable<EmptyType>());
121+
122+ CHECK (!assert_is_moveable<UnconstructibleType>());
123+ CHECK (!assert_is_trivially_moveable<UnconstructibleType>());
124+ CHECK (!assert_is_nothrow_moveable<UnconstructibleType>());
125+
126+ CHECK (assert_is_moveable<EmptyTypeWithExplicitConstructor>());
127+ CHECK (assert_is_trivially_moveable<EmptyTypeWithExplicitConstructor>());
128+ CHECK (assert_is_nothrow_moveable<EmptyTypeWithExplicitConstructor>());
129+
130+ CHECK (assert_is_moveable<EmptyTypeWithExplicitNoexceptConstructor>());
131+ CHECK (assert_is_trivially_moveable<EmptyTypeWithExplicitNoexceptConstructor>());
132+ CHECK (assert_is_nothrow_moveable<EmptyTypeWithExplicitNoexceptConstructor>());
133+
134+ CHECK (!assert_is_moveable<CopyOnlyType>());
135+ CHECK (!assert_is_trivially_moveable<CopyOnlyType>());
136+ CHECK (!assert_is_nothrow_moveable<CopyOnlyType>());
137+
138+ CHECK (assert_is_moveable<MoveOnlyType>());
139+ CHECK (assert_is_trivially_moveable<MoveOnlyType>());
140+ CHECK (assert_is_nothrow_moveable<MoveOnlyType>());
141+
142+ CHECK (assert_is_moveable<UniquePtrType>());
143+ CHECK (!assert_is_trivially_moveable<UniquePtrType>());
144+ CHECK (assert_is_nothrow_moveable<UniquePtrType>());
145+ }
146+
147+ SECTION (" Types can be enforced to be destructible" , " [standard_rules]" )
148+ {
149+ CHECK (assert_is_destructible<EmptyType>());
150+ CHECK (assert_is_trivially_destructible<EmptyType>());
151+ CHECK (assert_is_nothrow_destructible<EmptyType>());
152+
153+ CHECK (assert_is_destructible<UnconstructibleType>());
154+ CHECK (assert_is_trivially_destructible<UnconstructibleType>());
155+ CHECK (assert_is_nothrow_destructible<UnconstructibleType>());
156+
157+ CHECK (assert_is_destructible<EmptyTypeWithExplicitConstructor>());
158+ CHECK (assert_is_trivially_destructible<EmptyTypeWithExplicitConstructor>());
159+ CHECK (assert_is_nothrow_destructible<EmptyTypeWithExplicitConstructor>());
160+
161+ CHECK (assert_is_destructible<EmptyTypeWithExplicitNoexceptConstructor>());
162+ CHECK (assert_is_trivially_destructible<EmptyTypeWithExplicitNoexceptConstructor>());
163+ CHECK (assert_is_nothrow_destructible<EmptyTypeWithExplicitNoexceptConstructor>());
164+
165+ CHECK (assert_is_destructible<CopyOnlyType>());
166+ CHECK (assert_is_trivially_destructible<CopyOnlyType>());
167+ CHECK (assert_is_nothrow_destructible<CopyOnlyType>());
168+
169+ CHECK (assert_is_destructible<MoveOnlyType>());
170+ CHECK (assert_is_trivially_destructible<MoveOnlyType>());
171+ CHECK (assert_is_nothrow_destructible<MoveOnlyType>());
172+
173+ CHECK (assert_is_destructible<UniquePtrType>());
174+ CHECK (!assert_is_trivially_destructible<UniquePtrType>());
175+ CHECK (assert_is_nothrow_destructible<UniquePtrType>());
176+ }
177+
178+ SECTION (" Types can be enforced to be trivial" , " [standard_rules]" )
179+ {
180+ CHECK (assert_is_trivial<EmptyType>());
181+ CHECK (assert_is_trivial<UnconstructibleType>());
182+ CHECK (!assert_is_trivial<EmptyTypeWithExplicitConstructor>());
183+ CHECK (!assert_is_trivial<EmptyTypeWithExplicitNoexceptConstructor>());
184+ CHECK (!assert_is_trivial<CopyOnlyType>());
185+ CHECK (!assert_is_trivial<MoveOnlyType>());
186+ CHECK (!assert_is_trivial<UniquePtrType>());
187+ }
188+ }
0 commit comments