Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / PolicyFactory / server.cpp
blob3b7252f938e7486669a65ee462c565c57b22129a
1 // -*- C++ -*-
2 #include "Server_ORBInitializer.h"
3 #include "tao/ORBInitializer_Registry.h"
4 #include "testC.h"
5 #include "tao/PortableServer/PortableServer.h"
6 #include "ace/Log_Msg.h"
8 int
9 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
11 try
13 PortableInterceptor::ORBInitializer_ptr temp_initializer =
14 PortableInterceptor::ORBInitializer::_nil ();
16 ACE_NEW_RETURN (temp_initializer,
17 Server_ORBInitializer,
18 -1); // No CORBA exceptions yet!
19 PortableInterceptor::ORBInitializer_var orb_initializer =
20 temp_initializer;
22 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
24 CORBA::ORB_var orb = CORBA::ORB_init (argc,
25 argv,
26 "test_orb");
28 // Create the test policy.
30 const CORBA::ULong val = 40442;
31 CORBA::Any any;
32 any <<= val;
34 CORBA::Policy_var p (orb->create_policy (Test::POLICY_TYPE,
35 any));
37 const CORBA::PolicyType ptype =
38 p->policy_type ();
40 // Sanity check.
41 if (ptype != Test::POLICY_TYPE)
42 throw CORBA::INTERNAL ();
44 Test::Policy_var policy (Test::Policy::_narrow (p.in ()));
46 const CORBA::ULong pval = policy->value ();
48 // Sanity check.
49 if (val != pval)
50 throw CORBA::INTERNAL ();
52 CORBA::Object_var obj =
53 orb->resolve_initial_references ("RootPOA");
55 PortableServer::POA_var root_poa =
56 PortableServer::POA::_narrow (obj.in ());
58 if (CORBA::is_nil (root_poa.in ()))
59 ACE_ERROR_RETURN ((LM_ERROR,
60 "Unable to obtain RootPOA reference.\n"),
61 -1);
63 PortableServer::POAManager_var poa_manager =
64 root_poa->the_POAManager ();
66 CORBA::PolicyList policies (1);
67 policies.length (1);
69 policies[0] = policy->copy ();
71 PortableServer::POA_var poa =
72 root_poa->create_POA ("Test POA",
73 poa_manager.in (),
74 policies);
76 policy->destroy ();
78 poa_manager->activate ();
80 root_poa->destroy (true, true);
82 orb->destroy ();
84 ACE_DEBUG ((LM_INFO,
85 "\n"
86 "PolicyFactory test succeeded.\n"));
88 catch (const CORBA::Exception& ex)
90 ex._tao_print_exception ("PolicyFactory test:");
92 return -1;
95 return 0;