Source Code Cross Referenced for IDNAConformanceTest.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) 2005-2006, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:
007:         *******************************************************************************
008:         */
009:
010:        package com.ibm.icu.dev.test.stringprep;
011:
012:        import java.io.BufferedReader;
013:        import java.io.FileNotFoundException;
014:        import java.io.IOException;
015:        import java.io.UnsupportedEncodingException;
016:        import java.util.HashMap;
017:        import java.util.Iterator;
018:        import java.util.Set;
019:        import java.util.TreeMap;
020:
021:        import com.ibm.icu.dev.test.TestFmwk;
022:        import com.ibm.icu.dev.test.TestUtil;
023:        import com.ibm.icu.text.IDNA;
024:        import com.ibm.icu.text.StringPrepParseException;
025:        import com.ibm.icu.text.UTF16;
026:
027:        /**
028:         * @author limaoyu
029:         * 
030:         */
031:        public class IDNAConformanceTest extends TestFmwk {
032:
033:            public static void main(String[] args) throws Exception {
034:                new IDNAConformanceTest().run(args);
035:            }
036:
037:            public void TestConformance() {
038:
039:                TreeMap inputData = null;
040:
041:                try {
042:                    inputData = ReadInput.getInputData();
043:                } catch (UnsupportedEncodingException e) {
044:                    errln(e.getMessage());
045:                } catch (IOException e) {
046:                    errln(e.getMessage());
047:                }
048:
049:                Set keyMap = inputData.keySet();
050:                for (Iterator iter = keyMap.iterator(); iter.hasNext();) {
051:                    Long element = (Long) iter.next();
052:                    HashMap tempHash = (HashMap) inputData.get(element);
053:
054:                    //get all attributes from input data
055:                    String passfail = (String) tempHash.get("passfail");
056:                    String desc = (String) tempHash.get("desc");
057:                    String type = (String) tempHash.get("type");
058:                    String namebase = (String) tempHash.get("namebase");
059:                    String nameutf8 = (String) tempHash.get("nameutf8");
060:                    String namezone = (String) tempHash.get("namezone");
061:                    String failzone1 = (String) tempHash.get("failzone1");
062:                    String failzone2 = (String) tempHash.get("failzone2");
063:
064:                    //they maybe includes <*> style unicode
065:                    namebase = stringReplace(namebase);
066:                    namezone = stringReplace(namezone);
067:
068:                    String result = null;
069:                    boolean failed = false;
070:
071:                    if ("toascii".equals(tempHash.get("type"))) {
072:
073:                        //get the result
074:                        try {
075:                            //by default STD3 rules are not used, but if the description
076:                            //includes UseSTD3ASCIIRules, we will set it.
077:                            if (desc.toLowerCase().indexOf(
078:                                    "UseSTD3ASCIIRules".toLowerCase()) == -1) {
079:                                result = IDNA.convertIDNToASCII(namebase,
080:                                        IDNA.ALLOW_UNASSIGNED).toString();
081:                            } else {
082:                                result = IDNA.convertIDNToASCII(namebase,
083:                                        IDNA.USE_STD3_RULES).toString();
084:                            }
085:                        } catch (StringPrepParseException e2) {
086:                            //errln(e2.getMessage());
087:                            failed = true;
088:                        }
089:
090:                        if ("pass".equals(passfail)) {
091:                            if (!namezone.equals(result)) {
092:                                printInfo(desc, namebase, nameutf8, namezone,
093:                                        failzone1, failzone2, result, type,
094:                                        passfail);
095:                                errln("\t pass fail standard is pass, but failed");
096:                            } else {
097:                                printInfo(desc, namebase, nameutf8, namezone,
098:                                        failzone1, failzone2, result, type,
099:                                        passfail);
100:                                logln("\tpassed");
101:                            }
102:                        }
103:
104:                        if ("fail".equals(passfail)) {
105:                            if (failed) {
106:                                printInfo(desc, namebase, nameutf8, namezone,
107:                                        failzone1, failzone2, result, type,
108:                                        passfail);
109:                                logln("passed");
110:                            } else {
111:                                printInfo(desc, namebase, nameutf8, namezone,
112:                                        failzone1, failzone2, result, type,
113:                                        passfail);
114:                                errln("\t pass fail standard is fail, but no exception thrown out");
115:                            }
116:                        }
117:                    } else if ("tounicode".equals(tempHash.get("type"))) {
118:                        try {
119:                            //by default STD3 rules are not used, but if the description
120:                            //includes UseSTD3ASCIIRules, we will set it.
121:                            if (desc.toLowerCase().indexOf(
122:                                    "UseSTD3ASCIIRules".toLowerCase()) == -1) {
123:                                result = IDNA.convertIDNToUnicode(namebase,
124:                                        IDNA.ALLOW_UNASSIGNED).toString();
125:                            } else {
126:                                result = IDNA.convertIDNToUnicode(namebase,
127:                                        IDNA.USE_STD3_RULES).toString();
128:                            }
129:                        } catch (StringPrepParseException e2) {
130:                            //errln(e2.getMessage());
131:                            failed = true;
132:                        }
133:                        if ("pass".equals(passfail)) {
134:                            if (!namezone.equals(result)) {
135:                                printInfo(desc, namebase, nameutf8, namezone,
136:                                        failzone1, failzone2, result, type,
137:                                        passfail);
138:
139:                                errln("\t Did not get the expected result. Expected: "
140:                                        + prettify(namezone)
141:                                        + " Got: "
142:                                        + prettify(result));
143:                            } else {
144:                                printInfo(desc, namebase, nameutf8, namezone,
145:                                        failzone1, failzone2, result, type,
146:                                        passfail);
147:                                logln("\tpassed");
148:                            }
149:                        }
150:
151:                        if ("fail".equals(passfail)) {
152:                            if (failed || namebase.equals(result)) {
153:                                printInfo(desc, namebase, nameutf8, namezone,
154:                                        failzone1, failzone2, result, type,
155:                                        passfail);
156:
157:                                logln("\tpassed");
158:                            } else {
159:                                printInfo(desc, namebase, nameutf8, namezone,
160:                                        failzone1, failzone2, result, type,
161:                                        passfail);
162:
163:                                errln("\t pass fail standard is fail, but no exception thrown out");
164:                            }
165:                        }
166:                    } else {
167:                        continue;
168:                    }
169:                }
170:            }
171:
172:            /**
173:             * Print log message.
174:             * @param desc
175:             * @param namebase
176:             * @param nameutf8
177:             * @param namezone
178:             * @param failzone1
179:             * @param failzone2
180:             * @param result
181:             */
182:            private void printInfo(String desc, String namebase,
183:                    String nameutf8, String namezone, String failzone1,
184:                    String failzone2, String result, String type,
185:                    String passfail) {
186:                logln("desc:\t" + desc);
187:                log("\t");
188:                logln("type:\t" + type);
189:                log("\t");
190:                logln("pass fail standard:\t" + passfail);
191:                log("\t");
192:                logln("namebase:\t" + namebase);
193:                log("\t");
194:                logln("nameutf8:\t" + nameutf8);
195:                log("\t");
196:                logln("namezone:\t" + namezone);
197:                log("\t");
198:                logln("failzone1:\t" + failzone1);
199:                log("\t");
200:                logln("failzone2:\t" + failzone2);
201:                log("\t");
202:                logln("result:\t" + result);
203:            }
204:
205:            /**
206:             * Change unicode string from <00AD> to \u00AD, for the later is accepted
207:             * by Java
208:             * @param str String including <*> style unicode
209:             * @return \\u String
210:     */
211:            private static String stringReplace(String str) {
212:
213:                StringBuffer result = new StringBuffer();
214:                char[] chars = str.toCharArray();
215:                StringBuffer sbTemp = new StringBuffer();
216:                for (int i = 0; i < chars.length; i++) {
217:                    if ('<' == chars[i]) {
218:                        sbTemp = new StringBuffer();
219:                        while ('>' != chars[i + 1]) {
220:                            sbTemp.append(chars[++i]);
221:                        }
222:                        /*
223:                         * The unicode sometimes is larger then \uFFFF, so have to use
224:                         * UTF16.
225:                         */
226:                        int toBeInserted = Integer.parseInt(sbTemp.toString(),
227:                                16);
228:                        if ((toBeInserted >> 16) == 0) {
229:                            result.append((char) toBeInserted);
230:                        } else {
231:                            String utf16String = UTF16.valueOf(toBeInserted);
232:                            char[] charsTemp = utf16String.toCharArray();
233:                            for (int j = 0; j < charsTemp.length; j++) {
234:                                result.append((char) charsTemp[j]);
235:                            }
236:                        }
237:                    } else if ('>' == chars[i]) {//end when met with '>'
238:                        continue;
239:                    } else {
240:                        result.append(chars[i]);
241:                    }
242:
243:                }
244:                return result.toString();
245:            }
246:
247:            /**
248:             * This class is used to read test data from TestInput file.
249:             * 
250:             * @author limaoyu
251:             *  
252:             */
253:            public static class ReadInput {
254:
255:                public static TreeMap getInputData() throws IOException,
256:                        UnsupportedEncodingException {
257:
258:                    TreeMap result = new TreeMap();
259:                    try {
260:                        BufferedReader in = TestUtil.getDataReader(
261:                                "IDNATestInput.txt", "utf-8");
262:
263:                        String tempStr = null;
264:                        int records = 0;
265:                        boolean firstLine = true;
266:                        HashMap hashItem = new HashMap();
267:
268:                        while ((tempStr = in.readLine()) != null) {
269:                            //ignore the first line if it's "====="
270:                            if (firstLine) {
271:                                if ("=====".equals(tempStr))
272:                                    continue;
273:                                firstLine = false;
274:                            }
275:
276:                            //Ignore empty line
277:                            if ("".equals(tempStr)) {
278:                                continue;
279:                            }
280:
281:                            String attr = "";//attribute
282:                            String body = "";//value
283:
284:                            //get attr and body from line input, and then set them into each hash item.                    
285:                            int postion = tempStr.indexOf(":");
286:                            if (postion > -1) {
287:                                attr = tempStr.substring(0, postion).trim();
288:                                body = tempStr.substring(postion + 1).trim();
289:
290:                                //deal with combination lines when end with '\'
291:                                while (null != body
292:                                        && body.length() > 0
293:                                        && '\\' == body
294:                                                .charAt(body.length() - 1)) {
295:                                    body = body.substring(0, body.length() - 1);
296:                                    body += "\n";
297:                                    tempStr = in.readLine();
298:                                    body += tempStr;
299:                                }
300:                            }
301:                            //push them to hash item
302:                            hashItem.put(attr, body);
303:
304:                            //if met "=====", it means this item is finished
305:                            if ("=====".equals(tempStr)) {
306:                                //set them into result, using records number as key
307:                                result.put(new Long(records), hashItem);
308:                                //create another hash item and continue
309:                                hashItem = new HashMap();
310:                                records++;
311:                                continue;
312:                            }
313:                        }
314:                    } catch (UnsupportedEncodingException e) {
315:                        throw e;
316:                    } catch (FileNotFoundException e) {
317:                        throw e;
318:                    } catch (IOException e) {
319:                        throw e;
320:                    }
321:                    return result;
322:                }
323:            }
324:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.