summaryrefslogtreecommitdiff
path: root/orbsvcs/tests/Concurrency/CC_tests.h
blob: 94e50852ee1279d5cfcfeb9086dde2cb54168df1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204

//=============================================================================
/**
 *  @file    CC_tests.h
 *
 *  $Id$
 *
 *    This class implements a number of test objects to test the
 *    concurrency service.
 *
 *
 *  @author Torben Worm <tworm@cs.wustl.edu>
 */
//=============================================================================


#include "orbsvcs/CosConcurrencyControlC.h"
#include "orbsvcs/CosNamingC.h"
#include "CC_naming_service.h"

#ifndef _CC_TESTS_H_
#define _CC_TESTS_H_

// Return codes for the tests
enum
{
  CC_FAIL,
  CC_SUCCESS = 1
};

/**
 * @class CC_Test
 *
 * @brief Defines an abstract base class for a test
 *
 * This class declares an interface to run the test of the
 * concurrency service.
 */
class CC_Test
{
public:
  /// Default constructor
  CC_Test (CC_naming_service *ns);

  /// Destructor
  virtual ~CC_Test (void);

  /// Run the test times_to_run number of times. Returns CC_SUCCESS on
  /// success CC_FAIL otherwise.
  virtual int run (int times_to_run = 1) = 0;

  /// Create a new lock set using the default global lock set factory
  /// from the naming service.
  CosConcurrencyControl::LockSet_ptr create_lock_set (void);

  /// Returns a human readable string from the lock mode enum.
  char *get_lock_mode_name (CosConcurrencyControl::lock_mode mode);

protected:
  /// The result of the test being performed.
  int result;

  /// The naming service beeing used to register and look up locks
  CC_naming_service *naming_service_;
};

/**
 * @class Test_Single_Lock_With_Mode
 *
 * @brief This is a simple test that checks that it is possible to set
 * the lock in the desired mode, try it, and release it.
 */
class Test_Single_Lock_With_Mode : public CC_Test
{
public:
  /**
   * Default constructor. The naming service must be initialized
   * before calling this method. The mode is the mode of the lock to
   * be tested.
   */
  Test_Single_Lock_With_Mode (CC_naming_service *naming_service,
                              CosConcurrencyControl::lock_mode mode);

  /// Destructor
  virtual ~Test_Single_Lock_With_Mode (void);

  /// Runs the test the specified number of times.
  virtual int run (int times_to_run = 1);

private:
  /// The lock mode of the lock being tested
  CosConcurrencyControl::lock_mode mode_;
};

/**
 * @class Test_Setup_LockSet
 *
 * @brief This class creates a read lock, registeres it with the naming
 * service and locks it.
 */
class Test_Setup_LockSet : public CC_Test
{
public:
  /**
   * Default constructor. The naming service must be initialized
   * before calling this method. The name is the name the lock will be
   * registered under in the naming service.
   */
  Test_Setup_LockSet (CC_naming_service *naming_service_,
                      char *name);

  /// Destructor
  virtual ~Test_Setup_LockSet (void);

  /// Runs the test the specified number of times.
  virtual int run (int times_to_run = 1);

private:
  /// The name of the lock
  char *my_name_;
};

/**
 * @class Test_Use_Already_Created_LockSet
 *
 * @brief This class looks up the lock in the naming service and locks
 * it.
 */
class Test_Use_Already_Created_LockSet : public CC_Test
{
public:
  /**
   * Default constructor. The naming service must be initialized
   * before calling this method. The name is the name the lock will be
   * looked up under in the naming service.
   */
  Test_Use_Already_Created_LockSet (CC_naming_service *naming_service_,
                                   char *name);

  /// Destructor
  virtual ~Test_Use_Already_Created_LockSet (void);

  /// Runs the test the specified number of times.
  virtual int run (int times_to_run = 1);

private:
  /// The name of the lock
  char *my_name_;
};

/**
 * @class Test_Unlock_Already_Created_LockSet
 *
 * @brief This class looks up the lock in the naming service and unlocks
 * it.
 */
class Test_Unlock_Already_Created_LockSet : public CC_Test
{
public:
  /**
   * Default constructor. The naming service must be initialized
   * before calling this method. The name is the name the lock will be
   * looked up under in the naming service.
   */
  Test_Unlock_Already_Created_LockSet (CC_naming_service *naming_service_,
                                       char *name);

  /// Destructor
  virtual ~Test_Unlock_Already_Created_LockSet (void);

  /// Runs the test the specified number of times.
  virtual int run (int times_to_run = 1);

private:
  /// The name of the lock
  char *my_name_;
};

/**
 * @class Test_Release_Not_Held_Lock
 *
 * @brief This class tests that the LockNotHeld exception is thrown if a
 * not held lock is released.
 */
class Test_Release_Not_Held_Lock : public CC_Test
{
public:
  /// Default constructor. The naming service must be initialized
  /// before calling this method. The mode is the mode of the lock
  Test_Release_Not_Held_Lock (CC_naming_service *naming_service_,
                                CosConcurrencyControl::lock_mode mode_);

  /// Destructor
  virtual ~Test_Release_Not_Held_Lock (void);

  /// Runs the test the specified number of times.
  virtual int run (int times_to_run = 1);

private:
  /// The lock mode of the lock being tested
  CosConcurrencyControl::lock_mode mode_;
};

#endif /* !defined (_CC_TESTS_H_) */