Ocean
Loading...
Searching...
No Matches
TestStackHeapVector.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTBASE_TEST_STACK_HEAP_VECTOR_H
9#define META_OCEAN_TEST_TESTBASE_TEST_STACK_HEAP_VECTOR_H
10
13
14namespace Ocean
15{
16
17namespace Test
18{
19
20namespace TestBase
21{
22
23/**
24 * This class implements tests for StackHeapVector.
25 * @ingroup testbase
26 */
27class OCEAN_TEST_BASE_EXPORT TestStackHeapVector
28{
29 protected:
30
31 /**
32 * This class implements a test element allowing to test copy vs. move behavior.
33 */
35 {
36 public:
37
38 /// The value offset when the element is moved.
39 static constexpr size_t moveOffset_ = 1000;
40
41 /// The value offset when the element is copied.
42 static constexpr size_t copyOffset_ = 2000;
43
44 public:
45
46 /**
47 * Default constructor.
48 */
49 TestElement() = default;
50
51 /**
52 * Creates a new test element with a given value.
53 * @param value The value to be set
54 */
55 explicit inline TestElement(const size_t value);
56
57 /**
58 * Move constructor.
59 * The value will be incremented by moveOffset_.
60 * @param element The element to be moved
61 */
62 inline TestElement(TestElement&& element) noexcept;
63
64 /**
65 * Copy constructor.
66 * The value will be incremented by copyOffset_.
67 * @param element The element to be copied
68 */
69 inline TestElement(const TestElement& element);
70
71 /**
72 * Returns the value of this element.
73 * @return The element's value
74 */
75 inline size_t value() const;
76
77 /**
78 * Move operator.
79 * The value will be incremented by moveOffset_.
80 * @param element The element to be moved
81 * @return Reference to this object
82 */
83 inline TestElement& operator=(TestElement&& element) noexcept;
84
85 /**
86 * Copy operator.
87 * @param element The element to be copied
88 * The value will be incremented by copyOffset_.
89 * @return Reference to this object
90 */
91 inline TestElement& operator=(const TestElement& element);
92
93 protected:
94
95 /// The value of the element.
96 size_t value_ = size_t(-1);
97 };
98
99 public:
100
101 /**
102 * Invokes all tests.
103 * @param testDuration Number of seconds for each test, with range (0, infinity)
104 * @param selector The test selector to filter specific tests
105 * @return True, if succeeded
106 */
107 static bool test(const double testDuration, const TestSelector& selector = TestSelector());
108
109 /**
110 * Tests the default constructor.
111 * @param testDuration Number of seconds for each test, with range (0, infinity)
112 * @return True, if succeeded
113 */
114 static bool testDefaultConstructor(const double testDuration);
115
116 /**
117 * Tests the size-only constructor.
118 * @param testDuration Number of seconds for each test, with range (0, infinity)
119 * @return True, if succeeded
120 */
121 static bool testSizeConstructor(const double testDuration);
122
123 /**
124 * Tests the size and element constructor.
125 * @param testDuration Number of seconds for each test, with range (0, infinity)
126 * @return True, if succeeded
127 */
128 static bool testSizeElementConstructor(const double testDuration);
129
130 /**
131 * Tests the move constructor from std::vector.
132 * @param testDuration Number of seconds for each test, with range (0, infinity)
133 * @return True, if succeeded
134 */
135 static bool testMoveConstructorFromVector(const double testDuration);
136
137 /**
138 * Tests the copy constructor from std::vector.
139 * @param testDuration Number of seconds for each test, with range (0, infinity)
140 * @return True, if succeeded
141 */
142 static bool testCopyConstructorFromVector(const double testDuration);
143
144 /**
145 * Tests the initializer list constructor.
146 * @param testDuration Number of seconds for each test, with range (0, infinity)
147 * @return True, if succeeded
148 */
149 static bool testInitializerListConstructor(const double testDuration);
150
151 /**
152 * Tests the copy constructor from another StackHeapVector.
153 * @param testDuration Number of seconds for each test, with range (0, infinity)
154 * @return True, if succeeded
155 */
156 static bool testCopyConstructor(const double testDuration);
157
158 /**
159 * Tests the move constructor from another StackHeapVector.
160 * @param testDuration Number of seconds for each test, with range (0, infinity)
161 * @return True, if succeeded
162 */
163 static bool testMoveConstructor(const double testDuration);
164
165 /**
166 * Tests the copy assignment operator.
167 * @param testDuration Number of seconds for each test, with range (0, infinity)
168 * @return True, if succeeded
169 */
170 static bool testCopyAssignment(const double testDuration);
171
172 /**
173 * Tests the move assignment operator.
174 * @param testDuration Number of seconds for each test, with range (0, infinity)
175 * @return True, if succeeded
176 */
177 static bool testMoveAssignment(const double testDuration);
178
179 /**
180 * Tests the equality operator.
181 * @param testDuration Number of seconds for each test, with range (0, infinity)
182 * @return True, if succeeded
183 */
184 static bool testEquality(const double testDuration);
185
186 /**
187 * Tests the assign function.
188 * @param testDuration Number of seconds for each test, with range (0, infinity)
189 * @return True, if succeeded
190 */
191 static bool testAssign(const double testDuration);
192
193 /**
194 * Tests push back function.
195 * @param testDuration Number of seconds for each test, with range (0, infinity)
196 * @return True, if succeeded
197 */
198 static bool testPushBack(const double testDuration);
199
200 /**
201 * Tests resize function.
202 * @param testDuration Number of seconds for each test, with range (0, infinity)
203 * @return True, if succeeded
204 */
205 static bool testResize(const double testDuration);
206
207 /**
208 * Tests emplace back function.
209 * @param testDuration Number of seconds for each test, with range (0, infinity)
210 * @return True, if succeeded
211 */
212 static bool testEmplaceBack(const double testDuration);
213
214 /**
215 * Tests pop back function.
216 * @param testDuration Number of seconds for each test, with range (0, infinity)
217 * @return True, if succeeded
218 */
219 static bool testPopBack(const double testDuration);
220
221 /**
222 * Tests front and back functions.
223 * @param testDuration Number of seconds for each test, with range (0, infinity)
224 * @return True, if succeeded
225 */
226 static bool testFrontBack(const double testDuration);
227
228 /**
229 * Tests reserve function.
230 * @param testDuration Number of seconds for each test, with range (0, infinity)
231 * @return True, if succeeded
232 */
233 static bool testReserve(const double testDuration);
234
235 /**
236 * Tests the performance of the stack heap vector.
237 * @param testDuration Number of seconds for each test, with range (0, infinity)
238 * @return True, if succeeded
239 */
240 static bool testPerformance(const double testDuration);
241
242 protected:
243
244 /**
245 * Tests the default constructor
246 * @param testDuration Number of seconds for each test, with range (0, infinity)
247 * @return True, if succeeded
248 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
249 */
250 template <size_t tStackCapacity>
251 static bool testDefaultConstructor(const double testDuration);
252
253 /**
254 * Tests the size-only constructor
255 * @param testDuration Number of seconds for each test, with range (0, infinity)
256 * @return True, if succeeded
257 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
258 */
259 template <size_t tStackCapacity>
260 static bool testSizeConstructor(const double testDuration);
261
262 /**
263 * Tests the size and element constructor
264 * @param testDuration Number of seconds for each test, with range (0, infinity)
265 * @return True, if succeeded
266 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
267 */
268 template <size_t tStackCapacity>
269 static bool testSizeElementConstructor(const double testDuration);
270
271 /**
272 * Tests the move constructor from std::vector
273 * @param testDuration Number of seconds for each test, with range (0, infinity)
274 * @return True, if succeeded
275 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
276 */
277 template <size_t tStackCapacity>
278 static bool testMoveConstructorFromVector(const double testDuration);
279
280 /**
281 * Tests the copy constructor from std::vector
282 * @param testDuration Number of seconds for each test, with range (0, infinity)
283 * @return True, if succeeded
284 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
285 */
286 template <size_t tStackCapacity>
287 static bool testCopyConstructorFromVector(const double testDuration);
288
289 /**
290 * Tests the initializer list constructor
291 * @param testDuration Number of seconds for each test, with range (0, infinity)
292 * @return True, if succeeded
293 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
294 */
295 template <size_t tStackCapacity>
296 static bool testInitializerListConstructor(const double testDuration);
297
298 /**
299 * Tests the copy constructor from another StackHeapVector
300 * @param testDuration Number of seconds for each test, with range (0, infinity)
301 * @return True, if succeeded
302 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
303 */
304 template <size_t tStackCapacity>
305 static bool testCopyConstructor(const double testDuration);
306
307 /**
308 * Tests the move constructor from another StackHeapVector
309 * @param testDuration Number of seconds for each test, with range (0, infinity)
310 * @return True, if succeeded
311 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
312 */
313 template <size_t tStackCapacity>
314 static bool testMoveConstructor(const double testDuration);
315
316 /**
317 * Tests the copy assignment operator
318 * @param testDuration Number of seconds for each test, with range (0, infinity)
319 * @return True, if succeeded
320 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
321 */
322 template <size_t tStackCapacity>
323 static bool testCopyAssignment(const double testDuration);
324
325 /**
326 * Tests the move assignment operator
327 * @param testDuration Number of seconds for each test, with range (0, infinity)
328 * @return True, if succeeded
329 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
330 */
331 template <size_t tStackCapacity>
332 static bool testMoveAssignment(const double testDuration);
333
334 /**
335 * Tests the equality operator
336 * @param testDuration Number of seconds for each test, with range (0, infinity)
337 * @return True, if succeeded
338 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
339 */
340 template <size_t tStackCapacity>
341 static bool testEquality(const double testDuration);
342
343 /**
344 * Tests the assign function.
345 * @param testDuration Number of seconds for each test, with range (0, infinity)
346 * @return True, if succeeded
347 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
348 */
349 template <size_t tStackCapacity>
350 static bool testAssign(const double testDuration);
351
352 /**
353 * Tests push back function.
354 * @param testDuration Number of seconds for each test, with range (0, infinity)
355 * @return True, if succeeded
356 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
357 */
358 template <size_t tStackCapacity>
359 static bool testPushBack(const double testDuration);
360
361 /**
362 * Tests resize function.
363 * @param testDuration Number of seconds for each test, with range (0, infinity)
364 * @return True, if succeeded
365 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
366 */
367 template <size_t tStackCapacity>
368 static bool testResize(const double testDuration);
369
370 /**
371 * Tests emplace back function.
372 * @param testDuration Number of seconds for each test, with range (0, infinity)
373 * @return True, if succeeded
374 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
375 */
376 template <size_t tStackCapacity>
377 static bool testEmplaceBack(const double testDuration);
378
379 /**
380 * Tests pop back function.
381 * @param testDuration Number of seconds for each test, with range (0, infinity)
382 * @return True, if succeeded
383 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
384 */
385 template <size_t tStackCapacity>
386 static bool testPopBack(const double testDuration);
387
388 /**
389 * Tests front and back functions.
390 * @param testDuration Number of seconds for each test, with range (0, infinity)
391 * @return True, if succeeded
392 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
393 */
394 template <size_t tStackCapacity>
395 static bool testFrontBack(const double testDuration);
396
397 /**
398 * Tests reserve function.
399 * @param testDuration Number of seconds for each test, with range (0, infinity)
400 * @return True, if succeeded
401 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
402 */
403 template <size_t tStackCapacity>
404 static bool testReserve(const double testDuration);
405
406 /**
407 * Tests the performance of the stack heap vector.
408 * @param testDuration Number of seconds for each test, with range (0, infinity)
409 * @return True, if succeeded
410 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
411 */
412 template <size_t tStackCapacity>
413 static bool testPerformance(const double testDuration);
414};
415
417 value_(value)
418{
419 // nothing to do here
420}
421
423{
424 *this = std::move(element);
425}
426
428{
429 *this = element;
430}
431
433{
434 return value_;
435}
436
438{
439 if (this != &element)
440 {
441 value_ = element.value_ + moveOffset_;
442 element.value_ = size_t(-1);
443 }
444
445 return *this;
446}
447
449{
450 value_ = element.value_ + copyOffset_;
451
452 return *this;
453}
454
455}
456
457}
458
459}
460
461#endif // META_OCEAN_TEST_TESTBASE_TEST_STACK_HEAP_VECTOR_H
This class implements a test element allowing to test copy vs.
Definition TestStackHeapVector.h:35
TestElement & operator=(TestElement &&element) noexcept
Move operator.
Definition TestStackHeapVector.h:437
size_t value() const
Returns the value of this element.
Definition TestStackHeapVector.h:432
size_t value_
The value of the element.
Definition TestStackHeapVector.h:96
This class implements tests for StackHeapVector.
Definition TestStackHeapVector.h:28
static bool testCopyAssignment(const double testDuration)
Tests the copy assignment operator.
static bool testSizeConstructor(const double testDuration)
Tests the size-only constructor.
static bool testPushBack(const double testDuration)
Tests push back function.
static bool testEmplaceBack(const double testDuration)
Tests emplace back function.
static bool testCopyAssignment(const double testDuration)
Tests the copy assignment operator.
static bool testPopBack(const double testDuration)
Tests pop back function.
static bool testMoveAssignment(const double testDuration)
Tests the move assignment operator.
static bool testEmplaceBack(const double testDuration)
Tests emplace back function.
static bool testPerformance(const double testDuration)
Tests the performance of the stack heap vector.
static bool testResize(const double testDuration)
Tests resize function.
static bool testMoveConstructor(const double testDuration)
Tests the move constructor from another StackHeapVector.
static bool testPerformance(const double testDuration)
Tests the performance of the stack heap vector.
static bool testReserve(const double testDuration)
Tests reserve function.
static bool testSizeConstructor(const double testDuration)
Tests the size-only constructor.
static bool testCopyConstructorFromVector(const double testDuration)
Tests the copy constructor from std::vector.
static bool testMoveConstructorFromVector(const double testDuration)
Tests the move constructor from std::vector.
static bool testCopyConstructorFromVector(const double testDuration)
Tests the copy constructor from std::vector.
static bool testResize(const double testDuration)
Tests resize function.
static bool testDefaultConstructor(const double testDuration)
Tests the default constructor.
static bool testInitializerListConstructor(const double testDuration)
Tests the initializer list constructor.
static bool testDefaultConstructor(const double testDuration)
Tests the default constructor.
static bool testCopyConstructor(const double testDuration)
Tests the copy constructor from another StackHeapVector.
static bool testMoveConstructor(const double testDuration)
Tests the move constructor from another StackHeapVector.
static bool testSizeElementConstructor(const double testDuration)
Tests the size and element constructor.
static bool testAssign(const double testDuration)
Tests the assign function.
static bool testAssign(const double testDuration)
Tests the assign function.
static bool testPopBack(const double testDuration)
Tests pop back function.
static bool testMoveAssignment(const double testDuration)
Tests the move assignment operator.
static bool testEquality(const double testDuration)
Tests the equality operator.
static bool testFrontBack(const double testDuration)
Tests front and back functions.
static bool testCopyConstructor(const double testDuration)
Tests the copy constructor from another StackHeapVector.
static bool testMoveConstructorFromVector(const double testDuration)
Tests the move constructor from std::vector.
static bool testReserve(const double testDuration)
Tests reserve function.
static bool test(const double testDuration, const TestSelector &selector=TestSelector())
Invokes all tests.
static bool testEquality(const double testDuration)
Tests the equality operator.
static bool testSizeElementConstructor(const double testDuration)
Tests the size and element constructor.
static bool testInitializerListConstructor(const double testDuration)
Tests the initializer list constructor.
static bool testPushBack(const double testDuration)
Tests push back function.
static bool testFrontBack(const double testDuration)
Tests front and back functions.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
The namespace covering the entire Ocean framework.
Definition Accessor.h:15