• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /********************************************************************
2  * Copyright (c) 1997-2007, International Business Machines
3  * Corporation and others. All Rights Reserved.
4  ********************************************************************/
5 
6 #include "unicode/utypes.h"
7 
8 #if !UCONFIG_NO_FORMATTING
9 
10 #include "tsdtfmsy.h"
11 
12 #include "unicode/dtfmtsym.h"
13 
14 
15 //--------------------------------------------------------------------
16 // Time bomb - allows temporary behavior that expires at a given
17 //             release
18 //--------------------------------------------------------------------
19 
runIndexedTest(int32_t index,UBool exec,const char * & name,char *)20 void IntlTestDateFormatSymbols::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
21 {
22     if (exec) logln("TestSuite DateFormatSymbols");
23     switch (index) {
24         TESTCASE(0,TestSymbols);
25         TESTCASE(1,TestGetMonths);
26         TESTCASE(2,TestGetMonths2);
27         TESTCASE(3,TestGetWeekdays2);
28         TESTCASE(4,TestGetEraNames);
29         default: name = ""; break;
30     }
31 }
32 
33 /**
34  * Test getMonths.
35  */
TestGetMonths()36 void IntlTestDateFormatSymbols::TestGetMonths()
37 {
38     UErrorCode  status = U_ZERO_ERROR;
39     int32_t cnt;
40     const UnicodeString* month;
41     DateFormatSymbols *symbol;
42 
43     symbol=new DateFormatSymbols(Locale::getDefault(), status);
44 
45     month=symbol->getMonths(cnt);
46 
47     logln((UnicodeString)"size = " + cnt);
48 
49     for (int32_t i=0; i<cnt; ++i)
50     {
51         logln(month[i]);
52     }
53 
54     delete symbol;
55 }
56 
TestGetMonths2()57 void IntlTestDateFormatSymbols::TestGetMonths2()
58 {
59     UErrorCode  status = U_ZERO_ERROR;
60     DateFormatSymbols *symbol;
61 
62     symbol=new DateFormatSymbols(Locale::getDefault(), status);
63 
64     DateFormatSymbols::DtContextType context[] = {DateFormatSymbols::STANDALONE, DateFormatSymbols::FORMAT};
65     DateFormatSymbols::DtWidthType width[] = {DateFormatSymbols::WIDE, DateFormatSymbols::ABBREVIATED, DateFormatSymbols::NARROW};
66 
67     for (int32_t i = 0; i < 2; i++) {
68         for (int32_t j = 0; j < 3; j++) {
69             int32_t cnt;
70             const UnicodeString * month = symbol->getMonths(cnt,context[i],width[j]);
71 
72             logln((UnicodeString)"size = " + cnt);
73 
74             for (int32_t k = 0; k < cnt; k++) {
75                 logln(month[k]);
76             }
77         }
78     }
79     delete symbol;
80 }
81 
TestGetWeekdays2()82 void IntlTestDateFormatSymbols::TestGetWeekdays2()
83 {
84     UErrorCode  status = U_ZERO_ERROR;
85     DateFormatSymbols *symbol;
86 
87     symbol=new DateFormatSymbols(Locale::getDefault(), status);
88 
89     DateFormatSymbols::DtContextType context[] = {DateFormatSymbols::STANDALONE, DateFormatSymbols::FORMAT};
90     DateFormatSymbols::DtWidthType width[] = {DateFormatSymbols::WIDE, DateFormatSymbols::ABBREVIATED, DateFormatSymbols::NARROW};
91 
92     for (int32_t i = 0; i < 2; i++) {
93         for (int32_t j = 0; j < 3; j++) {
94             int32_t cnt;
95             const UnicodeString * wd = symbol->getWeekdays(cnt,context[i],width[j]);
96 
97             logln((UnicodeString)"size = " + cnt);
98 
99             for (int32_t k = 0; k < cnt; k++) {
100                 logln(wd[k]);
101             }
102         }
103     }
104     delete symbol;
105 }
106 
107 
TestGetEraNames()108 void IntlTestDateFormatSymbols::TestGetEraNames()
109 {
110     UErrorCode  status = U_ZERO_ERROR;
111     int32_t cnt;
112     const UnicodeString* name;
113     DateFormatSymbols *symbol;
114 
115     symbol=new DateFormatSymbols(Locale::getDefault(), status);
116 
117     name=symbol->getEraNames(cnt);
118 
119     logln((UnicodeString)"size = " + cnt);
120 
121     for (int32_t i=0; i<cnt; ++i)
122     {
123         logln(name[i]);
124     }
125 
126     delete symbol;
127 }
128 
129 /**
130  * Test the API of DateFormatSymbols; primarily a simple get/set set.
131  */
TestSymbols()132 void IntlTestDateFormatSymbols::TestSymbols(/* char *par */)
133 {
134     UErrorCode status = U_ZERO_ERROR;
135 
136     DateFormatSymbols fr(Locale::getFrench(), status);
137     if(U_FAILURE(status)) {
138         errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status));
139     }
140 
141     status = U_ZERO_ERROR;
142     DateFormatSymbols fr2(Locale::getFrench(), status);
143     if(U_FAILURE(status)) {
144         errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status));
145     }
146 
147     status = U_ZERO_ERROR;
148     DateFormatSymbols en(Locale::getEnglish(), status);
149     if(U_FAILURE(status)) {
150         errln("ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString)u_errorName(status));
151     }
152 
153     if(en == fr || ! (en != fr) ) {
154         errln("ERROR: English DateFormatSymbols equal to French");
155     }
156 
157     // just do some VERY basic tests to make sure that get/set work
158 
159     int32_t count = 0;
160     const UnicodeString *eras = en.getEras(count);
161     if(count == 0) {
162       errln("ERROR: 0 english eras.. exitting..\n");
163       return;
164     }
165 
166     fr.setEras(eras, count);
167     if( *en.getEras(count) != *fr.getEras(count)) {
168       errln("ERROR: setEras() failed");
169     }
170 
171     const UnicodeString *months = en.getMonths(count);
172     fr.setMonths(months, count);
173     if( *en.getMonths(count) != *fr.getMonths(count)) {
174         errln("ERROR: setMonths() failed");
175     }
176 
177     const UnicodeString *shortMonths = en.getShortMonths(count);
178     fr.setShortMonths(shortMonths, count);
179     if( *en.getShortMonths(count) != *fr.getShortMonths(count)) {
180         errln("ERROR: setShortMonths() failed");
181     }
182 
183     const UnicodeString *wideMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
184     fr2.setMonths(wideMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
185     if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE) !=
186         *fr2.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE )) {
187         errln("ERROR: setMonths(FORMAT,WIDE) failed");
188     }
189 
190     const UnicodeString *abbrMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
191     fr2.setMonths(abbrMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
192     if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED) !=
193         *fr2.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED )) {
194         errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed");
195     }
196 
197     const UnicodeString *narrowMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
198     fr.setMonths(narrowMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
199     if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW) !=
200         *fr.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW )) {
201         errln("ERROR: setMonths(FORMAT,NARROW) failed");
202     }
203 
204     const UnicodeString *standaloneWideMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
205     fr.setMonths(standaloneWideMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
206     if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE) !=
207         *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE )) {
208         errln("ERROR: setMonths(STANDALONE,WIDE) failed");
209     }
210 
211     const UnicodeString *standaloneShortMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
212     fr.setMonths(standaloneShortMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
213     if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED) !=
214         *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED )) {
215         errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed");
216     }
217 
218     const UnicodeString *standaloneNarrowMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
219     fr.setMonths(standaloneNarrowMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
220     if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW) !=
221         *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW )) {
222         errln("ERROR: setMonths(STANDALONE,NARROW) failed");
223     }
224 
225     const UnicodeString *weekdays = en.getWeekdays(count);
226     fr.setWeekdays(weekdays, count);
227     if( *en.getWeekdays(count) != *fr.getWeekdays(count)) {
228         errln("ERROR: setWeekdays() failed");
229     }
230 
231     const UnicodeString *shortWeekdays = en.getShortWeekdays(count);
232     fr.setShortWeekdays(shortWeekdays, count);
233     if( *en.getShortWeekdays(count) != *fr.getShortWeekdays(count)) {
234         errln("ERROR: setShortWeekdays() failed");
235     }
236 
237     const UnicodeString *wideWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
238     fr2.setWeekdays(wideWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
239     if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE) !=
240         *fr2.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE )) {
241         errln("ERROR: setWeekdays(FORMAT,WIDE) failed");
242     }
243 
244     const UnicodeString *abbrWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
245     fr2.setWeekdays(abbrWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
246     if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED) !=
247         *fr2.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED )) {
248         errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed");
249     }
250 
251     const UnicodeString *narrowWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
252     fr.setWeekdays(narrowWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
253     if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW) !=
254         *fr.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW )) {
255         errln("ERROR: setWeekdays(FORMAT,NARROW) failed");
256     }
257 
258     const UnicodeString *standaloneWideWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
259     fr.setWeekdays(standaloneWideWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
260     if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE) !=
261         *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE )) {
262         errln("ERROR: setWeekdays(STANDALONE,WIDE) failed");
263     }
264 
265     const UnicodeString *standaloneShortWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
266     fr.setWeekdays(standaloneShortWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
267     if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED) !=
268         *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED )) {
269         errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed");
270     }
271 
272     const UnicodeString *standaloneNarrowWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
273     fr.setWeekdays(standaloneNarrowWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
274     if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW) !=
275         *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW )) {
276         errln("ERROR: setWeekdays(STANDALONE,NARROW) failed");
277     }
278 
279     const UnicodeString *wideQuarters = en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
280     fr2.setQuarters(wideQuarters, count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
281     if( *en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE) !=
282         *fr2.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE )) {
283         errln("ERROR: setQuarters(FORMAT, WIDE) failed");
284     }
285 
286     const UnicodeString *abbrQuarters = en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
287     fr2.setQuarters(abbrQuarters, count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
288     if( *en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED) !=
289         *fr2.getQuarters(count,DateFormatSymbols::FORMAT ,DateFormatSymbols::ABBREVIATED )) {
290         errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed");
291     }
292 
293     const UnicodeString *standaloneWideQuarters = en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
294     fr.setQuarters(standaloneWideQuarters, count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
295     if( *en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE) !=
296         *fr.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE )) {
297         errln("ERROR: setQuarters(STANDALONE, WIDE) failed");
298     }
299 
300     const UnicodeString *standaloneShortQuarters = en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
301     fr.setQuarters(standaloneShortQuarters, count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
302     if( *en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED) !=
303         *fr.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED )) {
304         errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed");
305     }
306 
307     const UnicodeString *ampms = en.getAmPmStrings(count);
308     fr.setAmPmStrings(ampms, count);
309     if( *en.getAmPmStrings(count) != *fr.getAmPmStrings(count)) {
310         errln("ERROR: setAmPmStrings() failed");
311     }
312 
313     int32_t rowCount = 0, columnCount = 0;
314     const UnicodeString **strings = en.getZoneStrings(rowCount, columnCount);
315     fr.setZoneStrings(strings, rowCount, columnCount);
316     const UnicodeString **strings1 = fr.getZoneStrings(rowCount, columnCount);
317     for(int32_t i = 0; i < rowCount; i++) {
318        for(int32_t j = 0; j < columnCount; j++) {
319             if( strings[i][j] != strings1[i][j] ) {
320                 errln("ERROR: setZoneStrings() failed");
321             }
322         }
323     }
324 
325     UnicodeString localPattern, pat1, pat2;
326     localPattern = en.getLocalPatternChars(localPattern);
327     fr.setLocalPatternChars(localPattern);
328     if( en.getLocalPatternChars(pat1) != fr.getLocalPatternChars(pat2)) {
329         errln("ERROR: setLocalPatternChars() failed");
330     }
331 
332 
333     status = U_ZERO_ERROR;
334     DateFormatSymbols foo(status);
335     DateFormatSymbols bar(foo);
336 
337     en = fr;
338 
339     if(en != fr) {
340         errln("ERROR: Assignment operator failed");
341     }
342     if(foo != bar) {
343         errln("ERROR: Copy Constructor failed");
344     }
345 }
346 
347 #endif /* #if !UCONFIG_NO_FORMATTING */
348