Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / FaultTolerance / GroupRef_Manipulation / client.cpp
blobada224e6656111990fb845731f0612a0d8775d96
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "testC.h"
4 // Ensure that the PI library is linked in when building statically
5 #include "tao/PI/PI.h"
6 #include "orbsvcs/FaultTolerance/FT_Service_Activate.h"
8 const ACE_TCHAR *ior = 0;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "Usage: %s "
26 "-k IOR_1 -k IOR_2\n",
27 argv[0]),
28 -1);
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 int status = 0;
39 try
41 CORBA::ORB_var orb = CORBA::ORB_init (argc,
42 argv,
43 "Client ORB");
45 if (::parse_args (argc, argv) != 0)
46 return -1;
48 // Start out with the first IOR. Interaction with the second
49 // IOR occurs during the various interceptions executed during
50 // this test.
51 CORBA::Object_var object =
52 orb->string_to_object (ior);
54 ForwardRequestTest::test_var server =
55 ForwardRequestTest::test::_narrow (object.in ());
57 // Before and after the LOCATION_FORWARD_PERM the marshaled
58 // object reference must differ.
60 // Create a stringified/marshaled snapshot of Object reference
61 CORBA::String_var marshaled_obj_snapshot1 =
62 orb->object_to_string (server.in ());
64 if (CORBA::is_nil (server.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR,
67 "Object reference <%s> is nil\n",
68 ior),
69 1);
72 CORBA::ULong number = 0;
73 for (int i = 1; i <= 25; ++i)
75 ACE_DEBUG ((LM_INFO,
76 "CLIENT: Issuing request %d.\n",
77 i));
79 number += server->number ();
81 ACE_DEBUG ((LM_INFO,
82 "CLIENT: Number %d .\n",
83 number));
89 if (number < 250)
91 ACE_ERROR ((LM_ERROR,
92 "(%P|%t) ERROR: Did not forward to new location\n"));
93 ACE_OS::abort ();
96 // One of the request triggerd a LOCATION_FORWARD_PERM, in
97 // consequence the marshaled representation of "server" should
98 // look different now, compare to snapshot1.
99 CORBA::String_var marshaled_obj_snapshot2 =
100 orb->object_to_string (server.in ());
102 if (ACE_OS::strcmp (marshaled_obj_snapshot1.in (), marshaled_obj_snapshot2.in ()) == 0)
104 // Error, before and after the marhaled object references look equal
105 ACE_ERROR ((LM_ERROR,
106 "(%P|%t) ERROR: Marshaled Object reference should differ after LOCATION_FORWARD_PERM\n"));
107 ACE_OS::abort ();
110 server->shutdown ();
112 catch (const CORBA::Exception& ex)
114 ex._tao_print_exception ("Caught exception:");
115 return -1;
118 ACE_DEBUG ((LM_INFO,
119 "Group_Ref_Manip Test passed.\n"));
121 return status;