=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / RTCORBA / Server_Declared / client.cpp
blob1a580973dc6b378a020f81f48337b9b9933a4dd7
1 #include "testC.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/RTCORBA/RTCORBA.h"
5 const ACE_TCHAR *ior1 = ACE_TEXT("file://test1.ior");
6 const ACE_TCHAR *ior2 = ACE_TEXT("file://test2.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:o:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'p':
18 ior1 = get_opts.opt_arg ();
19 break;
20 case 'o':
21 ior2 = get_opts.opt_arg ();
22 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-p <ior> "
28 "-o <ior> "
29 "\n",
30 argv [0]),
31 -1);
34 return 0;
37 int
38 check_for_nil (CORBA::Object_ptr obj, const char *msg)
40 if (CORBA::is_nil (obj))
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "ERROR: Object reference <%C> is nil\n",
43 msg),
44 -1);
45 else
46 return 0;
49 CORBA::Short
50 check_policy (Test_ptr server)
52 CORBA::Policy_var policy =
53 server->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE);
55 RTCORBA::PriorityModelPolicy_var priority_policy =
56 RTCORBA::PriorityModelPolicy::_narrow (policy.in ());
58 if (check_for_nil (priority_policy.in (), "PriorityModelPolicy") == -1)
59 return -1;
61 RTCORBA::PriorityModel priority_model =
62 priority_policy->priority_model ();
63 if (priority_model != RTCORBA::SERVER_DECLARED)
64 ACE_ERROR_RETURN ((LM_ERROR,
65 "ERROR: priority_model != "
66 "RTCORBA::SERVER_DECLARED!\n"),
67 -1);
69 return priority_policy->server_priority ();
72 int
73 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
75 try
77 // Initialize the ORB, resolve references and parse arguments.
79 // ORB.
80 CORBA::ORB_var orb =
81 CORBA::ORB_init (argc, argv);
83 // Parse arguments.
84 if (parse_args (argc, argv) != 0)
85 return -1;
87 // Test object 1.
88 CORBA::Object_var object =
89 orb->string_to_object (ior1);
91 Test_var server1 = Test::_narrow (object.in ());
92 if (check_for_nil (server1.in (), "server1") == -1)
93 return -1;
95 // Test object 2.
96 object = orb->string_to_object (ior2);
98 Test_var server2 = Test::_narrow (object.in ());
99 if (check_for_nil (server2.in (), "server2") == -1)
100 return -1;
102 // Check that test objects are configured with SERVER_DECLARED
103 // PriorityModelPolicy, and get their server priorities.
105 // Test object 1.
106 CORBA::Short server1_priority =
107 check_policy (server1.in ());
109 if (server1_priority == -1)
110 return -1;
112 // Test object 2.
113 CORBA::Short server2_priority =
114 check_policy (server2.in ());
115 if (server2_priority == -1)
116 return -1;
118 // Testing: make several invocations on test objects.
119 for (int i = 0; i < 5; ++i)
121 server1->test_method (server1_priority);
123 server2->test_method (server2_priority);
126 // Testing over. Shut down Server ORB.
127 server1->shutdown ();
129 catch (const CORBA::Exception& ex)
131 ex._tao_print_exception (
132 "Unexpected exception in Server_Declared test client:");
133 return -1;
136 return 0;