summaryrefslogtreecommitdiff
path: root/TAO/tests/Param_Test/complex_any.cpp
blob: fead61f28217f9df8aec1d96a69d2620fd5e0d68 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/tests/Param_Test
//
// = FILENAME
//    complex_any.cpp
//
// = DESCRIPTION
//    tests complex Anys
//
// = AUTHORS
//    Aniruddha Gokhale, Jeff Parsons, Frank Buschmann
//
// ============================================================================

#include "helper.h"
#include "complex_any.h"
#include "tao/debug.h"

ACE_RCSID (Param_Test,
           complex_any,
           "$Id$")

const int LEVEL_2_LENGTH = 5;
const int LEVEL_3_LENGTH = 3;

// ************************************************************************
//               Test_Complex_Any
// ************************************************************************

size_t Test_Complex_Any::counter = 0;

Test_Complex_Any::Test_Complex_Any (void)
  : opname_ (CORBA::string_dup ("test_complex_any")),
    out_ (new CORBA::Any),
    ret_ (new CORBA::Any)
{
}

Test_Complex_Any::~Test_Complex_Any (void)
{
  CORBA::string_free (this->opname_);
  this->opname_ = 0;
}

const char *
Test_Complex_Any::opname (void) const
{
  return this->opname_;
}

void
Test_Complex_Any::dii_req_invoke (CORBA::Request *req)
{
  req->add_in_arg ("s1") <<= this->in_;
  req->add_inout_arg ("s2") <<= this->inout_;
  req->add_out_arg ("s3") <<= this->out_.in ();

  req->set_return_type (CORBA::_tc_any);

  req->invoke ();

  const CORBA::Any *tmp;
  req->return_value () >>= tmp;
  this->ret_ = new CORBA::Any (*tmp);

  CORBA::NamedValue_ptr o2 =
    req->arguments ()->item (1);
  *o2->value () >>= tmp;
  this->inout_ = CORBA::Any (*tmp);

  CORBA::NamedValue_ptr o3 =
    req->arguments ()->item (2);
  *o3->value () >>= tmp;
  this->out_ = new CORBA::Any (*tmp);
}

int
Test_Complex_Any::init_parameters (Param_Test_ptr)
{
  return this->reset_parameters ();
}

// This Any is a real-world use cases
// submitted by Frank Buschmann of Siemens. Here's the structure:
//
// Any <- AnySeq <- AnySeq <- struct <- string
//                                   <- Any <- Any <- Any <- struct <- string
//                                                                  <- boolean
//                                                                  <- short
int
Test_Complex_Any::reset_parameters (void)
{
  Generator *gen = GENERATOR::instance (); // value generator

  CORBA::AnySeq level2_seq, level3_seq;
  level2_seq.length (LEVEL_2_LENGTH);
  level3_seq.length (LEVEL_3_LENGTH);

  for (int j = 0; j < LEVEL_2_LENGTH; j++)
    {
      for (int i = 0; i < LEVEL_3_LENGTH; i++)
        {
          Param_Test::level4 level4_struct;

          char *l5_str = gen->gen_string ();

          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        "setting level 5 string = %s\n",
                        l5_str));

          level4_struct.level5_string = l5_str;

          CORBA::Any level6_any, level7_any;

          Param_Test::level8 level8_struct;

          char *l9_str = gen->gen_string ();

          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        "setting level 9 string = %s\n",
                        l9_str));

          level8_struct.level9_string = l9_str;

          CORBA::Short l9_bool = ACE_OS::rand () % 2;

          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        "setting level 9 boolean = %d\n",
                        l9_bool));

          level8_struct.level9_boolean = (CORBA::Boolean) l9_bool;

          CORBA::Short l9_short = gen->gen_short ();

          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        "setting level 9 short = %d\n",
                        l9_short));

          level8_struct.level9_short = l9_short;

          level7_any <<= level8_struct;

          level6_any <<= level7_any;

          level4_struct.level5_any <<= level6_any;

          level3_seq[i] <<= level4_struct;
        }

      level2_seq[j] <<= level3_seq;
    }

  this->in_ <<= level2_seq;

  return 0;
}

