2 *******************************************************************************
3 * Copyright (C) 2003-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.dev.test.stringprep;
9 import com.ibm.icu.dev.test.TestFmwk;
10 import com.ibm.icu.text.StringPrepParseException;
11 import com.ibm.icu.text.UCharacterIterator;
16 * To change the template for this generated type comment go to
17 * Window>Preferences>Java>Code Generation>Code and Comments
19 public class TestIDNARef extends TestFmwk {
20 public static void main(String[] args) throws Exception {
21 new TestIDNARef().run(args);
23 private StringPrepParseException unassignedException = new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR);
24 public void TestToUnicode() throws Exception{
26 for(int i=0; i<TestData.asciiIn.length; i++){
27 // test StringBuffer toUnicode
28 doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.DEFAULT, null);
29 doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.ALLOW_UNASSIGNED, null);
30 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES, null);
31 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES|IDNAReference.ALLOW_UNASSIGNED, null);
34 }catch(java.lang.ExceptionInInitializerError ex){
35 warnln("Could not load NamePrepTransform data");
36 }catch(java.lang.NoClassDefFoundError ex){
37 warnln("Could not load NamePrepTransform data");
41 public void TestToASCII() throws Exception{
43 for(int i=0; i<TestData.asciiIn.length; i++){
44 // test StringBuffer toUnicode
45 doTestToASCII(new String(TestData.unicodeIn[i]),TestData.asciiIn[i],IDNAReference.DEFAULT, null);
46 doTestToASCII(new String(TestData.unicodeIn[i]),TestData.asciiIn[i],IDNAReference.ALLOW_UNASSIGNED, null);
47 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES, null);
48 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES|IDNAReference.ALLOW_UNASSIGNED, null);
51 }catch(java.lang.ExceptionInInitializerError ex){
52 warnln("Could not load NamePrepTransform data");
53 }catch(java.lang.NoClassDefFoundError ex){
54 warnln("Could not load NamePrepTransform data");
58 public void TestIDNToASCII() throws Exception{
60 for(int i=0; i<TestData.domainNames.length; i++){
61 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.DEFAULT, null);
62 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED, null);
63 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.USE_STD3_RULES, null);
64 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null);
67 for(int i=0; i<TestData.domainNames1Uni.length; i++){
68 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.DEFAULT, null);
69 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.ALLOW_UNASSIGNED, null);
70 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.USE_STD3_RULES, null);
71 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null);
74 }catch(java.lang.ExceptionInInitializerError ex){
75 warnln("Could not load NamePrepTransform data");
76 }catch(java.lang.NoClassDefFoundError ex){
77 warnln("Could not load NamePrepTransform data");
80 public void TestIDNToUnicode() throws Exception{
82 for(int i=0; i<TestData.domainNames.length; i++){
83 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.DEFAULT, null);
84 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED, null);
85 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.USE_STD3_RULES, null);
86 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null);
88 for(int i=0; i<TestData.domainNamesToASCIIOut.length; i++){
89 doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],TestData.domainNamesToUnicodeOut[i],IDNAReference.DEFAULT, null);
90 doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],TestData.domainNamesToUnicodeOut[i],IDNAReference.ALLOW_UNASSIGNED, null);
92 }catch(java.lang.ExceptionInInitializerError ex){
93 warnln("Could not load NamePrepTransform data");
94 }catch(java.lang.NoClassDefFoundError ex){
95 warnln("Could not load NamePrepTransform data");
99 private void doTestToUnicode(String src, String expected, int options, Object expectedException)
102 if (!IDNAReference.isReady()) {
103 logln("Transliterator is not available on this environment. Skipping doTestToUnicode.");
107 StringBuffer inBuf = new StringBuffer(src);
108 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
111 StringBuffer out = IDNAReference.convertToUnicode(src,options);
112 if(expected!=null && out != null && !out.toString().equals(expected)){
113 errln("convertToUnicode did not return expected result with options : "+ options +
114 " Expected: " + prettify(expected)+" Got: "+prettify(out));
116 if(expectedException!=null && !unassignedException.equals(expectedException)){
117 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
119 }catch(StringPrepParseException ex){
120 if(expectedException == null || !ex.equals(expectedException)){
121 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
126 StringBuffer out = IDNAReference.convertToUnicode(inBuf,options);
127 if(expected!=null && out != null && !out.toString().equals(expected)){
128 errln("convertToUnicode did not return expected result with options : "+ options +
129 " Expected: " + prettify(expected)+" Got: "+out);
131 if(expectedException!=null && !unassignedException.equals(expectedException)){
132 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
134 }catch(StringPrepParseException ex){
135 if(expectedException == null || !ex.equals(expectedException)){
136 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
141 StringBuffer out = IDNAReference.convertToUnicode(inIter,options);
142 if(expected!=null && out != null && !out.toString().equals(expected)){
143 errln("convertToUnicode did not return expected result with options : "+ options +
144 " Expected: " + prettify(expected)+" Got: "+prettify(out));
146 if(expectedException!=null && !unassignedException.equals(expectedException)){
147 errln("Did not get the expected exception. The operation succeeded!");
149 }catch(StringPrepParseException ex){
150 if(expectedException == null || !ex.equals(expectedException)){
151 errln("Did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
156 private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException)
159 if (!IDNAReference.isReady()) {
160 logln("Transliterator is not available on this environment. Skipping doTestIDNToUnicode.");
164 StringBuffer inBuf = new StringBuffer(src);
165 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
168 StringBuffer out = IDNAReference.convertIDNToUnicode(src,options);
169 if(expected!=null && out != null && !out.toString().equals(expected)){
170 errln("convertToUnicode did not return expected result with options : "+ options +
171 " Expected: " + prettify(expected)+" Got: "+prettify(out));
173 if(expectedException!=null && !unassignedException.equals(expectedException)){
174 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
176 }catch(StringPrepParseException ex){
177 if(expectedException == null || !expectedException.equals(ex)){
178 errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
182 StringBuffer out = IDNAReference.convertIDNToUnicode(inBuf,options);
183 if(expected!=null && out != null && !out.toString().equals(expected)){
184 errln("convertToUnicode did not return expected result with options : "+ options +
185 " Expected: " + prettify(expected)+" Got: "+out);
187 if(expectedException!=null && !unassignedException.equals(expectedException)){
188 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
190 }catch(StringPrepParseException ex){
191 if(expectedException == null || !expectedException.equals(ex)){
192 errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
197 StringBuffer out = IDNAReference.convertIDNToUnicode(inIter,options);
198 if(expected!=null && out != null && !out.toString().equals(expected)){
199 errln("convertToUnicode did not return expected result with options : "+ options +
200 " Expected: " + prettify(expected)+" Got: "+prettify(out));
202 if(expectedException!=null && !unassignedException.equals(expectedException)){
203 errln("Did not get the expected exception. The operation succeeded!");
205 }catch(StringPrepParseException ex){
206 if(expectedException == null || !expectedException.equals(ex)){
207 errln("Did not get the expected exception for source: " +src +" Got: "+ ex.toString());
211 private void doTestToASCII(String src, String expected, int options, Object expectedException)
214 if (!IDNAReference.isReady()) {
215 logln("Transliterator is not available on this environment. Skipping doTestToASCII.");
219 StringBuffer inBuf = new StringBuffer(src);
220 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
223 StringBuffer out = IDNAReference.convertToASCII(src,options);
224 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
225 errln("convertToASCII did not return expected result with options : "+ options +
226 " Expected: " + expected+" Got: "+out);
228 if(expectedException!=null && !unassignedException.equals(expectedException)){
229 errln("convertToASCII did not get the expected exception. The operation succeeded!");
231 }catch(StringPrepParseException ex){
232 if(expectedException == null || !expectedException.equals(ex)){
233 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
238 StringBuffer out = IDNAReference.convertToASCII(inBuf,options);
239 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
240 errln("convertToASCII did not return expected result with options : "+ options +
241 " Expected: " + expected+" Got: "+out);
243 if(expectedException!=null && !unassignedException.equals(expectedException)){
244 errln("convertToASCII did not get the expected exception. The operation succeeded!");
246 }catch(StringPrepParseException ex){
247 if(expectedException == null || !expectedException.equals(ex)){
248 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
253 StringBuffer out = IDNAReference.convertToASCII(inIter,options);
254 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
255 errln("convertToASCII did not return expected result with options : "+ options +
256 " Expected: " + expected+" Got: "+ out);
258 if(expectedException!=null && !unassignedException.equals(expectedException)){
259 errln("convertToASCII did not get the expected exception. The operation succeeded!");
261 }catch(StringPrepParseException ex){
262 if(expectedException == null || !expectedException.equals(ex)){
263 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
267 private void doTestIDNToASCII(String src, String expected, int options, Object expectedException)
270 if (!IDNAReference.isReady()) {
271 logln("Transliterator is not available on this environment. Skipping doTestIDNToASCII.");
275 StringBuffer inBuf = new StringBuffer(src);
276 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
279 StringBuffer out = IDNAReference.convertIDNToASCII(src,options);
280 if(expected!=null && out != null && !out.toString().equals(expected)){
281 errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options +
282 " Expected: " + expected+" Got: "+out);
284 if(expectedException!=null && !unassignedException.equals(expectedException)){
285 errln("convertToIDNAReferenceASCII did not get the expected exception. The operation succeeded!");
287 }catch(StringPrepParseException ex){
288 if(expectedException == null || !ex.equals(expectedException)){
289 errln("convertToIDNAReferenceASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
293 StringBuffer out = IDNAReference.convertIDNtoASCII(inBuf,options);
294 if(expected!=null && out != null && !out.toString().equals(expected)){
295 errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options +
296 " Expected: " + expected+" Got: "+out);
298 if(expectedException!=null && !unassignedException.equals(expectedException)){
299 errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!");
301 }catch(StringPrepParseException ex){
302 if(expectedException == null || !ex.equals(expectedException)){
303 errln("convertToIDNAReferenceSCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
308 StringBuffer out = IDNAReference.convertIDNtoASCII(inIter,options);
309 if(expected!=null && out != null && !out.toString().equals(expected)){
310 errln("convertIDNToASCII did not return expected result with options : "+ options +
311 " Expected: " + expected+" Got: "+ out);
314 if(expectedException!=null && !unassignedException.equals(expectedException)){
315 errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");
317 }catch(StringPrepParseException ex){
318 if(expectedException == null || !ex.equals(expectedException)){
319 errln("convertIDNToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
323 public void TestConformance()throws Exception{
325 for(int i=0; i<TestData.conformanceTestCases.length;i++){
327 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
328 if(testCase.expected != null){
330 doTestToASCII(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
331 doTestToASCII(testCase.input,testCase.output,IDNAReference.ALLOW_UNASSIGNED,testCase.expected);
334 //doTestToUnicode(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
336 }catch(java.lang.ExceptionInInitializerError ex){
337 warnln("Could not load NamePrepTransform data");
338 }catch(java.lang.NoClassDefFoundError ex){
339 warnln("Could not load NamePrepTransform data");
342 public void TestNamePrepConformance() throws Exception{
344 NamePrepTransform namePrep = NamePrepTransform.getInstance();
345 if (!namePrep.isReady()) {
346 logln("Transliterator is not available on this environment.");
349 for(int i=0; i<TestData.conformanceTestCases.length;i++){
350 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
351 UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
353 StringBuffer output = namePrep.prepare(iter,NamePrepTransform.NONE);
354 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
355 errln("Did not get the expected output. Expected: " + prettify(testCase.output)+
356 " Got: "+ prettify(output) );
358 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
359 errln("Did not get the expected exception. The operation succeeded!");
361 }catch(StringPrepParseException ex){
362 if(testCase.expected == null || !ex.equals(testCase.expected)){
363 errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
369 StringBuffer output = namePrep.prepare(iter,NamePrepTransform.ALLOW_UNASSIGNED);
370 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
371 errln("Did not get the expected output. Expected: " + prettify(testCase.output)+
372 " Got: "+ prettify(output) );
374 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
375 errln("Did not get the expected exception. The operation succeeded!");
377 }catch(StringPrepParseException ex){
378 if(testCase.expected == null || !ex.equals(testCase.expected)){
379 errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
383 }catch(java.lang.ExceptionInInitializerError e){
384 warnln("Could not load NamePrepTransformData");
385 }catch(java.lang.NoClassDefFoundError ex){
386 warnln("Could not load NamePrepTransform data");
390 public void TestErrorCases() throws Exception{
392 for(int i=0; i < TestData.errorCases.length; i++){
393 TestData.ErrorCase errCase = TestData.errorCases[i];
394 if(errCase.testLabel==true){
396 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.DEFAULT,errCase.expected);
397 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
398 if(errCase.useSTD3ASCIIRules){
399 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected);
402 if(errCase.useSTD3ASCIIRules!=true){
405 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.DEFAULT,errCase.expected);
406 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
409 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected);
413 if(errCase.testToUnicode==true){
414 if(errCase.useSTD3ASCIIRules!=true){
416 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.DEFAULT,errCase.expected);
417 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
420 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.USE_STD3_RULES,errCase.expected);
424 }catch(java.lang.ExceptionInInitializerError ex){
425 warnln("Could not load NamePrepTransform data");
426 }catch(java.lang.NoClassDefFoundError ex){
427 warnln("Could not load NamePrepTransform data");
430 private void doTestCompare(String s1, String s2, boolean isEqual){
432 if (!IDNAReference.isReady()) {
433 logln("Transliterator is not available on this environment. Skipping doTestCompare.");
438 int retVal = IDNAReference.compare(s1,s2,IDNAReference.DEFAULT);
439 if(isEqual==true && retVal != 0){
440 errln("Did not get the expected result for s1: "+ prettify(s1)+
441 " s2: "+prettify(s2));
443 retVal = IDNAReference.compare(new StringBuffer(s1), new StringBuffer(s2), IDNAReference.DEFAULT);
444 if(isEqual==true && retVal != 0){
445 errln("Did not get the expected result for s1: "+ prettify(s1)+
446 " s2: "+prettify(s2));
448 retVal = IDNAReference.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNAReference.DEFAULT);
449 if(isEqual==true && retVal != 0){
450 errln("Did not get the expected result for s1: "+ prettify(s1)+
451 " s2: "+prettify(s2));
455 errln("Unexpected exception thrown by IDNAReference.compare");
459 int retVal = IDNAReference.compare(s1,s2,IDNAReference.ALLOW_UNASSIGNED);
460 if(isEqual==true && retVal != 0){
461 errln("Did not get the expected result for s1: "+ prettify(s1)+
462 " s2: "+prettify(s2));
464 retVal = IDNAReference.compare(new StringBuffer(s1), new StringBuffer(s2), IDNAReference.ALLOW_UNASSIGNED);
465 if(isEqual==true && retVal != 0){
466 errln("Did not get the expected result for s1: "+ prettify(s1)+
467 " s2: "+prettify(s2));
469 retVal = IDNAReference.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNAReference.ALLOW_UNASSIGNED);
470 if(isEqual==true && retVal != 0){
471 errln("Did not get the expected result for s1: "+ prettify(s1)+
472 " s2: "+prettify(s2));
475 errln("Unexpected exception thrown by IDNAReference.compare");
478 public void TestCompare() throws Exception{
481 StringBuffer source = new StringBuffer(www);
482 StringBuffer uni0 = new StringBuffer(www);
483 StringBuffer uni1 = new StringBuffer(www);
484 StringBuffer ascii0 = new StringBuffer(www);
485 StringBuffer ascii1 = new StringBuffer(www);
487 uni0.append(TestData.unicodeIn[0]);
490 uni1.append(TestData.unicodeIn[1]);
493 ascii0.append(TestData.asciiIn[0]);
496 ascii1.append(TestData.asciiIn[1]);
499 for(int i=0;i< TestData.unicodeIn.length; i++){
501 // for every entry in unicodeIn array
502 // prepend www. and append .com
504 source.append(TestData.unicodeIn[i]);
507 // a) compare it with itself
508 doTestCompare(source.toString(),source.toString(),true);
510 // b) compare it with asciiIn equivalent
511 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);
513 // c) compare it with unicodeIn not equivalent
515 doTestCompare(source.toString(), uni1.toString(), false);
517 doTestCompare(source.toString(),uni0.toString(), false);
519 // d) compare it with asciiIn not equivalent
521 doTestCompare(source.toString(),ascii1.toString(), false);
523 doTestCompare(source.toString(),ascii0.toString(), false);
526 }catch(java.lang.ExceptionInInitializerError ex){
527 warnln("Could not load NamePrepTransform data");
528 }catch(java.lang.NoClassDefFoundError ex){
529 warnln("Could not load NamePrepTransform data");
533 // test and ascertain
534 // func(func(func(src))) == func(src)
535 public void doTestChainingToASCII(String source)throws Exception{
537 if (!IDNAReference.isReady()) {
538 logln("Transliterator is not available on this environment. Skipping doTestChainingToASCII.");
542 StringBuffer expected;
543 StringBuffer chained;
545 // test convertIDNToASCII
546 expected = IDNAReference.convertIDNToASCII(source,IDNAReference.DEFAULT);
548 for(int i=0; i< 4; i++){
549 chained = IDNAReference.convertIDNtoASCII(chained,IDNAReference.DEFAULT);
551 if(!expected.toString().equals(chained.toString())){
552 errln("Chaining test failed for convertIDNToASCII");
554 // test convertIDNToA
555 expected = IDNAReference.convertToASCII(source,IDNAReference.DEFAULT);
557 for(int i=0; i< 4; i++){
558 chained = IDNAReference.convertToASCII(chained,IDNAReference.DEFAULT);
560 if(!expected.toString().equals(chained.toString())){
561 errln("Chaining test failed for convertToASCII");
565 // test and ascertain
566 // func(func(func(src))) == func(src)
567 public void doTestChainingToUnicode(String source)throws Exception{
569 if (!IDNAReference.isReady()) {
570 logln("Transliterator is not available on this environment. Skipping doTestChainingToUnicode.");
574 StringBuffer expected;
575 StringBuffer chained;
577 // test convertIDNToUnicode
578 expected = IDNAReference.convertIDNToUnicode(source,IDNAReference.DEFAULT);
580 for(int i=0; i< 4; i++){
581 chained = IDNAReference.convertIDNToUnicode(chained,IDNAReference.DEFAULT);
583 if(!expected.toString().equals(chained.toString())){
584 errln("Chaining test failed for convertIDNToUnicode");
586 // test convertIDNToA
587 expected = IDNAReference.convertToUnicode(source,IDNAReference.DEFAULT);
589 for(int i=0; i< 4; i++){
590 chained = IDNAReference.convertToUnicode(chained,IDNAReference.DEFAULT);
592 if(!expected.toString().equals(chained.toString())){
593 errln("Chaining test failed for convertToUnicode");
597 public void TestChaining() throws Exception{
599 for(int i=0; i< TestData.unicodeIn.length; i++){
600 doTestChainingToASCII(new String(TestData.unicodeIn[i]));
602 for(int i=0; i< TestData.asciiIn.length; i++){
603 doTestChainingToUnicode(TestData.asciiIn[i]);
605 }catch(java.lang.ExceptionInInitializerError ex){
606 warnln("Could not load NamePrepTransform data");
607 }catch(java.lang.NoClassDefFoundError ex){
608 warnln("Could not load NamePrepTransform data");
611 public void TestRootLabelSeparator() throws Exception{
613 String com = ".com."; /*root label separator*/
614 StringBuffer source = new StringBuffer(www);
615 StringBuffer uni0 = new StringBuffer(www);
616 StringBuffer uni1 = new StringBuffer(www);
617 StringBuffer ascii0 = new StringBuffer(www);
618 StringBuffer ascii1 = new StringBuffer(www);
620 uni0.append(TestData.unicodeIn[0]);
623 uni1.append(TestData.unicodeIn[1]);
626 ascii0.append(TestData.asciiIn[0]);
629 ascii1.append(TestData.asciiIn[1]);
632 for(int i=0;i< TestData.unicodeIn.length; i++){
634 // for every entry in unicodeIn array
635 // prepend www. and append .com
637 source.append(TestData.unicodeIn[i]);
640 // a) compare it with itself
641 doTestCompare(source.toString(),source.toString(),true);
643 // b) compare it with asciiIn equivalent
644 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);
646 // c) compare it with unicodeIn not equivalent
648 doTestCompare(source.toString(), uni1.toString(), false);
650 doTestCompare(source.toString(),uni0.toString(), false);
652 // d) compare it with asciiIn not equivalent
654 doTestCompare(source.toString(),ascii1.toString(), false);
656 doTestCompare(source.toString(),ascii0.toString(), false);
659 }catch(java.lang.ExceptionInInitializerError ex){
660 warnln("Could not load NamePrepTransform data");
661 }catch(java.lang.NoClassDefFoundError ex){
662 warnln("Could not load NamePrepTransform data");