2 *******************************************************************************
\r
3 * Copyright (C) 2003-2005, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.dev.test.stringprep;
\r
9 import com.ibm.icu.dev.test.TestFmwk;
\r
10 import com.ibm.icu.text.StringPrepParseException;
\r
11 import com.ibm.icu.text.UCharacterIterator;
\r
16 * To change the template for this generated type comment go to
\r
17 * Window>Preferences>Java>Code Generation>Code and Comments
\r
19 public class TestIDNARef extends TestFmwk {
\r
20 public static void main(String[] args) throws Exception {
\r
21 new TestIDNARef().run(args);
\r
23 private StringPrepParseException unassignedException = new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR);
\r
24 public void TestToUnicode() throws Exception{
\r
26 for(int i=0; i<TestData.asciiIn.length; i++){
\r
27 // test StringBuffer toUnicode
\r
28 doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.DEFAULT, null);
\r
29 doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.ALLOW_UNASSIGNED, null);
\r
30 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES, null);
\r
31 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES|IDNAReference.ALLOW_UNASSIGNED, null);
\r
34 }catch(java.lang.ExceptionInInitializerError ex){
\r
35 warnln("Could not load NamePrepTransform data");
\r
36 }catch(java.lang.NoClassDefFoundError ex){
\r
37 warnln("Could not load NamePrepTransform data");
\r
41 public void TestToASCII() throws Exception{
\r
43 for(int i=0; i<TestData.asciiIn.length; i++){
\r
44 // test StringBuffer toUnicode
\r
45 doTestToASCII(new String(TestData.unicodeIn[i]),TestData.asciiIn[i],IDNAReference.DEFAULT, null);
\r
46 doTestToASCII(new String(TestData.unicodeIn[i]),TestData.asciiIn[i],IDNAReference.ALLOW_UNASSIGNED, null);
\r
47 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES, null);
\r
48 //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES|IDNAReference.ALLOW_UNASSIGNED, null);
\r
51 }catch(java.lang.ExceptionInInitializerError ex){
\r
52 warnln("Could not load NamePrepTransform data");
\r
53 }catch(java.lang.NoClassDefFoundError ex){
\r
54 warnln("Could not load NamePrepTransform data");
\r
58 public void TestIDNToASCII() throws Exception{
\r
60 for(int i=0; i<TestData.domainNames.length; i++){
\r
61 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.DEFAULT, null);
\r
62 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED, null);
\r
63 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.USE_STD3_RULES, null);
\r
64 doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null);
\r
67 for(int i=0; i<TestData.domainNames1Uni.length; i++){
\r
68 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.DEFAULT, null);
\r
69 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.ALLOW_UNASSIGNED, null);
\r
70 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.USE_STD3_RULES, null);
\r
71 doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null);
\r
74 }catch(java.lang.ExceptionInInitializerError ex){
\r
75 warnln("Could not load NamePrepTransform data");
\r
76 }catch(java.lang.NoClassDefFoundError ex){
\r
77 warnln("Could not load NamePrepTransform data");
\r
80 public void TestIDNToUnicode() throws Exception{
\r
82 for(int i=0; i<TestData.domainNames.length; i++){
\r
83 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.DEFAULT, null);
\r
84 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED, null);
\r
85 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.USE_STD3_RULES, null);
\r
86 doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNAReference.ALLOW_UNASSIGNED|IDNAReference.USE_STD3_RULES, null);
\r
88 for(int i=0; i<TestData.domainNamesToASCIIOut.length; i++){
\r
89 doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],TestData.domainNamesToUnicodeOut[i],IDNAReference.DEFAULT, null);
\r
90 doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],TestData.domainNamesToUnicodeOut[i],IDNAReference.ALLOW_UNASSIGNED, null);
\r
92 }catch(java.lang.ExceptionInInitializerError ex){
\r
93 warnln("Could not load NamePrepTransform data");
\r
94 }catch(java.lang.NoClassDefFoundError ex){
\r
95 warnln("Could not load NamePrepTransform data");
\r
99 private void doTestToUnicode(String src, String expected, int options, Object expectedException)
\r
101 StringBuffer inBuf = new StringBuffer(src);
\r
102 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
\r
105 StringBuffer out = IDNAReference.convertToUnicode(src,options);
\r
106 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
107 errln("convertToUnicode did not return expected result with options : "+ options +
\r
108 " Expected: " + prettify(expected)+" Got: "+prettify(out));
\r
110 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
111 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
\r
113 }catch(StringPrepParseException ex){
\r
114 if(expectedException == null || !ex.equals(expectedException)){
\r
115 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
\r
120 StringBuffer out = IDNAReference.convertToUnicode(inBuf,options);
\r
121 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
122 errln("convertToUnicode did not return expected result with options : "+ options +
\r
123 " Expected: " + prettify(expected)+" Got: "+out);
\r
125 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
126 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
\r
128 }catch(StringPrepParseException ex){
\r
129 if(expectedException == null || !ex.equals(expectedException)){
\r
130 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
\r
135 StringBuffer out = IDNAReference.convertToUnicode(inIter,options);
\r
136 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
137 errln("convertToUnicode did not return expected result with options : "+ options +
\r
138 " Expected: " + prettify(expected)+" Got: "+prettify(out));
\r
140 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
141 errln("Did not get the expected exception. The operation succeeded!");
\r
143 }catch(StringPrepParseException ex){
\r
144 if(expectedException == null || !ex.equals(expectedException)){
\r
145 errln("Did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
\r
150 private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException)
\r
152 StringBuffer inBuf = new StringBuffer(src);
\r
153 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
\r
156 StringBuffer out = IDNAReference.convertIDNToUnicode(src,options);
\r
157 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
158 errln("convertToUnicode did not return expected result with options : "+ options +
\r
159 " Expected: " + prettify(expected)+" Got: "+prettify(out));
\r
161 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
162 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
\r
164 }catch(StringPrepParseException ex){
\r
165 if(expectedException == null || !expectedException.equals(ex)){
\r
166 errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
170 StringBuffer out = IDNAReference.convertIDNToUnicode(inBuf,options);
\r
171 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
172 errln("convertToUnicode did not return expected result with options : "+ options +
\r
173 " Expected: " + prettify(expected)+" Got: "+out);
\r
175 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
176 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
\r
178 }catch(StringPrepParseException ex){
\r
179 if(expectedException == null || !expectedException.equals(ex)){
\r
180 errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
185 StringBuffer out = IDNAReference.convertIDNToUnicode(inIter,options);
\r
186 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
187 errln("convertToUnicode did not return expected result with options : "+ options +
\r
188 " Expected: " + prettify(expected)+" Got: "+prettify(out));
\r
190 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
191 errln("Did not get the expected exception. The operation succeeded!");
\r
193 }catch(StringPrepParseException ex){
\r
194 if(expectedException == null || !expectedException.equals(ex)){
\r
195 errln("Did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
199 private void doTestToASCII(String src, String expected, int options, Object expectedException)
\r
201 StringBuffer inBuf = new StringBuffer(src);
\r
202 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
\r
205 StringBuffer out = IDNAReference.convertToASCII(src,options);
\r
206 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
\r
207 errln("convertToASCII did not return expected result with options : "+ options +
\r
208 " Expected: " + expected+" Got: "+out);
\r
210 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
211 errln("convertToASCII did not get the expected exception. The operation succeeded!");
\r
213 }catch(StringPrepParseException ex){
\r
214 if(expectedException == null || !expectedException.equals(ex)){
\r
215 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
220 StringBuffer out = IDNAReference.convertToASCII(inBuf,options);
\r
221 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
\r
222 errln("convertToASCII did not return expected result with options : "+ options +
\r
223 " Expected: " + expected+" Got: "+out);
\r
225 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
226 errln("convertToASCII did not get the expected exception. The operation succeeded!");
\r
228 }catch(StringPrepParseException ex){
\r
229 if(expectedException == null || !expectedException.equals(ex)){
\r
230 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
235 StringBuffer out = IDNAReference.convertToASCII(inIter,options);
\r
236 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
\r
237 errln("convertToASCII did not return expected result with options : "+ options +
\r
238 " Expected: " + expected+" Got: "+ out);
\r
240 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
241 errln("convertToASCII did not get the expected exception. The operation succeeded!");
\r
243 }catch(StringPrepParseException ex){
\r
244 if(expectedException == null || !expectedException.equals(ex)){
\r
245 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
249 private void doTestIDNToASCII(String src, String expected, int options, Object expectedException)
\r
252 StringBuffer inBuf = new StringBuffer(src);
\r
253 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
\r
256 StringBuffer out = IDNAReference.convertIDNToASCII(src,options);
\r
257 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
258 errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options +
\r
259 " Expected: " + expected+" Got: "+out);
\r
261 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
262 errln("convertToIDNAReferenceASCII did not get the expected exception. The operation succeeded!");
\r
264 }catch(StringPrepParseException ex){
\r
265 if(expectedException == null || !ex.equals(expectedException)){
\r
266 errln("convertToIDNAReferenceASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
270 StringBuffer out = IDNAReference.convertIDNtoASCII(inBuf,options);
\r
271 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
272 errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options +
\r
273 " Expected: " + expected+" Got: "+out);
\r
275 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
276 errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!");
\r
278 }catch(StringPrepParseException ex){
\r
279 if(expectedException == null || !ex.equals(expectedException)){
\r
280 errln("convertToIDNAReferenceSCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
285 StringBuffer out = IDNAReference.convertIDNtoASCII(inIter,options);
\r
286 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
287 errln("convertIDNToASCII did not return expected result with options : "+ options +
\r
288 " Expected: " + expected+" Got: "+ out);
\r
291 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
292 errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");
\r
294 }catch(StringPrepParseException ex){
\r
295 if(expectedException == null || !ex.equals(expectedException)){
\r
296 errln("convertIDNToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
300 public void TestConformance()throws Exception{
\r
302 for(int i=0; i<TestData.conformanceTestCases.length;i++){
\r
304 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
\r
305 if(testCase.expected != null){
\r
307 doTestToASCII(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
\r
308 doTestToASCII(testCase.input,testCase.output,IDNAReference.ALLOW_UNASSIGNED,testCase.expected);
\r
311 //doTestToUnicode(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
\r
313 }catch(java.lang.ExceptionInInitializerError ex){
\r
314 warnln("Could not load NamePrepTransform data");
\r
315 }catch(java.lang.NoClassDefFoundError ex){
\r
316 warnln("Could not load NamePrepTransform data");
\r
319 public void TestNamePrepConformance() throws Exception{
\r
321 NamePrepTransform namePrep = NamePrepTransform.getInstance();
\r
322 for(int i=0; i<TestData.conformanceTestCases.length;i++){
\r
323 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
\r
324 UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
\r
326 StringBuffer output = namePrep.prepare(iter,NamePrepTransform.NONE);
\r
327 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
\r
328 errln("Did not get the expected output. Expected: " + prettify(testCase.output)+
\r
329 " Got: "+ prettify(output) );
\r
331 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
\r
332 errln("Did not get the expected exception. The operation succeeded!");
\r
334 }catch(StringPrepParseException ex){
\r
335 if(testCase.expected == null || !ex.equals(testCase.expected)){
\r
336 errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
\r
342 StringBuffer output = namePrep.prepare(iter,NamePrepTransform.ALLOW_UNASSIGNED);
\r
343 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
\r
344 errln("Did not get the expected output. Expected: " + prettify(testCase.output)+
\r
345 " Got: "+ prettify(output) );
\r
347 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
\r
348 errln("Did not get the expected exception. The operation succeeded!");
\r
350 }catch(StringPrepParseException ex){
\r
351 if(testCase.expected == null || !ex.equals(testCase.expected)){
\r
352 errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
\r
356 }catch(java.lang.ExceptionInInitializerError e){
\r
357 warnln("Could not load NamePrepTransformData");
\r
358 }catch(java.lang.NoClassDefFoundError ex){
\r
359 warnln("Could not load NamePrepTransform data");
\r
363 public void TestErrorCases() throws Exception{
\r
365 for(int i=0; i < TestData.errorCases.length; i++){
\r
366 TestData.ErrorCase errCase = TestData.errorCases[i];
\r
367 if(errCase.testLabel==true){
\r
369 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.DEFAULT,errCase.expected);
\r
370 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
\r
371 if(errCase.useSTD3ASCIIRules){
\r
372 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected);
\r
375 if(errCase.useSTD3ASCIIRules!=true){
\r
378 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.DEFAULT,errCase.expected);
\r
379 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
\r
382 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected);
\r
386 if(errCase.testToUnicode==true){
\r
387 if(errCase.useSTD3ASCIIRules!=true){
\r
388 // Test IDNToUnicode
\r
389 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.DEFAULT,errCase.expected);
\r
390 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
\r
393 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.USE_STD3_RULES,errCase.expected);
\r
397 }catch(java.lang.ExceptionInInitializerError ex){
\r
398 warnln("Could not load NamePrepTransform data");
\r
399 }catch(java.lang.NoClassDefFoundError ex){
\r
400 warnln("Could not load NamePrepTransform data");
\r
403 private void doTestCompare(String s1, String s2, boolean isEqual){
\r
405 int retVal = IDNAReference.compare(s1,s2,IDNAReference.DEFAULT);
\r
406 if(isEqual==true && retVal != 0){
\r
407 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
408 " s2: "+prettify(s2));
\r
410 retVal = IDNAReference.compare(new StringBuffer(s1), new StringBuffer(s2), IDNAReference.DEFAULT);
\r
411 if(isEqual==true && retVal != 0){
\r
412 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
413 " s2: "+prettify(s2));
\r
415 retVal = IDNAReference.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNAReference.DEFAULT);
\r
416 if(isEqual==true && retVal != 0){
\r
417 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
418 " s2: "+prettify(s2));
\r
420 }catch(Exception e){
\r
421 e.printStackTrace();
\r
422 errln("Unexpected exception thrown by IDNAReference.compare");
\r
426 int retVal = IDNAReference.compare(s1,s2,IDNAReference.ALLOW_UNASSIGNED);
\r
427 if(isEqual==true && retVal != 0){
\r
428 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
429 " s2: "+prettify(s2));
\r
431 retVal = IDNAReference.compare(new StringBuffer(s1), new StringBuffer(s2), IDNAReference.ALLOW_UNASSIGNED);
\r
432 if(isEqual==true && retVal != 0){
\r
433 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
434 " s2: "+prettify(s2));
\r
436 retVal = IDNAReference.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNAReference.ALLOW_UNASSIGNED);
\r
437 if(isEqual==true && retVal != 0){
\r
438 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
439 " s2: "+prettify(s2));
\r
441 }catch(Exception e){
\r
442 errln("Unexpected exception thrown by IDNAReference.compare");
\r
445 public void TestCompare() throws Exception{
\r
446 String www = "www.";
\r
447 String com = ".com";
\r
448 StringBuffer source = new StringBuffer(www);
\r
449 StringBuffer uni0 = new StringBuffer(www);
\r
450 StringBuffer uni1 = new StringBuffer(www);
\r
451 StringBuffer ascii0 = new StringBuffer(www);
\r
452 StringBuffer ascii1 = new StringBuffer(www);
\r
454 uni0.append(TestData.unicodeIn[0]);
\r
457 uni1.append(TestData.unicodeIn[1]);
\r
460 ascii0.append(TestData.asciiIn[0]);
\r
461 ascii0.append(com);
\r
463 ascii1.append(TestData.asciiIn[1]);
\r
464 ascii1.append(com);
\r
466 for(int i=0;i< TestData.unicodeIn.length; i++){
\r
468 // for every entry in unicodeIn array
\r
469 // prepend www. and append .com
\r
470 source.setLength(4);
\r
471 source.append(TestData.unicodeIn[i]);
\r
472 source.append(com);
\r
474 // a) compare it with itself
\r
475 doTestCompare(source.toString(),source.toString(),true);
\r
477 // b) compare it with asciiIn equivalent
\r
478 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);
\r
480 // c) compare it with unicodeIn not equivalent
\r
482 doTestCompare(source.toString(), uni1.toString(), false);
\r
484 doTestCompare(source.toString(),uni0.toString(), false);
\r
486 // d) compare it with asciiIn not equivalent
\r
488 doTestCompare(source.toString(),ascii1.toString(), false);
\r
490 doTestCompare(source.toString(),ascii0.toString(), false);
\r
493 }catch(java.lang.ExceptionInInitializerError ex){
\r
494 warnln("Could not load NamePrepTransform data");
\r
495 }catch(java.lang.NoClassDefFoundError ex){
\r
496 warnln("Could not load NamePrepTransform data");
\r
500 // test and ascertain
\r
501 // func(func(func(src))) == func(src)
\r
502 public void doTestChainingToASCII(String source)throws Exception{
\r
503 StringBuffer expected;
\r
504 StringBuffer chained;
\r
506 // test convertIDNToASCII
\r
507 expected = IDNAReference.convertIDNToASCII(source,IDNAReference.DEFAULT);
\r
508 chained = expected;
\r
509 for(int i=0; i< 4; i++){
\r
510 chained = IDNAReference.convertIDNtoASCII(chained,IDNAReference.DEFAULT);
\r
512 if(!expected.toString().equals(chained.toString())){
\r
513 errln("Chaining test failed for convertIDNToASCII");
\r
515 // test convertIDNToA
\r
516 expected = IDNAReference.convertToASCII(source,IDNAReference.DEFAULT);
\r
517 chained = expected;
\r
518 for(int i=0; i< 4; i++){
\r
519 chained = IDNAReference.convertToASCII(chained,IDNAReference.DEFAULT);
\r
521 if(!expected.toString().equals(chained.toString())){
\r
522 errln("Chaining test failed for convertToASCII");
\r
526 // test and ascertain
\r
527 // func(func(func(src))) == func(src)
\r
528 public void doTestChainingToUnicode(String source)throws Exception{
\r
529 StringBuffer expected;
\r
530 StringBuffer chained;
\r
532 // test convertIDNToUnicode
\r
533 expected = IDNAReference.convertIDNToUnicode(source,IDNAReference.DEFAULT);
\r
534 chained = expected;
\r
535 for(int i=0; i< 4; i++){
\r
536 chained = IDNAReference.convertIDNToUnicode(chained,IDNAReference.DEFAULT);
\r
538 if(!expected.toString().equals(chained.toString())){
\r
539 errln("Chaining test failed for convertIDNToUnicode");
\r
541 // test convertIDNToA
\r
542 expected = IDNAReference.convertToUnicode(source,IDNAReference.DEFAULT);
\r
543 chained = expected;
\r
544 for(int i=0; i< 4; i++){
\r
545 chained = IDNAReference.convertToUnicode(chained,IDNAReference.DEFAULT);
\r
547 if(!expected.toString().equals(chained.toString())){
\r
548 errln("Chaining test failed for convertToUnicode");
\r
552 public void TestChaining() throws Exception{
\r
554 for(int i=0; i< TestData.unicodeIn.length; i++){
\r
555 doTestChainingToASCII(new String(TestData.unicodeIn[i]));
\r
557 for(int i=0; i< TestData.asciiIn.length; i++){
\r
558 doTestChainingToUnicode(TestData.asciiIn[i]);
\r
560 }catch(java.lang.ExceptionInInitializerError ex){
\r
561 warnln("Could not load NamePrepTransform data");
\r
562 }catch(java.lang.NoClassDefFoundError ex){
\r
563 warnln("Could not load NamePrepTransform data");
\r
566 public void TestRootLabelSeparator() throws Exception{
\r
567 String www = "www.";
\r
568 String com = ".com."; /*root label separator*/
\r
569 StringBuffer source = new StringBuffer(www);
\r
570 StringBuffer uni0 = new StringBuffer(www);
\r
571 StringBuffer uni1 = new StringBuffer(www);
\r
572 StringBuffer ascii0 = new StringBuffer(www);
\r
573 StringBuffer ascii1 = new StringBuffer(www);
\r
575 uni0.append(TestData.unicodeIn[0]);
\r
578 uni1.append(TestData.unicodeIn[1]);
\r
581 ascii0.append(TestData.asciiIn[0]);
\r
582 ascii0.append(com);
\r
584 ascii1.append(TestData.asciiIn[1]);
\r
585 ascii1.append(com);
\r
587 for(int i=0;i< TestData.unicodeIn.length; i++){
\r
589 // for every entry in unicodeIn array
\r
590 // prepend www. and append .com
\r
591 source.setLength(4);
\r
592 source.append(TestData.unicodeIn[i]);
\r
593 source.append(com);
\r
595 // a) compare it with itself
\r
596 doTestCompare(source.toString(),source.toString(),true);
\r
598 // b) compare it with asciiIn equivalent
\r
599 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);
\r
601 // c) compare it with unicodeIn not equivalent
\r
603 doTestCompare(source.toString(), uni1.toString(), false);
\r
605 doTestCompare(source.toString(),uni0.toString(), false);
\r
607 // d) compare it with asciiIn not equivalent
\r
609 doTestCompare(source.toString(),ascii1.toString(), false);
\r
611 doTestCompare(source.toString(),ascii0.toString(), false);
\r
614 }catch(java.lang.ExceptionInInitializerError ex){
\r
615 warnln("Could not load NamePrepTransform data");
\r
616 }catch(java.lang.NoClassDefFoundError ex){
\r
617 warnln("Could not load NamePrepTransform data");
\r