2 #include "tao/IFR_Client/IFR_BaseC.h"
3 #include "tao/TypeCodeFactory/TypeCodeFactory_Loader.h"
5 #include "ace/Get_Opt.h"
10 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
18 while ((c
= get_opts ()) != -1)
22 ior
= get_opts
.opt_arg ();
28 ACE_ERROR_RETURN ((LM_ERROR
,
36 // Successful command line parsing.
40 template<typename T
> void dump (T
*); // Forward declaration.
44 dump
<Test::RecursiveStruct
> (Test::RecursiveStruct
* data
)
47 "Test::RecursiveStruct\n"
53 data
->recursive_structs
.length (),
54 data
->recursive_structs
[0].i
,
55 data
->recursive_structs
[1].i
));
60 dump
<Test::NestedRecursiveStruct
> (Test::NestedRecursiveStruct
* data
)
63 "Test::NestedRecursiveStruct\n"
69 data
->ins
.recursive_structs
.length (),
70 data
->ins
.recursive_structs
[0].i
,
71 data
->ins
.recursive_structs
[1].i
));
76 dump
<Test::RecursiveUnion
> (Test::RecursiveUnion
* data
)
78 ACE_DEBUG ((LM_DEBUG
, "Test::RecursiveUnion\n"));
84 Test::RecursiveUnionSeq
const & seq
= data
->recursive_unions ();
92 seq
[1].recursive_unions ().length ()));
105 perform_invocation (Test::Hello_ptr hello
,
106 CORBA::Any
const & the_any
)
108 // Execute more than once to help verify that mutable recursive
109 // TypeCode state is managed correctly.
110 for (unsigned int n
= 0; n
< 2; ++n
)
112 CORBA::Any_var my_any
=
113 hello
->get_any (the_any
);
115 const T
* my_foo
= 0;
116 if (!(my_any
.in () >>= my_foo
))
117 throw Test::Demarshaling_From_Any_Failed ();
119 // ACE_DEBUG ((LM_DEBUG, "Data dump:\n"));
122 CORBA::TypeCode_var the_tc
= the_any
.type ();
123 CORBA::TypeCode_var my_tc
= my_any
->type ();
125 CORBA::Boolean
const equal_tc
=
126 the_tc
->equal (my_tc
.in ());
129 throw Test::Recursive_Type_In_Any_Test_Failed ();
131 CORBA::Boolean
const equiv_tc
=
132 the_tc
->equivalent (my_tc
.in ());
135 throw Test::Recursive_Type_In_Any_Test_Failed ();
140 recursive_struct_test (CORBA::ORB_ptr
/* orb */,
141 Test::Hello_ptr hello
)
144 "Executing recursive struct test\n"));
146 Test::RecursiveStruct foo
;
148 foo
.recursive_structs
.length (2);
149 foo
.recursive_structs
[0].i
= 37;
150 foo
.recursive_structs
[1].i
= 11034;
156 ::perform_invocation
<Test::RecursiveStruct
> (hello
,
161 nested_recursive_struct_test (CORBA::ORB_ptr
/* orb */,
162 Test::Hello_ptr hello
)
165 "Executing nested recursive struct test\n"));
167 Test::NestedRecursiveStruct foo
;
169 foo
.ins
.recursive_structs
.length (2);
170 foo
.ins
.recursive_structs
[0].i
= 37;
171 foo
.ins
.recursive_structs
[1].i
= 11034;
177 ::perform_invocation
<Test::NestedRecursiveStruct
> (hello
, the_any
);
182 recursive_union_test (CORBA::ORB_ptr
/* orb */,
183 Test::Hello_ptr hello
)
186 "Executing recursive union test\n"));
190 Test::EnumUnion foo_enum
;
191 static CORBA::Short
const test_long
= 23901;
193 // First simple case, just an union with an enum as discriminator
194 foo_enum
.i (test_long
);
195 the_any
<<= foo_enum
;
197 ::perform_invocation
<Test::EnumUnion
> (hello
, the_any
);
199 // Non-recursive member case.
200 Test::RecursiveUnion foo
;
205 ::perform_invocation
<Test::RecursiveUnion
> (hello
, the_any
);
207 Test::RecursiveUnion2 foo2
;
212 ::perform_invocation
<Test::RecursiveUnion2
> (hello
,
215 Test::RecursiveUnion3 foo3
;
221 for (n
=0; n
< 200; ++n
)
223 ::perform_invocation
<Test::RecursiveUnion3
> (hello
,
228 // Recursive member case.
229 Test::RecursiveUnionSeq seq
;
232 seq
[1].recursive_unions (Test::RecursiveUnionSeq ());
234 foo
.recursive_unions (seq
);
238 ::perform_invocation
<Test::RecursiveUnion
> (hello
,
241 // Recursive member case with no default member
242 Test::RecursiveUnionSeqNoDefault seqnodefault
;
243 seqnodefault
.length (2);
244 seqnodefault
[0].a (37);
245 seqnodefault
[1].recursive_unions (Test::RecursiveUnionSeqNoDefault ());
247 Test::RecursiveUnionNoDefault foonodefault
;
248 foonodefault
.recursive_unions (seqnodefault
);
250 the_any
<<= foonodefault
;
252 ::perform_invocation
<Test::RecursiveUnionNoDefault
> (hello
,
255 // Recursive member case with enum .
256 Test::VSortRecursiveUnionSeq vsortseq
;
259 vsortseq
[1].recursive_unions (Test::VSortRecursiveUnionSeq ());
261 Test::VSortRecursiveUnion vsort_foo
;
262 vsort_foo
.recursive_unions (vsortseq
);
264 the_any
<<= vsort_foo
;
266 ::perform_invocation
<Test::VSortRecursiveUnion
> (hello
,
269 // Non-recursive member case with enum .
270 Test::NonRecursiveUnionWithEnum val
;
273 ::perform_invocation
<Test::NonRecursiveUnionWithEnum
> (hello
,
276 // Non-recursive member case with recursive struct .
278 Test::NonRecursiveUnionWithStringStruct val2
;
281 ::perform_invocation
<Test::NonRecursiveUnionWithStringStruct
> (hello
, the_any
);
286 indirectly_recursive_valuetype_test (CORBA::ORB_ptr
/* orb */,
287 Test::Hello_ptr
/* hello */)
290 "Executing indirectly recursive valuetype test\n"));
292 ACE_DEBUG ((LM_WARNING
,
293 " Currently unimplemented.\n"));
297 directly_recursive_valuetype_test (CORBA::ORB_ptr
/* orb */,
298 Test::Hello_ptr
/* hello */)
301 "Executing directly recursive valuetype test\n"));
303 ACE_DEBUG ((LM_WARNING
,
304 " Currently unimplemented.\n"));
307 #if TAO_HAS_MINIMUM_CORBA == 0
310 recursive_struct_typecodefactory_test (CORBA::ORB_ptr orb
,
311 Test::Hello_ptr hello
)
314 "Executing recursive struct via TypeCodeFactory test\n"));
316 Test::RecursiveStruct foo
;
318 foo
.recursive_structs
.length (2);
319 foo
.recursive_structs
[0].i
= 37;
320 foo
.recursive_structs
[1].i
= 11034;
326 CORBA::TypeCode_var recursive_tc
=
327 orb
->create_recursive_tc ("IDL:Test/RecursiveStruct:1.0");
329 CORBA::TypeCode_var seq_tc
=
330 orb
->create_sequence_tc (0,
333 CORBA::StructMemberSeq
members (3);
335 members
[0].name
= "recursive_structs";
336 members
[0].type
= seq_tc
;
337 members
[1].name
= "i";
338 members
[1].type
= CORBA::TypeCode::_duplicate (CORBA::_tc_long
);
339 members
[2].name
= "recursive_structs_second";
340 members
[2].type
= seq_tc
;
342 CORBA::TypeCode_var struct_tc
=
343 orb
->create_struct_tc ("IDL:Test/RecursiveStruct:1.0",
347 // Reset the underlying TypeCode to the one we just created with the
349 the_any
.type (struct_tc
.in ());
351 ::perform_invocation
<Test::RecursiveStruct
> (hello
,
356 recursive_union_typecodefactory_test (CORBA::ORB_ptr
/* orb */,
357 Test::Hello_ptr
/* hello */)
360 "Executing recursive union via TypeCodeFactory test\n"));
362 ACE_DEBUG ((LM_WARNING
,
363 " Currently unimplemented.\n"));
367 indirectly_recursive_valuetype_typecodefactory_test (
368 CORBA::ORB_ptr
/* orb */,
369 Test::Hello_ptr
/* hello */)
372 "Executing indirectly recursive valuetype via "
373 "TypeCodeFactory test\n"));
375 ACE_DEBUG ((LM_WARNING
,
376 " Currently unimplemented.\n"));
380 directly_recursive_valuetype_typecodefactory_test (CORBA::ORB_ptr
/* orb */,
381 Test::Hello_ptr
/* hello */)
384 "Executing directly recursive valuetype via "
385 "TypeCodeFactory test\n"));
387 ACE_DEBUG ((LM_WARNING
,
388 " Currently unimplemented.\n"));
391 #endif /* TAO_HAS_MINIMUM_CORBA == 0 */
397 * @brief Test method invocation functor.
399 * Test method invocation functor.
401 template <typename T
>
402 struct Caller
: public std::function
<void(T
)>
405 Caller (CORBA::ORB_ptr o
, Test::Hello_ptr h
)
406 : orb (CORBA::ORB::_duplicate (o
))
407 , hello (Test::Hello::_duplicate (h
))
412 /// Function call operator overload.
413 void operator() (T f
)
420 catch (const CORBA::Exception
& ex
)
422 ex
._tao_print_exception ("Exception thrown:");
429 Test::Hello_var hello
;
434 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
439 CORBA::ORB_init (argc
, argv
);
441 if (parse_args (argc
, argv
) != 0)
444 CORBA::Object_var tmp
=
445 orb
->string_to_object(ior
);
447 Test::Hello_var hello
=
448 Test::Hello::_narrow(tmp
.in ());
450 if (CORBA::is_nil (hello
.in ()))
452 ACE_ERROR_RETURN ((LM_DEBUG
,
453 "Nil Test::Hello reference <%s>\n",
458 typedef void (*test_func
) (CORBA::ORB_ptr
,
461 static test_func
const tests
[] =
463 recursive_struct_test
464 , nested_recursive_struct_test
465 , indirectly_recursive_valuetype_test
466 , directly_recursive_valuetype_test
467 , recursive_union_test
468 #if TAO_HAS_MINIMUM_CORBA == 0
469 , recursive_struct_typecodefactory_test
470 , recursive_union_typecodefactory_test
471 , indirectly_recursive_valuetype_typecodefactory_test
472 , directly_recursive_valuetype_typecodefactory_test
473 #endif /* TAO_HAS_MINIMUM_CORBA == 0 */
476 static size_t const test_count
= sizeof (tests
) / sizeof (test_func
);
478 // Have some fun with the STL. :-)
479 Caller
<test_func
> c
=
480 std::for_each (tests
,
482 Caller
<test_func
> (orb
.in (),
486 throw Test::Recursive_Type_In_Any_Test_Failed ();
492 catch (const CORBA::Exception
& ex
)
494 ex
._tao_print_exception ("Exception caught:");