Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Bug_3541_Regression_Test.cpp
blob302ade29a3bacbbf934b907339141bb724bf4b2f
1 /**
2 * @file Bug_3541_Regression_Test.cpp
4 * Reproduces the problems reported in bug 3541:
5 * http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=3541
7 * @author Bill Rizzi <rizzi@softserv.com>
8 */
10 #include "ace/Event.h"
11 #include "ace/Mutex.h"
12 #include "ace/Semaphore.h"
13 #include "ace/OS_NS_errno.h"
14 #include "ace/SString.h"
15 #include "test_config.h"
17 int
18 run_main (int, ACE_TCHAR *[])
20 ACE_START_TEST (ACE_TEXT ("Bug_3541_Regression_Test"));
22 int ret = 0;
24 #if defined(ACE_WIN32)
25 int lastError;
27 // ACE_OS::event_init()
29 const ACE_TCHAR *eventName = ACE_TEXT ("Bug3541_Event");
31 ACE_Event event0(0, // int manual_reset = 0
32 0, // int initial_state = 0
33 USYNC_PROCESS, // int type = USYNC_THREAD
34 eventName); // const ACE_TCHAR *name = 0
36 lastError = ACE_OS::last_error();
38 ACE_event_t eventHandle = event0.handle();
40 if ((eventHandle == ACE_INVALID_HANDLE) ||
41 (lastError != 0))
43 ret = -1;
45 ACE_ERROR ((LM_ERROR,
46 ACE_TEXT ("ACE_Event(%s) failed - handle %d lastError %d\n"),
47 eventName, eventHandle, lastError));
49 else
51 ACE_Event event1(0, // int manual_reset = 0
52 0, // int initial_state = 0
53 USYNC_PROCESS, // int type = USYNC_THREAD
54 eventName); // const ACE_TCHAR *name = 0
56 lastError = ACE_OS::last_error();
58 eventHandle = event1.handle();
60 if ((eventHandle == ACE_INVALID_HANDLE) ||
61 (lastError != ERROR_ALREADY_EXISTS))
63 ret = -1;
65 ACE_ERROR ((LM_ERROR,
66 ACE_TEXT ("ACE_Event(%s) failed - handle %d lastError %d\n"),
67 eventName, eventHandle, lastError));
71 // ACE_OS::sema_init
73 const ACE_TCHAR *semaphoreName = ACE_TEXT ("Bug3541_Semaphore");
75 ACE_Semaphore semaphore0(1, // int count = 1
76 USYNC_PROCESS, // int type = USYNC_THREAD
77 semaphoreName); // const ACE_TCHAR *name = 0
79 lastError = ACE_OS::last_error();
81 const ACE_sema_t &semaphoreLock = semaphore0.lock();
82 if ((semaphoreLock == ACE_INVALID_HANDLE) ||
83 (lastError != 0))
85 ret = -1;
87 ACE_ERROR ((LM_ERROR,
88 ACE_TEXT ("ACE_Semaphore(%s) failed - lock %d lastError %d\n"),
89 semaphoreName, semaphoreLock, lastError));
91 else
93 ACE_Semaphore semaphore1(1, // int count = 1
94 USYNC_PROCESS, // int type = USYNC_THREAD
95 semaphoreName); // const ACE_TCHAR *name = 0
97 lastError = ACE_OS::last_error();
99 const ACE_sema_t &semaphoreLock = semaphore1.lock();
101 if ((semaphoreLock == ACE_INVALID_HANDLE) ||
102 (lastError != ERROR_ALREADY_EXISTS))
104 ret = -1;
106 ACE_ERROR ((LM_ERROR,
107 ACE_TEXT ("ACE_Semaphore(%s) failed - lock %d lastError %d\n"),
108 semaphoreName, semaphoreLock, lastError));
112 // ACE_OS::mutex_init()
114 const ACE_TCHAR *mutexName = ACE_TEXT ("Bug3541_Mutex");
116 ACE_Mutex mutex0(USYNC_PROCESS, // int type = USYNC_THREAD
117 mutexName); // const ACE_TCHAR *name = 0
119 lastError = ACE_OS::last_error();
121 const ACE_mutex_t &mutexLock = mutex0.lock();
123 if ((mutexLock.proc_mutex_ == ACE_INVALID_HANDLE) ||
124 (lastError != 0))
126 ret = -1;
128 ACE_ERROR ((LM_ERROR,
129 ACE_TEXT ("ACE_Mutex(%s) failed - lock %d lastError %d\n"),
130 mutexName, mutexLock, lastError));
132 else
134 ACE_Mutex mutex1(USYNC_PROCESS, // int type = USYNC_THREAD
135 mutexName); // const ACE_TCHAR *name = 0
137 lastError = ACE_OS::last_error();
139 const ACE_mutex_t &mutexLock = mutex1.lock();
141 if ((mutexLock.proc_mutex_ == ACE_INVALID_HANDLE) ||
142 (lastError != ERROR_ALREADY_EXISTS))
144 ret = -1;
146 ACE_ERROR ((LM_ERROR,
147 ACE_TEXT ("ACE_Mutex(%s) failed - lock %d lastError %d\n"),
148 mutexName, mutexLock, lastError));
152 #endif
154 ACE_END_TEST;
156 return ret;