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


001:        /*****************************************************************************************
002:         *
003:         *   Copyright (C) 1996-2006, International Business Machines
004:         *   Corporation and others.  All Rights Reserved.
005:         **/
006:
007:        /** 
008:         * Port From:   JDK 1.4b1 : java.text.Format.IntlTestNumberFormatAPI
009:         * Source File: java/text/format/IntlTestNumberFormatAPI.java
010:         **/package com.ibm.icu.dev.test.format;
011:
012:        import com.ibm.icu.text.*;
013:        import com.ibm.icu.util.ULocale;
014:
015:        import java.util.Locale;
016:        import java.math.BigDecimal;
017:        import java.math.BigInteger;
018:        import java.text.FieldPosition;
019:        import java.text.ParsePosition;
020:        import java.text.ParseException;
021:
022:        public class IntlTestNumberFormatAPI extends
023:                com.ibm.icu.dev.test.TestFmwk {
024:            public static void main(String[] args) throws Exception {
025:                new IntlTestNumberFormatAPI().run(args);
026:            }
027:
028:            // This test checks various generic API methods in DecimalFormat to achieve 100% API coverage.
029:            public void TestAPI() {
030:                logln("NumberFormat API test---");
031:                logln("");
032:                Locale.setDefault(Locale.ENGLISH);
033:
034:                // ======= Test constructors
035:
036:                logln("Testing NumberFormat constructors");
037:
038:                NumberFormat def = NumberFormat.getInstance();
039:
040:                NumberFormat fr = NumberFormat.getInstance(Locale.FRENCH);
041:
042:                NumberFormat cur = NumberFormat.getCurrencyInstance();
043:
044:                NumberFormat cur_fr = NumberFormat
045:                        .getCurrencyInstance(Locale.FRENCH);
046:
047:                NumberFormat per = NumberFormat.getPercentInstance();
048:
049:                NumberFormat per_fr = NumberFormat
050:                        .getPercentInstance(Locale.FRENCH);
051:
052:                NumberFormat integer = NumberFormat.getIntegerInstance();
053:
054:                NumberFormat int_fr = NumberFormat
055:                        .getIntegerInstance(Locale.FRENCH);
056:
057:                //Fix "The variable is never used" compilation warnings
058:                logln("Currency : " + cur.format(1234.5));
059:                logln("Percent : " + per.format(1234.5));
060:                logln("Integer : " + integer.format(1234.5));
061:                logln("Int_fr : " + int_fr.format(1234.5));
062:
063:                // ======= Test equality
064:
065:                logln("Testing equality operator");
066:
067:                if (per_fr.equals(cur_fr)) {
068:                    errln("ERROR: == failed");
069:                }
070:
071:                // ======= Test various format() methods
072:
073:                logln("Testing various format() methods");
074:
075:                //        final double d = -10456.0037; // this appears as -10456.003700000001 on NT
076:                //        final double d = -1.04560037e-4; // this appears as -1.0456003700000002E-4 on NT
077:                final double d = -10456.00370000000000; // this works!
078:                final long l = 100000000;
079:
080:                String res1 = new String();
081:                String res2 = new String();
082:                StringBuffer res3 = new StringBuffer();
083:                StringBuffer res4 = new StringBuffer();
084:                StringBuffer res5 = new StringBuffer();
085:                StringBuffer res6 = new StringBuffer();
086:                FieldPosition pos1 = new FieldPosition(0);
087:                FieldPosition pos2 = new FieldPosition(0);
088:                FieldPosition pos3 = new FieldPosition(0);
089:                FieldPosition pos4 = new FieldPosition(0);
090:
091:                res1 = cur_fr.format(d);
092:                logln("" + d + " formatted to " + res1);
093:
094:                res2 = cur_fr.format(l);
095:                logln("" + l + " formatted to " + res2);
096:
097:                res3 = cur_fr.format(d, res3, pos1);
098:                logln("" + d + " formatted to " + res3);
099:
100:                res4 = cur_fr.format(l, res4, pos2);
101:                logln("" + l + " formatted to " + res4);
102:
103:                res5 = cur_fr.format(d, res5, pos3);
104:                logln("" + d + " formatted to " + res5);
105:
106:                res6 = cur_fr.format(l, res6, pos4);
107:                logln("" + l + " formatted to " + res6);
108:
109:                // ======= Test parse()
110:
111:                logln("Testing parse()");
112:
113:                //        String text = new String("-10,456.0037");
114:                String text = new String("-10456,0037");
115:                ParsePosition pos = new ParsePosition(0);
116:                ParsePosition pos01 = new ParsePosition(0);
117:                double d1 = ((Number) fr.parseObject(text, pos)).doubleValue();
118:                if (d1 != d) {
119:                    errln("ERROR: Roundtrip failed (via parse()) for " + text);
120:                }
121:                logln(text + " parsed into " + d1);
122:
123:                double d2 = fr.parse(text, pos01).doubleValue();
124:                if (d2 != d) {
125:                    errln("ERROR: Roundtrip failed (via parse()) for " + text);
126:                }
127:                logln(text + " parsed into " + d2);
128:
129:                double d3 = 0;
130:                try {
131:                    d3 = fr.parse(text).doubleValue();
132:                } catch (ParseException e) {
133:                    errln("ERROR: parse() failed");
134:                }
135:                if (d3 != d) {
136:                    errln("ERROR: Roundtrip failed (via parse()) for " + text);
137:                }
138:                logln(text + " parsed into " + d3);
139:
140:                // ======= Test getters and setters
141:
142:                logln("Testing getters and setters");
143:
144:                final Locale[] locales = NumberFormat.getAvailableLocales();
145:                long count = locales.length;
146:                logln("Got " + count + " locales");
147:                for (int i = 0; i < count; i++) {
148:                    String name;
149:                    name = locales[i].getDisplayName();
150:                    logln(name);
151:                }
152:
153:                fr.setParseIntegerOnly(def.isParseIntegerOnly());
154:                if (fr.isParseIntegerOnly() != def.isParseIntegerOnly()) {
155:                    errln("ERROR: setParseIntegerOnly() failed");
156:                }
157:
158:                fr.setGroupingUsed(def.isGroupingUsed());
159:                if (fr.isGroupingUsed() != def.isGroupingUsed()) {
160:                    errln("ERROR: setGroupingUsed() failed");
161:                }
162:
163:                fr.setMaximumIntegerDigits(def.getMaximumIntegerDigits());
164:                if (fr.getMaximumIntegerDigits() != def
165:                        .getMaximumIntegerDigits()) {
166:                    errln("ERROR: setMaximumIntegerDigits() failed");
167:                }
168:
169:                fr.setMinimumIntegerDigits(def.getMinimumIntegerDigits());
170:                if (fr.getMinimumIntegerDigits() != def
171:                        .getMinimumIntegerDigits()) {
172:                    errln("ERROR: setMinimumIntegerDigits() failed");
173:                }
174:
175:                fr.setMaximumFractionDigits(def.getMaximumFractionDigits());
176:                if (fr.getMaximumFractionDigits() != def
177:                        .getMaximumFractionDigits()) {
178:                    errln("ERROR: setMaximumFractionDigits() failed");
179:                }
180:
181:                fr.setMinimumFractionDigits(def.getMinimumFractionDigits());
182:                if (fr.getMinimumFractionDigits() != def
183:                        .getMinimumFractionDigits()) {
184:                    errln("ERROR: setMinimumFractionDigits() failed");
185:                }
186:
187:                // ======= Test getStaticClassID()
188:
189:                //        logln("Testing instanceof()");
190:
191:                //        try {
192:                //            NumberFormat test = new DecimalFormat();
193:
194:                //            if (! (test instanceof DecimalFormat)) {
195:                //                errln("ERROR: instanceof failed");
196:                //            }
197:                //        }
198:                //        catch (Exception e) {
199:                //            errln("ERROR: Couldn't create a DecimalFormat");
200:                //        }
201:            }
202:
203:            // Jitterbug 4451, for coverage
204:            public void TestCoverage() {
205:                class StubNumberFormat extends NumberFormat {
206:                    public void run() {
207:                        String p = NumberFormat.getPattern(ULocale.getDefault()
208:                                .toLocale(), 0);
209:                        if (!p.equals(NumberFormat.getPattern(ULocale
210:                                .getDefault(), 0))) {
211:                            errln("NumberFormat.getPattern(Locale, int) should delegate to (ULocale,)");
212:                        }
213:                    }
214:
215:                    public StringBuffer format(double number,
216:                            StringBuffer toAppendTo, FieldPosition pos) {
217:                        return null;
218:                    }
219:
220:                    public StringBuffer format(long number,
221:                            StringBuffer toAppendTo, FieldPosition pos) {
222:                        return null;
223:                    }
224:
225:                    public StringBuffer format(BigInteger number,
226:                            StringBuffer toAppendTo, FieldPosition pos) {
227:                        return null;
228:                    }
229:
230:                    public StringBuffer format(BigDecimal number,
231:                            StringBuffer toAppendTo, FieldPosition pos) {
232:                        return null;
233:                    }
234:
235:                    public StringBuffer format(
236:                            com.ibm.icu.math.BigDecimal number,
237:                            StringBuffer toAppendTo, FieldPosition pos) {
238:                        return null;
239:                    }
240:
241:                    public Number parse(String text, ParsePosition parsePosition) {
242:                        return null;
243:                    }
244:                }
245:                new StubNumberFormat().run();
246:            }
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.