Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_1535_Regression / bug_1535_regression.cpp
blob3b55807be47ba95075a799e19a4da5290aa1576f
1 #include "Test.h"
2 #include "tao/Utils/ORB_Destroyer.h"
3 #include "tao/Utils/RIR_Narrow.h"
4 #include "tao/Utils/PolicyList_Destroyer.h"
6 PortableServer::POA_ptr
7 create_persistent_POA (PortableServer::POA_ptr parent,
8 char const * name)
10 TAO::Utils::PolicyList_Destroyer plist (3);
11 plist.length(3);
13 plist[0] =
14 parent->create_lifespan_policy (PortableServer::PERSISTENT);
16 plist[1] =
17 parent->create_id_assignment_policy (PortableServer::USER_ID);
19 plist[2] =
20 parent->create_implicit_activation_policy (
21 PortableServer::NO_IMPLICIT_ACTIVATION);
23 PortableServer::POAManager_var mgr =
24 parent->the_POAManager ();
26 return parent->create_POA (name,
27 mgr.in(),
28 plist);
31 void
32 test_create_object_before_servant_reactivation (
33 CORBA::ORB_ptr orb,
34 PortableServer::POA_ptr root_poa)
36 // Create a persistent POA and then create a reference in it...
37 PortableServer::POA_var persistent_poa =
38 create_persistent_POA(root_poa,
39 "T1");
42 PortableServer::ObjectId_var oid =
43 PortableServer::string_to_ObjectId ("TestServant");
45 char const * id = _tc_Test->id ();
47 CORBA::Object_var object =
48 persistent_poa->create_reference_with_id (
49 oid.in (),
50 id);
52 if (CORBA::is_nil (object.in ()))
54 ACE_ERROR ((LM_ERROR,
55 "(%P|%t) nil reference in create_reference_with_id\n"));
57 return;
60 CORBA::String_var ior =
61 orb->object_to_string (object.in ());
63 // Now destroy the POA...
64 persistent_poa->destroy (true,
65 true);
67 // Now create the POA again...
68 persistent_poa =
69 create_persistent_POA (root_poa,
70 "T1");
72 // And try to create the object again...
73 object =
74 orb->string_to_object (ior.in ());
76 if(CORBA::is_nil (object.in ()))
78 ACE_ERROR ((LM_ERROR,
79 "(%P|%t) nil reference in string_to_object (servant reactivation)\n"));
80 return;
83 persistent_poa->destroy (true,
84 true);
87 void
88 test_create_object_before_POA_reactivation(
89 CORBA::ORB_ptr orb,
90 PortableServer::POA_ptr root_poa)
92 // Create a persistent POA and then create a reference in it...
93 PortableServer::POA_var persistent_poa =
94 create_persistent_POA (root_poa,
95 "T2");
97 PortableServer::ObjectId_var oid =
98 PortableServer::string_to_ObjectId ("TestServant");
100 char const * id = _tc_Test->id ();
102 CORBA::Object_var object =
103 persistent_poa->create_reference_with_id (oid.in (),
104 id);
106 if (CORBA::is_nil (object.in ()))
108 ACE_DEBUG ((LM_DEBUG,
109 "(%P|%t) nil reference in create_reference_with_id\n"));
110 return;
113 CORBA::String_var ior =
114 orb->object_to_string (object.in ());
116 // Now destroy the POA...
117 persistent_poa->destroy (true,
118 true);
120 // And try to create the object again...
121 object = orb->string_to_object (ior.in ());
123 if (CORBA::is_nil (object.in ()))
125 ACE_DEBUG ((LM_DEBUG,
126 "(%P|%t) nil reference in string_to_object (POA reactivation)\n"));
128 return;
131 persistent_poa->destroy (true,
132 true);
135 void
136 test_no_implicit_activation (
137 PortableServer::POA_ptr root_poa)
139 // Create a persistent POA and then create a reference in it...
140 PortableServer::POA_var persistent_poa =
141 create_persistent_POA (root_poa,
142 "T3");
144 Hello myhello (persistent_poa.in ());
146 bool succeed = false;
149 // Implicit activation should fail
150 Test_var myservant =
151 myhello._this ();
153 catch (const PortableServer::POA::WrongPolicy& )
155 succeed = true;
157 catch (const PortableServer::POA::ServantNotActive& )
159 // This is now the case when looking at the corba spec, raised
160 // an issue 10522 about this
161 succeed = true;
163 catch (const CORBA::Exception&)
167 if (!succeed)
169 ACE_ERROR ((LM_ERROR,
170 "(%t) ERROR, Implicit activation failed with invalid exception\n"));
173 // Now destroy the POA...
174 persistent_poa->destroy (true,
175 true);
179 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
183 CORBA::ORB_var orb =
184 CORBA::ORB_init (argc,
185 argv);
187 TAO::Utils::ORB_Destroyer orb_destroyer (orb.in());
189 PortableServer::POA_var root_poa =
190 TAO::Utils::RIR_Narrow<PortableServer::POA>::narrow (orb.in (),
191 "RootPOA");
193 PortableServer::POAManager_var poa_manager =
194 root_poa->the_POAManager ();
196 poa_manager->activate ();
198 test_create_object_before_POA_reactivation (orb.in(),
199 root_poa.in ());
201 test_create_object_before_servant_reactivation (orb.in (),
202 root_poa.in ());
204 test_no_implicit_activation (root_poa.in ());
206 catch (const CORBA::Exception& ex)
208 ex._tao_print_exception ("Caught a CORBA exception\n");
209 return 1;
211 catch (...)
213 return 1;
216 return 0;