Source Code Cross Referenced for UCAConformanceTest.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » collator » 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.collator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /********************************************************************
002:         * COPYRIGHT: 
003:         * Copyright (c) 2002-2006, International Business Machines Corporation and
004:         * others. All Rights Reserved.
005:         ********************************************************************/
006:
007:        /**
008:         * UCAConformanceTest performs conformance tests defined in the data
009:         * files. ICU ships with stub data files, as the whole test are too 
010:         * long. To do the whole test, download the test files.
011:         */package com.ibm.icu.dev.test.collator;
012:
013:        import java.io.BufferedReader;
014:        import java.util.Locale;
015:
016:        import com.ibm.icu.dev.test.TestFmwk;
017:        import com.ibm.icu.dev.test.TestUtil;
018:        import com.ibm.icu.text.CollationKey;
019:        import com.ibm.icu.text.Collator;
020:        import com.ibm.icu.text.RuleBasedCollator;
021:        import com.ibm.icu.text.UTF16;
022:
023:        public class UCAConformanceTest extends TestFmwk {
024:
025:            /**
026:             * @param args
027:             */
028:            public static void main(String[] args) {
029:                new UCAConformanceTest().run(args);
030:            }
031:
032:            public UCAConformanceTest() {
033:            }
034:
035:            protected void init() throws Exception {
036:                UCA = (RuleBasedCollator) Collator.getInstance(new Locale(
037:                        "root", "", ""));
038:
039:                comparer = new UTF16.StringComparator(true, false,
040:                        UTF16.StringComparator.FOLD_CASE_DEFAULT);
041:            }
042:
043:            RuleBasedCollator UCA;
044:            RuleBasedCollator rbUCA;
045:            UTF16.StringComparator comparer;
046:
047:            public void TestTableNonIgnorable() {
048:                setCollNonIgnorable(UCA);
049:                openTestFile("NON_IGNORABLE");
050:                conformanceTest(UCA);
051:            }
052:
053:            public void TestTableShifted() {
054:                setCollShifted(UCA);
055:                openTestFile("SHIFTED");
056:                conformanceTest(UCA);
057:            }
058:
059:            public void TestRulesNonIgnorable() {
060:                initRbUCA();
061:
062:                setCollNonIgnorable(rbUCA);
063:                openTestFile("NON_IGNORABLE");
064:                conformanceTest(rbUCA);
065:            }
066:
067:            public void TestRulesShifted() {
068:                logln("This test is currently disabled, as it is impossible to "
069:                        + "wholly represent fractional UCA using tailoring rules.");
070:                return;
071:                /*        initRbUCA();
072:                 
073:                 if(U_SUCCESS(status)) {
074:                 setCollShifted(rbUCA);
075:                 openTestFile("SHIFTED");
076:                 testConformance(rbUCA);
077:                 }
078:                 */
079:            }
080:
081:            BufferedReader in;
082:
083:            private void openTestFile(String type) {
084:                String collationTest = "CollationTest_";
085:                String ext = ".txt";
086:                try {
087:                    if (in != null) {
088:                        in.close();
089:                    }
090:                } catch (Exception e) {
091:                    errln("Could not close the opened file!");
092:                    return;
093:                }
094:                try {
095:                    in = TestUtil.getDataReader(collationTest + type + ext);
096:                } catch (Exception e) {
097:                    try {
098:                        in = TestUtil.getDataReader(collationTest + type
099:                                + "_SHORT" + ext);
100:                    } catch (Exception e1) {
101:                        try {
102:                            in = TestUtil.getDataReader(collationTest + type
103:                                    + "_STUB" + ext);
104:                            logln("INFO: Working with the stub file.\n"
105:                                    + "If you need the full conformance test, please\n"
106:                                    + "download the appropriate data files from:\n"
107:                                    + "http://dev.icu-project.org/cgi-bin/viewcvs.cgi/unicodetools/com/ibm/text/data/");
108:                        } catch (Exception e11) {
109:                            errln("ERROR: Could not find any of the test files");
110:                        }
111:                    }
112:                }
113:            }
114:
115:            private void setCollNonIgnorable(RuleBasedCollator coll) {
116:                if (coll != null) {
117:                    coll
118:                            .setDecomposition(RuleBasedCollator.CANONICAL_DECOMPOSITION);
119:                    coll.setLowerCaseFirst(false);
120:                    coll.setCaseLevel(false);
121:                    coll.setStrength(RuleBasedCollator.TERTIARY);
122:                    coll.setAlternateHandlingShifted(false);
123:                }
124:            }
125:
126:            private void setCollShifted(RuleBasedCollator coll) {
127:                if (coll != null) {
128:                    coll
129:                            .setDecomposition(RuleBasedCollator.CANONICAL_DECOMPOSITION);
130:                    coll.setLowerCaseFirst(false);
131:                    coll.setCaseLevel(false);
132:                    coll.setStrength(RuleBasedCollator.QUATERNARY);
133:                    coll.setAlternateHandlingShifted(true);
134:                }
135:            }
136:
137:            private void initRbUCA() {
138:                /*      if(!rbUCA) {
139:                 UParseError parseError;
140:                 UChar      *ucarules = buffer;
141:                 int32_t size = ucol_getRulesEx(UCA, UCOL_FULL_RULES, ucarules, 
142:                 BUFFER_SIZE_);
143:                 if (size > BUFFER_SIZE_) {
144:                 ucarules = (UChar *)malloc(size * sizeof(UChar));
145:                 size = ucol_getRulesEx(UCA, UCOL_FULL_RULES, ucarules, size);
146:                 }
147:                 rbUCA = ucol_openRules(ucarules, size, UCOL_DEFAULT, UCOL_TERTIARY, 
148:                 &parseError, &status);
149:                 if (U_FAILURE(status)) {
150:                 errln("Failure creating UCA rule-based collator: %s", u_errorName(status));
151:                 return;
152:                 }
153:                 }
154:                 */
155:            }
156:
157:            private String parseString(String line) {
158:                int i = 0, value;
159:                StringBuffer result = new StringBuffer(), buffer = new StringBuffer();
160:
161:                for (;;) {
162:                    while (Character.isWhitespace(line.charAt(i))) {
163:                        i++;
164:                    }
165:                    if (line.charAt(i) == ';' || i == line.length()) {
166:                        return result.toString();
167:                    }
168:                    while (Character.isLetterOrDigit(line.charAt(i))) {
169:                        buffer.append(line.charAt(i));
170:                        i++;
171:                    }
172:                    /* read one code point */
173:                    value = Integer.parseInt(buffer.toString(), 16);
174:                    buffer.delete(0, buffer.length());
175:
176:                    UTF16.append(result, value);
177:                }
178:
179:            }
180:
181:            private void conformanceTest(RuleBasedCollator coll) {
182:                if (in == null || coll == null) {
183:                    return;
184:                }
185:
186:                int lineNo = 0;
187:
188:                String line = null, oldLine = null, buffer = null, oldB = null;
189:                CollationKey oldSk = null, newSk = null;
190:
191:                int res = 0, cmpres = 0, cmpres2 = 0;
192:
193:                try {
194:                    while ((line = in.readLine()) != null) {
195:                        lineNo++;
196:                        if (line.length() < 3 || line.charAt(0) == '#') {
197:                            continue;
198:                        }
199:                        buffer = parseString(line);
200:
201:                        newSk = coll.getCollationKey(buffer);
202:                        if (oldSk != null) {
203:                            res = oldSk.compareTo(newSk);
204:                            cmpres = coll.compare(oldB, buffer);
205:                            cmpres2 = coll.compare(buffer, oldB);
206:
207:                            if (cmpres != -cmpres2) {
208:                                errln("Compare result not symmetrical on line "
209:                                        + lineNo);
210:                            }
211:                            if (((res & 0x80000000) != (cmpres & 0x80000000))
212:                                    || (res == 0 && cmpres != 0)
213:                                    || (res != 0 && cmpres == 0)) {
214:                                errln("Difference between ucol_strcoll and sortkey compare on line "
215:                                        + lineNo);
216:                                logln(oldLine);
217:                                logln(line);
218:                            }
219:
220:                            if (res > 0) {
221:                                errln("Line "
222:                                        + lineNo
223:                                        + " is not greater or equal than previous line");
224:                                logln(oldLine);
225:                                logln(line);
226:                                cmpres = coll.compare(oldB, buffer);
227:                            } else if (res == 0) { // equal 
228:                                res = comparer.compare(oldB, buffer);
229:                                if (res == 0) {
230:                                    errln("Probable error in test file on line "
231:                                            + lineNo
232:                                            + " (comparing identical strings)");
233:                                    logln(oldLine);
234:                                    logln(line);
235:                                } else if (res > 0) {
236:                                    errln("Sortkeys are identical, but code point comapare gives >0 on line "
237:                                            + lineNo);
238:                                    logln(oldLine);
239:                                    logln(line);
240:                                }
241:                            }
242:                        }
243:
244:                        oldSk = newSk;
245:                        oldB = buffer;
246:                        oldLine = line;
247:                    }
248:                } catch (Exception e) {
249:                    errln("Unexpected exception " + e);
250:                }
251:            }
252:
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.