2 //=============================================================================
6 * We test the pragma prefixes generated in pragma.idl, and
7 * the values of some generated constants in constants.idl.
9 * @author Jeff Parsons <parsons@cs.wustl.edu>
11 //=============================================================================
16 #include "repo_id_modC.h"
17 #include "constantsC.h"
18 #include "nested_scopeS.h"
20 #include "expressionsC.h"
22 #include "ace/Log_Msg.h"
23 #include "ace/OS_NS_string.h"
24 #include "tao/AnyTypeCode/Any.h"
26 class hello_i
: public virtual POA_hello
30 class goodbye_i
: public virtual POA_goodbye
34 class sayonara_i
: public virtual POA_salutation::sayonara
38 class ciao_i
: public virtual POA_ciao
42 class aloha_i
: public virtual POA_aloha
46 class schmooze_i
: public virtual gleep::schmooze
50 class schmeer_i
: public virtual gleep::schmeer
54 class schlemiel_i
: public virtual gleep::schlemiel
58 class spilkis_i
: public virtual gleep::spilkis
62 class schmuck_i
: public virtual gleep::floop::schmuck
66 class schmendrick_i
: public virtual gleep::floop::schmendrick
70 class schlemazel_i
: public virtual gleep::floop::verklempt::schlemazel
74 class schmegegging_i
: public virtual gleep::schmegegging
78 struct something_handler
79 : public POA_bug_1985_c::d::AMI_somethingHandler
83 template <typename Type
>
85 expect_equals (int &error_count
, const char *name
, Type actual
, Type expected
)
87 if (actual
!= expected
)
89 *ACE_DEFAULT_LOG_STREAM
90 << "ERROR: For " << name
<< " expected: " << expected
91 << ", but got " << actual
<< "\n";
97 test_expressions (int &error_count
)
99 expect_equals
<CORBA::Short
> (error_count
, "ShortValues::a", ShortValues::a
, 6);
100 expect_equals
<CORBA::Short
> (error_count
, "ShortValues::b", ShortValues::b
, 3);
101 expect_equals
<CORBA::Short
> (error_count
, "ShortValues::div", ShortValues::div
, 2);
102 expect_equals
<CORBA::Short
> (error_count
, "ShortValues::mul", ShortValues::mul
, 18);
103 expect_equals
<CORBA::Short
> (error_count
, "ShortValues::add", ShortValues::add
, 9);
104 expect_equals
<CORBA::Short
> (error_count
, "ShortValues::sub", ShortValues::sub
, 3);
105 expect_equals
<CORBA::Short
> (error_count
, "ShortValues::mod", ShortValues::mod
, 0);
107 expect_equals
<CORBA::Long
> (error_count
, "LongValues::a", LongValues::a
, 6);
108 expect_equals
<CORBA::Long
> (error_count
, "LongValues::b", LongValues::b
, 3);
109 expect_equals
<CORBA::Long
> (error_count
, "LongValues::div", LongValues::div
, 2);
110 expect_equals
<CORBA::Long
> (error_count
, "LongValues::mul", LongValues::mul
, 18);
111 expect_equals
<CORBA::Long
> (error_count
, "LongValues::add", LongValues::add
, 9);
112 expect_equals
<CORBA::Long
> (error_count
, "LongValues::sub", LongValues::sub
, 3);
113 expect_equals
<CORBA::Long
> (error_count
, "LongValues::mod", LongValues::mod
, 0);
115 expect_equals
<CORBA::Long
> (error_count
, "MixedIntValues::div", MixedIntValues::div
, 2);
116 expect_equals
<CORBA::Long
> (error_count
, "MixedIntValues::mul", MixedIntValues::mul
, 18);
117 expect_equals
<CORBA::Long
> (error_count
, "MixedIntValues::add", MixedIntValues::add
, 9);
118 expect_equals
<CORBA::Long
> (error_count
, "MixedIntValues::sub", MixedIntValues::sub
, 3);
119 expect_equals
<CORBA::Long
> (error_count
, "MixedIntValues::mod", MixedIntValues::mod
, 0);
121 expect_equals
<CORBA::Float
> (error_count
, "FloatValues::a", FloatValues::a
, 6.0f
);
122 expect_equals
<CORBA::Float
> (error_count
, "FloatValues::b", FloatValues::b
, 3.0f
);
123 expect_equals
<CORBA::Float
> (error_count
, "FloatValues::div", FloatValues::div
, 2.0f
);
124 expect_equals
<CORBA::Float
> (error_count
, "FloatValues::mul", FloatValues::mul
, 18.0f
);
125 expect_equals
<CORBA::Float
> (error_count
, "FloatValues::add", FloatValues::add
, 9.0f
);
126 expect_equals
<CORBA::Float
> (error_count
, "FloatValues::sub", FloatValues::sub
, 3.0f
);
128 expect_equals
<CORBA::Double
> (error_count
, "DoubleValues::a", DoubleValues::a
, 6.0);
129 expect_equals
<CORBA::Double
> (error_count
, "DoubleValues::b", DoubleValues::b
, 3.0);
130 expect_equals
<CORBA::Double
> (error_count
, "DoubleValues::div", DoubleValues::div
, 2.0);
131 expect_equals
<CORBA::Double
> (error_count
, "DoubleValues::mul", DoubleValues::mul
, 18.0);
132 expect_equals
<CORBA::Double
> (error_count
, "DoubleValues::add", DoubleValues::add
, 9.0);
133 expect_equals
<CORBA::Double
> (error_count
, "DoubleValues::sub", DoubleValues::sub
, 3.0);
135 expect_equals
<CORBA::Double
> (error_count
, "MixedFloatValues::div", MixedFloatValues::div
, 2.0);
136 expect_equals
<CORBA::Double
> (error_count
, "MixedFloatValues::mul", MixedFloatValues::mul
, 18.0);
137 expect_equals
<CORBA::Double
> (error_count
, "MixedFloatValues::add", MixedFloatValues::add
, 9.0);
138 expect_equals
<CORBA::Double
> (error_count
, "MixedFloatValues::sub", MixedFloatValues::sub
, 3.0);
142 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
146 const ACE_CDR::ULongLong test_ull
=
147 ACE_UINT64_LITERAL (122192928000000000);
152 ACE_ERROR ((LM_ERROR
,
153 ACE_TEXT ("Generated value of unsigned")
154 ACE_TEXT (" long long AAA in constants.idl")
155 ACE_TEXT (" is incorrect\n")));
158 const CORBA::LongLong test_nll
= ACE_INT64_LITERAL (-122192928000000000);
160 if (test_nll
!= NAAA
)
163 ACE_ERROR ((LM_ERROR
,
164 ACE_TEXT ("Generated value of signed")
165 ACE_TEXT (" long long NAAA in constants.idl")
166 ACE_TEXT (" is incorrect\n")));
169 const CORBA::LongLong test_pll
= ACE_INT64_LITERAL (122192928000000000);
171 if (test_pll
!= PAAA
)
174 ACE_ERROR ((LM_ERROR
,
175 ACE_TEXT ("Generated value of signed")
176 ACE_TEXT (" long long PAAA in constants.idl")
177 ACE_TEXT (" is incorrect\n")));
182 CORBA::ORB_var orb
= CORBA::ORB_init (argc
,
185 CORBA::Object_var poa_object
=
186 orb
->resolve_initial_references ("RootPOA");
188 PortableServer::POA_var root_poa
=
189 PortableServer::POA::_narrow (poa_object
.in ());
191 // Test of #pragma prefix behavior.
193 CORBA::Object_var obj
;
196 PortableServer::ObjectId_var id
= root_poa
->activate_object (&h
);
197 obj
= root_poa
->id_to_reference (id
.in ());
198 obj
= hello::_narrow (obj
.in ());
200 if (ACE_OS::strcmp (obj
->_interface_repository_id (),
201 "IDL:anvil.com/hello:1.0"))
204 ACE_ERROR ((LM_ERROR
,
205 "pragma prefix error in object 'hello'\n"));
209 id
= root_poa
->activate_object (&g
);
210 obj
= root_poa
->id_to_reference (id
.in ());
211 obj
= goodbye::_narrow (obj
.in ());
213 if (ACE_OS::strcmp (obj
->_interface_repository_id (),
214 "IDL:anvil.com/goodbye:1.0"))
217 ACE_ERROR ((LM_ERROR
,
218 "pragma prefix error in object 'goodbye'\n"));
222 id
= root_poa
->activate_object (&s
);
223 obj
= root_poa
->id_to_reference (id
.in ());
224 obj
= salutation::sayonara::_narrow (obj
.in ());
226 if (ACE_OS::strcmp (obj
->_interface_repository_id (),
227 "IDL:hammer.com/salutation/sayonara:1.0"))
230 ACE_ERROR ((LM_ERROR
,
231 "pragma prefix error in object 'sayonara'\n"));
234 // Check whether the implementation of Dubble and Toil are generated
235 CommaList::Dubble dub
;
241 id
= root_poa
->activate_object (&c
);
242 obj
= root_poa
->id_to_reference (id
.in ());
243 obj
= ciao::_narrow (obj
.in ());
245 if (ACE_OS::strcmp (obj
->_interface_repository_id (),
246 "IDL:anvil.com/ciao:1.0"))
249 ACE_ERROR ((LM_ERROR
,
250 "pragma prefix error in object 'ciao'\n"));
254 id
= root_poa
->activate_object (&a
);
255 obj
= root_poa
->id_to_reference (id
.in ());
256 obj
= aloha::_narrow (obj
.in ());
258 if (ACE_OS::strcmp (obj
->_interface_repository_id (),
259 "IDL:anvil.com/aloha:1.0"))
262 ACE_ERROR ((LM_ERROR
,
263 "pragma prefix error in object 'aloha'\n"));
266 // Test of typeprefix, typeid, and #pragma version behavior.
268 schmooze_i s_schmooze
;
270 if (ACE_OS::strcmp (s_schmooze
._interface_repository_id (),
271 "IDL:gleep_prefix/gleep/schmooze:1.0"))
274 ACE_ERROR ((LM_ERROR
,
275 "pragma prefix error in object 'schmooze'\n"));
280 if (ACE_OS::strcmp (s_schmeer
._interface_repository_id (),
281 "IDL:gleep_prefix/gleep/schmeer:1.0"))
284 ACE_ERROR ((LM_ERROR
,
285 "pragma prefix error in object 'schmeer'\n"));
288 schlemiel_i s_schlemiel
;
290 if (ACE_OS::strcmp (s_schlemiel
._interface_repository_id (),
291 "IDL:gleep_prefix/gleep/schlemiel:1.0"))
294 ACE_ERROR ((LM_ERROR
,
295 "pragma prefix error in object 'schlemiel'\n"));
300 if (ACE_OS::strcmp (s_spilkis
._interface_repository_id (),
301 "IDL:gleep_prefix/gleep/spilkis:1.0"))
304 ACE_ERROR ((LM_ERROR
,
305 "pragma prefix error in object 'spilkis'\n"));
310 if (ACE_OS::strcmp (s_schmuck
._interface_repository_id (),
311 "ABRA:cadabra/hocus/pocus:1.23"))
314 ACE_ERROR ((LM_ERROR
,
315 "pragma prefix error in object 'schmuck'\n"));
318 schmendrick_i s_schmendrick
;
320 if (ACE_OS::strcmp (s_schmendrick
._interface_repository_id (),
321 "IDL:floop_prefix/gleep/floop/schmendrick:524.23"))
324 ACE_ERROR ((LM_ERROR
,
325 "pragma prefix error in object 'schmendrick'\n"));
327 if (ACE_OS::strcmp (gleep::floop::schmendrick::_desc_repository_id (),
328 "IDL:floop_prefix/gleep/floop/schmendrick:524.23"))
331 ACE_ERROR ((LM_ERROR
,
332 "error in _desc_repository_id 'schmendrick'\n"));
334 if (ACE_OS::strcmp (gleep::floop::schmendrick::_desc_interface_name (),
338 ACE_ERROR ((LM_ERROR
,
339 "error in _desc_interface_name 'schmendrick'\n"));
342 schlemazel_i s_schlemazel
;
345 s_schlemazel
._interface_repository_id (),
346 "IDL:verklempt_prefix/gleep/floop/verklempt/schlemazel:1.0"
350 ACE_ERROR ((LM_ERROR
,
351 "pragma prefix error in object 'schlemazel'\n"));
354 schmegegging_i s_schmegegging
;
356 if (ACE_OS::strcmp (s_schmegegging
._interface_repository_id (),
357 "IDL:gleep_prefix/gleep/schmegegging:1.0"))
360 ACE_ERROR ((LM_ERROR
,
361 "pragma prefix error in object 'schmegegging'\n"));
366 char const * base
[] =
368 "IDL:bug_1985_c/d/AMI_somethingHandler:1.0",
369 "IDL:bug_1985_a/b/AMI_somethingHandler:1.0",
370 "IDL:omg.org/Messaging/ReplyHandler:1.0",
371 "IDL:omg.org/CORBA/Object:1.0"
374 for (size_t i
= 0; i
!= sizeof (base
)/sizeof (base
[0]); ++i
)
376 if (!x
._is_a (base
[i
]))
379 ACE_ERROR ((LM_ERROR
,
380 "something_handler::_is_a should return true for %C\n",
385 if (!dynamic_cast<POA_bug_1985_c::d::AMI_somethingHandler
*> (&x
))
388 ACE_ERROR ((LM_ERROR
,
389 "mismatch in downcast for %C\n",
393 if (!dynamic_cast<POA_bug_1985_a::b::AMI_somethingHandler
*> (&x
))
396 ACE_ERROR ((LM_ERROR
,
397 "mismatch in downcast for %C\n",
401 if (!dynamic_cast<POA_Messaging::ReplyHandler
*> (&x
))
404 ACE_ERROR ((LM_ERROR
,
405 "mismatch in downcast for %C\n",
410 // Testing (de)marshaling of IDL union values
411 // under duplicate and default case labels.
414 field
.value
.strValue (
415 CORBA::string_dup ("duplicate case label test string"));
416 field
.value
._d (FTYPE_VARCHAR
);
419 const Field
*outfield
= 0;
421 if ((any1
>>= outfield
) == 0)
424 ACE_ERROR ((LM_ERROR
,
425 "error in extraction of "
426 "duplicate case label value\n"));
429 const char *str
= outfield
->value
.strValue ();
431 if (ACE_OS::strcmp (str
, "duplicate case label test string") != 0)
434 ACE_ERROR ((LM_ERROR
,
435 "error - corruption of "
436 "duplicate case label value\n"));
439 field
.value
.defstr (CORBA::string_dup ("default case test string"));
442 if ((any1
>>= outfield
) == 0)
445 ACE_ERROR ((LM_ERROR
,
446 "error in extraction of "
447 "default case label value\n"));
450 str
= outfield
->value
.defstr ();
452 if (ACE_OS::strcmp (str
, "default case test string") != 0)
455 ACE_ERROR ((LM_ERROR
,
456 "error - corruption of "
457 "default case label value\n"));
460 if (SignedGen::val
!= -3)
463 ACE_ERROR ((LM_ERROR
,
464 "error - signed integer literal "
465 "generated as unsigned\n"));
468 root_poa
->destroy (true, true);
470 catch (const CORBA::Exception
& ex
)
472 ex
._tao_print_exception ("Unexpected exception in main");
476 test_expressions (error_count
);
478 return error_count
? 1 : 0;