summaryrefslogtreecommitdiff
path: root/TAO/tests/DynAny_Test/test_dynunion.cpp
blob: e74a02b241564d8e75675b870c2ecba047c229ad (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
// -*- c++ -*-
// $Id$
// ============================================================================
//
// = LIBRARY
//    TAO/tests/DynAny_Test
//
// = FILENAME
//    test_dynunion.cpp
//
// = DESCRIPTION
//    Implementation of the simple DynUnion test
//
// = AUTHOR
//    Jeff Parsons <parsons@cs.wustl.edu>
//
// ============================================================================

#include "test_dynunion.h"
#include "da_testsC.h"
#include "data.h"

Test_DynUnion::Test_DynUnion (CORBA::ORB_var orb)
  : orb_ (orb),
    test_name_ (CORBA::string_dup ("test_dynunion")),
    error_count_ (0)
{
}

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

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

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

  DynAnyTests::test_union tu;

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

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

      tu._d(DynAnyTests::TE_SECOND);
      tu.tc (data.m_typecode2);
      CORBA_Any in_any1;
      in_any1 <<= tu;
      CORBA_DynAny_ptr dp1 =
        this->orb_->create_dyn_any (in_any1,
                                    ACE_TRY_ENV);
      ACE_TRY_CHECK;
      CORBA_DynUnion_ptr fa1 = CORBA_DynUnion::_narrow (dp1,
                                                        ACE_TRY_ENV);
      ACE_TRY_CHECK;
      fa1->insert_typecode (data.m_typecode1,
                            ACE_TRY_ENV);
      ACE_TRY_CHECK;
      CORBA::TypeCode_ptr s_out1 = fa1->get_typecode (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      if (s_out1->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"));

      CORBA_Any* out_any1 = fa1->to_any (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      CORBA_DynUnion_ptr ftc1 = 
        this->orb_->create_dyn_union (DynAnyTests::_tc_test_union,
                                      ACE_TRY_ENV);
      ACE_TRY_CHECK;
      ftc1->from_any (*out_any1,
                      ACE_TRY_ENV);
      ACE_TRY_CHECK;
      CORBA::TypeCode_ptr s_out2 = ftc1->get_typecode (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      if (s_out2->equal (data.m_typecode1))
        ACE_DEBUG ((LM_DEBUG,
                   "++ OK ++\n"));
      else 
        ++this->error_count_;

      // Created with NEW
      delete out_any1;

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

      if (!ftc1->set_as_default (ACE_TRY_ENV))
        ACE_DEBUG ((LM_DEBUG,
                   "++ OK ++\n"));
      else 
        ++this->error_count_;

      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG,
                 "testing:discriminator/discriminator_kind\n"));

      CORBA_DynAny_ptr dp2 = ftc1->discriminator (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      if (dp2->type (ACE_TRY_ENV)->kind () 
            == ftc1->discriminator_kind (ACE_TRY_ENV))
        ACE_DEBUG ((LM_DEBUG,
                   "++ OK ++\n"));
      else 
        ++this->error_count_; 
      
      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG,
                 "testing:member/member_kind/member_name\n"));

      CORBA_DynAny_ptr dp3 = ftc1->member (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      CORBA::String m_nm = ftc1->member_name (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      CORBA::TCKind tk = ftc1->member_kind (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      if (!ACE_OS::strcmp (m_nm, "tc")
          && tk == CORBA::tk_TypeCode
          && data.m_typecode1->equal (dp3->get_typecode (ACE_TRY_ENV)))
        ACE_DEBUG ((LM_DEBUG,
                   "++ OK ++\n"));
      else 
        ++this->error_count_; 

      ACE_TRY_CHECK;

      // Created with string_dup
      CORBA::string_free (m_nm);
      
      fa1->destroy (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      CORBA::release (fa1);
      CORBA::release (dp1);
      ftc1->destroy (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      CORBA::release (ftc1);
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "test_dynunion::run_test");
      return -1;
    }
  ACE_ENDTRY;

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

  return 0;
}