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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
// $Id$
//========================================================================
//
// = LIBRARY
// TAO/tests/POA/POAManagerFactory
//
// = FILENAME
// POAManagerFactory.cpp
//
// = DESCRIPTION
// This program tests Root_POA::the_POAManagerFactory and
// the POAManagerFactory interfaces such as create_POAManager(),
// list () and find ().
//
// = AUTHOR
// Yan Dai
//
//=========================================================================
#include "tao/ORB.h"
#include "tao/AnyTypeCode/Any.h"
#include "tao/PortableServer/PortableServer.h"
#include "tao/PI_Server/PI_Server.h"
#include "ace/Log_Msg.h"
#include "ace/OS_NS_string.h"
#include "ace/Get_Opt.h"
int fail = 0;
int pretest = 0;
int verbose = 0;
#define VERIFY_CONDITION(Condition) \
{ \
if (!(Condition)) \
{ \
fail++; \
if (!verbose) \
ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) - Failure at line %l\n"))); \
} \
}
int
parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opts (argc, argv, "v");
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'v':
verbose = 1;
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s "
"-v "
"\n",
argv [0]),
-1);
}
// Indicates sucessful parsing of the command line
return 0;
}
int
main (int argc, char **argv)
{
try
{
// Initialize the ORB first.
CORBA::ORB_var orb =
CORBA::ORB_init (argc,
argv,
"POAManagerFactoryTest");
if (parse_args (argc, argv) != 0)
return 1;
// Obtain the RootPOA.
CORBA::Object_var obj =
orb->resolve_initial_references ("RootPOA");
// Narrow to POA.
PortableServer::POA_var root_poa =
PortableServer::POA::_narrow (obj.in ());
if (verbose)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("Obtain PoaManagerFactory reference: ")));
pretest = fail;
// Obtain the POAManagerFactory.
PortableServer::POAManagerFactory_var poa_manager_factory
= root_poa->the_POAManagerFactory ();
VERIFY_CONDITION (!CORBA::is_nil(poa_manager_factory.in()));
if (verbose)
ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
(pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
if (CORBA::is_nil(poa_manager_factory.in()))
return 1;
CORBA::PolicyList policies (0);
policies.length (0);
if (verbose)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("Create a POAManager: ")));
pretest = fail;
// Explicitly create a POAManager - "POAManager1" .
PortableServer::POAManager_var poa_manager_1
= poa_manager_factory->create_POAManager ("POAManager1",
policies);
VERIFY_CONDITION (!CORBA::is_nil(poa_manager_1.in()));
if (verbose)
ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
(pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
if (CORBA::is_nil(poa_manager_1.in()))
return 1;
// Creating a POAManager with an exiting POAManager name raises exception.
if (verbose)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("Prevent duplicated POAManagers: ")));
pretest = fail;
CORBA::Boolean got_expected_exception = false;
try
{
PortableServer::POAManager_var poa_manager
= poa_manager_factory->create_POAManager ("POAManager1",
policies);
}
catch (const PortableServer::POAManagerFactory::ManagerAlreadyExists& )
{
got_expected_exception = true;
}
VERIFY_CONDITION (got_expected_exception);
if (verbose)
ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
(pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
if (! got_expected_exception)
return 1;
{
if (verbose)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("Implicitly create a POAManagers: ")));
pretest = fail;
// Implicitly create a POAManager instance which has an automatically
// assigned name.
PortableServer::POA_var child_poa =
root_poa->create_POA ("childPOA2",
PortableServer::POAManager::_nil (),
policies);
PortableServer::POAManager_var poa_manager_2
= child_poa->the_POAManager ();
VERIFY_CONDITION (!CORBA::is_nil(poa_manager_2.in()));
if (verbose)
ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
(pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
if (CORBA::is_nil(poa_manager_2.in()))
return 1;
CORBA::String_var poa_manager_2_name
= poa_manager_2->get_id ();
if (verbose)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("Implicitly created POAManager's ID: [%s]\n"),
ACE_TEXT_CHAR_TO_TCHAR(poa_manager_2_name.in())));
if (ACE_OS::strlen(poa_manager_2_name.in()) == 0)
return 1;
if (verbose)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT("List POAManagers: ")));
pretest = fail;
PortableServer::POAManagerFactory::POAManagerSeq_var managers
= poa_manager_factory->list ();
VERIFY_CONDITION (managers->length () == 3);
if (verbose)
ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
(pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
PortableServer::POAManager_var root_poa_manager
= root_poa->the_POAManager();
for (CORBA::ULong i = 0; i < managers->length(); ++i)
{
CORBA::String_var name = managers[i]->get_id ();
if (verbose)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("Validate listed POAManager [%s]: "),
ACE_TEXT_CHAR_TO_TCHAR(name.in())));
pretest = fail;
const PortableServer::POAManager_ptr tmp_pm = managers[i];
if ((ACE_OS::strcmp (name.in (), "RootPOAManager") == 0
&& tmp_pm == root_poa_manager.in ())
|| (ACE_OS::strcmp (name.in (), "POAManager1") == 0
&& tmp_pm == poa_manager_1.in ())
|| (ACE_OS::strcmp (name.in (), poa_manager_2_name.in ()) == 0
&& tmp_pm == poa_manager_2.in ()))
{
if (verbose)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT("passed\n")));
continue;
}
else
{
if (verbose)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT("failed\n")));
fail++;
}
}
}
{
// Find a specific POAManager.
if (verbose)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("Find a POAManager: ")));
pretest = fail;
PortableServer::POAManager_var manager
= poa_manager_factory->find ("POAManager1");
CORBA::String_var name = manager->get_id ();
VERIFY_CONDITION ((ACE_OS::strcmp (name.in (), "POAManager1") == 0
&& manager.in () == poa_manager_1.in ()));
if (verbose)
ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
(pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
}
// Create a child poa that associates with the explicitly
// created POAManager.
if (verbose)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("Create A POA with explicit POAManager: ")));
pretest = fail;
PortableServer::POA_var child_poa =
root_poa->create_POA ("childPOA",
poa_manager_1.in (),
policies);
poa_manager_1->activate ();
root_poa->destroy (1, 1);
if (verbose)
ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("passed\n")));
}
catch (const CORBA::Exception& ex)
{
fail++;
if (verbose)
ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("failed\n")));
ex._tao_print_exception ("Exception caught");
}
ACE_DEBUG ((LM_DEBUG, ACE_TEXT("POAManagerFactory %s\n"),
(pretest == fail) ? ACE_TEXT ("succeeded") : ACE_TEXT ("failed")));
return 0;
}
|