KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > orb > dynany > DynAnyUnboundedSeqTest


1 package org.jacorb.test.orb.dynany;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2001 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import junit.framework.*;
24 import junit.extensions.TestSetup;
25 import org.omg.CORBA.TCKind JavaDoc;
26
27 import org.jacorb.test.common.ORBSetup;
28 import org.jacorb.test.UnboundedDataHelper;
29
30 /**
31  * DynAnyUnboundedSeqTest.java
32  *
33  * DynAny tests for (unbounded) sequence types.
34  *
35  */

36
37 public class DynAnyUnboundedSeqTest extends TestCase
38 {
39    private static org.omg.DynamicAny.DynAnyFactory JavaDoc factory = null;
40    private static org.omg.CORBA.ORB JavaDoc orb = null;
41
42    public DynAnyUnboundedSeqTest (String JavaDoc name)
43    {
44       super (name);
45    }
46
47
48    public static Test suite ()
49    {
50       TestSuite suite = new TestSuite ("Unbounded DynSequence Tests");
51       Setup setup = new Setup (suite);
52       ORBSetup osetup = new ORBSetup (setup);
53
54       suite.addTest (new DynAnyUnboundedSeqTest ("testFactoryCreateFromAny"));
55       suite.addTest (new DynAnyUnboundedSeqTest ("testFactoryCreateFromTypeCode"));
56       suite.addTest (new DynAnyUnboundedSeqTest ("testFactoryCreateFromIDLTypeCode"));
57       suite.addTest (new DynAnyUnboundedSeqTest ("testCompareDynAny"));
58       suite.addTest (new DynAnyUnboundedSeqTest ("testIterateDynAny"));
59       suite.addTest (new DynAnyUnboundedSeqTest ("testAccessSeqElements"));
60       suite.addTest (new DynAnyUnboundedSeqTest ("testAccessSeqDynAnyElements"));
61       suite.addTest (new DynAnyUnboundedSeqTest ("testAccessSeqElementsEx"));
62       suite.addTest (new DynAnyUnboundedSeqTest ("testDynAnyTypeCode"));
63       suite.addTest (new DynAnyUnboundedSeqTest ("testInitDynAnyFromDynAny"));
64       suite.addTest (new DynAnyUnboundedSeqTest ("testInitDynAnyFromAny"));
65       suite.addTest (new DynAnyUnboundedSeqTest ("testInitFromAnyTypeMismatchEx"));
66       suite.addTest (new DynAnyUnboundedSeqTest ("testGenerateAnyFromDynAny"));
67       suite.addTest (new DynAnyUnboundedSeqTest ("testDestroyDynAny"));
68       suite.addTest (new DynAnyUnboundedSeqTest ("testDestroyComponent"));
69       suite.addTest (new DynAnyUnboundedSeqTest ("testCopyDynAny"));
70
71       return osetup;
72    }
73
74
75    /**
76     * Tests creating a DynAny object from an Any object using the
77     * DynAnyFactory object.
78     */

79    public void testFactoryCreateFromAny ()
80    {
81       int [] type = null;
82       org.omg.CORBA.Any JavaDoc any = null;
83
84       type = getIntSeq (10);
85       any = orb.create_any ();
86       UnboundedDataHelper.insert (any, type);
87
88       createDynAnyFromAny (any);
89    }
90
91
92    /**
93     * Tests creating a DynAny object from a TypeCode object using the
94     * DynAnyFactory object.
95     */

96    public void testFactoryCreateFromTypeCode ()
97    {
98       org.omg.CORBA.TypeCode JavaDoc tc = null;
99
100       tc = orb.get_primitive_tc (TCKind.tk_long);
101       tc = orb.create_sequence_tc (0, tc);
102       createDynAnyFromTypeCode (tc);
103    }
104
105
106    /**
107     * Tests creating a DynAny object from a TypeCode object generated from
108     * IDL using the DynAnyFactory object.
109     */

110    public void testFactoryCreateFromIDLTypeCode ()
111    {
112       org.omg.CORBA.TypeCode JavaDoc tc = null;
113
114       tc = UnboundedDataHelper.type ();
115       createDynAnyFromTypeCode (tc);
116    }
117
118
119    /**
120     * Test comparing DynAny values.
121     */

122    public void testCompareDynAny ()
123    {
124       String JavaDoc msg;
125       int [] type;
126       org.omg.CORBA.Any JavaDoc any = null;
127       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
128       org.omg.DynamicAny.DynSequence JavaDoc dynAny2 = null;
129
130       type = getIntSeq (10);
131       any = orb.create_any ();
132       UnboundedDataHelper.insert (any, type);
133       dynAny = createDynAnyFromAny (any);
134       dynAny2 = createDynAnyFromAny (any);
135
136       msg = "Comparing two equal DynAny values using DynAny::equal failed";
137       assertTrue (msg, dynAny.equal (dynAny2));
138    }
139
140
141    /**
142     * Test iterating through components of a DynAny.
143     */

144    public void testIterateDynAny ()
145    {
146       String JavaDoc msg;
147       int [] type;
148       int compCount = -1;
149       int len = 10;
150       boolean seek;
151       org.omg.CORBA.Any JavaDoc any = null;
152       org.omg.CORBA.TypeCode JavaDoc tc = null;
153       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
154       org.omg.DynamicAny.DynAny JavaDoc compSeek = null;
155       org.omg.DynamicAny.DynAny JavaDoc compRewind = null;
156
157       type = getIntSeq (len);
158       any = orb.create_any ();
159       UnboundedDataHelper.insert (any, type);
160       dynAny = createDynAnyFromAny (any);
161
162       // test the component count
163
msg = "The number of components returned from the ";
164       msg += "DynAny::component_count method is incorrect";
165       try
166       {
167          compCount = dynAny.component_count ();
168       }
169       catch (Throwable JavaDoc ex)
170       {
171          // should not be needed, but it prevents compiler errors
172
fail ("Unexpected error raised by DynAny::component_count operation");
173       }
174       assertEquals (msg, len, compCount);
175
176       // seek an invalid position
177
msg = "The DynAny::seek operation indicates a valid current position ";
178       msg += "when the current position should be invalid";
179       seek = dynAny.seek (-1);
180       assertTrue (msg, !seek);
181
182       // seek the first position
183
msg = "The DynAny::seek operation indicates an invalid current position ";
184       msg += "when the current position should be valid";
185       seek = dynAny.seek (0);
186       assertTrue (msg, seek);
187
188       // extract a value from the current position
189
try
190       {
191          compSeek = dynAny.current_component ();
192       }
193       catch (Throwable JavaDoc ex)
194       {
195          msg = "Failed to get the current component using the ";
196          msg += "DynAny::current_component operation after calling the ";
197          msg += "DynAny::seek operation";
198          fail (msg + ": " + ex);
199       }
200
201       // seek the next position
202
msg = "The DynAny::next operation indicates an invalid current position ";
203       msg += "when the current position should be valid";
204       seek = dynAny.next ();
205       assertTrue (msg, seek);
206
207       // return to the first position
208
dynAny.rewind ();
209
210       // extract a value from the current position
211
try
212       {
213          compRewind = dynAny.current_component ();
214       }
215       catch (Throwable JavaDoc ex)
216       {
217          msg = "Failed to get the current component using the ";
218          msg += "DynAny::current_component operation after calling the ";
219          msg += "DynAny::rewind operation";
220          fail (msg + ": " + ex);
221       }
222       msg = "The component at DynAny::seek(0) is not equal to the ";
223       msg += "component at DynAny::rewind";
224       assertTrue (msg, compSeek.equal (compRewind));
225    }
226
227
228    /**
229     * Test accessing the elements in a DynSequence object.
230     */

231    public void testAccessSeqElements ()
232    {
233       String JavaDoc msg;
234       int len;
235       int newLen;
236       int curVal;
237       boolean next;
238       org.omg.CORBA.TypeCode JavaDoc tc = null;
239       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
240       org.omg.CORBA.Any JavaDoc [] anys = null;
241
242       tc = UnboundedDataHelper.type ();
243       dynAny = createDynAnyFromTypeCode (tc);
244
245       // test the default length is correct
246
msg = "The default length of DynSequence created from a TypeCode is ";
247       msg += "incorrect";
248       len = dynAny.get_length ();
249       assertEquals (msg, 0, len);
250
251       // test setting the elements
252
len = 5;
253       anys = new org.omg.CORBA.Any JavaDoc [len];
254       for (int i = 0; i < len; i++)
255       {
256          anys [i] = orb.create_any ();
257          anys [i].insert_long (i);
258       }
259
260       try
261       {
262          dynAny.set_elements (anys);
263       }
264       catch (Throwable JavaDoc ex)
265       {
266          msg = "Failed to set the elements using the DynSequence:set_elements ";
267          msg += "operation";
268          fail (msg + ": " + ex);
269       }
270
271       // test increasing the length
272
newLen = 10;
273       try
274       {
275          dynAny.set_length (newLen);
276       }
277       catch (Throwable JavaDoc ex)
278       {
279          msg = "Failed to set the length of the sequence using ";
280          msg += "DynSequence::set_length operation";
281          fail (msg + ": " + ex);
282       }
283
284       for (int i = 0; i < newLen; i++)
285       {
286          msg = "Failed to get the correct value of the DynSequence at ";
287          msg += "position " + i;
288          curVal = -1;
289          try
290          {
291             curVal = dynAny.get_long ();
292          }
293          catch (Throwable JavaDoc ex)
294          {
295             fail (msg + ": " + ex);
296          }
297
298          if (i < len)
299          {
300             assertEquals (msg, i, curVal);
301          }
302          else
303          {
304             assertEquals (msg, 0, curVal);
305          }
306          dynAny.next ();
307       }
308
309       // test decreasing the length
310
newLen = 1;
311       try
312       {
313          dynAny.set_length (newLen);
314       }
315       catch (Throwable JavaDoc ex)
316       {
317          msg = "Failed to set the length of the sequence using ";
318          msg += "DynSequence::set_length operation";
319          fail (msg + ": " + ex);
320       }
321       anys = dynAny.get_elements ();
322       msg = "The wrong number of elements were returned from the ";
323       msg += "DynSequence::get_elements operation";
324       assertEquals (msg, newLen, anys.length);
325
326       msg = "Failed to get the correct value of a DynSequence";
327       curVal = anys [0].extract_long ();
328       assertEquals (msg, 0, curVal);
329    }
330
331
332    /**
333     * Test accessing the elements in a DynSequence object as DynAnys.
334     */

335    public void testAccessSeqDynAnyElements ()
336    {
337       String JavaDoc msg;
338       int len;
339       int newLen;
340       int curVal;
341       boolean next;
342       org.omg.CORBA.TypeCode JavaDoc tc = null;
343       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
344       org.omg.DynamicAny.DynAny JavaDoc [] dynAnys = null;
345
346       tc = UnboundedDataHelper.type ();
347       dynAny = createDynAnyFromTypeCode (tc);
348
349       // test the default length is correct
350
msg = "The default length of DynSequence created from a TypeCode is ";
351       msg += "incorrect";
352       len = dynAny.get_length ();
353       assertEquals (msg, 0, len);
354
355       // test setting the elements
356
len = 5;
357       dynAnys = new org.omg.DynamicAny.DynAny JavaDoc [len];
358       tc = orb.get_primitive_tc (TCKind.tk_long);
359       for (int i = 0; i < len; i++)
360       {
361          try
362          {
363             dynAnys [i] = factory.create_dyn_any_from_type_code (tc);
364          }
365          catch (Throwable JavaDoc ex)
366          {
367             fail ("Failed to create a DynAny at position " + i + ": " + ex);
368          }
369
370          try
371          {
372             dynAnys [i].insert_long (i);
373          }
374          catch (Throwable JavaDoc ex)
375          {
376             msg = "Failed to insert a value into a DynAny at position " + i;
377             msg += ": " + ex;
378             fail (msg);
379          }
380       }
381
382       try
383       {
384          dynAny.set_elements_as_dyn_any (dynAnys);
385       }
386       catch (Throwable JavaDoc ex)
387       {
388          msg = "Failed to set the elements using the ";
389          msg += "DynSequence:set_elements_as_dyn_any operation";
390          fail (msg + ": " + ex);
391       }
392
393       // test increasing the length
394
newLen = 10;
395       try
396       {
397          dynAny.set_length (newLen);
398       }
399       catch (Throwable JavaDoc ex)
400       {
401          msg = "Failed to set the length of the sequence using ";
402          msg += "DynSequence::set_length operation";
403          fail (msg + ": " + ex);
404       }
405
406       for (int i = 0; i < newLen; i++)
407       {
408          msg = "Failed to get the correct value of the DynSequence at ";
409          msg += "position " + i;
410          curVal = -1;
411          try
412          {
413             curVal = dynAny.get_long ();
414          }
415          catch (Throwable JavaDoc ex)
416          {
417             fail (msg + ": " + ex);
418          }
419
420          if (i < len)
421          {
422             assertEquals (msg, i, curVal);
423          }
424          else
425          {
426             assertEquals (msg, 0, curVal);
427          }
428          dynAny.next ();
429       }
430
431       // test decreasing the length
432
newLen = 1;
433       try
434       {
435          dynAny.set_length (newLen);
436       }
437       catch (Throwable JavaDoc ex)
438       {
439          msg = "Failed to set the length of the sequence using ";
440          msg += "DynSequence::set_length operation";
441          fail (msg + ": " + ex);
442       }
443       dynAnys = dynAny.get_elements_as_dyn_any ();
444
445       msg = "The wrong number of elements were returned from the ";
446       msg += "DynSequence::get_elements_as_dyn_any operation";
447       assertEquals (msg, newLen, dynAnys.length);
448
449       msg = "Failed to get the correct value of a DynSequence";
450       curVal = -1;
451       try
452       {
453          curVal = dynAnys [0].get_long ();
454       }
455       catch (Throwable JavaDoc ex)
456       {
457          fail (msg + ": " + ex);
458       }
459       assertEquals (msg, 0, curVal);
460    }
461
462
463    /**
464     * Test that the correct exceptions are raised when accessing the elements
465     * in a DynSequence object incorrectly.
466     */

467    public void testAccessSeqElementsEx ()
468    {
469       String JavaDoc msg;
470       org.omg.CORBA.TypeCode JavaDoc tc = null;
471       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
472       org.omg.CORBA.Any JavaDoc [] anys = null;
473
474       tc = UnboundedDataHelper.type ();
475       dynAny = createDynAnyFromTypeCode (tc);
476
477       // test setting the elements with components of an invalid type
478
anys = new org.omg.CORBA.Any JavaDoc [1];
479       anys [0] = orb.create_any ();
480       anys [0].insert_string ("BadType");
481
482       msg = "Failed to raise a TypeMismatch exception when setting a ";
483       msg += "DynSequence object with components of the wrong type using ";
484       msg += "DynSequence::set_elements";
485       try
486       {
487          dynAny.set_elements (anys);
488
489          fail (msg);
490       }
491       catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc ex)
492       {
493          // success
494
}
495       catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc ex)
496       {
497          fail (msg + ": " + ex);
498       }
499    }
500
501
502    /**
503     * Test obtaining the TypeCode associated with a DynAny object.
504     */

