Ocean
TestScopedFunction.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_SCOPED_FUNCTION_H
9 #define META_OCEAN_TEST_TESTBASE_TEST_SCOPED_FUNCTION_H
10 
12 
13 #include "ocean/base/Lock.h"
14 #include "ocean/base/Singleton.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Test
20 {
21 
22 namespace TestBase
23 {
24 
25 /**
26  * This class implement a test for the TestScopedFunction class.
27  * @ingroup testbase
28  */
29 class OCEAN_TEST_BASE_EXPORT TestScopedFunction
30 {
31  protected:
32 
33  /**
34  * Helper class allowing to determine whether a function was invoked or not.
35  */
36  class Object
37  {
38  public:
39 
40  /**
41  * Default constructor.
42  */
43  Object() = default;
44 
45  /**
46  * Invokes a function.
47  */
48  inline void invokeFunction();
49 
50  /**
51  * Returns the number of times the function has been invoked
52  * @return The number of function calls, with range [0, infinity)
53  */
54  inline size_t number() const;
55 
56  protected:
57 
58  /**
59  * Disabled copy constructor.
60  */
61  Object(const Object&) = delete;
62 
63  /**
64  * Disabled assign operator.
65  * @return Reference to this object
66  */
67  Object& operator=(const Object&) = delete;
68 
69  protected:
70 
71  /// The number of times the function has been invoked.
72  size_t number_ = 0;
73  };
74 
75  public:
76 
77  /**
78  * Tests the ScopedFunction class.
79  * @param testDuration Number of seconds for each test, with range (0, infinity)
80  * @return True, if succeeded
81  */
82  static bool test(const double testDuration);
83 
84  /**
85  * Tests the release functionality.
86  * @return True, if succeeded
87  */
88  static bool testRelease();
89 };
90 
92 {
93  ++number_;
94 }
95 
97 {
98  return number_;
99 }
100 
101 }
102 
103 }
104 
105 }
106 
107 #endif // META_OCEAN_TEST_TESTBASE_TEST_SCOPED_FUNCTION_H
Helper class allowing to determine whether a function was invoked or not.
Definition: TestScopedFunction.h:37
size_t number() const
Returns the number of times the function has been invoked.
Definition: TestScopedFunction.h:96
Object & operator=(const Object &)=delete
Disabled assign operator.
size_t number_
The number of times the function has been invoked.
Definition: TestScopedFunction.h:72
void invokeFunction()
Invokes a function.
Definition: TestScopedFunction.h:91
Object(const Object &)=delete
Disabled copy constructor.
This class implement a test for the TestScopedFunction class.
Definition: TestScopedFunction.h:30
static bool test(const double testDuration)
Tests the ScopedFunction class.
static bool testRelease()
Tests the release functionality.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15