Sequoia
Loading...
Searching...
No Matches
MoveOnlyAllocationTestCore.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2020. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
19
20namespace sequoia::testing
21{
27 template<test_mode Mode>
29 {
30 public:
31 constexpr static test_mode mode{Mode};
32
34
35 template<class Self, moveonly T, class U, std::invocable<T&> Mutator, alloc_getter<T>... Getters>
36 requires checkable_against_for_semantics<Mode, T, U> && (!std::totally_ordered<T>) && (sizeof...(Getters) > 0)
37 void check_semantics(this Self& self,
38 const reporter& description,
39 T&& x,
40 T&& y,
41 const U& xEquivalent,
42 const U& yEquivalent,
43 const U& movedFromPostConstruction,
44 const U& movedFromPostAssignment,
45 Mutator yMutator,
46 const allocation_info<T, Getters>&... info)
47 {
48 testing::check_semantics(move_only_message(self.report(description)),
49 self.m_Logger,
50 std::move(x),
51 std::move(y),
52 xEquivalent,
53 yEquivalent,
54 optional_ref<const U>{movedFromPostConstruction},
55 optional_ref<const U>{movedFromPostAssignment},
56 std::move(yMutator),
57 info...);
58 }
59
60 template<class Self, moveonly T, class U, std::invocable<T&> Mutator, alloc_getter<T>... Getters>
61 requires checkable_against_for_semantics<Mode, T, U> && (!std::totally_ordered<T>) && (sizeof...(Getters) > 0)
62 void check_semantics(this Self& self,
63 const reporter& description,
64 T&& x,
65 T&& y,
66 const U& xEquivalent,
67 const U& yEquivalent,
68 Mutator yMutator,
69 const allocation_info<T, Getters>&... info)
70 {
71 testing::check_semantics(move_only_message(self.report(description)),
72 self.m_Logger,
73 std::move(x),
74 std::move(y),
75 xEquivalent,
76 yEquivalent,
77 optional_ref<const U>{},
78 optional_ref<const U>{},
79 std::move(yMutator),
80 info...);
81 }
82
83 template
84 <
85 class Self,
86 moveonly T,
89 std::invocable<T&> Mutator,
90 alloc_getter<T>... Getters
91 >
92 requires (!std::totally_ordered<T>) && (sizeof...(Getters) > 0)
93 std::pair<T,T> check_semantics(this Self& self,
94 const reporter& description,
95 xMaker xFn,
96 yMaker yFn,
97 const T& movedFromPostConstruction,
98 const T& movedFromPostAssignment,
99 Mutator yMutator,
100 const allocation_info<T, Getters>&... info)
101 {
102 return testing::check_semantics(move_only_message(self.report(description)),
103 self.m_Logger,
104 std::move(xFn),
105 std::move(yFn),
106 optional_ref<const T>{movedFromPostConstruction},
107 optional_ref<const T>{movedFromPostAssignment},
108 std::move(yMutator),
109 info...);
110 }
111
112 template
113 <
114 class Self,
115 moveonly T,
118 std::invocable<T&> Mutator,
119 alloc_getter<T>... Getters
120 >
121 requires (!std::totally_ordered<T>) && (sizeof...(Getters) > 0)
122 std::pair<T,T> check_semantics(this Self& self, const reporter& description, xMaker xFn, yMaker yFn, Mutator yMutator, const allocation_info<T, Getters>&... info)
123 {
124 return testing::check_semantics(move_only_message(self.report(description)),
125 self.m_Logger,
126 std::move(xFn),
127 std::move(yFn),
128 optional_ref<const T>{},
129 optional_ref<const T>{},
130 std::move(yMutator),
131 info...);
132 }
133
134 template<class Self, moveonly T, class U, std::invocable<T&> Mutator, alloc_getter<T>... Getters>
135 requires checkable_against_for_semantics<Mode, T, U> && std::totally_ordered<T> && (sizeof...(Getters) > 0)
136 void check_semantics(this Self& self,
137 const reporter& description,
138 T&& x,
139 T&& y,
140 const U& xEquivalent,
141 const U& yEquivalent,
142 const U& movedFromPostConstruction,
143 const U& movedFromPostAssignment,
144 std::weak_ordering order,
145 Mutator yMutator,
146 const allocation_info<T, Getters>&... info)
147 {
148 testing::check_semantics(move_only_message(self.report(description)),
149 self.m_Logger,
150 std::move(x),
151 std::move(y),
152 xEquivalent,
153 yEquivalent,
154 optional_ref<const U>{movedFromPostConstruction},
155 optional_ref<const U>{movedFromPostAssignment},
156 order,
157 std::move(yMutator),
158 info...);
159 }
160
161 template<class Self, moveonly T, class U, std::invocable<T&> Mutator, alloc_getter<T>... Getters>
162 requires checkable_against_for_semantics<Mode, T, U> && std::totally_ordered<T> && (sizeof...(Getters) > 0)
163 void check_semantics(this Self& self,
164 const reporter& description,
165 T&& x,
166 T&& y,
167 const U& xEquivalent,
168 const U& yEquivalent,
169 std::weak_ordering order,
170 Mutator yMutator,
171 const allocation_info<T, Getters>&... info)
172 {
173 testing::check_semantics(move_only_message(self.report(description)),
174 self.m_Logger,
175 std::move(x),
176 std::move(y),
177 xEquivalent,
178 yEquivalent,
179 optional_ref<const U>{},
180 optional_ref<const U>{},
181 order,
182 std::move(yMutator),
183 info...);
184 }
185
186 template
187 <
188 class Self,
189 moveonly T,
192 std::invocable<T&> Mutator,
193 alloc_getter<T>... Getters
194 >
195 requires std::totally_ordered<T> && (sizeof...(Getters) > 0)
196 std::pair<T, T> check_semantics(this Self& self,
197 const reporter& description,
198 xMaker xFn,
199 yMaker yFn,
200 const T& movedFromPostConstruction,
201 const T& movedFromPostAssignment,
202 std::weak_ordering order,
203 Mutator yMutator,
205 {
206 return testing::check_semantics(move_only_message(self.report(description)),
207 self.m_Logger,
208 std::move(xFn),
209 std::move(yFn),
210 optional_ref<const T>{movedFromPostConstruction},
211 optional_ref<const T>{movedFromPostAssignment},
212 order,
213 std::move(yMutator),
214 info...);
215 }
216
217 template
218 <
219 class Self,
220 moveonly T,
223 std::invocable<T&> Mutator,
224 alloc_getter<T>... Getters
225 >
226 requires std::totally_ordered<T> && (sizeof...(Getters) > 0)
227 std::pair<T,T> check_semantics(this Self& self,
228 const reporter& description,
229 xMaker xFn,
230 yMaker yFn,
231 std::weak_ordering order,
232 Mutator yMutator,
234 {
235 return testing::check_semantics(move_only_message(self.report(description)),
236 self.m_Logger,
237 std::move(xFn),
238 std::move(yFn),
239 optional_ref<const T>{},
240 optional_ref<const T>{},
241 order,
242 std::move(yMutator),
243 info...);
244 }
245 protected:
247
249 move_only_allocation_extender& operator=(move_only_allocation_extender&&) noexcept = default;
250 };
251
271 template<test_mode Mode>
272 class basic_move_only_allocation_test : public basic_test<Mode, move_only_allocation_extender<Mode>>
273 {
274 public:
275 using basic_test<Mode, move_only_allocation_extender<Mode>>::basic_test;
276
279 protected:
282
284
285 template<class Self>
286 void do_allocation_tests(this Self& self)
287 {
288 self.template test_allocation<false, false>();
289 self.template test_allocation<false, true>();
290 self.template test_allocation<true, false>();
291 self.template test_allocation<true, true>();
292 }
293 };
294
299}
Utilities for allocation testing.
Utilities for performing allocation checks of move-only types.
Extension for testing classes exhibiting move-only semantics.
Class for use with a container possessing a (shared counting) allocator.
Definition: AllocationCheckers.hpp:425
Templated on the test_mode, this forms the basis of all allocation tests for move-only types.
Definition: MoveOnlyAllocationTestCore.hpp:273
class template from which all concrete tests should derive.
Definition: FreeTestCore.hpp:144
class template for plugging into the checker class template to provide allocation checks for move-onl...
Definition: MoveOnlyAllocationTestCore.hpp:29
Definition: Output.hpp:186
The move-only version of sequoia::pseudoregular.
Definition: Concepts.hpp:43
Supplements std::regular_invocable.
Definition: Concepts.hpp:31
Definition: AllocationCheckersTraits.hpp:24