1 /******************************************************************** 2 * Copyright (c) 1997-2009, 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 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 */ 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 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 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 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 */ 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 errcheckln(status, "ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status)); 139 return; 140 } 141 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)); 146 return; 147 } 148 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)); 153 return; 154 } 155 156 if(en == fr || ! (en != fr) ) { 157 errln("ERROR: English DateFormatSymbols equal to French"); 158 } 159 160 // just do some VERY basic tests to make sure that get/set work 161 162 int32_t count = 0; 163 const UnicodeString *eras = en.getEras(count); 164 if(count == 0) { 165 errln("ERROR: 0 english eras.. exiting..\n"); 166 return; 167 } 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"); 175 } 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"); 183 } 184 185 fr.setEras(eras, count); 186 if( *en.getEras(count) != *fr.getEras(count)) { 187 errln("ERROR: setEras() failed"); 188 } 189 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"); 194 } 195 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"); 200 } 201 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"); 207 } 208 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"); 214 } 215 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"); 221 } 222 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"); 228 } 229 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"); 235 } 236 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"); 242 } 243 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"); 248 } 249 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"); 254 } 255 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"); 261 } 262 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"); 268 } 269 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"); 275 } 276 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"); 282 } 283 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"); 289 } 290 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"); 296 } 297 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"); 303 } 304 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"); 310 } 311 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"); 317 } 318 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"); 324 } 325 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"); 330 } 331 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"); 340 } 341 } 342 } 343 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"); 349 } 350 351 352 status = U_ZERO_ERROR; 353 DateFormatSymbols foo(status); 354 DateFormatSymbols bar(foo); 355 356 en = fr; 357 358 if(en != fr) { 359 errln("ERROR: Assignment operator failed"); 360 } 361 if(foo != bar) { 362 errln("ERROR: Copy Constructor failed"); 363 } 364 } 365 366 #endif /* #if !UCONFIG_NO_FORMATTING */ 367