505    public void testDynAnyTypeCode ()
506    {
507       String JavaDoc msg;
508       org.omg.CORBA.TypeCode JavaDoc tc = null;
509       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
510
511       tc = orb.get_primitive_tc (TCKind.tk_long);
512       tc = orb.create_sequence_tc (0, tc);
513       dynAny = createDynAnyFromTypeCode (tc);
514
515       msg = "Incorrect TypeCode retrieved from DynAny::type operation";
516       assertTrue (msg, dynAny.type ().equal (tc));
517    }
518
519
520    /**
521     * Test initializing a DynAny object from another DynAny object.
522     */

523    public void testInitDynAnyFromDynAny ()
524    {
525       String JavaDoc msg;
526       int [] type;
527       org.omg.CORBA.Any JavaDoc any = null;
528       org.omg.CORBA.TypeCode JavaDoc tc = null;
529       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
530       org.omg.DynamicAny.DynSequence JavaDoc dynAny2 = null;
531
532       tc = UnboundedDataHelper.type ();
533       dynAny = createDynAnyFromTypeCode (tc);
534
535       type = getIntSeq (10);
536       any = orb.create_any ();
537       UnboundedDataHelper.insert (any, type);
538       dynAny2 = createDynAnyFromAny (any);
539
540       msg = "Failed to initialize a DynAny object from another DynAny ";
541       msg += "object using the DynAny::assign operation";
542       try
543       {
544          dynAny.assign (dynAny2);
545       }
546       catch (Throwable JavaDoc ex)
547       {
548          fail (msg + ": " + ex);
549       }
550       assertTrue (msg, dynAny.equal (dynAny2));
551    }
552
553
554    /**
555     * Test initializing a DynAny object from an Any value.
556     */

