Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / ForwardRequest / client.cpp
blobccb2b1f35aa19f552b28346080f7a3a192a2b12a
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
4 #include "testC.h"
5 #include "Client_ORBInitializer.h"
7 #include "tao/ORBInitializer_Registry.h"
9 const ACE_TCHAR *ior1 = 0;
10 const ACE_TCHAR *ior2 = 0;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 if (argc != 5) // foo -k IOR_1 -k IOR_2
16 ACE_ERROR_RETURN ((LM_ERROR,
17 "Wrong number of arguments.\n"),
18 -1);
20 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
21 int c;
23 while ((c = get_opts ()) != -1)
24 switch (c)
26 case 'k':
28 if (ior1 == 0)
29 ior1 = get_opts.opt_arg ();
30 else if (ior2 == 0)
31 ior2 = get_opts.opt_arg ();
33 break;
34 default:
35 ACE_ERROR_RETURN ((LM_ERROR,
36 "Usage: %s "
37 "-k IOR_1 -k IOR_2\n",
38 argv[0]),
39 -1);
42 return 0;
45 int
46 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
48 int status = 0;
50 try
52 #if TAO_HAS_INTERCEPTORS == 1
53 PortableInterceptor::ORBInitializer_ptr temp_initializer =
54 PortableInterceptor::ORBInitializer::_nil ();
56 ACE_NEW_RETURN (temp_initializer,
57 Client_ORBInitializer,
58 -1); // No exceptions yet!
59 PortableInterceptor::ORBInitializer_var orb_initializer =
60 temp_initializer;
62 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
63 #endif /* TAO_HAS_INTERCEPTORS == 1 */
65 CORBA::ORB_var orb = CORBA::ORB_init (argc,
66 argv,
67 "Client ORB");
69 if (::parse_args (argc, argv) != 0)
70 return -1;
72 // Start out with the first IOR. Interaction with the second
73 // IOR occurs during the various interceptions executed during
74 // this test.
75 CORBA::Object_var object =
76 orb->string_to_object (ior1);
78 ForwardRequestTest::test_var server =
79 ForwardRequestTest::test::_narrow (object.in ());
81 if (CORBA::is_nil (server.in ()))
83 ACE_ERROR_RETURN ((LM_ERROR,
84 "Object reference <%s> is nil.\n",
85 ior1),
86 1);
89 // Invoke the operation four times. By design, the last three
90 // invocations in this test will cause
91 // PortableInterceptor::ForwardRequest exceptions to be thrown,
92 // thus causing the request to be forwarded to another object.
94 CORBA::Short old_number = 0; // Previous invocation result.
95 CORBA::Short number = 0; // New invocation result.
96 for (int i = 1; i <= 5; ++i)
98 ACE_DEBUG ((LM_INFO,
99 "CLIENT: Issuing request %d.\n",
100 i));
102 if (i > 1)
103 old_number = number;
105 number = server->number ();
108 ACE_DEBUG ((LM_INFO,
109 "CLIENT: Request %d handled by object %d.\n",
111 number));
113 // Check if the new result is the same as the previous
114 // result.
116 // This test is designed so that no two sequential
117 // invocation results are the same. If they are the same,
118 // then the requests were invoked on the same object, one
119 // after the other. This means that forwarding did not
120 // occur, which is of course a failure in the
121 // PortableInterceptor::ForwardRequest support.
122 if (i > 1 && old_number == number)
124 status = -1;
126 ACE_ERROR ((LM_ERROR,
127 "TEST FAILED: Request was not "
128 "forwarded.\n"));
129 break;
133 server->shutdown ();
135 orb->destroy ();
137 catch (const CORBA::Exception& ex)
139 ex._tao_print_exception ("Caught exception:");
140 return -1;
143 if (status != -1)
144 ACE_DEBUG ((LM_INFO,
145 "PortableInterceptor::ForwardRequest test passed.\n"));
147 return status;