]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_8_1_1/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDateFormatSymbols.java
Added flags.
[Dictionary.git] / jars / icu4j-4_8_1_1 / main / tests / core / src / com / ibm / icu / dev / test / format / IntlTestDateFormatSymbols.java
1 /*****************************************************************************************
2  *
3  *   Copyright (C) 1996-2010, International Business Machines
4  *   Corporation and others.  All Rights Reserved.
5  **/
6
7 /** 
8  * Port From:   JDK 1.4b1 : java.text.Format.IntlTestDateFormatSymbols
9  * Source File: java/text/format/IntlTestDateFormatSymbols.java
10  **/
11  
12 /*
13     @test 1.4 98/03/06
14     @summary test International Date Format Symbols
15 */
16
17 package com.ibm.icu.dev.test.format;
18
19 import java.util.Locale;
20
21 import com.ibm.icu.text.DateFormatSymbols;
22
23 public class IntlTestDateFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
24 {
25     public static void main(String[] args) throws Exception {
26         new IntlTestDateFormatSymbols().run(args);
27     }
28
29     // Test getMonths
30     public void TestGetMonths()
31     {
32         final String[] month;
33         DateFormatSymbols symbol;
34
35         symbol=new DateFormatSymbols(Locale.getDefault());
36
37         month=symbol.getMonths();
38         int cnt = month.length;
39
40         logln("size = " + cnt);
41
42         for (int i=0; i<cnt; ++i)
43         {
44             logln(month[i]);
45         }
46     }
47
48     public void TestGetMonths2()
49     {
50         DateFormatSymbols symbol;
51         symbol=new DateFormatSymbols(Locale.getDefault());
52
53         int[] context = {DateFormatSymbols.STANDALONE, DateFormatSymbols.FORMAT};
54         int[] width = {DateFormatSymbols.WIDE, DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW};
55         
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;
60
61                 logln("size = " + cnt);
62
63                 for (int k = 0; k < month.length; k++) {
64                     logln(month[k]);
65                 }
66             }
67         }
68     }
69     
70     public void TestGetWeekdays2(){
71         DateFormatSymbols symbol;
72         symbol=new DateFormatSymbols(Locale.getDefault());
73
74         int[] context = {DateFormatSymbols.STANDALONE, DateFormatSymbols.FORMAT};
75         int[] width = {DateFormatSymbols.WIDE, DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW};
76         
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]);
80                 int cnt = wd.length;
81
82                 logln("size = " + cnt);
83
84                 for (int k = 0; k < wd.length; k++) {
85                     logln(wd[k]);
86                 }
87             }
88         }
89         
90     }
91     
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++) {
97             logln(s[i]);
98         }
99         
100     }
101
102     // Test the API of DateFormatSymbols; primarily a simple get/set set.
103     public void TestSymbols()
104     {
105         DateFormatSymbols fr = new DateFormatSymbols(Locale.FRENCH);
106         DateFormatSymbols fr2 = new DateFormatSymbols(Locale.FRENCH);
107
108         DateFormatSymbols en = new DateFormatSymbols(Locale.ENGLISH);
109
110         if(en.equals(fr)) {
111             errln("ERROR: English DateFormatSymbols equal to French");
112         }
113
114         // just do some VERY basic tests to make sure that get/set work
115
116         long count;
117         final String[] eras = en.getEras();
118         fr.setEras(eras);
119         final String[] eras1 = fr.getEras();
120         count = eras.length;
121         if( count != eras1.length) {
122             errln("ERROR: setEras() failed (different size array)");
123         }
124         else {
125             for(int i = 0; i < count; i++) {
126                 if(! eras[i].equals(eras1[i])) {
127                     errln("ERROR: setEras() failed (different string values)");
128                 }
129             }
130         }
131
132
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)");
139         }
140         else {
141             for(int i = 0; i < count; i++) {
142                 if(! months[i].equals(months1[i])) {
143                     errln("ERROR: setMonths() failed (different string values)");
144                 }
145             }
146         }
147
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)");
154         }
155         else {
156             for(int i = 0; i < count; i++) {
157                 if(! shortMonths[i].equals(shortMonths1[i])) {
158                     errln("ERROR: setShortMonths() failed (different string values)");
159                 }
160             }
161         }
162
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)");
169         }
170         else {
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)");
174                 }
175             }
176         }
177
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)");
184         }
185         else {
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)");
189                 }
190             }
191         }
192
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)");
199         }
200         else {
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)");
204                 }
205             }
206         }
207
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)");
214         }
215         else {
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)");
219                 }
220             }
221         }
222
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)");
229         }
230         else {
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)");
234                 }
235             }
236         }
237
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)");
244         }
245         else {
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)");
249                 }
250             }
251         }
252
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)");
259         }
260         else {
261             for(int i = 0; i < count; i++) {
262                 if(! weekdays[i].equals(weekdays1[i])) {
263                     errln("ERROR: setWeekdays() failed (different string values)");
264                 }
265             }
266         }
267
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)");
274         }
275         else {
276             for(int i = 0; i < count; i++) {
277                 if(! shortWeekdays[i].equals(shortWeekdays1[i])) {
278                     errln("ERROR: setShortWeekdays() failed (different string values)");
279                 }
280             }
281         }
282
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)");
289         }
290         else {
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)");
294                 }
295             }
296         }
297
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)");
304         }
305         else {
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)");
309                 }
310             }
311         }
312
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)");
319         }
320         else {
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)");
324                 }
325             }
326         }
327
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)");
334         }
335         else {
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)");
339                 }
340             }
341         }
342
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)");
349         }
350         else {
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)");
354                 }
355             }
356         }
357
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)");
364         }
365         else {
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)");
369                 }
370             }
371         }
372
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)");
379         }
380         else {
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)");
384                 }
385             }
386         }
387
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)");
394         }
395         else {
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)");
399                 }
400             }
401         }
402
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)");
409         }
410         else {
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)");
414                 }
415             }
416         }
417
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)");
424         }
425         else {
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)");
429                 }
430             }
431         }
432
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)");
439         }
440         else {
441             for(int i = 0; i < count; i++) {
442                 if(! ampms[i].equals(ampms1[i])) {
443                     errln("ERROR: setAmPmStrings() failed (different string values)");
444                 }
445             }
446         }
447
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");
458                 }
459             }
460         }
461
462 //        final String pattern = DateFormatSymbols.getPatternChars();
463
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");
469         }
470
471
472         //DateFormatSymbols foo = new DateFormatSymbols(); //The variable is never used
473
474         en = (DateFormatSymbols) fr.clone();
475
476         if(! en.equals(fr)) {
477             errln("ERROR: Clone failed");
478         }
479     }
480 }