Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / DII_Collocation_Tests / oneway / Client_Task.cpp
blobca5c1aa295ab46fecfcc4c3990e6399db5c63338
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 CORBA::Long TEST_BASIC_VALUE = 12345;
10 CORBA::Char TEST_SPECIAL_VALUE = 'x';
11 CORBA::Short TEST_HOUR = 12;
12 CORBA::Short TEST_MINUTE = 59;
13 CORBA::Short TEST_SECOND = 59;
15 Client_Task::Client_Task (const ACE_TCHAR *ior,
16 const ACE_TCHAR *simple_test_ior,
17 CORBA::ORB_ptr corb,
18 ACE_Thread_Manager *thr_mgr)
19 : ACE_Task_Base (thr_mgr)
20 , input_ (ior)
21 , simple_test_input_ (simple_test_ior)
22 , corb_ (CORBA::ORB::_duplicate (corb))
23 , error_count_ (0)
27 int
28 Client_Task::svc (void)
30 try
32 CORBA::Object_var obj =
33 this->corb_->string_to_object (input_);
35 if (CORBA::is_nil (obj.in ()))
37 ACE_ERROR_RETURN ((LM_DEBUG,
38 "Nil Test::Hello reference <%s>\n",
39 input_),
40 1);
43 CORBA::Object_var simple_test_obj =
44 this->corb_->string_to_object (simple_test_input_);
46 if (CORBA::is_nil (simple_test_obj.in ()))
48 ACE_ERROR_RETURN ((LM_DEBUG,
49 "Nil Test::Simple_Test reference <%s>\n",
50 simple_test_input_),
51 1);
54 Test::Simple_Test_var simple_test
55 = Test::Simple_Test::_narrow (simple_test_obj.in ());
57 CORBA::Request_var req (obj->_request ("test_basic_arg"));
58 req->add_in_arg ("basic") <<= TEST_BASIC_VALUE;
59 req->send_oneway ();
62 req = obj->_request ("test_unbounded_string_arg");
64 req->add_in_arg ("ub_string") <<= TEST_STR;
65 req->send_oneway ();
68 req = obj->_request ("test_bounded_string_arg");
70 ACE_CString bs (TEST_STR);
71 bs = bs.substr (0, ::Test::BOUNDED_STRING_SIZE);
73 req->add_in_arg ("bd_string")
74 <<= CORBA::Any::from_string (bs.c_str (), ::Test::BOUNDED_STRING_SIZE);
75 req->send_oneway ();
78 req = obj->_request ("test_fixed_array_arg");
80 ::Test::Fixed_Array fixed_array;
82 for (CORBA::ULong m = 0 ; m < ::Test::FIX_ARRAY_SIZE; m ++)
84 fixed_array[m] = m + 999;
87 req->add_in_arg ("fixed_array") <<= ::Test::Fixed_Array_forany (fixed_array);
88 req->send_oneway ();
91 req = obj->_request ("test_var_array_arg");
93 ::Test::Var_Array var_array;
95 for (CORBA::ULong i = 0; i < ::Test::VAR_ARRAY_SIZE; ++i)
97 var_array[i] = CORBA::string_dup(TEST_STR);
100 req->add_in_arg ("var_array") <<= var_array;
101 req->send_oneway ();
104 req = obj->_request ("test_bounded_var_size_arg");
106 ACE_CString bvs (TEST_STR);
107 bvs = bvs.substr (0, ::Test::BOUNDED_VAR_SIZE);
109 ::Test::Bounded_Var_Size_Arg* bd_var_size
110 = new ::Test::Bounded_Var_Size_Arg();
112 bd_var_size->replace (::Test::BOUNDED_VAR_SIZE,
113 const_cast <CORBA::Char*> (bvs.c_str ()));
115 req->add_in_arg ("bd_var_size") <<= bd_var_size;
116 req->send_oneway ();
119 req = obj->_request ("test_unbounded_var_size_arg");
121 ::Test::Unbounded_Var_Size_Arg* ub_var_size
122 = new ::Test::Unbounded_Var_Size_Arg();
123 ub_var_size->replace (ub_var_size->maximum (),
124 ACE_OS::strlen (TEST_STR),
125 TEST_STR);
127 req->add_in_arg ("ub_var_size") <<= ub_var_size;
128 req->send_oneway ();
131 req = obj->_request ("test_fixed_size_arg");
133 ::Test::TimeOfDay t;
134 t.hour = TEST_HOUR;
135 t.minute = TEST_MINUTE;
136 t.second = TEST_SECOND;
138 req->add_in_arg ("fixed_size") <<= t;
139 req->send_oneway ();
142 req = obj->_request ("test_special_basic_arg");
144 req->add_in_arg ("special") <<= CORBA::Any::from_char (TEST_SPECIAL_VALUE);
145 req->send_oneway ();
148 req = obj->_request ("test_object_arg");
150 req->add_in_arg ("object") <<= simple_test_obj.in ();
151 req->send_oneway ();
154 req = obj->_request ("test_objref_arg");
156 req->add_in_arg ("objref") <<= simple_test.in ();
157 req->send_oneway ();
160 req = obj->_request ("test_args_1");
162 req->add_in_arg ("arg1") <<= simple_test_obj.in ();
163 req->add_in_arg ("arg2") <<= CORBA::Any::from_char (TEST_SPECIAL_VALUE);
164 req->add_in_arg ("arg3") <<= simple_test.in ();
165 req->send_oneway ();
168 req = obj->_request ("test_args_2");
170 req->add_in_arg ("arg1") <<= TEST_STR;
171 req->add_in_arg ("arg2") <<= ::Test::Fixed_Array_forany (fixed_array);
172 req->add_in_arg ("arg3") <<= t;
173 req->send_oneway ();
176 req = obj->_request ("test_args_3");
178 bd_var_size
179 = new ::Test::Bounded_Var_Size_Arg();
180 bd_var_size->replace (::Test::BOUNDED_VAR_SIZE,
181 const_cast <CORBA::Char*> (bvs.c_str ()));
183 ub_var_size
184 = new ::Test::Unbounded_Var_Size_Arg();
185 ub_var_size->replace (ub_var_size->maximum (),
186 ACE_OS::strlen (TEST_STR),
187 TEST_STR);
189 for (CORBA::ULong j = 0; j < ::Test::VAR_ARRAY_SIZE; ++j)
191 var_array[j] = CORBA::string_dup(TEST_STR);
194 req->add_in_arg ("arg1")
195 <<= CORBA::Any::from_string (bs.c_str (), ::Test::BOUNDED_STRING_SIZE);
197 req->add_in_arg ("arg2") <<= bd_var_size;
198 req->add_in_arg ("arg3") <<= ub_var_size;
199 req->add_in_arg ("arg4") <<= var_array;
200 req->send_oneway ();
203 req = obj->_request ("shutdown");
205 req->send_oneway ();
209 catch (const CORBA::Exception& ex)
211 error_count_ ++;
212 ex._tao_print_exception ("Exception caught:");
213 return 1;
215 catch (...)
217 error_count_ ++;
218 ACE_ERROR ((LM_ERROR, "(%P|%t)Client_Task::svc - caught unknown exception\n"));
219 return 1;
222 return 0;
226 CORBA::ULong
227 Client_Task::error_count () const
229 return error_count_;