More tests update
[ACE_TAO.git] / TAO / tests / Bug_1639_Regression / struct_client.cpp
blob9e29e5fb013a1899e5243f60cfd05e841325f495
1 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
2 #include "tao/DynamicAny/DynAnyFactory.h"
3 #include "structC.h"
4 #include <ace/streams.h>
6 using namespace StructTest;
7 using namespace DynamicAny;
9 //--------------------------------------------------------------------
10 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
11 //--------------------------------------------------------------------
14 // Generic catch handler
15 try {
17 // Initialize the ORB
18 // ------------------
19 CORBA::ORB_var orb; // _var, so we don't need/may not CORBA::release(orb)
20 try {
21 orb = CORBA::ORB_init (argc, argv);
22 } catch (...) {
23 cerr << "Cannot initialize ORB" << endl;
24 throw;
27 // Get reference to the DynAny Factory
28 CORBA::Object_var obj = orb->resolve_initial_references("DynAnyFactory");
30 DynAnyFactory_var daf =
31 DynAnyFactory::_narrow(obj.in());
33 MyStruct my_struct;
34 MyStructAlias my_struct_alias;
35 MyUnion my_union;
36 MyUnionAlias my_union_alias;
38 CORBA::Any any_struct;
39 CORBA::Any any_struct_alias;
40 CORBA::Any any_union;
41 CORBA::Any any_union_alias;
43 // Write the structs and unions to anys so we can get the TypeCode info
44 any_struct <<= my_struct;
45 any_struct_alias <<= my_struct_alias;
46 any_union <<= my_union;
47 any_union_alias <<= my_union_alias;
49 // Explicitly set the TypeCode for the aliased types because the any
50 // doesn't take care of aliases
51 any_struct_alias.type(_tc_MyStructAlias);
52 any_union_alias.type(_tc_MyUnionAlias);
54 CORBA::TypeCode_var tc_struct = any_struct.type();
55 CORBA::TypeCode_var tc_struct_alias = any_struct_alias.type();
56 CORBA::TypeCode_var tc_union = any_union.type();
57 CORBA::TypeCode_var tc_union_alias = any_union_alias.type();
59 cout << "Type Code of the struct: " << tc_struct->kind() << endl;
60 cout << "Type Code of the struct alias: " << tc_struct_alias->kind() << endl;
61 cout << "Type Code of the union: " << tc_union->kind() << endl;
62 cout << "Type Code of the union alias: " << tc_union_alias->kind() << endl;
64 // equal returns true only when the TypeCodes are exactly the same.
65 if (tc_struct->equal(tc_struct_alias.in())) {
66 cout << "Type Codes are identical" << endl;
67 } else {
68 cout << "Type Codes are different" << endl;
70 // equivalent returns true when the TypeCode is an alias
71 if (tc_struct->equivalent(tc_struct_alias.in())) {
72 cout << "Type Codes are equivalent" << endl;
73 } else {
74 cout << "Type Codes are not equivalent" << endl;
77 DynAny_var da_struct = daf->create_dyn_any_from_type_code (tc_struct.in());
79 try {
80 DynAny_var da_struct_alias = daf->create_dyn_any_from_type_code (tc_struct_alias.in());
81 } catch ( const CORBA::UNKNOWN &) {
82 cout << "CORBA::UNKNOWN exception when calling create_dyn_any_from_type_code (tc_struct_alias)" << endl;
85 try {
86 DynAny_var da_struct_alias = daf->create_dyn_any (any_struct_alias);
87 } catch ( const CORBA::UNKNOWN &) {
88 cout << "CORBA::UNKNOWN exception when calling create_dyn_any (any_struct_alias)" << endl;
91 DynAny_var da_union = daf->create_dyn_any_from_type_code (tc_union.in());
93 try {
94 DynAny_var da_union_alias = daf->create_dyn_any_from_type_code (tc_union_alias.in());
95 } catch ( const CORBA::UNKNOWN &) {
96 cout << "CORBA::UNKNOWN exception when calling create_dyn_any_from_type_code (tc_union_alias)" << endl;
99 try {
100 DynAny_var da_union_alias = daf->create_dyn_any (any_union_alias);
101 } catch ( const CORBA::UNKNOWN &) {
102 cout << "CORBA::UNKNOWN exception when calling create_dyn_any (any_union_alias)" << endl;
105 } // end try
107 catch (const CORBA::Exception &) {
108 cerr << "Caught CORBA exception" << endl;
109 return 1;
111 catch (...) {
112 return 1;
114 return 0;