summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_1639_Regression/struct_client.cpp
blob: 16ba27452ea0d831fc4f2228f32c2fd67913d373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// $Id$
//
#include "tao/DynamicAny/DynAnyFactory.h"
#include "structC.h"
#include <ace/streams.h>

using namespace StructTest;
using namespace DynamicAny;

//--------------------------------------------------------------------
int main (int argc, char * argv[])
//--------------------------------------------------------------------
{

  // Generic catch handler
  try {

    // Initialize the ORB
    // ------------------
    CORBA::ORB_var orb;  // _var, so we don't need/may not CORBA::release(orb)
    try {
      orb = CORBA::ORB_init (argc, argv);
    } catch (...) {
      cerr << "Cannot initialize ORB" << endl;
      throw;
    }

    // Get reference to the DynAny Factory
    CORBA::Object_var obj =  orb->resolve_initial_references("DynAnyFactory");

    DynAnyFactory_var daf =
      DynAnyFactory::_narrow(obj.in());

    MyStruct my_struct;
    MyStructAlias my_struct_alias;
    MyUnion my_union;
    MyUnionAlias my_union_alias;

    CORBA::Any any_struct;
    CORBA::Any any_struct_alias;
    CORBA::Any any_union;
    CORBA::Any any_union_alias;

    // Write the structs and unions to anys so we can get the TypeCode info
    any_struct <<= my_struct;
    any_struct_alias <<= my_struct_alias;
    any_union <<= my_union;
    any_union_alias <<= my_union_alias;

    // Explicitly set the TypeCode for the aliased types because the any
    // doesn't take care of aliases
    any_struct_alias.type(_tc_MyStructAlias);
    any_union_alias.type(_tc_MyUnionAlias);

    CORBA::TypeCode_var tc_struct = any_struct.type();
    CORBA::TypeCode_var tc_struct_alias = any_struct_alias.type();
    CORBA::TypeCode_var tc_union = any_union.type();
    CORBA::TypeCode_var tc_union_alias = any_union_alias.type();

    cout << "Type Code of the struct: " << tc_struct->kind() << endl;
    cout << "Type Code of the struct alias: " << tc_struct_alias->kind() << endl;
    cout << "Type Code of the union: " << tc_union->kind() << endl;
    cout << "Type Code of the union alias: " << tc_union_alias->kind() << endl;

    // equal returns true only when the TypeCodes are exactly the same.
    if (tc_struct->equal(tc_struct_alias.in())) {
      cout << "Type Codes are identical" << endl;
    } else {
      cout << "Type Codes are different" << endl;
    }
    // equivalent returns true when the TypeCode is an alias
    if (tc_struct->equivalent(tc_struct_alias.in())) {
      cout << "Type Codes are equivalent" << endl;
    } else {
      cout << "Type Codes are not equivalent" << endl;
    }

    DynAny_var da_struct = daf->create_dyn_any_from_type_code (tc_struct.in());

    try {
      DynAny_var da_struct_alias = daf->create_dyn_any_from_type_code (tc_struct_alias.in());
    } catch ( const CORBA::UNKNOWN &) {
      cout << "CORBA::UNKNOWN exception when calling create_dyn_any_from_type_code (tc_struct_alias)" << endl;
    }

    try {
      DynAny_var da_struct_alias = daf->create_dyn_any (any_struct_alias);
    } catch ( const CORBA::UNKNOWN &) {
      cout << "CORBA::UNKNOWN exception when calling create_dyn_any (any_struct_alias)" << endl;
    }

    DynAny_var da_union = daf->create_dyn_any_from_type_code (tc_union.in());

    try {
      DynAny_var da_union_alias = daf->create_dyn_any_from_type_code (tc_union_alias.in());
    } catch ( const CORBA::UNKNOWN &) {
      cout << "CORBA::UNKNOWN exception when calling create_dyn_any_from_type_code (tc_union_alias)" << endl;
    }

    try {
      DynAny_var da_union_alias = daf->create_dyn_any (any_union_alias);
    } catch ( const CORBA::UNKNOWN &) {
      cout << "CORBA::UNKNOWN exception when calling create_dyn_any (any_union_alias)" << endl;
    }

  } // end try

  catch (const CORBA::Exception &) {
    cerr << "Caught CORBA exception" << endl;
    return 1;
  }
  catch (...) {
    return 1;
  }
  return 0;
}