1 /*****************************************************************************************
3 * Copyright (C) 1996-2010, International Business Machines
4 * Corporation and others. All Rights Reserved.
8 * Port From: JDK 1.4b1 : java.text.Format.IntlTestDateFormatSymbols
9 * Source File: java/text/format/IntlTestDateFormatSymbols.java
14 @summary test International Date Format Symbols
17 package com.ibm.icu.dev.test.format;
19 import java.util.Locale;
21 import com.ibm.icu.text.DateFormatSymbols;
23 public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
25 public static void main(String[] args) throws Exception {
26 new IntlTestDateFormatSymbols().run(args);
30 public void TestGetMonths()
33 DateFormatSymbols symbol;
35 symbol=new DateFormatSymbols(Locale.getDefault());
37 month=symbol.getMonths();
38 int cnt = month.length;
40 logln("size = " + cnt);
42 for (int i=0; i<cnt; ++i)
48 public void TestGetMonths2()
50 DateFormatSymbols symbol;
51 symbol=new DateFormatSymbols(Locale.getDefault());
53 int[] context = {DateFormatSymbols.STANDALONE, DateFormatSymbols.FORMAT};
54 int[] width = {DateFormatSymbols.WIDE, DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW};
56 for (int i = 0; i < context.length; i++) {
57 for (int j = 0; j < width.length; j++) {
58 String[] month =symbol.getMonths(context[i],width[j]);
59 int cnt = month.length;
61 logln("size = " + cnt);
63 for (int k = 0; k < month.length; k++) {
70 public void TestGetWeekdays2(){
71 DateFormatSymbols symbol;
72 symbol=new DateFormatSymbols(Locale.getDefault());
74 int[] context = {DateFormatSymbols.STANDALONE, DateFormatSymbols.FORMAT};
75 int[] width = {DateFormatSymbols.WIDE, DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW};
77 for (int i = 0; i < context.length; i++) {
78 for (int j = 0; j < width.length; j++) {
79 String[] wd =symbol.getWeekdays(context[i],width[j]);
82 logln("size = " + cnt);
84 for (int k = 0; k < wd.length; k++) {
92 public void TestGetEraNames(){
93 DateFormatSymbols symbol;
94 symbol=new DateFormatSymbols(Locale.getDefault());
95 String[] s = symbol.getEraNames();
96 for (int i = 0; i < s.length; i++) {
102 // Test the API of DateFormatSymbols; primarily a simple get/set set.
103 public void TestSymbols()
105 DateFormatSymbols fr = new DateFormatSymbols(Locale.FRENCH);
106 DateFormatSymbols fr2 = new DateFormatSymbols(Locale.FRENCH);
108 DateFormatSymbols en = new DateFormatSymbols(Locale.ENGLISH);
111 errln("ERROR: English DateFormatSymbols equal to French");
114 // just do some VERY basic tests to make sure that get/set work
117 final String[] eras = en.getEras();
119 final String[] eras1 = fr.getEras();
121 if( count != eras1.length) {
122 errln("ERROR: setEras() failed (different size array)");
125 for(int i = 0; i < count; i++) {
126 if(! eras[i].equals(eras1[i])) {
127 errln("ERROR: setEras() failed (different string values)");
133 final String[] months = en.getMonths();
134 fr.setMonths(months);
135 final String[] months1 = fr.getMonths();
136 count = months.length;
137 if( count != months1.length) {
138 errln("ERROR: setMonths() failed (different size array)");
141 for(int i = 0; i < count; i++) {
142 if(! months[i].equals(months1[i])) {
143 errln("ERROR: setMonths() failed (different string values)");
148 final String[] shortMonths = en.getShortMonths();
149 fr.setShortMonths(shortMonths);
150 final String[] shortMonths1 = fr.getShortMonths();
151 count = shortMonths.length;
152 if( count != shortMonths1.length) {
153 errln("ERROR: setShortMonths() failed (different size array)");
156 for(int i = 0; i < count; i++) {
157 if(! shortMonths[i].equals(shortMonths1[i])) {
158 errln("ERROR: setShortMonths() failed (different string values)");
163 final String[] wideMonths = en.getMonths(DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
164 fr2.setMonths(wideMonths,DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
165 final String[] wideMonths1 = fr2.getMonths(DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
166 count = wideMonths.length;
167 if( count != wideMonths1.length) {
168 errln("ERROR: setMonths(FORMAT,WIDE) failed (different size array)");
171 for(int i = 0; i < count; i++) {
172 if(! wideMonths[i].equals(wideMonths1[i])) {
173 errln("ERROR: setMonths(FORMAT,WIDE) failed (different string values)");
178 final String[] abbrMonths = en.getMonths(DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
179 fr2.setMonths(abbrMonths,DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
180 final String[] abbrMonths1 = fr2.getMonths(DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
181 count = abbrMonths.length;
182 if( count != abbrMonths1.length) {
183 errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed (different size array)");
186 for(int i = 0; i < count; i++) {
187 if(! abbrMonths[i].equals(abbrMonths1[i])) {
188 errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed (different string values)");
193 final String[] narrowMonths = en.getMonths(DateFormatSymbols.FORMAT,DateFormatSymbols.NARROW);
194 fr.setMonths(narrowMonths,DateFormatSymbols.FORMAT,DateFormatSymbols.NARROW);
195 final String[] narrowMonths1 = fr.getMonths(DateFormatSymbols.FORMAT,DateFormatSymbols.NARROW);
196 count = narrowMonths.length;
197 if( count != narrowMonths1.length) {
198 errln("ERROR: setMonths(FORMAT,NARROW) failed (different size array)");
201 for(int i = 0; i < count; i++) {
202 if(! narrowMonths[i].equals(narrowMonths1[i])) {
203 errln("ERROR: setMonths(FORMAT,NARROW) failed (different string values)");
208 final String[] standaloneMonths = en.getMonths(DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
209 fr.setMonths(standaloneMonths,DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
210 final String[] standaloneMonths1 = fr.getMonths(DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
211 count = standaloneMonths.length;
212 if( count != standaloneMonths1.length) {
213 errln("ERROR: setMonths(STANDALONE,WIDE) failed (different size array)");
216 for(int i = 0; i < count; i++) {
217 if(! standaloneMonths[i].equals(standaloneMonths1[i])) {
218 errln("ERROR: setMonths(STANDALONE,WIDE) failed (different string values)");
223 final String[] standaloneShortMonths = en.getMonths(DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
224 fr.setMonths(standaloneShortMonths,DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
225 final String[] standaloneShortMonths1 = fr.getMonths(DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
226 count = standaloneShortMonths.length;
227 if( count != standaloneShortMonths1.length) {
228 errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed (different size array)");
231 for(int i = 0; i < count; i++) {
232 if(! standaloneShortMonths[i].equals(standaloneShortMonths1[i])) {
233 errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed (different string values)");
238 final String[] standaloneNarrowMonths = en.getMonths(DateFormatSymbols.STANDALONE,DateFormatSymbols.NARROW);
239 fr.setMonths(standaloneNarrowMonths,DateFormatSymbols.STANDALONE,DateFormatSymbols.NARROW);
240 final String[] standaloneNarrowMonths1 = fr.getMonths(DateFormatSymbols.STANDALONE,DateFormatSymbols.NARROW);
241 count = standaloneNarrowMonths.length;
242 if( count != standaloneNarrowMonths1.length) {
243 errln("ERROR: setMonths(STANDALONE,NARROW) failed (different size array)");
246 for(int i = 0; i < count; i++) {
247 if(! standaloneNarrowMonths[i].equals(standaloneNarrowMonths1[i])) {
248 errln("ERROR: setMonths(STANDALONE,NARROW) failed (different string values)");
253 final String[] weekdays = en.getWeekdays();
254 fr.setWeekdays(weekdays);
255 final String[] weekdays1 = fr.getWeekdays();
256 count = weekdays.length;
257 if( count != weekdays1.length) {
258 errln("ERROR: setWeekdays() failed (different size array)");
261 for(int i = 0; i < count; i++) {
262 if(! weekdays[i].equals(weekdays1[i])) {
263 errln("ERROR: setWeekdays() failed (different string values)");
268 final String[] shortWeekdays = en.getShortWeekdays();
269 fr.setShortWeekdays(shortWeekdays);
270 final String[] shortWeekdays1 = fr.getShortWeekdays();
271 count = shortWeekdays.length;
272 if( count != shortWeekdays1.length) {
273 errln("ERROR: setShortWeekdays() failed (different size array)");
276 for(int i = 0; i < count; i++) {
277 if(! shortWeekdays[i].equals(shortWeekdays1[i])) {
278 errln("ERROR: setShortWeekdays() failed (different string values)");
283 final String[] wideWeekdays = en.getWeekdays(DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
284 fr2.setWeekdays(wideWeekdays,DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
285 final String[] wideWeekdays1 = fr2.getWeekdays(DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
286 count = wideWeekdays.length;
287 if( count != wideWeekdays1.length) {
288 errln("ERROR: setWeekdays(FORMAT,WIDE) failed (different size array)");
291 for(int i = 0; i < count; i++) {
292 if(! wideWeekdays[i].equals(wideWeekdays1[i])) {
293 errln("ERROR: setWeekdays(FORMAT,WIDE) failed (different string values)");
298 final String[] abbrWeekdays = en.getWeekdays(DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
299 fr2.setWeekdays(abbrWeekdays,DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
300 final String[] abbrWeekdays1 = fr2.getWeekdays(DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
301 count = abbrWeekdays.length;
302 if( count != abbrWeekdays1.length) {
303 errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed (different size array)");
306 for(int i = 0; i < count; i++) {
307 if(! abbrWeekdays[i].equals(abbrWeekdays1[i])) {
308 errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed (different string values)");
313 final String[] narrowWeekdays = en.getWeekdays(DateFormatSymbols.FORMAT,DateFormatSymbols.NARROW);
314 fr.setWeekdays(narrowWeekdays,DateFormatSymbols.FORMAT,DateFormatSymbols.NARROW);
315 final String[] narrowWeekdays1 = fr.getWeekdays(DateFormatSymbols.FORMAT,DateFormatSymbols.NARROW);
316 count = narrowWeekdays.length;
317 if( count != narrowWeekdays1.length) {
318 errln("ERROR: setWeekdays(FORMAT,NARROW) failed (different size array)");
321 for(int i = 0; i < count; i++) {
322 if(! narrowWeekdays[i].equals(narrowWeekdays1[i])) {
323 errln("ERROR: setWeekdays(FORMAT,NARROW) failed (different string values)");
328 final String[] standaloneWeekdays = en.getWeekdays(DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
329 fr.setWeekdays(standaloneWeekdays,DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
330 final String[] standaloneWeekdays1 = fr.getWeekdays(DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
331 count = standaloneWeekdays.length;
332 if( count != standaloneWeekdays1.length) {
333 errln("ERROR: setWeekdays(STANDALONE,WIDE) failed (different size array)");
336 for(int i = 0; i < count; i++) {
337 if(! standaloneWeekdays[i].equals(standaloneWeekdays1[i])) {
338 errln("ERROR: setWeekdays(STANDALONE,WIDE) failed (different string values)");
343 final String[] standaloneShortWeekdays = en.getWeekdays(DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
344 fr.setWeekdays(standaloneShortWeekdays,DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
345 final String[] standaloneShortWeekdays1 = fr.getWeekdays(DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
346 count = standaloneShortWeekdays.length;
347 if( count != standaloneShortWeekdays1.length) {
348 errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed (different size array)");
351 for(int i = 0; i < count; i++) {
352 if(! standaloneShortWeekdays[i].equals(standaloneShortWeekdays1[i])) {
353 errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed (different string values)");
358 final String[] standaloneNarrowWeekdays = en.getWeekdays(DateFormatSymbols.STANDALONE,DateFormatSymbols.NARROW);
359 fr.setWeekdays(standaloneNarrowWeekdays,DateFormatSymbols.STANDALONE,DateFormatSymbols.NARROW);
360 final String[] standaloneNarrowWeekdays1 = fr.getWeekdays(DateFormatSymbols.STANDALONE,DateFormatSymbols.NARROW);
361 count = standaloneNarrowWeekdays.length;
362 if( count != standaloneNarrowWeekdays1.length) {
363 errln("ERROR: setWeekdays(STANDALONE,NARROW) failed (different size array)");
366 for(int i = 0; i < count; i++) {
367 if(! standaloneNarrowWeekdays[i].equals(standaloneNarrowWeekdays1[i])) {
368 errln("ERROR: setWeekdays(STANDALONE,NARROW) failed (different string values)");
373 final String[] wideQuarters = en.getQuarters(DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
374 fr2.setQuarters(wideQuarters,DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
375 final String[] wideQuarters1 = fr2.getQuarters(DateFormatSymbols.FORMAT,DateFormatSymbols.WIDE);
376 count = wideQuarters.length;
377 if( count != wideQuarters1.length) {
378 errln("ERROR: setQuarters(FORMAT, WIDE) failed (different size array)");
381 for(int i = 0; i < count; i++) {
382 if(! wideQuarters[i].equals(wideQuarters1[i])) {
383 errln("ERROR: setQuarters(FORMAT, WIDE) failed (different string values)");
388 final String[] abbrQuarters = en.getQuarters(DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
389 fr2.setQuarters(abbrQuarters,DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
390 final String[] abbrQuarters1 = fr2.getQuarters(DateFormatSymbols.FORMAT,DateFormatSymbols.ABBREVIATED);
391 count = abbrQuarters.length;
392 if( count != abbrQuarters1.length) {
393 errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed (different size array)");
396 for(int i = 0; i < count; i++) {
397 if(! abbrQuarters[i].equals(abbrQuarters1[i])) {
398 errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed (different string values)");
403 final String[] standaloneQuarters = en.getQuarters(DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
404 fr.setQuarters(standaloneQuarters,DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
405 final String[] standaloneQuarters1 = fr.getQuarters(DateFormatSymbols.STANDALONE,DateFormatSymbols.WIDE);
406 count = standaloneQuarters.length;
407 if( count != standaloneQuarters1.length) {
408 errln("ERROR: setQuarters(STANDALONE, WIDE) failed (different size array)");
411 for(int i = 0; i < count; i++) {
412 if(! standaloneQuarters[i].equals(standaloneQuarters1[i])) {
413 errln("ERROR: setQuarters(STANDALONE, WIDE) failed (different string values)");
418 final String[] standaloneShortQuarters = en.getQuarters(DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
419 fr.setQuarters(standaloneShortQuarters,DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
420 final String[] standaloneShortQuarters1 = fr.getQuarters(DateFormatSymbols.STANDALONE,DateFormatSymbols.ABBREVIATED);
421 count = standaloneShortQuarters.length;
422 if( count != standaloneShortQuarters1.length) {
423 errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed (different size array)");
426 for(int i = 0; i < count; i++) {
427 if(! standaloneShortQuarters[i].equals(standaloneShortQuarters1[i])) {
428 errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed (different string values)");
433 final String[] ampms = en.getAmPmStrings();
434 fr.setAmPmStrings(ampms);
435 final String[] ampms1 = fr.getAmPmStrings();
436 count = ampms.length;
437 if( count != ampms1.length) {
438 errln("ERROR: setAmPmStrings() failed (different size array)");
441 for(int i = 0; i < count; i++) {
442 if(! ampms[i].equals(ampms1[i])) {
443 errln("ERROR: setAmPmStrings() failed (different string values)");
448 long rowCount = 0, columnCount = 0;
449 final String[][] strings = en.getZoneStrings();
450 fr.setZoneStrings(strings);
451 final String[][] strings1 = fr.getZoneStrings();
452 rowCount = strings.length;
453 for(int i = 0; i < rowCount; i++) {
454 columnCount = strings[i].length;
455 for(int j = 0; j < columnCount; j++) {
456 if( strings[i][j] != strings1[i][j] ) {
457 errln("ERROR: setZoneStrings() failed");
462 // final String pattern = DateFormatSymbols.getPatternChars();
464 String localPattern; // pat1, pat2; //The variable is never used
465 localPattern = en.getLocalPatternChars();
466 fr.setLocalPatternChars(localPattern);
467 if(! en.getLocalPatternChars().equals(fr.getLocalPatternChars())) {
468 errln("ERROR: setLocalPatternChars() failed");
472 //DateFormatSymbols foo = new DateFormatSymbols(); //The variable is never used
474 en = (DateFormatSymbols) fr.clone();
476 if(! en.equals(fr)) {
477 errln("ERROR: Clone failed");