1 package org.jacorb.test.orb; 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 import org.jacorb.test.CharServerPackage.wcharSeqHolder; 30 import org.jacorb.test.CharServerPackage.DataFlavour; 31 import org.jacorb.test.CharServerPackage.DataFlavourHelper; 32 import org.jacorb.test.CharServerPackage.NameValuePair; 33 34 35 public class CharTest extends ClientServerTestCase 36 { 37 private CharServer server; 38 39 private static final char E_ACUTE = '\u00e9'; private static final char EURO_SIGN = '\u20AC'; 43 public CharTest(String name, ClientServerSetup setup) 44 { 45 super(name, setup); 46 } 47 48 public void setUp() throws Exception 49 { 50 server = CharServerHelper.narrow( setup.getServerObject() ); 51 } 52 53 public static Test suite() 54 { 55 TestSuite suite = new TestSuite( "Client/server char tests" ); 56 ClientServerSetup setup = 57 new ClientServerSetup( suite, 58 "org.jacorb.test.orb.CharServerImpl" ); 59 60 suite.addTest( new CharTest( "test_pass_in_char", setup ) ); 61 suite.addTest( new CharTest( "test_pass_in_char_illegal", setup ) ); 62 suite.addTest( new CharTest( "test_pass_out_char", setup ) ); 63 suite.addTest( new CharTest( "test_pass_out_char_illegal", setup ) ); 64 suite.addTest( new CharTest( "test_pass_inout_char", setup ) ); 65 suite.addTest( new CharTest( "test_pass_inout_char_illegal", setup ) ); 66 suite.addTest( new CharTest( "test_return_char", setup ) ); 67 suite.addTest( new CharTest( "test_return_char_illegal", setup ) ); 68 suite.addTest( new CharTest( "test_bounce_char", setup ) ); 69 70 suite.addTest( new CharTest( "test_pass_in_wchar", setup ) ); 71 suite.addTest( new CharTest( "test_pass_out_wchar", setup ) ); 72 suite.addTest( new CharTest( "test_pass_inout_wchar", setup ) ); 73 suite.addTest( new CharTest( "test_return_wchar", setup ) ); 74 suite.addTest( new CharTest( "test_bounce_wchar", setup ) ); 75 76 suite.addTest( new CharTest( "test_wchar_seq", setup ) ); 77 suite.addTest( new CharTest( "test_return_dataflavour_inany", setup ) ); 78 79 return setup; 80 } 81 82 84 public void test_pass_in_char() 85 { 86 for (short c=0; c<255; c++) 87 { 88 short result = server.pass_in_char( (char)c ); 89 assertEquals( c, result ); 90 } 91 } 92 93 public void test_pass_in_char_illegal() 94 { 95 short result = -1; 96 try 97 { 98 result = server.pass_in_char( (char)256 ); 99 fail( "exception expected for (char)256" ); 100 } 101 catch( org.omg.CORBA.DATA_CONVERSION e ) { } 102 catch( Exception e ) 103 { 104 fail( "unexpected exception: " + e ); 105 } 106 107 try 108 { 109 result = server.pass_in_char( EURO_SIGN ); 110 fail( "exception expected for euro sign" ); 111 } 112 catch( org.omg.CORBA.DATA_CONVERSION e ) { } 113 catch( Exception e ) 114 { 115 fail( "unexpected exception: " + e ); 116 } 117 118 try 119 { 120 result = server.pass_in_char( (char)0xffff ); 121 fail( "exception expected for (char)0xffff" ); 122 } 123 catch( org.omg.CORBA.DATA_CONVERSION e ) { } 124 catch( Exception e ) 125 { 126 fail( "unexpected exception: " + e ); 127 } 128 } 129 130 public void test_pass_out_char() 131 { 132 CharHolder x = new CharHolder ( 'a' ); 133 server.pass_out_char( (short)'c', x ); 134 assertEquals( 'c', x.value ); 135 136 server.pass_out_char( (short)E_ACUTE, x ); 137 assertEquals( E_ACUTE, x.value ); 138 } 139 140 public void test_pass_out_char_illegal() 141 { 142 CharHolder x = new CharHolder ( 'a' ); 143 try 144 { 145 server.pass_out_char( (short)EURO_SIGN, x ); 146 fail( "exception expected for euro sign" ); 147 } 148 catch( org.omg.CORBA.DATA_CONVERSION e ) { } 149 catch( Exception e ) 150 { 151 fail( "unexpected exception: " + e ); 152 } 153 154 try 155 { 156 server.pass_out_char( (short)0x8fff, x ); 157 fail( "exception expected for (char)0x8fff" ); 158 } 159 catch( org.omg.CORBA.DATA_CONVERSION e ) { } 160 catch( Exception e ) 161 { 162 fail( "unexpected exception: " + e ); 163 } 164 } 165 166 public void test_pass_inout_char() 167 { 168 CharHolder x = new CharHolder( 'a' ); 169 server.pass_inout_char( x ); 170 assertEquals( 'A', x.value ); 171 172 x.value = E_ACUTE; 173 server.pass_inout_char( x ); 174 assertEquals( '\u00c9', x.value ); 176 } 177 178 public void test_pass_inout_char_illegal() 179 { 180 CharHolder x = new CharHolder( EURO_SIGN ); 181 try 182 { 183 server.pass_inout_char( x ); 184 fail( "exception expected for euro sign" ); 185 } 186 catch( org.omg.CORBA.DATA_CONVERSION e ) { } 187 catch( Exception e ) 188 { 189 fail( "unexpected exception: " + e ); 190 } 191 } 192 193 public void test_return_char() 194 { 195 for (short c = 0; c < 255; c++) 196 { 197 char result = server.return_char( c ); 198 assertEquals( (char)c, result ); 199 } 200 } 201 202 public void test_return_char_illegal() 203 { 204 try 205 { 206 char result = server.return_char( (short)EURO_SIGN ); 207 fail( "exception expected for euro sign" ); 208 } 209 catch( org.omg.CORBA.DATA_CONVERSION e ) { } 210 catch( Exception e ) 211 { 212 fail( "unexpected exception: " + e ); 213 } 214 215 } 216 217 public void test_bounce_char() 218 { 219 char result = server.bounce_char( 'a' ); 220 assertEquals( 'a', result ); 221 } 222 223 225 public void test_pass_in_wchar() 226 { 227 short result = server.pass_in_wchar( 'a' ); 228 assertEquals( (short)'a', result ); 229 230 result = server.pass_in_wchar( E_ACUTE ); 231 assertEquals( (short)E_ACUTE, result ); 232 233 result = server.pass_in_wchar( EURO_SIGN ); 234 assertEquals( (short)EURO_SIGN, result ); 235 236 result = server.pass_in_wchar( '\uA000' ); 237 assertEquals( (short)0xA000, result ); 238 } 239 240 public void test_pass_out_wchar() 241 { 242 CharHolder x = new CharHolder( 'a' ); 243 server.pass_out_wchar( (short)'s', x ); 244 assertEquals( 's', x.value ); 245 246 server.pass_out_wchar( (short)E_ACUTE, x ); 247 assertEquals( E_ACUTE, x.value ); 248 249 server.pass_out_wchar( (short)EURO_SIGN, x ); 250 assertEquals( EURO_SIGN, x.value ); 251 252 server.pass_out_wchar( (short)0xA000, x ); 253 assertEquals( '\uA000', x.value ); 254 } 255 256 public void test_pass_inout_wchar() 257 { 258 CharHolder x = new CharHolder( E_ACUTE ); 259 server.pass_inout_wchar( x ); 260 assertEquals ( '\u00c9', x.value ); } 262 263 public void test_return_wchar() 264 { 265 char result = server.return_wchar( (short)'a' ); 266 assertEquals( 'a', result ); 267 268 result = server.return_wchar( (short)E_ACUTE ); 269 assertEquals( E_ACUTE, result ); 270 271 result = server.return_wchar( (short)EURO_SIGN ); 272 assertEquals( EURO_SIGN, result ); 273 274 result = server.return_wchar( (short)0xA000 ); 275 assertEquals( '\uA000', result ); 276 } 277 278 public void test_bounce_wchar() 279 { 280 char result = server.bounce_wchar( EURO_SIGN ); 281 assertEquals( EURO_SIGN, result ); 282 } 283 284 public void test_wchar_seq() 285 { 286 try 287 { 288 wcharSeqHolder argout = new wcharSeqHolder(); 289 wcharSeqHolder arginout = new wcharSeqHolder( new char[]{ 'a', 'a' } ); 290 wcharSeqHolder argin = new wcharSeqHolder( new char[]{ 'a', 'a' } ); 291 292 for( int i = 0; i < 1000; i++ ) 293 { 294 test( server.test_wchar_seq( new char[]{ 'a', 'a' }, 296 argout, 297 arginout )); 298 299 test( argout.value); 300 } 301 } 302 catch( Exception e ) 303 { 304 fail( "unexpected exception: " + e ); 305 } 306 } 307 308 309 public void test_return_dataflavour_inany() 310 { 311 try 312 { 313 DataFlavour flavour = new DataFlavour 314 ("Test_Flavour", new NameValuePair[0]); 315 316 org.omg.CORBA.Any data = server.return_dataflavour_inany( flavour ); 317 318 DataFlavour flavour2 = DataFlavourHelper.extract( data ); 319 320 assertEquals( flavour2.name, "Test_Flavour" ); 321 } 322 catch( Exception e ) 323 { 324 fail( "unexpected exception: " + e ); 325 } 326 } 327 328 private static void test( char[] arg ) 329 { 330 assertEquals( arg[ 0 ], 'a' ); 331 assertEquals( arg[ 1 ], 'a' ); 332 } 333 } 334 | Popular Tags |