557    public void testInitDynAnyFromAny ()
558    {
559       String JavaDoc msg;
560       int [] type;
561       org.omg.CORBA.Any JavaDoc any = null;
562       org.omg.CORBA.TypeCode JavaDoc tc = null;
563       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
564       org.omg.DynamicAny.DynSequence JavaDoc dynAny2 = null;
565
566       tc = UnboundedDataHelper.type ();
567       dynAny = createDynAnyFromTypeCode (tc);
568
569       type = getIntSeq (10);
570       any = orb.create_any ();
571       UnboundedDataHelper.insert (any, type);
572       dynAny2 = createDynAnyFromAny (any);
573
574       msg = "Failed to initialize a DynAny object from an Any object ";
575       msg += "using the DynAny::from_any operation";
576       try
577       {
578          dynAny.from_any (any);
579       }
580       catch (Throwable JavaDoc ex)
581       {
582          fail (msg + ": " + ex);
583       }
584       assertTrue (msg, dynAny.equal (dynAny2));
585    }
586
587
588    /**
589     * Test that a TypeMismatch exception is raised if there is a type
590     * mismatch between the DynAny and Any types in an assignment.
591     */

592    public void testInitFromAnyTypeMismatchEx ()
593    {
594       String JavaDoc msg;
595       org.omg.CORBA.Any JavaDoc any = null;
596       org.omg.CORBA.TypeCode JavaDoc tc = null;
597       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
598
599       any = orb.create_any ();
600       any.insert_string ("Hello");
601
602       tc = orb.get_primitive_tc (TCKind.tk_long);
603       tc = orb.create_sequence_tc (0, tc);
604       dynAny = createDynAnyFromTypeCode (tc);
605
606       msg = "TypeMismatch exception not thrown by DynAny::from_any ";
607       msg += "operation when DynAny and Any operands have different types";
608       try
609       {
610          dynAny.from_any (any);
611
612          fail (msg);
613       }
614       catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc ex)
615       {
616          // success
617
}
618       catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc ex)
619       {
620          fail (msg + ": " + ex);
621       }
622    }
623
624
625    /**
626     * Test generating an Any value from a DynAny object.
627     */

