2 *******************************************************************************
\r
3 * Copyright (C) 2003-2010, 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
102 if (!IDNAReference.isReady()) {
\r
103 logln("Transliterator is not available on this environment. Skipping doTestToUnicode.");
\r
107 StringBuffer inBuf = new StringBuffer(src);
\r
108 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
\r
111 StringBuffer out = IDNAReference.convertToUnicode(src,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
116 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
117 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
\r
119 }catch(StringPrepParseException ex){
\r
120 if(expectedException == null || !ex.equals(expectedException)){
\r
121 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
\r
126 StringBuffer out = IDNAReference.convertToUnicode(inBuf,options);
\r
127 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
128 errln("convertToUnicode did not return expected result with options : "+ options +
\r
129 " Expected: " + prettify(expected)+" Got: "+out);
\r
131 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
132 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
\r
134 }catch(StringPrepParseException ex){
\r
135 if(expectedException == null || !ex.equals(expectedException)){
\r
136 errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
\r
141 StringBuffer out = IDNAReference.convertToUnicode(inIter,options);
\r
142 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
143 errln("convertToUnicode did not return expected result with options : "+ options +
\r
144 " Expected: " + prettify(expected)+" Got: "+prettify(out));
\r
146 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
147 errln("Did not get the expected exception. The operation succeeded!");
\r
149 }catch(StringPrepParseException ex){
\r
150 if(expectedException == null || !ex.equals(expectedException)){
\r
151 errln("Did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
\r
156 private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException)
\r
159 if (!IDNAReference.isReady()) {
\r
160 logln("Transliterator is not available on this environment. Skipping doTestIDNToUnicode.");
\r
164 StringBuffer inBuf = new StringBuffer(src);
\r
165 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
\r
168 StringBuffer out = IDNAReference.convertIDNToUnicode(src,options);
\r
169 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
170 errln("convertToUnicode did not return expected result with options : "+ options +
\r
171 " Expected: " + prettify(expected)+" Got: "+prettify(out));
\r
173 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
174 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
\r
176 }catch(StringPrepParseException ex){
\r
177 if(expectedException == null || !expectedException.equals(ex)){
\r
178 errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
182 StringBuffer out = IDNAReference.convertIDNToUnicode(inBuf,options);
\r
183 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
184 errln("convertToUnicode did not return expected result with options : "+ options +
\r
185 " Expected: " + prettify(expected)+" Got: "+out);
\r
187 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
188 errln("convertToUnicode did not get the expected exception. The operation succeeded!");
\r
190 }catch(StringPrepParseException ex){
\r
191 if(expectedException == null || !expectedException.equals(ex)){
\r
192 errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
197 StringBuffer out = IDNAReference.convertIDNToUnicode(inIter,options);
\r
198 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
199 errln("convertToUnicode did not return expected result with options : "+ options +
\r
200 " Expected: " + prettify(expected)+" Got: "+prettify(out));
\r
202 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
203 errln("Did not get the expected exception. The operation succeeded!");
\r
205 }catch(StringPrepParseException ex){
\r
206 if(expectedException == null || !expectedException.equals(ex)){
\r
207 errln("Did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
211 private void doTestToASCII(String src, String expected, int options, Object expectedException)
\r
214 if (!IDNAReference.isReady()) {
\r
215 logln("Transliterator is not available on this environment. Skipping doTestToASCII.");
\r
219 StringBuffer inBuf = new StringBuffer(src);
\r
220 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
\r
223 StringBuffer out = IDNAReference.convertToASCII(src,options);
\r
224 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
\r
225 errln("convertToASCII did not return expected result with options : "+ options +
\r
226 " Expected: " + expected+" Got: "+out);
\r
228 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
229 errln("convertToASCII did not get the expected exception. The operation succeeded!");
\r
231 }catch(StringPrepParseException ex){
\r
232 if(expectedException == null || !expectedException.equals(ex)){
\r
233 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
238 StringBuffer out = IDNAReference.convertToASCII(inBuf,options);
\r
239 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
\r
240 errln("convertToASCII did not return expected result with options : "+ options +
\r
241 " Expected: " + expected+" Got: "+out);
\r
243 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
244 errln("convertToASCII did not get the expected exception. The operation succeeded!");
\r
246 }catch(StringPrepParseException ex){
\r
247 if(expectedException == null || !expectedException.equals(ex)){
\r
248 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
253 StringBuffer out = IDNAReference.convertToASCII(inIter,options);
\r
254 if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
\r
255 errln("convertToASCII did not return expected result with options : "+ options +
\r
256 " Expected: " + expected+" Got: "+ out);
\r
258 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
259 errln("convertToASCII did not get the expected exception. The operation succeeded!");
\r
261 }catch(StringPrepParseException ex){
\r
262 if(expectedException == null || !expectedException.equals(ex)){
\r
263 errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
267 private void doTestIDNToASCII(String src, String expected, int options, Object expectedException)
\r
270 if (!IDNAReference.isReady()) {
\r
271 logln("Transliterator is not available on this environment. Skipping doTestIDNToASCII.");
\r
275 StringBuffer inBuf = new StringBuffer(src);
\r
276 UCharacterIterator inIter = UCharacterIterator.getInstance(src);
\r
279 StringBuffer out = IDNAReference.convertIDNToASCII(src,options);
\r
280 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
281 errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options +
\r
282 " Expected: " + expected+" Got: "+out);
\r
284 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
285 errln("convertToIDNAReferenceASCII did not get the expected exception. The operation succeeded!");
\r
287 }catch(StringPrepParseException ex){
\r
288 if(expectedException == null || !ex.equals(expectedException)){
\r
289 errln("convertToIDNAReferenceASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
293 StringBuffer out = IDNAReference.convertIDNtoASCII(inBuf,options);
\r
294 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
295 errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options +
\r
296 " Expected: " + expected+" Got: "+out);
\r
298 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
299 errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!");
\r
301 }catch(StringPrepParseException ex){
\r
302 if(expectedException == null || !ex.equals(expectedException)){
\r
303 errln("convertToIDNAReferenceSCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
308 StringBuffer out = IDNAReference.convertIDNtoASCII(inIter,options);
\r
309 if(expected!=null && out != null && !out.toString().equals(expected)){
\r
310 errln("convertIDNToASCII did not return expected result with options : "+ options +
\r
311 " Expected: " + expected+" Got: "+ out);
\r
314 if(expectedException!=null && !unassignedException.equals(expectedException)){
\r
315 errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");
\r
317 }catch(StringPrepParseException ex){
\r
318 if(expectedException == null || !ex.equals(expectedException)){
\r
319 errln("convertIDNToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
\r
323 public void TestConformance()throws Exception{
\r
325 for(int i=0; i<TestData.conformanceTestCases.length;i++){
\r
327 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
\r
328 if(testCase.expected != null){
\r
330 doTestToASCII(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
\r
331 doTestToASCII(testCase.input,testCase.output,IDNAReference.ALLOW_UNASSIGNED,testCase.expected);
\r
334 //doTestToUnicode(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
\r
336 }catch(java.lang.ExceptionInInitializerError ex){
\r
337 warnln("Could not load NamePrepTransform data");
\r
338 }catch(java.lang.NoClassDefFoundError ex){
\r
339 warnln("Could not load NamePrepTransform data");
\r
342 public void TestNamePrepConformance() throws Exception{
\r
344 NamePrepTransform namePrep = NamePrepTransform.getInstance();
\r
345 if (!namePrep.isReady()) {
\r
346 logln("Transliterator is not available on this environment.");
\r
349 for(int i=0; i<TestData.conformanceTestCases.length;i++){
\r
350 TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
\r
351 UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
\r
353 StringBuffer output = namePrep.prepare(iter,NamePrepTransform.NONE);
\r
354 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
\r
355 errln("Did not get the expected output. Expected: " + prettify(testCase.output)+
\r
356 " Got: "+ prettify(output) );
\r
358 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
\r
359 errln("Did not get the expected exception. The operation succeeded!");
\r
361 }catch(StringPrepParseException ex){
\r
362 if(testCase.expected == null || !ex.equals(testCase.expected)){
\r
363 errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
\r
369 StringBuffer output = namePrep.prepare(iter,NamePrepTransform.ALLOW_UNASSIGNED);
\r
370 if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
\r
371 errln("Did not get the expected output. Expected: " + prettify(testCase.output)+
\r
372 " Got: "+ prettify(output) );
\r
374 if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
\r
375 errln("Did not get the expected exception. The operation succeeded!");
\r
377 }catch(StringPrepParseException ex){
\r
378 if(testCase.expected == null || !ex.equals(testCase.expected)){
\r
379 errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
\r
383 }catch(java.lang.ExceptionInInitializerError e){
\r
384 warnln("Could not load NamePrepTransformData");
\r
385 }catch(java.lang.NoClassDefFoundError ex){
\r
386 warnln("Could not load NamePrepTransform data");
\r
390 public void TestErrorCases() throws Exception{
\r
392 for(int i=0; i < TestData.errorCases.length; i++){
\r
393 TestData.ErrorCase errCase = TestData.errorCases[i];
\r
394 if(errCase.testLabel==true){
\r
396 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.DEFAULT,errCase.expected);
\r
397 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
\r
398 if(errCase.useSTD3ASCIIRules){
\r
399 doTestToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected);
\r
402 if(errCase.useSTD3ASCIIRules!=true){
\r
405 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.DEFAULT,errCase.expected);
\r
406 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
\r
409 doTestIDNToASCII(new String(errCase.unicode),errCase.ascii,IDNAReference.USE_STD3_RULES,errCase.expected);
\r
413 if(errCase.testToUnicode==true){
\r
414 if(errCase.useSTD3ASCIIRules!=true){
\r
415 // Test IDNToUnicode
\r
416 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.DEFAULT,errCase.expected);
\r
417 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.ALLOW_UNASSIGNED,errCase.expected);
\r
420 doTestIDNToUnicode(errCase.ascii,new String(errCase.unicode),IDNAReference.USE_STD3_RULES,errCase.expected);
\r
424 }catch(java.lang.ExceptionInInitializerError ex){
\r
425 warnln("Could not load NamePrepTransform data");
\r
426 }catch(java.lang.NoClassDefFoundError ex){
\r
427 warnln("Could not load NamePrepTransform data");
\r
430 private void doTestCompare(String s1, String s2, boolean isEqual){
\r
432 if (!IDNAReference.isReady()) {
\r
433 logln("Transliterator is not available on this environment. Skipping doTestCompare.");
\r
438 int retVal = IDNAReference.compare(s1,s2,IDNAReference.DEFAULT);
\r
439 if(isEqual==true && retVal != 0){
\r
440 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
441 " s2: "+prettify(s2));
\r
443 retVal = IDNAReference.compare(new StringBuffer(s1), new StringBuffer(s2), IDNAReference.DEFAULT);
\r
444 if(isEqual==true && retVal != 0){
\r
445 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
446 " s2: "+prettify(s2));
\r
448 retVal = IDNAReference.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNAReference.DEFAULT);
\r
449 if(isEqual==true && retVal != 0){
\r
450 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
451 " s2: "+prettify(s2));
\r
453 }catch(Exception e){
\r
454 e.printStackTrace();
\r
455 errln("Unexpected exception thrown by IDNAReference.compare");
\r
459 int retVal = IDNAReference.compare(s1,s2,IDNAReference.ALLOW_UNASSIGNED);
\r
460 if(isEqual==true && retVal != 0){
\r
461 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
462 " s2: "+prettify(s2));
\r
464 retVal = IDNAReference.compare(new StringBuffer(s1), new StringBuffer(s2), IDNAReference.ALLOW_UNASSIGNED);
\r
465 if(isEqual==true && retVal != 0){
\r
466 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
467 " s2: "+prettify(s2));
\r
469 retVal = IDNAReference.compare(UCharacterIterator.getInstance(s1), UCharacterIterator.getInstance(s2), IDNAReference.ALLOW_UNASSIGNED);
\r
470 if(isEqual==true && retVal != 0){
\r
471 errln("Did not get the expected result for s1: "+ prettify(s1)+
\r
472 " s2: "+prettify(s2));
\r
474 }catch(Exception e){
\r
475 errln("Unexpected exception thrown by IDNAReference.compare");
\r
478 public void TestCompare() throws Exception{
\r
479 String www = "www.";
\r
480 String com = ".com";
\r
481 StringBuffer source = new StringBuffer(www);
\r
482 StringBuffer uni0 = new StringBuffer(www);
\r
483 StringBuffer uni1 = new StringBuffer(www);
\r
484 StringBuffer ascii0 = new StringBuffer(www);
\r
485 StringBuffer ascii1 = new StringBuffer(www);
\r
487 uni0.append(TestData.unicodeIn[0]);
\r
490 uni1.append(TestData.unicodeIn[1]);
\r
493 ascii0.append(TestData.asciiIn[0]);
\r
494 ascii0.append(com);
\r
496 ascii1.append(TestData.asciiIn[1]);
\r
497 ascii1.append(com);
\r
499 for(int i=0;i< TestData.unicodeIn.length; i++){
\r
501 // for every entry in unicodeIn array
\r
502 // prepend www. and append .com
\r
503 source.setLength(4);
\r
504 source.append(TestData.unicodeIn[i]);
\r
505 source.append(com);
\r
507 // a) compare it with itself
\r
508 doTestCompare(source.toString(),source.toString(),true);
\r
510 // b) compare it with asciiIn equivalent
\r
511 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);
\r
513 // c) compare it with unicodeIn not equivalent
\r
515 doTestCompare(source.toString(), uni1.toString(), false);
\r
517 doTestCompare(source.toString(),uni0.toString(), false);
\r
519 // d) compare it with asciiIn not equivalent
\r
521 doTestCompare(source.toString(),ascii1.toString(), false);
\r
523 doTestCompare(source.toString(),ascii0.toString(), false);
\r
526 }catch(java.lang.ExceptionInInitializerError ex){
\r
527 warnln("Could not load NamePrepTransform data");
\r
528 }catch(java.lang.NoClassDefFoundError ex){
\r
529 warnln("Could not load NamePrepTransform data");
\r
533 // test and ascertain
\r
534 // func(func(func(src))) == func(src)
\r
535 public void doTestChainingToASCII(String source)throws Exception{
\r
537 if (!IDNAReference.isReady()) {
\r
538 logln("Transliterator is not available on this environment. Skipping doTestChainingToASCII.");
\r
542 StringBuffer expected;
\r
543 StringBuffer chained;
\r
545 // test convertIDNToASCII
\r
546 expected = IDNAReference.convertIDNToASCII(source,IDNAReference.DEFAULT);
\r
547 chained = expected;
\r
548 for(int i=0; i< 4; i++){
\r
549 chained = IDNAReference.convertIDNtoASCII(chained,IDNAReference.DEFAULT);
\r
551 if(!expected.toString().equals(chained.toString())){
\r
552 errln("Chaining test failed for convertIDNToASCII");
\r
554 // test convertIDNToA
\r
555 expected = IDNAReference.convertToASCII(source,IDNAReference.DEFAULT);
\r
556 chained = expected;
\r
557 for(int i=0; i< 4; i++){
\r
558 chained = IDNAReference.convertToASCII(chained,IDNAReference.DEFAULT);
\r
560 if(!expected.toString().equals(chained.toString())){
\r
561 errln("Chaining test failed for convertToASCII");
\r
565 // test and ascertain
\r
566 // func(func(func(src))) == func(src)
\r
567 public void doTestChainingToUnicode(String source)throws Exception{
\r
569 if (!IDNAReference.isReady()) {
\r
570 logln("Transliterator is not available on this environment. Skipping doTestChainingToUnicode.");
\r
574 StringBuffer expected;
\r
575 StringBuffer chained;
\r
577 // test convertIDNToUnicode
\r
578 expected = IDNAReference.convertIDNToUnicode(source,IDNAReference.DEFAULT);
\r
579 chained = expected;
\r
580 for(int i=0; i< 4; i++){
\r
581 chained = IDNAReference.convertIDNToUnicode(chained,IDNAReference.DEFAULT);
\r
583 if(!expected.toString().equals(chained.toString())){
\r
584 errln("Chaining test failed for convertIDNToUnicode");
\r
586 // test convertIDNToA
\r
587 expected = IDNAReference.convertToUnicode(source,IDNAReference.DEFAULT);
\r
588 chained = expected;
\r
589 for(int i=0; i< 4; i++){
\r
590 chained = IDNAReference.convertToUnicode(chained,IDNAReference.DEFAULT);
\r
592 if(!expected.toString().equals(chained.toString())){
\r
593 errln("Chaining test failed for convertToUnicode");
\r
597 public void TestChaining() throws Exception{
\r
599 for(int i=0; i< TestData.unicodeIn.length; i++){
\r
600 doTestChainingToASCII(new String(TestData.unicodeIn[i]));
\r
602 for(int i=0; i< TestData.asciiIn.length; i++){
\r
603 doTestChainingToUnicode(TestData.asciiIn[i]);
\r
605 }catch(java.lang.ExceptionInInitializerError ex){
\r
606 warnln("Could not load NamePrepTransform data");
\r
607 }catch(java.lang.NoClassDefFoundError ex){
\r
608 warnln("Could not load NamePrepTransform data");
\r
611 public void TestRootLabelSeparator() throws Exception{
\r
612 String www = "www.";
\r
613 String com = ".com."; /*root label separator*/
\r
614 StringBuffer source = new StringBuffer(www);
\r
615 StringBuffer uni0 = new StringBuffer(www);
\r
616 StringBuffer uni1 = new StringBuffer(www);
\r
617 StringBuffer ascii0 = new StringBuffer(www);
\r
618 StringBuffer ascii1 = new StringBuffer(www);
\r
620 uni0.append(TestData.unicodeIn[0]);
\r
623 uni1.append(TestData.unicodeIn[1]);
\r
626 ascii0.append(TestData.asciiIn[0]);
\r
627 ascii0.append(com);
\r
629 ascii1.append(TestData.asciiIn[1]);
\r
630 ascii1.append(com);
\r
632 for(int i=0;i< TestData.unicodeIn.length; i++){
\r
634 // for every entry in unicodeIn array
\r
635 // prepend www. and append .com
\r
636 source.setLength(4);
\r
637 source.append(TestData.unicodeIn[i]);
\r
638 source.append(com);
\r
640 // a) compare it with itself
\r
641 doTestCompare(source.toString(),source.toString(),true);
\r
643 // b) compare it with asciiIn equivalent
\r
644 doTestCompare(source.toString(),www+TestData.asciiIn[i]+com,true);
\r
646 // c) compare it with unicodeIn not equivalent
\r
648 doTestCompare(source.toString(), uni1.toString(), false);
\r
650 doTestCompare(source.toString(),uni0.toString(), false);
\r
652 // d) compare it with asciiIn not equivalent
\r
654 doTestCompare(source.toString(),ascii1.toString(), false);
\r
656 doTestCompare(source.toString(),ascii0.toString(), false);
\r
659 }catch(java.lang.ExceptionInInitializerError ex){
\r
660 warnln("Could not load NamePrepTransform data");
\r
661 }catch(java.lang.NoClassDefFoundError ex){
\r
662 warnln("Could not load NamePrepTransform data");
\r