Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Bug_3647_Regression / client.cpp
blob2098f1ebec4d64973f2983ea66e75162fe18cdfa
1 // -*- C++ -*-
2 #include "TestC.h"
3 #include "tao/Strategies/advanced_resource.h"
4 #include "tao/Utils/PolicyList_Destroyer.h"
5 #include "tao/Messaging/Messaging.h"
6 #include "tao/AnyTypeCode/Any.h"
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR *ior = ACE_TEXT ("file://middle.ior");
10 bool verbose = true;
11 long timeout = 2;
13 void
14 usage(ACE_TCHAR const *cmd,
15 ACE_TCHAR const *msg)
17 ACE_ERROR ((LM_ERROR,
18 ACE_TEXT("usage: %s ")
19 ACE_TEXT("-v ")
20 ACE_TEXT("-k <ior> ")
21 ACE_TEXT("-t timeout ")
22 ACE_TEXT("\n")
23 ACE_TEXT(" %s\n"),
24 cmd, msg));
27 int
28 parse_args (int argc, ACE_TCHAR *argv[])
30 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("vk:t:"));
31 int c;
32 ACE_TCHAR const *stimeout = 0;
34 while ((c = get_opts ()) != -1)
35 switch (c)
37 case 'v':
38 verbose = true;
39 break;
41 case 'k':
42 ior = get_opts.opt_arg ();
43 break;
45 case 't':
46 stimeout = get_opts.opt_arg();
47 break;
49 case '?':
50 default:
51 usage(argv[0], ACE_TEXT("unknown argument"));
52 return -1;
55 if (stimeout != 0)
57 ACE_TCHAR *end;
58 long tmp = ACE_OS::strtol(stimeout, &end, 10);
59 if (end == 0 || *end != '\0')
61 usage(argv[0], ACE_TEXT("Invalid timeout value"));
62 return -1;
64 timeout = tmp;
67 // Indicates successful parsing of the command line
68 return 0;
71 int
72 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
74 try
76 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
78 if (parse_args (argc, argv) != 0)
79 return 1;
81 CORBA::Object_var tmp = orb->string_to_object(ior);
83 // one second in TimeT units
84 TimeBase::TimeT const second = 10 * TimeBase::TimeT(1000000);
86 CORBA::Any timeout_as_any;
87 timeout_as_any <<= TimeBase::TimeT(timeout * second);
89 TAO::Utils::PolicyList_Destroyer plist(1);
90 plist.length(1);
91 plist[0] =
92 orb->create_policy(Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
93 timeout_as_any);
95 tmp = tmp->_set_policy_overrides(plist, CORBA::SET_OVERRIDE);
97 Bug_3647_Regression::Middle_var middle =
98 Bug_3647_Regression::Middle::_narrow(tmp.in ());
100 if (CORBA::is_nil (middle.in ()))
102 ACE_ERROR_RETURN ((LM_DEBUG,
103 "client(%P|%t) - nil "
104 "Bug_3647_Regression::Middle reference <%s>\n",
105 ior),
109 // Startup the tests ...
110 middle->startup_test();
112 ACE_DEBUG ((LM_DEBUG, "client(%P|%t) - test started up\n"));
114 int const iterations = 10000;
115 int const interval = iterations / 20;
116 ACE_DEBUG ((LM_DEBUG, "client(%P|%t) - running pings"));
117 for (int i = 0; i != iterations; ++i)
119 middle->ping();
120 if (i % interval == 0 && i > 0)
122 ACE_DEBUG((LM_DEBUG, "."));
125 ACE_DEBUG ((LM_DEBUG, "done\n"));
127 middle->shutdown ();
128 ACE_DEBUG ((LM_DEBUG,
129 "client(%P|%t) - server shutdown request sent\n"));
131 orb->destroy ();
133 catch (const CORBA::Exception& ex)
135 ACE_DEBUG ((LM_DEBUG,
136 "client"));
137 ex._tao_print_exception ("Exception caught:");
138 return 1;
141 return 0;