2 #include "ace/Get_Opt.h"
4 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
7 parse_args (int argc
, ACE_TCHAR
*argv
[])
9 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
12 while ((c
= get_opts ()) != -1)
16 ior
= get_opts
.optarg
;
21 ACE_ERROR_RETURN ((LM_ERROR
,
28 // Indicates successful parsing of the command line
33 #define OBV_VERITY(Condition) \
38 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Failure at line %l\n")); \
43 // Templated function for testing various aspects of valuetypes.
44 // valuebox is a type created by the user, with UT as the underlying type.
45 // It is assumed that, on entry, valuebox->_value() != val1, and that
46 // val1 and val2 are distinct.
48 template <class BoxT
, class UT
>
49 int box_test1 (BoxT
*valuebox
, UT val1
, UT val2
)
52 BoxT
*valuebox_clone
= 0;
53 ACE_NEW_RETURN (valuebox_clone
,
57 // should be a deep copy of val1...
58 OBV_VERITY (&valuebox_clone
->_boxed_inout () != &valuebox
->_boxed_inout ());
60 // but values should be equal
61 OBV_VERITY (ACE::is_equal (valuebox_clone
->_value (), valuebox
->_value ()));
63 // Check that modifier is working.
64 valuebox_clone
->_value (val2
);
65 OBV_VERITY (!ACE::is_equal (valuebox_clone
->_value (), valuebox
->_value ()));
69 OBV_VERITY (ACE::is_equal (valuebox_clone
->_value (), valuebox
->_value ()));
71 // Check that _value and _boxed_in are the same.
72 OBV_VERITY (ACE::is_equal (valuebox_clone
->_value (), valuebox_clone
->_boxed_in ()));
73 OBV_VERITY (ACE::is_equal (valuebox
->_value (), valuebox
->_boxed_in ()));
75 // Used _boxed_inout to change the value
76 OBV_VERITY (!ACE::is_equal (valuebox
->_value (), val1
));
77 valuebox
->_boxed_inout () = val1
;
78 OBV_VERITY (ACE::is_equal (valuebox
->_value (), val1
));
80 // Use _boxed_out to access the value
81 OBV_VERITY (!ACE::is_equal (valuebox_clone
->_value (), val1
));
82 valuebox_clone
->_boxed_out () = val1
;
83 OBV_VERITY (ACE::is_equal (valuebox_clone
->_value (), val1
));
86 CORBA::ValueBase
*copy
= valuebox
->_copy_value ();
87 OBV_VERITY (copy
!= 0);
88 // check add_ref, remove_ref
92 // try downcast...then we can check that copy was correct.
93 BoxT
*down
= BoxT::_downcast (copy
);
97 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Failure at line %l\n"));
101 OBV_VERITY (ACE::is_equal (down
->_value (), val1
));
103 OBV_VERITY (!ACE::is_equal (down
->_value (), valuebox
->_value ()));
104 OBV_VERITY (ACE::is_equal (down
->_value (), val2
));
107 CORBA::remove_ref (copy
);
109 // cleanup. Use purify on the PC to check for leaks.
110 CORBA::remove_ref (valuebox_clone
);
115 template <class BoxT
, class UT
>
116 int simple_box_test ()
123 fail
+= box_test1
<BoxT
, UT
> (p
, 101, 202);
125 CORBA::remove_ref (p
);
131 // Test boxed values that use an underlying UT&
133 template <class BoxT
, class UT
>
134 int box_test_ref (BoxT
*valuebox
, UT
&val1
, UT
&val2
)
142 // should be a deep copy of val1...
143 OBV_VERITY (&p
->_boxed_inout () != &valuebox
->_boxed_inout ());
145 p
->_value (val2
); // deep copy
146 OBV_VERITY (&p
->_boxed_inout () != &valuebox
->_boxed_inout () );
148 *valuebox
= val2
; // deep copy, too.
149 OBV_VERITY (&p
->_boxed_inout () != &valuebox
->_boxed_inout () );
151 CORBA::remove_ref (p
);
161 fail
+= simple_box_test
<VBshort
, CORBA::Short
> ();
162 fail
+= simple_box_test
<VBlong
, CORBA::Long
> ();
163 fail
+= simple_box_test
<VBlonglong
, CORBA::LongLong
> ();
164 fail
+= simple_box_test
<VBushort
, CORBA::UShort
> ();
165 fail
+= simple_box_test
<VBulong
, CORBA::ULong
> ();
166 fail
+= simple_box_test
<VBulonglong
, CORBA::ULongLong
> ();
167 fail
+= simple_box_test
<VBwchar
, CORBA::WChar
> ();
168 fail
+= simple_box_test
<VBoctet
, CORBA::Octet
> ();
169 fail
+= simple_box_test
<VBfloat
, CORBA::Float
> ();
170 fail
+= simple_box_test
<VBdouble
, CORBA::Double
> ();
173 ACE_NEW_RETURN (pchar
,
176 fail
+= box_test1
<VBchar
, CORBA::Char
> (pchar
, 'A', 'Z');
177 CORBA::remove_ref (pchar
);
179 VBboolean
*pbool
= 0;
180 ACE_NEW_RETURN (pbool
,
183 fail
+= box_test1
<VBboolean
, CORBA::Boolean
> (pbool
, true, false);
184 CORBA::remove_ref (pbool
);
186 // Typedef of basic types
187 fail
+= simple_box_test
<VBTDshort
, CORBA::Short
> ();
188 fail
+= simple_box_test
<VBTDlong
, CORBA::Long
> ();
189 fail
+= simple_box_test
<VBTDlonglong
, CORBA::LongLong
> ();
190 fail
+= simple_box_test
<VBTDushort
, CORBA::UShort
> ();
191 fail
+= simple_box_test
<VBTDulong
, CORBA::ULong
> ();
192 fail
+= simple_box_test
<VBTDulonglong
, CORBA::ULongLong
> ();
193 fail
+= simple_box_test
<VBTDwchar
, CORBA::WChar
> ();
194 fail
+= simple_box_test
<VBTDoctet
, CORBA::Octet
> ();
195 fail
+= simple_box_test
<VBTDfloat
, CORBA::Float
> ();
196 fail
+= simple_box_test
<VBTDdouble
, CORBA::Double
> ();
198 VBTDchar
*pchar2
= 0;
199 ACE_NEW_RETURN (pchar2
,
202 fail
+= box_test1
<VBTDchar
, CORBA::Char
> (pchar2
, 'A', 'Z');
203 CORBA::remove_ref (pchar2
);
205 VBTDboolean
*pbool2
= 0;
206 ACE_NEW_RETURN (pbool2
,
209 fail
+= box_test1
<VBTDboolean
, CORBA::Boolean
> (pbool2
, true, false);
210 CORBA::remove_ref (pbool2
);
214 ACE_NEW_RETURN (penum
,
217 fail
+= box_test1
<VBenum
, Color
> (penum
, yellow
, red
);
218 CORBA::remove_ref (penum
);
220 // Typedef of enumerated type
221 VBTDenum
*penum2
= 0;
222 ACE_NEW_RETURN (penum2
,
225 fail
+= box_test1
<VBTDenum
, Color
> (penum2
, yellow
, red
);
226 CORBA::remove_ref (penum2
);
233 CORBA::Any_var
any1 (a1
);
239 CORBA::Any_var
any2 (a2
);
242 ACE_NEW_RETURN (pany
,
245 fail
+= box_test_ref
<VBany
, CORBA::Any
> (pany
, any1
.inout (),
247 CORBA::remove_ref (pany
);
251 ACE_NEW_RETURN (pany2
,
252 VBTDany (any1
.in ()),
254 fail
+= box_test_ref
<VBTDany
, CORBA::Any
> (pany2
, any1
.inout (),
256 CORBA::remove_ref (pany2
);
261 int test_basic_invocations (Test
* test_object
)
269 vb_basic::M_VBlong
*mp1
= 0;
270 vb_basic::M_VBlong
*mp2
= 0;
271 vb_basic::M_VBlong
*mp3
;
275 //============================================================
276 // Test method invocation with boxed value
277 //============================================================
286 OBV_VERITY (p1
->_value () == 25);
287 OBV_VERITY (p2
->_value () == 53);
290 test_object
->basic_op1(p1
, p2
, p3
);
292 OBV_VERITY (p2
->_value () == (53*3));
293 OBV_VERITY (p3
->_value () == (53*5));
294 OBV_VERITY (result
->_value () == (p1
->_value () *3));
296 //============================================================
297 // Test method invocation with boxed value from nested module
298 //============================================================
301 vb_basic::M_VBlong(25),
305 vb_basic::M_VBlong(53),
308 OBV_VERITY (mp1
->_value () == 25);
309 OBV_VERITY (mp2
->_value () == 53);
311 vb_basic::M_VBlong_var mresult
=
312 test_object
->basic_op2(mp1
, mp2
, mp3
);
314 OBV_VERITY (mp2
->_value () == (53*3));
315 OBV_VERITY (mp3
->_value () == (53*5));
316 OBV_VERITY (mresult
->_value () == (mp1
->_value () *3));
318 //============================================================
319 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
320 //============================================================
326 test_object
->basic_op3(p1
->_boxed_in(), p2
->_boxed_inout(),
329 OBV_VERITY (p2
->_value () == (93*3));
330 OBV_VERITY (p3
->_value () == (93*5));
331 OBV_VERITY (lresult
== (p1
->_value()*3));
333 catch (const CORBA::Exception
& ex
)
335 ex
._tao_print_exception ("test_basic_invocations");
340 ACE_DEBUG ((LM_DEBUG
,
341 "(%P|%t) test_basic_invocations: caught a C++ exception\n"));
344 if (p1
) p1
->_remove_ref ();
345 if (p2
) p2
->_remove_ref ();
346 if (p3
) p3
->_remove_ref ();
348 if (mp1
) mp1
->_remove_ref ();
349 if (mp2
) mp2
->_remove_ref ();
350 if (mp3
) mp3
->_remove_ref ();
356 int test_boxed_string()
359 const char *string1
= "First-string";
360 const char *string2
= "Second-string";
362 // Establish that we have data setup correctly...
363 OBV_VERITY (ACE_OS::strcmp (string1
, string2
) < 0);
364 OBV_VERITY (ACE_OS::strcmp (string2
, string1
) > 0);
365 OBV_VERITY (ACE_OS::strcmp (string1
, string1
) == 0);
367 // Make some objects, using our data
369 ACE_NEW_RETURN (temp
,
372 VBstring_var
vbstring1 (temp
);
374 VBstring
*vbstring2
= 0;
375 ACE_NEW_RETURN (vbstring2
,
376 VBstring(string1
), // tests const char * ctor.
379 OBV_VERITY (ACE_OS::strcmp (vbstring1
->_value(), string1
) == 0);
380 OBV_VERITY (ACE_OS::strcmp (vbstring2
->_value(), string1
) == 0);
382 // Test assignment operators
384 ACE_NEW_RETURN (carray1
,
387 ACE_OS::memcpy(carray1
, string2
, ACE_OS::strlen(string2
));
388 *vbstring2
= carray1
; // char * (adopted by box)
389 OBV_VERITY ((*vbstring2
)[0] == 'S');
390 *vbstring2
= string1
;
391 OBV_VERITY ((*vbstring2
)[0] == 'F');
392 CORBA::String_var
svar(string2
);
394 OBV_VERITY ((*vbstring2
)[0] == 'S');
396 // Test _value modifiers--like assignment drill above.
398 ACE_NEW_RETURN (carray2
,
401 ACE_OS::memcpy(carray2
, string1
, ACE_OS::strlen(string1
));
402 vbstring2
->_value(carray2
); // char * (adopted by box)
403 OBV_VERITY ((*vbstring2
)[0] == 'F');
404 vbstring2
->_value(string2
); // const char *
405 OBV_VERITY ((*vbstring2
)[0] == 'S');
406 (*vbstring2
)[0] = 'Y';
407 OBV_VERITY ((*vbstring2
)[0] != 'S');
408 vbstring2
->_value(svar
);
409 OBV_VERITY ((*vbstring2
)[0] == 'S');
410 // test value accessor
411 OBV_VERITY ((vbstring2
->_value())[0] == 'S');
415 // const boxed string
416 VBstring
*vbstring3
= 0;
417 ACE_NEW_RETURN (vbstring3
,
418 VBstring(*vbstring2
),
420 OBV_VERITY ((*vbstring3
)[0] == 'S');
421 (*vbstring3
)[0] = 'W';
422 OBV_VERITY ((*vbstring3
)[0] == 'W' && (*vbstring2
)[0] == 'S');
423 vbstring3
->_remove_ref ();
428 ACE_NEW_RETURN (carray3
,
431 ACE_OS::memcpy(carray3
, string1
, ACE_OS::strlen(string1
));
432 VBstring
*vbstring4
= 0;
433 ACE_NEW_RETURN (vbstring4
,
436 OBV_VERITY ((*vbstring4
)[0] == 'F');
437 vbstring4
->_remove_ref ();
440 // test CORBA::String_var ctor
441 VBstring
*vbstring5
= 0;
442 ACE_NEW_RETURN (vbstring5
,
445 OBV_VERITY ((*vbstring5
)[0] == 'S');
446 (*vbstring5
)[0] = 'W';
447 OBV_VERITY ((*vbstring5
)[0] == 'W' && (svar
.in())[0] == 'S');
448 vbstring5
->_remove_ref ();
451 vbstring2
->_remove_ref ();
456 int test_boxed_string_invocations (Test
* test_object
)
466 //============================================================
467 // Test method invocation with boxed value
468 //============================================================
471 VBstring(CORBA::string_dup ("string1")),
474 VBstring(CORBA::string_dup ("string2")),
477 OBV_VERITY (ACE_OS::strcmp(p1
->_value (), "string1") == 0);
478 OBV_VERITY (ACE_OS::strcmp(p2
->_value (), "string2") == 0);
480 VBstring_var result
= test_object
->string_op1(p1
, p2
, p3
);
482 OBV_VERITY (ACE_OS::strcmp(p2
->_value (), "2string") == 0);
483 OBV_VERITY (ACE_OS::strcmp(p3
->_value (), "2string") == 0);
484 OBV_VERITY (ACE_OS::strcmp(result
->_value (), "1string") == 0);
486 //============================================================
487 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
488 //============================================================
490 p2
->_value(CORBA::string_dup ("second string2"));
492 CORBA::String_var sresult
=
493 test_object
->string_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
496 OBV_VERITY (ACE_OS::strcmp(p2
->_value (), "2second string") == 0);
497 OBV_VERITY (ACE_OS::strcmp(p3
->_value (), "2second string") == 0);
498 OBV_VERITY (ACE_OS::strcmp(sresult
.in (), "1string") == 0);
500 catch (const CORBA::Exception
& ex
)
502 ex
._tao_print_exception ("test_boxed_string_invocations");
507 ACE_DEBUG ((LM_DEBUG
,
508 "(%P|%t) test_boxed_string_invocations: "
509 "caught a C++ exception\n"));
512 if (p1
) p1
->_remove_ref ();
513 if (p2
) p2
->_remove_ref ();
514 if (p3
) p3
->_remove_ref ();
520 // Test boxed sequence types.
522 int test_boxed_sequence ()
527 VBseqlong
*vbseqlong1
= 0;
528 ACE_NEW_RETURN (vbseqlong1
,
533 ACE_NEW_RETURN (temp
,
537 VBseqlong_var
vbseqlong2 (temp
);
538 OBV_VERITY (vbseqlong1
->length() == 0);
539 OBV_VERITY (vbseqlong2
->length() == 0);
540 CORBA::Long
*longarray
= 0;
541 ACE_NEW_RETURN (longarray
,
549 TDseqlong
*temp2
= 0;
550 ACE_NEW_RETURN (temp2
,
551 TDseqlong(10, 3, longarray
, 1),
553 TDseqlong_var
seqlong1 (temp2
);
554 OBV_VERITY (seqlong1
[0] == 101 && seqlong1
[2] == 303);
556 VBseqlong
*vbseqlong3
= 0;
557 ACE_NEW_RETURN (vbseqlong3
,
558 VBseqlong(seqlong1
.in()),
561 // Test sequence ctor.
562 VBseqlong
*vbseqlong4
= 0;
563 ACE_NEW_RETURN (vbseqlong4
,
564 VBseqlong(10, 3, longarray
, 0),
567 // Test assignment and subscript operators
568 vbseqlong2
= vbseqlong3
;
569 OBV_VERITY (vbseqlong2
->length() == 3);
570 VBseqlong
&vbseqlong5
= *vbseqlong2
.inout();
571 OBV_VERITY (vbseqlong5
[2] == 303);
573 OBV_VERITY (vbseqlong5
[2] == 444);
574 OBV_VERITY (seqlong1
[0] == 101 && seqlong1
[2] == 303);
575 OBV_VERITY ((*vbseqlong4
)[0] == 101 && (*vbseqlong4
)[2] == 303);
577 OBV_VERITY ((*vbseqlong4
)[0] == 111);
578 OBV_VERITY (vbseqlong4
->maximum() == 10);
579 *vbseqlong4
= vbseqlong1
->_value();
580 OBV_VERITY (vbseqlong4
->length() == 0);
583 VBseqlong
*vbseqlong6
= VBseqlong::_downcast( vbseqlong4
->_copy_value());
587 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Failure at line %l\n"));
591 OBV_VERITY (vbseqlong6
->length() == 0);
592 vbseqlong6
->_remove_ref ();
596 vbseqlong1
->_remove_ref ();
597 vbseqlong4
->_remove_ref ();
599 catch (const ::CORBA::Exception
&ex
)
601 ex
._tao_print_exception ("test_boxed_sequence");
606 ACE_ERROR ((LM_ERROR
, "test_boxed_sequence : unexpected exception caught\n"));
612 int test_boxed_sequence_invocations (Test
* test_object
)
621 //============================================================
622 // Test method invocation with boxed value
623 //============================================================
643 OBV_VERITY ((*p1
)[0] == 10);
644 OBV_VERITY ((*p1
)[1] == 9);
645 OBV_VERITY ((*p1
)[2] == 8);
646 OBV_VERITY ((*p1
)[3] == 7);
648 VBseqlong_var result
= test_object
->seq_op1(p1
, p2
, p3
);
650 OBV_VERITY ((*p2
)[0] == 100*3);
651 OBV_VERITY ((*p2
)[1] == 99*3);
652 OBV_VERITY ((*p2
)[2] == 98*3);
653 OBV_VERITY ((*p3
)[0] == 100*5);
654 OBV_VERITY ((*p3
)[1] == 99*5);
655 OBV_VERITY ((*p3
)[2] == 98*5);
656 OBV_VERITY ((*result
.in ())[0] == 10);
657 OBV_VERITY ((*result
.in ())[1] == 9);
658 OBV_VERITY ((*result
.in ())[2] == 8);
659 OBV_VERITY ((*result
.in ())[3] == 7);
661 //============================================================
662 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
663 //============================================================
665 test_object
->seq_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
668 OBV_VERITY ((*p2
)[0] == 100*3*3);
669 OBV_VERITY ((*p2
)[1] == 99*3*3);
670 OBV_VERITY ((*p2
)[2] == 98*3*3);
671 OBV_VERITY ((*p3
)[0] == (*p1
)[0]*5);
672 OBV_VERITY ((*p3
)[1] == (*p1
)[1]*5);
673 OBV_VERITY ((*p3
)[2] == (*p1
)[2]*5);
674 OBV_VERITY ((*p3
)[3] == (*p1
)[3]*5);
676 catch (const CORBA::Exception
& ex
)
678 ex
._tao_print_exception ("test_boxed_sequence_invocations");
683 ACE_DEBUG ((LM_DEBUG
,
684 "(%P|%t) test_boxed_sequence_invocations: "
685 "caught a C++ exception\n"));
689 if (p1
) p1
->_remove_ref ();
690 if (p2
) p2
->_remove_ref ();
691 if (p3
) p3
->_remove_ref ();
698 // Test a boxed struct type. This is not templated since the struct
699 // members are accessed by name, so this is specific to a certain IDL.
701 int test_boxed_struct ()
705 Fixed_Struct1
*fixed_struct_a
= 0;
706 ACE_NEW_RETURN (fixed_struct_a
,
709 fixed_struct_a
->l
= 3233;
710 fixed_struct_a
->abstruct
.s1
= 73;
711 fixed_struct_a
->abstruct
.s2
= 37;
713 // Test the VBfixed_struct1 constructor
714 VBfixed_struct1
*valuebox1
= 0;
715 ACE_NEW_RETURN (valuebox1
,
716 VBfixed_struct1 (*fixed_struct_a
),
719 // Test boxed copy ctor.
720 VBfixed_struct1
* valuebox2_ptr
= 0;
721 ACE_NEW_RETURN (valuebox2_ptr
,
722 VBfixed_struct1 (*valuebox1
),
724 VBfixed_struct1_var valuebox2
= valuebox2_ptr
;
726 OBV_VERITY (valuebox1
->l () == valuebox2
->l ());
727 OBV_VERITY ((valuebox1
->abstruct ()).s1
== (valuebox2
->abstruct ()).s1
);
728 OBV_VERITY ((valuebox1
->abstruct ()).s2
== (valuebox2
->abstruct ()).s2
);
732 OBV_VERITY (valuebox1
->l () != valuebox2
->l ());
734 // Change some more, to test other types.
735 (valuebox2
->abstruct ()).s1
= 667;
736 OBV_VERITY ((valuebox1
->abstruct ()).s1
!= (valuebox2
->abstruct ()).s1
);
737 (valuebox2
->abstruct ()).s2
= 1667;
738 OBV_VERITY ((valuebox1
->abstruct ()).s2
!= (valuebox2
->abstruct ()).s2
);
740 Fixed_Struct1
*fixed_struct_b
= 0;
741 ACE_NEW_RETURN (fixed_struct_b
,
744 fixed_struct_b
->l
= 7372;
745 fixed_struct_b
->abstruct
.s1
= 11;
746 fixed_struct_b
->abstruct
.s2
= 51;
748 // Make another VBfixed_struct1
749 VBfixed_struct1
*valuebox3
= 0;
750 ACE_NEW_RETURN (valuebox3
,
754 // Test assignment operator
755 *valuebox3
= *fixed_struct_b
;
757 OBV_VERITY (valuebox3
->l () == fixed_struct_b
->l
);
758 OBV_VERITY ((valuebox3
->abstruct ()).s1
== fixed_struct_b
->abstruct
.s1
);
759 OBV_VERITY ((valuebox3
->abstruct ()).s2
== fixed_struct_b
->abstruct
.s2
);
761 // Test _value modifier method
762 valuebox2
->_value (*fixed_struct_b
);
763 OBV_VERITY (valuebox2
->l () == fixed_struct_b
->l
);
764 OBV_VERITY ((valuebox2
->abstruct ()).s1
== fixed_struct_b
->abstruct
.s1
);
765 OBV_VERITY ((valuebox2
->abstruct ()).s2
== fixed_struct_b
->abstruct
.s2
);
767 // Test _copy_value and _downcast
768 VBfixed_struct1_var valuebox4
=
769 VBfixed_struct1::_downcast (valuebox3
->_copy_value ());
770 if (valuebox4
.in () == 0)
773 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Failure at line %l\n"));
777 OBV_VERITY (valuebox4
->l () == fixed_struct_b
->l
);
778 OBV_VERITY ((valuebox4
->abstruct ()).s1
== fixed_struct_b
->abstruct
.s1
);
779 OBV_VERITY ((valuebox4
->abstruct ()).s2
== fixed_struct_b
->abstruct
.s2
);
783 // valuebox1 and valuebox3 must be explicitly removed.
784 CORBA::remove_ref (valuebox1
);
785 CORBA::remove_ref (valuebox3
);
788 // as well as the structs we new'ed.
789 delete fixed_struct_a
;
790 delete fixed_struct_b
;
793 // Other types are _var so their dtors will clean up remaining
800 int test_boxed_struct_invocations (Test
* test_object
)
806 //============================================================
808 // Test method invocation with boxed value
809 //============================================================
812 fs1
.abstruct
.s1
= 117;
813 fs1
.abstruct
.s2
= 21;
815 VBfixed_struct1
*p1
= 0;
817 VBfixed_struct1(fs1
),
822 fs2
.abstruct
.s1
= 171;
823 fs2
.abstruct
.s2
= 12;
825 VBfixed_struct1
*p2
= 0;
827 VBfixed_struct1(fs2
),
832 OBV_VERITY (p1
->l() == 29);
833 OBV_VERITY ((p1
->abstruct()).s1
== 117);
834 OBV_VERITY ((p1
->abstruct()).s2
== 21);
836 VBfixed_struct1_var result
= test_object
->struct_op1(p1
, p2
, p3
);
838 OBV_VERITY (p2
->l() == 92*3);
839 OBV_VERITY ((p2
->abstruct()).s1
== 171*3);
840 OBV_VERITY ((p2
->abstruct()).s2
== 12*3);
842 OBV_VERITY (p3
->l() == 92*5);
843 OBV_VERITY ((p3
->abstruct()).s1
== 171*5);
844 OBV_VERITY ((p3
->abstruct()).s2
== 12*5);
846 OBV_VERITY (result
->l() == fs1
.l
);
847 OBV_VERITY ((result
->abstruct()).s1
== fs1
.abstruct
.s1
);
848 OBV_VERITY ((result
->abstruct()).s2
== fs1
.abstruct
.s2
);
850 //============================================================
852 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
853 //============================================================
855 test_object
->struct_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
858 OBV_VERITY (p2
->l() == 92*3*3);
859 OBV_VERITY ((p2
->abstruct()).s1
== 171*3*3);
860 OBV_VERITY ((p2
->abstruct()).s2
== 12*3*3);
862 OBV_VERITY (p3
->l() == fs1
.l
);
863 OBV_VERITY ((p3
->abstruct()).s1
== fs1
.abstruct
.s1
);
864 OBV_VERITY ((p3
->abstruct()).s2
== fs1
.abstruct
.s2
);
872 //============================================================
874 // Test method invocation with boxed value
875 //============================================================
877 Variable_Struct1 vs1
;
879 vs1
.str
= CORBA::string_dup ("variable1");
881 VBvariable_struct1
*p4
= 0;
883 VBvariable_struct1 (vs1
),
886 Variable_Struct1 vs2
;
888 vs2
.str
= "variable2";
890 VBvariable_struct1
*p5
= 0;
892 VBvariable_struct1 (vs2
),
895 VBvariable_struct1
*p6
;
898 OBV_VERITY (p4
->l() == 29);
899 OBV_VERITY (ACE_OS::strcmp(p4
->str(), "variable1") == 0);
901 VBvariable_struct1_var result2
= test_object
->struct_op3(p4
, p5
, p6
);
903 OBV_VERITY (p5
->l() == vs2
.l
*3);
904 OBV_VERITY (ACE_OS::strcmp(p5
->str(), "2variable") == 0);
906 OBV_VERITY (p6
->l() == vs2
.l
*3);
907 OBV_VERITY (ACE_OS::strcmp(p6
->str(), "2variable") == 0);
909 OBV_VERITY (result2
->l() == vs1
.l
);
910 OBV_VERITY (ACE_OS::strcmp(result2
->str(), vs1
.str
) == 0);
913 //============================================================
915 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
916 //============================================================
918 test_object
->struct_op4(p4
->_boxed_in(), p5
->_boxed_inout(),
921 OBV_VERITY (p5
->l() == vs2
.l
*3*3);
922 OBV_VERITY (ACE_OS::strcmp(p5
->str(), "e2variabl") == 0);
924 OBV_VERITY (p6
->l() == vs1
.l
);
925 OBV_VERITY (ACE_OS::strcmp(p6
->str(), vs1
.str
) == 0);
932 catch (const CORBA::Exception
& ex
)
934 ex
._tao_print_exception ("test_boxed_struct_invocations");
939 ACE_DEBUG ((LM_DEBUG
,
940 "(%P|%t) test_boxed_struct_invocations: "
941 "caught a C++ exception\n"));
949 // Test boxed array types.
951 int test_boxed_array()
960 VBlongarray
*valuebox1
= 0;
961 ACE_NEW_RETURN (valuebox1
,
964 VBlongarray
*valuebox2
= 0;
965 ACE_NEW_RETURN (valuebox2
,
968 VBlongarray
*valuebox3
= 0;
969 ACE_NEW_RETURN (valuebox3
,
970 VBlongarray(*valuebox2
),
973 OBV_VERITY ((*valuebox2
)[0] == 101
974 && valuebox2
->_value()[1] == 202
975 && valuebox2
->_value()[2] == 303);
977 OBV_VERITY ((*valuebox3
)[0] == 101
978 && (*valuebox3
)[1] == 202
979 && (*valuebox3
)[2] == 303);
981 (*valuebox3
)[0] = 111;
982 valuebox3
->_value()[1] = 222;
984 OBV_VERITY ((*valuebox2
)[0] == 101
985 && (*valuebox2
)[1] == 202
986 && (*valuebox2
)[2] == 303);
988 OBV_VERITY ((*valuebox3
)[0] == 111
989 && (*valuebox3
)[1] == 222
990 && (*valuebox3
)[2] == 303);
994 OBV_VERITY ((*valuebox1
)[0] == 101
995 && valuebox1
->_value()[1] == 202
996 && valuebox1
->_value()[2] == 303);
998 valuebox2
->_value(la
);
1000 OBV_VERITY ((*valuebox2
)[0] == 101
1001 && valuebox2
->_value()[1] == 202
1002 && valuebox2
->_value()[2] == 303);
1004 LongArray_var
lv_la(LongArray_dup(la
));
1005 *valuebox2
= lv_la
.in();
1007 *valuebox2
= valuebox3
->_value();
1008 valuebox3
->_value()[1] = 777;
1009 OBV_VERITY ((*valuebox2
)[0] == 111
1010 && valuebox2
->_value()[1] == 222
1011 && valuebox2
->_value()[2] == 303);
1014 valuebox1
->_remove_ref ();
1015 valuebox2
->_remove_ref ();
1016 valuebox3
->_remove_ref ();
1022 int test_boxed_array_invocations (Test
* test_object
)
1028 //============================================================
1030 // Test method invocation with boxed value
1031 //============================================================
1038 VBlongarray
*p1
= 0;
1048 VBlongarray
*p2
= 0;
1053 OBV_VERITY ((*p1
)[0] == 101
1055 && (*p1
)[2] == 303);
1059 VBlongarray_var result
= test_object
->array_op1 (p1
, p2
, p3
);
1061 OBV_VERITY ((*p2
)[0] == (3101*3)
1062 && (*p2
)[1] == (3202*3)
1063 && (*p3
)[2] == (3303*3));
1065 OBV_VERITY ((*p3
)[0] == (3101*3)
1066 && (*p3
)[1] == (3202*3)
1067 && (*p3
)[2] == (3303*3));
1069 OBV_VERITY ((*result
.in ())[0] == 101
1070 && (*result
.in ())[1] == 202
1071 && (*result
.in ())[2] == 303);
1073 //============================================================
1075 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
1076 //============================================================
1078 // Exclude the following test for now until issues with _boxed_out()
1079 // for arrays are resolved.
1081 test_object
->array_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
1084 OBV_VERITY ((*p2
)[0] == (3101*3*3)
1085 && (*p2
)[1] == (3202*3*3)
1086 && (*p2
)[2] == (3303*3*3));
1088 OBV_VERITY ((*p3
)[0] == (*p1
)[0]
1089 && (*p3
)[1] == (*p1
)[1]
1090 && (*p3
)[2] == (*p1
)[2]);
1097 //============================================================
1099 // Test method invocation with boxed value
1100 //============================================================
1103 sa
[0] = CORBA::string_dup ("in string1");
1104 sa
[1] = CORBA::string_dup ("in string2");
1106 VBstringarray
*p4
= 0;
1112 sa2
[0] = CORBA::string_dup ("inout string1");
1113 sa2
[1] = CORBA::string_dup ("inout string2");
1115 VBstringarray
*p5
= 0;
1117 VBstringarray (sa2
),
1120 OBV_VERITY (ACE_OS::strcmp((*p4
)[0], sa
[0]) == 0);
1121 OBV_VERITY (ACE_OS::strcmp((*p4
)[1], sa
[1]) == 0);
1125 VBstringarray_var result2
= test_object
->array_op3 (p4
, p5
, p6
);
1127 OBV_VERITY (ACE_OS::strcmp((*p5
)[0], "1inout string") == 0);
1128 OBV_VERITY (ACE_OS::strcmp((*p5
)[1], "2inout string") == 0);
1129 OBV_VERITY (ACE_OS::strcmp((*p6
)[0], "1inout string") == 0);
1130 OBV_VERITY (ACE_OS::strcmp((*p6
)[1], "2inout string") == 0);
1131 OBV_VERITY (ACE_OS::strcmp((*result2
.in ())[0], sa
[0]) == 0);
1132 OBV_VERITY (ACE_OS::strcmp((*result2
.in ())[1], sa
[1]) == 0);
1134 //============================================================
1136 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
1137 //============================================================
1139 // Disable the following for now. Need to troubleshoot it.
1141 // Following gets compilation error on parameter 3
1142 // test_object->array_op4(p4->_boxed_in(), p5->_boxed_inout(),
1143 // p6->_boxed_out());
1145 // Trying the following variation to troubleshoot. No compilation error
1146 // but p6 is unchanged after return from method.
1147 StringArray sa_experimental
;
1148 StringArray_slice
*slice
= p6
->_boxed_out();
1149 StringArray_out
an_out (slice
);
1151 test_object
->array_op4(p4
->_boxed_in(), p5
->_boxed_inout(),
1154 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) after array_op4\n"));
1155 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) p5[0]=%s\n", (const char *)((*p5
)[0])));
1156 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) p5[1]=%s\n", (const char *)((*p5
)[1])));
1157 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) p6[0]=%s\n", (const char *)((*p6
)[0])));
1158 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) p6[1]=%s\n", (const char *)((*p6
)[1])));
1159 OBV_VERITY (ACE_OS::strcmp((*p5
)[0], "g1inout strin") == 0);
1160 OBV_VERITY (ACE_OS::strcmp((*p5
)[1], "g2inout strin") == 0);
1161 OBV_VERITY (ACE_OS::strcmp((*p6
)[0], sa
[0]) == 0);
1162 OBV_VERITY (ACE_OS::strcmp((*p6
)[1], sa
[1]) == 0);
1169 catch (const CORBA::Exception
& ex
)
1171 ex
._tao_print_exception ("test_boxed_array_invocations");
1176 ACE_DEBUG ((LM_DEBUG
,
1177 "(%P|%t) test_boxed_array_invocations: "
1178 "caught a C++ exception\n"));
1187 // Test a boxed union type.
1189 int test_boxed_union()
1193 VBfixed_union1
*ptemp
;
1194 ACE_NEW_RETURN (ptemp
,
1197 VBfixed_union1_var
valuebox1(ptemp
);
1200 Fixed_Union1
*ptemp2
;
1201 ACE_NEW_RETURN (ptemp2
,
1204 Fixed_Union1_var
fixed_union1(ptemp2
);
1206 // Test modifiers, accessors, discriminant access
1208 OBV_VERITY (valuebox1
->m1 () == 37);
1209 OBV_VERITY (valuebox1
->_d () == 1 || valuebox1
->_d () == 2);
1211 // Explicitly set discriminant, make sure thats the only thing
1214 OBV_VERITY (valuebox1
->_d () == 2);
1215 OBV_VERITY (valuebox1
->m1 () == 37);
1217 OBV_VERITY (valuebox1
->_d () == 1);
1218 OBV_VERITY (valuebox1
->m1 () == 37);
1220 // Use _value() to access
1221 valuebox1
->_value ()._d (2);
1222 OBV_VERITY (valuebox1
->_d () == 2);
1224 // Use _value as modifier.
1225 valuebox1
->_value (fixed_union1
.in());
1226 OBV_VERITY (valuebox1
->_d () != 1 && valuebox1
->_d () != 2);
1229 VBfixed_union1
* valuebox2_ptr
= 0;
1230 ACE_NEW_RETURN (valuebox2_ptr
,
1233 VBfixed_union1_var
valuebox2 (valuebox2_ptr
);
1235 OBV_VERITY (valuebox2
->_d () == 2);
1238 VBfixed_union1
* valuebox3_ptr
= 0;
1239 ACE_NEW_RETURN (valuebox3_ptr
,
1240 VBfixed_union1 (*valuebox2
.in ()),
1242 VBfixed_union1_var
valuebox3 (valuebox3_ptr
);
1243 OBV_VERITY (valuebox3
->_d () == 2);
1244 OBV_VERITY (valuebox3
->m2 () == 333);
1246 // Test assignment op
1247 valuebox3
->m2 (456);
1248 *valuebox3
.in () = valuebox2
->_value ();
1249 OBV_VERITY (valuebox3
->_d () == 2);
1250 OBV_VERITY (valuebox3
->m2 () == 333);
1252 // Test constructor taking union argument
1253 fixed_union1
->m2 (137);
1254 VBfixed_union1
*valuebox4_ptr
= 0;
1255 ACE_NEW_RETURN (valuebox4_ptr
,
1256 VBfixed_union1 (fixed_union1
.in ()),
1258 VBfixed_union1_var
valuebox4 (valuebox4_ptr
);
1259 OBV_VERITY (valuebox4
->m2 () == 137);
1260 OBV_VERITY (valuebox4
->_d () == 1 || valuebox4
->_d () == 2);
1267 int test_boxed_union_invocations (Test
* test_object
)
1273 //============================================================
1275 // Test method invocation with boxed value
1276 //============================================================
1278 Fixed_Union1
*ptemp
= 0;
1279 ACE_NEW_RETURN (ptemp
,
1282 Fixed_Union1_var
fixed_union1(ptemp
);
1284 fixed_union1
->m1 (321);
1285 VBfixed_union1
*p1
= 0;
1287 VBfixed_union1 (fixed_union1
.in ()),
1290 Fixed_Union1
*ptemp2
= 0;
1291 ACE_NEW_RETURN (ptemp2
,
1294 Fixed_Union1_var
fixed_union2(ptemp2
);
1295 fixed_union2
->m2 (789);
1296 VBfixed_union1
*p2
= 0;
1298 VBfixed_union1 (fixed_union2
.in ()),
1301 OBV_VERITY (p1
->_d () == 1);
1302 OBV_VERITY (p1
->m1 () == 321);
1303 OBV_VERITY (p2
->_d () == 2);
1304 OBV_VERITY (p2
->m2 () == 789);
1306 VBfixed_union1
* p3
;
1308 VBfixed_union1_var result
= test_object
->union_op1 (p1
, p2
, p3
);
1310 OBV_VERITY (p2
->_d () == 2);
1311 OBV_VERITY (p2
->m2 () == 789*3);
1312 OBV_VERITY (p3
->_d () == 1);
1313 OBV_VERITY (p3
->m1 () == 321*3);
1314 OBV_VERITY (result
->_d () == 1);
1315 OBV_VERITY (result
->m1 () == 321*3);
1318 //============================================================
1320 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
1321 //============================================================
1323 test_object
->union_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
1326 OBV_VERITY (p2
->_d () == 2);
1327 OBV_VERITY (p2
->m2 () == 789*3*3);
1329 OBV_VERITY (p3
->_d () == 1);
1330 OBV_VERITY (p3
->m1 () == 321);
1336 //============================================================
1338 // Test method invocation with boxed value
1339 //============================================================
1341 Variable_Union1_var variable_union1
;
1342 ACE_NEW_RETURN (variable_union1
,
1345 variable_union1
->m1 (321);
1346 // TODO : resource leak
1347 VBvariable_union1
*p4
= 0;
1349 VBvariable_union1 (variable_union1
.in ()),
1352 Variable_Union1_var variable_union2
;
1353 ACE_NEW_RETURN (variable_union2
,
1356 variable_union2
->m2 (CORBA::string_dup ("abracadabra"));
1357 VBvariable_union1
*p5
= 0;
1359 VBvariable_union1 (variable_union2
.in ()),
1362 OBV_VERITY (p4
->_d () == 1);
1363 OBV_VERITY (p4
->m1 () == 321);
1364 OBV_VERITY (p5
->_d () == 2);
1365 OBV_VERITY (ACE_OS::strcmp(p5
->m2 (), "abracadabra") == 0);
1367 VBvariable_union1
* p6
;
1369 VBvariable_union1_var result2
= test_object
->union_op3 (p4
, p5
, p6
);
1371 OBV_VERITY (p5
->_d () == 2);
1372 OBV_VERITY (ACE_OS::strcmp(p5
->m2 (), "aabracadabr") == 0);
1373 OBV_VERITY (p6
->_d () == 1);
1374 OBV_VERITY (p6
->m1 () == 321);
1375 OBV_VERITY (result2
->_d () == 1);
1376 OBV_VERITY (result2
->m1 () == 321);
1378 //============================================================
1380 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
1381 //============================================================
1385 test_object
->union_op4(p4
->_boxed_in(), p5
->_boxed_inout(),
1388 OBV_VERITY (p5
->_d () == 2);
1389 OBV_VERITY (ACE_OS::strcmp(p5
->m2 (), "raabracadab") == 0);
1391 OBV_VERITY (p6
->_d () == 1);
1392 OBV_VERITY (p6
->m1 () == 1722);
1398 catch (const CORBA::Exception
& ex
)
1400 ex
._tao_print_exception ("test_boxed_union_invocations");
1405 ACE_DEBUG ((LM_DEBUG
,
1406 "(%P|%t) test_boxed_union_invocations: "
1407 "caught a C++ exception\n"));
1415 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
1417 Test_var test_object
;
1423 orb
= CORBA::ORB_init (argc
, argv
);
1425 if (parse_args (argc
, argv
) != 0)
1428 // Obtain reference to the object.
1429 CORBA::Object_var tmp
=
1430 orb
->string_to_object(ior
);
1432 test_object
= Test::_narrow(tmp
.in ());
1434 if (CORBA::is_nil (test_object
.in ()))
1436 ACE_ERROR_RETURN ((LM_DEBUG
,
1437 "Nil Test reference <%s>\n",
1442 catch (const CORBA::Exception
& ex
)
1444 ex
._tao_print_exception ("Initialization failure");
1449 ACE_DEBUG ((LM_DEBUG
,
1450 "(%P|%t) Initialization failure: caught a C++ exception\n"));
1456 fail
= test_basic ();
1458 fail
+= test_basic_invocations (test_object
.in ());
1460 fail
+= test_boxed_string ();
1462 fail
+= test_boxed_string_invocations (test_object
.in ());
1464 fail
+= test_boxed_sequence ();
1466 fail
+= test_boxed_sequence_invocations (test_object
.in ());
1468 fail
+= test_boxed_struct ();
1470 fail
+= test_boxed_struct_invocations (test_object
.in ());
1472 fail
+= test_boxed_array ();
1474 fail
+= test_boxed_array_invocations (test_object
.in ());
1476 fail
+= test_boxed_union();
1478 fail
+= test_boxed_union_invocations (test_object
.in ());
1483 test_object
->shutdown ();
1485 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - test finished\n"));
1489 catch (const CORBA::Exception
& ex
)
1491 ex
._tao_print_exception ("Exception caught:");
1495 return (fail
) ? 1 : 0;