Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_3333_Regression / client.cpp
blob67f73bf3665db6da8c2c82c6e06a36100fc0f478
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/Messaging/Messaging.h"
5 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
6 const ACE_TCHAR *loop_forever_ior = ACE_TEXT ("file://forward_forever.ior");
7 bool shutdown_only = false;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:l:s"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 ior = get_opts.opt_arg ();
21 break;
22 case 'l':
23 loop_forever_ior = get_opts.opt_arg ();
24 break;
25 case 's':
26 shutdown_only = true;
27 break;
28 case '?':
29 default:
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "usage: %s "
32 "-k <ior> "
33 "\n",
34 argv [0]),
35 -1);
37 // Indicates successful parsing of the command line
38 return 0;
41 int
42 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
44 try
46 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - ORB_init()\n"));
47 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
49 if (parse_args (argc, argv) != 0)
50 return 1;
52 CORBA::Object_var tmp;
53 Test::Hello_var hello;
55 if (!shutdown_only)
57 tmp = orb->string_to_object (loop_forever_ior);
59 if (CORBA::is_nil (tmp.in ()))
61 ACE_ERROR_RETURN ((LM_DEBUG,
62 "ERROR: Nil object from string_to_object of <%s>\n",
63 loop_forever_ior),
64 1);
67 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - create timeout policy\n"));
68 // Three second relative roundtrip timeout.
69 TimeBase::TimeT timeout_period = 30000000u;
71 CORBA::Any timeout_as_any;
72 timeout_as_any <<= timeout_period;
74 CORBA::PolicyList policy_list (1);
75 policy_list.length (1);
76 policy_list[0] =
77 orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
78 timeout_as_any);
79 tmp = tmp->_set_policy_overrides (policy_list,
80 CORBA::SET_OVERRIDE);
82 for (CORBA::ULong i = 0;
83 i < policy_list.length ();
84 ++i)
86 policy_list[i]->destroy ();
89 try
91 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - loop_forever narrow\n"));
93 // This should LOCATION_FORWARD loop until the timeout
94 hello = Test::Hello::_narrow(tmp.in ());
96 if (CORBA::is_nil (hello.in ()))
98 ACE_ERROR_RETURN ((LM_DEBUG,
99 "ERROR: Nil hello from <%s>\n",
100 loop_forever_ior),
104 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - loop_forever call\n"));
105 CORBA::String_var the_string = hello->get_string ();
107 ACE_ERROR_RETURN ((LM_ERROR,
108 "ERROR - We have managed to invoke a server method. \n"),
111 catch (const CORBA::TIMEOUT &)
113 // Hooray - all OK
114 ACE_DEBUG ((LM_DEBUG, "Test OK - RELATIVE_RT_TIMEOUT ends location forward loop.\n"));
118 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - shutdown server\n"));
119 tmp = orb->string_to_object (ior);
121 hello = Test::Hello::_narrow(tmp.in ());
123 if (CORBA::is_nil (hello.in ()))
125 ACE_ERROR_RETURN ((LM_DEBUG,
126 "ERROR: Nil hello from <%s>\n",
127 ior),
131 hello->shutdown ();
133 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - End\n"));
134 orb->destroy ();
136 catch (const CORBA::Exception& ex)
138 ex._tao_print_exception ("ERROR: Exception caught:");
139 return 1;
142 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - Test SUCCESSFULL!\n"));
143 return 0;