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