Ocean
Loading...
Searching...
No Matches
TestMoveBehavior.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_MOVE_BEHAVIOR_H
9#define META_OCEAN_TEST_TESTBASE_TEST_MOVE_BEHAVIOR_H
10
13
14#include "ocean/base/Lock.h"
16
17namespace Ocean
18{
19
20namespace Test
21{
22
23namespace TestBase
24{
25
26/**
27 * This class tests the move behavior of the underlying C++ std implementation.
28 * @ingroup testbase
29 */
30class OCEAN_TEST_BASE_EXPORT TestMoveBehavior
31{
32 protected:
33
34 /**
35 * Simple helper class counting operations.
36 */
37 class OperationCounter : public Singleton<OperationCounter>
38 {
39 friend class Singleton<OperationCounter>;
40
41 public:
42
43 /**
44 * Increments individual operation counters.
45 * @param constructor True, to increment the constructor counter
46 * @param copyConstructor True, to increment the copyConstructor counter
47 * @param moveConstructor True, to increment the moveConstructor counter
48 * @param assignOperator True, to increment the assignOperator counter
49 * @param moveOperator True, to increment the moveOperator counter
50 */
51 void increment(const bool constructor, const bool copyConstructor, const bool moveConstructor, const bool assignOperator, const bool moveOperator);
52
53 /**
54 * Returns the constructor counter.
55 * @return The constructor counter
56 */
57 size_t constructor() const;
58
59 /**
60 * Returns the copyConstructor counter.
61 * @return The copyConstructor counter
62 */
63 size_t copyConstructor() const;
64
65 /**
66 * Returns the moveConstructor counter.
67 * @return The moveConstructor counter
68 */
69 size_t moveConstructor() const;
70
71 /**
72 * Returns the assignOperator counter.
73 * @return The assignOperator counter
74 */
75 size_t assignOperator() const;
76
77 /**
78 * Returns the moveOperator counter.
79 * @return The moveOperator counter
80 */
81 size_t moveOperator() const;
82
83 /**
84 * Resets all counters.
85 */
86 void reset();
87
88 protected:
89
90 /**
91 * Default conststructor.
92 */
94
95 protected:
96
97 /// The constructor counter.
99
100 /// The copyConstructor counter.
102
103 /// The moveConstructor counter.
105
106 /// The assignOperator counter.
108
109 /// The moveOperator counter.
111
112 /// The lock object.
113 mutable Lock lock_;
114 };
115
116 /**
117 * Simple object with copy and move semantic without 'noexcept' keywords.
118 */
119 class Object
120 {
121 public:
122
123 /**
124 * Crates a new object.
125 * @param member The member value to be set
126 */
127 Object(const int member);
128
129 /**
130 * Copy constructor.
131 * @param object The object to be copied
132 */
133 Object(const Object& object);
134
135 /**
136 * Move constructor.
137 * @param object The object to be moved
138 */
139 Object(Object&& object);
140
141 /**
142 * Copy constructor.
143 * @param object The object to be copied
144 * @return The reference to this object
145 */
146 Object& operator=(const Object& object);
147
148 /**
149 * Move constructor.
150 * @param object The object to be moved
151 * @return The reference to this object
152 */
154
155 protected:
156
157 /// The member of this object;
158 int member_ = 0;
159 };
160
161 /**
162 * Simple object with copy and move semantic with 'noexcept' keywords.
163 */
165 {
166 public:
167
168 /**
169 * Crates a new object.
170 * @param member The member value to be set
171 */
172 NonExceptObject(const int member);
173
174 /**
175 * Copy constructor.
176 * @param object The object to be copied
177 */
179
180 /**
181 * Move constructor.
182 * @param object The object to be moved
183 */
185
186 /**
187 * Copy constructor.
188 * @param object The object to be copied
189 * @return The reference to this object
190 */
192
193 /**
194 * Move constructor.
195 * @param object The object to be moved
196 * @return The reference to this object
197 */
199
200 protected:
201
202 /// The member of this object;
203 int member_ = 0;
204 };
205
206 /**
207 * Definition of a vector holding objects.
208 */
209 using Objects = std::vector<Object>;
210
211 /**
212 * Definition of a vector holding objects.
213 */
214 using NonExceptObjects = std::vector<NonExceptObject>;
215
216 public:
217
218 /**
219 * Tests all lock functions.
220 * @param testDuration The number of seconds for each test, with range (0, infinity)
221 * @param selector The test selector to control which tests to run
222 * @return True, if succeeded
223 */
224 static bool test(const double testDuration, const TestSelector& selector = TestSelector());
225
226 /**
227 * Tests the behavior for the default object.
228 * @param testDuration The number of seconds for each test, with range (0, infinity)
229 * @return True, if succeeded
230 */
231 static bool testDefaultObject(const double testDuration);
232
233 /**
234 * Tests the behavior for the object with nonexcept keyword.
235 * @param testDuration The number of seconds for each test, with range (0, infinity)
236 * @return True, if succeeded
237 */
238 static bool testNonExceptObject(const double testDuration);
239};
240
241}
242
243}
244
245}
246
247#endif // META_OCEAN_TEST_TESTBASE_TEST_MOVE_BEHAVIOR_H
This class implements a recursive lock object.
Definition Lock.h:31
This template class is the base class for all singleton objects.
Definition Singleton.h:71
Simple object with copy and move semantic with 'noexcept' keywords.
Definition TestMoveBehavior.h:165
NonExceptObject & operator=(NonExceptObject &&object) noexcept
Move constructor.
NonExceptObject & operator=(const NonExceptObject &object)
Copy constructor.
NonExceptObject(NonExceptObject &&object) noexcept
Move constructor.
NonExceptObject(const int member)
Crates a new object.
NonExceptObject(const NonExceptObject &object)
Copy constructor.
Simple object with copy and move semantic without 'noexcept' keywords.
Definition TestMoveBehavior.h:120
Object(const int member)
Crates a new object.
Object & operator=(const Object &object)
Copy constructor.
Object(Object &&object)
Move constructor.
Object(const Object &object)
Copy constructor.
Object & operator=(Object &&object)
Move constructor.
Simple helper class counting operations.
Definition TestMoveBehavior.h:38
size_t assignOperator_
The assignOperator counter.
Definition TestMoveBehavior.h:107
size_t copyConstructor() const
Returns the copyConstructor counter.
void increment(const bool constructor, const bool copyConstructor, const bool moveConstructor, const bool assignOperator, const bool moveOperator)
Increments individual operation counters.
size_t copyConstructor_
The copyConstructor counter.
Definition TestMoveBehavior.h:101
size_t assignOperator() const
Returns the assignOperator counter.
Lock lock_
The lock object.
Definition TestMoveBehavior.h:113
size_t constructor_
The constructor counter.
Definition TestMoveBehavior.h:98
size_t moveOperator_
The moveOperator counter.
Definition TestMoveBehavior.h:110
size_t constructor() const
Returns the constructor counter.
size_t moveConstructor_
The moveConstructor counter.
Definition TestMoveBehavior.h:104
size_t moveConstructor() const
Returns the moveConstructor counter.
size_t moveOperator() const
Returns the moveOperator counter.
This class tests the move behavior of the underlying C++ std implementation.
Definition TestMoveBehavior.h:31
static bool test(const double testDuration, const TestSelector &selector=TestSelector())
Tests all lock functions.
std::vector< NonExceptObject > NonExceptObjects
Definition of a vector holding objects.
Definition TestMoveBehavior.h:214
std::vector< Object > Objects
Definition of a vector holding objects.
Definition TestMoveBehavior.h:209
static bool testDefaultObject(const double testDuration)
Tests the behavior for the default object.
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