1/* GENERATED SOURCE. DO NOT MODIFY. */ 2/* 3 ******************************************************************************* 4 * Copyright (C) 2003-2010, International Business Machines Corporation and * 5 * others. All Rights Reserved. * 6 ******************************************************************************* 7*/ 8package android.icu.dev.test.stringprep; 9 10import android.icu.dev.test.TestFmwk; 11import android.icu.text.StringPrepParseException; 12import android.icu.text.UCharacterIterator; 13import org.junit.runner.RunWith; 14import android.icu.junit.IcuTestFmwkRunner; 15 16/** 17 * @author ram 18 * 19 * To change the template for this generated type comment go to 20 * Window>Preferences>Java>Code Generation>Code and Comments 21 */ 22@RunWith(IcuTestFmwkRunner.class) 23public class TestIDNARef extends TestFmwk { 24 public static void main(String[] args) throws Exception { 25 new TestIDNARef().run(args); 26 } 27 private StringPrepParseException unassignedException = new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR); 28 public void TestToUnicode() throws Exception{ 29 try{ 30 for(int i=0; i<TestData.asciiIn.length; i++){ 31 // test StringBuffer toUnicode 32 doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.DEFAULT, null); 33 doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.ALLOW_UNASSIGNED, null); 34 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES, null); 35 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES|IDNAReference.ALLOW_UNASSIGNED, null); 36 37 } 38 }catch(java.lang.ExceptionInInitializerError ex){ 39 warnln("Could not load NamePrepTransform data"); 40 }catch(java.lang.NoClassDefFoundError ex){ 41 warnln("Could not load NamePrepTransform data"); 42 } 43 } 44 45 public void TestToASCII() throws Exception{ 46 try{ 47 for(int i=0; i<TestData.asciiIn.length; i++){ 48 // test StringBuffer toUnicode 49 doTestToASCII(new String(TestData.unicodeIn[i]),TestData.asciiIn[i],IDNAReference.DEFAULT, null); 50 doTestToASCII(new String(TestData.unicodeIn[i]),TestData.asciiIn[i],IDNAReference.ALLOW_UNASSIGNED, null); 51 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES, null); 52 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES|IDNAReference.ALLOW_UNASSIGNED, null); 53 54 } 55 }catch(java.lang.ExceptionInInitializerError ex){ 56 warnln("Could not load NamePrepTransform data"); 57 }catch(java.lang.NoClassDefFoundError ex){ 58 warnln("Could not load NamePrepTransform data"); 59 } 60 } 61 62 public void TestIDNToASCII() throws Exception{ 63 try{ 64 for(int i=0; i<TestData.domainNames.length; i++){ 65 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.DEFAULT, null); 66 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED, null); 67 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.USE_STD3_RULES, null); 68 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null); 69 } 70 71 for(int i=0; i<TestData.domainNames1Uni.length; i++){ 72 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.DEFAULT, null); 73 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.ALLOW_UNASSIGNED, null); 74 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.USE_STD3_RULES, null); 75 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null); 76 77 } 78 }catch(java.lang.ExceptionInInitializerError ex){ 79 warnln("Could not load NamePrepTransform data"); 80 }catch(java.lang.NoClassDefFoundError ex){ 81 warnln("Could not load NamePrepTransform data"); 82 } 83 } 84 public void TestIDNToUnicode() throws Exception{ 85 try{ 86 for(int i=0; i<TestData.domainNames.length; i++){ 87 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.DEFAULT, null); 88 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED, null); 89 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.USE_STD3_RULES, null); 90 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null); 91 } 92 for(int i=0; i<TestData.domainNamesToASCIIOut.length; i++){ 93 doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],TestData.domainNamesToUnicodeOut[i],IDNAReference.DEFAULT, null); 94 doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],TestData.domainNamesToUnicodeOut[i],IDNAReference.ALLOW_UNASSIGNED, null); 95 } 96 }catch(java.lang.ExceptionInInitializerError ex){ 97 warnln("Could not load NamePrepTransform data"); 98 }catch(java.lang.NoClassDefFoundError ex){ 99 warnln("Could not load NamePrepTransform data"); 100 } 101 } 102 103 private void doTestToUnicode(String src, String expected, int options, Object expectedException) 104 throws Exception{ 105 106 if (!IDNAReference.isReady()) { 107 logln("Transliterator is not available on this environment. Skipping doTestToUnicode."); 108 return; 109 } 110 111 StringBuffer inBuf = new StringBuffer(src); 112 UCharacterIterator inIter = UCharacterIterator.getInstance(src); 113 try{ 114 115 StringBuffer out = IDNAReference.convertToUnicode(src,options); 116 if(expected!=null && out != null && !out.toString().equals(expected)){ 117 errln("convertToUnicode did not return expected result with options : "+ options + 118 " Expected: " + prettify(expected)+" Got: "+prettify(out)); 119 } 120 if(expectedException!=null && !unassignedException.equals(expectedException)){ 121 errln("convertToUnicode did not get the expected exception. The operation succeeded!"); 122 } 123 }catch(StringPrepParseException ex){ 124 if(expectedException == null || !ex.equals(expectedException)){ 125 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString()); 126 } 127 } 128 try{ 129 130 StringBuffer out = IDNAReference.convertToUnicode(inBuf,options); 131 if(expected!=null && out != null && !out.toString().equals(expected)){ 132 errln("convertToUnicode did not return expected result with options : "+ options + 133 " Expected: " + prettify(expected)+" Got: "+out); 134 } 135 if(expectedException!=null && !unassignedException.equals(expectedException)){ 136 errln("convertToUnicode did not get the expected exception. The operation succeeded!"); 137 } 138 }catch(StringPrepParseException ex){ 139 if(expectedException == null || !ex.equals(expectedException)){ 140 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString()); 141 } 142 } 143 144 try{ 145 StringBuffer out = IDNAReference.convertToUnicode(inIter,options); 146 if(expected!=null && out != null && !out.toString().equals(expected)){ 147 errln("convertToUnicode did not return expected result with options : "+ options + 148 " Expected: " + prettify(expected)+" Got: "+prettify(out)); 149 } 150 if(expectedException!=null && !unassignedException.equals(expectedException)){ 151 errln("Did not get the expected exception. The operation succeeded!"); 152 } 153 }catch(StringPrepParseException ex){ 154 if(expectedException == null || !ex.equals(expectedException)){ 155 errln("Did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString()); 156 } 157 } 158 } 159 160 private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException) 161 throws Exception{ 162 163 if (!IDNAReference.isReady()) { 164 logln("Transliterator is not available on this environment. Skipping doTestIDNToUnicode."); 165 return; 166 } 167 168 StringBuffer inBuf = new StringBuffer(src); 169 UCharacterIterator inIter = UCharacterIterator.getInstance(src); 170 try{ 171 172 StringBuffer out = IDNAReference.convertIDNToUnicode(src,options); 173 if(expected!=null && out != null && !out.toString().equals(expected)){ 174 errln("convertToUnicode did not return expected result with options : "+ options + 175 " Expected: " + prettify(expected)+" Got: "+prettify(out)); 176 } 177 if(expectedException!=null && !unassignedException.equals(expectedException)){ 178 errln("convertToUnicode did not get the expected exception. The operation succeeded!"); 179 } 180 }catch(StringPrepParseException ex){ 181 if(expectedException == null || !expectedException.equals(ex)){ 182 errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 183 } 184 } 185 try{ 186 StringBuffer out = IDNAReference.convertIDNToUnicode(inBuf,options); 187 if(expected!=null && out != null && !out.toString().equals(expected)){ 188 errln("convertToUnicode did not return expected result with options : "+ options + 189 " Expected: " + prettify(expected)+" Got: "+out); 190 } 191 if(expectedException!=null && !unassignedException.equals(expectedException)){ 192 errln("convertToUnicode did not get the expected exception. The operation succeeded!"); 193 } 194 }catch(StringPrepParseException ex){ 195 if(expectedException == null || !expectedException.equals(ex)){ 196 errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 197 } 198 } 199 200 try{ 201 StringBuffer out = IDNAReference.convertIDNToUnicode(inIter,options); 202 if(expected!=null && out != null && !out.toString().equals(expected)){ 203 errln("convertToUnicode did not return expected result with options : "+ options + 204 " Expected: " + prettify(expected)+" Got: "+prettify(out)); 205 } 206 if(expectedException!=null && !unassignedException.equals(expectedException)){ 207 errln("Did not get the expected exception. The operation succeeded!"); 208 } 209 }catch(StringPrepParseException ex){ 210 if(expectedException == null || !expectedException.equals(ex)){ 211 errln("Did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 212 } 213 } 214 } 215 private void doTestToASCII(String src, String expected, int options, Object expectedException) 216 throws Exception{ 217 218 if (!IDNAReference.isReady()) { 219 logln("Transliterator is not available on this environment. Skipping doTestToASCII."); 220 return; 221 } 222 223 StringBuffer inBuf = new StringBuffer(src); 224 UCharacterIterator inIter = UCharacterIterator.getInstance(src); 225 try{ 226 227 StringBuffer out = IDNAReference.convertToASCII(src,options); 228 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){ 229 errln("convertToASCII did not return expected result with options : "+ options + 230 " Expected: " + expected+" Got: "+out); 231 } 232 if(expectedException!=null && !unassignedException.equals(expectedException)){ 233 errln("convertToASCII did not get the expected exception. The operation succeeded!"); 234 } 235 }catch(StringPrepParseException ex){ 236 if(expectedException == null || !expectedException.equals(ex)){ 237 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 238 } 239 } 240 241 try{ 242 StringBuffer out = IDNAReference.convertToASCII(inBuf,options); 243 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){ 244 errln("convertToASCII did not return expected result with options : "+ options + 245 " Expected: " + expected+" Got: "+out); 246 } 247 if(expectedException!=null && !unassignedException.equals(expectedException)){ 248 errln("convertToASCII did not get the expected exception. The operation succeeded!"); 249 } 250 }catch(StringPrepParseException ex){ 251 if(expectedException == null || !expectedException.equals(ex)){ 252 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 253 } 254 } 255 256 try{ 257 StringBuffer out = IDNAReference.convertToASCII(inIter,options); 258 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){ 259 errln("convertToASCII did not return expected result with options : "+ options + 260 " Expected: " + expected+" Got: "+ out); 261 } 262 if(expectedException!=null && !unassignedException.equals(expectedException)){ 263 errln("convertToASCII did not get the expected exception. The operation succeeded!"); 264 } 265 }catch(StringPrepParseException ex){ 266 if(expectedException == null || !expectedException.equals(ex)){ 267 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 268 } 269 } 270 } 271 private void doTestIDNToASCII(String src, String expected, int options, Object expectedException) 272 throws Exception{ 273 274 if (!IDNAReference.isReady()) { 275 logln("Transliterator is not available on this environment. Skipping doTestIDNToASCII."); 276 return; 277 } 278 279 StringBuffer inBuf = new StringBuffer(src); 280 UCharacterIterator inIter = UCharacterIterator.getInstance(src); 281 try{ 282 283 StringBuffer out = IDNAReference.convertIDNToASCII(src,options); 284 if(expected!=null && out != null && !out.toString().equals(expected)){ 285 errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options + 286 " Expected: " + expected+" Got: "+out); 287 } 288 if(expectedException!=null && !unassignedException.equals(expectedException)){ 289 errln("convertToIDNAReferenceASCII did not get the expected exception. The operation succeeded!"); 290 } 291 }catch(StringPrepParseException ex){ 292 if(expectedException == null || !ex.equals(expectedException)){ 293 errln("convertToIDNAReferenceASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 294 } 295 } 296 try{ 297 StringBuffer out = IDNAReference.convertIDNtoASCII(inBuf,options); 298 if(expected!=null && out != null && !out.toString().equals(expected)){ 299 errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options + 300 " Expected: " + expected+" Got: "+out); 301 } 302 if(expectedException!=null && !unassignedException.equals(expectedException)){ 303 errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!"); 304 } 305 }catch(StringPrepParseException ex){ 306 if(expectedException == null || !ex.equals(expectedException)){ 307 errln("convertToIDNAReferenceSCII did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 308 } 309 } 310 311 try{ 312 StringBuffer out = IDNAReference.convertIDNtoASCII(inIter,options); 313 if(expected!=null && out != null && !out.toString().equals(expected)){ 314 errln("convertIDNToASCII did not return expected result with options : "+ options + 315 " Expected: " + expected+" Got: "+ out); 316 } 317 318 if(expectedException!=null && !unassignedException.equals(expectedException)){ 319 errln("convertIDNToASCII did not get the expected exception. The operation succeeded!"); 320 } 321 }catch(StringPrepParseException ex){ 322 if(expectedException == null || !ex.equals(expectedException)){ 323 errln("convertIDNToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString()); 324 } 325 } 326 } 327 public void TestConformance()throws Exception{ 328 try{ 329 for(int i=0; i<TestData.conformanceTestCases.length;i++){ 330 331 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i]; 332 if(testCase.expected != null){ 333 //Test toASCII 334 doTestToASCII(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected); 335 doTestToASCII(testCase.input,testCase.output,IDNAReference.ALLOW_UNASSIGNED,testCase.expected); 336 } 337 //Test toUnicode 338 //doTestToUnicode(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected); 339 } 340 }catch(java.lang.ExceptionInInitializerError ex){ 341 warnln("Could not load NamePrepTransform data"); 342 }catch(java.lang.NoClassDefFoundError ex){ 343 warnln("Could not load NamePrepTransform data"); 344 } 345 } 346 public void TestNamePrepConformance() throws Exception{ 347 try{ 348 NamePrepTransform namePrep = NamePrepTransform.getInstance(); 349 if (!namePrep.isReady()) { 350 logln("Transliterator is not available on this environment."); 351 return; 352 } 353 for(int i=0; i<TestData.conformanceTestCases.length;i++){ 354 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i]; 355 UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input); 356 try{ 357 StringBuffer output = namePrep.prepare(iter,NamePrepTransform.NONE); 358 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){ 359 errln("Did not get the expected output. Expected: " + prettify(testCase.output)+ 360 " Got: "+ prettify(output) ); 361 } 362 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){ 363 errln("Did not get the expected exception. The operation succeeded!"); 364 } 365 }catch(StringPrepParseException ex){ 366 if(testCase.expected == null || !ex.equals(testCase.expected)){ 367 errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString()); 368 } 369 } 370 371 try{ 372 iter.setToStart(); 373 StringBuffer output = namePrep.prepare(iter,NamePrepTransform.ALLOW_UNASSIGNED); 374 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){ 375 errln("Did not get the expected output. Expected: " + prettify(testCase.output)+ 376 " Got: "+ prettify(output) ); 377 } 378 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){ 379 errln("Did not get the expected exception. The operation succeeded!"); 380 } 381 }catch(StringPrepParseException ex){ 382 if(testCase.expected == null || !ex.equals(testCase.expected)){ 383 errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString()); 384 } 385 } 386 } 387 }catch(java.lang.ExceptionInInitializerError e){ 388 warnln("Could not load NamePrepTransformData"); 389 }catch(java.lang.NoClassDefFoundError ex){ 390 warnln("Could not load NamePrepTransform data"); 391 } 392 393 } 394 public void TestErrorCases() throws Exception{ 395 try{ 396 for(int i=0; i < TestData.errorCases.length; i++){ 397 TestData.ErrorCase errCase = TestData.errorCases[i]; 398 if(errCase.testLabel==true){ 399 // Test ToASCII 400 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.DEFAULT,errCase.expected); 401 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.ALLOW_UNASSIGNED,errCase.expected); 402 if(errCase.useSTD3ASCIIRules){ 403 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected); 404 } 405 } 406 if(errCase.useSTD3ASCIIRules!=true){ 407 408 // Test IDNToASCII 409 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.DEFAULT,errCase.expected); 410 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.ALLOW_UNASSIGNED,errCase.expected); 411 412 }else{ 413 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected); 414 } 415 416 //TestToUnicode 417 if(errCase.testToUnicode==true){ 418 if(errCase.useSTD3ASCIIRules!=true){ 419 // Test IDNToUnicode 420 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.DEFAULT,errCase.expected); 421 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.ALLOW_UNASSIGNED,errCase.expected); 422 423 }else{ 424 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.USE_STD3_RULES,errCase.expected); 425 } 426 } 427 } 428 }catch(java.lang.ExceptionInInitializerError ex){ 429 warnln("Could not load NamePrepTransform data"); 430 }catch(java.lang.NoClassDefFoundError ex){ 431 warnln("Could not load NamePrepTransform data"); 432 } 433 } 434 private void doTestCompare(String s1, String s2, boolean isEqual){ 435 436 if (!IDNAReference.isReady()) { 437 logln("Transliterator is not available on this environment. Skipping doTestCompare."); 438 return; 439 } 440 441 try{ 442 int retVal = IDNAReference.compare(s1,s2,IDNAReference.DEFAULT); 443 if(isEqual==true && retVal != 0){ 444 errln("Did not get the expected result for s1: "+ prettify(s1)+ 445 " s2: "+prettify(s2)); 446 } 447 retVal = IDNAReference.compare(new StringBuffer(s1), new StringBuffer(s2), IDNAReference.DEFAULT); 448 if(isEqual==true && retVal != 0){ 449 errln("Did not get the expected result for s1: "+ prettify(s1)+ 450 " s2: "+prettify(s2)); 451 } 452 retVal = IDNAReference.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNAReference.DEFAULT); 453 if(isEqual==true && retVal != 0){ 454 errln("Did not get the expected result for s1: "+ prettify(s1)+ 455 " s2: "+prettify(s2)); 456 } 457 }catch(Exception e){ 458 e.printStackTrace(); 459 errln("Unexpected exception thrown by IDNAReference.compare"); 460 } 461 462 try{ 463 int retVal = IDNAReference.compare(s1,s2,IDNAReference.ALLOW_UNASSIGNED); 464 if(isEqual==true && retVal != 0){ 465 errln("Did not get the expected result for s1: "+ prettify(s1)+ 466 " s2: "+prettify(s2)); 467 } 468 retVal = IDNAReference.compare(new StringBuffer(s1), new StringBuffer(s2), IDNAReference.ALLOW_UNASSIGNED); 469 if(isEqual==true && retVal != 0){ 470 errln("Did not get the expected result for s1: "+ prettify(s1)+ 471 " s2: "+prettify(s2)); 472 } 473 retVal = IDNAReference.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNAReference.ALLOW_UNASSIGNED); 474 if(isEqual==true && retVal != 0){ 475 errln("Did not get the expected result for s1: "+ prettify(s1)+ 476 " s2: "+prettify(s2)); 477 } 478 }catch(Exception e){ 479 errln("Unexpected exception thrown by IDNAReference.compare"); 480 } 481 } 482 public void TestCompare() throws Exception{ 483 String www = "www."; 484 String com = ".com"; 485 StringBuffer source = new StringBuffer(www); 486 StringBuffer uni0 = new StringBuffer(www); 487 StringBuffer uni1 = new StringBuffer(www); 488 StringBuffer ascii0 = new StringBuffer(www); 489 StringBuffer ascii1 = new StringBuffer(www); 490 491 uni0.append(TestData.unicodeIn[0]); 492 uni0.append(com); 493 494 uni1.append(TestData.unicodeIn[1]); 495 uni1.append(com); 496 497 ascii0.append(TestData.asciiIn[0]); 498 ascii0.append(com); 499 500 ascii1.append(TestData.asciiIn[1]); 501 ascii1.append(com); 502 try{ 503 for(int i=0;i< TestData.unicodeIn.length; i++){ 504 505 // for every entry in unicodeIn array 506 // prepend www. and append .com 507 source.setLength(4); 508 source.append(TestData.unicodeIn[i]); 509 source.append(com); 510 511 // a) compare it with itself 512 doTestCompare(source.toString(),source.toString(),true); 513 514 // b) compare it with asciiIn equivalent 515 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true); 516 517 // c) compare it with unicodeIn not equivalent 518 if(i==0){ 519 doTestCompare(source.toString(), uni1.toString(), false); 520 }else{ 521 doTestCompare(source.toString(),uni0.toString(), false); 522 } 523 // d) compare it with asciiIn not equivalent 524 if(i==0){ 525 doTestCompare(source.toString(),ascii1.toString(), false); 526 }else{ 527 doTestCompare(source.toString(),ascii0.toString(), false); 528 } 529 } 530 }catch(java.lang.ExceptionInInitializerError ex){ 531 warnln("Could not load NamePrepTransform data"); 532 }catch(java.lang.NoClassDefFoundError ex){ 533 warnln("Could not load NamePrepTransform data"); 534 } 535 } 536 537 // test and ascertain 538 // func(func(func(src))) == func(src) 539 public void doTestChainingToASCII(String source)throws Exception{ 540 541 if (!IDNAReference.isReady()) { 542 logln("Transliterator is not available on this environment. Skipping doTestChainingToASCII."); 543 return; 544 } 545 546 StringBuffer expected; 547 StringBuffer chained; 548 549 // test convertIDNToASCII 550 expected = IDNAReference.convertIDNToASCII(source,IDNAReference.DEFAULT); 551 chained = expected; 552 for(int i=0; i< 4; i++){ 553 chained = IDNAReference.convertIDNtoASCII(chained,IDNAReference.DEFAULT); 554 } 555 if(!expected.toString().equals(chained.toString())){ 556 errln("Chaining test failed for convertIDNToASCII"); 557 } 558 // test convertIDNToA 559 expected = IDNAReference.convertToASCII(source,IDNAReference.DEFAULT); 560 chained = expected; 561 for(int i=0; i< 4; i++){ 562 chained = IDNAReference.convertToASCII(chained,IDNAReference.DEFAULT); 563 } 564 if(!expected.toString().equals(chained.toString())){ 565 errln("Chaining test failed for convertToASCII"); 566 } 567 568 } 569 // test and ascertain 570 // func(func(func(src))) == func(src) 571 public void doTestChainingToUnicode(String source)throws Exception{ 572 573 if (!IDNAReference.isReady()) { 574 logln("Transliterator is not available on this environment. Skipping doTestChainingToUnicode."); 575 return; 576 } 577 578 StringBuffer expected; 579 StringBuffer chained; 580 581 // test convertIDNToUnicode 582 expected = IDNAReference.convertIDNToUnicode(source,IDNAReference.DEFAULT); 583 chained = expected; 584 for(int i=0; i< 4; i++){ 585 chained = IDNAReference.convertIDNToUnicode(chained,IDNAReference.DEFAULT); 586 } 587 if(!expected.toString().equals(chained.toString())){ 588 errln("Chaining test failed for convertIDNToUnicode"); 589 } 590 // test convertIDNToA 591 expected = IDNAReference.convertToUnicode(source,IDNAReference.DEFAULT); 592 chained = expected; 593 for(int i=0; i< 4; i++){ 594 chained = IDNAReference.convertToUnicode(chained,IDNAReference.DEFAULT); 595 } 596 if(!expected.toString().equals(chained.toString())){ 597 errln("Chaining test failed for convertToUnicode"); 598 } 599 600 } 601 public void TestChaining() throws Exception{ 602 try{ 603 for(int i=0; i< TestData.unicodeIn.length; i++){ 604 doTestChainingToASCII(new String(TestData.unicodeIn[i])); 605 } 606 for(int i=0; i< TestData.asciiIn.length; i++){ 607 doTestChainingToUnicode(TestData.asciiIn[i]); 608 } 609 }catch(java.lang.ExceptionInInitializerError ex){ 610 warnln("Could not load NamePrepTransform data"); 611 }catch(java.lang.NoClassDefFoundError ex){ 612 warnln("Could not load NamePrepTransform data"); 613 } 614 } 615 public void TestRootLabelSeparator() throws Exception{ 616 String www = "www."; 617 String com = ".com."; /*root label separator*/ 618 StringBuffer source = new StringBuffer(www); 619 StringBuffer uni0 = new StringBuffer(www); 620 StringBuffer uni1 = new StringBuffer(www); 621 StringBuffer ascii0 = new StringBuffer(www); 622 StringBuffer ascii1 = new StringBuffer(www); 623 624 uni0.append(TestData.unicodeIn[0]); 625 uni0.append(com); 626 627 uni1.append(TestData.unicodeIn[1]); 628 uni1.append(com); 629 630 ascii0.append(TestData.asciiIn[0]); 631 ascii0.append(com); 632 633 ascii1.append(TestData.asciiIn[1]); 634 ascii1.append(com); 635 try{ 636 for(int i=0;i< TestData.unicodeIn.length; i++){ 637 638 // for every entry in unicodeIn array 639 // prepend www. and append .com 640 source.setLength(4); 641 source.append(TestData.unicodeIn[i]); 642 source.append(com); 643 644 // a) compare it with itself 645 doTestCompare(source.toString(),source.toString(),true); 646 647 // b) compare it with asciiIn equivalent 648 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true); 649 650 // c) compare it with unicodeIn not equivalent 651 if(i==0){ 652 doTestCompare(source.toString(), uni1.toString(), false); 653 }else{ 654 doTestCompare(source.toString(),uni0.toString(), false); 655 } 656 // d) compare it with asciiIn not equivalent 657 if(i==0){ 658 doTestCompare(source.toString(),ascii1.toString(), false); 659 }else{ 660 doTestCompare(source.toString(),ascii0.toString(), false); 661 } 662 } 663 }catch(java.lang.ExceptionInInitializerError ex){ 664 warnln("Could not load NamePrepTransform data"); 665 }catch(java.lang.NoClassDefFoundError ex){ 666 warnln("Could not load NamePrepTransform data"); 667 } 668 669 } 670} 671