Ocean
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 
12 
13 #include "ocean/base/Lock.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Test
19 {
20 
21 namespace TestBase
22 {
23 
24 /**
25  * This class tests lock functions.
26  * @ingroup testbase
27  */
28 class OCEAN_TEST_BASE_EXPORT TestLock
29 {
30  protected:
31 
32  /**
33  * Definition of an empty class.
34  */
35  class Empty
36  {
37 
38  };
39 
40  /**
41  * Definition of a helper class.
42  */
43  template <bool tThreadSafe>
44  class Object
45  {
46  public:
47 
48  /**
49  * A function.
50  * @param value A value
51  */
52  void function(int& value);
53 
54  protected:
55 
56  /// The object's lock.
58  };
59 
60  public:
61 
62  /**
63  * Tests all lock functions.
64  * @return True, if succeeded
65  */
66  static bool test();
67 
68  /**
69  * Tests the lock and unlock functions.
70  * @return True, if succeeded
71  */
72  static bool testLockUnlock();
73 
74  /**
75  * Tests the scoped lock object.
76  * @return True, if succeeded
77  */
78  static bool testScopedLock();
79 
80  /**
81  * Tests a static scoped lock object.
82  * @return True, if succeeded
83  */
84  static bool testStaticScopedLock();
85 
86  /**
87  * Tests the templated lock object.
88  * @return True, if succeeded
89  */
90  static bool testTemplatedLock();
91 
92  private:
93 
94  /**
95  * Returns the static lock object.
96  * @return Static lock object
97  */
99 };
100 
101 template <bool tThreadSafe>
103 {
104  const TemplatedScopedLock scopedLock(lock_);
105 
106  value += 1;
107 }
108 
109 }
110 
111 }
112 
113 }
114 
115 #endif // META_OCEAN_TEST_TESTBASE_TEST_LOCK_H
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a recursive scoped lock object that is activated by a boolean template paramete...
Definition: Lock.h:178
Definition of an empty class.
Definition: TestLock.h:36
Definition of a helper class.
Definition: TestLock.h:45
void function(int &value)
A function.
Definition: TestLock.h:102
TemplatedLock< tThreadSafe > lock_
The object's lock.
Definition: TestLock.h:57
This class tests lock functions.
Definition: TestLock.h:29
static Lock & staticLockObject()
Returns the static lock object.
static bool test()
Tests all lock functions.
static bool testScopedLock()
Tests the scoped 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.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15