Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / DII_Collocation_Tests / oneway / Hello.cpp
blob128f6d994db963c9bf37ea7e7e0bfee778d21be7
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 (void)
27 // Implementation skeleton destructor
28 Test_Simple_Test_i::~Test_Simple_Test_i (void)
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
52 if (basic != TEST_BASIC_VALUE)
53 ERROR_COUNT ("Hello::test_basic_arg")
56 void
57 Hello::test_unbounded_string_arg(const char* message)
59 if (debug)
60 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_unbounded_string_arg ")
61 ACE_TEXT("got unbounded string: %s\n"),
62 message));
63 if (ACE_OS::strncmp (message, TEST_STR, ACE_OS::strlen (TEST_STR) != 0))
65 ERROR_COUNT ("Hello::test_unbounded_string_arg")
70 void
71 Hello::test_bounded_string_arg(const char* message)
73 if (debug)
74 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_bounded_string_arg ")
75 ACE_TEXT("got bounded string: %s\n"),
76 message));
77 if (ACE_OS::strncmp (message, TEST_STR, ::Test::BOUNDED_STRING_SIZE) != 0)
79 ERROR_COUNT ("Hello::test_bounded_string_arg")
84 void
85 Hello::test_fixed_array_arg(const ::Test::Fixed_Array message)
87 for (unsigned i = 0; i < ::Test::FIX_ARRAY_SIZE; i++)
89 if (debug)
90 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_fixed_array_arg ")
91 ACE_TEXT("got fixed array: %d\n"),
92 message[i]));
93 if (message[i] != static_cast<CORBA::Long> (i + 999))
94 ERROR_COUNT ("Hello::test_fixed_array_arg")
99 void
100 Hello::test_bounded_var_size_arg(const ::Test::Bounded_Var_Size_Arg& message)
102 if (debug)
103 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_bounded_var_size_arg ")
104 ACE_TEXT("got bounded var size arg\n")));
105 if (ACE_OS::strncmp (message.get_buffer (), TEST_STR, ::Test::BOUNDED_VAR_SIZE) != 0)
106 ERROR_COUNT ("Hello::test_bounded_var_size_arg")
110 void
111 Hello::test_unbounded_var_size_arg(const ::Test::Unbounded_Var_Size_Arg& message)
113 if (debug)
114 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_unbounded_var_size_arg ")
115 ACE_TEXT("got unbounded var size arg.\n")));
116 if (ACE_OS::strncmp (message.get_buffer (), TEST_STR, ACE_OS::strlen (TEST_STR)) != 0)
117 ERROR_COUNT ("Hello::test_unbounded_var_size_arg")
121 void
122 Hello::test_fixed_size_arg(const ::Test::TimeOfDay& t)
124 if (debug)
125 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_fixed_size_arg ")
126 ACE_TEXT("got timeofday: %d:%d:%d\n"),
127 t.hour, t.minute, t.second));
129 if (t.hour != TEST_HOUR
130 || t.minute != TEST_MINUTE
131 || t.second != TEST_SECOND)
132 ERROR_COUNT ("Hello::test_fixed_size_arg")
136 void
137 Hello::test_var_array_arg(const Test::Var_Array messages)
139 for (CORBA::ULong i = 0; i != ::Test::VAR_ARRAY_SIZE; i ++)
141 if (debug)
142 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_var_array_arg ")
143 ACE_TEXT("messages[%d] = %s\n"), i, messages[i].in ()));
144 if (ACE_OS::strncmp (messages[i].in (), TEST_STR, ACE_OS::strlen (TEST_STR)) != 0)
145 ERROR_COUNT ("Hello::test_var_array_arg")
150 void
151 Hello::test_special_basic_arg(CORBA::Char value)
153 if (debug)
154 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_special_basic_arg ")
155 ACE_TEXT(" got special basic arg: %c\n"), value));
156 if (value != TEST_SPECIAL_VALUE)
157 ERROR_COUNT ("Hello::test_special_basic_arg")
161 void Hello::test_objref_arg (
162 ::Test::Simple_Test_ptr test
165 if (debug)
166 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_objref_arg\n")));
168 if (CORBA::is_nil (test))
169 ERROR_COUNT ("Hello::test_objref_arg")
170 else
172 // Increment the error_count before calling test_method() and decrement
173 // the error_count when the server handling the test_method() call.
174 CORBA::ULong error_count = 0;
175 error_count ++;
176 test->test_method (error_count);
177 if (error_count != 0)
179 ERROR_COUNT ("Hello::test_objref_arg")
184 void Hello::test_object_arg (
185 ::CORBA::Object_ptr o
188 if (debug)
189 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_object_arg\n")));
190 ::Test::Simple_Test_var simple_test = ::Test::Simple_Test::_narrow (o);
192 CORBA::ULong error_count = 0;
193 error_count ++;
194 simple_test->test_method (error_count);
195 if (error_count != 0)
197 ERROR_COUNT ("Hello::test_object_arg")
201 void Hello::test_args_1 (
202 ::CORBA::Object_ptr arg1,
203 ::CORBA::Char arg2,
204 ::Test::Simple_Test_ptr arg3
207 if (debug)
208 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_args_1\n")));
209 ::Test::Simple_Test_var simple_test = ::Test::Simple_Test::_narrow (arg1);
211 CORBA::ULong error_count = 0;
212 error_count ++;
213 simple_test->test_method (error_count);
214 error_count ++;
215 arg3->test_method (error_count);
217 if (error_count != 0)
219 ERROR_COUNT ("Hello::test_args_1")
222 if (arg2 != TEST_SPECIAL_VALUE)
223 ERROR_COUNT ("Hello::test_args_1")
226 void Hello::test_args_2 (
227 const char * arg1,
228 const ::Test::Fixed_Array arg2,
229 const ::Test::TimeOfDay & arg3
232 if (debug)
233 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_args_2\n")));
234 if (ACE_OS::strncmp (arg1, TEST_STR, ACE_OS::strlen (TEST_STR)) != 0 )
235 ERROR_COUNT ("Hello::test_args_2")
237 for (unsigned i = 0; i < ::Test::FIX_ARRAY_SIZE; i++)
239 if (arg2[i] != static_cast<CORBA::Long> (i + 999))
240 ERROR_COUNT ("Hello::test_args_2")
243 if (arg3.hour != TEST_HOUR
244 || arg3.minute != TEST_MINUTE
245 || arg3.second != TEST_SECOND)
246 ERROR_COUNT ("Hello::test_args_2")
249 void Hello::test_args_3 (
250 const char * arg1,
251 const ::Test::Bounded_Var_Size_Arg & arg2,
252 const ::Test::Unbounded_Var_Size_Arg & arg3,
253 const ::Test::Var_Array arg4
256 if (debug)
257 ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t)Hello::test_args_3\n")));
258 if (ACE_OS::strncmp (arg1, TEST_STR, ACE_OS::strlen (arg1)) != 0)
259 ERROR_COUNT ("Hello::test_args_3")
260 if (ACE_OS::strncmp (arg2.get_buffer (), TEST_STR, ::Test::BOUNDED_VAR_SIZE) != 0)
261 ERROR_COUNT ("Hello::test_args_3")
262 if (ACE_OS::strncmp (arg3.get_buffer (), TEST_STR, ACE_OS::strlen (TEST_STR)) != 0)
263 ERROR_COUNT ("Hello::test_args_3")
264 for (CORBA::ULong i = 0; i != ::Test::VAR_ARRAY_SIZE; i ++)
266 if (ACE_OS::strncmp (arg4[i].in (), TEST_STR, ACE_OS::strlen (TEST_STR)) != 0)
267 ERROR_COUNT ("Hello::test_args_3")
271 char *
272 Hello::get_string (void)
274 if (debug)
275 ACE_DEBUG ((LM_DEBUG,
276 "(%P|%t) Upcall in process ..\n"));
278 if (ACE_Thread::self () == this->thr_id_)
280 if (this->orb_->orb_core ()->optimize_collocation_objects () &&
281 this->orb_->orb_core ()->use_global_collocation ())
283 ACE_ERROR ((LM_ERROR,
284 "(%P|%t) ERROR: A remote call has been made "
285 " exiting ..\n"));
286 ACE_OS::abort ();
288 else if (this->orb_->orb_core ()->optimize_collocation_objects () &&
289 this->orb_->orb_core ()->use_global_collocation () == 0)
291 TAO::ORB_Table * const orb_table =
292 TAO::ORB_Table::instance ();
294 TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
295 if (tmp.get () == 0)
297 // We are running on a single ORB and this is an error.
298 ACE_ERROR ((LM_ERROR,
299 "(%P|%t) ERROR: A remote call has been made "
300 " with a single ORB "
301 " exiting ..\n"));
302 ACE_OS::abort ();
307 return CORBA::string_dup ("Hello there!");
310 char *
311 Hello::test_unbounded_string (
312 const char * s1,
313 char *& s2,
314 CORBA::String_out s3
317 char *retstr = CORBA::string_dup (s1);
318 s3 = CORBA::string_dup (s1);
319 char *tmp = CORBA::string_alloc (2*ACE_OS::strlen (s2));
320 ACE_OS::sprintf (tmp, "%s%s", s2, s2);
321 CORBA::string_free (s2);
322 s2 = tmp;
323 return retstr;
326 void
327 Hello::shutdown (void)
329 // Give the client thread time to return from the collocated
330 // call to this method before shutting down the ORB. We sleep
331 // to avoid BAD_INV_ORDER exceptions on fast dual processor machines.
332 ACE_OS::sleep (1);
333 this->orb_->shutdown (0);
336 CORBA::ULong Hello::error_count () const
338 return error_count_;