1 package org.jacorb.test.orb.value; 2 3 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 33 public class ValueTest extends ClientServerTestCase 34 { 35 private ValueServer server; 36 37 public ValueTest(String name, ClientServerSetup setup) 38 { 39 super(name, setup); 40 } 41 42 public void setUp() throws Exception 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 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 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 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 result = server.receive_long(p1, p1); 96 assertEquals("shared long: 441", result); 97 } 98 99 104 public void test_pass_equal_boxed_long() 105 { 106 boxedLong p1 = new boxedLong(443); 107 boxedLong p2 = new boxedLong(443); 108 String 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 s1 = "hello"; 115 String s2 = "g'day"; 116 String 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 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 s1 = "hello, world"; 129 String result = server.receive_string(s1, s1); 130 assertEquals("shared string: `hello, world'", result); 131 } 132 133 138 public void test_pass_equal_boxed_string() 139 { 140 String s1 = "hello, world"; 141 String s2 = new String (s1); 142 String 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 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 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 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 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 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 result = server.receive_list(n1); 255 assertEquals("list of length: 4 -- 1 2 3 4 -- shared", result); 256 } 257 } 258 | Popular Tags |