int
Test_Complex_Any::run_sii_test (Param_Test_ptr objref)
{
  try
    {
      this->ret_ = objref->test_complex_any (this->in_,
                                             this->inout_,
                                             this->out_.out ());
    }
  catch (const CORBA::Exception& ex)
    {
      return -1;
    }
  return 0;
}

CORBA::Boolean
Test_Complex_Any::check_validity (void)
{
  CORBA::AnySeq *level2_in_seq;
  CORBA::AnySeq *level2_test_seq;

  if (!(this->in_ >>= level2_in_seq))
    return 0;

  if (!(this->inout_ >>= level2_test_seq))
    return 0;

  if (this->comp_engine (level2_in_seq, level2_test_seq) == 0)
    return 0;

  if (!(this->out_.in () >>= level2_test_seq))
    return 0;

  if (this->comp_engine (level2_in_seq, level2_test_seq) == 0)
    return 0;

  if (!(this->ret_.in () >>= level2_test_seq))
    return 0;

  if (this->comp_engine (level2_in_seq, level2_test_seq) == 0)
    return 0;

  return 1;
}

// Private helper function for check_validity.
CORBA::Boolean
Test_Complex_Any::comp_engine (const CORBA::AnySeq *level2_in_seq,
                               const CORBA::AnySeq *level2_comp_seq)
{
  if (level2_in_seq->length() != level2_comp_seq->length())
    {
      ACE_DEBUG ((LM_DEBUG,
                  "mismatch of level 2 sequence lengths\n"));
      return 0;
    }

  for (CORBA::ULong i = 0; i < level2_in_seq->length (); i++)
    {
      CORBA::AnySeq *level3_in_seq;
      CORBA::AnySeq *level3_test_seq;

      if (!((*level2_in_seq)[i] >>= level3_in_seq))
        return 0;
      if (!((*level2_comp_seq)[i] >>= level3_test_seq))
        return 0;

      if (level3_in_seq->length() != level3_test_seq->length())
        {
          ACE_DEBUG ((LM_DEBUG,
                      "mismatch of level 3 sequence lengths\n"));
          return 0;
        }

      for (CORBA::ULong j = 0; j < level3_in_seq->length (); j ++)
        {
          Param_Test::level4 *level4_in_struct;
          Param_Test::level4 *level4_test_struct;

          if (!((*level3_in_seq)[j] >>= level4_in_struct))
            return 0;
          if (!((*level3_test_seq)[j] >>= level4_test_struct))
            return 0;

          if (ACE_OS::strcmp (level4_in_struct->level5_string,
                              level4_test_struct->level5_string))
            {
              ACE_DEBUG ((LM_DEBUG,
                          "mismatch of level 5 string values\n"));
              return 0;
            }

          const CORBA::Any *level6_in_any;
          const CORBA::Any *level6_test_any;
          const CORBA::Any *level7_in_any;
          const CORBA::Any *level7_test_any;

          if (!(level4_in_struct->level5_any >>= level6_in_any))
            return 0;
          if (!(level4_test_struct->level5_any >>= level6_test_any))
            return 0;

          if (!((*level6_in_any) >>= level7_in_any))
            return 0;
          if (!((*level6_test_any) >>= level7_test_any))
            return 0;

          Param_Test::level8 *level8_in_struct;
          Param_Test::level8 *level8_test_struct;

          if (!((*level7_in_any) >>= level8_in_struct))
            return 0;
          if (!((*level7_test_any) >>= level8_test_struct))
            return 0;

          if (ACE_OS::strcmp (level8_in_struct->level9_string,
                               level8_test_struct->level9_string))
            {
              ACE_DEBUG ((LM_DEBUG,
                          "mismatch of level 9 string values\n"));
              return 0;
            }

          if (level8_in_struct->level9_boolean != level8_test_struct->level9_boolean)
            {
              ACE_DEBUG ((LM_DEBUG,
                          "mismatch of level 9 boolean values\n"));
              return 0;
            }

          if (level8_in_struct->level9_short != level8_test_struct->level9_short)
            {
              ACE_DEBUG ((LM_DEBUG,
                          "mismatch of level 9 short values\n"));
              return 0;
            }
        }
    }

  // If we get here, all is correct.
  return 1;
}

CORBA::Boolean
Test_Complex_Any::check_validity (CORBA::Request_ptr /*req*/)
{
  return this->check_validity ();
}

void
Test_Complex_Any::print_values (void)
{
}