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