Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / OBV / ValueBox / Test_impl.cpp
blob7f6f0d2ceba33de2b4b18ffb644a4cc2f6a9a425
1 #include "Test_impl.h"
3 Test_impl::Test_impl (CORBA::ORB_ptr orb)
4 : orb_ (CORBA::ORB::_duplicate (orb))
8 //***************************************************************************
9 // Rotate characters in string, last character becomes the first and
10 // all others are shifted to the right.
11 //***************************************************************************
12 void rotate_string(char *s)
14 unsigned char c;
15 size_t l;
17 l = ACE_OS::strlen(s);
18 if (l>1)
20 c = s[l-1];
21 ACE_OS::memmove(&s[1], &s[0], l-1);
22 s[0] = c;
27 VBlong *
28 Test_impl::basic_op1 (VBlong * p1, VBlong *& p2, VBlong_out p3)
30 ACE_NEW_RETURN (p3,
31 VBlong (p2->_value()*5),
32 0);
34 p2->_value (p2->_value() * 3);
36 VBlong *retval = 0;
37 ACE_NEW_RETURN (retval,
38 VBlong (p1->_value()*3),
39 0);
41 return retval;
44 vb_basic::M_VBlong *
45 Test_impl::basic_op2 (vb_basic::M_VBlong * p1,
46 vb_basic::M_VBlong *& p2,
47 vb_basic::M_VBlong_out p3)
49 ACE_NEW_RETURN (p3,
50 vb_basic::M_VBlong (p2->_value()*5),
51 0);
53 p2->_value (p2->_value() * 3);
55 vb_basic::M_VBlong *retval = 0;
56 ACE_NEW_RETURN (retval,
57 vb_basic::M_VBlong (p1->_value()*3),
58 0);
60 return retval;
63 ::CORBA::Long
64 Test_impl::basic_op3 (::CORBA::Long p1, ::CORBA::Long& p2,
65 ::CORBA::Long_out p3)
67 p3 = p2 * 5;
69 p2 = p2 * 3;
71 return p1 * 3;
75 VBstring *
76 Test_impl::string_op1 (::VBstring * p1,
77 ::VBstring *& p2,
78 ::VBstring_out p3)
80 rotate_string (p2->_boxed_inout ());
82 ACE_NEW_RETURN (p3,
83 VBstring (p2->_value ()),
84 0);
86 rotate_string (p1->_boxed_inout ());
88 VBstring *retval = 0;
89 ACE_NEW_RETURN (retval,
90 VBstring (p1->_value ()),
91 0);
93 return retval;
96 char *
97 Test_impl::string_op2 (const char * p1,
98 char *& p2,
99 CORBA::String_out p3)
101 rotate_string (p2);
103 p3 = CORBA::string_alloc (ACE_OS::strlen(p2));
104 ACE_OS::strcpy (p3, p2);
106 rotate_string ((char *) p1);
108 char *return_string;
109 return_string = CORBA::string_alloc (ACE_OS::strlen(p1));
110 ACE_OS::strcpy (return_string, p1);
112 return return_string;
115 ::VBseqlong *
116 Test_impl::seq_op1 (::VBseqlong * p1,
117 ::VBseqlong *& p2,
118 ::VBseqlong_out p3)
120 ACE_NEW_RETURN (p3,
121 VBseqlong(*p2),
123 CORBA::ULong i;
124 for (i=0; i<p3->_value().length(); i++)
126 (*p3)[i] *= 5;
129 for (i=0; i<p2->_value().length(); i++)
131 (*p2)[i] *= 3;
134 VBseqlong *retval = 0;
135 ACE_NEW_RETURN (retval,
136 VBseqlong(*p1),
139 return retval;
142 void
143 Test_impl::seq_op2 (const ::TDseqlong & p1,
144 ::TDseqlong & p2,
145 ::TDseqlong_out p3)
147 ACE_NEW (p3,
148 TDseqlong(p1));
149 CORBA::ULong i;
150 for (i=0; i<p3->length(); i++)
152 (*p3)[i] *= 5;
155 for (i=0; i<p2.length(); i++)
157 p2[i] *= 3;
161 ::VBfixed_struct1 *
162 Test_impl::struct_op1 (::VBfixed_struct1 * p1,
163 ::VBfixed_struct1 *& p2,
164 ::VBfixed_struct1_out p3)
166 ACE_NEW_RETURN (p3,
167 VBfixed_struct1 (p2->_value()),
169 // transform p3 values
170 p3->l (p3->l() * 5);
171 p3->abstruct().s1 = (p3->abstruct()).s1 * 5;
172 p3->abstruct().s2 = (p3->abstruct()).s2 * 5;
174 // transform p2 values
175 p2->l (p2->l() * 3);
176 p2->abstruct().s1 = (p2->abstruct()).s1 * 3;
177 p2->abstruct().s2 = (p2->abstruct()).s2 * 3;
179 VBfixed_struct1 *retval = 0;
180 ACE_NEW_RETURN (retval,
181 VBfixed_struct1 (p1->_value()),
184 return retval;
187 void
188 Test_impl::struct_op2 (const ::Fixed_Struct1 & p1,
189 ::Fixed_Struct1 & p2,
190 ::Fixed_Struct1_out p3)
192 p3 = p1;
194 p2.l *= 3;
195 p2.abstruct.s1 *= 3;
196 p2.abstruct.s2 *= 3;
199 ::VBvariable_struct1 *
200 Test_impl::struct_op3 (::VBvariable_struct1 * p1,
201 ::VBvariable_struct1 *& p2,
202 ::VBvariable_struct1_out p3)
204 // transform p2 values
205 p2->l (p2->l() * 3);
206 rotate_string ((CORBA::Char *)p2->str());
208 ACE_NEW_RETURN (p3,
209 VBvariable_struct1 (p2->_value()),
212 VBvariable_struct1 *retval = 0;
213 ACE_NEW_RETURN (retval,
214 VBvariable_struct1 (p1->_value()),
217 return retval;
221 void
222 Test_impl::struct_op4 (const ::Variable_Struct1 & p1,
223 ::Variable_Struct1 & p2,
224 ::Variable_Struct1_out p3)
226 ACE_NEW (p3,
227 Variable_Struct1());
228 p3->l = p1.l;
229 p3->str = p1.str;
231 p2.l *= 3;
232 rotate_string ((CORBA::Char *)p2.str.in());
236 ::VBlongarray *
237 Test_impl::array_op1 (::VBlongarray * p1,
238 ::VBlongarray *& p2,
239 ::VBlongarray_out p3)
241 long array_len = sizeof(LongArray) / sizeof(CORBA::Long);
243 for (long i=0; i<array_len; i++)
245 (*p2)[i] *= 3;
248 ACE_NEW_RETURN (p3,
249 VBlongarray(*p2),
252 VBlongarray *retval = 0;
253 ACE_NEW_RETURN (retval,
254 VBlongarray(*p1),
257 return retval;
260 void
261 Test_impl::array_op2 (const ::LongArray p1,
262 ::LongArray p2,
263 ::LongArray_out p3)
265 long array_len = sizeof(LongArray) / sizeof(CORBA::Long);
267 long i;
268 for (i=0; i<array_len; i++)
270 p2[i] *= 3;
273 for (i=0; i<array_len; i++)
275 p3[i] = p1[i];
280 ::VBstringarray *
281 Test_impl::array_op3 (::VBstringarray * p1,
282 ::VBstringarray *& p2,
283 ::VBstringarray_out p3)
285 long array_len = sizeof( ::StringArray ) / sizeof( StringArray_slice );
287 char * p;
288 for (long i=0; i<array_len; i++)
290 p = (CORBA::Char *)((*p2)[i]).in();
291 rotate_string (p);
294 ACE_NEW_RETURN (p3,
295 VBstringarray(*p2),
298 VBstringarray *retval = 0;
299 ACE_NEW_RETURN (retval,
300 VBstringarray(*p1),
303 return retval;
306 void
307 Test_impl::array_op4 (const ::StringArray p1,
308 ::StringArray p2,
309 ::StringArray_out p3)
311 long array_len = sizeof( ::StringArray ) / sizeof( StringArray_slice );
313 char * p;
314 long i;
315 for (i=0; i<array_len; i++)
317 p = (CORBA::Char *)(p2[i]).in();
318 rotate_string (p);
321 StringArray_slice *sa = StringArray_alloc ();
323 for (i=0; i<array_len; i++)
325 sa[i] = p1[i];
328 p3 = sa;
333 ::VBfixed_union1 *
334 Test_impl::union_op1 (::VBfixed_union1 * p1,
335 ::VBfixed_union1 *& p2,
336 ::VBfixed_union1_out p3)
338 CORBA::Long longValue;
339 CORBA::Short shortValue;
340 ACE_NEW_RETURN (p3,
341 VBfixed_union1 (),
343 VBfixed_union1 *rv = 0;
344 ACE_NEW_RETURN (rv,
345 VBfixed_union1 (),
348 // Set output and return values
349 switch (p1->_d ())
351 case 1: // Long
352 longValue = p1->m1 () * 3;
353 p3->m1 (longValue);
354 rv->m1 (longValue);
355 break;
356 case 2: // Short
357 shortValue = p1->m2 () * 3;
358 p3->m2 (shortValue);
359 rv->m2 (shortValue);
360 break;
363 // Set new "inout" parameter value
364 switch (p2->_d())
366 case 1: // Long
367 p2->m1 (p2->m1 () * 3);
368 break;
369 case 2: // Short
370 p2->m2 (p2->m2 () * 3);
371 break;
374 return rv;
377 void
378 Test_impl::union_op2 (const ::Fixed_Union1 & p1,
379 ::Fixed_Union1 & p2,
380 ::Fixed_Union1_out p3)
382 p3 = p1;
384 // Set new "inout" parameter value
385 switch (p2._d())
387 case 1: // Long
388 p2.m1 (p2.m1 () * 3);
389 break;
390 case 2: // Short
391 p2.m2 (p2.m2 () * 3);
392 break;
396 ::VBvariable_union1 *
397 Test_impl::union_op3 (::VBvariable_union1 * p1,
398 ::VBvariable_union1 *& p2,
399 ::VBvariable_union1_out p3)
401 CORBA::Long longValue;
402 CORBA::String_var stringValue;
403 ACE_NEW_RETURN (p3,
404 VBvariable_union1 (),
406 VBvariable_union1 *rv = 0;
407 ACE_NEW_RETURN (rv,
408 VBvariable_union1 (),
412 // Set output and return values
413 switch (p1->_d ())
415 case 1: // Long
416 longValue = p1->m1 ();
417 p3->m1 (longValue);
418 rv->m1 (longValue);
419 break;
420 case 2: // String
421 stringValue = p1->m2 ();
422 p3->m2 (stringValue);
423 rv->m2 (stringValue);
424 break;
427 // Set new "inout" parameter value
428 switch (p2->_d())
430 case 1: // Long
431 p2->m1 (p2->m1 () * 3);
432 break;
433 case 2: // String
434 stringValue = p2->m2 ();
435 rotate_string (stringValue);
436 p2->m2 (stringValue);
437 break;
440 return rv;
443 void
444 Test_impl::union_op4 (const ::Variable_Union1 & p1,
445 ::Variable_Union1 & p2,
446 ::Variable_Union1_out p3)
448 CORBA::String_var stringValue;
450 // Return value of "in" parameter to "out" parameter
451 ACE_NEW (p3,
452 Variable_Union1());
454 switch (p1._d ())
456 case 1: // Long
457 p3->m1 (p1.m1 ());
458 break;
459 case 2: // String
460 p3->m2 (p1.m2 ());
461 break;
464 // Set new "inout" parameter value
465 switch (p2._d())
467 case 1: // Long
468 p2.m1 (p2.m1 () * 3);
469 break;
470 case 2: // String
471 stringValue = p2.m2 ();
472 rotate_string (stringValue);
473 p2.m2 (stringValue);
474 break;
479 void
480 Test_impl::shutdown (void)
482 this->orb_->shutdown (0);