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
));
102 down
->_value ( val2
);
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
);
132 // Test boxed values that use an underlying UT&
134 template <class BoxT
, class UT
>
135 int box_test_ref (BoxT
*valuebox
, UT
&val1
, UT
&val2
)
143 // should be a deep copy of val1...
144 OBV_VERITY ( &p
->_boxed_inout () != &valuebox
->_boxed_inout () );
146 p
->_value ( val2
); // deep copy
147 OBV_VERITY ( &p
->_boxed_inout () != &valuebox
->_boxed_inout () );
149 *valuebox
= val2
; // deep copy, too.
150 OBV_VERITY ( &p
->_boxed_inout () != &valuebox
->_boxed_inout () );
152 CORBA::remove_ref (p
);
157 int test_basic (void)
162 fail
+= simple_box_test
<VBshort
, CORBA::Short
> ();
163 fail
+= simple_box_test
<VBlong
, CORBA::Long
> ();
164 fail
+= simple_box_test
<VBlonglong
, CORBA::LongLong
> ();
165 fail
+= simple_box_test
<VBushort
, CORBA::UShort
> ();
166 fail
+= simple_box_test
<VBulong
, CORBA::ULong
> ();
167 fail
+= simple_box_test
<VBulonglong
, CORBA::ULongLong
> ();
168 fail
+= simple_box_test
<VBwchar
, CORBA::WChar
> ();
169 fail
+= simple_box_test
<VBoctet
, CORBA::Octet
> ();
170 fail
+= simple_box_test
<VBfloat
, CORBA::Float
> ();
171 fail
+= simple_box_test
<VBdouble
, CORBA::Double
> ();
174 ACE_NEW_RETURN (pchar
,
177 fail
+= box_test1
<VBchar
, CORBA::Char
> (pchar
, 'A', 'Z');
178 CORBA::remove_ref (pchar
);
180 VBboolean
*pbool
= 0;
181 ACE_NEW_RETURN (pbool
,
184 fail
+= box_test1
<VBboolean
, CORBA::Boolean
> (pbool
, true, false);
185 CORBA::remove_ref (pbool
);
187 // Typedef of basic types
188 fail
+= simple_box_test
<VBTDshort
, CORBA::Short
> ();
189 fail
+= simple_box_test
<VBTDlong
, CORBA::Long
> ();
190 fail
+= simple_box_test
<VBTDlonglong
, CORBA::LongLong
> ();
191 fail
+= simple_box_test
<VBTDushort
, CORBA::UShort
> ();
192 fail
+= simple_box_test
<VBTDulong
, CORBA::ULong
> ();
193 fail
+= simple_box_test
<VBTDulonglong
, CORBA::ULongLong
> ();
194 fail
+= simple_box_test
<VBTDwchar
, CORBA::WChar
> ();
195 fail
+= simple_box_test
<VBTDoctet
, CORBA::Octet
> ();
196 fail
+= simple_box_test
<VBTDfloat
, CORBA::Float
> ();
197 fail
+= simple_box_test
<VBTDdouble
, CORBA::Double
> ();
199 VBTDchar
*pchar2
= 0;
200 ACE_NEW_RETURN (pchar2
,
203 fail
+= box_test1
<VBTDchar
, CORBA::Char
> (pchar2
, 'A', 'Z');
204 CORBA::remove_ref (pchar2
);
206 VBTDboolean
*pbool2
= 0;
207 ACE_NEW_RETURN (pbool2
,
210 fail
+= box_test1
<VBTDboolean
, CORBA::Boolean
> (pbool2
, true, false);
211 CORBA::remove_ref (pbool2
);
215 ACE_NEW_RETURN (penum
,
218 fail
+= box_test1
<VBenum
, Color
> (penum
, yellow
, red
);
219 CORBA::remove_ref (penum
);
221 // Typedef of enumerated type
222 VBTDenum
*penum2
= 0;
223 ACE_NEW_RETURN (penum2
,
226 fail
+= box_test1
<VBTDenum
, Color
> (penum2
, yellow
, red
);
227 CORBA::remove_ref (penum2
);
234 CORBA::Any_var
any1 (a1
);
240 CORBA::Any_var
any2 (a2
);
243 ACE_NEW_RETURN (pany
,
246 fail
+= box_test_ref
<VBany
, CORBA::Any
> (pany
, any1
.inout (),
248 CORBA::remove_ref (pany
);
252 ACE_NEW_RETURN (pany2
,
253 VBTDany (any1
.in ()),
255 fail
+= box_test_ref
<VBTDany
, CORBA::Any
> (pany2
, any1
.inout (),
257 CORBA::remove_ref (pany2
);
262 int test_basic_invocations (Test
* test_object
)
270 vb_basic::M_VBlong
*mp1
= 0;
271 vb_basic::M_VBlong
*mp2
= 0;
272 vb_basic::M_VBlong
*mp3
;
277 //============================================================
278 // Test method invocation with boxed value
279 //============================================================
288 OBV_VERITY (p1
->_value () == 25);
289 OBV_VERITY (p2
->_value () == 53);
292 test_object
->basic_op1(p1
, p2
, p3
);
294 OBV_VERITY (p2
->_value () == (53*3));
295 OBV_VERITY (p3
->_value () == (53*5));
296 OBV_VERITY (result
->_value () == (p1
->_value () *3));
298 //============================================================
299 // Test method invocation with boxed value from nested module
300 //============================================================
303 vb_basic::M_VBlong(25),
307 vb_basic::M_VBlong(53),
310 OBV_VERITY (mp1
->_value () == 25);
311 OBV_VERITY (mp2
->_value () == 53);
313 vb_basic::M_VBlong_var mresult
=
314 test_object
->basic_op2(mp1
, mp2
, mp3
);
316 OBV_VERITY (mp2
->_value () == (53*3));
317 OBV_VERITY (mp3
->_value () == (53*5));
318 OBV_VERITY (mresult
->_value () == (mp1
->_value () *3));
320 //============================================================
321 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
322 //============================================================
328 test_object
->basic_op3(p1
->_boxed_in(), p2
->_boxed_inout(),
331 OBV_VERITY (p2
->_value () == (93*3));
332 OBV_VERITY (p3
->_value () == (93*5));
333 OBV_VERITY (lresult
== (p1
->_value()*3));
335 catch (const CORBA::Exception
& ex
)
337 ex
._tao_print_exception ("test_basic_invocations");
342 ACE_DEBUG ((LM_DEBUG
,
343 "(%P|%t) test_basic_invocations: caught a C++ exception\n"));
346 if (p1
) p1
->_remove_ref ();
347 if (p2
) p2
->_remove_ref ();
348 if (p3
) p3
->_remove_ref ();
350 if (mp1
) mp1
->_remove_ref ();
351 if (mp2
) mp2
->_remove_ref ();
352 if (mp3
) mp3
->_remove_ref ();
358 int test_boxed_string()
361 const char *string1
= "First-string";
362 const char *string2
= "Second-string";
364 // Establish that we have data setup correctly...
365 OBV_VERITY (ACE_OS::strcmp (string1
, string2
) < 0);
366 OBV_VERITY (ACE_OS::strcmp (string2
, string1
) > 0);
367 OBV_VERITY (ACE_OS::strcmp (string1
, string1
) == 0);
369 // Make some objects, using our data
371 ACE_NEW_RETURN (temp
,
374 VBstring_var
vbstring1 (temp
);
376 VBstring
*vbstring2
= 0;
377 ACE_NEW_RETURN (vbstring2
,
378 VBstring(string1
), // tests const char * ctor.
381 OBV_VERITY (ACE_OS::strcmp (vbstring1
->_value(), string1
) == 0);
382 OBV_VERITY (ACE_OS::strcmp (vbstring2
->_value(), string1
) == 0);
384 // Test assignment operators
386 ACE_NEW_RETURN (carray1
,
389 ACE_OS::memcpy(carray1
, string2
, ACE_OS::strlen(string2
));
390 *vbstring2
= carray1
; // char * (adopted by box)
391 OBV_VERITY ((*vbstring2
)[0] == 'S');
392 *vbstring2
= string1
;
393 OBV_VERITY ((*vbstring2
)[0] == 'F');
394 CORBA::String_var
svar(string2
);
396 OBV_VERITY ((*vbstring2
)[0] == 'S');
398 // Test _value modifiers--like assignment drill above.
400 ACE_NEW_RETURN (carray2
,
403 ACE_OS::memcpy(carray2
, string1
, ACE_OS::strlen(string1
));
404 vbstring2
->_value(carray2
); // char * (adopted by box)
405 OBV_VERITY ((*vbstring2
)[0] == 'F');
406 vbstring2
->_value(string2
); // const char *
407 OBV_VERITY ((*vbstring2
)[0] == 'S');
408 (*vbstring2
)[0] = 'Y';
409 OBV_VERITY ((*vbstring2
)[0] != 'S');
410 vbstring2
->_value(svar
);
411 OBV_VERITY ((*vbstring2
)[0] == 'S');
412 // test value accessor
413 OBV_VERITY ( (vbstring2
->_value())[0] == 'S' );
417 // const boxed string
418 VBstring
*vbstring3
= 0;
419 ACE_NEW_RETURN (vbstring3
,
420 VBstring(*vbstring2
),
422 OBV_VERITY ((*vbstring3
)[0] == 'S');
423 (*vbstring3
)[0] = 'W';
424 OBV_VERITY ((*vbstring3
)[0] == 'W' && (*vbstring2
)[0] == 'S');
425 vbstring3
->_remove_ref ();
430 ACE_NEW_RETURN (carray3
,
433 ACE_OS::memcpy(carray3
, string1
, ACE_OS::strlen(string1
));
434 VBstring
*vbstring4
= 0;
435 ACE_NEW_RETURN (vbstring4
,
438 OBV_VERITY ((*vbstring4
)[0] == 'F');
439 vbstring4
->_remove_ref ();
442 // test CORBA::String_var ctor
443 VBstring
*vbstring5
= 0;
444 ACE_NEW_RETURN (vbstring5
,
447 OBV_VERITY ((*vbstring5
)[0] == 'S');
448 (*vbstring5
)[0] = 'W';
449 OBV_VERITY ((*vbstring5
)[0] == 'W' && (svar
.in())[0] == 'S');
450 vbstring5
->_remove_ref ();
453 vbstring2
->_remove_ref ();
458 int test_boxed_string_invocations (Test
* test_object
)
469 //============================================================
470 // Test method invocation with boxed value
471 //============================================================
474 VBstring(CORBA::string_dup ("string1")),
477 VBstring(CORBA::string_dup ("string2")),
480 OBV_VERITY (ACE_OS::strcmp(p1
->_value (), "string1") == 0);
481 OBV_VERITY (ACE_OS::strcmp(p2
->_value (), "string2") == 0);
483 VBstring_var result
= test_object
->string_op1(p1
, p2
, p3
);
485 OBV_VERITY (ACE_OS::strcmp(p2
->_value (), "2string") == 0);
486 OBV_VERITY (ACE_OS::strcmp(p3
->_value (), "2string") == 0);
487 OBV_VERITY (ACE_OS::strcmp(result
->_value (), "1string") == 0);
489 //============================================================
490 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
491 //============================================================
493 p2
->_value(CORBA::string_dup ("second string2"));
495 CORBA::String_var sresult
=
496 test_object
->string_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
499 OBV_VERITY (ACE_OS::strcmp(p2
->_value (), "2second string") == 0);
500 OBV_VERITY (ACE_OS::strcmp(p3
->_value (), "2second string") == 0);
501 OBV_VERITY (ACE_OS::strcmp(sresult
.in (), "1string") == 0);
503 catch (const CORBA::Exception
& ex
)
505 ex
._tao_print_exception ("test_boxed_string_invocations");
510 ACE_DEBUG ((LM_DEBUG
,
511 "(%P|%t) test_boxed_string_invocations: "
512 "caught a C++ exception\n"));
515 if (p1
) p1
->_remove_ref ();
516 if (p2
) p2
->_remove_ref ();
517 if (p3
) p3
->_remove_ref ();
523 // Test boxed sequence types.
525 int test_boxed_sequence (void)
530 VBseqlong
*vbseqlong1
= 0;
531 ACE_NEW_RETURN (vbseqlong1
,
536 ACE_NEW_RETURN (temp
,
540 VBseqlong_var
vbseqlong2 (temp
);
541 OBV_VERITY (vbseqlong1
->length() == 0);
542 OBV_VERITY (vbseqlong2
->length() == 0);
543 CORBA::Long
*longarray
= 0;
544 ACE_NEW_RETURN (longarray
,
552 TDseqlong
*temp2
= 0;
553 ACE_NEW_RETURN (temp2
,
554 TDseqlong(10, 3, longarray
, 1),
556 TDseqlong_var
seqlong1 (temp2
);
557 OBV_VERITY (seqlong1
[0] == 101 && seqlong1
[2] == 303);
559 VBseqlong
*vbseqlong3
= 0;
560 ACE_NEW_RETURN (vbseqlong3
,
561 VBseqlong(seqlong1
.in()),
564 // Test sequence ctor.
565 VBseqlong
*vbseqlong4
= 0;
566 ACE_NEW_RETURN (vbseqlong4
,
567 VBseqlong(10, 3, longarray
, 0),
570 // Test assignment and subscript operators
571 vbseqlong2
= vbseqlong3
;
572 OBV_VERITY (vbseqlong2
->length() == 3);
573 VBseqlong
&vbseqlong5
= *vbseqlong2
.inout();
574 OBV_VERITY (vbseqlong5
[2] == 303);
576 OBV_VERITY (vbseqlong5
[2] == 444);
577 OBV_VERITY (seqlong1
[0] == 101 && seqlong1
[2] == 303);
578 OBV_VERITY ((*vbseqlong4
)[0] == 101 && (*vbseqlong4
)[2] == 303);
580 OBV_VERITY ((*vbseqlong4
)[0] == 111);
581 OBV_VERITY (vbseqlong4
->maximum() == 10);
582 *vbseqlong4
= vbseqlong1
->_value();
583 OBV_VERITY (vbseqlong4
->length() == 0);
586 VBseqlong
*vbseqlong6
= VBseqlong::_downcast( vbseqlong4
->_copy_value() );
590 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Failure at line %l\n"));
594 OBV_VERITY (vbseqlong6
->length() == 0);
595 vbseqlong6
->_remove_ref ();
599 vbseqlong1
->_remove_ref ();
600 vbseqlong4
->_remove_ref ();
602 catch (const ::CORBA::Exception
&ex
)
604 ex
._tao_print_exception ("test_boxed_sequence");
609 ACE_ERROR ((LM_ERROR
, "test_boxed_sequence : unexpected exception caught\n"));
616 int test_boxed_sequence_invocations (Test
* test_object
)
626 //============================================================
627 // Test method invocation with boxed value
628 //============================================================
648 OBV_VERITY ((*p1
)[0] == 10);
649 OBV_VERITY ((*p1
)[1] == 9);
650 OBV_VERITY ((*p1
)[2] == 8);
651 OBV_VERITY ((*p1
)[3] == 7);
653 VBseqlong_var result
= test_object
->seq_op1(p1
, p2
, p3
);
655 OBV_VERITY ((*p2
)[0] == 100*3);
656 OBV_VERITY ((*p2
)[1] == 99*3);
657 OBV_VERITY ((*p2
)[2] == 98*3);
658 OBV_VERITY ((*p3
)[0] == 100*5);
659 OBV_VERITY ((*p3
)[1] == 99*5);
660 OBV_VERITY ((*p3
)[2] == 98*5);
661 OBV_VERITY ((*result
.in ())[0] == 10);
662 OBV_VERITY ((*result
.in ())[1] == 9);
663 OBV_VERITY ((*result
.in ())[2] == 8);
664 OBV_VERITY ((*result
.in ())[3] == 7);
666 //============================================================
667 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
668 //============================================================
670 test_object
->seq_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
673 OBV_VERITY ((*p2
)[0] == 100*3*3);
674 OBV_VERITY ((*p2
)[1] == 99*3*3);
675 OBV_VERITY ((*p2
)[2] == 98*3*3);
676 OBV_VERITY ((*p3
)[0] == (*p1
)[0]*5);
677 OBV_VERITY ((*p3
)[1] == (*p1
)[1]*5);
678 OBV_VERITY ((*p3
)[2] == (*p1
)[2]*5);
679 OBV_VERITY ((*p3
)[3] == (*p1
)[3]*5);
681 catch (const CORBA::Exception
& ex
)
683 ex
._tao_print_exception ("test_boxed_sequence_invocations");
688 ACE_DEBUG ((LM_DEBUG
,
689 "(%P|%t) test_boxed_sequence_invocations: "
690 "caught a C++ exception\n"));
694 if (p1
) p1
->_remove_ref ();
695 if (p2
) p2
->_remove_ref ();
696 if (p3
) p3
->_remove_ref ();
703 // Test a boxed struct type. This is not templated since the struct
704 // members are accessed by name, so this is specific to a certain IDL.
706 int test_boxed_struct (void)
710 Fixed_Struct1
*fixed_struct_a
= 0;
711 ACE_NEW_RETURN (fixed_struct_a
,
714 fixed_struct_a
->l
= 3233;
715 fixed_struct_a
->abstruct
.s1
= 73;
716 fixed_struct_a
->abstruct
.s2
= 37;
718 // Test the VBfixed_struct1 constructor
719 VBfixed_struct1
*valuebox1
= 0;
720 ACE_NEW_RETURN (valuebox1
,
721 VBfixed_struct1 (*fixed_struct_a
),
724 // Test boxed copy ctor.
725 VBfixed_struct1
* valuebox2_ptr
= 0;
726 ACE_NEW_RETURN (valuebox2_ptr
,
727 VBfixed_struct1 (*valuebox1
),
729 VBfixed_struct1_var valuebox2
= valuebox2_ptr
;
731 OBV_VERITY (valuebox1
->l () == valuebox2
->l ());
732 OBV_VERITY ((valuebox1
->abstruct ()).s1
== (valuebox2
->abstruct ()).s1
);
733 OBV_VERITY ((valuebox1
->abstruct ()).s2
== (valuebox2
->abstruct ()).s2
);
737 OBV_VERITY (valuebox1
->l () != valuebox2
->l ());
739 // Change some more, to test other types.
740 (valuebox2
->abstruct ()).s1
= 667;
741 OBV_VERITY ((valuebox1
->abstruct ()).s1
!= (valuebox2
->abstruct ()).s1
);
742 (valuebox2
->abstruct ()).s2
= 1667;
743 OBV_VERITY ((valuebox1
->abstruct ()).s2
!= (valuebox2
->abstruct ()).s2
);
745 Fixed_Struct1
*fixed_struct_b
= 0;
746 ACE_NEW_RETURN (fixed_struct_b
,
749 fixed_struct_b
->l
= 7372;
750 fixed_struct_b
->abstruct
.s1
= 11;
751 fixed_struct_b
->abstruct
.s2
= 51;
753 // Make another VBfixed_struct1
754 VBfixed_struct1
*valuebox3
= 0;
755 ACE_NEW_RETURN (valuebox3
,
759 // Test assignment operator
760 *valuebox3
= *fixed_struct_b
;
762 OBV_VERITY (valuebox3
->l () == fixed_struct_b
->l
);
763 OBV_VERITY ((valuebox3
->abstruct ()).s1
== fixed_struct_b
->abstruct
.s1
);
764 OBV_VERITY ((valuebox3
->abstruct ()).s2
== fixed_struct_b
->abstruct
.s2
);
766 // Test _value modifier method
767 valuebox2
->_value (*fixed_struct_b
);
768 OBV_VERITY (valuebox2
->l () == fixed_struct_b
->l
);
769 OBV_VERITY ((valuebox2
->abstruct ()).s1
== fixed_struct_b
->abstruct
.s1
);
770 OBV_VERITY ((valuebox2
->abstruct ()).s2
== fixed_struct_b
->abstruct
.s2
);
772 // Test _copy_value and _downcast
773 VBfixed_struct1_var valuebox4
=
774 VBfixed_struct1::_downcast (valuebox3
->_copy_value ());
775 if (valuebox4
.in () == 0)
778 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Failure at line %l\n"));
782 OBV_VERITY (valuebox4
->l () == fixed_struct_b
->l
);
783 OBV_VERITY ((valuebox4
->abstruct ()).s1
== fixed_struct_b
->abstruct
.s1
);
784 OBV_VERITY ((valuebox4
->abstruct ()).s2
== fixed_struct_b
->abstruct
.s2
);
788 // valuebox1 and valuebox3 must be explicitly removed.
789 CORBA::remove_ref (valuebox1
);
790 CORBA::remove_ref (valuebox3
);
793 // as well as the structs we new'ed.
794 delete fixed_struct_a
;
795 delete fixed_struct_b
;
798 // Other types are _var so their dtors will clean up remaining
806 int test_boxed_struct_invocations (Test
* test_object
)
813 //============================================================
815 // Test method invocation with boxed value
816 //============================================================
819 fs1
.abstruct
.s1
= 117;
820 fs1
.abstruct
.s2
= 21;
822 VBfixed_struct1
*p1
= 0;
824 VBfixed_struct1(fs1
),
829 fs2
.abstruct
.s1
= 171;
830 fs2
.abstruct
.s2
= 12;
832 VBfixed_struct1
*p2
= 0;
834 VBfixed_struct1(fs2
),
839 OBV_VERITY (p1
->l() == 29);
840 OBV_VERITY ((p1
->abstruct()).s1
== 117);
841 OBV_VERITY ((p1
->abstruct()).s2
== 21);
843 VBfixed_struct1_var result
= test_object
->struct_op1(p1
, p2
, p3
);
845 OBV_VERITY (p2
->l() == 92*3);
846 OBV_VERITY ((p2
->abstruct()).s1
== 171*3);
847 OBV_VERITY ((p2
->abstruct()).s2
== 12*3);
849 OBV_VERITY (p3
->l() == 92*5);
850 OBV_VERITY ((p3
->abstruct()).s1
== 171*5);
851 OBV_VERITY ((p3
->abstruct()).s2
== 12*5);
853 OBV_VERITY (result
->l() == fs1
.l
);
854 OBV_VERITY ((result
->abstruct()).s1
== fs1
.abstruct
.s1
);
855 OBV_VERITY ((result
->abstruct()).s2
== fs1
.abstruct
.s2
);
857 //============================================================
859 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
860 //============================================================
862 test_object
->struct_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
865 OBV_VERITY (p2
->l() == 92*3*3);
866 OBV_VERITY ((p2
->abstruct()).s1
== 171*3*3);
867 OBV_VERITY ((p2
->abstruct()).s2
== 12*3*3);
869 OBV_VERITY (p3
->l() == fs1
.l
);
870 OBV_VERITY ((p3
->abstruct()).s1
== fs1
.abstruct
.s1
);
871 OBV_VERITY ((p3
->abstruct()).s2
== fs1
.abstruct
.s2
);
879 //============================================================
881 // Test method invocation with boxed value
882 //============================================================
884 Variable_Struct1 vs1
;
886 vs1
.str
= CORBA::string_dup ("variable1");
888 VBvariable_struct1
*p4
= 0;
890 VBvariable_struct1 (vs1
),
893 Variable_Struct1 vs2
;
895 vs2
.str
= "variable2";
897 VBvariable_struct1
*p5
= 0;
899 VBvariable_struct1 (vs2
),
902 VBvariable_struct1
*p6
;
905 OBV_VERITY (p4
->l() == 29);
906 OBV_VERITY (ACE_OS::strcmp(p4
->str(), "variable1") == 0);
908 VBvariable_struct1_var result2
= test_object
->struct_op3(p4
, p5
, p6
);
910 OBV_VERITY (p5
->l() == vs2
.l
*3);
911 OBV_VERITY (ACE_OS::strcmp(p5
->str(), "2variable") == 0);
913 OBV_VERITY (p6
->l() == vs2
.l
*3);
914 OBV_VERITY (ACE_OS::strcmp(p6
->str(), "2variable") == 0);
916 OBV_VERITY (result2
->l() == vs1
.l
);
917 OBV_VERITY (ACE_OS::strcmp(result2
->str(), vs1
.str
) == 0);
920 //============================================================
922 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
923 //============================================================
925 test_object
->struct_op4(p4
->_boxed_in(), p5
->_boxed_inout(),
928 OBV_VERITY (p5
->l() == vs2
.l
*3*3);
929 OBV_VERITY (ACE_OS::strcmp(p5
->str(), "e2variabl") == 0);
931 OBV_VERITY (p6
->l() == vs1
.l
);
932 OBV_VERITY (ACE_OS::strcmp(p6
->str(), vs1
.str
) == 0);
939 catch (const CORBA::Exception
& ex
)
941 ex
._tao_print_exception ("test_boxed_struct_invocations");
946 ACE_DEBUG ((LM_DEBUG
,
947 "(%P|%t) test_boxed_struct_invocations: "
948 "caught a C++ exception\n"));
956 // Test boxed array types.
958 int test_boxed_array()
967 VBlongarray
*valuebox1
= 0;
968 ACE_NEW_RETURN (valuebox1
,
971 VBlongarray
*valuebox2
= 0;
972 ACE_NEW_RETURN (valuebox2
,
975 VBlongarray
*valuebox3
= 0;
976 ACE_NEW_RETURN (valuebox3
,
977 VBlongarray(*valuebox2
),
980 OBV_VERITY ((*valuebox2
)[0] == 101
981 && valuebox2
->_value()[1] == 202
982 && valuebox2
->_value()[2] == 303);
984 OBV_VERITY ((*valuebox3
)[0] == 101
985 && (*valuebox3
)[1] == 202
986 && (*valuebox3
)[2] == 303);
988 (*valuebox3
)[0] = 111;
989 valuebox3
->_value()[1] = 222;
991 OBV_VERITY ((*valuebox2
)[0] == 101
992 && (*valuebox2
)[1] == 202
993 && (*valuebox2
)[2] == 303);
995 OBV_VERITY ((*valuebox3
)[0] == 111
996 && (*valuebox3
)[1] == 222
997 && (*valuebox3
)[2] == 303);
1001 OBV_VERITY ((*valuebox1
)[0] == 101
1002 && valuebox1
->_value()[1] == 202
1003 && valuebox1
->_value()[2] == 303);
1005 valuebox2
->_value(la
);
1007 OBV_VERITY ((*valuebox2
)[0] == 101
1008 && valuebox2
->_value()[1] == 202
1009 && valuebox2
->_value()[2] == 303);
1011 LongArray_var
lv_la(LongArray_dup(la
));
1012 *valuebox2
= lv_la
.in();
1014 *valuebox2
= valuebox3
->_value();
1015 valuebox3
->_value()[1] = 777;
1016 OBV_VERITY ((*valuebox2
)[0] == 111
1017 && valuebox2
->_value()[1] == 222
1018 && valuebox2
->_value()[2] == 303);
1021 valuebox1
->_remove_ref ();
1022 valuebox2
->_remove_ref ();
1023 valuebox3
->_remove_ref ();
1030 int test_boxed_array_invocations (Test
* test_object
)
1036 //============================================================
1038 // Test method invocation with boxed value
1039 //============================================================
1046 VBlongarray
*p1
= 0;
1056 VBlongarray
*p2
= 0;
1061 OBV_VERITY ((*p1
)[0] == 101
1063 && (*p1
)[2] == 303);
1067 VBlongarray_var result
= test_object
->array_op1 (p1
, p2
, p3
);
1069 OBV_VERITY ((*p2
)[0] == (3101*3)
1070 && (*p2
)[1] == (3202*3)
1071 && (*p3
)[2] == (3303*3));
1073 OBV_VERITY ((*p3
)[0] == (3101*3)
1074 && (*p3
)[1] == (3202*3)
1075 && (*p3
)[2] == (3303*3));
1077 OBV_VERITY ((*result
.in ())[0] == 101
1078 && (*result
.in ())[1] == 202
1079 && (*result
.in ())[2] == 303);
1081 //============================================================
1083 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
1084 //============================================================
1086 // Exclude the following test for now until issues with _boxed_out()
1087 // for arrays are resolved.
1089 test_object
->array_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
1092 OBV_VERITY ((*p2
)[0] == (3101*3*3)
1093 && (*p2
)[1] == (3202*3*3)
1094 && (*p2
)[2] == (3303*3*3));
1096 OBV_VERITY ((*p3
)[0] == (*p1
)[0]
1097 && (*p3
)[1] == (*p1
)[1]
1098 && (*p3
)[2] == (*p1
)[2]);
1105 //============================================================
1107 // Test method invocation with boxed value
1108 //============================================================
1111 sa
[0] = CORBA::string_dup ("in string1");
1112 sa
[1] = CORBA::string_dup ("in string2");
1114 VBstringarray
*p4
= 0;
1120 sa2
[0] = CORBA::string_dup ("inout string1");
1121 sa2
[1] = CORBA::string_dup ("inout string2");
1123 VBstringarray
*p5
= 0;
1125 VBstringarray (sa2
),
1128 OBV_VERITY (ACE_OS::strcmp((*p4
)[0], sa
[0]) == 0);
1129 OBV_VERITY (ACE_OS::strcmp((*p4
)[1], sa
[1]) == 0);
1133 VBstringarray_var result2
= test_object
->array_op3 (p4
, p5
, p6
);
1135 OBV_VERITY (ACE_OS::strcmp((*p5
)[0], "1inout string") == 0);
1136 OBV_VERITY (ACE_OS::strcmp((*p5
)[1], "2inout string") == 0);
1137 OBV_VERITY (ACE_OS::strcmp((*p6
)[0], "1inout string") == 0);
1138 OBV_VERITY (ACE_OS::strcmp((*p6
)[1], "2inout string") == 0);
1139 OBV_VERITY (ACE_OS::strcmp((*result2
.in ())[0], sa
[0]) == 0);
1140 OBV_VERITY (ACE_OS::strcmp((*result2
.in ())[1], sa
[1]) == 0);
1142 //============================================================
1144 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
1145 //============================================================
1147 // Disable the following for now. Need to troubleshoot it.
1149 // Following gets compilation error on parameter 3
1150 // test_object->array_op4(p4->_boxed_in(), p5->_boxed_inout(),
1151 // p6->_boxed_out());
1153 // Trying the following variation to troubleshoot. No compilation error
1154 // but p6 is unchanged after return from method.
1155 StringArray sa_experimental
;
1156 StringArray_slice
*slice
= p6
->_boxed_out();
1157 StringArray_out
an_out (slice
);
1159 test_object
->array_op4(p4
->_boxed_in(), p5
->_boxed_inout(),
1162 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) after array_op4\n"));
1163 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) p5[0]=%s\n", (const char *)((*p5
)[0])));
1164 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) p5[1]=%s\n", (const char *)((*p5
)[1])));
1165 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) p6[0]=%s\n", (const char *)((*p6
)[0])));
1166 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) p6[1]=%s\n", (const char *)((*p6
)[1])));
1167 OBV_VERITY (ACE_OS::strcmp((*p5
)[0], "g1inout strin") == 0);
1168 OBV_VERITY (ACE_OS::strcmp((*p5
)[1], "g2inout strin") == 0);
1169 OBV_VERITY (ACE_OS::strcmp((*p6
)[0], sa
[0]) == 0);
1170 OBV_VERITY (ACE_OS::strcmp((*p6
)[1], sa
[1]) == 0);
1178 catch (const CORBA::Exception
& ex
)
1180 ex
._tao_print_exception ("test_boxed_array_invocations");
1185 ACE_DEBUG ((LM_DEBUG
,
1186 "(%P|%t) test_boxed_array_invocations: "
1187 "caught a C++ exception\n"));
1196 // Test a boxed union type.
1198 int test_boxed_union()
1202 VBfixed_union1
*ptemp
;
1203 ACE_NEW_RETURN (ptemp
,
1206 VBfixed_union1_var
valuebox1(ptemp
);
1209 Fixed_Union1
*ptemp2
;
1210 ACE_NEW_RETURN (ptemp2
,
1213 Fixed_Union1_var
fixed_union1(ptemp2
);
1215 // Test modifiers, accessors, discriminant access
1217 OBV_VERITY (valuebox1
->m1 () == 37);
1218 OBV_VERITY (valuebox1
->_d () == 1 || valuebox1
->_d () == 2);
1220 // Explicitly set discriminant, make sure thats the only thing
1223 OBV_VERITY (valuebox1
->_d () == 2);
1224 OBV_VERITY (valuebox1
->m1 () == 37);
1226 OBV_VERITY (valuebox1
->_d () == 1);
1227 OBV_VERITY (valuebox1
->m1 () == 37);
1229 // Use _value() to access
1230 valuebox1
->_value ()._d (2);
1231 OBV_VERITY (valuebox1
->_d () == 2);
1233 // Use _value as modifier.
1234 valuebox1
->_value (fixed_union1
.in());
1235 OBV_VERITY (valuebox1
->_d () != 1 && valuebox1
->_d () != 2);
1238 VBfixed_union1
* valuebox2_ptr
= 0;
1239 ACE_NEW_RETURN (valuebox2_ptr
,
1242 VBfixed_union1_var
valuebox2 (valuebox2_ptr
);
1244 OBV_VERITY (valuebox2
->_d () == 2);
1247 VBfixed_union1
* valuebox3_ptr
= 0;
1248 ACE_NEW_RETURN (valuebox3_ptr
,
1249 VBfixed_union1 (*valuebox2
.in ()),
1251 VBfixed_union1_var
valuebox3 (valuebox3_ptr
);
1252 OBV_VERITY (valuebox3
->_d () == 2);
1253 OBV_VERITY (valuebox3
->m2 () == 333);
1255 // Test assignment op
1256 valuebox3
->m2 (456);
1257 *valuebox3
.in () = valuebox2
->_value ();
1258 OBV_VERITY (valuebox3
->_d () == 2);
1259 OBV_VERITY (valuebox3
->m2 () == 333);
1261 // Test constructor taking union argument
1262 fixed_union1
->m2 (137);
1263 VBfixed_union1
*valuebox4_ptr
= 0;
1264 ACE_NEW_RETURN (valuebox4_ptr
,
1265 VBfixed_union1 (fixed_union1
.in ()),
1267 VBfixed_union1_var
valuebox4 (valuebox4_ptr
);
1268 OBV_VERITY (valuebox4
->m2 () == 137);
1269 OBV_VERITY (valuebox4
->_d () == 1 || valuebox4
->_d () == 2);
1277 int test_boxed_union_invocations (Test
* test_object
)
1283 //============================================================
1285 // Test method invocation with boxed value
1286 //============================================================
1288 Fixed_Union1
*ptemp
= 0;
1289 ACE_NEW_RETURN (ptemp
,
1292 Fixed_Union1_var
fixed_union1(ptemp
);
1294 fixed_union1
->m1 (321);
1295 VBfixed_union1
*p1
= 0;
1297 VBfixed_union1 (fixed_union1
.in ()),
1300 Fixed_Union1
*ptemp2
= 0;
1301 ACE_NEW_RETURN (ptemp2
,
1304 Fixed_Union1_var
fixed_union2(ptemp2
);
1305 fixed_union2
->m2 (789);
1306 VBfixed_union1
*p2
= 0;
1308 VBfixed_union1 (fixed_union2
.in ()),
1311 OBV_VERITY (p1
->_d () == 1);
1312 OBV_VERITY (p1
->m1 () == 321);
1313 OBV_VERITY (p2
->_d () == 2);
1314 OBV_VERITY (p2
->m2 () == 789);
1316 VBfixed_union1
* p3
;
1318 VBfixed_union1_var result
= test_object
->union_op1 (p1
, p2
, p3
);
1320 OBV_VERITY (p2
->_d () == 2);
1321 OBV_VERITY (p2
->m2 () == 789*3);
1322 OBV_VERITY (p3
->_d () == 1);
1323 OBV_VERITY (p3
->m1 () == 321*3);
1324 OBV_VERITY (result
->_d () == 1);
1325 OBV_VERITY (result
->m1 () == 321*3);
1328 //============================================================
1330 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
1331 //============================================================
1333 test_object
->union_op2(p1
->_boxed_in(), p2
->_boxed_inout(),
1336 OBV_VERITY (p2
->_d () == 2);
1337 OBV_VERITY (p2
->m2 () == 789*3*3);
1339 OBV_VERITY (p3
->_d () == 1);
1340 OBV_VERITY (p3
->m1 () == 321);
1346 //============================================================
1348 // Test method invocation with boxed value
1349 //============================================================
1351 Variable_Union1_var variable_union1
;
1352 ACE_NEW_RETURN (variable_union1
,
1355 variable_union1
->m1 (321);
1356 // TODO : resource leak
1357 VBvariable_union1
*p4
= 0;
1359 VBvariable_union1 (variable_union1
.in ()),
1362 Variable_Union1_var variable_union2
;
1363 ACE_NEW_RETURN (variable_union2
,
1366 variable_union2
->m2 (CORBA::string_dup ("abracadabra"));
1367 VBvariable_union1
*p5
= 0;
1369 VBvariable_union1 (variable_union2
.in ()),
1372 OBV_VERITY (p4
->_d () == 1);
1373 OBV_VERITY (p4
->m1 () == 321);
1374 OBV_VERITY (p5
->_d () == 2);
1375 OBV_VERITY (ACE_OS::strcmp(p5
->m2 (), "abracadabra") == 0);
1377 VBvariable_union1
* p6
;
1379 VBvariable_union1_var result2
= test_object
->union_op3 (p4
, p5
, p6
);
1381 OBV_VERITY (p5
->_d () == 2);
1382 OBV_VERITY (ACE_OS::strcmp(p5
->m2 (), "aabracadabr") == 0);
1383 OBV_VERITY (p6
->_d () == 1);
1384 OBV_VERITY (p6
->m1 () == 321);
1385 OBV_VERITY (result2
->_d () == 1);
1386 OBV_VERITY (result2
->m1 () == 321);
1388 //============================================================
1390 // Test _boxed_in(), _boxed_inout(), and _boxed_out())
1391 //============================================================
1395 test_object
->union_op4(p4
->_boxed_in(), p5
->_boxed_inout(),
1398 OBV_VERITY (p5
->_d () == 2);
1399 OBV_VERITY (ACE_OS::strcmp(p5
->m2 (), "raabracadab") == 0);
1401 OBV_VERITY (p6
->_d () == 1);
1402 OBV_VERITY (p6
->m1 () == 1722);
1409 catch (const CORBA::Exception
& ex
)
1411 ex
._tao_print_exception ("test_boxed_union_invocations");
1416 ACE_DEBUG ((LM_DEBUG
,
1417 "(%P|%t) test_boxed_union_invocations: "
1418 "caught a C++ exception\n"));
1426 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
1428 Test_var test_object
;
1434 orb
= CORBA::ORB_init (argc
, argv
);
1436 if (parse_args (argc
, argv
) != 0)
1439 // Obtain reference to the object.
1440 CORBA::Object_var tmp
=
1441 orb
->string_to_object(ior
);
1443 test_object
= Test::_narrow(tmp
.in ());
1445 if (CORBA::is_nil (test_object
.in ()))
1447 ACE_ERROR_RETURN ((LM_DEBUG
,
1448 "Nil Test reference <%s>\n",
1453 catch (const CORBA::Exception
& ex
)
1455 ex
._tao_print_exception ("Initialization failure");
1460 ACE_DEBUG ((LM_DEBUG
,
1461 "(%P|%t) Initialization failure: caught a C++ exception\n"));
1467 fail
= test_basic ();
1469 fail
+= test_basic_invocations (test_object
.in ());
1471 fail
+= test_boxed_string ();
1473 fail
+= test_boxed_string_invocations (test_object
.in ());
1475 fail
+= test_boxed_sequence ();
1477 fail
+= test_boxed_sequence_invocations (test_object
.in ());
1479 fail
+= test_boxed_struct ();
1481 fail
+= test_boxed_struct_invocations (test_object
.in ());
1483 fail
+= test_boxed_array ();
1485 fail
+= test_boxed_array_invocations (test_object
.in ());
1487 fail
+= test_boxed_union();
1489 fail
+= test_boxed_union_invocations (test_object
.in ());
1494 test_object
->shutdown ();
1496 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - test finished\n"));
1500 catch (const CORBA::Exception
& ex
)
1502 ex
._tao_print_exception ("Exception caught:");
1506 return (fail
) ? 1 : 0;