628    public void testGenerateAnyFromDynAny ()
629    {
630       String JavaDoc msg;
631       org.omg.CORBA.Any JavaDoc any = null;
632       org.omg.CORBA.TypeCode JavaDoc tc = null;
633       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
634       org.omg.DynamicAny.DynSequence JavaDoc dynAny2 = null;
635
636       tc = UnboundedDataHelper.type ();
637       dynAny = createDynAnyFromTypeCode (tc);
638
639       any = orb.create_any ();
640       any = dynAny.to_any ();
641       dynAny2 = createDynAnyFromAny (any);
642
643       msg = "The DynAny::to_any operation failed to create an Any ";
644       msg += "object with the same value as the DynAny object";
645       assertTrue (msg, dynAny.equal (dynAny2));
646    }
647
648
649    /**
650     * Test destroying a DynAny object.
651     */

652    public void testDestroyDynAny ()
653    {
654       String JavaDoc msg;
655       int [] type;
656       org.omg.CORBA.Any JavaDoc any = null;
657       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
658
659       type = getIntSeq (10);
660       any = orb.create_any ();
661       UnboundedDataHelper.insert (any, type);
662       dynAny = createDynAnyFromAny (any);
663       dynAny.destroy ();
664
665       try
666       {
667          dynAny.type ();
668
669          msg = "Failed to destroy DynAny using DynAny::destroy operation - ";
670          msg += "calling DynAny::type operation on a destroyed DynAny object ";
671          msg += "did not raise OBJECT_NOT_EXIST exception";
672          fail (msg);
673       }
674       catch (org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc ex)
675       {
676          // success
677
}
678
679       msg = "Failed to destroy DynAny using DynAny::destroy operation - ";
680       msg += "calling DynAny::current_component operation on a destroyed ";
681       msg += "DynAny object did not raise OBJECT_NOT_EXIST exception";
682       try
683       {
684          dynAny.current_component ();
685
686          fail (msg);
687       }
688       catch (org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc ex)
689       {
690          // success
691
}
692       catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc ex)
693       {
694          fail (msg + ": " + ex);
695       }
696    }
697
698
699    /**
700     * Test destroying a component of a DynAny object.
701     */

