Merge pull request #1815 from sonndinh/get_signal_info
[ACE_TAO.git] / TAO / tests / Bug_1535_Regression / bug_1535_regression.cpp
bloba0d3ff9494b9be193cd70b357f6bf52ad80d4d11
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 ();
154 catch (const PortableServer::POA::WrongPolicy& )
156 succeed = true;
158 catch (const PortableServer::POA::ServantNotActive& )
160 // This is now the case when looking at the corba spec, raised
161 // an issue 10522 about this
162 succeed = true;
164 catch (const CORBA::Exception&)
168 if (!succeed)
170 ACE_ERROR ((LM_ERROR,
171 "(%t) ERROR, Implicit activation failed with invalid exception\n"));
174 // Now destroy the POA...
175 persistent_poa->destroy (true,
176 true);
180 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
184 CORBA::ORB_var orb =
185 CORBA::ORB_init (argc,
186 argv);
188 TAO::Utils::ORB_Destroyer orb_destroyer (orb.in());
190 PortableServer::POA_var root_poa =
191 TAO::Utils::RIR_Narrow<PortableServer::POA>::narrow (orb.in (),
192 "RootPOA");
194 PortableServer::POAManager_var poa_manager =
195 root_poa->the_POAManager ();
197 poa_manager->activate ();
199 test_create_object_before_POA_reactivation (orb.in(),
200 root_poa.in ());
202 test_create_object_before_servant_reactivation (orb.in (),
203 root_poa.in ());
205 test_no_implicit_activation (root_poa.in ());
207 catch (const CORBA::Exception& ex)
209 ex._tao_print_exception ("Caught a CORBA exception\n");
210 return 1;
212 catch (...)
214 return 1;
217 return 0;