summaryrefslogtreecommitdiff
path: root/TAO/tests/DynAny_Test/test_dynany.cpp
blob: 4bed14fab5b385f6b0ebbd6f2b664811b1fa1b52 (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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//=============================================================================
/**
 *  @file    test_dynany.cpp
 *
 *  Implementation of the basic test for simple DynAnys
 *
 *  @author Jeff Parsons <parsons@cs.wustl.edu>
 */
//=============================================================================

#include "tao/AnyTypeCode/AnyTypeCode_methods.h"
#include "tao/AnyTypeCode/ShortSeqA.h"
#include "tao/DynamicAny/DynamicAny.h"

#include "test_dynany.h"
#include "data.h"
#include "analyzer.h"

Test_DynAny::Test_DynAny (CORBA::ORB_var orb, int debug)
  : orb_ (orb),
    test_name_ (CORBA::string_dup ("test_dynany")),
    error_count_ (0),
    debug_ (debug)
{
}

Test_DynAny::~Test_DynAny ()
{
  CORBA::string_free (this->test_name_);
  this->test_name_ = 0;
}

const char*
Test_DynAny::test_name () const
{
  return this->test_name_;
}

int
Test_DynAny::run_test ()
{
  Data data (this->orb_);

  try
    {
      CORBA::Object_var factory_obj =
        this->orb_->resolve_initial_references ("DynAnyFactory");

      DynamicAny::DynAnyFactory_var dynany_factory =
        DynamicAny::DynAnyFactory::_narrow (factory_obj.in ());

      if (CORBA::is_nil (dynany_factory.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Nil dynamic any factory after narrow\n"),
                            -1);
        }

      DynAnyAnalyzer analyzer (this->orb_.in (),
                               dynany_factory.in (),
                               debug_);
      {
        ACE_DEBUG ((LM_DEBUG,
                    "\t*=*=*=*= %C =*=*=*=*\n",
                    data.labels[8]));

        ACE_DEBUG ((LM_DEBUG,
                    "testing: constructor(Any)/insert/get\n"));

        CORBA::Any in1;
        in1 <<= data.m_double2;
        DynamicAny::DynAny_var fa1 =
          dynany_factory->create_dyn_any (in1);

        if (fa1->equal(fa1.in ()))
          {
            ACE_DEBUG ((LM_DEBUG,
                        "++ OK ++\n"));
          }
        else
          {
            ACE_DEBUG ((LM_DEBUG,
                        "Double Not equal\n"));
            ++this->error_count_;
          }
        fa1->insert_double (data.m_double1);

        CORBA::Double d_out =
          fa1->get_double ();

        if (ACE::is_equal (d_out, data.m_double1))
          {
            ACE_DEBUG ((LM_DEBUG,
                        "++ OK ++\n"));
          }
        else
          {
            ++this->error_count_;
          }

        ACE_DEBUG ((LM_DEBUG,
                    "testing: constructor(TypeCode)/from_any/to_any\n"));

        d_out = data.m_double2;
        DynamicAny::DynAny_var ftc1 =
          dynany_factory->create_dyn_any_from_type_code (CORBA::_tc_double);
        CORBA::Any in_any1;
        in_any1 <<= data.m_double1;
        ftc1->from_any (in_any1);
        analyzer.analyze (ftc1.in());
        CORBA::Any_var out_any1 = ftc1->to_any ();
        out_any1 >>= d_out;

        if (ACE::is_equal (d_out, data.m_double1))
          {
            ACE_DEBUG ((LM_DEBUG,
                        "++ OK ++\n"));
          }
        else
          {
            ++this->error_count_;
          }

        fa1->destroy ();
        ftc1->destroy ();
      }

      {
        ACE_DEBUG ((LM_DEBUG,
                    "\t*=*=*=*= %C =*=*=*=*\n",
                    data.labels[17]));

        ACE_DEBUG ((LM_DEBUG,
                    "testing: constructor(Any)/insert/get\n"));

        CORBA::Any in1;
        in1 <<= data.m_longdouble2;
        DynamicAny::DynAny_var fa1 =
          dynany_factory->create_dyn_any (in1);

        if (fa1->equal(fa1.in ()))
          {
            ACE_DEBUG ((LM_DEBUG,
                        "++ OK ++\n"));
          }
        else
          {
            ACE_DEBUG ((LM_DEBUG,
                        "Long Double Not equal\n"));
            ++this->error_count_;
          }

        fa1->insert_longdouble (data.m_longdouble1);

        CORBA::LongDouble d_out = fa1->get_longdouble ();

        if (ACE::is_equal (d_out, data.m_longdouble1))
          {
            ACE_DEBUG ((LM_DEBUG,
                        "++ OK ++\n"));
          }
        else
          {
            ++this->error_count_;
          }

        ACE_DEBUG ((LM_DEBUG,
                    "testing: constructor(TypeCode)/from_any/to_any\n"));

        d_out = data.m_longdouble2;
        DynamicAny::DynAny_var ftc1 =
          dynany_factory->create_dyn_any_from_type_code (CORBA::_tc_longdouble);

        CORBA::Any in_any1;
        in_any1 <<= data.m_longdouble1;
        ftc1->from_any (in_any1);

        analyzer.analyze(ftc1.in());

        CORBA::Any_var out_any1 = ftc1->to_any ();

        out_any1.in() >>= d_out;

        if (ACE::is_equal (d_out, data.m_longdouble1))
          {
            ACE_DEBUG ((LM_DEBUG,
                        "++ OK ++\n"));
          }
        else
          {
            ++this->error_count_;
          }

        fa1->destroy ();
        ftc1->destroy ();
      }

      ACE_DEBUG ((LM_DEBUG,
                  "\t*=*=*=*= %C =*=*=*=*\n",
                  data.labels[12]));

      ACE_DEBUG ((LM_DEBUG,
                  "testing: constructor(Any)/insert/get\n"));

      CORBA::Any in;
      in <<= data.m_typecode2;
      DynamicAny::DynAny_var fa2 =
        dynany_factory->create_dyn_any (in);
      fa2->insert_typecode (data.m_typecode1);
      CORBA::TypeCode_var tc_out =
        fa2->get_typecode ();

      if (tc_out->equal (data.m_typecode1))
        {
          ACE_DEBUG ((LM_DEBUG,
                      "++ OK ++\n"));
        }
      else
        {
          ++this->error_count_;
        }


      ACE_DEBUG ((LM_DEBUG,
                  "testing: constructor(TypeCode)/from_any/to_any\n"));

      DynamicAny::DynAny_var ftc2 =
        dynany_factory->create_dyn_any_from_type_code (CORBA::_tc_TypeCode);
      CORBA::Any in_any2;
      in_any2 <<= data.m_typecode1;
      ftc2->from_any (in_any2);
      analyzer.analyze (ftc2.in());
      CORBA::Any_var out_any2 = ftc2->to_any ();
      CORBA::TypeCode_ptr out_tc;
      out_any2 >>= out_tc;

      CORBA::Boolean equal = out_tc->equal (data.m_typecode1);

      if (equal)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "++ OK ++\n"));
        }
      else
        {
          ++this->error_count_;
        }


      fa2->destroy ();
      ftc2->destroy ();

      ACE_DEBUG ((LM_DEBUG,
                  "\t*=*=*=*= %C =*=*=*=*\n",
                  data.labels[16]));

      ACE_DEBUG ((LM_DEBUG,
                  "testing: constructor(Any)/insert/get\n"));

      CORBA::Any in3;
      CORBA::ShortSeq ss;
      ss.length (0UL);
      in3 <<= ss;
      DynamicAny::DynAny_var fa3 =
        dynany_factory->create_dyn_any (in3);
      fa3->insert_short_seq (data.m_shortseq1);
      data.m_shortseq2 =
        fa3->get_short_seq ();

      bool good =
        data.m_shortseq2->length () == data.m_shortseq1.length ();

      if (good)
        {
          for (CORBA::ULong i = 0; i < data.m_shortseq1.length (); ++i)
            {
              if (data.m_shortseq2[i] != data.m_shortseq1[i])
                {
                  good = false;
                  break;
                }
            }
        }

      if (good)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "++ OK ++\n"));
        }
      else
        {
          ++this->error_count_;
        }


      ACE_DEBUG ((LM_DEBUG,
                  "testing: constructor(TypeCode)/from_any/to_any\n"));

      DynamicAny::DynAny_var ftc3 =
        dynany_factory->create_dyn_any_from_type_code (CORBA::_tc_ShortSeq);
      CORBA::Any in_any3;
      in_any3 <<= data.m_shortseq1;
      ftc3->from_any (in_any3);
      analyzer.analyze (ftc3.in ());
      CORBA::Any_var out_any3 = ftc3->to_any ();

      const CORBA::ShortSeq *outseq = 0;
      out_any3.in () >>= outseq;

      good =
        outseq->length () == data.m_shortseq1.length ();

      if (good)
        {
          for (CORBA::ULong i = 0; i < data.m_shortseq1.length (); ++i)
            {
              if ((*outseq)[i] != data.m_shortseq1[i])
                {
                  good = false;
                  break;
                }
            }
        }

      if (good)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "++ OK ++\n"));
        }
      else
        {
          ++this->error_count_;
        }

      fa3->destroy ();
      ftc3->destroy ();

      ACE_DEBUG ((LM_DEBUG,
                  "testing: equal\n"));

      // Simple equal to self test for basic sequence
      // Check equal to self, not equal for different length
      // not equal for different values
      CORBA::Any in4;
      in4 <<= data.m_shortseq1;
      DynamicAny::DynAny_var fa4 =
        dynany_factory->create_dyn_any (in4);

      // is equal to self
      good = fa4->equal(fa4.in ());

      CORBA::ShortSeq ss5;
      ss5.length(1);
      ss5[0] = 5;
      CORBA::Any in5;
      in5 <<= ss5;
      DynamicAny::DynAny_var fa5 =
        dynany_factory->create_dyn_any (in5);

      // is not equal for different lengths
      good = good && !fa4->equal(fa5.in ());

      CORBA::ShortSeq ss6(data.m_shortseq1);
      ss6[0]++;
      CORBA::Any in6;
      in6 <<= ss6;

      DynamicAny::DynAny_var fa6 =
        dynany_factory->create_dyn_any (in6);

      // is not equal for different values
      good = good && !fa4->equal(fa6.in ());


      CORBA::Any in7;
      in7 <<= data.m_shortseq1;
      DynamicAny::DynAny_var fa7 =
        dynany_factory->create_dyn_any (in7);


      // is equal to identical sequence, not self
      good = good && fa4->equal(fa7.in ());


      if (good)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "++ OK ++\n"));
        }
      else
        {
          ++this->error_count_;
        }

    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("test_dynany::run_test");
      ++this->error_count_;
    }

  ACE_DEBUG ((LM_DEBUG,
              "\n%d errors\n",
              this->error_count_));

  return error_count_;
}