1 /********************************************************************
2 * Copyright (c) 1997-2009, International Business Machines
3 * Corporation and others. All Rights Reserved.
4 ********************************************************************/
6 #include "unicode/utypes.h"
8 #if !UCONFIG_NO_FORMATTING
12 #include "unicode/dtfmtsym.h"
15 //--------------------------------------------------------------------
16 // Time bomb - allows temporary behavior that expires at a given
18 //--------------------------------------------------------------------
20 void IntlTestDateFormatSymbols::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
22 if (exec
) logln("TestSuite DateFormatSymbols");
24 TESTCASE(0,TestSymbols
);
25 TESTCASE(1,TestGetMonths
);
26 TESTCASE(2,TestGetMonths2
);
27 TESTCASE(3,TestGetWeekdays2
);
28 TESTCASE(4,TestGetEraNames
);
29 default: name
= ""; break;
36 void IntlTestDateFormatSymbols::TestGetMonths()
38 UErrorCode status
= U_ZERO_ERROR
;
40 const UnicodeString
* month
;
41 DateFormatSymbols
*symbol
;
43 symbol
=new DateFormatSymbols(Locale::getDefault(), status
);
45 month
=symbol
->getMonths(cnt
);
47 logln((UnicodeString
)"size = " + cnt
);
49 for (int32_t i
=0; i
<cnt
; ++i
)
57 void IntlTestDateFormatSymbols::TestGetMonths2()
59 UErrorCode status
= U_ZERO_ERROR
;
60 DateFormatSymbols
*symbol
;
62 symbol
=new DateFormatSymbols(Locale::getDefault(), status
);
64 DateFormatSymbols::DtContextType context
[] = {DateFormatSymbols::STANDALONE
, DateFormatSymbols::FORMAT
};
65 DateFormatSymbols::DtWidthType width
[] = {DateFormatSymbols::WIDE
, DateFormatSymbols::ABBREVIATED
, DateFormatSymbols::NARROW
};
67 for (int32_t i
= 0; i
< 2; i
++) {
68 for (int32_t j
= 0; j
< 3; j
++) {
70 const UnicodeString
* month
= symbol
->getMonths(cnt
,context
[i
],width
[j
]);
72 logln((UnicodeString
)"size = " + cnt
);
74 for (int32_t k
= 0; k
< cnt
; k
++) {
82 void IntlTestDateFormatSymbols::TestGetWeekdays2()
84 UErrorCode status
= U_ZERO_ERROR
;
85 DateFormatSymbols
*symbol
;
87 symbol
=new DateFormatSymbols(Locale::getDefault(), status
);
89 DateFormatSymbols::DtContextType context
[] = {DateFormatSymbols::STANDALONE
, DateFormatSymbols::FORMAT
};
90 DateFormatSymbols::DtWidthType width
[] = {DateFormatSymbols::WIDE
, DateFormatSymbols::ABBREVIATED
, DateFormatSymbols::NARROW
};
92 for (int32_t i
= 0; i
< 2; i
++) {
93 for (int32_t j
= 0; j
< 3; j
++) {
95 const UnicodeString
* wd
= symbol
->getWeekdays(cnt
,context
[i
],width
[j
]);
97 logln((UnicodeString
)"size = " + cnt
);
99 for (int32_t k
= 0; k
< cnt
; k
++) {
108 void IntlTestDateFormatSymbols::TestGetEraNames()
110 UErrorCode status
= U_ZERO_ERROR
;
112 const UnicodeString
* name
;
113 DateFormatSymbols
*symbol
;
115 symbol
=new DateFormatSymbols(Locale::getDefault(), status
);
117 name
=symbol
->getEraNames(cnt
);
119 logln((UnicodeString
)"size = " + cnt
);
121 for (int32_t i
=0; i
<cnt
; ++i
)
130 * Test the API of DateFormatSymbols; primarily a simple get/set set.
132 void IntlTestDateFormatSymbols::TestSymbols(/* char *par */)
134 UErrorCode status
= U_ZERO_ERROR
;
136 DateFormatSymbols
fr(Locale::getFrench(), status
);
137 if(U_FAILURE(status
)) {
138 errcheckln(status
, "ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString
)u_errorName(status
));
142 status
= U_ZERO_ERROR
;
143 DateFormatSymbols
fr2(Locale::getFrench(), status
);
144 if(U_FAILURE(status
)) {
145 errcheckln(status
, "ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString
)u_errorName(status
));
149 status
= U_ZERO_ERROR
;
150 DateFormatSymbols
en(Locale::getEnglish(), status
);
151 if(U_FAILURE(status
)) {
152 errcheckln(status
, "ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString
)u_errorName(status
));
156 if(en
== fr
|| ! (en
!= fr
) ) {
157 errln("ERROR: English DateFormatSymbols equal to French");
160 // just do some VERY basic tests to make sure that get/set work
163 const UnicodeString
*eras
= en
.getEras(count
);
165 errln("ERROR: 0 english eras.. exiting..\n");
168 int32_t eraNamesCount
= 0;
169 const UnicodeString
*eraNames
= en
.getEraNames(eraNamesCount
);
170 if(eraNamesCount
== 0) {
171 errln("ERROR: 0 english eraNames\n");
172 } else if ( eraNames
[0].length() <= eras
[0].length() ) {
173 // At least for English we know a wide eraName should be longer than an abbrev era
174 errln("ERROR: english eraNames[0] not longer than eras[0]\n");
176 int32_t narrowErasCount
= 0;
177 const UnicodeString
*narrowEras
= en
.getNarrowEras(narrowErasCount
);
178 if(narrowErasCount
== 0) {
179 errln("ERROR: 0 english narrowEras\n");
180 } else if ( narrowEras
[0].length() >= eras
[0].length() ) {
181 // At least for English we know a narrowEra should be shorter than an abbrev era
182 errln("ERROR: english narrowEras[0] not shorter than eras[0]\n");
185 fr
.setEras(eras
, count
);
186 if( *en
.getEras(count
) != *fr
.getEras(count
)) {
187 errln("ERROR: setEras() failed");
190 const UnicodeString
*months
= en
.getMonths(count
);
191 fr
.setMonths(months
, count
);
192 if( *en
.getMonths(count
) != *fr
.getMonths(count
)) {
193 errln("ERROR: setMonths() failed");
196 const UnicodeString
*shortMonths
= en
.getShortMonths(count
);
197 fr
.setShortMonths(shortMonths
, count
);
198 if( *en
.getShortMonths(count
) != *fr
.getShortMonths(count
)) {
199 errln("ERROR: setShortMonths() failed");
202 const UnicodeString
*wideMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
203 fr2
.setMonths(wideMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
204 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
) !=
205 *fr2
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
)) {
206 errln("ERROR: setMonths(FORMAT,WIDE) failed");
209 const UnicodeString
*abbrMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
210 fr2
.setMonths(abbrMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
211 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
) !=
212 *fr2
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
213 errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed");
216 const UnicodeString
*narrowMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
217 fr
.setMonths(narrowMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
218 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
) !=
219 *fr
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
)) {
220 errln("ERROR: setMonths(FORMAT,NARROW) failed");
223 const UnicodeString
*standaloneWideMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
224 fr
.setMonths(standaloneWideMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
225 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
) !=
226 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
)) {
227 errln("ERROR: setMonths(STANDALONE,WIDE) failed");
230 const UnicodeString
*standaloneShortMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
231 fr
.setMonths(standaloneShortMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
232 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
) !=
233 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
)) {
234 errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed");
237 const UnicodeString
*standaloneNarrowMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
238 fr
.setMonths(standaloneNarrowMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
239 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
) !=
240 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
)) {
241 errln("ERROR: setMonths(STANDALONE,NARROW) failed");
244 const UnicodeString
*weekdays
= en
.getWeekdays(count
);
245 fr
.setWeekdays(weekdays
, count
);
246 if( *en
.getWeekdays(count
) != *fr
.getWeekdays(count
)) {
247 errln("ERROR: setWeekdays() failed");
250 const UnicodeString
*shortWeekdays
= en
.getShortWeekdays(count
);
251 fr
.setShortWeekdays(shortWeekdays
, count
);
252 if( *en
.getShortWeekdays(count
) != *fr
.getShortWeekdays(count
)) {
253 errln("ERROR: setShortWeekdays() failed");
256 const UnicodeString
*wideWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
257 fr2
.setWeekdays(wideWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
258 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
) !=
259 *fr2
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
)) {
260 errln("ERROR: setWeekdays(FORMAT,WIDE) failed");
263 const UnicodeString
*abbrWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
264 fr2
.setWeekdays(abbrWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
265 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
) !=
266 *fr2
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
267 errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed");
270 const UnicodeString
*narrowWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
271 fr
.setWeekdays(narrowWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
272 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
) !=
273 *fr
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
)) {
274 errln("ERROR: setWeekdays(FORMAT,NARROW) failed");
277 const UnicodeString
*standaloneWideWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
278 fr
.setWeekdays(standaloneWideWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
279 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
) !=
280 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
)) {
281 errln("ERROR: setWeekdays(STANDALONE,WIDE) failed");
284 const UnicodeString
*standaloneShortWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
285 fr
.setWeekdays(standaloneShortWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
286 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
) !=
287 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
)) {
288 errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed");
291 const UnicodeString
*standaloneNarrowWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
292 fr
.setWeekdays(standaloneNarrowWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
293 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
) !=
294 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
)) {
295 errln("ERROR: setWeekdays(STANDALONE,NARROW) failed");
298 const UnicodeString
*wideQuarters
= en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
299 fr2
.setQuarters(wideQuarters
, count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
300 if( *en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
) !=
301 *fr2
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
)) {
302 errln("ERROR: setQuarters(FORMAT, WIDE) failed");
305 const UnicodeString
*abbrQuarters
= en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
306 fr2
.setQuarters(abbrQuarters
, count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
307 if( *en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
) !=
308 *fr2
.getQuarters(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
309 errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed");
312 const UnicodeString
*standaloneWideQuarters
= en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
313 fr
.setQuarters(standaloneWideQuarters
, count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
314 if( *en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
) !=
315 *fr
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
)) {
316 errln("ERROR: setQuarters(STANDALONE, WIDE) failed");
319 const UnicodeString
*standaloneShortQuarters
= en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
320 fr
.setQuarters(standaloneShortQuarters
, count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
321 if( *en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
) !=
322 *fr
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
)) {
323 errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed");
326 const UnicodeString
*ampms
= en
.getAmPmStrings(count
);
327 fr
.setAmPmStrings(ampms
, count
);
328 if( *en
.getAmPmStrings(count
) != *fr
.getAmPmStrings(count
)) {
329 errln("ERROR: setAmPmStrings() failed");
332 int32_t rowCount
= 0, columnCount
= 0;
333 const UnicodeString
**strings
= en
.getZoneStrings(rowCount
, columnCount
);
334 fr
.setZoneStrings(strings
, rowCount
, columnCount
);
335 const UnicodeString
**strings1
= fr
.getZoneStrings(rowCount
, columnCount
);
336 for(int32_t i
= 0; i
< rowCount
; i
++) {
337 for(int32_t j
= 0; j
< columnCount
; j
++) {
338 if( strings
[i
][j
] != strings1
[i
][j
] ) {
339 errln("ERROR: setZoneStrings() failed");
344 UnicodeString localPattern
, pat1
, pat2
;
345 localPattern
= en
.getLocalPatternChars(localPattern
);
346 fr
.setLocalPatternChars(localPattern
);
347 if( en
.getLocalPatternChars(pat1
) != fr
.getLocalPatternChars(pat2
)) {
348 errln("ERROR: setLocalPatternChars() failed");
352 status
= U_ZERO_ERROR
;
353 DateFormatSymbols
foo(status
);
354 DateFormatSymbols
bar(foo
);
359 errln("ERROR: Assignment operator failed");
362 errln("ERROR: Copy Constructor failed");
366 #endif /* #if !UCONFIG_NO_FORMATTING */