1 /********************************************************************
3 * Copyright (c) 1997-2006, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_FORMATTING
13 #include "unicode/dtfmtsym.h"
16 void IntlTestDateFormatSymbols::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
18 if (exec
) logln("TestSuite DateFormatSymbols");
20 TESTCASE(0,TestSymbols
);
21 TESTCASE(1,TestGetMonths
);
22 TESTCASE(2,TestGetMonths2
);
23 TESTCASE(3,TestGetWeekdays2
);
24 TESTCASE(4,TestGetEraNames
);
25 default: name
= ""; break;
32 void IntlTestDateFormatSymbols::TestGetMonths()
34 UErrorCode status
= U_ZERO_ERROR
;
36 const UnicodeString
* month
;
37 DateFormatSymbols
*symbol
;
39 symbol
=new DateFormatSymbols(Locale::getDefault(), status
);
41 month
=symbol
->getMonths(cnt
);
43 logln((UnicodeString
)"size = " + cnt
);
45 for (int32_t i
=0; i
<cnt
; ++i
)
53 void IntlTestDateFormatSymbols::TestGetMonths2()
55 UErrorCode status
= U_ZERO_ERROR
;
56 DateFormatSymbols
*symbol
;
58 symbol
=new DateFormatSymbols(Locale::getDefault(), status
);
60 DateFormatSymbols::DtContextType context
[] = {DateFormatSymbols::STANDALONE
, DateFormatSymbols::FORMAT
};
61 DateFormatSymbols::DtWidthType width
[] = {DateFormatSymbols::WIDE
, DateFormatSymbols::ABBREVIATED
, DateFormatSymbols::NARROW
};
63 for (int32_t i
= 0; i
< 2; i
++) {
64 for (int32_t j
= 0; j
< 3; j
++) {
66 const UnicodeString
* month
= symbol
->getMonths(cnt
,context
[i
],width
[j
]);
68 logln((UnicodeString
)"size = " + cnt
);
70 for (int32_t k
= 0; k
< cnt
; k
++) {
78 void IntlTestDateFormatSymbols::TestGetWeekdays2()
80 UErrorCode status
= U_ZERO_ERROR
;
81 DateFormatSymbols
*symbol
;
83 symbol
=new DateFormatSymbols(Locale::getDefault(), status
);
85 DateFormatSymbols::DtContextType context
[] = {DateFormatSymbols::STANDALONE
, DateFormatSymbols::FORMAT
};
86 DateFormatSymbols::DtWidthType width
[] = {DateFormatSymbols::WIDE
, DateFormatSymbols::ABBREVIATED
, DateFormatSymbols::NARROW
};
88 for (int32_t i
= 0; i
< 2; i
++) {
89 for (int32_t j
= 0; j
< 3; j
++) {
91 const UnicodeString
* wd
= symbol
->getWeekdays(cnt
,context
[i
],width
[j
]);
93 logln((UnicodeString
)"size = " + cnt
);
95 for (int32_t k
= 0; k
< cnt
; k
++) {
104 void IntlTestDateFormatSymbols::TestGetEraNames()
106 UErrorCode status
= U_ZERO_ERROR
;
108 const UnicodeString
* name
;
109 DateFormatSymbols
*symbol
;
111 symbol
=new DateFormatSymbols(Locale::getDefault(), status
);
113 name
=symbol
->getEraNames(cnt
);
115 logln((UnicodeString
)"size = " + cnt
);
117 for (int32_t i
=0; i
<cnt
; ++i
)
126 * Test the API of DateFormatSymbols; primarily a simple get/set set.
128 void IntlTestDateFormatSymbols::TestSymbols(/* char *par */)
130 UErrorCode status
= U_ZERO_ERROR
;
132 DateFormatSymbols
fr(Locale::getFrench(), status
);
133 if(U_FAILURE(status
)) {
134 errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString
)u_errorName(status
));
137 status
= U_ZERO_ERROR
;
138 DateFormatSymbols
fr2(Locale::getFrench(), status
);
139 if(U_FAILURE(status
)) {
140 errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString
)u_errorName(status
));
143 status
= U_ZERO_ERROR
;
144 DateFormatSymbols
en(Locale::getEnglish(), status
);
145 if(U_FAILURE(status
)) {
146 errln("ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString
)u_errorName(status
));
149 if(en
== fr
|| ! (en
!= fr
) ) {
150 errln("ERROR: English DateFormatSymbols equal to French");
153 // just do some VERY basic tests to make sure that get/set work
156 const UnicodeString
*eras
= en
.getEras(count
);
158 errln("ERROR: 0 english eras.. exitting..\n");
162 fr
.setEras(eras
, count
);
163 if( *en
.getEras(count
) != *fr
.getEras(count
)) {
164 errln("ERROR: setEras() failed");
167 const UnicodeString
*months
= en
.getMonths(count
);
168 fr
.setMonths(months
, count
);
169 if( *en
.getMonths(count
) != *fr
.getMonths(count
)) {
170 errln("ERROR: setMonths() failed");
173 const UnicodeString
*shortMonths
= en
.getShortMonths(count
);
174 fr
.setShortMonths(shortMonths
, count
);
175 if( *en
.getShortMonths(count
) != *fr
.getShortMonths(count
)) {
176 errln("ERROR: setShortMonths() failed");
179 const UnicodeString
*wideMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
180 fr2
.setMonths(wideMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
181 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
) !=
182 *fr2
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
)) {
183 errln("ERROR: setMonths(FORMAT,WIDE) failed");
186 const UnicodeString
*abbrMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
187 fr2
.setMonths(abbrMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
188 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
) !=
189 *fr2
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
190 errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed");
193 const UnicodeString
*narrowMonths
= en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
194 fr
.setMonths(narrowMonths
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
195 if( *en
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
) !=
196 *fr
.getMonths(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
)) {
197 errln("ERROR: setMonths(FORMAT,NARROW) failed");
200 const UnicodeString
*standaloneWideMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
201 fr
.setMonths(standaloneWideMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
202 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
) !=
203 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
)) {
204 errln("ERROR: setMonths(STANDALONE,WIDE) failed");
207 const UnicodeString
*standaloneShortMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
208 fr
.setMonths(standaloneShortMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
209 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
) !=
210 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
)) {
211 errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed");
214 const UnicodeString
*standaloneNarrowMonths
= en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
215 fr
.setMonths(standaloneNarrowMonths
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
216 if( *en
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
) !=
217 *fr
.getMonths(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
)) {
218 errln("ERROR: setMonths(STANDALONE,NARROW) failed");
221 const UnicodeString
*weekdays
= en
.getWeekdays(count
);
222 fr
.setWeekdays(weekdays
, count
);
223 if( *en
.getWeekdays(count
) != *fr
.getWeekdays(count
)) {
224 errln("ERROR: setWeekdays() failed");
227 const UnicodeString
*shortWeekdays
= en
.getShortWeekdays(count
);
228 fr
.setShortWeekdays(shortWeekdays
, count
);
229 if( *en
.getShortWeekdays(count
) != *fr
.getShortWeekdays(count
)) {
230 errln("ERROR: setShortWeekdays() failed");
233 const UnicodeString
*wideWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
234 fr2
.setWeekdays(wideWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
);
235 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
) !=
236 *fr2
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::WIDE
)) {
237 errln("ERROR: setWeekdays(FORMAT,WIDE) failed");
240 const UnicodeString
*abbrWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
241 fr2
.setWeekdays(abbrWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
);
242 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
) !=
243 *fr2
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
244 errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed");
247 const UnicodeString
*narrowWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
248 fr
.setWeekdays(narrowWeekdays
, count
, DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
);
249 if( *en
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
) !=
250 *fr
.getWeekdays(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::NARROW
)) {
251 errln("ERROR: setWeekdays(FORMAT,NARROW) failed");
254 const UnicodeString
*standaloneWideWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
255 fr
.setWeekdays(standaloneWideWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
);
256 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
) !=
257 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::WIDE
)) {
258 errln("ERROR: setWeekdays(STANDALONE,WIDE) failed");
261 const UnicodeString
*standaloneShortWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
262 fr
.setWeekdays(standaloneShortWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
);
263 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
) !=
264 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::ABBREVIATED
)) {
265 errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed");
268 const UnicodeString
*standaloneNarrowWeekdays
= en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
269 fr
.setWeekdays(standaloneNarrowWeekdays
, count
, DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
);
270 if( *en
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
) !=
271 *fr
.getWeekdays(count
,DateFormatSymbols::STANDALONE
,DateFormatSymbols::NARROW
)) {
272 errln("ERROR: setWeekdays(STANDALONE,NARROW) failed");
275 const UnicodeString
*wideQuarters
= en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
276 fr2
.setQuarters(wideQuarters
, count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
277 if( *en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
) !=
278 *fr2
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
)) {
279 errln("ERROR: setQuarters(FORMAT, WIDE) failed");
282 const UnicodeString
*abbrQuarters
= en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
283 fr2
.setQuarters(abbrQuarters
, count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
284 if( *en
.getQuarters(count
,DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
) !=
285 *fr2
.getQuarters(count
,DateFormatSymbols::FORMAT
,DateFormatSymbols::ABBREVIATED
)) {
286 errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed");
289 const UnicodeString
*standaloneWideQuarters
= en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
290 fr
.setQuarters(standaloneWideQuarters
, count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
291 if( *en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
) !=
292 *fr
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
)) {
293 errln("ERROR: setQuarters(STANDALONE, WIDE) failed");
296 const UnicodeString
*standaloneShortQuarters
= en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
297 fr
.setQuarters(standaloneShortQuarters
, count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
298 if( *en
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
) !=
299 *fr
.getQuarters(count
,DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
)) {
300 errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed");
303 const UnicodeString
*ampms
= en
.getAmPmStrings(count
);
304 fr
.setAmPmStrings(ampms
, count
);
305 if( *en
.getAmPmStrings(count
) != *fr
.getAmPmStrings(count
)) {
306 errln("ERROR: setAmPmStrings() failed");
309 int32_t rowCount
= 0, columnCount
= 0;
310 const UnicodeString
**strings
= en
.getZoneStrings(rowCount
, columnCount
);
311 fr
.setZoneStrings(strings
, rowCount
, columnCount
);
312 const UnicodeString
**strings1
= fr
.getZoneStrings(rowCount
, columnCount
);
313 for(int32_t i
= 0; i
< rowCount
; i
++) {
314 for(int32_t j
= 0; j
< columnCount
; j
++) {
315 if( strings
[i
][j
] != strings1
[i
][j
] ) {
316 errln("ERROR: setZoneStrings() failed");
322 UnicodeString localPattern
, pat1
, pat2
;
323 localPattern
= en
.getLocalPatternChars(localPattern
);
324 fr
.setLocalPatternChars(localPattern
);
325 if( en
.getLocalPatternChars(pat1
) != fr
.getLocalPatternChars(pat2
)) {
326 errln("ERROR: setLocalPatternChars() failed");
330 status
= U_ZERO_ERROR
;
331 DateFormatSymbols
foo(status
);
332 DateFormatSymbols
bar(foo
);
337 errln("ERROR: Assignment operator failed");
340 errln("ERROR: Copy Constructor failed");
344 #endif /* #if !UCONFIG_NO_FORMATTING */