Source Code Cross Referenced for IntlTestDateFormatAPI.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-2004, International Business Machines
004:         *   Corporation and others.  All Rights Reserved.
005:         **/
006:
007:        /** 
008:         * Port From:   JDK 1.4b1 : java.text.Format.IntlTestDateFormatAPI
009:         * Source File: java/text/format/IntlTestDateFormatAPI.java
010:         **/package com.ibm.icu.dev.test.format;
011:
012:        import com.ibm.icu.util.*;
013:        import com.ibm.icu.text.*;
014:        import java.util.Locale;
015:        import java.util.Date;
016:        import java.text.ParsePosition;
017:        import java.text.FieldPosition;
018:        import java.text.ParseException;
019:
020:        public class IntlTestDateFormatAPI extends
021:                com.ibm.icu.dev.test.TestFmwk {
022:            public static void main(String[] args) throws Exception {
023:                new IntlTestDateFormatAPI().run(args);
024:            }
025:
026:            // Test that the equals method works correctly.
027:            public void TestEquals() {
028:                // Create two objects at different system times
029:                DateFormat a = DateFormat.getInstance();
030:                Date start = Calendar.getInstance().getTime();
031:                while (true) {
032:                    // changed to remove compiler warnings.
033:                    if (!start.equals(Calendar.getInstance().getTime())) {
034:                        break; // Wait for time to change
035:                    }
036:                }
037:                DateFormat b = DateFormat.getInstance();
038:
039:                if (!(a.equals(b)))
040:                    errln("FAIL: DateFormat objects created at different times are unequal.");
041:
042:                // Why has this test been disabled??? - aliu
043:                //        if (b instanceof SimpleDateFormat)
044:                //        {
045:                //            //double ONE_YEAR = 365*24*60*60*1000.0; //The variable is never used
046:                //            try {
047:                //                ((SimpleDateFormat)b).setTwoDigitStartDate(start.getTime() + 50*ONE_YEAR);
048:                //                if (a.equals(b))
049:                //                    errln("FAIL: DateFormat objects with different two digit start dates are equal.");
050:                //            }
051:                //            catch (Exception e) {
052:                //                errln("FAIL: setTwoDigitStartDate failed.");
053:                //            }
054:                //        }
055:            }
056:
057:            // This test checks various generic API methods in DateFormat to achieve 100% API coverage.
058:            public void TestAPI() {
059:                logln("DateFormat API test---");
060:                logln("");
061:                Locale.setDefault(Locale.ENGLISH);
062:
063:                // ======= Test constructors
064:
065:                logln("Testing DateFormat constructors");
066:
067:                DateFormat def = DateFormat.getInstance();
068:                DateFormat fr = DateFormat.getTimeInstance(DateFormat.FULL,
069:                        Locale.FRENCH);
070:                DateFormat it = DateFormat.getDateInstance(DateFormat.MEDIUM,
071:                        Locale.ITALIAN);
072:                DateFormat de = DateFormat.getDateTimeInstance(DateFormat.LONG,
073:                        DateFormat.LONG, Locale.GERMAN);
074:
075:                // ======= Test equality
076:
077:                logln("Testing equality operator");
078:
079:                if (fr.equals(it)) {
080:                    errln("ERROR: equals failed");
081:                }
082:
083:                // ======= Test various format() methods
084:
085:                logln("Testing various format() methods");
086:
087:                Date d = new Date((long) 837039928046.0);
088:
089:                StringBuffer res1 = new StringBuffer();
090:                StringBuffer res2 = new StringBuffer();
091:                String res3 = new String();
092:                FieldPosition pos1 = new FieldPosition(0);
093:                FieldPosition pos2 = new FieldPosition(0);
094:
095:                res1 = fr.format(d, res1, pos1);
096:                logln("" + d.getTime() + " formatted to " + res1);
097:
098:                res2 = it.format(d, res2, pos2);
099:                logln("" + d.getTime() + " formatted to " + res2);
100:
101:                res3 = de.format(d);
102:                logln("" + d.getTime() + " formatted to " + res3);
103:
104:                // ======= Test parse()
105:
106:                logln("Testing parse()");
107:
108:                String text = new String("02/03/76 2:50 AM, CST");
109:                Object result1 = new Date();
110:                Date result2 = new Date();
111:                Date result3 = new Date();
112:                ParsePosition pos = new ParsePosition(0);
113:                ParsePosition pos01 = new ParsePosition(0);
114:
115:                result1 = def.parseObject(text, pos);
116:                if (result1 == null) {
117:                    errln("ERROR: parseObject() failed for " + text);
118:                }
119:                logln(text + " parsed into " + ((Date) result1).getTime());
120:
121:                try {
122:                    result2 = def.parse(text);
123:                } catch (ParseException e) {
124:                    errln("ERROR: parse() failed");
125:                }
126:                logln(text + " parsed into " + result2.getTime());
127:
128:                result3 = def.parse(text, pos01);
129:                if (result3 == null) {
130:                    errln("ERROR: parse() failed for " + text);
131:                }
132:                logln(text + " parsed into " + result3.getTime());
133:
134:                // ======= Test getters and setters
135:
136:                logln("Testing getters and setters");
137:
138:                final Locale[] locales = DateFormat.getAvailableLocales();
139:                long count = locales.length;
140:                logln("Got " + count + " locales");
141:                for (int i = 0; i < count; i++) {
142:                    String name;
143:                    name = locales[i].getDisplayName();
144:                    logln(name);
145:                }
146:
147:                fr.setLenient(it.isLenient());
148:                if (fr.isLenient() != it.isLenient()) {
149:                    errln("ERROR: setLenient() failed");
150:                }
151:
152:                final Calendar cal = def.getCalendar();
153:                Calendar newCal = (Calendar) cal.clone();
154:                de.setCalendar(newCal);
155:                it.setCalendar(newCal);
156:                if (!de.getCalendar().equals(it.getCalendar())) {
157:                    errln("ERROR: set Calendar() failed");
158:                }
159:
160:                final NumberFormat nf = def.getNumberFormat();
161:                NumberFormat newNf = (NumberFormat) nf.clone();
162:                de.setNumberFormat(newNf);
163:                it.setNumberFormat(newNf);
164:                if (!de.getNumberFormat().equals(it.getNumberFormat())) {
165:                    errln("ERROR: set NumberFormat() failed");
166:                }
167:
168:                final TimeZone tz = def.getTimeZone();
169:                TimeZone newTz = (TimeZone) tz.clone();
170:                de.setTimeZone(newTz);
171:                it.setTimeZone(newTz);
172:                if (!de.getTimeZone().equals(it.getTimeZone())) {
173:                    errln("ERROR: set TimeZone() failed");
174:                }
175:
176:                // ======= Test getStaticClassID()
177:
178:                //        logln("Testing instanceof()");
179:
180:                //        try {
181:                //            DateFormat test = new SimpleDateFormat();
182:
183:                //            if (! (test instanceof SimpleDateFormat)) {
184:                //                errln("ERROR: instanceof failed");
185:                //            }
186:                //        }
187:                //        catch (Exception e) {
188:                //            errln("ERROR: Couldn't create a DateFormat");
189:                //        }
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.