Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / DII_Collocation_Tests / twoway / Hello.cpp
blob2d9afbb205a5a62a48251921639498170667ad70
1 #include "Hello.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/ORB_Table.h"
4 #include "tao/ORB_Core_Auto_Ptr.h"
5 // Force static build to load the DII_Arguments_Converter service.
6 #include "tao/DynamicInterface/DII_Arguments_Converter_Impl.h"
8 extern CORBA::Boolean debug;
9 extern char TEST_STR[];
10 extern CORBA::Long TEST_BASIC_VALUE;
11 extern CORBA::Char TEST_SPECIAL_VALUE;
12 extern CORBA::Short TEST_HOUR;
13 extern CORBA::Short TEST_MINUTE;
14 extern CORBA::Short TEST_SECOND;
16 #define ERROR_COUNT(message) \
17 { error_count_ ++; \
18 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)%s - failed error_count = %u\n"), \
19 message, error_count_)); \
22 // Implementation skeleton constructor
23 Test_Simple_Test_i::Test_Simple_Test_i ()
27 // Implementation skeleton destructor
28 Test_Simple_Test_i::~Test_Simple_Test_i ()
32 void Test_Simple_Test_i::test_method (
33 ::CORBA::ULong & error_count
36 error_count --;
39 Hello::Hello (CORBA::ORB_ptr orb,
40 ACE_thread_t thrid)
41 : orb_ (CORBA::ORB::_duplicate (orb))
42 , thr_id_ (thrid)
43 , error_count_ (0)
47 void
48 Hello::test_basic_arg (
49 ::CORBA::Long basic,
50 ::CORBA::Long_out x
53 if (basic != TEST_BASIC_VALUE)
54 ERROR_COUNT ("Hello::test_basic_arg")
56 x = 10;
59 void
60 Hello::test_unbounded_string_arg(const char* message)
62 if (debug)
63 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_unbounded_string_arg ")
64 ACE_TEXT("got unbounded string: %s\n"),
65 message));
66 if (ACE_OS::strncmp (message, TEST_STR, ACE_OS::strlen (TEST_STR) != 0))
68 ERROR_COUNT ("Hello::test_unbounded_string_arg")
72 void
73 Hello::test_unbounded_string_arg_out(const char* message, ::CORBA::String_out out_message)
75 if (debug)
76 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_unbounded_string_arg_out ")
77 ACE_TEXT("got unbounded string: %s\n"),
78 message));
79 if (ACE_OS::strncmp (message, TEST_STR, ACE_OS::strlen (TEST_STR) != 0))
81 ERROR_COUNT ("Hello::test_unbounded_string_arg_out")
83 out_message = CORBA::string_dup (message);
87 void
88 Hello::test_bounded_string_arg(const char* message)
90 if (debug)
91 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_bounded_string_arg ")
92 ACE_TEXT("got bounded string: %s\n"),
93 message));
94 if (ACE_OS::strncmp (message, TEST_STR, ::Test::BOUNDED_STRING_SIZE) != 0)
96 ERROR_COUNT ("Hello::test_bounded_string_arg")
101 void
102 Hello::test_fixed_array_arg(const ::Test::Fixed_Array message)
104 for (unsigned i = 0; i < ::Test::FIX_ARRAY_SIZE; i++)
106 if (debug)
107 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_fixed_array_arg ")
108 ACE_TEXT("got fixed array: %d\n"),
109 message[i]));
110 if (message[i] != static_cast<CORBA::Long> (i + 999))
111 ERROR_COUNT ("Hello::test_fixed_array_arg")
116 void
117 Hello::test_bounded_var_size_arg(const ::Test::Bounded_Var_Size_Arg& message)
119 if (debug)
120 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_bounded_var_size_arg ")
121 ACE_TEXT("got bounded var size arg\n")));
122 if (ACE_OS::strncmp (message.get_buffer (), TEST_STR, ::Test::BOUNDED_VAR_SIZE) != 0)
123 ERROR_COUNT ("Hello::test_bounded_var_size_arg")
127 void
128 Hello::test_unbounded_var_size_arg(const ::Test::Unbounded_Var_Size_Arg& message)
130 if (debug)
131 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_unbounded_var_size_arg ")
132 ACE_TEXT("got unbounded var size arg.\n")));
133 if (ACE_OS::strncmp (message.get_buffer (), TEST_STR, ACE_OS::strlen (TEST_STR)) != 0)
134 ERROR_COUNT ("Hello::test_unbounded_var_size_arg")
138 void
139 Hello::test_fixed_size_arg(const ::Test::TimeOfDay& t)
141 if (debug)
142 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_fixed_size_arg ")
143 ACE_TEXT("got timeofday: %d:%d:%d\n"),
144 t.hour, t.minute, t.second));
146 if (t.hour != TEST_HOUR
147 || t.minute != TEST_MINUTE
148 || t.second != TEST_SECOND)
149 ERROR_COUNT ("Hello::test_fixed_size_arg")
153 void
154 Hello::test_var_array_arg(const Test::Var_Array messages)
156 for (CORBA::ULong i = 0; i != ::Test::VAR_ARRAY_SIZE; i ++)
158 if (debug)
159 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_var_array_arg ")
160 ACE_TEXT("messages[%d] = %s\n"), i, messages[i].in ()));
161 if (ACE_OS::strncmp (messages[i].in (), TEST_STR, ACE_OS::strlen (TEST_STR)) != 0)
162 ERROR_COUNT ("Hello::test_var_array_arg")
167 void
168 Hello::test_special_basic_arg(CORBA::Char value)
170 if (debug)
171 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_special_basic_arg ")
172 ACE_TEXT(" got special basic arg: %c\n"), value));
173 if (value != TEST_SPECIAL_VALUE)
174 ERROR_COUNT ("Hello::test_special_basic_arg")
178 void Hello::test_objref_arg (
179 ::Test::Simple_Test_ptr test
182 if (debug)
183 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_objref_arg\n")));
185 if (CORBA::is_nil (test))
186 ERROR_COUNT ("Hello::test_objref_arg")
187 else
189 // Increment the error_count before calling test_method() and decrement
190 // the error_count when the server handling the test_method() call.
191 CORBA::ULong error_count = 0;
192 error_count ++;
193 test->test_method (error_count);
194 if (error_count != 0)
196 ERROR_COUNT ("Hello::test_objref_arg")
201 void Hello::test_object_arg (
202 ::CORBA::Object_ptr o
205 if (debug)
206 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_object_arg\n")));
207 ::Test::Simple_Test_var simple_test = ::Test::Simple_Test::_narrow (o);
209 CORBA::ULong error_count = 0;
210 error_count ++;
211 simple_test->test_method (error_count);
212 if (error_count != 0)
214 ERROR_COUNT ("Hello::test_object_arg")
218 void Hello::test_args_1 (
219 ::CORBA::Object_ptr arg1,
220 ::CORBA::Char arg2,
221 ::Test::Simple_Test_ptr arg3
224 if (debug)
225 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_args_1\n")));
226 ::Test::Simple_Test_var simple_test = ::Test::Simple_Test::_narrow (arg1);
228 CORBA::ULong error_count = 0;
229 error_count ++;
230 simple_test->test_method (error_count);
231 error_count ++;
232 arg3->test_method (error_count);
234 if (error_count != 0)
236 ERROR_COUNT ("Hello::test_args_1")
239 if (arg2 != TEST_SPECIAL_VALUE)
240 ERROR_COUNT ("Hello::test_args_1")
243 void Hello::test_args_2 (
244 const char * arg1,
245 const ::Test::Fixed_Array arg2,
246 const ::Test::TimeOfDay & arg3
249 if (debug)
250 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_args_2\n")));
251 if (ACE_OS::strncmp (arg1, TEST_STR, ACE_OS::strlen (TEST_STR)) != 0 )
252 ERROR_COUNT ("Hello::test_args_2")
254 for (unsigned i = 0; i < ::Test::FIX_ARRAY_SIZE; i++)
256 if (arg2[i] != static_cast<CORBA::Long> (i + 999))
257 ERROR_COUNT ("Hello::test_args_2")
260 if (arg3.hour != TEST_HOUR
261 || arg3.minute != TEST_MINUTE
262 || arg3.second != TEST_SECOND)
263 ERROR_COUNT ("Hello::test_args_2")
266 void Hello::test_args_3 (
267 const char * arg1,
268 const ::Test::Bounded_Var_Size_Arg & arg2,
269 const ::Test::Unbounded_Var_Size_Arg & arg3,
270 const ::Test::Var_Array arg4
273 if (debug)
274 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_args_3\n")));
275 if (ACE_OS::strncmp (arg1, TEST_STR, ACE_OS::strlen (arg1)) != 0)
276 ERROR_COUNT ("Hello::test_args_3")
277 if (ACE_OS::strncmp (arg2.get_buffer (), TEST_STR, ::Test::BOUNDED_VAR_SIZE) != 0)
278 ERROR_COUNT ("Hello::test_args_3")
279 if (ACE_OS::strncmp (arg3.get_buffer (), TEST_STR, ACE_OS::strlen (TEST_STR)) != 0)
280 ERROR_COUNT ("Hello::test_args_3")
281 for (CORBA::ULong i = 0; i != ::Test::VAR_ARRAY_SIZE; i ++)
283 if (ACE_OS::strncmp (arg4[i].in (), TEST_STR, ACE_OS::strlen (TEST_STR)) != 0)
284 ERROR_COUNT ("Hello::test_args_3")
288 char *
289 Hello::get_string ()
291 if (debug)
292 ACE_DEBUG ((LM_DEBUG,
293 "(%P|%t) Upcall in process ..\n"));
295 if (ACE_Thread::self () == this->thr_id_)
297 if (this->orb_->orb_core ()->optimize_collocation_objects () &&
298 this->orb_->orb_core ()->use_global_collocation ())
300 ACE_ERROR ((LM_ERROR,
301 "(%P|%t) ERROR: A remote call has been made "
302 " exiting ..\n"));
303 ACE_OS::abort ();
305 else if (this->orb_->orb_core ()->optimize_collocation_objects () &&
306 this->orb_->orb_core ()->use_global_collocation () == 0)
308 TAO::ORB_Table * const orb_table =
309 TAO::ORB_Table::instance ();
311 TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
312 if (tmp.get () == nullptr)
314 // We are running on a single ORB and this is an error.
315 ACE_ERROR ((LM_ERROR,
316 "(%P|%t) ERROR: A remote call has been made "
317 " with a single ORB "
318 " exiting ..\n"));
319 ACE_OS::abort ();
324 return CORBA::string_dup ("Hello there!");
327 char *
328 Hello::test_unbounded_string (
329 const char * s1,
330 char *& s2,
331 CORBA::String_out s3
334 char *retstr = CORBA::string_dup (s1);
335 s3 = CORBA::string_dup (s1);
336 char *tmp = CORBA::string_alloc (2*ACE_OS::strlen (s2));
337 ACE_OS::sprintf (tmp, "%s%s", s2, s2);
338 CORBA::string_free (s2);
339 s2 = tmp;
340 return retstr;
343 void
344 Hello::shutdown ()
346 // Give the client thread time to return from the collocated
347 // call to this method before shutting down the ORB. We sleep
348 // to avoid BAD_INV_ORDER exceptions on fast dual processor machines.
349 ACE_OS::sleep (1);
350 this->orb_->shutdown (false);
353 CORBA::ULong Hello::error_count () const
355 return error_count_;