Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Dynamic / client.cpp
blobc0153f9e3659c85aa82c27a61ebd75c515a0064d
1 #include "ace/Get_Opt.h"
3 #include "testC.h"
4 #include "Echo_Client_ORBInitializer.h"
6 #include "tao/ORBInitializer_Registry.h"
8 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("ef:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'e':
20 break;
21 case 'f':
22 ior = get_opts.opt_arg ();
23 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-v "
29 "\n",
30 argv [0]),
31 -1);
33 return 0;
36 void
37 run_test (Test_Interceptors::Visual_ptr server)
39 CORBA::String_var msg;
41 server->normal (10,
42 msg.out ());
44 CORBA::Long one = 1, two = 1, result = 0;
45 result = server->calculate (one,
46 two);
48 ACE_DEBUG ((LM_DEBUG,
49 "calculate() result = %d\n",
50 result));
52 Test_Interceptors::Visual::VarLenStruct_var v =
53 server->the_structure ();
55 ACE_DEBUG ((LM_DEBUG,
56 "the_structure() result is:\n"
57 " flag = %d\n"
58 " message = %C\n",
59 v->flag,
60 v->message.in ()));
62 try
64 server->user ();
66 catch (const Test_Interceptors::Silly&)
68 ACE_DEBUG ((LM_DEBUG, "Caught Silly\n"));
71 try
73 server->system ();
75 catch (const CORBA::INV_OBJREF&)
77 ACE_DEBUG ((LM_DEBUG, "Caught CORBA::INV_OBJREF\n"));
81 int
82 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
84 try
86 #if TAO_HAS_INTERCEPTORS == 1
87 PortableInterceptor::ORBInitializer_ptr temp_initializer =
88 PortableInterceptor::ORBInitializer::_nil ();
90 ACE_NEW_RETURN (temp_initializer,
91 Echo_Client_ORBInitializer,
92 -1); // No exceptions yet!
93 PortableInterceptor::ORBInitializer_var orb_initializer =
94 temp_initializer;
96 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
97 #endif /* TAO_HAS_INTERCEPTORS == 1 */
99 CORBA::ORB_var orb =
100 CORBA::ORB_init (argc, argv);
102 if (parse_args (argc, argv) != 0)
103 return 1;
105 CORBA::Object_var object =
106 orb->string_to_object (ior);
108 Test_Interceptors::Visual_var server =
109 Test_Interceptors::Visual::_narrow (object.in ());
111 if (CORBA::is_nil (server.in ()))
113 ACE_ERROR_RETURN ((LM_ERROR,
114 "Object reference <%s> is nil.\n",
115 ior),
119 run_test (server.in ());
121 server->shutdown ();
123 orb->destroy ();
125 catch (const CORBA::Exception& ex)
127 ex._tao_print_exception ("Caught exception:");
128 return 1;
131 return 0;