001: /*
002: *******************************************************************************
003: * Copyright (C) 1996-2006, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: *
007: */
008:
009: package com.ibm.icu.dev.test.serializable;
010:
011: import java.util.Locale;
012:
013: import com.ibm.icu.util.BuddhistCalendar;
014: import com.ibm.icu.util.Calendar;
015: import com.ibm.icu.util.ChineseCalendar;
016: import com.ibm.icu.util.CopticCalendar;
017: import com.ibm.icu.util.EthiopicCalendar;
018: import com.ibm.icu.util.GregorianCalendar;
019: import com.ibm.icu.util.HebrewCalendar;
020: import com.ibm.icu.util.IslamicCalendar;
021: import com.ibm.icu.util.JapaneseCalendar;
022: import com.ibm.icu.util.TimeZone;
023:
024: /**
025: * @author emader
026: *
027: * TODO To change the template for this generated type comment go to
028: * Window - Preferences - Java - Code Style - Code Templates
029: */
030: public class CalendarTests {
031: static class CalendarHandler implements SerializableTest.Handler {
032: public Object[] getTestObjects() {
033: Locale locales[] = SerializableTest.getLocales();
034: TimeZone pst = TimeZone.getTimeZone("America/Los_Angeles");
035: Calendar calendars[] = new Calendar[locales.length];
036:
037: for (int i = 0; i < locales.length; i += 1) {
038: calendars[i] = Calendar.getInstance(pst, locales[i]);
039: }
040:
041: return calendars;
042: }
043:
044: public boolean hasSameBehavior(Object a, Object b) {
045: Calendar cal_a = (Calendar) a;
046: Calendar cal_b = (Calendar) b;
047: long now = System.currentTimeMillis();
048:
049: cal_a.setTimeInMillis(now);
050: cal_a.roll(Calendar.MONTH, 1);
051:
052: cal_b.setTimeInMillis(now);
053: cal_b.roll(Calendar.MONTH, 1);
054:
055: return cal_a.getTime().equals(cal_a.getTime());
056: }
057: }
058:
059: static class BuddhistCalendarHandler extends CalendarHandler {
060: public Object[] getTestObjects() {
061: Locale locales[] = SerializableTest.getLocales();
062: TimeZone tst = TimeZone.getTimeZone("Asia/Bangkok");
063: BuddhistCalendar calendars[] = new BuddhistCalendar[locales.length];
064:
065: for (int i = 0; i < locales.length; i += 1) {
066: calendars[i] = new BuddhistCalendar(tst, locales[i]);
067: }
068:
069: return calendars;
070: }
071: }
072:
073: static class ChineseCalendarHandler extends CalendarHandler {
074: public Object[] getTestObjects() {
075: Locale locales[] = SerializableTest.getLocales();
076: TimeZone cst = TimeZone.getTimeZone("Asia/Shanghai");
077: ChineseCalendar calendars[] = new ChineseCalendar[locales.length];
078:
079: for (int i = 0; i < locales.length; i += 1) {
080: calendars[i] = new ChineseCalendar(cst, locales[i]);
081: }
082:
083: return calendars;
084: }
085: }
086:
087: static class CopticCalendarHandler extends CalendarHandler {
088: public Object[] getTestObjects() {
089: Locale locales[] = SerializableTest.getLocales();
090: TimeZone ast = TimeZone.getTimeZone("Europe/Athens");
091: CopticCalendar calendars[] = new CopticCalendar[locales.length];
092:
093: for (int i = 0; i < locales.length; i += 1) {
094: calendars[i] = new CopticCalendar(ast, locales[i]);
095: }
096:
097: return calendars;
098: }
099: }
100:
101: static class EthiopicCalendarHandler extends CalendarHandler {
102: public Object[] getTestObjects() {
103: Locale locales[] = SerializableTest.getLocales();
104: TimeZone ast = TimeZone.getTimeZone("Africa/Addis_Ababa");
105: EthiopicCalendar calendars[] = new EthiopicCalendar[locales.length];
106:
107: for (int i = 0; i < locales.length; i += 1) {
108: calendars[i] = new EthiopicCalendar(ast, locales[i]);
109: }
110:
111: return calendars;
112: }
113: }
114:
115: static class GregorianCalendarHandler extends CalendarHandler {
116: public Object[] getTestObjects() {
117: Locale locales[] = SerializableTest.getLocales();
118: TimeZone pst = TimeZone.getTimeZone("America/Los_Angeles");
119: GregorianCalendar calendars[] = new GregorianCalendar[locales.length];
120:
121: for (int i = 0; i < locales.length; i += 1) {
122: calendars[i] = new GregorianCalendar(pst, locales[i]);
123: }
124:
125: return calendars;
126: }
127: }
128:
129: static class HebrewCalendarHandler extends CalendarHandler {
130: public Object[] getTestObjects() {
131: Locale locales[] = SerializableTest.getLocales();
132: TimeZone jst = TimeZone.getTimeZone("Asia/Jerusalem");
133: HebrewCalendar calendars[] = new HebrewCalendar[locales.length];
134:
135: for (int i = 0; i < locales.length; i += 1) {
136: calendars[i] = new HebrewCalendar(jst, locales[i]);
137: }
138:
139: return calendars;
140: }
141: }
142:
143: static class IslamicCalendarHandler extends CalendarHandler {
144: public Object[] getTestObjects() {
145: Locale locales[] = SerializableTest.getLocales();
146: TimeZone cst = TimeZone.getTimeZone("Africa/Cairo");
147: IslamicCalendar calendars[] = new IslamicCalendar[locales.length];
148:
149: for (int i = 0; i < locales.length; i += 1) {
150: calendars[i] = new IslamicCalendar(cst, locales[i]);
151: }
152:
153: return calendars;
154: }
155: }
156:
157: static class JapaneseCalendarHandler extends CalendarHandler {
158: public Object[] getTestObjects() {
159: Locale locales[] = SerializableTest.getLocales();
160: TimeZone jst = TimeZone.getTimeZone("Asia/Tokyo");
161: JapaneseCalendar calendars[] = new JapaneseCalendar[locales.length];
162:
163: for (int i = 0; i < locales.length; i += 1) {
164: calendars[i] = new JapaneseCalendar(jst, locales[i]);
165: }
166:
167: return calendars;
168: }
169: }
170:
171: public static void main(String[] args) {
172: //nothing needed yet...
173: }
174: }
|