Ocean
Loading...
Searching...
No Matches
TestLock.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_LOCK_H
9#define META_OCEAN_TEST_TESTBASE_TEST_LOCK_H
10
13
14#include "ocean/base/Lock.h"
15
16namespace Ocean
17{
18
19namespace Test
20{
21
22namespace TestBase
23{
24
25/**
26 * This class tests lock functions.
27 * @ingroup testbase
28 */
29class OCEAN_TEST_BASE_EXPORT TestLock
30{
31 protected:
32
33 /**
34 * Definition of an empty class.
35 */
36 class Empty
37 {
38
39 };
40
41 /**
42 * Definition of a helper class.
43 */
44 template <bool tThreadSafe>
45 class Object
46 {
47 public:
48
49 /**
50 * A function.
51 * @param value A value
52 */
53 void function(int& value);
54
55 protected:
56
57 /// The object's lock.
59 };
60
61 public:
62
63 /**
64 * Tests all lock functions.
65 * @param selector Optional test selector to control which tests to run
66 * @return True, if succeeded
67 */
68 static bool test(const TestSelector& selector = TestSelector());
69
70 /**
71 * Tests the lock and unlock functions.
72 * @return True, if succeeded
73 */
74 static bool testLockUnlock();
75
76 /**
77 * Tests the scoped lock object.
78 * @return True, if succeeded
79 */
80 static bool testScopedLock();
81
82 /**
83 * Tests a static scoped lock object.
84 * @return True, if succeeded
85 */
86 static bool testStaticScopedLock();
87
88 /**
89 * Tests the templated lock object.
90 * @return True, if succeeded
91 */
92 static bool testTemplatedLock();
93
94 /**
95 * Tests the dual scoped lock object.
96 * @return True, if succeeded
97 */
98 static bool testDualScopedLock();
99
100 private:
101
102 /**
103 * Thread function for testing DualScopedLockT.
104 * @param firstLock The first lock to be locked
105 * @param secondLock The second lock to be locked
106 * @param counter The counter to increment while holding both locks
107 * @param iterations The number of iterations to perform
108 */
109 static void threadFunction(Lock& firstLock, Lock& secondLock, unsigned int& counter, const unsigned int iterations);
110
111 /**
112 * Returns the static lock object.
113 * @return Static lock object
114 */
116};
117
118template <bool tThreadSafe>
120{
121 const TemplatedScopedLock scopedLock(lock_);
122
123 value += 1;
124}
125
126}
127
128}
129
130}
131
132#endif // META_OCEAN_TEST_TESTBASE_TEST_LOCK_H
This class implements a recursive lock object.
Definition Lock.h:31
This class implements a template-based recursive lock object.
Definition Lock.h:99
This class implements a recursive scoped lock object that is activated by a boolean template paramete...
Definition Lock.h:190
Definition of an empty class.
Definition TestLock.h:37
Definition of a helper class.
Definition TestLock.h:46
void function(int &value)
A function.
Definition TestLock.h:119
TemplatedLock< tThreadSafe > lock_
The object's lock.
Definition TestLock.h:58
This class tests lock functions.
Definition TestLock.h:30
static bool testScopedLock()
Tests the scoped lock object.
static bool testDualScopedLock()
Tests the dual scoped lock object.
static bool test(const TestSelector &selector=TestSelector())
Tests all lock functions.
static void threadFunction(Lock &firstLock, Lock &secondLock, unsigned int &counter, const unsigned int iterations)
Thread function for testing DualScopedLockT.
static Lock & staticLockObject()
Returns the static lock object.
static bool testTemplatedLock()
Tests the templated lock object.
static bool testLockUnlock()
Tests the lock and unlock functions.
static bool testStaticScopedLock()
Tests a static scoped lock 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