1 /********************************************************************
2 * Copyright (c) 1997-2013, 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 TESTCASE(5,TestGetSetSpecificItems);
30 default: name = ""; break;
37 void IntlTestDateFormatSymbols::TestGetMonths()
39 UErrorCode status = U_ZERO_ERROR;
41 const UnicodeString* month;
42 DateFormatSymbols *symbol;
44 symbol=new DateFormatSymbols(Locale::getDefault(), status);
46 month=symbol->getMonths(cnt);
48 logln((UnicodeString)"size = " + cnt);
50 for (int32_t i=0; i<cnt; ++i)
58 void IntlTestDateFormatSymbols::TestGetMonths2()
60 UErrorCode status = U_ZERO_ERROR;
61 DateFormatSymbols *symbol;
63 symbol=new DateFormatSymbols(Locale::getDefault(), status);
65 DateFormatSymbols::DtContextType context[] = {DateFormatSymbols::STANDALONE, DateFormatSymbols::FORMAT};
66 DateFormatSymbols::DtWidthType width[] = {DateFormatSymbols::WIDE, DateFormatSymbols::ABBREVIATED, DateFormatSymbols::NARROW};
68 for (int32_t i = 0; i < 2; i++) {
69 for (int32_t j = 0; j < 3; j++) {
71 const UnicodeString * month = symbol->getMonths(cnt,context[i],width[j]);
73 logln((UnicodeString)"size = " + cnt);
75 for (int32_t k = 0; k < cnt; k++) {
83 void IntlTestDateFormatSymbols::TestGetWeekdays2()
85 UErrorCode status = U_ZERO_ERROR;
86 DateFormatSymbols *symbol;
88 symbol=new DateFormatSymbols(Locale::getDefault(), status);
90 DateFormatSymbols::DtContextType context[] = {DateFormatSymbols::STANDALONE, DateFormatSymbols::FORMAT};
91 DateFormatSymbols::DtWidthType width[] = {DateFormatSymbols::WIDE, DateFormatSymbols::ABBREVIATED, DateFormatSymbols::NARROW};
93 for (int32_t i = 0; i < 2; i++) {
94 for (int32_t j = 0; j < 3; j++) {
96 const UnicodeString * wd = symbol->getWeekdays(cnt,context[i],width[j]);
98 logln((UnicodeString)"size = " + cnt);
100 for (int32_t k = 0; k < cnt; k++) {
109 void IntlTestDateFormatSymbols::TestGetEraNames()
111 UErrorCode status = U_ZERO_ERROR;
113 const UnicodeString* name;
114 DateFormatSymbols *symbol;
116 symbol=new DateFormatSymbols(Locale::getDefault(), status);
118 name=symbol->getEraNames(cnt);
120 logln((UnicodeString)"size = " + cnt);
122 for (int32_t i=0; i<cnt; ++i)
130 UBool IntlTestDateFormatSymbols::UnicodeStringsArePrefixes(int32_t count, int32_t prefixLen, const UnicodeString *prefixArray, const UnicodeString *baseArray)
133 for (i = 0; i < count; i++) {
134 if (baseArray[i].compare(0, prefixLen, prefixArray[i]) != 0) {
135 errln("ERROR: Mismatch example: expect prefix \"" + prefixArray[i] + "\" of base \"" + baseArray[i] + "\".");
142 void IntlTestDateFormatSymbols::TestGetSetSpecificItems()
144 UErrorCode status = U_ZERO_ERROR;
145 DateFormatSymbols *symbol=new DateFormatSymbols(Locale::getEnglish(), status);
146 if(U_FAILURE(status)) {
147 dataerrln("ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString)u_errorName(status));
150 int32_t cntFmtAbbrev, cntFmtShort, cntStdAloneShort;
151 const UnicodeString * wdFmtAbbrev = symbol->getWeekdays(cntFmtAbbrev,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
152 const UnicodeString * wdFmtShort = symbol->getWeekdays(cntFmtShort,DateFormatSymbols::FORMAT,DateFormatSymbols::SHORT);
153 const UnicodeString * wdStdAloneShort = symbol->getWeekdays(cntStdAloneShort,DateFormatSymbols::STANDALONE,DateFormatSymbols::SHORT);
154 // Expect that English short names are prefixes of abbreviated names
155 if (cntFmtShort != cntFmtAbbrev || !UnicodeStringsArePrefixes(cntFmtAbbrev, 2, wdFmtShort, wdFmtAbbrev)) {
156 errln("ERROR: English format short weekday names don't match prefixes of format abbreviated names");
158 if (cntStdAloneShort != cntFmtAbbrev || !UnicodeStringsArePrefixes(cntFmtAbbrev, 2, wdStdAloneShort, wdFmtAbbrev)) {
159 errln("ERROR: English standalone short weekday names don't match prefixes of format abbreviated names");
166 * Test the API of DateFormatSymbols; primarily a simple get/set set.
168 void IntlTestDateFormatSymbols::TestSymbols(/* char *par */)
170 UErrorCode status = U_ZERO_ERROR;
172 DateFormatSymbols fr(Locale::getFrench(), status);
173 if(U_FAILURE(status)) {
174 dataerrln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status));
178 status = U_ZERO_ERROR;
179 DateFormatSymbols fr2(Locale::getFrench(), status);
180 if(U_FAILURE(status)) {
181 errcheckln(status, "ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status));
185 status = U_ZERO_ERROR;
186 DateFormatSymbols en(Locale::getEnglish(), status);
187 if(U_FAILURE(status)) {
188 errcheckln(status, "ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString)u_errorName(status));
192 if(en == fr || ! (en != fr) ) {
193 errln("ERROR: English DateFormatSymbols equal to French");
196 // just do some VERY basic tests to make sure that get/set work
199 const UnicodeString *eras = en.getEras(count);
201 errln("ERROR: 0 english eras.. exiting..\n");
204 int32_t eraNamesCount = 0;
205 const UnicodeString *eraNames = en.getEraNames(eraNamesCount);
206 if(eraNamesCount == 0) {
207 errln("ERROR: 0 english eraNames\n");
208 } else if ( eraNames[0].length() <= eras[0].length() ) {
209 // At least for English we know a wide eraName should be longer than an abbrev era
210 errln("ERROR: english eraNames[0] not longer than eras[0]\n");
212 int32_t narrowErasCount = 0;
213 const UnicodeString *narrowEras = en.getNarrowEras(narrowErasCount);
214 if(narrowErasCount == 0) {
215 errln("ERROR: 0 english narrowEras\n");
216 } else if ( narrowEras[0].length() >= eras[0].length() ) {
217 // At least for English we know a narrowEra should be shorter than an abbrev era
218 errln("ERROR: english narrowEras[0] not shorter than eras[0]\n");
221 fr.setEras(eras, count);
222 if( *en.getEras(count) != *fr.getEras(count)) {
223 errln("ERROR: setEras() failed");
226 const UnicodeString *months = en.getMonths(count);
227 fr.setMonths(months, count);
228 if( *en.getMonths(count) != *fr.getMonths(count)) {
229 errln("ERROR: setMonths() failed");
232 const UnicodeString *shortMonths = en.getShortMonths(count);
233 fr.setShortMonths(shortMonths, count);
234 if( *en.getShortMonths(count) != *fr.getShortMonths(count)) {
235 errln("ERROR: setShortMonths() failed");
238 const UnicodeString *wideMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
239 fr2.setMonths(wideMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
240 if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE) !=
241 *fr2.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE )) {
242 errln("ERROR: setMonths(FORMAT,WIDE) failed");
245 const UnicodeString *abbrMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
246 fr2.setMonths(abbrMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
247 if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED) !=
248 *fr2.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED )) {
249 errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed");
252 const UnicodeString *narrowMonths = en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
253 fr.setMonths(narrowMonths, count, DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
254 if( *en.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW) !=
255 *fr.getMonths(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW )) {
256 errln("ERROR: setMonths(FORMAT,NARROW) failed");
259 const UnicodeString *standaloneWideMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
260 fr.setMonths(standaloneWideMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
261 if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE) !=
262 *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE )) {
263 errln("ERROR: setMonths(STANDALONE,WIDE) failed");
266 const UnicodeString *standaloneShortMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
267 fr.setMonths(standaloneShortMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
268 if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED) !=
269 *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED )) {
270 errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed");
273 const UnicodeString *standaloneNarrowMonths = en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
274 fr.setMonths(standaloneNarrowMonths, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
275 if( *en.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW) !=
276 *fr.getMonths(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW )) {
277 errln("ERROR: setMonths(STANDALONE,NARROW) failed");
280 const UnicodeString *weekdays = en.getWeekdays(count);
281 fr.setWeekdays(weekdays, count);
282 if( *en.getWeekdays(count) != *fr.getWeekdays(count)) {
283 errln("ERROR: setWeekdays() failed");
286 const UnicodeString *shortWeekdays = en.getShortWeekdays(count);
287 fr.setShortWeekdays(shortWeekdays, count);
288 if( *en.getShortWeekdays(count) != *fr.getShortWeekdays(count)) {
289 errln("ERROR: setShortWeekdays() failed");
292 const UnicodeString *wideWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
293 fr2.setWeekdays(wideWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE);
294 if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE) !=
295 *fr2.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::WIDE )) {
296 errln("ERROR: setWeekdays(FORMAT,WIDE) failed");
299 const UnicodeString *abbrWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
300 fr2.setWeekdays(abbrWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED);
301 if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED) !=
302 *fr2.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED )) {
303 errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed");
306 const UnicodeString *narrowWeekdays = en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
307 fr.setWeekdays(narrowWeekdays, count, DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW);
308 if( *en.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW) !=
309 *fr.getWeekdays(count,DateFormatSymbols::FORMAT,DateFormatSymbols::NARROW )) {
310 errln("ERROR: setWeekdays(FORMAT,NARROW) failed");
313 const UnicodeString *standaloneWideWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
314 fr.setWeekdays(standaloneWideWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE);
315 if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE) !=
316 *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::WIDE )) {
317 errln("ERROR: setWeekdays(STANDALONE,WIDE) failed");
320 const UnicodeString *standaloneShortWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
321 fr.setWeekdays(standaloneShortWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED);
322 if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED) !=
323 *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::ABBREVIATED )) {
324 errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed");
327 const UnicodeString *standaloneNarrowWeekdays = en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
328 fr.setWeekdays(standaloneNarrowWeekdays, count, DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW);
329 if( *en.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW) !=
330 *fr.getWeekdays(count,DateFormatSymbols::STANDALONE,DateFormatSymbols::NARROW )) {
331 errln("ERROR: setWeekdays(STANDALONE,NARROW) failed");
334 const UnicodeString *wideQuarters = en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
335 fr2.setQuarters(wideQuarters, count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
336 if( *en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE) !=
337 *fr2.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE )) {
338 errln("ERROR: setQuarters(FORMAT, WIDE) failed");
341 const UnicodeString *abbrQuarters = en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
342 fr2.setQuarters(abbrQuarters, count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
343 if( *en.getQuarters(count,DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED) !=
344 *fr2.getQuarters(count,DateFormatSymbols::FORMAT ,DateFormatSymbols::ABBREVIATED )) {
345 errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed");
348 const UnicodeString *standaloneWideQuarters = en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
349 fr.setQuarters(standaloneWideQuarters, count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
350 if( *en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE) !=
351 *fr.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE )) {
352 errln("ERROR: setQuarters(STANDALONE, WIDE) failed");
355 const UnicodeString *standaloneShortQuarters = en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
356 fr.setQuarters(standaloneShortQuarters, count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
357 if( *en.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED) !=
358 *fr.getQuarters(count,DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED )) {
359 errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed");
362 const UnicodeString *ampms = en.getAmPmStrings(count);
363 fr.setAmPmStrings(ampms, count);
364 if( *en.getAmPmStrings(count) != *fr.getAmPmStrings(count)) {
365 errln("ERROR: setAmPmStrings() failed");
368 int32_t rowCount = 0, columnCount = 0;
369 const UnicodeString **strings = en.getZoneStrings(rowCount, columnCount);
370 fr.setZoneStrings(strings, rowCount, columnCount);
371 const UnicodeString **strings1 = fr.getZoneStrings(rowCount, columnCount);
372 for(int32_t i = 0; i < rowCount; i++) {
373 for(int32_t j = 0; j < columnCount; j++) {
374 if( strings[i][j] != strings1[i][j] ) {
375 errln("ERROR: setZoneStrings() failed");
380 UnicodeString localPattern, pat1, pat2;
381 localPattern = en.getLocalPatternChars(localPattern);
382 fr.setLocalPatternChars(localPattern);
383 if( en.getLocalPatternChars(pat1) != fr.getLocalPatternChars(pat2)) {
384 errln("ERROR: setLocalPatternChars() failed");
388 status = U_ZERO_ERROR;
389 DateFormatSymbols foo(status);
390 DateFormatSymbols bar(foo);
395 errln("ERROR: Assignment operator failed");
398 errln("ERROR: Copy Constructor failed");
402 #endif /* #if !UCONFIG_NO_FORMATTING */