Source Code Cross Referenced for TestIDNARef.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » stringprep » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.icu.dev.test.stringprep 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 2003-2005, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:        package com.ibm.icu.dev.test.stringprep;
008:
009:        import com.ibm.icu.dev.test.TestFmwk;
010:        import com.ibm.icu.text.StringPrepParseException;
011:        import com.ibm.icu.text.UCharacterIterator;
012:
013:        /**
014:         * @author ram
015:         *
016:         * To change the template for this generated type comment go to
017:         * Window>Preferences>Java>Code Generation>Code and Comments
018:         */
019:        public class TestIDNARef extends TestFmwk {
020:            public static void main(String[] args) throws Exception {
021:                new TestIDNARef().run(args);
022:            }
023:
024:            private StringPrepParseException unassignedException = new StringPrepParseException(
025:                    "", StringPrepParseException.UNASSIGNED_ERROR);
026:
027:            public void TestToUnicode() throws Exception {
028:                try {
029:                    for (int i = 0; i < TestData.asciiIn.length; i++) {
030:                        // test StringBuffer toUnicode
031:                        doTestToUnicode(TestData.asciiIn[i], new String(
032:                                TestData.unicodeIn[i]), IDNAReference.DEFAULT,
033:                                null);
034:                        doTestToUnicode(TestData.asciiIn[i], new String(
035:                                TestData.unicodeIn[i]),
036:                                IDNAReference.ALLOW_UNASSIGNED, null);
037:                        //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES, null); 
038:                        //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES|IDNAReference.ALLOW_UNASSIGNED, null); 
039:
040:                    }
041:                } catch (java.lang.ExceptionInInitializerError ex) {
042:                    warnln("Could not load NamePrepTransform data");
043:                } catch (java.lang.NoClassDefFoundError ex) {
044:                    warnln("Could not load NamePrepTransform data");
045:                }
046:            }
047:
048:            public void TestToASCII() throws Exception {
049:                try {
050:                    for (int i = 0; i < TestData.asciiIn.length; i++) {
051:                        // test StringBuffer toUnicode
052:                        doTestToASCII(new String(TestData.unicodeIn[i]),
053:                                TestData.asciiIn[i], IDNAReference.DEFAULT,
054:                                null);
055:                        doTestToASCII(new String(TestData.unicodeIn[i]),
056:                                TestData.asciiIn[i],
057:                                IDNAReference.ALLOW_UNASSIGNED, null);
058:                        //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES, null); 
059:                        //doTestToUnicode(TestData.asciiIn[i],new String(TestData.unicodeIn[i]),IDNAReference.USE_STD3_RULES|IDNAReference.ALLOW_UNASSIGNED, null); 
060:
061:                    }
062:                } catch (java.lang.ExceptionInInitializerError ex) {
063:                    warnln("Could not load NamePrepTransform data");
064:                } catch (java.lang.NoClassDefFoundError ex) {
065:                    warnln("Could not load NamePrepTransform data");
066:                }
067:            }
068:
069:            public void TestIDNToASCII() throws Exception {
070:                try {
071:                    for (int i = 0; i < TestData.domainNames.length; i++) {
072:                        doTestIDNToASCII(TestData.domainNames[i],
073:                                TestData.domainNames[i], IDNAReference.DEFAULT,
074:                                null);
075:                        doTestIDNToASCII(TestData.domainNames[i],
076:                                TestData.domainNames[i],
077:                                IDNAReference.ALLOW_UNASSIGNED, null);
078:                        doTestIDNToASCII(TestData.domainNames[i],
079:                                TestData.domainNames[i],
080:                                IDNAReference.USE_STD3_RULES, null);
081:                        doTestIDNToASCII(TestData.domainNames[i],
082:                                TestData.domainNames[i],
083:                                IDNAReference.ALLOW_UNASSIGNED
084:                                        | IDNAReference.USE_STD3_RULES, null);
085:                    }
086:
087:                    for (int i = 0; i < TestData.domainNames1Uni.length; i++) {
088:                        doTestIDNToASCII(TestData.domainNames1Uni[i],
089:                                TestData.domainNamesToASCIIOut[i],
090:                                IDNAReference.DEFAULT, null);
091:                        doTestIDNToASCII(TestData.domainNames1Uni[i],
092:                                TestData.domainNamesToASCIIOut[i],
093:                                IDNAReference.ALLOW_UNASSIGNED, null);
094:                        doTestIDNToASCII(TestData.domainNames1Uni[i],
095:                                TestData.domainNamesToASCIIOut[i],
096:                                IDNAReference.USE_STD3_RULES, null);
097:                        doTestIDNToASCII(TestData.domainNames1Uni[i],
098:                                TestData.domainNamesToASCIIOut[i],
099:                                IDNAReference.ALLOW_UNASSIGNED
100:                                        | IDNAReference.USE_STD3_RULES, null);
101:
102:                    }
103:                } catch (java.lang.ExceptionInInitializerError ex) {
104:                    warnln("Could not load NamePrepTransform data");
105:                } catch (java.lang.NoClassDefFoundError ex) {
106:                    warnln("Could not load NamePrepTransform data");
107:                }
108:            }
109:
110:            public void TestIDNToUnicode() throws Exception {
111:                try {
112:                    for (int i = 0; i < TestData.domainNames.length; i++) {
113:                        doTestIDNToUnicode(TestData.domainNames[i],
114:                                TestData.domainNames[i], IDNAReference.DEFAULT,
115:                                null);
116:                        doTestIDNToUnicode(TestData.domainNames[i],
117:                                TestData.domainNames[i],
118:                                IDNAReference.ALLOW_UNASSIGNED, null);
119:                        doTestIDNToUnicode(TestData.domainNames[i],
120:                                TestData.domainNames[i],
121:                                IDNAReference.USE_STD3_RULES, null);
122:                        doTestIDNToUnicode(TestData.domainNames[i],
123:                                TestData.domainNames[i],
124:                                IDNAReference.ALLOW_UNASSIGNED
125:                                        | IDNAReference.USE_STD3_RULES, null);
126:                    }
127:                    for (int i = 0; i < TestData.domainNamesToASCIIOut.length; i++) {
128:                        doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],
129:                                TestData.domainNamesToUnicodeOut[i],
130:                                IDNAReference.DEFAULT, null);
131:                        doTestIDNToUnicode(TestData.domainNamesToASCIIOut[i],
132:                                TestData.domainNamesToUnicodeOut[i],
133:                                IDNAReference.ALLOW_UNASSIGNED, null);
134:                    }
135:                } catch (java.lang.ExceptionInInitializerError ex) {
136:                    warnln("Could not load NamePrepTransform data");
137:                } catch (java.lang.NoClassDefFoundError ex) {
138:                    warnln("Could not load NamePrepTransform data");
139:                }
140:            }
141:
142:            private void doTestToUnicode(String src, String expected,
143:                    int options, Object expectedException) throws Exception {
144:                StringBuffer inBuf = new StringBuffer(src);
145:                UCharacterIterator inIter = UCharacterIterator.getInstance(src);
146:                try {
147:
148:                    StringBuffer out = IDNAReference.convertToUnicode(src,
149:                            options);
150:                    if (expected != null && out != null
151:                            && !out.toString().equals(expected)) {
152:                        errln("convertToUnicode did not return expected result with options : "
153:                                + options
154:                                + " Expected: "
155:                                + prettify(expected)
156:                                + " Got: " + prettify(out));
157:                    }
158:                    if (expectedException != null
159:                            && !unassignedException.equals(expectedException)) {
160:                        errln("convertToUnicode did not get the expected exception. The operation succeeded!");
161:                    }
162:                } catch (StringPrepParseException ex) {
163:                    if (expectedException == null
164:                            || !ex.equals(expectedException)) {
165:                        errln("convertToUnicode did not get the expected exception for source: "
166:                                + prettify(src) + " Got:  " + ex.toString());
167:                    }
168:                }
169:                try {
170:
171:                    StringBuffer out = IDNAReference.convertToUnicode(inBuf,
172:                            options);
173:                    if (expected != null && out != null
174:                            && !out.toString().equals(expected)) {
175:                        errln("convertToUnicode did not return expected result with options : "
176:                                + options
177:                                + " Expected: "
178:                                + prettify(expected)
179:                                + " Got: " + out);
180:                    }
181:                    if (expectedException != null
182:                            && !unassignedException.equals(expectedException)) {
183:                        errln("convertToUnicode did not get the expected exception. The operation succeeded!");
184:                    }
185:                } catch (StringPrepParseException ex) {
186:                    if (expectedException == null
187:                            || !ex.equals(expectedException)) {
188:                        errln("convertToUnicode did not get the expected exception for source: "
189:                                + prettify(src) + " Got:  " + ex.toString());
190:                    }
191:                }
192:
193:                try {
194:                    StringBuffer out = IDNAReference.convertToUnicode(inIter,
195:                            options);
196:                    if (expected != null && out != null
197:                            && !out.toString().equals(expected)) {
198:                        errln("convertToUnicode did not return expected result with options : "
199:                                + options
200:                                + " Expected: "
201:                                + prettify(expected)
202:                                + " Got: " + prettify(out));
203:                    }
204:                    if (expectedException != null
205:                            && !unassignedException.equals(expectedException)) {
206:                        errln("Did not get the expected exception. The operation succeeded!");
207:                    }
208:                } catch (StringPrepParseException ex) {
209:                    if (expectedException == null
210:                            || !ex.equals(expectedException)) {
211:                        errln("Did not get the expected exception for source: "
212:                                + prettify(src) + " Got:  " + ex.toString());
213:                    }
214:                }
215:            }
216:
217:            private void doTestIDNToUnicode(String src, String expected,
218:                    int options, Object expectedException) throws Exception {
219:                StringBuffer inBuf = new StringBuffer(src);
220:                UCharacterIterator inIter = UCharacterIterator.getInstance(src);
221:                try {
222:
223:                    StringBuffer out = IDNAReference.convertIDNToUnicode(src,
224:                            options);
225:                    if (expected != null && out != null
226:                            && !out.toString().equals(expected)) {
227:                        errln("convertToUnicode did not return expected result with options : "
228:                                + options
229:                                + " Expected: "
230:                                + prettify(expected)
231:                                + " Got: " + prettify(out));
232:                    }
233:                    if (expectedException != null
234:                            && !unassignedException.equals(expectedException)) {
235:                        errln("convertToUnicode did not get the expected exception. The operation succeeded!");
236:                    }
237:                } catch (StringPrepParseException ex) {
238:                    if (expectedException == null
239:                            || !expectedException.equals(ex)) {
240:                        errln("convertToUnicode did not get the expected exception for source: "
241:                                + src + " Got:  " + ex.toString());
242:                    }
243:                }
244:                try {
245:                    StringBuffer out = IDNAReference.convertIDNToUnicode(inBuf,
246:                            options);
247:                    if (expected != null && out != null
248:                            && !out.toString().equals(expected)) {
249:                        errln("convertToUnicode did not return expected result with options : "
250:                                + options
251:                                + " Expected: "
252:                                + prettify(expected)
253:                                + " Got: " + out);
254:                    }
255:                    if (expectedException != null
256:                            && !unassignedException.equals(expectedException)) {
257:                        errln("convertToUnicode did not get the expected exception. The operation succeeded!");
258:                    }
259:                } catch (StringPrepParseException ex) {
260:                    if (expectedException == null
261:                            || !expectedException.equals(ex)) {
262:                        errln("convertToUnicode did not get the expected exception for source: "
263:                                + src + " Got:  " + ex.toString());
264:                    }
265:                }
266:
267:                try {
268:                    StringBuffer out = IDNAReference.convertIDNToUnicode(
269:                            inIter, options);
270:                    if (expected != null && out != null
271:                            && !out.toString().equals(expected)) {
272:                        errln("convertToUnicode did not return expected result with options : "
273:                                + options
274:                                + " Expected: "
275:                                + prettify(expected)
276:                                + " Got: " + prettify(out));
277:                    }
278:                    if (expectedException != null
279:                            && !unassignedException.equals(expectedException)) {
280:                        errln("Did not get the expected exception. The operation succeeded!");
281:                    }
282:                } catch (StringPrepParseException ex) {
283:                    if (expectedException == null
284:                            || !expectedException.equals(ex)) {
285:                        errln("Did not get the expected exception for source: "
286:                                + src + " Got:  " + ex.toString());
287:                    }
288:                }
289:            }
290:
291:            private void doTestToASCII(String src, String expected,
292:                    int options, Object expectedException) throws Exception {
293:                StringBuffer inBuf = new StringBuffer(src);
294:                UCharacterIterator inIter = UCharacterIterator.getInstance(src);
295:                try {
296:
297:                    StringBuffer out = IDNAReference.convertToASCII(src,
298:                            options);
299:                    if (!unassignedException.equals(expectedException)
300:                            && expected != null && out != null
301:                            && expected != null && out != null
302:                            && !out.toString().equals(expected.toLowerCase())) {
303:                        errln("convertToASCII did not return expected result with options : "
304:                                + options
305:                                + " Expected: "
306:                                + expected
307:                                + " Got: "
308:                                + out);
309:                    }
310:                    if (expectedException != null
311:                            && !unassignedException.equals(expectedException)) {
312:                        errln("convertToASCII did not get the expected exception. The operation succeeded!");
313:                    }
314:                } catch (StringPrepParseException ex) {
315:                    if (expectedException == null
316:                            || !expectedException.equals(ex)) {
317:                        errln("convertToASCII did not get the expected exception for source: "
318:                                + src + " Got:  " + ex.toString());
319:                    }
320:                }
321:
322:                try {
323:                    StringBuffer out = IDNAReference.convertToASCII(inBuf,
324:                            options);
325:                    if (!unassignedException.equals(expectedException)
326:                            && expected != null && out != null
327:                            && expected != null && out != null
328:                            && !out.toString().equals(expected.toLowerCase())) {
329:                        errln("convertToASCII did not return expected result with options : "
330:                                + options
331:                                + " Expected: "
332:                                + expected
333:                                + " Got: "
334:                                + out);
335:                    }
336:                    if (expectedException != null
337:                            && !unassignedException.equals(expectedException)) {
338:                        errln("convertToASCII did not get the expected exception. The operation succeeded!");
339:                    }
340:                } catch (StringPrepParseException ex) {
341:                    if (expectedException == null
342:                            || !expectedException.equals(ex)) {
343:                        errln("convertToASCII did not get the expected exception for source: "
344:                                + src + " Got:  " + ex.toString());
345:                    }
346:                }
347:
348:                try {
349:                    StringBuffer out = IDNAReference.convertToASCII(inIter,
350:                            options);
351:                    if (!unassignedException.equals(expectedException)
352:                            && expected != null && out != null
353:                            && expected != null && out != null
354:                            && !out.toString().equals(expected.toLowerCase())) {
355:                        errln("convertToASCII did not return expected result with options : "
356:                                + options
357:                                + " Expected: "
358:                                + expected
359:                                + " Got: "
360:                                + out);
361:                    }
362:                    if (expectedException != null
363:                            && !unassignedException.equals(expectedException)) {
364:                        errln("convertToASCII did not get the expected exception. The operation succeeded!");
365:                    }
366:                } catch (StringPrepParseException ex) {
367:                    if (expectedException == null
368:                            || !expectedException.equals(ex)) {
369:                        errln("convertToASCII did not get the expected exception for source: "
370:                                + src + " Got:  " + ex.toString());
371:                    }
372:                }
373:            }
374:
375:            private void doTestIDNToASCII(String src, String expected,
376:                    int options, Object expectedException) throws Exception {
377:
378:                StringBuffer inBuf = new StringBuffer(src);
379:                UCharacterIterator inIter = UCharacterIterator.getInstance(src);
380:                try {
381:
382:                    StringBuffer out = IDNAReference.convertIDNToASCII(src,
383:                            options);
384:                    if (expected != null && out != null
385:                            && !out.toString().equals(expected)) {
386:                        errln("convertToIDNAReferenceASCII did not return expected result with options : "
387:                                + options
388:                                + " Expected: "
389:                                + expected
390:                                + " Got: "
391:                                + out);
392:                    }
393:                    if (expectedException != null
394:                            && !unassignedException.equals(expectedException)) {
395:                        errln("convertToIDNAReferenceASCII did not get the expected exception. The operation succeeded!");
396:                    }
397:                } catch (StringPrepParseException ex) {
398:                    if (expectedException == null
399:                            || !ex.equals(expectedException)) {
400:                        errln("convertToIDNAReferenceASCII did not get the expected exception for source: "
401:                                + src + " Got:  " + ex.toString());
402:                    }
403:                }
404:                try {
405:                    StringBuffer out = IDNAReference.convertIDNtoASCII(inBuf,
406:                            options);
407:                    if (expected != null && out != null
408:                            && !out.toString().equals(expected)) {
409:                        errln("convertToIDNAReferenceASCII did not return expected result with options : "
410:                                + options
411:                                + " Expected: "
412:                                + expected
413:                                + " Got: "
414:                                + out);
415:                    }
416:                    if (expectedException != null
417:                            && !unassignedException.equals(expectedException)) {
418:                        errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!");
419:                    }
420:                } catch (StringPrepParseException ex) {
421:                    if (expectedException == null
422:                            || !ex.equals(expectedException)) {
423:                        errln("convertToIDNAReferenceSCII did not get the expected exception for source: "
424:                                + src + " Got:  " + ex.toString());
425:                    }
426:                }
427:
428:                try {
429:                    StringBuffer out = IDNAReference.convertIDNtoASCII(inIter,
430:                            options);
431:                    if (expected != null && out != null
432:                            && !out.toString().equals(expected)) {
433:                        errln("convertIDNToASCII did not return expected result with options : "
434:                                + options
435:                                + " Expected: "
436:                                + expected
437:                                + " Got: "
438:                                + out);
439:                    }
440:
441:                    if (expectedException != null
442:                            && !unassignedException.equals(expectedException)) {
443:                        errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");
444:                    }
445:                } catch (StringPrepParseException ex) {
446:                    if (expectedException == null
447:                            || !ex.equals(expectedException)) {
448:                        errln("convertIDNToASCII did not get the expected exception for source: "
449:                                + src + " Got:  " + ex.toString());
450:                    }
451:                }
452:            }
453:
454:            public void TestConformance() throws Exception {
455:                try {
456:                    for (int i = 0; i < TestData.conformanceTestCases.length; i++) {
457:
458:                        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
459:                        if (testCase.expected != null) {
460:                            //Test toASCII
461:                            doTestToASCII(testCase.input, testCase.output,
462:                                    IDNAReference.DEFAULT, testCase.expected);
463:                            doTestToASCII(testCase.input, testCase.output,
464:                                    IDNAReference.ALLOW_UNASSIGNED,
465:                                    testCase.expected);
466:                        }
467:                        //Test toUnicode
468:                        //doTestToUnicode(testCase.input,testCase.output,IDNAReference.DEFAULT,testCase.expected);
469:                    }
470:                } catch (java.lang.ExceptionInInitializerError ex) {
471:                    warnln("Could not load NamePrepTransform data");
472:                } catch (java.lang.NoClassDefFoundError ex) {
473:                    warnln("Could not load NamePrepTransform data");
474:                }
475:            }
476:
477:            public void TestNamePrepConformance() throws Exception {
478:                try {
479:                    NamePrepTransform namePrep = NamePrepTransform
480:                            .getInstance();
481:                    for (int i = 0; i < TestData.conformanceTestCases.length; i++) {
482:                        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
483:                        UCharacterIterator iter = UCharacterIterator
484:                                .getInstance(testCase.input);
485:                        try {
486:                            StringBuffer output = namePrep.prepare(iter,
487:                                    NamePrepTransform.NONE);
488:                            if (testCase.output != null
489:                                    && output != null
490:                                    && !testCase.output.equals(output
491:                                            .toString())) {
492:                                errln("Did not get the expected output. Expected: "
493:                                        + prettify(testCase.output)
494:                                        + " Got: "
495:                                        + prettify(output));
496:                            }
497:                            if (testCase.expected != null
498:                                    && !unassignedException
499:                                            .equals(testCase.expected)) {
500:                                errln("Did not get the expected exception. The operation succeeded!");
501:                            }
502:                        } catch (StringPrepParseException ex) {
503:                            if (testCase.expected == null
504:                                    || !ex.equals(testCase.expected)) {
505:                                errln("Did not get the expected exception for source: "
506:                                        + testCase.input
507:                                        + " Got:  "
508:                                        + ex.toString());
509:                            }
510:                        }
511:
512:                        try {
513:                            iter.setToStart();
514:                            StringBuffer output = namePrep.prepare(iter,
515:                                    NamePrepTransform.ALLOW_UNASSIGNED);
516:                            if (testCase.output != null
517:                                    && output != null
518:                                    && !testCase.output.equals(output
519:                                            .toString())) {
520:                                errln("Did not get the expected output. Expected: "
521:                                        + prettify(testCase.output)
522:                                        + " Got: "
523:                                        + prettify(output));
524:                            }
525:                            if (testCase.expected != null
526:                                    && !unassignedException
527:                                            .equals(testCase.expected)) {
528:                                errln("Did not get the expected exception. The operation succeeded!");
529:                            }
530:                        } catch (StringPrepParseException ex) {
531:                            if (testCase.expected == null
532:                                    || !ex.equals(testCase.expected)) {
533:                                errln("Did not get the expected exception for source: "
534:                                        + testCase.input
535:                                        + " Got:  "
536:                                        + ex.toString());
537:                            }
538:                        }
539:                    }
540:                } catch (java.lang.ExceptionInInitializerError e) {
541:                    warnln("Could not load NamePrepTransformData");
542:                } catch (java.lang.NoClassDefFoundError ex) {
543:                    warnln("Could not load NamePrepTransform data");
544:                }
545:
546:            }
547:
548:            public void TestErrorCases() throws Exception {
549:                try {
550:                    for (int i = 0; i < TestData.errorCases.length; i++) {
551:                        TestData.ErrorCase errCase = TestData.errorCases[i];
552:                        if (errCase.testLabel == true) {
553:                            // Test ToASCII
554:                            doTestToASCII(new String(errCase.unicode),
555:                                    errCase.ascii, IDNAReference.DEFAULT,
556:                                    errCase.expected);
557:                            doTestToASCII(new String(errCase.unicode),
558:                                    errCase.ascii,
559:                                    IDNAReference.ALLOW_UNASSIGNED,
560:                                    errCase.expected);
561:                            if (errCase.useSTD3ASCIIRules) {
562:                                doTestToASCII(new String(errCase.unicode),
563:                                        errCase.ascii,
564:                                        IDNAReference.USE_STD3_RULES,
565:                                        errCase.expected);
566:                            }
567:                        }
568:                        if (errCase.useSTD3ASCIIRules != true) {
569:
570:                            // Test IDNToASCII
571:                            doTestIDNToASCII(new String(errCase.unicode),
572:                                    errCase.ascii, IDNAReference.DEFAULT,
573:                                    errCase.expected);
574:                            doTestIDNToASCII(new String(errCase.unicode),
575:                                    errCase.ascii,
576:                                    IDNAReference.ALLOW_UNASSIGNED,
577:                                    errCase.expected);
578:
579:                        } else {
580:                            doTestIDNToASCII(new String(errCase.unicode),
581:                                    errCase.ascii,
582:                                    IDNAReference.USE_STD3_RULES,
583:                                    errCase.expected);
584:                        }
585:
586:                        //TestToUnicode
587:                        if (errCase.testToUnicode == true) {
588:                            if (errCase.useSTD3ASCIIRules != true) {
589:                                // Test IDNToUnicode
590:                                doTestIDNToUnicode(errCase.ascii, new String(
591:                                        errCase.unicode),
592:                                        IDNAReference.DEFAULT, errCase.expected);
593:                                doTestIDNToUnicode(errCase.ascii, new String(
594:                                        errCase.unicode),
595:                                        IDNAReference.ALLOW_UNASSIGNED,
596:                                        errCase.expected);
597:
598:                            } else {
599:                                doTestIDNToUnicode(errCase.ascii, new String(
600:                                        errCase.unicode),
601:                                        IDNAReference.USE_STD3_RULES,
602:                                        errCase.expected);
603:                            }
604:                        }
605:                    }
606:                } catch (java.lang.ExceptionInInitializerError ex) {
607:                    warnln("Could not load NamePrepTransform data");
608:                } catch (java.lang.NoClassDefFoundError ex) {
609:                    warnln("Could not load NamePrepTransform data");
610:                }
611:            }
612:
613:            private void doTestCompare(String s1, String s2, boolean isEqual) {
614:                try {
615:                    int retVal = IDNAReference.compare(s1, s2,
616:                            IDNAReference.DEFAULT);
617:                    if (isEqual == true && retVal != 0) {
618:                        errln("Did not get the expected result for s1: "
619:                                + prettify(s1) + " s2: " + prettify(s2));
620:                    }
621:                    retVal = IDNAReference.compare(new StringBuffer(s1),
622:                            new StringBuffer(s2), IDNAReference.DEFAULT);
623:                    if (isEqual == true && retVal != 0) {
624:                        errln("Did not get the expected result for s1: "
625:                                + prettify(s1) + " s2: " + prettify(s2));
626:                    }
627:                    retVal = IDNAReference.compare(UCharacterIterator
628:                            .getInstance(s1), UCharacterIterator
629:                            .getInstance(s2), IDNAReference.DEFAULT);
630:                    if (isEqual == true && retVal != 0) {
631:                        errln("Did not get the expected result for s1: "
632:                                + prettify(s1) + " s2: " + prettify(s2));
633:                    }
634:                } catch (Exception e) {
635:                    e.printStackTrace();
636:                    errln("Unexpected exception thrown by IDNAReference.compare");
637:                }
638:
639:                try {
640:                    int retVal = IDNAReference.compare(s1, s2,
641:                            IDNAReference.ALLOW_UNASSIGNED);
642:                    if (isEqual == true && retVal != 0) {
643:                        errln("Did not get the expected result for s1: "
644:                                + prettify(s1) + " s2: " + prettify(s2));
645:                    }
646:                    retVal = IDNAReference.compare(new StringBuffer(s1),
647:                            new StringBuffer(s2),
648:                            IDNAReference.ALLOW_UNASSIGNED);
649:                    if (isEqual == true && retVal != 0) {
650:                        errln("Did not get the expected result for s1: "
651:                                + prettify(s1) + " s2: " + prettify(s2));
652:                    }
653:                    retVal = IDNAReference.compare(UCharacterIterator
654:                            .getInstance(s1), UCharacterIterator
655:                            .getInstance(s2), IDNAReference.ALLOW_UNASSIGNED);
656:                    if (isEqual == true && retVal != 0) {
657:                        errln("Did not get the expected result for s1: "
658:                                + prettify(s1) + " s2: " + prettify(s2));
659:                    }
660:                } catch (Exception e) {
661:                    errln("Unexpected exception thrown by IDNAReference.compare");
662:                }
663:            }
664:
665:            public void TestCompare() throws Exception {
666:                String www = "www.";
667:                String com = ".com";
668:                StringBuffer source = new StringBuffer(www);
669:                StringBuffer uni0 = new StringBuffer(www);
670:                StringBuffer uni1 = new StringBuffer(www);
671:                StringBuffer ascii0 = new StringBuffer(www);
672:                StringBuffer ascii1 = new StringBuffer(www);
673:
674:                uni0.append(TestData.unicodeIn[0]);
675:                uni0.append(com);
676:
677:                uni1.append(TestData.unicodeIn[1]);
678:                uni1.append(com);
679:
680:                ascii0.append(TestData.asciiIn[0]);
681:                ascii0.append(com);
682:
683:                ascii1.append(TestData.asciiIn[1]);
684:                ascii1.append(com);
685:                try {
686:                    for (int i = 0; i < TestData.unicodeIn.length; i++) {
687:
688:                        // for every entry in unicodeIn array
689:                        // prepend www. and append .com
690:                        source.setLength(4);
691:                        source.append(TestData.unicodeIn[i]);
692:                        source.append(com);
693:
694:                        // a) compare it with itself
695:                        doTestCompare(source.toString(), source.toString(),
696:                                true);
697:
698:                        // b) compare it with asciiIn equivalent
699:                        doTestCompare(source.toString(), www
700:                                + TestData.asciiIn[i] + com, true);
701:
702:                        // c) compare it with unicodeIn not equivalent
703:                        if (i == 0) {
704:                            doTestCompare(source.toString(), uni1.toString(),
705:                                    false);
706:                        } else {
707:                            doTestCompare(source.toString(), uni0.toString(),
708:                                    false);
709:                        }
710:                        // d) compare it with asciiIn not equivalent
711:                        if (i == 0) {
712:                            doTestCompare(source.toString(), ascii1.toString(),
713:                                    false);
714:                        } else {
715:                            doTestCompare(source.toString(), ascii0.toString(),
716:                                    false);
717:                        }
718:                    }
719:                } catch (java.lang.ExceptionInInitializerError ex) {
720:                    warnln("Could not load NamePrepTransform data");
721:                } catch (java.lang.NoClassDefFoundError ex) {
722:                    warnln("Could not load NamePrepTransform data");
723:                }
724:            }
725:
726:            //  test and ascertain
727:            //  func(func(func(src))) == func(src)
728:            public void doTestChainingToASCII(String source) throws Exception {
729:                StringBuffer expected;
730:                StringBuffer chained;
731:
732:                // test convertIDNToASCII
733:                expected = IDNAReference.convertIDNToASCII(source,
734:                        IDNAReference.DEFAULT);
735:                chained = expected;
736:                for (int i = 0; i < 4; i++) {
737:                    chained = IDNAReference.convertIDNtoASCII(chained,
738:                            IDNAReference.DEFAULT);
739:                }
740:                if (!expected.toString().equals(chained.toString())) {
741:                    errln("Chaining test failed for convertIDNToASCII");
742:                }
743:                // test convertIDNToA
744:                expected = IDNAReference.convertToASCII(source,
745:                        IDNAReference.DEFAULT);
746:                chained = expected;
747:                for (int i = 0; i < 4; i++) {
748:                    chained = IDNAReference.convertToASCII(chained,
749:                            IDNAReference.DEFAULT);
750:                }
751:                if (!expected.toString().equals(chained.toString())) {
752:                    errln("Chaining test failed for convertToASCII");
753:                }
754:
755:            }
756:
757:            //  test and ascertain
758:            //  func(func(func(src))) == func(src)
759:            public void doTestChainingToUnicode(String source) throws Exception {
760:                StringBuffer expected;
761:                StringBuffer chained;
762:
763:                // test convertIDNToUnicode
764:                expected = IDNAReference.convertIDNToUnicode(source,
765:                        IDNAReference.DEFAULT);
766:                chained = expected;
767:                for (int i = 0; i < 4; i++) {
768:                    chained = IDNAReference.convertIDNToUnicode(chained,
769:                            IDNAReference.DEFAULT);
770:                }
771:                if (!expected.toString().equals(chained.toString())) {
772:                    errln("Chaining test failed for convertIDNToUnicode");
773:                }
774:                // test convertIDNToA
775:                expected = IDNAReference.convertToUnicode(source,
776:                        IDNAReference.DEFAULT);
777:                chained = expected;
778:                for (int i = 0; i < 4; i++) {
779:                    chained = IDNAReference.convertToUnicode(chained,
780:                            IDNAReference.DEFAULT);
781:                }
782:                if (!expected.toString().equals(chained.toString())) {
783:                    errln("Chaining test failed for convertToUnicode");
784:                }
785:
786:            }
787:
788:            public void TestChaining() throws Exception {
789:                try {
790:                    for (int i = 0; i < TestData.unicodeIn.length; i++) {
791:                        doTestChainingToASCII(new String(TestData.unicodeIn[i]));
792:                    }
793:                    for (int i = 0; i < TestData.asciiIn.length; i++) {
794:                        doTestChainingToUnicode(TestData.asciiIn[i]);
795:                    }
796:                } catch (java.lang.ExceptionInInitializerError ex) {
797:                    warnln("Could not load NamePrepTransform data");
798:                } catch (java.lang.NoClassDefFoundError ex) {
799:                    warnln("Could not load NamePrepTransform data");
800:                }
801:            }
802:
803:            public void TestRootLabelSeparator() throws Exception {
804:                String www = "www.";
805:                String com = ".com."; /*root label separator*/
806:                StringBuffer source = new StringBuffer(www);
807:                StringBuffer uni0 = new StringBuffer(www);
808:                StringBuffer uni1 = new StringBuffer(www);
809:                StringBuffer ascii0 = new StringBuffer(www);
810:                StringBuffer ascii1 = new StringBuffer(www);
811:
812:                uni0.append(TestData.unicodeIn[0]);
813:                uni0.append(com);
814:
815:                uni1.append(TestData.unicodeIn[1]);
816:                uni1.append(com);
817:
818:                ascii0.append(TestData.asciiIn[0]);
819:                ascii0.append(com);
820:
821:                ascii1.append(TestData.asciiIn[1]);
822:                ascii1.append(com);
823:                try {
824:                    for (int i = 0; i < TestData.unicodeIn.length; i++) {
825:
826:                        // for every entry in unicodeIn array
827:                        // prepend www. and append .com
828:                        source.setLength(4);
829:                        source.append(TestData.unicodeIn[i]);
830:                        source.append(com);
831:
832:                        // a) compare it with itself
833:                        doTestCompare(source.toString(), source.toString(),
834:                                true);
835:
836:                        // b) compare it with asciiIn equivalent
837:                        doTestCompare(source.toString(), www
838:                                + TestData.asciiIn[i] + com, true);
839:
840:                        // c) compare it with unicodeIn not equivalent
841:                        if (i == 0) {
842:                            doTestCompare(source.toString(), uni1.toString(),
843:                                    false);
844:                        } else {
845:                            doTestCompare(source.toString(), uni0.toString(),
846:                                    false);
847:                        }
848:                        // d) compare it with asciiIn not equivalent
849:                        if (i == 0) {
850:                            doTestCompare(source.toString(), ascii1.toString(),
851:                                    false);
852:                        } else {
853:                            doTestCompare(source.toString(), ascii0.toString(),
854:                                    false);
855:                        }
856:                    }
857:                } catch (java.lang.ExceptionInInitializerError ex) {
858:                    warnln("Could not load NamePrepTransform data");
859:                } catch (java.lang.NoClassDefFoundError ex) {
860:                    warnln("Could not load NamePrepTransform data");
861:                }
862:
863:            }
864:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.