1 /********************************************************************
2 * Copyright (c) 1997-2008, 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 errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString
)u_errorName(status
));
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
));
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
));
153 if(en
== fr
|| ! (en
!= fr
) ) {
154 errln("ERROR: English DateFormatSymbols equal to French");
157 // just do some VERY basic tests to make sure that get/set work
160 const UnicodeString
*eras
= en
.getEras(count
);
162 errln("ERROR: 0 english eras.. exiting..\n");
165 int32_t eraNamesCount
= 0;
166 const UnicodeString
*eraNames
= en
.getEraNames(eraNamesCount
);
167 if(eraNamesCount
== 0) {
168 errln("ERROR: 0 english eraNames\n");
169 } else if ( eraNames
[0].length() <= eras
[0].length() ) {
170 // At least for English we know a wide eraName should be longer than an abbrev era
171 errln("ERROR: english eraNames[0] not longer than eras[0]\n");
173 int32_t narrowErasCount
= 0;
174 const UnicodeString
*narrowEras
= en
.getNarrowEras(narrowErasCount
);
175 if(narrowErasCount
== 0) {
176 errln("ERROR: 0 english narrowEras\n");
177 } else if ( narrowEras
[0].length() >= eras
[0].length() ) {
178 // At least for English we know a narrowEra should be shorter than an abbrev era
179 errln("ERROR: english narrowEras[0] not shorter than eras[0]\n");
182 fr
.setEras(eras
, count
);
183 if( *en
.getEras(count
) != *fr
.getEras(count
)) {
184 errln("ERROR: setEras() failed");
187 const UnicodeString
*months
= en
.getMonths(count
);
188 fr
.setMonths(months
, count
);
189 if( *en
.getMonths(count
) != *fr
.getMonths(count
)) {
190 errln("ERROR: setMonths() failed");
193 const UnicodeString
*shortMonths
= en
.getShortMonths(count
);
194 fr
.setShortMonths(shortMonths
, count
);
195 if( *en
.getShortMonths(count
) != *fr
.getShortMonths(count
)) {
196 errln("ERROR: setShortMonths() failed");
199 const UnicodeString
*wideMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
200 fr2
.setMonths(wideMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
201 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
) !=
202 *fr2
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
)) {
203 errln("ERROR: setMonths(FORMAT,WIDE) failed");
206 const UnicodeString
*abbrMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
207 fr2
.setMonths(abbrMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
208 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
) !=
209 *fr2
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
210 errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed");
213 const UnicodeString
*narrowMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
214 fr
.setMonths(narrowMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
215 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
) !=
216 *fr
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
)) {
217 errln("ERROR: setMonths(FORMAT,NARROW) failed");
220 const UnicodeString
*standaloneWideMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
221 fr
.setMonths(standaloneWideMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
222 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
) !=
223 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
)) {
224 errln("ERROR: setMonths(STANDALONE,WIDE) failed");
227 const UnicodeString
*standaloneShortMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
228 fr
.setMonths(standaloneShortMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
229 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
) !=
230 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
)) {
231 errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed");
234 const UnicodeString
*standaloneNarrowMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
235 fr
.setMonths(standaloneNarrowMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
236 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
) !=
237 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
)) {
238 errln("ERROR: setMonths(STANDALONE,NARROW) failed");
241 const UnicodeString
*weekdays
= en
.getWeekdays(count
);
242 fr
.setWeekdays(weekdays
, count
);
243 if( *en
.getWeekdays(count
) != *fr
.getWeekdays(count
)) {
244 errln("ERROR: setWeekdays() failed");
247 const UnicodeString
*shortWeekdays
= en
.getShortWeekdays(count
);
248 fr
.setShortWeekdays(shortWeekdays
, count
);
249 if( *en
.getShortWeekdays(count
) != *fr
.getShortWeekdays(count
)) {
250 errln("ERROR: setShortWeekdays() failed");
253 const UnicodeString
*wideWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
254 fr2
.setWeekdays(wideWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
255 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
) !=
256 *fr2
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
)) {
257 errln("ERROR: setWeekdays(FORMAT,WIDE) failed");
260 const UnicodeString
*abbrWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
261 fr2
.setWeekdays(abbrWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
262 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
) !=
263 *fr2
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
264 errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed");
267 const UnicodeString
*narrowWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
268 fr
.setWeekdays(narrowWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
269 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
) !=
270 *fr
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
)) {
271 errln("ERROR: setWeekdays(FORMAT,NARROW) failed");
274 const UnicodeString
*standaloneWideWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
275 fr
.setWeekdays(standaloneWideWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
276 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
) !=
277 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
)) {
278 errln("ERROR: setWeekdays(STANDALONE,WIDE) failed");
281 const UnicodeString
*standaloneShortWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
282 fr
.setWeekdays(standaloneShortWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
283 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
) !=
284 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
)) {
285 errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed");
288 const UnicodeString
*standaloneNarrowWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
289 fr
.setWeekdays(standaloneNarrowWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
290 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
) !=
291 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
)) {
292 errln("ERROR: setWeekdays(STANDALONE,NARROW) failed");
295 const UnicodeString
*wideQuarters
= en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
296 fr2
.setQuarters(wideQuarters
, count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
297 if( *en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
) !=
298 *fr2
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
)) {
299 errln("ERROR: setQuarters(FORMAT, WIDE) failed");
302 const UnicodeString
*abbrQuarters
= en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
303 fr2
.setQuarters(abbrQuarters
, count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
304 if( *en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
) !=
305 *fr2
.getQuarters(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
306 errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed");
309 const UnicodeString
*standaloneWideQuarters
= en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
310 fr
.setQuarters(standaloneWideQuarters
, count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
311 if( *en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
) !=
312 *fr
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
)) {
313 errln("ERROR: setQuarters(STANDALONE, WIDE) failed");
316 const UnicodeString
*standaloneShortQuarters
= en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
317 fr
.setQuarters(standaloneShortQuarters
, count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
318 if( *en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
) !=
319 *fr
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
)) {
320 errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed");
323 const UnicodeString
*ampms
= en
.getAmPmStrings(count
);
324 fr
.setAmPmStrings(ampms
, count
);
325 if( *en
.getAmPmStrings(count
) != *fr
.getAmPmStrings(count
)) {
326 errln("ERROR: setAmPmStrings() failed");
329 int32_t rowCount
= 0, columnCount
= 0;
330 const UnicodeString
**strings
= en
.getZoneStrings(rowCount
, columnCount
);
331 fr
.setZoneStrings(strings
, rowCount
, columnCount
);
332 const UnicodeString
**strings1
= fr
.getZoneStrings(rowCount
, columnCount
);
333 for(int32_t i
= 0; i
< rowCount
; i
++) {
334 for(int32_t j
= 0; j
< columnCount
; j
++) {
335 if( strings
[i
][j
] != strings1
[i
][j
] ) {
336 errln("ERROR: setZoneStrings() failed");
341 UnicodeString localPattern
, pat1
, pat2
;
342 localPattern
= en
.getLocalPatternChars(localPattern
);
343 fr
.setLocalPatternChars(localPattern
);
344 if( en
.getLocalPatternChars(pat1
) != fr
.getLocalPatternChars(pat2
)) {
345 errln("ERROR: setLocalPatternChars() failed");
349 status
= U_ZERO_ERROR
;
350 DateFormatSymbols
foo(status
);
351 DateFormatSymbols
bar(foo
);
356 errln("ERROR: Assignment operator failed");
359 errln("ERROR: Copy Constructor failed");
363 #endif /* #if !UCONFIG_NO_FORMATTING */