summaryrefslogtreecommitdiff
path: root/TAO/interop-tests/AnyTypeCode/tao/Client.cpp
blob: aa2f113e49bb3ad16170b0d8c0a22f0cd36611e7 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// $Id$
// FUZZ: disable check_for_ace_log_categories

#include "DemoC.h"
#include "BaseValueImpl.h"
#include "NestedValueImpl.h"

#include "ace/Log_Msg.h"
#include "ace/OS_NS_stdio.h"
#include "ace/Get_Opt.h"

void unionWithBar1 (CORBA::Any& any)
{
  Demo::BaseUnion bar1;
  bar1.str (CORBA::string_dup ("Bar 1"));
  Demo::NestedUnion any_union;
  any_union.bar1 (bar1);

  any <<= any_union;
}

void unionWithBar2 (CORBA::Any& any)
{
  Demo::BaseUnion bar2;
  bar2.l (9765625);
  Demo::NestedUnion any_union;
  any_union.bar2 (bar2);

  any <<= any_union;
}

void unionWithDefaultBar (CORBA::Any& any)
{
  Demo::BaseUnion defaultBar;
  defaultBar.s (1024);
  Demo::NestedUnion any_union;
  any_union.defaultBar (defaultBar);

  any <<= any_union;
}

const ACE_TCHAR *ior_str = ACE_TEXT ("file://test.ior");

int
parse_args (int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'k':
        ior_str = get_opts.opt_arg ();
        break;

      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("usage:  %s ")
                           ACE_TEXT ("-k <ior>")
                           ACE_TEXT ("\n"),
                           argv [0]),
                          -1);
      }
  // Indicates successful parsing of the command line
  return 0;
}

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  Demo::ATC_Test_var test;
  CORBA::ORB_var orb;
  try
    {
      orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) == -1)
        {
          return -1;
        }
      CORBA::Object_var obj =
        orb->string_to_object (ACE_TEXT_ALWAYS_CHAR (ior_str));
      if  (CORBA::is_nil (obj.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("%P could not get ATC_Test IOR.\n")),
                            -1);
        }

      test = Demo::ATC_Test::_narrow (obj.in ());
      if  (CORBA::is_nil (test.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("%P narrow failed.\n")),
                            -1);
        }
    }
  catch  (CORBA::Exception& ex)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%P initialization caught %s.\n"), ex._name()),
                        -1);
    }

  CORBA::Any any;
  CORBA::String_var str;

  // union tests
  try
    {
      unionWithBar1 (any);
      str = test->do_union (any);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%P Union test 1 returned %s\n"), str.in()));

      unionWithBar2 (any);
      str = test->do_union (any);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%P Union test 2 returned %s\n"), str.in()));

      unionWithDefaultBar (any);
      str = test->do_union (any);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%P Union test 3 returned %s\n"), str.in()));
    }
  catch  (CORBA::Exception& ex)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%P Union test caught %s.\n"), ex._name()));
    }

  // valuetype tests
  try
    {
      Demo_BaseValueImpl* foo1 = new Demo_BaseValueImpl();
      foo1->str(CORBA::string_dup("BaseValue 1"));

      Demo_BaseValueImpl* foo2 = new Demo_BaseValueImpl();
      foo2->str(CORBA::string_dup("BaseValue 2"));

      Demo_NestedValueImpl* bar = new Demo_NestedValueImpl();
      bar->foo1(foo1);
      bar->foo2(foo2);

      any <<= bar;

      str = test->do_value (any);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%P Valuetype test returned %s\n"),
                  str.in()));
    }
  catch  (CORBA::Exception& ex)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%P Valuetype test caught %s.\n"), ex._name()));
    }

  // struct tests
  try
    {

      Demo::BaseStruct foo1;
      foo1.str = CORBA::string_dup("BaseStruct 1");

      Demo::BaseStruct foo2;
      foo2.str = CORBA::string_dup("BaseStruct 2");

      Demo::BaseStruct foo3;
      foo3.str = CORBA::string_dup("BaseStruct 3");

      Demo::NestedStruct bar;
      bar.foo1 = foo1;
      bar.foo2 = foo2;
      bar.foo3 = foo3;

      Demo::BaseStruct innerBaseStruct1;
      innerBaseStruct1.str = CORBA::string_dup("Inner BaseStruct 1");

      Demo::BaseStruct innerBaseStruct2;
      innerBaseStruct2.str = CORBA::string_dup("Inner BaseStruct 2");

      Demo::BaseStruct innerBaseStruct3;
      innerBaseStruct3.str = CORBA::string_dup("Inner BaseStruct 3");

      Demo::NestedStruct innerBar;
      innerBar.foo1 = innerBaseStruct1;
      innerBar.foo2 = innerBaseStruct2;
      innerBar.foo3 = innerBaseStruct3;

      Demo::NestedSeq bars;
      bars.length(1);
      bars[0] = innerBar;

      bar.bars = bars;

      any <<= bar;

      str = test->do_struct (any);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%P struct test returned %s\n"),
                  str.in()));
    }
  catch  (CORBA::Exception& ex)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%P struct test caught %s.\n"), ex._name()));
    }

  test->shutdown ();

  return 0;
}