Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / DII_Collocation_Tests / twoway / Client_Task.cpp
blob1459ceae8b74b021e5e1b4073e2e8aee49099bf7
2 #include "tao/DynamicInterface/Request.h" /* This must come first for
3 G++ 3.4 or better */
4 #include "Client_Task.h"
5 #include "TestC.h"
6 #include "tao/Object.h"
8 char TEST_STR[] = "This is a DII collocation test.";
9 char NULL_STR[] = "";
10 CORBA::Long TEST_BASIC_VALUE = 12345;
11 CORBA::Char TEST_SPECIAL_VALUE = 'x';
12 CORBA::Short TEST_HOUR = 12;
13 CORBA::Short TEST_MINUTE = 59;
14 CORBA::Short TEST_SECOND = 59;
16 Client_Task::Client_Task (const ACE_TCHAR *ior,
17 const ACE_TCHAR *simple_test_ior,
18 CORBA::ORB_ptr corb,
19 ACE_Thread_Manager *thr_mgr)
20 : ACE_Task_Base (thr_mgr)
21 , input_ (ior)
22 , simple_test_input_ (simple_test_ior)
23 , corb_ (CORBA::ORB::_duplicate (corb))
24 , error_count_ (0)
28 int
29 Client_Task::svc (void)
31 try
33 CORBA::Object_var obj =
34 this->corb_->string_to_object (input_);
36 if (CORBA::is_nil (obj.in ()))
38 ACE_ERROR_RETURN ((LM_DEBUG,
39 "Nil Test::Hello reference <%s>\n",
40 input_),
41 1);
44 CORBA::Object_var simple_test_obj =
45 this->corb_->string_to_object (simple_test_input_);
47 if (CORBA::is_nil (simple_test_obj.in ()))
49 ACE_ERROR_RETURN ((LM_ERROR,
50 "Nil Test::Simple_Test reference <%s>\n",
51 simple_test_input_),
52 1);
55 Test::Simple_Test_var simple_test
56 = Test::Simple_Test::_narrow (simple_test_obj.in ());
57 CORBA::Long l = 200;
58 CORBA::Request_var req (obj->_request ("test_basic_arg"));
59 req->add_in_arg ("basic") <<= TEST_BASIC_VALUE;
60 req->add_out_arg ("x") <<= l;
61 req->invoke ();
62 if (req->response_received ())
64 for (CORBA::ULong count=0; count<req->arguments ()->count () ;++count)
66 CORBA::NamedValue_ptr arg = req->arguments ()->item (count);
67 if (ACE_OS::strcmp (arg->name (), "x") == 0)
69 CORBA::Long y = 0;
70 if (*(arg->value()) >>= y)
72 if (y != 10)
74 ++error_count_;
75 ACE_ERROR_RETURN ((LM_ERROR, "Invalid out value, received %d\n", y), 1);
78 else
80 ++error_count_;
81 ACE_ERROR_RETURN ((LM_ERROR, "Invalid typed value\n"), 1);
86 else
88 ++error_count_;
89 ACE_ERROR_RETURN ((LM_ERROR, "Response received not true\n"), 1);
92 req = obj->_request ("test_unbounded_string_arg");
94 req->add_in_arg ("ub_string") <<= TEST_STR;
95 req->invoke ();
96 if (req->response_received ())
99 else
101 ++error_count_;
102 ACE_ERROR_RETURN ((LM_ERROR, "Response received not true\n"), 1);
105 req = obj->_request ("test_unbounded_string_arg_out");
107 req->add_in_arg ("ub_string") <<= TEST_STR;
108 req->add_out_arg ("x") <<= NULL_STR;
109 req->invoke ();
110 if (req->response_received ())
112 for (CORBA::ULong count=0; count<req->arguments ()->count () ;++count)
114 CORBA::NamedValue_ptr arg = req->arguments ()->item (count);
115 if (ACE_OS::strcmp (arg->name (), "x") == 0)
117 const char * ystring = 0;
118 if (*(arg->value()) >>= ystring)
120 if (ACE_OS::strcmp(ystring, TEST_STR) != 0)
122 ++error_count_;
123 ACE_ERROR_RETURN ((LM_ERROR, "Invalid out value, received %s\n", ystring), 1);
126 else
128 ++error_count_;
129 ACE_ERROR_RETURN ((LM_ERROR, "Invalid typed value\n"), 1);
134 else
136 ++error_count_;
137 ACE_ERROR_RETURN ((LM_ERROR, "Response received not true\n"), 1);
140 req = obj->_request ("test_bounded_string_arg");
142 ACE_CString bs (TEST_STR);
143 bs = bs.substr (0, ::Test::BOUNDED_STRING_SIZE);
145 req->add_in_arg ("bd_string")
146 <<= CORBA::Any::from_string (bs.c_str (), ::Test::BOUNDED_STRING_SIZE);
147 req->invoke ();
150 req = obj->_request ("test_fixed_array_arg");
152 ::Test::Fixed_Array fixed_array;
154 for (CORBA::ULong m = 0 ; m < ::Test::FIX_ARRAY_SIZE; m ++)
156 fixed_array[m] = m + 999;
159 req->add_in_arg ("fixed_array") <<= ::Test::Fixed_Array_forany (fixed_array);
160 req->invoke ();
163 req = obj->_request ("test_var_array_arg");
165 ::Test::Var_Array var_array;
167 for (CORBA::ULong i = 0; i < ::Test::VAR_ARRAY_SIZE; ++i)
169 var_array[i] = CORBA::string_dup(TEST_STR);
172 req->add_in_arg ("var_array") <<= var_array;
173 req->invoke ();
176 req = obj->_request ("test_bounded_var_size_arg");
178 ACE_CString bvs (TEST_STR);
179 bvs = bvs.substr (0, ::Test::BOUNDED_VAR_SIZE);
181 ::Test::Bounded_Var_Size_Arg* bd_var_size
182 = new ::Test::Bounded_Var_Size_Arg();
184 bd_var_size->replace (::Test::BOUNDED_VAR_SIZE,
185 const_cast <CORBA::Char*> (bvs.c_str ()));
187 req->add_in_arg ("bd_var_size") <<= bd_var_size;
188 req->invoke ();
191 req = obj->_request ("test_unbounded_var_size_arg");
193 ::Test::Unbounded_Var_Size_Arg* ub_var_size
194 = new ::Test::Unbounded_Var_Size_Arg();
195 ub_var_size->replace (ub_var_size->maximum (),
196 ACE_OS::strlen (TEST_STR),
197 TEST_STR);
199 req->add_in_arg ("ub_var_size") <<= ub_var_size;
200 req->invoke ();
203 req = obj->_request ("test_fixed_size_arg");
205 ::Test::TimeOfDay t;
206 t.hour = TEST_HOUR;
207 t.minute = TEST_MINUTE;
208 t.second = TEST_SECOND;
210 req->add_in_arg ("fixed_size") <<= t;
211 req->invoke ();
214 req = obj->_request ("test_special_basic_arg");
216 req->add_in_arg ("special") <<= CORBA::Any::from_char (TEST_SPECIAL_VALUE);
217 req->invoke ();
220 req = obj->_request ("test_object_arg");
222 req->add_in_arg ("object") <<= simple_test_obj.in ();
223 req->invoke ();
226 req = obj->_request ("test_objref_arg");
228 req->add_in_arg ("objref") <<= simple_test.in ();
229 req->invoke ();
232 req = obj->_request ("test_args_1");
234 req->add_in_arg ("arg1") <<= simple_test_obj.in ();
235 req->add_in_arg ("arg2") <<= CORBA::Any::from_char (TEST_SPECIAL_VALUE);
236 req->add_in_arg ("arg3") <<= simple_test.in ();
237 req->invoke ();
240 req = obj->_request ("test_args_2");
242 req->add_in_arg ("arg1") <<= TEST_STR;
243 req->add_in_arg ("arg2") <<= ::Test::Fixed_Array_forany (fixed_array);
244 req->add_in_arg ("arg3") <<= t;
245 req->invoke ();
248 req = obj->_request ("test_args_3");
250 bd_var_size
251 = new ::Test::Bounded_Var_Size_Arg();
252 bd_var_size->replace (::Test::BOUNDED_VAR_SIZE,
253 const_cast <CORBA::Char*> (bvs.c_str ()));
255 ub_var_size
256 = new ::Test::Unbounded_Var_Size_Arg();
257 ub_var_size->replace (ub_var_size->maximum (),
258 ACE_OS::strlen (TEST_STR),
259 TEST_STR);
261 for (CORBA::ULong j = 0; j < ::Test::VAR_ARRAY_SIZE; ++j)
263 var_array[j] = CORBA::string_dup(TEST_STR);
266 req->add_in_arg ("arg1")
267 <<= CORBA::Any::from_string (bs.c_str (), ::Test::BOUNDED_STRING_SIZE);
269 req->add_in_arg ("arg2") <<= bd_var_size;
270 req->add_in_arg ("arg3") <<= ub_var_size;
271 req->add_in_arg ("arg4") <<= var_array;
272 req->invoke ();
275 req = obj->_request ("shutdown");
277 req->send_oneway ();
281 catch (const CORBA::Exception& ex)
283 ++error_count_;
284 ex._tao_print_exception ("Exception caught:");
285 return 1;
287 catch (...)
289 ++error_count_;
290 ACE_ERROR ((LM_ERROR, "(%P|%t)Client_Task::svc - caught unknown exception\n"));
291 return 1;
294 return 0;
298 CORBA::ULong
299 Client_Task::error_count () const
301 return error_count_;