1 package org.jacorb.test.orb; 2 3 22 23 import junit.framework.*; 24 import org.omg.CORBA.ORB ; 25 import org.omg.CORBA.portable.InputStream ; 26 27 import java.io.IOException ; 28 29 import org.jacorb.test.common.*; 30 31 36 public class CDRIOTest extends JacORBTestCase 37 { 38 private ORB orb; 39 private org.omg.CORBA.portable.OutputStream os; 40 41 46 public CDRIOTest (String name) 47 { 48 super (name); 49 } 50 51 protected void setUp() throws Exception 52 { 53 super.setUp(); 54 orb = org.omg.CORBA.ORB.init( (String [])null, null ); 55 os = orb.create_output_stream(); 56 } 57 58 protected void tearDown() throws Exception 59 { 60 super.tearDown(); 61 orb.destroy(); 62 } 63 64 69 public static Test suite () 70 { 71 TestSuite suite = new JacORBTestSuite("CDRIO Test", 72 CDRIOTest.class); 73 74 suite.addTest(new CDRIOTest("testLong")); 75 suite.addTest(new CDRIOTest("testString")); 76 suite.addTest(new CDRIOTest("testWString")); 77 suite.addTest(new CDRIOTest("testBoolean")); 78 suite.addTest(new CDRIOTest("testShort")); 79 suite.addTest(new CDRIOTest("testReadString")); 80 suite.addTest(new CDRIOTest("testRead")); 81 suite.addTest(new CDRIOTest("testMultiple")); 82 83 return suite; 84 } 85 86 public void testLong () throws IOException 87 { 88 int pre = 123; 89 os.write_long(pre); 90 InputStream is = os.create_input_stream(); 91 assertTrue(is.available() > 0); 92 int post = is.read_long(); 93 assertEquals(pre, post); 94 } 95 96 public void testString() throws IOException 97 { 98 String pre = "abc"; 99 os.write_string(pre); 100 InputStream is = os.create_input_stream(); 101 assertTrue(is.available() > 0); 102 String post = is.read_string(); 103 assertEquals(pre, post); 104 } 105 106 public void testWString() throws IOException 107 { 108 String pre = "abc"; 109 os.write_wstring(pre); 110 InputStream is = os.create_input_stream(); 111 assertTrue(is.available() > 0); 112 String post = is.read_wstring(); 113 assertEquals(pre, post); 114 } 115 116 public void testBoolean() throws IOException 117 { 118 boolean pre = true; 119 os.write_boolean(pre); 120 InputStream is = os.create_input_stream(); 121 assertTrue(is.available() > 0); 122 boolean post = is.read_boolean(); 123 assertEquals(pre, post); 124 } 125 126 public void testShort() throws IOException 127 { 128 short pre = 234; 129 os.write_short(pre); 130 InputStream is = os.create_input_stream(); 131 assertTrue(is.available() > 0); 132 short post = is.read_short(); 133 assertEquals(pre, post); 134 } 135 136 public void testReadString() throws IOException 137 { 138 os.write_string("abcde"); 139 InputStream is = os.create_input_stream(); 140 141 assertTrue(is.available() > 0); 142 byte[] buf = new byte[is.available()]; 143 int readAmount = is.read(buf); 144 assertTrue(readAmount > 0); 145 146 os = orb.create_output_stream(); 147 os.write_octet_array(buf, 0, buf.length); 148 InputStream is2 = os.create_input_stream(); 149 assertEquals("abcde", is2.read_string()); 150 } 151 152 public void testRead() throws IOException 153 { 154 os.write_string("thing-one"); 155 os.write_long(123); 156 os.write_string("thing-two"); 157 158 InputStream is = os.create_input_stream(); 159 assertTrue(is.available() > 0); 160 assertEquals("thing-one", is.read_string()); 161 assertEquals(123, is.read_long()); 162 163 assertTrue(is.available() > 0); 164 byte[] buf = new byte[is.available()]; 165 int readAmount = is.read(buf); 166 assertTrue(readAmount > 0); 167 168 os = orb.create_output_stream(); 169 os.write_octet_array(buf, 0, buf.length); 170 InputStream is2 = os.create_input_stream(); 171 assertEquals("thing-two", is2.read_string()); 172 } 173 174 public void testMultiple() throws IOException 175 { 176 os.write_boolean(true); 177 os.write_char('a'); 178 os.write_double(1.234); 179 os.write_float(2.345f); 180 os.write_long(987); 181 os.write_longlong(876); 182 os.write_short((short)13); 183 os.write_string("hi"); 184 os.write_ulong(765); 185 os.write_ulonglong(567); 186 os.write_ushort((short)23); 187 os.write_wchar('b'); 188 os.write_wstring("bye"); 189 190 InputStream is = os.create_input_stream(); 191 assertTrue(is.available() > 0); 192 193 assertEquals(is.read_boolean(), true); 194 assertEquals(is.read_char(), 'a'); 195 assertEquals(is.read_double(), 1.234, 0.001); 196 assertEquals(is.read_float(), 2.345f, 0.001f); 197 assertEquals(is.read_long(), 987); 198 assertEquals(is.read_longlong(), 876); 199 assertEquals(is.read_short(), (short)13); 200 assertEquals(is.read_string(), "hi"); 201 assertEquals(is.read_ulong(), 765); 202 assertEquals(is.read_ulonglong(), 567); 203 assertEquals(is.read_ushort(), (short)23); 204 assertEquals(is.read_wchar(), 'b'); 205 assertEquals(is.read_wstring(), "bye"); 206 } 207 208 } 209 | Popular Tags |