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


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 1996-2004, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:        package com.ibm.icu.dev.test.normalizer;
008:
009:        import com.ibm.icu.dev.test.TestFmwk;
010:        import com.ibm.icu.impl.NormalizerImpl;
011:        import com.ibm.icu.impl.Utility;
012:        import com.ibm.icu.lang.UCharacter;
013:        import com.ibm.icu.text.ComposedCharIter;
014:        import com.ibm.icu.text.Normalizer;
015:        import com.ibm.icu.text.StringCharacterIterator;
016:
017:        public class TestDeprecatedNormalizerAPI extends TestFmwk {
018:
019:            public static void main(String[] args) throws Exception {
020:                String[] tempArgs = new String[args.length];
021:                int count = 0;
022:
023:                // Allow the test to be pointed at a specific version of the Unicode database
024:                //for (int i = 0; i < args.length; i++)
025:                //{
026:                //    if (args[i].equals("-data")) {
027:                //        tempInfo = new UInfo(args[++i], args[++i]);
028:                //    } else {
029:                //        tempArgs[count++] = args[i];
030:                //    }
031:                //}
032:
033:                args = new String[count];
034:                System.arraycopy(tempArgs, 0, args, 0, count);
035:
036:                new TestDeprecatedNormalizerAPI().run(args);
037:            }
038:
039:            public TestDeprecatedNormalizerAPI() {
040:            }
041:
042:            public void TestNormalizerAPI() {
043:                // instantiate a Normalizer from a CharacterIterator
044:                String s = Utility.unescape("a\u0308\uac00\\U0002f800");
045:                // make s a bit longer and more interesting
046:                java.text.CharacterIterator iter = new StringCharacterIterator(
047:                        s + s);
048:                //test deprecated constructors
049:                Normalizer norm = new Normalizer(iter, Normalizer.NFC, 0);
050:                Normalizer norm2 = new Normalizer(s, Normalizer.NFC, 0);
051:                if (norm.next() != 0xe4) {
052:                    errln("error in Normalizer(CharacterIterator).next()");
053:                }
054:                // test clone(), ==, and hashCode()
055:                Normalizer clone = (Normalizer) norm.clone();
056:                if (clone.getBeginIndex() != norm.getBeginIndex()) {
057:                    errln("error in Normalizer.getBeginIndex()");
058:                }
059:
060:                if (clone.getEndIndex() != norm.getEndIndex()) {
061:                    errln("error in Normalizer.getEndIndex()");
062:                }
063:                // test setOption() and getOption()
064:                clone.setOption(0xaa0000, true);
065:                clone.setOption(0x20000, false);
066:                if (clone.getOption(0x880000) == 0
067:                        || clone.getOption(0x20000) == 1) {
068:                    errln("error in Normalizer::setOption() or Normalizer::getOption()");
069:                }
070:                //test deprecated normalize method
071:                Normalizer.normalize(s, Normalizer.NFC, 0);
072:                //test deprecated compose method
073:                Normalizer.compose(s, false, 0);
074:                //test deprecated decompose method
075:                Normalizer.decompose(s, false, 0);
076:
077:            }
078:
079:            /**
080:             * Run through all of the characters returned by a composed-char iterator
081:             * and make sure that:
082:             * <ul>
083:             * <li>a) They do indeed have decompositions.
084:             * <li>b) The decomposition according to the iterator is the same as
085:             *          returned by Normalizer.decompose().
086:             * <li>c) All characters <em>not</em> returned by the iterator do not
087:             *          have decompositions.
088:             * </ul>
089:             */
090:            public void TestComposedCharIter() {
091:                doTestComposedChars(false);
092:            }
093:
094:            public void doTestComposedChars(boolean compat) {
095:                int options = Normalizer.IGNORE_HANGUL;
096:                ComposedCharIter iter = new ComposedCharIter(compat, options);
097:
098:                char lastChar = 0;
099:
100:                while (iter.hasNext()) {
101:                    char ch = iter.next();
102:
103:                    // Test all characters between the last one and this one to make
104:                    // sure that they don't have decompositions
105:                    assertNoDecomp(lastChar, ch, compat, options);
106:                    lastChar = ch;
107:
108:                    // Now make sure that the decompositions for this character
109:                    // make sense
110:                    String chString = new StringBuffer().append(ch).toString();
111:                    String iterDecomp = iter.decomposition();
112:                    String normDecomp = Normalizer.decompose(chString, compat);
113:
114:                    if (iterDecomp.equals(chString)) {
115:                        errln("ERROR: " + hex(ch) + " has identical decomp");
116:                    } else if (!iterDecomp.equals(normDecomp)) {
117:                        errln("ERROR: Normalizer decomp for " + hex(ch) + " ("
118:                                + hex(normDecomp) + ")" + " != iter decomp ("
119:                                + hex(iterDecomp) + ")");
120:                    }
121:                }
122:                assertNoDecomp(lastChar, '\uFFFF', compat, options);
123:            }
124:
125:            void assertNoDecomp(char start, char limit, boolean compat,
126:                    int options) {
127:                for (char x = ++start; x < limit; x++) {
128:                    String xString = new StringBuffer().append(x).toString();
129:                    String decomp = Normalizer.decompose(xString, compat);
130:                    if (!decomp.equals(xString)) {
131:                        errln("ERROR: " + hex(x) + " has decomposition ("
132:                                + hex(decomp) + ")"
133:                                + " but was not returned by iterator");
134:                    }
135:                }
136:            }
137:
138:            public void TestRoundTrip() {
139:                int options = Normalizer.IGNORE_HANGUL;
140:                boolean compat = false;
141:
142:                ComposedCharIter iter = new ComposedCharIter(false, options);
143:                while (iter.hasNext()) {
144:                    char ch = iter.next();
145:
146:                    String chStr = new StringBuffer().append(ch).toString();
147:                    String decomp = Normalizer.decompose(chStr, compat);
148:                    String comp = Normalizer.compose(decomp, compat);
149:
150:                    int cClass = UCharacter.getCombiningClass(decomp.charAt(0));
151:                    cClass = 0;
152:
153:                    if (NormalizerImpl.isFullCompositionExclusion(ch)) {
154:                        logln("Skipped excluded char " + hex(ch) + " ("
155:                                + UCharacter.getName(ch) + ")");
156:                        continue;
157:                    }
158:
159:                    // Avoid disparaged characters
160:                    if (getDecomposition(ch, compat).length() == 4)
161:                        continue;
162:
163:                    if (!comp.equals(chStr)) {
164:                        errln("ERROR: Round trip invalid: " + hex(chStr)
165:                                + " --> " + hex(decomp) + " --> " + hex(comp));
166:
167:                        errln("  char decomp is '"
168:                                + getDecomposition(ch, compat) + "'");
169:                    }
170:                }
171:            }
172:
173:            private String getDecomposition(char ch, boolean compat) {
174:                char[] dest = new char[10];
175:                int length = NormalizerImpl.getDecomposition(ch, compat, dest,
176:                        0, dest.length);
177:                return new String(dest, 0, length);
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.