KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > orb > value > ValueTest


1 package org.jacorb.test.orb.value;
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.*;
25
26 import org.jacorb.test.common.*;
27 import org.omg.CORBA.*;
28 import org.jacorb.test.*;
29
30 /**
31  * Tests IDL valuetypes, especially sharing and null values.
32  */

33 public class ValueTest extends ClientServerTestCase
34 {
35     private ValueServer server;
36
37     public ValueTest(String JavaDoc name, ClientServerSetup setup)
38     {
39         super(name, setup);
40     }
41
42     public void setUp() throws Exception JavaDoc
43     {
44         server = ValueServerHelper.narrow( setup.getServerObject() );
45     }
46
47     public static Test suite()
48     {
49         TestSuite suite = new TestSuite( "valuetype tests" );
50         ClientServerSetup setup =
51             new ClientServerSetup( suite,
52                                    "org.jacorb.test.orb.value.ValueServerImpl" );
53
54         suite.addTest(new ValueTest("test_pass_boxed_long", setup));
55         suite.addTest(new ValueTest("test_pass_null_boxed_long", setup));
56         suite.addTest(new ValueTest("test_pass_shared_boxed_long", setup));
57         suite.addTest(new ValueTest("test_pass_equal_boxed_long", setup));
58
59         suite.addTest(new ValueTest("test_pass_boxed_string", setup));
60         suite.addTest(new ValueTest("test_pass_null_boxed_string", setup));
61         suite.addTest(new ValueTest("test_pass_shared_boxed_string", setup));
62         suite.addTest(new ValueTest("test_pass_equal_boxed_string", setup));
63
64         suite.addTest(new ValueTest("test_pass_value_sequence_1", setup));
65         suite.addTest(new ValueTest("test_pass_value_sequence_2", setup));
66         suite.addTest(new ValueTest("test_pass_value_sequence_3", setup));
67         suite.addTest(new ValueTest("test_return_value_sequence", setup));
68
69         suite.addTest(new ValueTest("test_pass_list", setup));
70         suite.addTest(new ValueTest("test_pass_circular_list", setup));
71
72         // comment this in to test bug430
73
// suite.addTest(new ValueTest("test_pass_list_in_any", setup));
74

75         return setup;
76     }
77
78     public void test_pass_boxed_long()
79     {
80         boxedLong p1 = new boxedLong(774);
81         boxedLong p2 = new boxedLong(774);
82         String JavaDoc result = server.receive_long(p1, p2);
83         assertEquals("two longs: 774, 774", result);
84     }
85
86     public void test_pass_null_boxed_long()
87     {
88         String JavaDoc result = server.receive_long(null, null);
89         assertEquals("one or two null values", result);
90     }
91
92     public void test_pass_shared_boxed_long()
93     {
94         boxedLong p1 = new boxedLong(441);
95         String JavaDoc result = server.receive_long(p1, p1);
96         assertEquals("shared long: 441", result);
97     }
98
99     /**
100      * Passes two boxed longs that are equal but not shared. This makes
101      * sure that reference sharing is indeed determined based on identity,
102      * not equality. (See comments in bug 387 for discussion.)
103      */

104     public void test_pass_equal_boxed_long()
105     {
106         boxedLong p1 = new boxedLong(443);
107         boxedLong p2 = new boxedLong(443);
108         String JavaDoc result = server.receive_long(p1, p2);
109         assertEquals("two longs: 443, 443", result);
110     }
111
112     public void test_pass_boxed_string()
113     {
114         String JavaDoc s1 = "hello";
115         String JavaDoc s2 = "g'day";
116         String JavaDoc result = server.receive_string(s1, s2);
117         assertEquals("two strings: `hello', `g'day'", result);
118     }
119
120     public void test_pass_null_boxed_string()
121     {
122         String JavaDoc result = server.receive_string(null, null);
123         assertEquals("one or two null values", result);
124     }
125
126     public void test_pass_shared_boxed_string()
127     {
128         String JavaDoc s1 = "hello, world";
129         String JavaDoc result = server.receive_string(s1, s1);
130         assertEquals("shared string: `hello, world'", result);
131     }
132
133     /**
134      * Passes two boxed strings that are equal but not shared. This makes
135      * sure that reference sharing is indeed determined based on identity,
136      * not equality. (See comments in bug 387 for discussion.)
137      */

138     public void test_pass_equal_boxed_string()
139     {
140         String JavaDoc s1 = "hello, world";
141         String JavaDoc s2 = new String JavaDoc(s1);
142         String JavaDoc result = server.receive_string(s1, s2);
143         assertEquals("two strings: `hello, world', `hello, world'", result);
144     }
145
146     public void test_pass_value_sequence_1()
147     {
148         Record[] seq = new Record[7];
149         seq[0] = new RecordImpl(0, "node: 0");
150         seq[1] = new RecordImpl(1, "node: 1");
151         seq[2] = new RecordImpl(2, "node: 2");
152         seq[3] = new RecordImpl(3, "node: 3");
153         seq[4] = new RecordImpl(4, "node: 4");
154         seq[5] = new RecordImpl(5, "node: 5");
155         seq[6] = new RecordImpl(6, "node: 6");
156
157         String JavaDoc result = server.receive_record_sequence(seq);
158         assertEquals("list of length 7, null values: , no palindrome", result);
159     }
160
161     public void test_pass_value_sequence_2()
162     {
163         Record[] seq = new Record[7];
164         seq[0] = new RecordImpl(0, "node: 0");
165         seq[1] = new RecordImpl(1, "node: 1");
166         seq[2] = new RecordImpl(2, "node: 2");
167         seq[3] = null;
168         seq[4] = null;
169         seq[5] = new RecordImpl(5, "node: 5");
170         seq[6] = new RecordImpl(6, "node: 6");
171
172         String JavaDoc result = server.receive_record_sequence(seq);
173         assertEquals("list of length 7, null values: 3 4 , no palindrome",
174                      result);
175     }
176
177     public void test_pass_value_sequence_3()
178     {
179         Record[] seq = new Record[7];
180         seq[0] = new RecordImpl(0, "node: 0");
181         seq[1] = new RecordImpl(1, "node: 1");
182         seq[2] = new RecordImpl(2, "node: 2");
183         seq[3] = null;
184         seq[4] = seq[2];
185         seq[5] = seq[1];
186         seq[6] = seq[0];
187
188         String JavaDoc result = server.receive_record_sequence(seq);
189         assertEquals("list of length 7, null values: 3 , palindrome",
190                      result);
191     }
192
193     public void test_return_value_sequence()
194     {
195         Record[] result = server.return_record_sequence(10);
196         assertEquals(10, result.length);
197         for (int i=0; i<result.length; i++)
198         {
199             assertEquals(i, result[i].id);
200             assertEquals("node: " + i, result[i].text);
201         }
202     }
203
204     public void test_pass_list()
205     {
206         Node n1 = new NodeImpl(1);
207         Node n2 = new NodeImpl(2);
208         Node n3 = new NodeImpl(3);
209         Node n4 = new NodeImpl(4);
210
211         n1.next = n2;
212         n2.next = n3;
213         n3.next = n4;
214         n4.next = null;
215
216         String JavaDoc result = server.receive_list(n1);
217         assertEquals("list of length: 4 -- 1 2 3 4", result);
218     }
219
220     public void test_pass_list_in_any()
221     {
222         Node n1 = new NodeImpl(1);
223         Node n2 = new NodeImpl(2);
224         Node n3 = new NodeImpl(3);
225         Node n4 = new NodeImpl(4);
226
227         n1.next = n2;
228         n2.next = n3;
229         n3.next = n4;
230         n4.next = null;
231
232         Any any = setup.getClientOrb().create_any();
233
234         NodeHelper.insert(any, n1);
235
236         assertEquals(n1, NodeHelper.extract(any));
237
238         String JavaDoc result = server.receive_list_in_any(any);
239         assertEquals("list of length: 4 -- 1 2 3 4", result);
240     }
241
242     public void test_pass_circular_list()
243     {
244         Node n1 = new NodeImpl(1);
245         Node n2 = new NodeImpl(2);
246         Node n3 = new NodeImpl(3);
247         Node n4 = new NodeImpl(4);
248
249         n1.next = n2;
250         n2.next = n3;
251         n3.next = n4;
252         n4.next = n1;
253
254         String JavaDoc result = server.receive_list(n1);
255         assertEquals("list of length: 4 -- 1 2 3 4 -- shared", result);
256     }
257 }
258
Popular Tags