1 #include "TruncatableC.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR
*ior
= ACE_TEXT ("file://test.ior");
15 #define VERIFY(Condition) \
21 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) client - Failure at line %l\n"))); \
26 parse_args (int argc
, ACE_TCHAR
*argv
[])
28 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("k:v"));
31 while ((c
= get_opts ()) != -1)
35 ior
= get_opts
.optarg
;
42 ACE_ERROR_RETURN ((LM_ERROR
,
49 // Indicates successful parsing of the command line
54 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
59 CORBA::ORB_init (argc
, argv
);
61 if (parse_args (argc
, argv
) != 0)
66 OBV_TruncatableTest::BaseValue_init
*base_factory
= 0;
67 ACE_NEW_RETURN (base_factory
,
68 OBV_TruncatableTest::BaseValue_init
,
71 orb
->register_value_factory (base_factory
->tao_repository_id (),
73 base_factory
->_remove_ref (); // release ownership
75 OBV_TruncatableTest::TValue1_init
*value1_factory
= 0;
76 ACE_NEW_RETURN (value1_factory
,
77 OBV_TruncatableTest::TValue1_init
,
80 orb
->register_value_factory (value1_factory
->tao_repository_id (),
82 value1_factory
->_remove_ref ();
84 OBV_TruncatableTest::TValue2_init
*value2_factory
= 0;
85 ACE_NEW_RETURN (value2_factory
,
86 OBV_TruncatableTest::TValue2_init
,
89 orb
->register_value_factory (value2_factory
->tao_repository_id (),
91 value2_factory
->_remove_ref ();
93 OBV_TruncatableTest::TValue3_init
*value3_factory
= 0;
94 ACE_NEW_RETURN (value3_factory
,
95 OBV_TruncatableTest::TValue3_init
,
98 orb
->register_value_factory (value3_factory
->tao_repository_id (),
100 value3_factory
->_remove_ref ();
102 OBV_TruncatableTest::TValue4_init
*value4_factory
= 0;
103 ACE_NEW_RETURN (value4_factory
,
104 OBV_TruncatableTest::TValue4_init
,
107 orb
->register_value_factory (value4_factory
->tao_repository_id (),
109 value4_factory
->_remove_ref ();
111 OBV_TruncatableTest::TValue5_init
*value5_factory
= 0;
112 ACE_NEW_RETURN (value5_factory
,
113 OBV_TruncatableTest::TValue5_init
,
116 orb
->register_value_factory (value5_factory
->tao_repository_id (),
118 value5_factory
->_remove_ref ();
120 OBV_TruncatableTest::NestedValue_init
*nested_value_factory
= 0;
121 ACE_NEW_RETURN (nested_value_factory
,
122 OBV_TruncatableTest::NestedValue_init
,
125 orb
->register_value_factory (nested_value_factory
->tao_repository_id (),
126 nested_value_factory
);
127 nested_value_factory
->_remove_ref ();
129 // Obtain reference to the object
130 CORBA::Object_var tmp
=
131 orb
->string_to_object(ior
);
133 OBV_TruncatableTest::Test_var test
=
134 OBV_TruncatableTest::Test::_narrow (tmp
.in ());
136 if (CORBA::is_nil (test
.in ()))
138 ACE_ERROR_RETURN ((LM_DEBUG
,
139 "Nil OBV_TruncatableTest::Test reference <%s>\n",
144 CORBA::String_var desc
;
145 { //isolate the scope of objects to avoid using wrong values
146 OBV_TruncatableTest::TValue1_var
v1 (new OBV_OBV_TruncatableTest::TValue1
);
150 OBV_TruncatableTest::BaseValue_var ov1
;
152 desc
= CORBA::string_dup ("A<-tB, truncate B to A");
154 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 1: %C: "),
158 test
->op1 ("case1", v1
.in (), ov1
.out (), desc
.inout ());
161 VERIFY (! ACE_OS::strcmp (desc
.in (),
162 "case1: A<-tB, truncate B to A"));
163 VERIFY (v1
->basic_data () == ov1
->basic_data ());
165 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%s\n"),
167 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
170 { //isolate the scope of objects to avoid using wrong values
171 OBV_TruncatableTest::TValue2_var
v2 (new OBV_OBV_TruncatableTest::TValue2
);
177 OBV_TruncatableTest::BaseValue_var ov2
;
178 desc
= CORBA::string_dup ("A<-tB<-tC, truncate C to A");
180 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 2: %C: "),
184 test
->op1 ("case2", v2
.in (), ov2
.out (), desc
.inout ());
186 VERIFY (! ACE_OS::strcmp (desc
.in (),
187 "case2: A<-tB<-tC, truncate C to A"));
188 VERIFY (v2
->basic_data () == ov2
->basic_data ());
190 ACE_DEBUG ((LM_DEBUG
,ACE_TEXT ("%s\n"),
192 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
194 OBV_TruncatableTest::TValue1_var otv1
;
195 desc
= CORBA::string_dup ("A<-tB<-tC, truncate C to B");
197 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("Case 3: %C: "),
201 test
->op2 (v2
.in (), "case3", otv1
.out (), desc
.inout ());
203 VERIFY (! ACE_OS::strcmp (desc
.in (),
204 "case3: A<-tB<-tC, truncate C to B"));
205 VERIFY (v2
->basic_data () == otv1
->basic_data ());
206 VERIFY (v2
->data1 () == otv1
->data1 ());
208 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%s\n"),
210 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
213 { //isolate the scope of objects to avoid using wrong values
214 OBV_TruncatableTest::TValue1_var
itv1b (new OBV_OBV_TruncatableTest::TValue1
);
216 itv1b
->basic_data(7);
218 OBV_TruncatableTest::TValue1_var otv1b
;
219 desc
= CORBA::string_dup ("A<-tB, truncatable but no truncation");
221 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 3b: %C: "),
225 test
->op2 (itv1b
.in (), "case3b", otv1b
.out (), desc
.inout ());
227 VERIFY (! ACE_OS::strcmp (desc
.in (),
228 "case3b: A<-tB, truncatable but no truncation"));
229 VERIFY (itv1b
->basic_data () == otv1b
->basic_data ());
230 VERIFY (itv1b
->data1 () == otv1b
->data1 ());
232 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%s\n"),
234 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
237 { //isolate the scope of objects to avoid using wrong values
238 OBV_TruncatableTest::TValue3_var
v3 (new OBV_OBV_TruncatableTest::TValue3
);
243 bool caught_expected_exception
= false;
246 OBV_TruncatableTest::BaseValue_var ov3
;
247 desc
= CORBA::string_dup
248 ("A<-tB<-C, try truncate C to A, MARSHAL exception");
250 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 4: %C: "),
252 test
->op1 ("case4", v3
.in (), ov3
.out (), desc
.inout ());
254 catch (const CORBA::MARSHAL
&)
257 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("passed\n")));
258 caught_expected_exception
= true;
261 if (!caught_expected_exception
)
265 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("faileded\n")));
267 } //end marshaling exception test.
269 { //isolate the scope of objects to avoid using wrong values
270 OBV_TruncatableTest::NestedValue_var
nv (new OBV_OBV_TruncatableTest::NestedValue
);
273 OBV_TruncatableTest::TValue5_var
v5 (new OBV_OBV_TruncatableTest::TValue5
);
278 v5
->str1 (CORBA::string_dup ("str1"));
281 v5
->str2 (CORBA::string_dup ("str2"));
283 OBV_TruncatableTest::BaseValue_var ov5
;
284 desc
= CORBA::string_dup
285 ("A<-tB<-tC, B & C have nested value type, truncate C to A");
287 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 5: %C: "),
290 test
->op1 ("case5", v5
.in (), ov5
.out (), desc
.inout ());
292 VERIFY (! ACE_OS::strcmp (desc
.in (),
293 "case5: A<-tB<-tC, B & C have nested value type, truncate C to A"));
294 VERIFY (v5
->basic_data () == ov5
->basic_data ());
296 ACE_DEBUG ((LM_DEBUG
,ACE_TEXT ("%s\n"),
298 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
300 OBV_TruncatableTest::TValue4_var otv4
;
301 desc
= CORBA::string_dup
302 ("A<-tB<-tC, B & C have nested value type, truncate C to B");
304 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 6: %C: "),
307 test
->op3 ("case6", v5
.in (), otv4
.out (), desc
.inout ());
309 VERIFY (! ACE_OS::strcmp (desc
.in (),
310 "case6: A<-tB<-tC, B & C have nested value type, truncate C to B"));
311 VERIFY (v5
->basic_data () == otv4
->basic_data ());
312 VERIFY (v5
->nv4 ()->data () == otv4
->nv4 ()->data ());
313 VERIFY (v5
->data4 () == otv4
->data4 ());
315 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%s\n"),
316 (pretest
== fail
) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
319 { //isolate the scope of objects to avoid using wrong values
320 OBV_TruncatableTest::TValue6_var
iv (new OBV_OBV_TruncatableTest::TValue6
);
323 OBV_TruncatableTest::BaseValue_var ov
;
325 desc
= CORBA::string_dup ("A<-tB, B has no data, truncate B to A");
327 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 7: %C: "),
330 test
->op1 ("case7", iv
.in (), ov
.out (), desc
.inout ());
332 VERIFY (! ACE_OS::strcmp (desc
.in (),
333 "case7: A<-tB, B has no data, truncate B to A"));
334 VERIFY (iv
->basic_data () == ov
->basic_data ());
336 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%s\n"),
338 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
341 { //isolate the scope of objects to avoid using wrong values
342 OBV_TruncatableTest::TValue1_var
v1 (new OBV_OBV_TruncatableTest::TValue1
);
346 OBV_TruncatableTest::TValue1_var
v4 (new OBV_OBV_TruncatableTest::TValue1
);
350 OBV_TruncatableTest::NestedValue_var
nv (new OBV_OBV_TruncatableTest::NestedValue
);
353 OBV_TruncatableTest::TValue4_var
v2 (new OBV_OBV_TruncatableTest::TValue4
);
359 OBV_TruncatableTest::TValue4_var
v3 (new OBV_OBV_TruncatableTest::TValue4
);
364 desc
= CORBA::string_dup
365 ("multiple IN truncatable valuetype parameters"
366 " and return truncatable valuetype");
368 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 8: %C: "),
371 OBV_TruncatableTest::BaseValue_var ov
372 = test
->op4 ("case8", v1
.in (), 5, v2
.in (), v3
.in (), v4
.in (), desc
.inout ());
374 VERIFY (! ACE_OS::strcmp (desc
.in (),
375 "case8: multiple IN truncatable valuetype parameters"
376 " and return truncatable valuetype"));
377 CORBA::ULong total
= 5 * (v1
->basic_data () + v2
->basic_data () +
378 v3
->basic_data () + v4
->basic_data ());
379 VERIFY (ov
->basic_data () == total
);
381 ACE_DEBUG ((LM_DEBUG
,ACE_TEXT ("%s\n"),
383 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
387 OBV_TruncatableTest::Extra1_var
v1 (new OBV_OBV_TruncatableTest::Extra1
);
392 OBV_TruncatableTest::TValue1_var ov1
;
394 desc
= CORBA::string_dup ("A<-tB, truncate unknown B to A");
396 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 9: %C: "),
400 test
->op2 (v1
.in (), "case9", ov1
.out (), desc
.inout ());
402 VERIFY (! ACE_OS::strcmp (desc
.in (),
403 "case9: A<-tB, truncate unknown B to A"));
404 VERIFY (v1
->basic_data () == ov1
->basic_data ()
405 && v1
->data1() == ov1
->data1());
407 ACE_DEBUG ((LM_DEBUG
,ACE_TEXT ("%s\n"),
409 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
413 OBV_TruncatableTest::TValue1_var
v1 (new OBV_OBV_TruncatableTest::TValue1
);
417 OBV_TruncatableTest::TValue1_var ov1
;
420 desc
= CORBA::string_dup ("A<-tB, known truncatable via Any");
422 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 10: %C: "),
426 test
->op5 (a
, "case10", ov1
.out (), desc
.inout ());
428 VERIFY (! ACE_OS::strcmp (desc
.in (),
429 "case10: A<-tB, known truncatable via Any"));
430 VERIFY (v1
->basic_data () == ov1
->basic_data ()
431 && v1
->data1() == ov1
->data1());
433 ACE_DEBUG ((LM_DEBUG
,ACE_TEXT ("%s\n"),
435 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
439 OBV_TruncatableTest::Extra1_var
v1 (new OBV_OBV_TruncatableTest::Extra1
);
444 OBV_TruncatableTest::TValue1_var ov1
;
447 desc
= CORBA::string_dup ("A<-tB, unknown truncatable via Any");
449 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Case 11: %C: "),
453 test
->op5 (a
, "case11", ov1
.out (), desc
.inout ());
456 VERIFY (! ACE_OS::strcmp (desc
.in (),
457 "case11: A<-tB, unknown truncatable via Any"));
458 VERIFY (v1
->basic_data () == ov1
->basic_data ()
459 && v1
->data1() == ov1
->data1());
461 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%s\n"),
463 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
466 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - shutdown orb\n"));
474 ACE_ERROR ((LM_ERROR
, "(%P|%t) client: test failed\n"));
478 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client: test passed\n"));
480 catch (const CORBA::Exception
& ex
)
482 ex
._tao_print_exception ("Exception caught:");