702    public void testDestroyComponent ()
703    {
704       String JavaDoc msg;
705       int [] type;
706       org.omg.CORBA.Any JavaDoc any = null;
707       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
708       org.omg.DynamicAny.DynAny JavaDoc comp = null;
709
710       type = getIntSeq (10);
711       any = orb.create_any ();
712       UnboundedDataHelper.insert (any, type);
713       dynAny = createDynAnyFromAny (any);
714
715       try
716       {
717          comp = dynAny.current_component ();
718       }
719       catch (Throwable JavaDoc ex)
720       {
721          msg = "Failed to get the current component of the DynAny using the ";
722          msg += "DynAny::current_component operation before calling the ";
723          msg += "DynAny::destroy operation";
724          fail (msg + ": " + ex);
725       }
726
727       comp.destroy ();
728       try
729       {
730          comp = dynAny.current_component ();
731       }
732       catch (Throwable JavaDoc ex)
733       {
734          msg = "Failed to get the current component of the DynAny using the ";
735          msg += "DynAny::current_component operation after calling the ";
736          msg += "DynAny::destroy operation";
737          fail (msg + ": " + ex);
738       }
739
740       try
741       {
742          comp.type ();
743       }
744       catch (org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc ex)
745       {
746          msg = "Calling destroy on a component resulted in destroying the ";
747          msg += "component object";
748          fail (msg + ": " + ex);
749       }
750    }
751
752
753    /**
754     * Test creating a copy of a DynAny object.
755     */

