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
12
13namespace Ocean
14{
15
16namespace Test
17{
18
19namespace TestBase
20{
21
22/**
23 * This class implements tests for StackHeapVector.
24 * @ingroup testbase
25 */
26class OCEAN_TEST_BASE_EXPORT TestStackHeapVector
27{
28 protected:
29
30 /**
31 * This class implements a test element allowing to test copy vs. move behavior.
32 */
34 {
35 public:
36
37 /// The value offset when the element is moved.
38 static constexpr size_t moveOffset_ = 1000;
39
40 /// The value offset when the element is copied.
41 static constexpr size_t copyOffset_ = 2000;
42
43 public:
44
45 /**
46 * Default constructor.
47 */
48 TestElement() = default;
49
50 /**
51 * Creates a new test element with a given value.
52 * @param value The value to be set
53 */
54 explicit inline TestElement(const size_t value);
55
56 /**
57 * Move constructor.
58 * The value will be incremented by moveOffset_.
59 * @param element The element to be moved
60 */
61 inline TestElement(TestElement&& element) noexcept;
62
63 /**
64 * Copy constructor.
65 * The value will be incremented by copyOffset_.
66 * @param element The element to be copied
67 */
68 inline TestElement(const TestElement& element);
69
70 /**
71 * Returns the value of this element.
72 * @return The element's value
73 */
74 inline size_t value() const;
75
76 /**
77 * Move operator.
78 * The value will be incremented by moveOffset_.
79 * @param element The element to be moved
80 * @return Reference to this object
81 */
82 inline TestElement& operator=(TestElement&& element) noexcept;
83
84 /**
85 * Copy operator.
86 * @param element The element to be copied
87 * The value will be incremented by copyOffset_.
88 * @return Reference to this object
89 */
90 inline TestElement& operator=(const TestElement& element);
91
92 protected:
93
94 /// The value of the element.
95 size_t value_ = size_t(-1);
96 };
97
98 public:
99
100 /**
101 * Invokes all tests.
102 * @param testDuration Number of seconds for each test, with range (0, infinity)
103 * @return True, if succeeded
104 */
105 static bool test(const double testDuration);
106
107 /**
108 * Tests the constructor.
109 * @param testDuration Number of seconds for each test, with range (0, infinity)
110 * @return True, if succeeded
111 */
112 static bool testConstructor(const double testDuration);
113
114 /**
115 * Tests the assign function.
116 * @param testDuration Number of seconds for each test, with range (0, infinity)
117 * @return True, if succeeded
118 */
119 static bool testAssign(const double testDuration);
120
121 /**
122 * Tests push back function.
123 * @param testDuration Number of seconds for each test, with range (0, infinity)
124 * @return True, if succeeded
125 */
126 static bool testPushBack(const double testDuration);
127
128 /**
129 * Tests resize function.
130 * @param testDuration Number of seconds for each test, with range (0, infinity)
131 * @return True, if succeeded
132 */
133 static bool testResize(const double testDuration);
134
135 /**
136 * Tests the performance of the stack heap vector.
137 * @param testDuration Number of seconds for each test, with range (0, infinity)
138 * @return True, if succeeded
139 */
140 static bool testPerformance(const double testDuration);
141
142 protected:
143
144 /**
145 * Tests the constructor
146 * @param testDuration Number of seconds for each test, with range (0, infinity)
147 * @return True, if succeeded
148 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
149 */
150 template <size_t tStackCapacity>
151 static bool testConstructor(double testDuration);
152
153 /**
154 * Tests the assign function.
155 * @param testDuration Number of seconds for each test, with range (0, infinity)
156 * @return True, if succeeded
157 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
158 */
159 template <size_t tStackCapacity>
160 static bool testAssign(const double testDuration);
161
162 /**
163 * Tests push back function.
164 * @param testDuration Number of seconds for each test, with range (0, infinity)
165 * @return True, if succeeded
166 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
167 */
168 template <size_t tStackCapacity>
169 static bool testPushBack(const double testDuration);
170
171 /**
172 * Tests resize function.
173 * @param testDuration Number of seconds for each test, with range (0, infinity)
174 * @return True, if succeeded
175 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
176 */
177 template <size_t tStackCapacity>
178 static bool testResize(const double testDuration);
179
180 /**
181 * Tests the performance of the stack heap vector.
182 * @param testDuration Number of seconds for each test, with range (0, infinity)
183 * @return True, if succeeded
184 * @tparam tStackCapacity Size of the vector's stack memory, with range [1, infinity)
185 */
186 template <size_t tStackCapacity>
187 static bool testPerformance(const double testDuration);
188};
189
191 value_(value)
192{
193 // nothing to do here
194}
195
197{
198 *this = std::move(element);
199}
200
202{
203 *this = element;
204}
205
207{
208 return value_;
209}
210
212{
213 if (this != &element)
214 {
215 value_ = element.value_ + moveOffset_;
216 element.value_ = size_t(-1);
217 }
218
219 return *this;
220}
221
223{
224 value_ = element.value_ + copyOffset_;
225
226 return *this;
227}
228
229}
230
231}
232
233}
234
235#endif // META_OCEAN_TEST_TESTBASE_TEST_STACK_HEAP_VECTOR_H
This class implements a test element allowing to test copy vs.
Definition TestStackHeapVector.h:34
TestElement & operator=(TestElement &&element) noexcept
Move operator.
Definition TestStackHeapVector.h:211
size_t value() const
Returns the value of this element.
Definition TestStackHeapVector.h:206
size_t value_
The value of the element.
Definition TestStackHeapVector.h:95
This class implements tests for StackHeapVector.
Definition TestStackHeapVector.h:27
static bool testPushBack(const double testDuration)
Tests push 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 testPerformance(const double testDuration)
Tests the performance of the stack heap vector.
static bool testConstructor(double testDuration)
Tests the constructor.
static bool testResize(const double testDuration)
Tests resize function.
static bool testAssign(const double testDuration)
Tests the assign function.
static bool testAssign(const double testDuration)
Tests the assign function.
static bool testConstructor(const double testDuration)
Tests the constructor.
static bool test(const double testDuration)
Invokes all tests.
static bool testPushBack(const double testDuration)
Tests push back function.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15