Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Concurrency / CC_tests.cpp
blob0dc8df76628679f0570d0a33c76692af38ad9173
2 //=============================================================================
3 /**
4 * @file CC_tests.cpp
6 * This class implements a number of test objects to test the
7 * concurrency service.
9 * @author Torben Worm <tworm@cs.wustl.edu>
11 //=============================================================================
14 #include "CC_tests.h"
15 #include "ace/Log_Msg.h"
17 CC_Test::CC_Test (CC_naming_service *ns)
18 : result (CC_FAIL),
19 naming_service_ (ns)
23 CC_Test::~CC_Test ()
27 CosConcurrencyControl::LockSet_ptr
28 CC_Test::create_lock_set ()
30 // Create the lock set and return an obj ref corresponding to the
31 // key.
32 CosConcurrencyControl::LockSet_ptr lock_set(0);
33 try
35 lock_set =
36 this->naming_service_->get_lock_set_factory ()->create ();
38 if (CORBA::is_nil (lock_set))
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "null lock set objref returned by factory\n"),
41 0);
43 catch (const CORBA::Exception& ex)
45 ex._tao_print_exception ("CC_Client::create_lock_set");
46 return 0;
48 return lock_set;
51 char *
52 CC_Test::get_lock_mode_name (CosConcurrencyControl::lock_mode mode)
54 if (mode==CosConcurrencyControl::read)
55 return const_cast<char *> ("read");
57 if (mode==CosConcurrencyControl::write)
58 return const_cast<char *> ("write");
60 if (mode==CosConcurrencyControl::upgrade)
61 return const_cast<char *> ("upgrade");
63 if (mode==CosConcurrencyControl::intention_read)
64 return const_cast<char *> ("intension_read");
66 if (mode==CosConcurrencyControl::intention_write)
67 return const_cast<char *> ("intension_write");
69 return const_cast<char *> ("unknown lock mode");
72 // ================================
73 // Here the tests start.
75 Test_Single_Lock_With_Mode::Test_Single_Lock_With_Mode (CC_naming_service *naming_service,
76 CosConcurrencyControl::lock_mode mode)
77 : CC_Test (naming_service),
78 mode_ (mode)
82 Test_Single_Lock_With_Mode::~Test_Single_Lock_With_Mode ()
86 int
87 Test_Single_Lock_With_Mode::run (int /* times_to_run */)
89 CORBA::Boolean lock_not_held;
91 CosConcurrencyControl::LockSet_ptr cc_lock_set_ = create_lock_set ();
93 try
95 cc_lock_set_->lock (mode_);
97 ACE_DEBUG ((LM_DEBUG,
98 "%s lock set\n",
99 get_lock_mode_name (mode_)));
101 lock_not_held = cc_lock_set_->try_lock (mode_);
103 if (lock_not_held)
105 ACE_DEBUG ((LM_DEBUG,
106 "%s lock not held\n",
107 get_lock_mode_name (mode_)));
108 return CC_FAIL;
110 else
111 ACE_DEBUG ((LM_DEBUG,
112 "%s lock held\n",
113 get_lock_mode_name (mode_)));
115 cc_lock_set_->unlock (mode_);
116 ACE_DEBUG ((LM_DEBUG,
117 "%s lock released\n",
118 get_lock_mode_name (mode_)));
120 lock_not_held = cc_lock_set_->try_lock (mode_);
122 if (lock_not_held)
123 ACE_DEBUG ((LM_DEBUG,
124 "%s lock not held\n",
125 get_lock_mode_name (mode_)));
126 else
128 ACE_DEBUG ((LM_DEBUG,
129 "%s lock held\n",
130 get_lock_mode_name (mode_)));
131 return CC_FAIL;
135 catch (const CORBA::Exception& ex)
137 ex._tao_print_exception ("Test_Single_Lock_With_Mode::run");
138 return CC_FAIL;
141 CORBA::release (cc_lock_set_);
143 return CC_SUCCESS;
146 // ================================
148 Test_Setup_LockSet::Test_Setup_LockSet (CC_naming_service *naming_service,
149 char *name)
150 : CC_Test (naming_service),
151 my_name_ (name)
155 Test_Setup_LockSet::~Test_Setup_LockSet ()
160 Test_Setup_LockSet::run (int /* times_to_run */)
164 CosConcurrencyControl::LockSet_ptr cc_lock_set_ =
165 create_lock_set ();
166 this->naming_service_->bind_name (my_name_, cc_lock_set_);
168 ACE_DEBUG ((LM_DEBUG,
169 "Name bound\n"));
171 cc_lock_set_->lock (CosConcurrencyControl::read);
173 ACE_DEBUG ((LM_DEBUG,
174 "Read lock set\n"));
176 catch (const CORBA::Exception& ex)
178 ex._tao_print_exception ("Test_Against_Other_LockSet::run");
179 return CC_FAIL;
182 return CC_SUCCESS;
185 // ================================
187 Test_Use_Already_Created_LockSet::
188 Test_Use_Already_Created_LockSet (CC_naming_service *naming_service,
189 char *name)
190 : CC_Test (naming_service),
191 my_name_ (name)
195 Test_Use_Already_Created_LockSet::~Test_Use_Already_Created_LockSet ()
200 Test_Use_Already_Created_LockSet::run (int /* times_to_run */)
204 CORBA::Object_var ccls_obj =
205 this->naming_service_->get_obj_from_name (const_cast<char *> (""),
206 my_name_);
208 CosConcurrencyControl::LockSet_var ccls =
209 CosConcurrencyControl::LockSet::_narrow (ccls_obj.in ());
211 ccls->lock (CosConcurrencyControl::read);
213 catch (const CORBA::Exception& ex)
215 ex._tao_print_exception ("Test_Against_Other_LockSet::run");
216 return CC_FAIL;
219 return CC_SUCCESS;
222 // ================================
224 Test_Unlock_Already_Created_LockSet::
225 Test_Unlock_Already_Created_LockSet (CC_naming_service *naming_service,
226 char *name)
227 : CC_Test (naming_service),
228 my_name_ (name)
232 Test_Unlock_Already_Created_LockSet::~Test_Unlock_Already_Created_LockSet ()
237 Test_Unlock_Already_Created_LockSet::run (int /* times_to_run */)
241 CORBA::Object_var ccls_obj =
242 this->naming_service_->get_obj_from_name (const_cast<char *> (""), my_name_);
244 CosConcurrencyControl::LockSet_var ccls =
245 CosConcurrencyControl::LockSet::_narrow (ccls_obj.in ());
247 ccls->unlock (CosConcurrencyControl::read);
249 catch (const CORBA::Exception& ex)
251 ex._tao_print_exception ("Test_Unlock_Already_Created_LockSet::run");
252 return CC_FAIL;
255 return CC_SUCCESS;
258 // ================================
260 Test_Release_Not_Held_Lock::Test_Release_Not_Held_Lock (CC_naming_service *naming_service,
261 CosConcurrencyControl::lock_mode mode)
262 : CC_Test (naming_service),
263 mode_ (mode)
267 Test_Release_Not_Held_Lock::~Test_Release_Not_Held_Lock ()
272 Test_Release_Not_Held_Lock::run (int /* times_to_run */)
274 CORBA::Boolean lock_not_held;
276 // Create the lock set
277 CosConcurrencyControl::LockSet_ptr cc_lock_set_ = create_lock_set ();
280 // lock the lock
281 cc_lock_set_->lock (mode_);
283 ACE_DEBUG ((LM_DEBUG,
284 "%s lock set\n",
285 get_lock_mode_name (mode_)));
287 // check to see if the lock is held
288 lock_not_held = cc_lock_set_->try_lock (mode_);
290 if (lock_not_held)
292 ACE_DEBUG ((LM_DEBUG,
293 "%s lock not held\n",
294 get_lock_mode_name (mode_)));
295 return CC_FAIL;
297 else
298 ACE_DEBUG ((LM_DEBUG,
299 "%s lock held\n",
300 get_lock_mode_name (mode_)));
302 // release the lock
303 cc_lock_set_->unlock (mode_);
304 ACE_DEBUG ((LM_DEBUG,
305 "%s lock released\n",
306 get_lock_mode_name (mode_)));
308 // release the lock again. this should raise an exception
309 cc_lock_set_->unlock (mode_);
311 ACE_DEBUG ((LM_DEBUG,
312 "attemptet to release %s lock\n",
313 get_lock_mode_name (mode_)));
315 catch (const CosConcurrencyControl::LockNotHeld& userex)
317 // We should end here
318 ACE_UNUSED_ARG (userex);
319 ACE_DEBUG((LM_DEBUG, "CosConcurrencyControl::LockNotHeld\n"));
320 return CC_SUCCESS;
323 catch (const CORBA::Exception& ex)
325 ex._tao_print_exception ("Test_Release_Not_Held_Lock::run");
326 return CC_FAIL;
329 CORBA::release (cc_lock_set_);
331 return CC_FAIL;