Source Code Cross Referenced for BreakIteratorRegTest.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » rbbi » 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.rbbi 
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.rbbi;
008:
009:        import com.ibm.icu.dev.test.TestFmwk;
010:        import com.ibm.icu.text.BreakIterator;
011:        import java.text.CharacterIterator;
012:        import java.util.Arrays;
013:        import java.util.Locale;
014:
015:        public class BreakIteratorRegTest extends TestFmwk {
016:            public static void main(String[] args) throws Exception {
017:                new BreakIteratorRegTest().run(args);
018:            }
019:
020:            public void TestRegUnreg() {
021:                Locale thailand_locale = new Locale("th", "TH", "");
022:                Locale foo_locale = new Locale("fu", "FU", "FOO");
023:                BreakIterator jwbi = BreakIterator
024:                        .getWordInstance(Locale.JAPAN);
025:                BreakIterator uwbi = BreakIterator.getWordInstance(Locale.US);
026:                BreakIterator usbi = BreakIterator
027:                        .getSentenceInstance(Locale.US);
028:                BreakIterator twbi = BreakIterator
029:                        .getWordInstance(thailand_locale);
030:                BreakIterator rwbi = BreakIterator.getWordInstance(new Locale(
031:                        "", "", ""));
032:
033:                BreakIterator sbi = (BreakIterator) usbi.clone();
034:                // todo: this will cause the test to fail, no way to set a breakiterator to null text so can't fix yet.
035:                // String text = "This is some test, by golly. Boy, they don't make tests like they used to, do they?  This here test ain't worth $2.50.  Nope.";
036:                // sbi.setText(text);
037:
038:                assertTrue(!BreakIterator.unregister(""),
039:                        "unregister before register"); // coverage
040:
041:                Object key0 = BreakIterator.registerInstance(
042:                        (BreakIterator) twbi.clone(), foo_locale,
043:                        BreakIterator.KIND_WORD);
044:                Object key1 = BreakIterator.registerInstance(sbi, Locale.US,
045:                        BreakIterator.KIND_WORD);
046:                Object key2 = BreakIterator.registerInstance(
047:                        (BreakIterator) twbi.clone(), Locale.US,
048:                        BreakIterator.KIND_WORD);
049:
050:                {
051:                    BreakIterator test0 = BreakIterator
052:                            .getWordInstance(Locale.JAPAN);
053:                    BreakIterator test1 = BreakIterator
054:                            .getWordInstance(Locale.US);
055:                    BreakIterator test2 = BreakIterator
056:                            .getSentenceInstance(Locale.US);
057:                    BreakIterator test3 = BreakIterator
058:                            .getWordInstance(thailand_locale);
059:                    BreakIterator test4 = BreakIterator
060:                            .getWordInstance(foo_locale);
061:
062:                    assertEqual(test0, jwbi, "japan word == japan word");
063:                    assertEqual(test1, twbi, "us word == thai word");
064:                    assertEqual(test2, usbi, "us sentence == us sentence");
065:                    assertEqual(test3, twbi, "thai word == thai word");
066:                    assertEqual(test4, twbi, "foo word == thai word");
067:                }
068:
069:                Locale[] locales = BreakIterator.getAvailableLocales();
070:
071:                assertTrue(BreakIterator.unregister(key2),
072:                        "unregister us word (thai word)");
073:                assertTrue(!BreakIterator.unregister(key2),
074:                        "unregister second time");
075:                boolean error = false;
076:                try {
077:                    BreakIterator.unregister(null);
078:                } catch (IllegalArgumentException e) {
079:                    error = true;
080:                }
081:
082:                assertTrue(error, "unregister null");
083:
084:                {
085:                    CharacterIterator sci = BreakIterator.getWordInstance(
086:                            Locale.US).getText();
087:                    int len = sci.getEndIndex() - sci.getBeginIndex();
088:                    assertEqual(len, 0, "us word text: " + getString(sci));
089:                }
090:
091:                assertTrue(Arrays.asList(BreakIterator.getAvailableLocales())
092:                        .contains(foo_locale), "foo_locale");
093:                assertTrue(BreakIterator.unregister(key0),
094:                        "unregister foo word (thai word)");
095:                assertTrue(!Arrays.asList(BreakIterator.getAvailableLocales())
096:                        .contains(foo_locale), "no foo_locale");
097:                assertEqual(BreakIterator.getWordInstance(Locale.US), usbi,
098:                        "us word == us sentence");
099:
100:                assertTrue(BreakIterator.unregister(key1),
101:                        "unregister us word (us sentence)");
102:                {
103:                    BreakIterator test0 = BreakIterator
104:                            .getWordInstance(Locale.JAPAN);
105:                    BreakIterator test1 = BreakIterator
106:                            .getWordInstance(Locale.US);
107:                    BreakIterator test2 = BreakIterator
108:                            .getSentenceInstance(Locale.US);
109:                    BreakIterator test3 = BreakIterator
110:                            .getWordInstance(thailand_locale);
111:                    BreakIterator test4 = BreakIterator
112:                            .getWordInstance(foo_locale);
113:
114:                    assertEqual(test0, jwbi, "japanese word break");
115:                    assertEqual(test1, uwbi, "us sentence-word break");
116:                    assertEqual(test2, usbi, "us sentence break");
117:                    assertEqual(test3, twbi, "thai word break");
118:                    assertEqual(test4, rwbi, "root word break");
119:
120:                    CharacterIterator sci = test1.getText();
121:                    int len = sci.getEndIndex() - sci.getBeginIndex();
122:                    assertEqual(len, 0, "us sentence-word break text: "
123:                            + getString(sci));
124:                }
125:            }
126:
127:            private void assertEqual(Object lhs, Object rhs, String msg) {
128:                msg(msg, lhs.equals(rhs) ? LOG : ERR, true, true);
129:            }
130:
131:            private void assertEqual(int lhs, int rhs, String msg) {
132:                msg(msg, lhs == rhs ? LOG : ERR, true, true);
133:            }
134:
135:            private void assertTrue(boolean arg, String msg) {
136:                msg(msg, arg ? LOG : ERR, true, true);
137:            }
138:
139:            private static String getString(CharacterIterator ci) {
140:                StringBuffer buf = new StringBuffer(ci.getEndIndex()
141:                        - ci.getBeginIndex() + 2);
142:                buf.append("'");
143:                for (char c = ci.first(); c != CharacterIterator.DONE; c = ci
144:                        .next()) {
145:                    buf.append(c);
146:                }
147:                buf.append("'");
148:                return buf.toString();
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.