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.IntlTestDateFormatSymbols
009: * Source File: java/text/format/IntlTestDateFormatSymbols.java
010: **/package com.ibm.icu.dev.test.format;
011:
012: import com.ibm.icu.text.*;
013: import java.util.Locale;
014:
015: public class IntlTestDateFormatSymbols extends
016: com.ibm.icu.dev.test.TestFmwk {
017: public static void main(String[] args) throws Exception {
018: new IntlTestDateFormatSymbols().run(args);
019: }
020:
021: // Test getMonths
022: public void TestGetMonths() {
023: final String[] month;
024: DateFormatSymbols symbol;
025:
026: symbol = new DateFormatSymbols(Locale.getDefault());
027:
028: month = symbol.getMonths();
029: int cnt = month.length;
030:
031: logln("size = " + cnt);
032:
033: for (int i = 0; i < cnt; ++i) {
034: logln(month[i]);
035: }
036: }
037:
038: public void TestGetMonths2() {
039: DateFormatSymbols symbol;
040: symbol = new DateFormatSymbols(Locale.getDefault());
041:
042: int[] context = { DateFormatSymbols.STANDALONE,
043: DateFormatSymbols.FORMAT };
044: int[] width = { DateFormatSymbols.WIDE,
045: DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW };
046:
047: for (int i = 0; i < context.length; i++) {
048: for (int j = 0; j < width.length; j++) {
049: String[] month = symbol.getMonths(context[i], width[j]);
050: int cnt = month.length;
051:
052: logln("size = " + cnt);
053:
054: for (int k = 0; k < month.length; k++) {
055: logln(month[k]);
056: }
057: }
058: }
059: }
060:
061: public void TestGetWeekdays2() {
062: DateFormatSymbols symbol;
063: symbol = new DateFormatSymbols(Locale.getDefault());
064:
065: int[] context = { DateFormatSymbols.STANDALONE,
066: DateFormatSymbols.FORMAT };
067: int[] width = { DateFormatSymbols.WIDE,
068: DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW };
069:
070: for (int i = 0; i < context.length; i++) {
071: for (int j = 0; j < width.length; j++) {
072: String[] wd = symbol.getWeekdays(context[i], width[j]);
073: int cnt = wd.length;
074:
075: logln("size = " + cnt);
076:
077: for (int k = 0; k < wd.length; k++) {
078: logln(wd[k]);
079: }
080: }
081: }
082:
083: }
084:
085: public void TestGetEraNames() {
086: DateFormatSymbols symbol;
087: symbol = new DateFormatSymbols(Locale.getDefault());
088: String[] s = symbol.getEraNames();
089: for (int i = 0; i < s.length; i++) {
090: logln(s[i]);
091: }
092:
093: }
094:
095: // Test the API of DateFormatSymbols; primarily a simple get/set set.
096: public void TestSymbols() {
097: DateFormatSymbols fr = new DateFormatSymbols(Locale.FRENCH);
098: DateFormatSymbols fr2 = new DateFormatSymbols(Locale.FRENCH);
099:
100: DateFormatSymbols en = new DateFormatSymbols(Locale.ENGLISH);
101:
102: if (en.equals(fr)) {
103: errln("ERROR: English DateFormatSymbols equal to French");
104: }
105:
106: // just do some VERY basic tests to make sure that get/set work
107:
108: long count;
109: final String[] eras = en.getEras();
110: fr.setEras(eras);
111: final String[] eras1 = fr.getEras();
112: count = eras.length;
113: if (count != eras1.length) {
114: errln("ERROR: setEras() failed (different size array)");
115: } else {
116: for (int i = 0; i < count; i++) {
117: if (!eras[i].equals(eras1[i])) {
118: errln("ERROR: setEras() failed (different string values)");
119: }
120: }
121: }
122:
123: final String[] months = en.getMonths();
124: fr.setMonths(months);
125: final String[] months1 = fr.getMonths();
126: count = months.length;
127: if (count != months1.length) {
128: errln("ERROR: setMonths() failed (different size array)");
129: } else {
130: for (int i = 0; i < count; i++) {
131: if (!months[i].equals(months1[i])) {
132: errln("ERROR: setMonths() failed (different string values)");
133: }
134: }
135: }
136:
137: final String[] shortMonths = en.getShortMonths();
138: fr.setShortMonths(shortMonths);
139: final String[] shortMonths1 = fr.getShortMonths();
140: count = shortMonths.length;
141: if (count != shortMonths1.length) {
142: errln("ERROR: setShortMonths() failed (different size array)");
143: } else {
144: for (int i = 0; i < count; i++) {
145: if (!shortMonths[i].equals(shortMonths1[i])) {
146: errln("ERROR: setShortMonths() failed (different string values)");
147: }
148: }
149: }
150:
151: final String[] wideMonths = en.getMonths(
152: DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
153: fr2.setMonths(wideMonths, DateFormatSymbols.FORMAT,
154: DateFormatSymbols.WIDE);
155: final String[] wideMonths1 = fr2.getMonths(
156: DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
157: count = wideMonths.length;
158: if (count != wideMonths1.length) {
159: errln("ERROR: setMonths(FORMAT,WIDE) failed (different size array)");
160: } else {
161: for (int i = 0; i < count; i++) {
162: if (!wideMonths[i].equals(wideMonths1[i])) {
163: errln("ERROR: setMonths(FORMAT,WIDE) failed (different string values)");
164: }
165: }
166: }
167:
168: final String[] abbrMonths = en
169: .getMonths(DateFormatSymbols.FORMAT,
170: DateFormatSymbols.ABBREVIATED);
171: fr2.setMonths(abbrMonths, DateFormatSymbols.FORMAT,
172: DateFormatSymbols.ABBREVIATED);
173: final String[] abbrMonths1 = fr2
174: .getMonths(DateFormatSymbols.FORMAT,
175: DateFormatSymbols.ABBREVIATED);
176: count = abbrMonths.length;
177: if (count != abbrMonths1.length) {
178: errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed (different size array)");
179: } else {
180: for (int i = 0; i < count; i++) {
181: if (!abbrMonths[i].equals(abbrMonths1[i])) {
182: errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed (different string values)");
183: }
184: }
185: }
186:
187: final String[] narrowMonths = en.getMonths(
188: DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
189: fr.setMonths(narrowMonths, DateFormatSymbols.FORMAT,
190: DateFormatSymbols.NARROW);
191: final String[] narrowMonths1 = fr.getMonths(
192: DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
193: count = narrowMonths.length;
194: if (count != narrowMonths1.length) {
195: errln("ERROR: setMonths(FORMAT,NARROW) failed (different size array)");
196: } else {
197: for (int i = 0; i < count; i++) {
198: if (!narrowMonths[i].equals(narrowMonths1[i])) {
199: errln("ERROR: setMonths(FORMAT,NARROW) failed (different string values)");
200: }
201: }
202: }
203:
204: final String[] standaloneMonths = en.getMonths(
205: DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
206: fr.setMonths(standaloneMonths, DateFormatSymbols.STANDALONE,
207: DateFormatSymbols.WIDE);
208: final String[] standaloneMonths1 = fr.getMonths(
209: DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
210: count = standaloneMonths.length;
211: if (count != standaloneMonths1.length) {
212: errln("ERROR: setMonths(STANDALONE,WIDE) failed (different size array)");
213: } else {
214: for (int i = 0; i < count; i++) {
215: if (!standaloneMonths[i].equals(standaloneMonths1[i])) {
216: errln("ERROR: setMonths(STANDALONE,WIDE) failed (different string values)");
217: }
218: }
219: }
220:
221: final String[] standaloneShortMonths = en.getMonths(
222: DateFormatSymbols.STANDALONE,
223: DateFormatSymbols.ABBREVIATED);
224: fr.setMonths(standaloneShortMonths,
225: DateFormatSymbols.STANDALONE,
226: DateFormatSymbols.ABBREVIATED);
227: final String[] standaloneShortMonths1 = fr.getMonths(
228: DateFormatSymbols.STANDALONE,
229: DateFormatSymbols.ABBREVIATED);
230: count = standaloneShortMonths.length;
231: if (count != standaloneShortMonths1.length) {
232: errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed (different size array)");
233: } else {
234: for (int i = 0; i < count; i++) {
235: if (!standaloneShortMonths[i]
236: .equals(standaloneShortMonths1[i])) {
237: errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed (different string values)");
238: }
239: }
240: }
241:
242: final String[] standaloneNarrowMonths = en.getMonths(
243: DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
244: fr.setMonths(standaloneNarrowMonths,
245: DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
246: final String[] standaloneNarrowMonths1 = fr.getMonths(
247: DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
248: count = standaloneNarrowMonths.length;
249: if (count != standaloneNarrowMonths1.length) {
250: errln("ERROR: setMonths(STANDALONE,NARROW) failed (different size array)");
251: } else {
252: for (int i = 0; i < count; i++) {
253: if (!standaloneNarrowMonths[i]
254: .equals(standaloneNarrowMonths1[i])) {
255: errln("ERROR: setMonths(STANDALONE,NARROW) failed (different string values)");
256: }
257: }
258: }
259:
260: final String[] weekdays = en.getWeekdays();
261: fr.setWeekdays(weekdays);
262: final String[] weekdays1 = fr.getWeekdays();
263: count = weekdays.length;
264: if (count != weekdays1.length) {
265: errln("ERROR: setWeekdays() failed (different size array)");
266: } else {
267: for (int i = 0; i < count; i++) {
268: if (!weekdays[i].equals(weekdays1[i])) {
269: errln("ERROR: setWeekdays() failed (different string values)");
270: }
271: }
272: }
273:
274: final String[] shortWeekdays = en.getShortWeekdays();
275: fr.setShortWeekdays(shortWeekdays);
276: final String[] shortWeekdays1 = fr.getShortWeekdays();
277: count = shortWeekdays.length;
278: if (count != shortWeekdays1.length) {
279: errln("ERROR: setShortWeekdays() failed (different size array)");
280: } else {
281: for (int i = 0; i < count; i++) {
282: if (!shortWeekdays[i].equals(shortWeekdays1[i])) {
283: errln("ERROR: setShortWeekdays() failed (different string values)");
284: }
285: }
286: }
287:
288: final String[] wideWeekdays = en.getWeekdays(
289: DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
290: fr2.setWeekdays(wideWeekdays, DateFormatSymbols.FORMAT,
291: DateFormatSymbols.WIDE);
292: final String[] wideWeekdays1 = fr2.getWeekdays(
293: DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
294: count = wideWeekdays.length;
295: if (count != wideWeekdays1.length) {
296: errln("ERROR: setWeekdays(FORMAT,WIDE) failed (different size array)");
297: } else {
298: for (int i = 0; i < count; i++) {
299: if (!wideWeekdays[i].equals(wideWeekdays1[i])) {
300: errln("ERROR: setWeekdays(FORMAT,WIDE) failed (different string values)");
301: }
302: }
303: }
304:
305: final String[] abbrWeekdays = en
306: .getWeekdays(DateFormatSymbols.FORMAT,
307: DateFormatSymbols.ABBREVIATED);
308: fr2.setWeekdays(abbrWeekdays, DateFormatSymbols.FORMAT,
309: DateFormatSymbols.ABBREVIATED);
310: final String[] abbrWeekdays1 = fr2
311: .getWeekdays(DateFormatSymbols.FORMAT,
312: DateFormatSymbols.ABBREVIATED);
313: count = abbrWeekdays.length;
314: if (count != abbrWeekdays1.length) {
315: errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed (different size array)");
316: } else {
317: for (int i = 0; i < count; i++) {
318: if (!abbrWeekdays[i].equals(abbrWeekdays1[i])) {
319: errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed (different string values)");
320: }
321: }
322: }
323:
324: final String[] narrowWeekdays = en.getWeekdays(
325: DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
326: fr.setWeekdays(narrowWeekdays, DateFormatSymbols.FORMAT,
327: DateFormatSymbols.NARROW);
328: final String[] narrowWeekdays1 = fr.getWeekdays(
329: DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
330: count = narrowWeekdays.length;
331: if (count != narrowWeekdays1.length) {
332: errln("ERROR: setWeekdays(FORMAT,NARROW) failed (different size array)");
333: } else {
334: for (int i = 0; i < count; i++) {
335: if (!narrowWeekdays[i].equals(narrowWeekdays1[i])) {
336: errln("ERROR: setWeekdays(FORMAT,NARROW) failed (different string values)");
337: }
338: }
339: }
340:
341: final String[] standaloneWeekdays = en.getWeekdays(
342: DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
343: fr.setWeekdays(standaloneWeekdays,
344: DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
345: final String[] standaloneWeekdays1 = fr.getWeekdays(
346: DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
347: count = standaloneWeekdays.length;
348: if (count != standaloneWeekdays1.length) {
349: errln("ERROR: setWeekdays(STANDALONE,WIDE) failed (different size array)");
350: } else {
351: for (int i = 0; i < count; i++) {
352: if (!standaloneWeekdays[i]
353: .equals(standaloneWeekdays1[i])) {
354: errln("ERROR: setWeekdays(STANDALONE,WIDE) failed (different string values)");
355: }
356: }
357: }
358:
359: final String[] standaloneShortWeekdays = en.getWeekdays(
360: DateFormatSymbols.STANDALONE,
361: DateFormatSymbols.ABBREVIATED);
362: fr.setWeekdays(standaloneShortWeekdays,
363: DateFormatSymbols.STANDALONE,
364: DateFormatSymbols.ABBREVIATED);
365: final String[] standaloneShortWeekdays1 = fr.getWeekdays(
366: DateFormatSymbols.STANDALONE,
367: DateFormatSymbols.ABBREVIATED);
368: count = standaloneShortWeekdays.length;
369: if (count != standaloneShortWeekdays1.length) {
370: errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed (different size array)");
371: } else {
372: for (int i = 0; i < count; i++) {
373: if (!standaloneShortWeekdays[i]
374: .equals(standaloneShortWeekdays1[i])) {
375: errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed (different string values)");
376: }
377: }
378: }
379:
380: final String[] standaloneNarrowWeekdays = en.getWeekdays(
381: DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
382: fr.setWeekdays(standaloneNarrowWeekdays,
383: DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
384: final String[] standaloneNarrowWeekdays1 = fr.getWeekdays(
385: DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
386: count = standaloneNarrowWeekdays.length;
387: if (count != standaloneNarrowWeekdays1.length) {
388: errln("ERROR: setWeekdays(STANDALONE,NARROW) failed (different size array)");
389: } else {
390: for (int i = 0; i < count; i++) {
391: if (!standaloneNarrowWeekdays[i]
392: .equals(standaloneNarrowWeekdays1[i])) {
393: errln("ERROR: setWeekdays(STANDALONE,NARROW) failed (different string values)");
394: }
395: }
396: }
397:
398: final String[] wideQuarters = en.getQuarters(
399: DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
400: fr2.setQuarters(wideQuarters, DateFormatSymbols.FORMAT,
401: DateFormatSymbols.WIDE);
402: final String[] wideQuarters1 = fr2.getQuarters(
403: DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
404: count = wideQuarters.length;
405: if (count != wideQuarters1.length) {
406: errln("ERROR: setQuarters(FORMAT, WIDE) failed (different size array)");
407: } else {
408: for (int i = 0; i < count; i++) {
409: if (!wideQuarters[i].equals(wideQuarters1[i])) {
410: errln("ERROR: setQuarters(FORMAT, WIDE) failed (different string values)");
411: }
412: }
413: }
414:
415: final String[] abbrQuarters = en
416: .getQuarters(DateFormatSymbols.FORMAT,
417: DateFormatSymbols.ABBREVIATED);
418: fr2.setQuarters(abbrQuarters, DateFormatSymbols.FORMAT,
419: DateFormatSymbols.ABBREVIATED);
420: final String[] abbrQuarters1 = fr2
421: .getQuarters(DateFormatSymbols.FORMAT,
422: DateFormatSymbols.ABBREVIATED);
423: count = abbrQuarters.length;
424: if (count != abbrQuarters1.length) {
425: errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed (different size array)");
426: } else {
427: for (int i = 0; i < count; i++) {
428: if (!abbrQuarters[i].equals(abbrQuarters1[i])) {
429: errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed (different string values)");
430: }
431: }
432: }
433:
434: final String[] standaloneQuarters = en.getQuarters(
435: DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
436: fr.setQuarters(standaloneQuarters,
437: DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
438: final String[] standaloneQuarters1 = fr.getQuarters(
439: DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
440: count = standaloneQuarters.length;
441: if (count != standaloneQuarters1.length) {
442: errln("ERROR: setQuarters(STANDALONE, WIDE) failed (different size array)");
443: } else {
444: for (int i = 0; i < count; i++) {
445: if (!standaloneQuarters[i]
446: .equals(standaloneQuarters1[i])) {
447: errln("ERROR: setQuarters(STANDALONE, WIDE) failed (different string values)");
448: }
449: }
450: }
451:
452: final String[] standaloneShortQuarters = en.getQuarters(
453: DateFormatSymbols.STANDALONE,
454: DateFormatSymbols.ABBREVIATED);
455: fr.setQuarters(standaloneShortQuarters,
456: DateFormatSymbols.STANDALONE,
457: DateFormatSymbols.ABBREVIATED);
458: final String[] standaloneShortQuarters1 = fr.getQuarters(
459: DateFormatSymbols.STANDALONE,
460: DateFormatSymbols.ABBREVIATED);
461: count = standaloneShortQuarters.length;
462: if (count != standaloneShortQuarters1.length) {
463: errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed (different size array)");
464: } else {
465: for (int i = 0; i < count; i++) {
466: if (!standaloneShortQuarters[i]
467: .equals(standaloneShortQuarters1[i])) {
468: errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed (different string values)");
469: }
470: }
471: }
472:
473: final String[] ampms = en.getAmPmStrings();
474: fr.setAmPmStrings(ampms);
475: final String[] ampms1 = fr.getAmPmStrings();
476: count = ampms.length;
477: if (count != ampms1.length) {
478: errln("ERROR: setAmPmStrings() failed (different size array)");
479: } else {
480: for (int i = 0; i < count; i++) {
481: if (!ampms[i].equals(ampms1[i])) {
482: errln("ERROR: setAmPmStrings() failed (different string values)");
483: }
484: }
485: }
486:
487: long rowCount = 0, columnCount = 0;
488: final String[][] strings = en.getZoneStrings();
489: fr.setZoneStrings(strings);
490: final String[][] strings1 = fr.getZoneStrings();
491: rowCount = strings.length;
492: for (int i = 0; i < rowCount; i++) {
493: columnCount = strings[i].length;
494: for (int j = 0; j < columnCount; j++) {
495: if (strings[i][j] != strings1[i][j]) {
496: errln("ERROR: setZoneStrings() failed");
497: }
498: }
499: }
500:
501: // final String pattern = DateFormatSymbols.getPatternChars();
502:
503: String localPattern; // pat1, pat2; //The variable is never used
504: localPattern = en.getLocalPatternChars();
505: fr.setLocalPatternChars(localPattern);
506: if (!en.getLocalPatternChars()
507: .equals(fr.getLocalPatternChars())) {
508: errln("ERROR: setLocalPatternChars() failed");
509: }
510:
511: //DateFormatSymbols foo = new DateFormatSymbols(); //The variable is never used
512:
513: en = (DateFormatSymbols) fr.clone();
514:
515: if (!en.equals(fr)) {
516: errln("ERROR: Clone failed");
517: }
518: }
519: }
|