KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > bugs > bug272 > TestCase


1 package org.jacorb.test.bugs.bug272;
2
3 import junit.framework.*;
4
5 import org.omg.CORBA.*;
6
7 /**
8  * Test for bug 272, byte array in Any.
9  *
10  * @author Andre Spiegel
11  * @version $Id: TestCase.java,v 1.2 2003/10/27 12:14:15 andre.spiegel Exp $
12  */

13 public class TestCase extends junit.framework.TestCase
14 {
15     public TestCase (String JavaDoc name)
16     {
17         super (name);
18     }
19     
20     public static Test suite()
21     {
22         TestSuite suite = new TestSuite ("bug 272 byte array in Any");
23         
24         suite.addTest (new TestCase ("test_Any_byte_array_1"));
25         suite.addTest (new TestCase ("test_Any_byte_array_3999"));
26         suite.addTest (new TestCase ("test_Any_byte_array_4000"));
27         suite.addTest (new TestCase ("test_Any_byte_array_4001"));
28         suite.addTest (new TestCase ("test_Any_byte_array_40123"));
29
30         return suite;
31     }
32     
33     /**
34      * Puts a byte array of length 1 into an Any.
35      * (Regression test for bug #272)
36      */

37     public void test_Any_byte_array_1()
38     {
39         do_Any_byte_array (1);
40     }
41
42     /**
43      * Puts a byte array of length 3999 into an Any,
44      * which is one less than the deferred write limit.
45      * (Regression test for bug #272)
46      */

47     public void test_Any_byte_array_3999()
48     {
49         do_Any_byte_array (3999);
50     }
51
52     /**
53      * Puts a byte array of length 4000 into an Any,
54      * which is the deferred write limit.
55      * (Regression test for bug #272)
56      */

57     public void test_Any_byte_array_4000()
58     {
59         do_Any_byte_array (4000);
60     }
61
62     /**
63      * Puts a byte array of length 4001 into an Any,
64      * which is one beyond the deferred write limit.
65      * (Regression test for bug #272)
66      */

67     public void test_Any_byte_array_4001()
68     {
69         do_Any_byte_array (4001);
70     }
71
72     /**
73      * Puts a byte array of length 40123 into an Any,
74      * which is way beyond the deferred write limit.
75      * (Regression test for bug #272)
76      */

77     public void test_Any_byte_array_40123()
78     {
79         do_Any_byte_array (40123);
80     }
81
82     private void do_Any_byte_array (int length)
83     {
84         ORB orb = ORB.init();
85         Any a = orb.create_any();
86         
87         byte[] b = new byte[length];
88         for (int i=0; i<b.length; i++) b[i] = (byte)(i % 256);
89         
90         OctetSeqHelper.insert( a, b );
91         
92         byte[] result = OctetSeqHelper.extract( a );
93         
94         assertTrue ( "arrays are the same", b != result);
95         assertEquals( "wrong length of resulting array: ", b.length, result.length );
96             
97         for (int i=0; i<result.length; i++)
98             assertEquals( "wrong array element at index " + i, b[i], result[i] );
99     }
100
101 }
102
Popular Tags