001: /*
002: *******************************************************************************
003: * Copyright (C) 2006, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007:
008: package com.ibm.icu.tests;
009:
010: import java.util.Date;
011: import java.util.Locale;
012:
013: import com.ibm.icu.util.Calendar;
014: import com.ibm.icu.util.TimeZone;
015: import com.ibm.icu.util.ULocale;
016:
017: public class TimeZoneTest extends ICUTestCase {
018:
019: /*
020: * Test method for 'com.ibm.icu.util.TimeZone.hashCode()'
021: */
022: public void testHashCode() {
023: TimeZone tz1 = TimeZone.getTimeZone("PST");
024: TimeZone tz2 = TimeZone.getTimeZone("PST");
025: TimeZone tzn = TimeZone.getTimeZone("CST");
026: testEHCS(tz1, tz2, tzn);
027: }
028:
029: /*
030: * Test method for 'com.ibm.icu.util.TimeZone.TimeZone(TimeZone)'
031: */
032: public void testTimeZone() {
033: // implicitly tested everywhere
034: }
035:
036: /*
037: * Test method for 'com.ibm.icu.util.TimeZone.getOffset(int, int, int, int, int, int)'
038: */
039: public void testGetOffset() {
040: TimeZone tz = TimeZone.getTimeZone("PST");
041: int offset = tz.getOffset(1, 2004, 0, 01, 1, 0);
042: assertEquals(-28800000, offset);
043: }
044:
045: /*
046: * Test method for 'com.ibm.icu.util.TimeZone.setRawOffset(int)'
047: */
048: public void testSetRawOffset() {
049: TimeZone tz = TimeZone.getTimeZone("PST");
050: int value = tz.getRawOffset();
051: int value1 = value + 100000;
052: tz.setRawOffset(value1);
053: int result = tz.getRawOffset();
054: assertNotEqual(value, result);
055: assertEquals(value1, result);
056: }
057:
058: /*
059: * Test method for 'com.ibm.icu.util.TimeZone.getRawOffset()'
060: */
061: public void testGetRawOffset() {
062: TimeZone tz = TimeZone.getTimeZone("PST");
063: int offset = tz.getRawOffset();
064: assertEquals(-28800000, offset);
065: }
066:
067: /*
068: * Test method for 'com.ibm.icu.util.TimeZone.getID()'
069: */
070: public void testGetID() {
071: TimeZone tz = TimeZone.getTimeZone("PST");
072: assertEquals("PST", tz.getID());
073: }
074:
075: /*
076: * Test method for 'com.ibm.icu.util.TimeZone.setID(String)'
077: */
078: public void testSetID() {
079: TimeZone tz = TimeZone.getTimeZone("PST");
080: String value1 = tz.getID();
081: String value2 = value1 + "!";
082: tz.setID(value2);
083: String result = tz.getID();
084: assertNotEqual(value1, result);
085: assertEquals(value2, result);
086: }
087:
088: /*
089: * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName()'
090: */
091: public void testGetDisplayName() {
092: TimeZone tz = TimeZone.getTimeZone("PST");
093: assertEquals("Pacific Standard Time", tz.getDisplayName());
094: }
095:
096: /*
097: * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(Locale)'
098: */
099: public void testGetDisplayNameLocale() {
100: TimeZone tz = TimeZone.getTimeZone("PST");
101: assertEquals("Pacific Standard Time", tz
102: .getDisplayName(Locale.US));
103: }
104:
105: /*
106: * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(ULocale)'
107: */
108: public void testGetDisplayNameULocale() {
109: TimeZone tz = TimeZone.getTimeZone("PST");
110: assertEquals("Pacific Standard Time", tz
111: .getDisplayName(ULocale.US));
112: }
113:
114: /*
115: * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(boolean, int)'
116: */
117: public void testGetDisplayNameBooleanInt() {
118: TimeZone tz = TimeZone.getTimeZone("PST");
119: assertEquals("PDT", tz.getDisplayName(true, TimeZone.SHORT));
120: assertEquals("Pacific Daylight Time", tz.getDisplayName(true,
121: TimeZone.LONG));
122: }
123:
124: /*
125: * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(boolean, int, Locale)'
126: */
127: public void testGetDisplayNameBooleanIntLocale() {
128: TimeZone tz = TimeZone.getTimeZone("PST");
129: assertEquals("PDT", tz.getDisplayName(true, TimeZone.SHORT,
130: Locale.US));
131: assertEquals("Pacific Daylight Time", tz.getDisplayName(true,
132: TimeZone.LONG, Locale.US));
133: }
134:
135: /*
136: * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(boolean, int, ULocale)'
137: */
138: public void testGetDisplayNameBooleanIntULocale() {
139: TimeZone tz = TimeZone.getTimeZone("PST");
140: assertEquals("PDT", tz.getDisplayName(true, TimeZone.SHORT,
141: ULocale.US));
142: assertEquals("Pacific Daylight Time", tz.getDisplayName(true,
143: TimeZone.LONG, ULocale.US));
144: }
145:
146: /*
147: * Test method for 'com.ibm.icu.util.TimeZone.getDSTSavings()'
148: */
149: public void testGetDSTSavings() {
150: TimeZone tz = TimeZone.getTimeZone("PST");
151: assertEquals(3600000, tz.getDSTSavings());
152: }
153:
154: /*
155: * Test method for 'com.ibm.icu.util.TimeZone.useDaylightTime()'
156: */
157: public void testUseDaylightTime() {
158: TimeZone tz = TimeZone.getTimeZone("PST");
159: assertTrue(tz.useDaylightTime());
160: }
161:
162: /*
163: * Test method for 'com.ibm.icu.util.TimeZone.inDaylightTime(Date)'
164: */
165: public void testInDaylightTime() {
166: TimeZone tz = TimeZone.getTimeZone("PST");
167: Calendar cal = Calendar.getInstance();
168: cal.set(2005, 0, 17);
169: Date date = cal.getTime();
170: assertFalse(tz.inDaylightTime(date));
171: cal.set(2005, 6, 17);
172: date = cal.getTime();
173: assertTrue(tz.inDaylightTime(date));
174: }
175:
176: /*
177: * Test method for 'com.ibm.icu.util.TimeZone.getTimeZone(String)'
178: */
179: public void testGetTimeZone() {
180: // implicitly tested everywhere
181: }
182:
183: /*
184: * Test method for 'com.ibm.icu.util.TimeZone.getAvailableIDs(int)'
185: */
186: public void testGetAvailableIDsInt() {
187: String[] ids = TimeZone.getAvailableIDs(-28800000);
188: assertNotNull(ids);
189: }
190:
191: /*
192: * Test method for 'com.ibm.icu.util.TimeZone.getAvailableIDs()'
193: */
194: public void testGetAvailableIDs() {
195: String[] ids = TimeZone.getAvailableIDs();
196: assertNotNull(ids);
197: }
198:
199: /*
200: * Test method for 'com.ibm.icu.util.TimeZone.getDefault()'
201: */
202: public void testGetDefault() {
203: TimeZone tz = TimeZone.getDefault();
204: assertNotNull(tz);
205: }
206:
207: /*
208: * Test method for 'com.ibm.icu.util.TimeZone.setDefault(TimeZone)'
209: */
210: public void testSetDefault() {
211: TimeZone tz1 = TimeZone.getDefault();
212: String newCode = "PDT".equals(tz1.getID()) ? "CST" : "PDT";
213: TimeZone tz2 = TimeZone.getTimeZone(newCode);
214: TimeZone.setDefault(tz2);
215: TimeZone result = TimeZone.getDefault();
216: assertNotEqual(tz1, result);
217: assertEquals(tz2, result);
218: }
219:
220: /*
221: * Test method for 'com.ibm.icu.util.TimeZone.hasSameRules(TimeZone)'
222: */
223: public void testHasSameRules() {
224: TimeZone tz1 = TimeZone.getTimeZone("PST");
225: TimeZone tz2 = TimeZone.getTimeZone("America/Los_Angeles");
226: assertTrue(tz1.hasSameRules(tz2));
227: }
228:
229: /*
230: * Test method for 'com.ibm.icu.util.TimeZone.clone()'
231: */
232: public void testClone() {
233: // tested by testHashCode
234: }
235:
236: /*
237: * Test method for 'com.ibm.icu.util.TimeZone.equals(Object)'
238: */
239: public void testEqualsObject() {
240: // tested by testHashCode
241: }
242: }
|