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
|
// -*- c++ -*-
// $Id$
// ============================================================================
//
// = LIBRARY
// TAO/tests/DynAny_Test
//
// = FILENAME
// test_dynany.cpp
//
// = DESCRIPTION
// Implementation of the basic test for simple DynAnys
//
// = AUTHOR
// Jeff Parsons <parsons@cs.wustl.edu>
//
// ============================================================================
#include "test_dynany.h"
#include "data.h"
#include "tao/DynamicAny/DynamicAny.h"
Test_DynAny::Test_DynAny (CORBA::ORB_var orb)
: orb_ (orb),
test_name_ (CORBA::string_dup ("test_dynany")),
error_count_ (0)
{
}
Test_DynAny::~Test_DynAny (void)
{
CORBA::string_free (this->test_name_);
this->test_name_ = 0;
}
const char*
Test_DynAny::test_name (void) const
{
return this->test_name_;
}
int
Test_DynAny::run_test (void)
{
Data data (this->orb_);
ACE_TRY_NEW_ENV
{
ACE_DEBUG ((LM_DEBUG,
"\t*=*=*=*= %s =*=*=*=*\n",
data.labels[8]));
ACE_DEBUG ((LM_DEBUG,
"testing: constructor(Any)/insert/get\n"));
CORBA::Object_var factory_obj =
this->orb_->resolve_initial_references ("DynAnyFactory",
ACE_TRY_ENV);
ACE_TRY_CHECK;
DynamicAny::DynAnyFactory_var dynany_factory =
DynamicAny::DynAnyFactory::_narrow (factory_obj.in (),
ACE_TRY_ENV);
ACE_TRY_CHECK;
if (CORBA::is_nil (dynany_factory.in ()))
{
ACE_ERROR_RETURN ((LM_ERROR,
"Nil dynamic any factory after narrow\n"),
-1);
}
CORBA::Any in1 (CORBA::_tc_double);
DynamicAny::DynAny_var fa1 =
dynany_factory->create_dyn_any (in1, ACE_TRY_ENV);
ACE_TRY_CHECK;
fa1->insert_double (data.m_double1,
ACE_TRY_ENV);
ACE_TRY_CHECK;
CORBA::Double d_out = fa1->get_double (ACE_TRY_ENV);
ACE_TRY_CHECK;
if (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,
ACE_TRY_ENV);
ACE_TRY_CHECK;
CORBA::Any in_any1;
in_any1 <<= data.m_double1;
ftc1->from_any (in_any1,
ACE_TRY_ENV);
ACE_TRY_CHECK;
CORBA::Any_var out_any1 = ftc1->to_any (ACE_TRY_ENV);
ACE_TRY_CHECK;
out_any1 >>= d_out;
if (d_out == data.m_double1)
{
ACE_DEBUG ((LM_DEBUG,
"++ OK ++\n"));
}
else
{
++this->error_count_;
}
fa1->destroy (ACE_TRY_ENV);
ACE_TRY_CHECK;
ftc1->destroy (ACE_TRY_ENV);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG,
"\t*=*=*=*= %s =*=*=*=*\n",
data.labels[12]));
ACE_DEBUG ((LM_DEBUG,
"testing: constructor(Any)/insert/get\n"));
CORBA_Any in (CORBA::_tc_TypeCode);
DynamicAny::DynAny_var fa2 =
dynany_factory->create_dyn_any (in,
ACE_TRY_ENV);
ACE_TRY_CHECK;
fa2->insert_typecode (data.m_typecode1,
ACE_TRY_ENV);
ACE_TRY_CHECK;
CORBA::TypeCode_var tc_out = fa2->get_typecode (ACE_TRY_ENV);
ACE_TRY_CHECK;
if (tc_out->equal (data.m_typecode1,
ACE_TRY_ENV))
{
ACE_DEBUG ((LM_DEBUG,
"++ OK ++\n"));
}
else
{
++this->error_count_;
}
ACE_TRY_CHECK;
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,
ACE_TRY_ENV);
ACE_TRY_CHECK;
CORBA::Any in_any2;
in_any2 <<= data.m_typecode1;
ftc2->from_any (in_any2,
ACE_TRY_ENV);
ACE_TRY_CHECK;
CORBA::Any_var out_any2 = ftc2->to_any (ACE_TRY_ENV);
ACE_TRY_CHECK;
CORBA::TypeCode_ptr out_tc;
out_any2 >>= out_tc;
CORBA::Boolean equal = out_tc->equal (data.m_typecode1,
ACE_TRY_ENV);
ACE_TRY_CHECK;
if (equal)
{
ACE_DEBUG ((LM_DEBUG,
"++ OK ++\n"));
}
else
{
++this->error_count_;
}
ACE_TRY_CHECK;
fa2->destroy (ACE_TRY_ENV);
ACE_TRY_CHECK;
ftc2->destroy (ACE_TRY_ENV);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"test_dynany::run_test");
return -1;
}
ACE_ENDTRY;
ACE_DEBUG ((LM_DEBUG,
"\n%d errors\n",
this->error_count_));
return 0;
}
|