]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/stringprep/TestIDNARef.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / core / src / com / ibm / icu / dev / test / stringprep / TestIDNARef.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2003-2010, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6 */
7 package com.ibm.icu.dev.test.stringprep;
8
9 import com.ibm.icu.dev.test.TestFmwk;
10 import com.ibm.icu.text.StringPrepParseException;
11 import com.ibm.icu.text.UCharacterIterator;
12
13 /**
14  * @author ram
15  *
16  * To change the template for this generated type comment go to
17  * Window>Preferences>Java>Code Generation>Code and Comments
18  */
19 public class TestIDNARef extends TestFmwk {
20     public static void main(String[] args) throws Exception {
21         new TestIDNARef().run(args);
22     }
23     private StringPrepParseException unassignedException = new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR);
24     public void TestToUnicode() throws Exception{
25         try{
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); 
32         
33             }
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");
38         } 
39     }
40     
41     public void TestToASCII() throws Exception{
42         try{
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); 
49         
50             }
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");
55         } 
56     }
57     
58     public void TestIDNToASCII() throws Exception{
59         try{
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);
65             }
66             
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);
72     
73             }
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");
78         } 
79     }
80     public void TestIDNToUnicode() throws Exception{
81         try{
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);
87             }
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);
91             }
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");
96         } 
97     }
98     
99     private void doTestToUnicode(String src, String expected, int options, Object expectedException) 
100                 throws Exception{
101
102         if (!IDNAReference.isReady()) {
103             logln("Transliterator is not available on this environment.  Skipping doTestToUnicode.");
104             return;
105         }
106
107         StringBuffer inBuf = new StringBuffer(src);
108         UCharacterIterator inIter = UCharacterIterator.getInstance(src);
109         try{
110             
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));
115             }
116             if(expectedException!=null && !unassignedException.equals(expectedException)){
117                 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
118             }
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());
122             }
123         }
124         try{
125             
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);
130             }
131             if(expectedException!=null && !unassignedException.equals(expectedException)){
132                 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
133             }
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());
137             }
138         }
139         
140         try{
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));
145             }
146             if(expectedException!=null && !unassignedException.equals(expectedException)){
147                 errln("Did not get the expected exception. The operation succeeded!");
148             }
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());
152             }
153         }
154     }
155     
156     private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException) 
157                 throws Exception{
158
159         if (!IDNAReference.isReady()) {
160             logln("Transliterator is not available on this environment.  Skipping doTestIDNToUnicode.");
161             return;
162         }
163
164         StringBuffer inBuf = new StringBuffer(src);
165         UCharacterIterator inIter = UCharacterIterator.getInstance(src);
166         try{
167             
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));
172             }
173             if(expectedException!=null && !unassignedException.equals(expectedException)){
174                 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
175             }
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());
179             }
180         }
181         try{
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);
186             }
187             if(expectedException!=null && !unassignedException.equals(expectedException)){
188                 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
189             }
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());
193             }
194         }
195         
196         try{
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));
201             }
202             if(expectedException!=null && !unassignedException.equals(expectedException)){
203                 errln("Did not get the expected exception. The operation succeeded!");
204             }
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());
208             }
209         }
210     }
211     private void doTestToASCII(String src, String expected, int options, Object expectedException) 
212                 throws Exception{
213
214         if (!IDNAReference.isReady()) {
215             logln("Transliterator is not available on this environment.  Skipping doTestToASCII.");
216             return;
217         }
218
219         StringBuffer inBuf = new StringBuffer(src);
220         UCharacterIterator inIter = UCharacterIterator.getInstance(src);
221         try{
222             
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);
227             }           
228             if(expectedException!=null && !unassignedException.equals(expectedException)){
229                 errln("convertToASCII did not get the expected exception. The operation succeeded!");
230             }
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());
234             }
235         }
236         
237         try{            
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);
242             }
243             if(expectedException!=null && !unassignedException.equals(expectedException)){
244                 errln("convertToASCII did not get the expected exception. The operation succeeded!");
245             }
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());
249             }
250         }
251         
252         try{
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);
257             }
258             if(expectedException!=null && !unassignedException.equals(expectedException)){
259                 errln("convertToASCII did not get the expected exception. The operation succeeded!");
260             }
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());
264             }
265         }
266     }
267     private void doTestIDNToASCII(String src, String expected, int options, Object expectedException) 
268                 throws Exception{
269
270         if (!IDNAReference.isReady()) {
271             logln("Transliterator is not available on this environment.  Skipping doTestIDNToASCII.");
272             return;
273         }
274
275         StringBuffer inBuf = new StringBuffer(src);
276         UCharacterIterator inIter = UCharacterIterator.getInstance(src);
277         try{
278             
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);
283             }
284             if(expectedException!=null && !unassignedException.equals(expectedException)){
285                 errln("convertToIDNAReferenceASCII did not get the expected exception. The operation succeeded!");
286             }
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());
290             }
291         }
292         try{
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);
297             }           
298             if(expectedException!=null && !unassignedException.equals(expectedException)){
299                 errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!");
300             }
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());
304             }
305         }
306         
307         try{
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);
312             }
313             
314             if(expectedException!=null && !unassignedException.equals(expectedException)){
315                 errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");
316             }
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());
320             }
321         }
322     }
323     public void TestConformance()throws Exception{
324         try{
325             for(int i=0; i<TestData.conformanceTestCases.length;i++){
326                 
327                 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
328                 if(testCase.expected != null){
329                     //Test toASCII
330                     doTestToASCII(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
331                     doTestToASCII(testCase.input,testCase.output,IDNAReference.ALLOW_UNASSIGNED,testCase.expected);
332                 }
333                 //Test toUnicode
334                 //doTestToUnicode(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
335             }
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");
340         } 
341     }
342     public void TestNamePrepConformance() throws Exception{
343         try{
344             NamePrepTransform namePrep = NamePrepTransform.getInstance();
345             if (!namePrep.isReady()) {
346                 logln("Transliterator is not available on this environment.");
347                 return;
348             }
349             for(int i=0; i<TestData.conformanceTestCases.length;i++){
350                 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
351                 UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
352                 try{
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) );
357                     }
358                     if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
359                         errln("Did not get the expected exception. The operation succeeded!");
360                     }
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());
364                     }
365                 }
366                 
367                 try{
368                     iter.setToStart();
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) );
373                     }
374                     if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
375                         errln("Did not get the expected exception. The operation succeeded!");
376                     }
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());
380                     }
381                 }
382             }
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");
387         } 
388         
389     }
390     public void TestErrorCases() throws Exception{
391         try{
392             for(int i=0; i < TestData.errorCases.length; i++){
393                 TestData.ErrorCase errCase = TestData.errorCases[i];
394                 if(errCase.testLabel==true){
395                     // Test ToASCII
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);
400                     }
401                 }
402                 if(errCase.useSTD3ASCIIRules!=true){
403                     
404                     // Test IDNToASCII
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);
407                     
408                 }else{
409                     doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected);
410                 }
411                 
412                 //TestToUnicode
413                 if(errCase.testToUnicode==true){
414                     if(errCase.useSTD3ASCIIRules!=true){
415                         // Test IDNToUnicode
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);
418                     
419                     }else{
420                         doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.USE_STD3_RULES,errCase.expected);
421                     }
422                 }
423             }
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");
428         } 
429     }
430     private void doTestCompare(String s1, String s2, boolean isEqual){
431
432         if (!IDNAReference.isReady()) {
433             logln("Transliterator is not available on this environment.  Skipping doTestCompare.");
434             return;
435         }
436
437         try{
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));
442             }
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));
447             }
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));
452             }
453         }catch(Exception e){
454             e.printStackTrace();
455             errln("Unexpected exception thrown by IDNAReference.compare");
456         }
457         
458         try{
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));
463             }
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));
468             }
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));
473             }
474         }catch(Exception e){
475             errln("Unexpected exception thrown by IDNAReference.compare");
476         }     
477     }
478     public void TestCompare() throws Exception{
479         String www = "www.";
480         String com = ".com";
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);
486
487         uni0.append(TestData.unicodeIn[0]);
488         uni0.append(com);
489
490         uni1.append(TestData.unicodeIn[1]);
491         uni1.append(com);
492
493         ascii0.append(TestData.asciiIn[0]);
494         ascii0.append(com);
495
496         ascii1.append(TestData.asciiIn[1]);
497         ascii1.append(com);
498         try{
499             for(int i=0;i< TestData.unicodeIn.length; i++){
500     
501                 // for every entry in unicodeIn array
502                 // prepend www. and append .com
503                 source.setLength(4);
504                 source.append(TestData.unicodeIn[i]);
505                 source.append(com);
506                 
507                 // a) compare it with itself
508                 doTestCompare(source.toString(),source.toString(),true);
509             
510                 // b) compare it with asciiIn equivalent
511                 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);
512             
513                 // c) compare it with unicodeIn not equivalent
514                 if(i==0){
515                     doTestCompare(source.toString(), uni1.toString(), false);
516                 }else{
517                     doTestCompare(source.toString(),uni0.toString(), false);
518                 }
519                 // d) compare it with asciiIn not equivalent
520                 if(i==0){
521                     doTestCompare(source.toString(),ascii1.toString(), false);
522                 }else{
523                     doTestCompare(source.toString(),ascii0.toString(), false);
524                 }
525             }
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");
530         } 
531     }
532
533     //  test and ascertain
534     //  func(func(func(src))) == func(src)
535     public void doTestChainingToASCII(String source)throws Exception{
536
537         if (!IDNAReference.isReady()) {
538             logln("Transliterator is not available on this environment.  Skipping doTestChainingToASCII.");
539             return;
540         }
541
542         StringBuffer expected; 
543         StringBuffer chained;
544         
545         // test convertIDNToASCII
546         expected = IDNAReference.convertIDNToASCII(source,IDNAReference.DEFAULT);
547         chained = expected;
548         for(int i=0; i< 4; i++){
549             chained = IDNAReference.convertIDNtoASCII(chained,IDNAReference.DEFAULT);
550         }
551         if(!expected.toString().equals(chained.toString())){
552             errln("Chaining test failed for convertIDNToASCII");
553         }
554         // test convertIDNToA
555         expected = IDNAReference.convertToASCII(source,IDNAReference.DEFAULT);
556         chained = expected;
557         for(int i=0; i< 4; i++){
558             chained = IDNAReference.convertToASCII(chained,IDNAReference.DEFAULT);
559         }
560         if(!expected.toString().equals(chained.toString())){
561             errln("Chaining test failed for convertToASCII");
562         } 
563         
564     }
565     //  test and ascertain
566     //  func(func(func(src))) == func(src)
567     public void doTestChainingToUnicode(String source)throws Exception{
568
569         if (!IDNAReference.isReady()) {
570             logln("Transliterator is not available on this environment.  Skipping doTestChainingToUnicode.");
571             return;
572         }
573
574         StringBuffer expected; 
575         StringBuffer chained;
576         
577         // test convertIDNToUnicode
578         expected = IDNAReference.convertIDNToUnicode(source,IDNAReference.DEFAULT);
579         chained = expected;
580         for(int i=0; i< 4; i++){
581             chained = IDNAReference.convertIDNToUnicode(chained,IDNAReference.DEFAULT);
582         }
583         if(!expected.toString().equals(chained.toString())){
584             errln("Chaining test failed for convertIDNToUnicode");
585         }
586         // test convertIDNToA
587         expected = IDNAReference.convertToUnicode(source,IDNAReference.DEFAULT);
588         chained = expected;
589         for(int i=0; i< 4; i++){
590             chained = IDNAReference.convertToUnicode(chained,IDNAReference.DEFAULT);
591         }
592         if(!expected.toString().equals(chained.toString())){
593             errln("Chaining test failed for convertToUnicode");
594         }
595
596     }
597     public void TestChaining() throws Exception{
598         try{
599             for(int i=0; i< TestData.unicodeIn.length; i++){
600                 doTestChainingToASCII(new String(TestData.unicodeIn[i]));
601             }
602             for(int i=0; i< TestData.asciiIn.length; i++){
603                 doTestChainingToUnicode(TestData.asciiIn[i]);
604             }
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");
609         } 
610     }
611     public void TestRootLabelSeparator() throws Exception{
612         String www = "www.";
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);
619
620         uni0.append(TestData.unicodeIn[0]);
621         uni0.append(com);
622
623         uni1.append(TestData.unicodeIn[1]);
624         uni1.append(com);
625
626         ascii0.append(TestData.asciiIn[0]);
627         ascii0.append(com);
628
629         ascii1.append(TestData.asciiIn[1]);
630         ascii1.append(com);
631         try{
632             for(int i=0;i< TestData.unicodeIn.length; i++){
633     
634                 // for every entry in unicodeIn array
635                 // prepend www. and append .com
636                 source.setLength(4);
637                 source.append(TestData.unicodeIn[i]);
638                 source.append(com);
639                 
640                 // a) compare it with itself
641                 doTestCompare(source.toString(),source.toString(),true);
642             
643                 // b) compare it with asciiIn equivalent
644                 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);
645             
646                 // c) compare it with unicodeIn not equivalent
647                 if(i==0){
648                     doTestCompare(source.toString(), uni1.toString(), false);
649                 }else{
650                     doTestCompare(source.toString(),uni0.toString(), false);
651                 }
652                 // d) compare it with asciiIn not equivalent
653                 if(i==0){
654                     doTestCompare(source.toString(),ascii1.toString(), false);
655                 }else{
656                     doTestCompare(source.toString(),ascii0.toString(), false);
657                 }
658             }
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");
663         } 
664
665     }
666 }