Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Bug_3080 / client.cpp
blob6f204d5bf47562d7f812caedbaa85c5dc4ee0ae0
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "testC.h"
4 #include "Client_ORBInitializer.h"
5 #include "Client_Request_Interceptor.h"
6 #include "tao/ORBInitializer_Registry.h"
8 const ACE_TCHAR *ior1 = 0;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 if (argc != 3) // foo -p IOR_1 -s IOR_2
14 ACE_ERROR_RETURN ((LM_ERROR,
15 "Wrong number of arguments.\n"),
16 -1);
18 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("f:s:"));
19 int c;
21 while ((c = get_opts ()) != -1)
22 switch (c)
24 case 'f':
25 ior1 = get_opts.opt_arg ();
26 break;
27 default:
28 ACE_ERROR_RETURN ((LM_ERROR,
29 "Usage: %s "
30 "-p IOR_1\n",
31 argv[0]),
32 -1);
35 return 0;
38 int
39 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
41 int status = 0;
43 try
45 #if TAO_HAS_INTERCEPTORS == 1
46 Client_ORBInitializer* temp_initializer = 0;
48 ACE_NEW_RETURN (temp_initializer,
49 Client_ORBInitializer,
50 -1); // No exceptions yet!
51 PortableInterceptor::ORBInitializer_var orb_initializer =
52 temp_initializer;
54 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
55 #endif /* TAO_HAS_INTERCEPTORS == 1 */
57 CORBA::ORB_var orb = CORBA::ORB_init (argc,
58 argv,
59 "Client ORB");
61 if (::parse_args (argc, argv) != 0)
62 return -1;
64 CORBA::Object_var object =
65 orb->string_to_object (ior1);
67 RedirectionTest::test_var server =
68 RedirectionTest::test::_narrow (object.in ());
70 if (CORBA::is_nil (server.in ()))
72 ACE_ERROR_RETURN ((LM_ERROR,
73 "Object reference <%s> is nil.\n",
74 ior1),
75 1);
78 try
80 (void) server->number ();
82 catch (const CORBA::TRANSIENT&)
84 // ignore
87 #if TAO_HAS_INTERCEPTORS == 1
88 if (temp_initializer->client_interceptor_->request_count () != 1)
90 ACE_ERROR_RETURN ((LM_ERROR,
91 "Error, send request interceptor not called\n"),
92 1);
95 if (temp_initializer->client_interceptor_->receive_exception_count () != 1)
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "Error, receive exception interceptor not called\n"),
99 1);
101 #endif /* TAO_HAS_INTERCEPTORS == 1 */
103 orb->destroy ();
105 catch (const CORBA::Exception& ex)
107 ex._tao_print_exception ("Caught exception:");
108 return -1;
111 if (status != -1)
112 ACE_DEBUG ((LM_INFO,
113 "PortableInterceptor::Redirection test passed.\n"));
115 return status;