756    public void testCopyDynAny ()
757    {
758       String JavaDoc msg;
759       org.omg.CORBA.TypeCode JavaDoc tc = null;
760       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
761       org.omg.DynamicAny.DynSequence JavaDoc dynAny2 = null;
762
763       tc = UnboundedDataHelper.type ();
764       dynAny = createDynAnyFromTypeCode (tc);
765       dynAny2 = (org.omg.DynamicAny.DynSequence JavaDoc) dynAny.copy ();
766
767       msg = "The DynAny object created with the DynAny::copy operation ";
768       msg += "is not equal to the DynAny object it was copied from";
769       assertTrue (msg, dynAny.equal (dynAny2));
770    }
771
772
773    private static class Setup extends TestSetup
774    {
775       public Setup (Test test)
776       {
777          super (test);
778       }
779
780       protected void setUp ()
781       {
782          org.omg.CORBA.Object JavaDoc obj = null;
783
784          orb = ORBSetup.getORB ();
785          try
786          {
787             obj = orb.resolve_initial_references ("DynAnyFactory");
788          }
789          catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc ex)
790          {
791             fail ("Failed to resolve DynAnyFactory: " + ex);
792          }
793          try
794          {
795             factory = org.omg.DynamicAny.DynAnyFactoryHelper.narrow (obj);
796          }
797          catch (Throwable JavaDoc ex)
798          {
799             fail ("Failed to narrow to DynAnyFactory: " + ex);
800          }
801       }
802
803       protected void tearDown ()
804       {
805       }
806    }
807
808
809    /**
810     * Create a DynAny object from an Any object.
811     */

812    private static org.omg.DynamicAny.DynSequence JavaDoc createDynAnyFromAny
813       (org.omg.CORBA.Any JavaDoc any)
814    {
815       String JavaDoc msg;
816       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
817
818       try
819       {
820          dynAny = (org.omg.DynamicAny.DynSequence JavaDoc) factory.create_dyn_any (any);
821       }
822       catch (Throwable JavaDoc ex)
823       {
824          msg = "Factory failed to create DynAny from Any using ";
825          msg += "DynAny::create_dyn_any operation: " + ex;
826          fail (msg);
827       }
828       return dynAny;
829    }
830
831
832    /**
833     * Create a DynAny object from a TypeCode object.
834     */

835    private static org.omg.DynamicAny.DynSequence JavaDoc createDynAnyFromTypeCode
836       (org.omg.CORBA.TypeCode JavaDoc tc)
837    {
838       String JavaDoc msg;
839       org.omg.DynamicAny.DynSequence JavaDoc dynAny = null;
840
841       try
842       {
843          dynAny = (org.omg.DynamicAny.DynSequence JavaDoc)
844             factory.create_dyn_any_from_type_code (tc);
845       }
846       catch (Throwable JavaDoc ex)
847       {
848          msg = "Factory failed to create DynAny from TypeCode using ";
849          msg += "DynAny::create_dyn_any_from_type_code operation: " + ex;
850          fail (msg);
851       }
852       return dynAny;
853    }
854
855
856    /**
857     * Create a sequence (array) of integers of the specified length.
858     */

859    private static int [] getIntSeq (int length)
860    {
861       int [] type = new int [length];
862       for (int i = 0; i < length; i++)
863       {
864          type [i] = i;
865       }
866       return type;
867    }
868
869 }
870
Popular Tags