]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/tests/core/src/com/ibm/icu/dev/test/stringprep/TestIDNA.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / tests / core / src / com / ibm / icu / dev / test / stringprep / TestIDNA.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 2003-2010, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6 */\r
7 package com.ibm.icu.dev.test.stringprep;\r
8 \r
9 import java.util.Random;\r
10 \r
11 import com.ibm.icu.dev.test.TestFmwk;\r
12 import com.ibm.icu.impl.Utility;\r
13 import com.ibm.icu.text.IDNA;\r
14 import com.ibm.icu.text.StringPrep;\r
15 import com.ibm.icu.text.StringPrepParseException;\r
16 import com.ibm.icu.text.UCharacterIterator;\r
17 import com.ibm.icu.text.UTF16;\r
18 \r
19 /**\r
20  * @author ram\r
21  */\r
22 public class TestIDNA extends TestFmwk {\r
23     public static void main(String[] args) throws Exception {\r
24         new TestIDNA().run(args);\r
25     }\r
26     private StringPrepParseException unassignedException = new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR);\r
27     public void TestToUnicode() throws Exception{\r
28         for(int i=0; i<TestData.asciiIn.length; i++){\r
29             // test StringBuffer toUnicode\r
30             doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNA.DEFAULT, null);\r
31             doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNA.ALLOW_UNASSIGNED, null);\r
32             doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNA.USE_STD3_RULES, null); \r
33             doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNA.USE_STD3_RULES|IDNA.ALLOW_UNASSIGNED, null); \r
34     \r
35         }\r
36     }\r
37     \r
38     public void TestToASCII() throws Exception{\r
39         for(int i=0; i<TestData.asciiIn.length; i++){\r
40             // test StringBuffer toUnicode\r
41             doTestToASCII(new String(TestData.unicodeIn[i]),TestData.asciiIn[i],IDNA.DEFAULT, null);\r
42             doTestToASCII(new String(TestData.unicodeIn[i]),TestData.asciiIn[i],IDNA.ALLOW_UNASSIGNED, null);\r
43             doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNA.USE_STD3_RULES, null); \r
44             doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNA.USE_STD3_RULES|IDNA.ALLOW_UNASSIGNED, null); \r
45     \r
46         }\r
47     }\r
48     \r
49     public void TestIDNToASCII() throws Exception{\r
50         for(int i=0; i<TestData.domainNames.length; i++){\r
51             doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNA.DEFAULT, null);\r
52             doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNA.ALLOW_UNASSIGNED, null);\r
53             doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNA.USE_STD3_RULES, null);\r
54             doTestIDNToASCII(TestData.domainNames[i],TestData.domainNames[i],IDNA.ALLOW_UNASSIGNED|IDNA.USE_STD3_RULES, null);\r
55         }\r
56         \r
57         for(int i=0; i<TestData.domainNames1Uni.length; i++){\r
58             doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNA.DEFAULT, null);\r
59             doTestIDNToASCII(TestData.domainNames1Uni[i],TestData.domainNamesToASCIIOut[i],IDNA.ALLOW_UNASSIGNED, null);\r
60         }\r
61     }\r
62     public void TestIDNToUnicode() throws Exception{\r
63         for(int i=0; i<TestData.domainNames.length; i++){\r
64             doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNA.DEFAULT, null);\r
65             doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNA.ALLOW_UNASSIGNED, null);\r
66             doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNA.USE_STD3_RULES, null);\r
67             doTestIDNToUnicode(TestData.domainNames[i],TestData.domainNames[i],IDNA.ALLOW_UNASSIGNED|IDNA.USE_STD3_RULES, null);\r
68         }\r
69         for(int i=0; i<TestData.domainNamesToASCIIOut.length; i++){\r
70             doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],TestData.domainNamesToUnicodeOut[i],IDNA.DEFAULT, null);\r
71             doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],TestData.domainNamesToUnicodeOut[i],IDNA.ALLOW_UNASSIGNED, null);\r
72         }\r
73     }\r
74     \r
75     private void doTestToUnicode(String src, String expected, int options, Object expectedException) \r
76                 throws Exception{\r
77         StringBuffer inBuf = new StringBuffer(src);\r
78         UCharacterIterator inIter = UCharacterIterator.getInstance(src);\r
79         try{\r
80             \r
81             StringBuffer out = IDNA.convertToUnicode(src,options);\r
82             if(expected!=null && out != null && !out.toString().equals(expected)){\r
83                 errln("convertToUnicode did not return expected result with options : "+ options + \r
84                       " Expected: " + prettify(expected)+" Got: "+prettify(out));\r
85             }\r
86             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
87                 errln("convertToUnicode did not get the expected exception. The operation succeeded!");\r
88             }\r
89         }catch(StringPrepParseException ex){\r
90             if(expectedException == null || !ex.equals(expectedException)){\r
91                 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got:  "+ ex.toString());\r
92             }\r
93         }\r
94         try{\r
95             \r
96             StringBuffer out = IDNA.convertToUnicode(inBuf,options);\r
97             if(expected!=null && out != null && !out.toString().equals(expected)){\r
98                errln("convertToUnicode did not return expected result with options : "+ options + \r
99                      " Expected: " + prettify(expected)+" Got: "+out);\r
100             }\r
101             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
102                 errln("convertToUnicode did not get the expected exception. The operation succeeded!");\r
103             }\r
104         }catch(StringPrepParseException ex){\r
105             if(expectedException == null || !ex.equals(expectedException)){\r
106                 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got:  "+ ex.toString());\r
107             }\r
108         }\r
109         \r
110         try{\r
111             StringBuffer out = IDNA.convertToUnicode(inIter,options);\r
112             if(expected!=null && out != null && !out.toString().equals(expected)){\r
113                errln("convertToUnicode did not return expected result with options : "+ options +\r
114                      " Expected: " + prettify(expected)+" Got: "+prettify(out));\r
115             }\r
116             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
117                 errln("Did not get the expected exception. The operation succeeded!");\r
118             }\r
119         }catch(StringPrepParseException ex){\r
120             if(expectedException == null || !ex.equals(expectedException)){\r
121                 errln("Did not get the expected exception for source: " + prettify(src) +" Got:  "+ ex.toString());\r
122             }\r
123         }\r
124     }\r
125     \r
126     private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException) \r
127                 throws Exception{\r
128         StringBuffer inBuf = new StringBuffer(src);\r
129         UCharacterIterator inIter = UCharacterIterator.getInstance(src);\r
130         try{\r
131             \r
132             StringBuffer out = IDNA.convertIDNToUnicode(src,options);\r
133             if(expected!=null && out != null && !out.toString().equals(expected)){\r
134                 errln("convertToUnicode did not return expected result with options : "+ options + \r
135                       " Expected: " + prettify(expected)+" Got: "+prettify(out));\r
136             }\r
137             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
138                 errln("convertToUnicode did not get the expected exception. The operation succeeded!");\r
139             }\r
140         }catch(StringPrepParseException ex){\r
141             if(expectedException == null || !expectedException.equals(ex)){\r
142                 errln("convertToUnicode did not get the expected exception for source: " +src +" Got:  "+ ex.toString());\r
143             }\r
144         }\r
145         try{\r
146             StringBuffer out = IDNA.convertIDNToUnicode(inBuf,options);\r
147             if(expected!=null && out != null && !out.toString().equals(expected)){\r
148                errln("convertToUnicode did not return expected result with options : "+ options + \r
149                      " Expected: " + prettify(expected)+" Got: "+out);\r
150             }\r
151             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
152                 errln("convertToUnicode did not get the expected exception. The operation succeeded!");\r
153             }\r
154         }catch(StringPrepParseException ex){\r
155             if(expectedException == null || !expectedException.equals(ex)){\r
156                 errln("convertToUnicode did not get the expected exception for source: " +src +" Got:  "+ ex.toString());\r
157             }\r
158         }\r
159         \r
160         try{\r
161             StringBuffer out = IDNA.convertIDNToUnicode(inIter,options);\r
162             if(expected!=null && out != null && !out.toString().equals(expected)){\r
163                errln("convertToUnicode did not return expected result with options : "+ options +\r
164                      " Expected: " + prettify(expected)+" Got: "+prettify(out));\r
165             }\r
166             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
167                 errln("Did not get the expected exception. The operation succeeded!");\r
168             }\r
169         }catch(StringPrepParseException ex){\r
170             if(expectedException == null || !expectedException.equals(ex)){\r
171                 errln("Did not get the expected exception for source: " +src +" Got:  "+ ex.toString());\r
172             }\r
173         }\r
174     }\r
175     private void doTestToASCII(String src, String expected, int options, Object expectedException) \r
176                 throws Exception{\r
177         StringBuffer inBuf = new StringBuffer(src);\r
178         UCharacterIterator inIter = UCharacterIterator.getInstance(src);\r
179         try{\r
180             \r
181             StringBuffer out = IDNA.convertToASCII(src,options);\r
182             if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){\r
183                 errln("convertToASCII did not return expected result with options : "+ options + \r
184                       " Expected: " + expected+" Got: "+out);\r
185             }           \r
186             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
187                 errln("convertToASCII did not get the expected exception. The operation succeeded!");\r
188             }\r
189         }catch(StringPrepParseException ex){\r
190             if(expectedException == null || !expectedException.equals(ex)){\r
191                 errln("convertToASCII did not get the expected exception for source: " +src +"\n Got:  "+ ex.toString() +"\n Expected: " +ex.toString());\r
192             }\r
193         }\r
194         \r
195         try{            \r
196             StringBuffer out = IDNA.convertToASCII(inBuf,options);\r
197             if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){\r
198                errln("convertToASCII did not return expected result with options : "+ options + \r
199                      " Expected: " + expected+" Got: "+out);\r
200             }\r
201             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
202                 errln("convertToASCII did not get the expected exception. The operation succeeded!");\r
203             }\r
204         }catch(StringPrepParseException ex){\r
205             if(expectedException == null || !expectedException.equals(ex)){\r
206                 errln("convertToASCII did not get the expected exception for source: " +src +" Got:  "+ ex.toString());\r
207             }\r
208         }\r
209         \r
210         try{\r
211             StringBuffer out = IDNA.convertToASCII(inIter,options);\r
212             if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){\r
213                errln("convertToASCII did not return expected result with options : "+ options +\r
214                      " Expected: " + expected+" Got: "+ out);\r
215             }\r
216             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
217                 errln("convertToASCII did not get the expected exception. The operation succeeded!");\r
218             }\r
219         }catch(StringPrepParseException ex){\r
220             if(expectedException == null || !expectedException.equals(ex)){\r
221                 errln("convertToASCII did not get the expected exception for source: " +src +" Got:  "+ ex.toString());\r
222             }\r
223         }\r
224     }\r
225     private void doTestIDNToASCII(String src, String expected, int options, Object expectedException) \r
226                 throws Exception{\r
227         StringBuffer inBuf = new StringBuffer(src);\r
228         UCharacterIterator inIter = UCharacterIterator.getInstance(src);\r
229         try{\r
230             \r
231             StringBuffer out = IDNA.convertIDNToASCII(src,options);\r
232             if(expected!=null && out != null && !out.toString().equals(expected)){\r
233                 errln("convertToIDNASCII did not return expected result with options : "+ options + \r
234                       " Expected: " + expected+" Got: "+out);\r
235             }\r
236             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
237                 errln("convertToIDNASCII did not get the expected exception. The operation succeeded!");\r
238             }\r
239         }catch(StringPrepParseException ex){\r
240             if(expectedException == null || !ex.equals(expectedException)){\r
241                 errln("convertToIDNASCII did not get the expected exception for source: " +src +" Got:  "+ ex.toString());\r
242             }\r
243         }\r
244         try{\r
245             StringBuffer out = IDNA.convertIDNToASCII(inBuf,options);\r
246             if(expected!=null && out != null && !out.toString().equals(expected)){\r
247                errln("convertToIDNASCII did not return expected result with options : "+ options + \r
248                      " Expected: " + expected+" Got: "+out);\r
249             }           \r
250             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
251                 errln("convertToIDNASCII did not get the expected exception. The operation succeeded!");\r
252             }\r
253         }catch(StringPrepParseException ex){\r
254             if(expectedException == null || !ex.equals(expectedException)){\r
255                 errln("convertToIDNASCII did not get the expected exception for source: " +src +" Got:  "+ ex.toString());\r
256             }\r
257         }\r
258         \r
259         try{\r
260             StringBuffer out = IDNA.convertIDNToASCII(inIter,options);\r
261             if(expected!=null && out != null && !out.toString().equals(expected)){\r
262                errln("convertIDNToASCII did not return expected result with options : "+ options +\r
263                      " Expected: " + expected+" Got: "+ out);\r
264             }\r
265             \r
266             if(expectedException!=null && !unassignedException.equals(expectedException)){\r
267                 errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");\r
268             }\r
269         }catch(StringPrepParseException ex){\r
270             if(expectedException == null || !ex.equals(expectedException)){\r
271                 errln("convertIDNToASCII did not get the expected exception for source: " +src +" Got:  "+ ex.toString());\r
272             }\r
273         }\r
274     }\r
275     public void TestConformance()throws Exception{\r
276         for(int i=0; i<TestData.conformanceTestCases.length;i++){\r
277             \r
278             TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];\r
279             if(testCase.expected != null){\r
280                 //Test toASCII\r
281                 doTestToASCII(testCase.input,testCase.output,IDNA.DEFAULT,testCase.expected);\r
282                 doTestToASCII(testCase.input,testCase.output,IDNA.ALLOW_UNASSIGNED,testCase.expected);\r
283             }\r
284             //Test toUnicode\r
285             //doTestToUnicode(testCase.input,testCase.output,IDNA.DEFAULT,testCase.expected);\r
286         }\r
287     }\r
288     public void TestNamePrepConformance() throws Exception{\r
289         StringPrep namePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP);\r
290         for(int i=0; i<TestData.conformanceTestCases.length;i++){\r
291             TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];\r
292             UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);\r
293             try{\r
294                 StringBuffer output = namePrep.prepare(iter,StringPrep.DEFAULT);\r
295                 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){\r
296                     errln("Did not get the expected output. Expected: " + prettify(testCase.output)+\r
297                           " Got: "+ prettify(output) );\r
298                 }\r
299                 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){\r
300                     errln("Did not get the expected exception. The operation succeeded!");\r
301                 }\r
302             }catch(StringPrepParseException ex){\r
303                 if(testCase.expected == null || !ex.equals(testCase.expected)){\r
304                     errln("Did not get the expected exception for source: " +testCase.input +" Got:  "+ ex.toString());\r
305                 }\r
306             }\r
307             \r
308             try{\r
309                 iter.setToStart();\r
310                 StringBuffer output = namePrep.prepare(iter,StringPrep.ALLOW_UNASSIGNED);\r
311                 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){\r
312                     errln("Did not get the expected output. Expected: " + prettify(testCase.output)+\r
313                           " Got: "+ prettify(output) );\r
314                 }\r
315                 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){\r
316                     errln("Did not get the expected exception. The operation succeeded!");\r
317                 }\r
318             }catch(StringPrepParseException ex){\r
319                 if(testCase.expected == null || !ex.equals(testCase.expected)){\r
320                     errln("Did not get the expected exception for source: " +testCase.input +" Got:  "+ ex.toString());\r
321                 }\r
322             }\r
323         }\r
324         \r
325     }\r
326     public void TestErrorCases() throws Exception{\r
327         for(int i=0; i < TestData.errorCases.length; i++){\r
328             TestData.ErrorCase errCase = TestData.errorCases[i];\r
329             if(errCase.testLabel==true){\r
330                 // Test ToASCII\r
331                 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNA.DEFAULT,errCase.expected);\r
332                 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNA.ALLOW_UNASSIGNED,errCase.expected);\r
333                 if(errCase.useSTD3ASCIIRules){\r
334                     doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNA.USE_STD3_RULES,errCase.expected);\r
335                 }\r
336             }\r
337             if(errCase.useSTD3ASCIIRules!=true){\r
338                 \r
339                 // Test IDNToASCII\r
340                 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNA.DEFAULT,errCase.expected);\r
341                 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNA.ALLOW_UNASSIGNED,errCase.expected);\r
342                 \r
343             }else{\r
344                 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNA.USE_STD3_RULES,errCase.expected);\r
345             }\r
346             \r
347             //TestToUnicode\r
348             if(false && errCase.testToUnicode==true){\r
349                 if(errCase.useSTD3ASCIIRules!=true){\r
350                     // Test IDNToUnicode\r
351                     doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNA.DEFAULT,errCase.expected);\r
352                     doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNA.ALLOW_UNASSIGNED,errCase.expected);\r
353                 \r
354                 }else{\r
355                     doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNA.USE_STD3_RULES,errCase.expected);\r
356                 }\r
357             }\r
358         }\r
359     }\r
360     private void doTestCompare(String s1, String s2, boolean isEqual){\r
361         try{\r
362             int retVal = IDNA.compare(s1,s2,IDNA.DEFAULT);\r
363             if(isEqual==true && retVal != 0){\r
364                 errln("Did not get the expected result for s1: "+ prettify(s1)+ \r
365                       " s2: "+prettify(s2));\r
366             }\r
367             retVal = IDNA.compare(new StringBuffer(s1), new StringBuffer(s2), IDNA.DEFAULT);\r
368             if(isEqual==true && retVal != 0){\r
369                 errln("Did not get the expected result for s1: "+ prettify(s1)+ \r
370                      " s2: "+prettify(s2));\r
371             }\r
372             retVal = IDNA.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNA.DEFAULT);\r
373             if(isEqual==true && retVal != 0){\r
374                 errln("Did not get the expected result for s1: "+ prettify(s1)+ \r
375                      " s2: "+prettify(s2));\r
376             }\r
377         }catch(Exception e){\r
378             e.printStackTrace();\r
379             errln("Unexpected exception thrown by IDNA.compare");\r
380         }\r
381         \r
382         try{\r
383             int retVal = IDNA.compare(s1,s2,IDNA.ALLOW_UNASSIGNED);\r
384             if(isEqual==true && retVal != 0){\r
385                 errln("Did not get the expected result for s1: "+ prettify(s1)+ \r
386                       " s2: "+prettify(s2));\r
387             }\r
388             retVal = IDNA.compare(new StringBuffer(s1), new StringBuffer(s2), IDNA.ALLOW_UNASSIGNED);\r
389             if(isEqual==true && retVal != 0){\r
390                 errln("Did not get the expected result for s1: "+ prettify(s1)+ \r
391                      " s2: "+prettify(s2));\r
392             }\r
393             retVal = IDNA.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNA.ALLOW_UNASSIGNED);\r
394             if(isEqual==true && retVal != 0){\r
395                 errln("Did not get the expected result for s1: "+ prettify(s1)+ \r
396                      " s2: "+prettify(s2));\r
397             }\r
398         }catch(Exception e){\r
399             errln("Unexpected exception thrown by IDNA.compare");\r
400         }\r
401     }\r
402     public void TestCompare() throws Exception{\r
403         String www = "www.";\r
404         String com = ".com";\r
405         StringBuffer source = new StringBuffer(www);\r
406         StringBuffer uni0   = new StringBuffer(www);\r
407         StringBuffer uni1   = new StringBuffer(www);\r
408         StringBuffer ascii0 = new StringBuffer(www);\r
409         StringBuffer ascii1 = new StringBuffer(www);\r
410 \r
411         uni0.append(TestData.unicodeIn[0]);\r
412         uni0.append(com);\r
413 \r
414         uni1.append(TestData.unicodeIn[1]);\r
415         uni1.append(com);\r
416 \r
417         ascii0.append(TestData.asciiIn[0]);\r
418         ascii0.append(com);\r
419 \r
420         ascii1.append(TestData.asciiIn[1]);\r
421         ascii1.append(com);\r
422 \r
423         for(int i=0;i< TestData.unicodeIn.length; i++){\r
424 \r
425             // for every entry in unicodeIn array\r
426             // prepend www. and append .com\r
427             source.setLength(4);\r
428             source.append(TestData.unicodeIn[i]);\r
429             source.append(com);\r
430             \r
431             // a) compare it with itself\r
432             doTestCompare(source.toString(),source.toString(),true);\r
433         \r
434             // b) compare it with asciiIn equivalent\r
435             doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);\r
436         \r
437             // c) compare it with unicodeIn not equivalent\r
438             if(i==0){\r
439                 doTestCompare(source.toString(), uni1.toString(), false);\r
440             }else{\r
441                 doTestCompare(source.toString(),uni0.toString(), false);\r
442             }\r
443             // d) compare it with asciiIn not equivalent\r
444             if(i==0){\r
445                 doTestCompare(source.toString(),ascii1.toString(), false);\r
446             }else{\r
447                 doTestCompare(source.toString(),ascii0.toString(), false);\r
448             }\r
449 \r
450         }\r
451     }\r
452 \r
453     //  test and ascertain\r
454     //  func(func(func(src))) == func(src)\r
455     public void doTestChainingToASCII(String source)throws Exception{\r
456         StringBuffer expected; \r
457         StringBuffer chained;\r
458         \r
459         // test convertIDNToASCII\r
460         expected = IDNA.convertIDNToASCII(source,IDNA.DEFAULT);\r
461         chained = expected;\r
462         for(int i=0; i< 4; i++){\r
463             chained = IDNA.convertIDNToASCII(chained,IDNA.DEFAULT);\r
464         }\r
465         if(!expected.toString().equals(chained.toString())){\r
466             errln("Chaining test failed for convertIDNToASCII");\r
467         }\r
468         // test convertIDNToA\r
469         expected = IDNA.convertToASCII(source,IDNA.DEFAULT);\r
470         chained = expected;\r
471         for(int i=0; i< 4; i++){\r
472             chained = IDNA.convertToASCII(chained,IDNA.DEFAULT);\r
473         }\r
474         if(!expected.toString().equals(chained.toString())){\r
475             errln("Chaining test failed for convertToASCII");\r
476         }   \r
477     }\r
478     //  test and ascertain\r
479     //  func(func(func(src))) == func(src)\r
480     public void doTestChainingToUnicode(String source)throws Exception{\r
481         StringBuffer expected; \r
482         StringBuffer chained;\r
483         \r
484         // test convertIDNToUnicode\r
485         expected = IDNA.convertIDNToUnicode(source,IDNA.DEFAULT);\r
486         chained = expected;\r
487         for(int i=0; i< 4; i++){\r
488             chained = IDNA.convertIDNToUnicode(chained,IDNA.DEFAULT);\r
489         }\r
490         if(!expected.toString().equals(chained.toString())){\r
491             errln("Chaining test failed for convertIDNToUnicode");\r
492         }\r
493         // test convertIDNToA\r
494         expected = IDNA.convertToUnicode(source,IDNA.DEFAULT);\r
495         chained = expected;\r
496         for(int i=0; i< 4; i++){\r
497             chained = IDNA.convertToUnicode(chained,IDNA.DEFAULT);\r
498         }\r
499         if(!expected.toString().equals(chained.toString())){\r
500             errln("Chaining test failed for convertToUnicode");\r
501         }   \r
502     }\r
503     public void TestChaining() throws Exception{\r
504         for(int i=0; i< TestData.asciiIn.length; i++){\r
505             doTestChainingToUnicode(TestData.asciiIn[i]);\r
506         }\r
507         for(int i=0; i< TestData.unicodeIn.length; i++){\r
508             doTestChainingToASCII(new String(TestData.unicodeIn[i]));\r
509         }\r
510     }\r
511     \r
512 \r
513     /* IDNA RFC Says:\r
514     A label is an individual part of a domain name.  Labels are usually\r
515     shown separated by dots; for example, the domain name\r
516     "www.example.com" is composed of three labels: "www", "example", and\r
517     "com".  (The zero-length root label described in [STD13], which can\r
518     be explicit as in "www.example.com." or implicit as in\r
519     "www.example.com", is not considered a label in this specification.)\r
520     */\r
521     public void TestRootLabelSeparator() throws Exception{\r
522         String www = "www.";\r
523         String com = ".com."; //root label separator\r
524         StringBuffer source = new StringBuffer(www);\r
525         StringBuffer uni0   = new StringBuffer(www);\r
526         StringBuffer uni1   = new StringBuffer(www);\r
527         StringBuffer ascii0 = new StringBuffer(www);\r
528         StringBuffer ascii1 = new StringBuffer(www);\r
529 \r
530         uni0.append(TestData.unicodeIn[0]);\r
531         uni0.append(com);\r
532 \r
533         uni1.append(TestData.unicodeIn[1]);\r
534         uni1.append(com);\r
535 \r
536         ascii0.append(TestData.asciiIn[0]);\r
537         ascii0.append(com);\r
538 \r
539         ascii1.append(TestData.asciiIn[1]);\r
540         ascii1.append(com);\r
541 \r
542         for(int i=0;i< TestData.unicodeIn.length; i++){\r
543 \r
544             // for every entry in unicodeIn array\r
545             // prepend www. and append .com\r
546             source.setLength(4);\r
547             source.append(TestData.unicodeIn[i]);\r
548             source.append(com);\r
549             \r
550             // a) compare it with itself\r
551             doTestCompare(source.toString(),source.toString(),true);\r
552         \r
553             // b) compare it with asciiIn equivalent\r
554             doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);\r
555         \r
556             // c) compare it with unicodeIn not equivalent\r
557             if(i==0){\r
558                 doTestCompare(source.toString(), uni1.toString(), false);\r
559             }else{\r
560                 doTestCompare(source.toString(),uni0.toString(), false);\r
561             }\r
562             // d) compare it with asciiIn not equivalent\r
563             if(i==0){\r
564                 doTestCompare(source.toString(),ascii1.toString(), false);\r
565             }else{\r
566                 doTestCompare(source.toString(),ascii0.toString(), false);\r
567             }\r
568 \r
569         }\r
570 \r
571     }\r
572     \r
573     \r
574     private static final int loopCount = 100;\r
575     private static final int maxCharCount = 15;\r
576    // private static final int maxCodePoint = 0x10ffff;\r
577     private Random random = null;\r
578     \r
579     /**\r
580      * Return a random integer i where 0 <= i < n.\r
581      * A special function that gets random codepoints from planes 0,1,2 and 14\r
582      */\r
583     private int rand_uni()\r
584     {\r
585        int retVal = (int)(random.nextLong()& 0x3FFFF);\r
586        if(retVal >= 0x30000){\r
587            retVal+=0xB0000;\r
588        }\r
589        return retVal;\r
590     }\r
591 \r
592     private int randi(int n){\r
593         return (random.nextInt(0x7fff) % (n+1));\r
594     }\r
595 \r
596     private StringBuffer getTestSource(StringBuffer fillIn) {\r
597         // use uniform seed value from the framework\r
598         if(random==null){\r
599             random = createRandom();\r
600         }\r
601         int i = 0;\r
602         int charCount = (randi(maxCharCount) + 1);\r
603         while (i <charCount ) {\r
604             int codepoint = rand_uni();\r
605             if(codepoint == 0x0000){\r
606                 continue;\r
607             }\r
608             UTF16.append(fillIn, codepoint);\r
609             i++;\r
610         }\r
611         return fillIn;\r
612        \r
613     }\r
614     public void MonkeyTest() throws Exception{\r
615          StringBuffer source = new StringBuffer();\r
616          /* do the monkey test   */       \r
617          for(int i=0; i<loopCount; i++){\r
618              source.setLength(0);\r
619              getTestSource(source);\r
620              doTestCompareReferenceImpl(source);\r
621          }\r
622          \r
623          // test string with embedded null  \r
624          source.append( "\\u0000\\u2109\\u3E1B\\U000E65CA\\U0001CAC5" );\r
625                            \r
626          source = new StringBuffer(Utility.unescape(source.toString()));\r
627          doTestCompareReferenceImpl(source);\r
628          \r
629          //StringBuffer src = new StringBuffer(Utility.unescape("\\uDEE8\\U000E228C\\U0002EE8E\\U000E6350\\U00024DD9\u4049\\U000E0DE4\\U000E448C\\U0001869B\\U000E3380\\U00016A8E\\U000172D5\\U0001C408\\U000E9FB5"));\r
630          //doTestCompareReferenceImpl(src);\r
631          \r
632          //test deletion of code points\r
633          source = new StringBuffer(Utility.unescape("\\u043f\\u00AD\\u034f\\u043e\\u0447\\u0435\\u043c\\u0443\\u0436\\u0435\\u043e\\u043d\\u0438\\u043d\\u0435\\u0433\\u043e\\u0432\\u043e\\u0440\\u044f\\u0442\\u043f\\u043e\\u0440\\u0443\\u0441\\u0441\\u043a\\u0438"));\r
634          StringBuffer expected = new StringBuffer("xn--b1abfaaepdrnnbgefbadotcwatmq2g4l");\r
635          doTestCompareReferenceImpl(source);\r
636          doTestToASCII(source.toString(),expected.toString(), IDNA.DEFAULT, null);\r
637     }\r
638     private void doTestCompareReferenceImpl(StringBuffer src) throws Exception{\r
639         \r
640         StringBuffer label = src;  \r
641 \r
642         StringPrepParseException expected = null;\r
643         StringBuffer ascii = null;\r
644         int options = IDNA.DEFAULT;\r
645         logln("Comparing idnaref_toASCII with uidna_toASCII for input: " + prettify(label));\r
646         try{       \r
647             ascii = IDNAReference.convertToASCII(label, options);\r
648         }catch( StringPrepParseException e){\r
649             expected = e;\r
650             if(e.equals(unassignedException)){\r
651                 options = IDNA.ALLOW_UNASSIGNED;\r
652                 expected = null;\r
653                 try{\r
654                     ascii = IDNAReference.convertToASCII(label, options);\r
655                 }catch( StringPrepParseException ex){\r
656                     expected = ex;                  \r
657                 }\r
658             }\r
659         }\r
660         \r
661         doTestToASCII(label.toString(), \r
662                       (ascii == null) ? null : ascii.toString(),\r
663                       options,\r
664                       expected);\r
665 \r
666         logln("Comparing idnaref_toUnicode with uidna_toUnicode for input: " + prettify(label));\r
667         StringBuffer uni =null;\r
668         \r
669         if(expected == null){\r
670             options = IDNA.DEFAULT;\r
671             try{\r
672                  uni = IDNAReference.convertToUnicode(ascii, options);\r
673             }catch( StringPrepParseException e ){\r
674                 expected = e;\r
675                 if(expected.equals(unassignedException)){\r
676                     options = IDNA.ALLOW_UNASSIGNED;\r
677                     expected = null;\r
678                     try{\r
679                         uni = IDNAReference.convertToUnicode(ascii, options);\r
680                     }catch(StringPrepParseException ex){\r
681                         expected = ex;\r
682                     }\r
683                 }\r
684             }\r
685             doTestToUnicode(ascii.toString(),\r
686                             (uni==null)? null : uni.toString(),\r
687                             options,\r
688                             expected);\r
689         }\r
690 \r
691     }\r
692     public void TestCompareRefImpl() throws Exception{\r
693         \r
694         for(int i = 0x40000 ; i< 0x10ffff; i++){\r
695             StringBuffer src = new StringBuffer();\r
696            \r
697             if(isQuick()==true && i> 0x1FFFF){\r
698                 return;\r
699             }\r
700             if(i >= 0x30000 && i<=0xf0000){\r
701                i+=0xB0000;\r
702             }\r
703             UTF16.append(src,i);\r
704             doTestCompareReferenceImpl(src);\r
705 \r
706         }  \r
707     }\r
708     public void TestUnicode32Norm() {\r
709         // This test fails - is this because of the new Noramlizer implementation?\r
710         // Revisit this after 4.4.\r
711         if (skipIfBeforeICU(4,5,1)) {\r
712             logln("Skipping TestUnicode32Norm");\r
713             return;\r
714         }\r
715 \r
716         /*\r
717          * test Unicode 3.2 normalization, before Public Review Issue #29\r
718          * see cnormtst.c TestComposition()\r
719          */\r
720         final String strings[]={\r
721             "\u1100\u0300\u1161\u0327",\r
722             "\u0b47\u0300\u0b3e\u0327"\r
723         };\r
724 \r
725         String ascii = null, unicode = null;\r
726         int i;\r
727 \r
728         for(i=0; i<strings.length; ++i) {\r
729             try {\r
730                 ascii=IDNA.convertToASCII(strings[i], 0).toString();\r
731                 unicode=IDNA.convertToUnicode(ascii, 0).toString();\r
732             } catch(StringPrepParseException ex) {\r
733                 errln("string " + i + " gets exception " + ex.toString());\r
734             }\r
735             \r
736             if(unicode == null || unicode.compareTo(ascii) != 0) {\r
737                 String uc = unicode == null? "(null)" : unicode;\r
738                 \r
739                 errln("string " + i + " yields " + uc +" instead of " + ascii);\r
740             }\r
741         }\r
742     }\r
743     public void TestJB4490(){\r
744         String[] in = new String[]{\r
745                 "\u00F5\u00dE\u00dF\u00dD",\r
746                 "\uFB00\uFB01"\r
747                };\r
748         for ( int i=0; i< in.length; i++){   \r
749             try{\r
750                 String ascii = IDNA.convertToASCII(in[i],IDNA.DEFAULT).toString();\r
751                 try{\r
752                     String unicode = IDNA.convertToUnicode(ascii,IDNA.DEFAULT).toString();\r
753                     logln("result " + unicode);\r
754                 }catch(StringPrepParseException ex){\r
755                     errln("Unexpected exception for convertToUnicode: " + ex.getMessage());\r
756                 }\r
757             }catch(StringPrepParseException ex){\r
758                 errln("Unexpected exception for convertToASCII: " + ex.getMessage());\r
759             }\r
760         }\r
761     }\r
762     public void TestJB4475(){\r
763         String[] in = new String[]{\r
764                         "TEST",\r
765                         "test"\r
766                        };\r
767         for ( int i=0; i< in.length; i++){\r
768             \r
769             try{\r
770                 String ascii = IDNA.convertToASCII(in[i],IDNA.DEFAULT).toString();\r
771                 if(!ascii.equals(in[i])){\r
772                     errln("Did not get the expected string for convertToASCII. Expected: "+ in[i] +" Got: " + ascii);\r
773                 }\r
774             }catch(StringPrepParseException ex){\r
775                 errln("Unexpected exception: " + ex.getMessage());\r
776             }\r
777         }\r
778             \r
779     }\r
780         \r
781     public void TestDebug(){     \r
782         try{\r
783             String src = "\u00ED4dn";\r
784             String uni = IDNA.convertToUnicode(src,IDNA.DEFAULT).toString();\r
785             if(!uni.equals(src)){\r
786                 errln("Did not get the expected result. Expected: "+ prettify(src) +" Got: " +uni);\r
787             }\r
788         }catch(StringPrepParseException ex){\r
789             logln("Unexpected exception: " + ex.getMessage());\r
790         }\r
791         try{\r
792             String ascii = IDNA.convertToASCII("\u00AD",IDNA.DEFAULT).toString();\r
793             if(ascii!=null){\r
794                 errln("Did not get the expected exception");\r
795             }\r
796         }catch(StringPrepParseException ex){\r
797             logln("Got the expected exception: " + ex.getMessage());\r
798         }\r
799     }\r
800     public void TestJB5273(){\r
801         String INVALID_DOMAIN_NAME = "xn--m\u00FCller.de";\r
802         try {\r
803             IDNA.convertIDNToUnicode(INVALID_DOMAIN_NAME, IDNA.DEFAULT);\r
804             IDNA.convertIDNToUnicode(INVALID_DOMAIN_NAME, IDNA.USE_STD3_RULES);\r
805 \r
806         } catch (StringPrepParseException ex) {\r
807             errln("Unexpected exception: " + ex.getMessage());\r
808         } catch (ArrayIndexOutOfBoundsException ex) {\r
809             errln("Got an ArrayIndexOutOfBoundsException calling convertIDNToUnicode(\"" + INVALID_DOMAIN_NAME + "\")");\r
810         }\r
811         \r
812         String domain = "xn--m\u00FCller.de";\r
813         try{\r
814             IDNA.convertIDNToUnicode(domain, IDNA.DEFAULT);\r
815         }catch(StringPrepParseException ex){\r
816             logln("Got the expected exception. "+ex.getMessage());\r
817         }catch (Exception ex){\r
818             errln("Unexpected exception: " + ex.getMessage());\r
819         }\r
820         try{\r
821             IDNA.convertIDNToUnicode(domain, IDNA.USE_STD3_RULES);\r
822         }catch(StringPrepParseException ex){\r
823             logln("Got the expected exception. "+ex.getMessage());\r
824         }catch (Exception ex){\r
825             errln("Unexpected exception: " + ex.getMessage());\r
826         }\r
827         try{\r
828             IDNA.convertToUnicode("xn--m\u00FCller", IDNA.DEFAULT);\r
829         }catch(Exception ex){\r
830             errln("ToUnicode operation failed! "+ex.getMessage());\r
831         }\r
832         try{\r
833             IDNA.convertToUnicode("xn--m\u00FCller", IDNA.USE_STD3_RULES);\r
834         }catch(Exception ex){\r
835             errln("ToUnicode operation failed! "+ex.getMessage());\r
836         }\r
837         try{\r
838             IDNA.convertIDNToUnicode("xn--m\u1234ller", IDNA.USE_STD3_RULES);\r
839         }catch(StringPrepParseException ex){\r
840             errln("ToUnicode operation failed! "+ex.getMessage());\r
841         }\r
842     }\r
843     \r
844     public void TestLength(){\r
845         String ul = "my_very_very_very_very_very_very_very_very_very_very_very_very_very_long_and_incredibly_uncreative_domain_label";\r
846 \r
847         /* this unicode string is longer than MAX_LABEL_BUFFER_SIZE and produces an \r
848            IDNA prepared string (including xn--)that is exactly 63 bytes long */\r
849         String ul1 ="\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774"+\r
850                     "\uD55C\uAD6D\uC5B4\uB97C\uC774\u00AD\u034F\u1806\u180B"+\r
851                     "\u180C\u180D\u200B\u200C\u200D\u2060\uFE00\uFE01\uFE02"+\r
852                     "\uFE03\uFE04\uFE05\uFE06\uFE07\uFE08\uFE09\uFE0A\uFE0B"+\r
853                     "\uFE0C\uFE0D\uFE0E\uFE0F\uFEFF\uD574\uD55C\uB2E4\uBA74"+\r
854                     "\uC138\u0041\u00AD\u034F\u1806\u180B\u180C\u180D\u200B"+\r
855                     "\u200C\u200D\u2060\uFE00\uFE01\uFE02\uFE03\uFE04\uFE05"+\r
856                     "\uFE06\uFE07\uFE08\uFE09\uFE0A\uFE0B\uFE0C\uFE0D\uFE0E"+\r
857                     "\uFE0F\uFEFF\u00AD\u034F\u1806\u180B\u180C\u180D\u200B"+\r
858                     "\u200C\u200D\u2060\uFE00\uFE01\uFE02\uFE03\uFE04\uFE05"+\r
859                     "\uFE06\uFE07\uFE08\uFE09\uFE0A\uFE0B\uFE0C\uFE0D\uFE0E"+\r
860                     "\uFE0F\uFEFF\u00AD\u034F\u1806\u180B\u180C\u180D\u200B"+\r
861                     "\u200C\u200D\u2060\uFE00\uFE01\uFE02\uFE03\uFE04\uFE05"+\r
862                     "\uFE06\uFE07\uFE08\uFE09\uFE0A\uFE0B\uFE0C\uFE0D\uFE0E"+\r
863                     "\uFE0F\uFEFF";\r
864         try{\r
865             IDNA.convertToASCII(ul, IDNA.DEFAULT);\r
866             errln("IDNA.convertToUnicode did not fail!");\r
867         }catch (StringPrepParseException ex){\r
868             if(ex.getError()!= StringPrepParseException.LABEL_TOO_LONG_ERROR){\r
869                 errln("IDNA.convertToASCII failed with error: "+ex.toString());\r
870             }else{\r
871                 logln("IDNA.convertToASCII(ul, IDNA.DEFAULT) Succeeded");\r
872             }\r
873         }\r
874         try{\r
875             IDNA.convertToASCII(ul1, IDNA.DEFAULT);\r
876         }catch (StringPrepParseException ex){\r
877             errln("IDNA.convertToASCII failed with error: "+ex.toString());\r
878         }\r
879         try{\r
880             IDNA.convertToUnicode(ul1, IDNA.DEFAULT);\r
881         }catch (StringPrepParseException ex){\r
882             errln("IDNA.convertToASCII failed with error: "+ex.toString());\r
883         }\r
884         try{\r
885             IDNA.convertToUnicode(ul, IDNA.DEFAULT);\r
886         }catch (StringPrepParseException ex){\r
887             errln("IDNA.convertToASCII failed with error: "+ex.toString());\r
888         }\r
889         \r
890         String idn = "my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.ibm.com";\r
891         try{\r
892             IDNA.convertIDNToASCII(idn, IDNA.DEFAULT);\r
893             errln("IDNA.convertToUnicode did not fail!");\r
894         }catch (StringPrepParseException ex){\r
895             if(ex.getError()!= StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR){\r
896                 errln("IDNA.convertToASCII failed with error: "+ex.toString());\r
897             }else{\r
898                 logln("IDNA.convertToASCII(idn, IDNA.DEFAULT) Succeeded");\r
899             }\r
900         }\r
901         try{\r
902             IDNA.convertIDNToUnicode(idn, IDNA.DEFAULT);\r
903             errln("IDNA.convertToUnicode did not fail!");  \r
904         }catch (StringPrepParseException ex){\r
905             if(ex.getError()!= StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR){\r
906                 errln("IDNA.convertToUnicode failed with error: "+ex.toString());\r
907             }else{\r
908                 logln("IDNA.convertToUnicode(idn, IDNA.DEFAULT) Succeeded");\r
909             }\r
910         }\r
911     }\r
912     \r
913     /* Tests the method public static StringBuffer convertToASCII(String src, int options) */\r
914     public void TestConvertToASCII() {\r
915         try {\r
916             if (!IDNA.convertToASCII("dummy", 0).toString().equals("dummy")) {\r
917                 errln("IDNA.convertToASCII(String,int) was suppose to return the same string passed.");\r
918             }\r
919         } catch (Exception e) {\r
920             errln("IDNA.convertToASCII(String,int) was not suppose to return an exception.");\r
921         }\r
922     }\r
923 \r
924     /*\r
925      * Tests the method public static StringBuffer convertIDNToASCII(UCharacterIterator src, int options), method public\r
926      * static StringBuffer public static StringBuffer convertIDNToASCII(StringBuffer src, int options), public static\r
927      * StringBuffer convertIDNToASCII(UCharacterIterator src, int options)\r
928      */\r
929     public void TestConvertIDNToASCII() {\r
930         try {\r
931             UCharacterIterator uci = UCharacterIterator.getInstance("dummy");\r
932             if (!IDNA.convertIDNToASCII(uci, 0).toString().equals("dummy")) {\r
933                 errln("IDNA.convertIDNToASCII(UCharacterIterator, int) was suppose to "\r
934                         + "return the same string passed.");\r
935             }\r
936             if (!IDNA.convertIDNToASCII(new StringBuffer("dummy"), 0).toString().equals("dummy")) {\r
937                 errln("IDNA.convertIDNToASCII(StringBuffer, int) was suppose to " + "return the same string passed.");\r
938             }\r
939         } catch (Exception e) {\r
940             errln("IDNA.convertIDNToASCII was not suppose to return an exception.");\r
941         }\r
942     }\r
943 \r
944     /*\r
945      * Tests the method public static StringBuffer convertToUnicode(String src, int options), public static StringBuffer\r
946      * convertToUnicode(StringBuffer src, int options)\r
947      */\r
948     public void TestConvertToUnicode() {\r
949         try {\r
950             if (!IDNA.convertToUnicode("dummy", 0).toString().equals("dummy")) {\r
951                 errln("IDNA.convertToUnicode(String, int) was suppose to " + "return the same string passed.");\r
952             }\r
953             if (!IDNA.convertToUnicode(new StringBuffer("dummy"), 0).toString().equals("dummy")) {\r
954                 errln("IDNA.convertToUnicode(StringBuffer, int) was suppose to " + "return the same string passed.");\r
955             }\r
956         } catch (Exception e) {\r
957             errln("IDNA.convertToUnicode was not suppose to return an exception.");\r
958         }\r
959     }\r
960 \r
961     /* Tests the method public static StringBuffer convertIDNToUnicode(UCharacterIterator src, int options) */\r
962     public void TestConvertIDNToUnicode() {\r
963         try {\r
964             UCharacterIterator uci = UCharacterIterator.getInstance("dummy");\r
965             if (!IDNA.convertIDNToUnicode(uci, 0).toString().equals("dummy")) {\r
966                 errln("IDNA.convertIDNToUnicode(UCharacterIterator, int) was suppose to "\r
967                         + "return the same string passed.");\r
968             }\r
969             if (!IDNA.convertIDNToUnicode(new StringBuffer("dummy"), 0).toString().equals("dummy")) {\r
970                 errln("IDNA.convertIDNToUnicode(StringBuffer, int) was suppose to " + "return the same string passed.");\r
971             }\r
972         } catch (Exception e) {\r
973             errln("IDNA.convertIDNToUnicode was not suppose to return an exception.");\r
974         }\r
975     }\r
976 \r
977     /* Tests the method public static int compare */\r
978     public void TestIDNACompare() {\r
979         // Testing the method public static int compare(String s1, String s2, int options)\r
980         try {\r
981             IDNA.compare((String) null, (String) null, 0);\r
982             errln("IDNA.compare((String)null,(String)null) was suppose to return an exception.");\r
983         } catch (Exception e) {\r
984         }\r
985 \r
986         try {\r
987             IDNA.compare((String) null, "dummy", 0);\r
988             errln("IDNA.compare((String)null,'dummy') was suppose to return an exception.");\r
989         } catch (Exception e) {\r
990         }\r
991 \r
992         try {\r
993             IDNA.compare("dummy", (String) null, 0);\r
994             errln("IDNA.compare('dummy',(String)null) was suppose to return an exception.");\r
995         } catch (Exception e) {\r
996         }\r
997 \r
998         try {\r
999             if (IDNA.compare("dummy", "dummy", 0) != 0) {\r
1000                 errln("IDNA.compare('dummy','dummy') was suppose to return a 0.");\r
1001             }\r
1002         } catch (Exception e) {\r
1003             errln("IDNA.compare('dummy','dummy') was not suppose to return an exception.");\r
1004         }\r
1005 \r
1006         // Testing the method public static int compare(StringBuffer s1, StringBuffer s2, int options)\r
1007         try {\r
1008             IDNA.compare((StringBuffer) null, (StringBuffer) null, 0);\r
1009             errln("IDNA.compare((StringBuffer)null,(StringBuffer)null) was suppose to return an exception.");\r
1010         } catch (Exception e) {\r
1011         }\r
1012 \r
1013         try {\r
1014             IDNA.compare((StringBuffer) null, new StringBuffer("dummy"), 0);\r
1015             errln("IDNA.compare((StringBuffer)null,'dummy') was suppose to return an exception.");\r
1016         } catch (Exception e) {\r
1017         }\r
1018 \r
1019         try {\r
1020             IDNA.compare(new StringBuffer("dummy"), (StringBuffer) null, 0);\r
1021             errln("IDNA.compare('dummy',(StringBuffer)null) was suppose to return an exception.");\r
1022         } catch (Exception e) {\r
1023         }\r
1024 \r
1025         try {\r
1026             if (IDNA.compare(new StringBuffer("dummy"), new StringBuffer("dummy"), 0) != 0) {\r
1027                 errln("IDNA.compare(new StringBuffer('dummy'),new StringBuffer('dummy')) was suppose to return a 0.");\r
1028             }\r
1029         } catch (Exception e) {\r
1030             errln("IDNA.compare(new StringBuffer('dummy'),new StringBuffer('dummy')) was not suppose to return an exception.");\r
1031         }\r
1032 \r
1033         // Testing the method public static int compare(UCharacterIterator s1, UCharacterIterator s2, int options)\r
1034         UCharacterIterator uci = UCharacterIterator.getInstance("dummy");\r
1035         try {\r
1036             IDNA.compare((UCharacterIterator) null, (UCharacterIterator) null, 0);\r
1037             errln("IDNA.compare((UCharacterIterator)null,(UCharacterIterator)null) was suppose to return an exception.");\r
1038         } catch (Exception e) {\r
1039         }\r
1040 \r
1041         try {\r
1042             IDNA.compare((UCharacterIterator) null, uci, 0);\r
1043             errln("IDNA.compare((UCharacterIterator)null,UCharacterIterator) was suppose to return an exception.");\r
1044         } catch (Exception e) {\r
1045         }\r
1046 \r
1047         try {\r
1048             IDNA.compare(uci, (UCharacterIterator) null, 0);\r
1049             errln("IDNA.compare(UCharacterIterator,(UCharacterIterator)null) was suppose to return an exception.");\r
1050         } catch (Exception e) {\r
1051         }\r
1052 \r
1053         try {\r
1054             if (IDNA.compare(uci, uci, 0) != 0) {\r
1055                 errln("IDNA.compare(UCharacterIterator('dummy'),UCharacterIterator('dummy')) was suppose to return a 0.");\r
1056             }\r
1057         } catch (Exception e) {\r
1058             errln("IDNA.compare(UCharacterIterator('dummy'),UCharacterIterator('dummy')) was not suppose to return an exception.");\r
1059         }\r
1060     }\r
1061 }\r