Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_2826_Regression / bug_2826_regression.cpp
blob4d2a19ed7880fb9727e875129eb635885a300794
1 #include "tao/ORB_Core.h"
2 #include "tao/PortableServer/PortableServer.h"
3 #include "fooS.h"
5 namespace
7 class Foo_i : public virtual POA_foo
9 public:
10 virtual void check ()
12 ACE_DEBUG ((LM_DEBUG, "(%P|%t) checking\n"));
16 int vc_check(foo_ptr ff, bool active=true)
18 try
20 CORBA::PolicyList_var policies;
21 CORBA::Boolean rv=ff->_validate_connection (policies.out());
22 if (!rv)
24 ACE_ERROR_RETURN ((LM_ERROR,
25 " (%P|%t) got false from _validate_connection\n"),
26 1);
29 catch (const CORBA::INV_POLICY&)
31 if (!active)
32 ACE_ERROR_RETURN ((LM_ERROR,
33 " (%P|%t) unexpect inlaid policies\n"),
34 2);
36 catch (const CORBA::OBJECT_NOT_EXIST&)
38 if (active)
39 ACE_ERROR_RETURN ((LM_ERROR,
40 " (%P|%t) unexpect object not exists\n"),
41 3);
43 catch (const CORBA::Exception&)
45 ACE_ERROR_RETURN ((LM_ERROR,
46 " (%P|%t) unexpect exception\n"),
47 4);
49 return 0;
53 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
55 CORBA::ORB_var orb;
56 try
58 orb = CORBA::ORB_init (argc, argv);
60 CORBA::Object_var root_poa_o =
61 orb->resolve_initial_references ("RootPOA");
63 PortableServer::POA_var rootPOA =
64 PortableServer::POA::_narrow (root_poa_o.in ());
66 if (CORBA::is_nil (rootPOA.in ()))
68 ACE_ERROR_RETURN ((LM_ERROR,
69 " (%P|%t) Panic: nil RootPOA\n"), 1);
72 PortableServer::POAManager_var poaMgr = rootPOA->the_POAManager ();
74 poaMgr->activate ();
76 CORBA::PolicyList policies;
77 policies.length (3);
78 policies[0] = rootPOA->create_id_assignment_policy (
79 PortableServer::SYSTEM_ID);
80 policies[1] = rootPOA->create_implicit_activation_policy (
81 PortableServer::NO_IMPLICIT_ACTIVATION);
82 policies[2] = rootPOA->create_lifespan_policy (
83 PortableServer::TRANSIENT);
85 PortableServer::POA_var fooPoa = rootPOA->create_POA (
86 "FOO_POA", poaMgr.in (), policies );
88 for (CORBA::ULong i = 0; i < policies.length (); ++i)
90 policies[i]->destroy ();
93 Foo_i servant;
94 PortableServer::ObjectId_var oid = fooPoa->activate_object( &servant );
96 CORBA::Object_var obj = fooPoa->id_to_reference (oid.in ());
98 foo_var client = foo::_narrow (obj.in());
100 client->check();
102 if (vc_check(client.in()))
104 orb->destroy();
105 return 1;
108 fooPoa->deactivate_object (oid.in () ); //servant is gone
110 if (vc_check(client.in(), false)) //exception expected
112 orb->destroy();
113 return 2;
116 catch(...)
118 return 3;
120 return 0;