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


001:        //##header
002:        /*
003:         **********************************************************************
004:         * Copyright (c) 2003-2005, International Business Machines
005:         * Corporation and others.  All Rights Reserved.
006:         **********************************************************************
007:         * Author: Alan Liu
008:         * Created: March 8 2003
009:         * Since: ICU 2.6
010:         **********************************************************************
011:         */
012:        package com.ibm.icu.dev.test.util;
013:
014:        import java.util.Arrays;
015:        import java.util.HashSet;
016:        import java.util.List;
017:        import java.util.Set;
018:
019:        import com.ibm.icu.dev.test.TestFmwk;
020:        import com.ibm.icu.impl.Utility;
021:        import com.ibm.icu.text.UnicodeSet;
022:        import com.ibm.icu.util.ByteArrayWrapper;
023:
024:        /**
025:         * @test
026:         * @summary Test of internal Utility class
027:         */
028:        public class UtilityTest extends TestFmwk {
029:
030:            public static void main(String[] args) throws Exception {
031:                new UtilityTest().run(args);
032:            }
033:
034:            public void TestUnescape() {
035:                final String input = "Sch\\u00f6nes Auto: \\u20ac 11240.\\fPrivates Zeichen: \\U00102345\\e\\cC\\n \\x1b\\x{263a}";
036:
037:                final String expect = "Sch\u00F6nes Auto: \u20AC 11240.\u000CPrivates Zeichen: \uDBC8\uDF45\u001B\u0003\012 \u001B\u263A";
038:
039:                String result = Utility.unescape(input);
040:                if (!result.equals(expect)) {
041:                    errln("FAIL: Utility.unescape() returned " + result
042:                            + ", exp. " + expect);
043:                }
044:            }
045:
046:            public void TestFormat() {
047:                String data[] = {
048:                        "the quick brown fox jumps over the lazy dog",
049:                        // result of this conversion will exceed the original length and
050:                        // cause a newline to be inserted
051:                        "testing space , quotations \"",
052:                        "testing weird supplementary characters \ud800\udc00",
053:                        "testing control characters \u0001 and line breaking!! \n are we done yet?" };
054:                String result[] = {
055:                        "        \"the quick brown fox jumps over the lazy dog\"",
056:                        "        \"testing space , quotations \\042\"",
057:                        "        \"testing weird supplementary characters \\uD800\\uDC00\"",
058:                        "        \"testing control characters \\001 and line breaking!! \\n are we done ye\"+"
059:                                + Utility.LINE_SEPARATOR + "        \"t?\"" };
060:                String result1[] = {
061:                        "\"the quick brown fox jumps over the lazy dog\"",
062:                        "\"testing space , quotations \\042\"",
063:                        "\"testing weird supplementary characters \\uD800\\uDC00\"",
064:                        "\"testing control characters \\001 and line breaking!! \\n are we done yet?\"" };
065:
066:                for (int i = 0; i < data.length; i++) {
067:                    assertEquals("formatForSource(\"" + data[i] + "\")",
068:                            result[i], Utility.formatForSource(data[i]));
069:                }
070:                for (int i = 0; i < data.length; i++) {
071:                    assertEquals("format1ForSource(\"" + data[i] + "\")",
072:                            result1[i], Utility.format1ForSource(data[i]));
073:                }
074:            }
075:
076:            public void TestHighBit() {
077:                int data[] = { -1, -1276, 0, 0xFFFF, 0x1234 };
078:                byte result[] = { -1, -1, -1, 15, 12 };
079:                for (int i = 0; i < data.length; i++) {
080:                    if (Utility.highBit(data[i]) != result[i]) {
081:                        errln("Fail: Highest bit of \\u"
082:                                + Integer.toHexString(data[i]) + " should be "
083:                                + result[i]);
084:                    }
085:                }
086:            }
087:
088:            public void TestCompareUnsigned() {
089:                int data[] = { 0, 1, 0x8fffffff, -1, Integer.MAX_VALUE,
090:                        Integer.MIN_VALUE, 2342423, -2342423 };
091:                for (int i = 0; i < data.length; i++) {
092:                    for (int j = 0; j < data.length; j++) {
093:                        if (Utility.compareUnsigned(data[i], data[j]) != compareLongUnsigned(
094:                                data[i], data[j])) {
095:                            errln("Fail: Unsigned comparison failed with "
096:                                    + data[i] + " " + data[i + 1]);
097:                        }
098:                    }
099:                }
100:            }
101:
102:            // This test indends to test the utility class ByteArrayWrapper
103:            // Seems that the class is somewhat incomplete, for example
104:            //      - getHashCode(Object) is weird
105:            //      - PatternMatch feature(search part of array within the whole one) lacks
106:            public void TestByteArrayWrapper() {
107:                byte[] ba = { 0x00, 0x01, 0x02 };
108:                byte[] bb = { 0x00, 0x01, 0x02, -1 };
109:                //#ifndef FOUNDATION
110:                java.nio.ByteBuffer buffer = java.nio.ByteBuffer.wrap(ba);
111:                //#else
112:                //##        com.ibm.icu.impl.ByteBuffer buffer = com.ibm.icu.impl.ByteBuffer.wrap(ba);
113:                //#endif
114:                ByteArrayWrapper x = new ByteArrayWrapper(buffer);
115:
116:                ByteArrayWrapper y = new ByteArrayWrapper(ba, 3);
117:                ByteArrayWrapper z = new ByteArrayWrapper(bb, 3);
118:
119:                if (!y.toString().equals("00 01 02")) {
120:                    errln("FAIL: test toString : Failed!");
121:                }
122:
123:                // test equality
124:                if (!x.equals(y) || !x.equals(z))
125:                    errln("FAIL: test (operator ==): Failed!");
126:                if (x.hashCode() != y.hashCode())
127:                    errln("FAIL: identical objects have different hash codes.");
128:
129:                // test non-equality
130:                y = new ByteArrayWrapper(bb, 4);
131:                if (x.equals(y))
132:                    errln("FAIL: test (operator !=): Failed!");
133:
134:                // test sign of unequal comparison
135:                if ((x.compareTo(y) > 0) != (y.compareTo(x) < 0)) {
136:                    errln("FAIL: comparisons not opposite sign");
137:                }
138:            }
139:
140:            private int compareLongUnsigned(int x, int y) {
141:                long x1 = x & 0xFFFFFFFFl;
142:                long y1 = y & 0xFFFFFFFFl;
143:                if (x1 < y1) {
144:                    return -1;
145:                } else if (x1 > y1) {
146:                    return 1;
147:                }
148:                return 0;
149:            }
150:
151:            public void TestUnicodeSet() {
152:                String[] array = new String[] { "a", "b", "c", "{de}" };
153:                List list = Arrays.asList(array);
154:                Set aset = new HashSet(list);
155:                logln(" *** The source set's size is: " + aset.size());
156:                //The size reads 4
157:                UnicodeSet set = new UnicodeSet();
158:                set.clear();
159:                set.addAll(aset);
160:                logln(" *** After addAll, the UnicodeSet size is: "
161:                        + set.size());
162:                //The size should also read 4, but 0 is seen instead
163:
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.