Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / ReconnectServer / client.cpp
blob60d7cf51eb54fd2bf34e3f97ba737a9bb7c1b4c0
1 #include "testS.h"
2 #include "tao/AnyTypeCode/Any.h"
3 #include "ace/Get_Opt.h"
4 #include <ace/Task.h>
5 #include "ace/OS_NS_unistd.h"
7 const ACE_TCHAR *ior_input_file = ACE_TEXT ("file://serverA.ior");
8 int test_duration_sec = 15;
9 bool expect_object_not_exist = false;
11 class Client_Task : public ACE_Task_Base
13 public:
14 Client_Task (taoimrtest::reconnectserver::TimeSrv_ptr obj)
15 : test_ (taoimrtest::reconnectserver::TimeSrv::_duplicate (obj)),
16 communication_failed_ (false),
17 reconnected_ (false),
18 caught_object_not_exist_ (false)
21 virtual int svc ()
23 ACE_Time_Value start = ACE_OS::gettimeofday ();
24 ACE_Time_Value elapsed;
25 for (int i = 0; elapsed < ACE_Time_Value (test_duration_sec); i++)
27 try
29 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)Request %d\n"), i ));
30 test_->current_time();
31 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)Done request %d\n"), i ));
32 if (communication_failed_)
34 communication_failed_ = false;
35 reconnected_ = true;
38 catch (const CORBA::OBJECT_NOT_EXIST &)
40 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)caught OBJECT_NOT_EXIST exception for request %d\n"), i ));
41 caught_object_not_exist_ = true;
43 catch (const CORBA::Exception & /*ex*/)
45 communication_failed_ = true;
47 ACE_OS::sleep (1);
48 elapsed = ACE_OS::gettimeofday () - start;
51 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)Client thread exit \n")));
52 return 0;
55 bool test_passed () const
57 bool conn_test = communication_failed_ != reconnected_;
58 bool one_test = expect_object_not_exist == caught_object_not_exist_;
59 bool success = (conn_test && one_test);
60 if (!success)
62 ACE_DEBUG ((LM_DEBUG,
63 ACE_TEXT ("(%P|%t)Client results, cf = %d, r = %d, ")
64 ACE_TEXT ("eone = %d, cone = %d\n"),
65 communication_failed_, reconnected_,
66 expect_object_not_exist, caught_object_not_exist_));
68 return success;
71 private:
72 taoimrtest::reconnectserver::TimeSrv_var test_;
73 bool communication_failed_;
74 bool reconnected_;
75 bool caught_object_not_exist_;
79 int
80 parse_args (int argc, ACE_TCHAR* argv[])
82 ACE_Get_Opt get_opts (argc, argv, "i:t:e:");
83 int c;
86 while ((c = get_opts ()) != -1)
87 switch (c)
89 case 'i':
90 ior_input_file = get_opts.opt_arg ();
91 break;
92 case 't':
93 test_duration_sec = ACE_OS::atoi (get_opts.opt_arg ());
94 break;
95 case 'e':
96 expect_object_not_exist = ACE_OS::atoi (get_opts.opt_arg ());
97 break;
98 case '?':
99 default:
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "usage: %s "
102 "-i <iorfile> -t <test_duration>"
103 "\n",
104 argv [0]),
105 -1);
107 // Indicates successful parsing of the command line
108 return 0;
112 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
116 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
118 if (parse_args (argc, argv) != 0)
120 return 1;
123 CORBA::Object_var object = orb->resolve_initial_references ("RootPOA");
125 object = orb->string_to_object(ior_input_file);
127 taoimrtest::reconnectserver::TimeSrv_var test =
128 taoimrtest::reconnectserver::TimeSrv::_narrow(object.in ());
130 if (CORBA::is_nil(test.in ()))
132 ACE_ERROR_RETURN ((LM_ERROR,
133 "(%P|%t) Object reference is nil \n"),
137 Client_Task task (test.in ());
138 task.activate (THR_NEW_LWP | THR_JOINABLE, 1, 1);
140 ACE_Time_Value tv(test_duration_sec);
141 orb->run (&tv);
143 task.wait ();
145 orb->destroy ();
147 if (task.test_passed ())
149 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Client test passed \n")));
151 else
153 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) Client test failed.\n")), 1);
156 catch (const CORBA::Exception &ex)
158 ex._tao_print_exception ("Exception caught by client:");
159 return 1;
162 return 0;