OLD | NEW |
1 /************************************************************************ | 1 /************************************************************************ |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2013, International Business Machines Corporation | 3 * Copyright (c) 1997-2014, International Business Machines Corporation |
4 * and others. All Rights Reserved. | 4 * and others. All Rights Reserved. |
5 ************************************************************************/ | 5 ************************************************************************/ |
6 #include "unicode/utypes.h" | 6 #include "unicode/utypes.h" |
7 | 7 |
8 #if !UCONFIG_NO_FORMATTING | 8 #if !UCONFIG_NO_FORMATTING |
9 | 9 |
10 #include "caltest.h" | 10 #include "caltest.h" |
11 #include "unicode/dtfmtsym.h" | 11 #include "unicode/dtfmtsym.h" |
12 #include "unicode/gregocal.h" | 12 #include "unicode/gregocal.h" |
13 #include "unicode/localpointer.h" | 13 #include "unicode/localpointer.h" |
(...skipping 10 matching lines...) Expand all Loading... |
24 #define mkcstr(U) u_austrcpy(calloc(8, u_strlen(U) + 1), U) | 24 #define mkcstr(U) u_austrcpy(calloc(8, u_strlen(U) + 1), U) |
25 | 25 |
26 #define TEST_CHECK_STATUS { \ | 26 #define TEST_CHECK_STATUS { \ |
27 if (U_FAILURE(status)) { \ | 27 if (U_FAILURE(status)) { \ |
28 if (status == U_MISSING_RESOURCE_ERROR) { \ | 28 if (status == U_MISSING_RESOURCE_ERROR) { \ |
29 dataerrln("%s:%d: Test failure. status=%s", __FILE__, __LINE__, u_e
rrorName(status)); \ | 29 dataerrln("%s:%d: Test failure. status=%s", __FILE__, __LINE__, u_e
rrorName(status)); \ |
30 } else { \ | 30 } else { \ |
31 errln("%s:%d: Test failure. status=%s", __FILE__, __LINE__, u_error
Name(status)); \ | 31 errln("%s:%d: Test failure. status=%s", __FILE__, __LINE__, u_error
Name(status)); \ |
32 } return;}} | 32 } return;}} |
33 | 33 |
| 34 #define TEST_CHECK_STATUS_LOCALE(testlocale) { \ |
| 35 if (U_FAILURE(status)) { \ |
| 36 if (status == U_MISSING_RESOURCE_ERROR) { \ |
| 37 dataerrln("%s:%d: Test failure, locale %s. status=%s", __FILE__, __
LINE__, testlocale, u_errorName(status)); \ |
| 38 } else { \ |
| 39 errln("%s:%d: Test failure, locale %s. status=%s", __FILE__, __LINE
__, testlocale, u_errorName(status)); \ |
| 40 } return;}} |
| 41 |
34 #define TEST_ASSERT(expr) {if ((expr)==FALSE) {errln("%s:%d: Test failure \n", _
_FILE__, __LINE__);};} | 42 #define TEST_ASSERT(expr) {if ((expr)==FALSE) {errln("%s:%d: Test failure \n", _
_FILE__, __LINE__);};} |
35 | 43 |
36 // ***************************************************************************** | 44 // ***************************************************************************** |
37 // class CalendarTest | 45 // class CalendarTest |
38 // ***************************************************************************** | 46 // ***************************************************************************** |
39 | 47 |
40 UnicodeString CalendarTest::calToStr(const Calendar & cal) | 48 UnicodeString CalendarTest::calToStr(const Calendar & cal) |
41 { | 49 { |
42 UnicodeString out; | 50 UnicodeString out; |
43 UErrorCode status = U_ZERO_ERROR; | 51 UErrorCode status = U_ZERO_ERROR; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 TestIslamicUmAlQura(); | 299 TestIslamicUmAlQura(); |
292 } | 300 } |
293 break; | 301 break; |
294 case 32: | 302 case 32: |
295 name = "TestIslamicTabularDates"; | 303 name = "TestIslamicTabularDates"; |
296 if(exec) { | 304 if(exec) { |
297 logln("TestIslamicTabularDates---"); logln(""); | 305 logln("TestIslamicTabularDates---"); logln(""); |
298 TestIslamicTabularDates(); | 306 TestIslamicTabularDates(); |
299 } | 307 } |
300 break; | 308 break; |
| 309 case 33: |
| 310 name = "TestHebrewMonthValidation"; |
| 311 if(exec) { |
| 312 logln("TestHebrewMonthValidation---"); logln(""); |
| 313 TestHebrewMonthValidation(); |
| 314 } |
| 315 break; |
| 316 case 34: |
| 317 name = "TestWeekData"; |
| 318 if(exec) { |
| 319 logln("TestWeekData---"); logln(""); |
| 320 TestWeekData(); |
| 321 } |
| 322 break; |
| 323 case 35: |
| 324 name = "TestAddAcrossZoneTransition"; |
| 325 if(exec) { |
| 326 logln("TestAddAcrossZoneTransition---"); logln(""); |
| 327 TestAddAcrossZoneTransition(); |
| 328 } |
| 329 break; |
301 default: name = ""; break; | 330 default: name = ""; break; |
302 } | 331 } |
303 } | 332 } |
304 | 333 |
305 // -----------------------------------------------------------------------------
---- | 334 // -----------------------------------------------------------------------------
---- |
306 | 335 |
307 UnicodeString CalendarTest::fieldName(UCalendarDateFields f) { | 336 UnicodeString CalendarTest::fieldName(UCalendarDateFields f) { |
308 switch (f) { | 337 switch (f) { |
309 #define FIELD_NAME_STR(x) case x: return (#x+5) | 338 #define FIELD_NAME_STR(x) case x: return (#x+5) |
310 FIELD_NAME_STR( UCAL_ERA ); | 339 FIELD_NAME_STR( UCAL_ERA ); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 UnicodeString str; | 375 UnicodeString str; |
347 UBool eq = FALSE,b4 = FALSE,af = FALSE; | 376 UBool eq = FALSE,b4 = FALSE,af = FALSE; |
348 | 377 |
349 UDate when = date(90, UCAL_APRIL, 15); | 378 UDate when = date(90, UCAL_APRIL, 15); |
350 | 379 |
351 UnicodeString tzid("TestZone"); | 380 UnicodeString tzid("TestZone"); |
352 int32_t tzoffset = 123400; | 381 int32_t tzoffset = 123400; |
353 | 382 |
354 SimpleTimeZone *zone = new SimpleTimeZone(tzoffset, tzid); | 383 SimpleTimeZone *zone = new SimpleTimeZone(tzoffset, tzid); |
355 Calendar *cal = Calendar::createInstance(zone->clone(), status); | 384 Calendar *cal = Calendar::createInstance(zone->clone(), status); |
356 if (failure(status, "Calendar::createInstance", TRUE)) return; | 385 if (failure(status, "Calendar::createInstance #1", TRUE)) return; |
357 | 386 |
358 if (*zone != cal->getTimeZone()) errln("FAIL: Calendar::getTimeZone failed")
; | 387 if (*zone != cal->getTimeZone()) errln("FAIL: Calendar::getTimeZone failed")
; |
359 | 388 |
360 Calendar *cal2 = Calendar::createInstance(cal->getTimeZone(), status); | 389 Calendar *cal2 = Calendar::createInstance(cal->getTimeZone(), status); |
361 if (failure(status, "Calendar::createInstance")) return; | 390 if (failure(status, "Calendar::createInstance #2")) return; |
362 cal->setTime(when, status); | 391 cal->setTime(when, status); |
363 cal2->setTime(when, status); | 392 cal2->setTime(when, status); |
364 if (failure(status, "Calendar::setTime")) return; | 393 if (failure(status, "Calendar::setTime")) return; |
365 | 394 |
366 if (!(*cal == *cal2)) errln("FAIL: Calendar::operator== failed"); | 395 if (!(*cal == *cal2)) errln("FAIL: Calendar::operator== failed"); |
367 if ((*cal != *cal2)) errln("FAIL: Calendar::operator!= failed"); | 396 if ((*cal != *cal2)) errln("FAIL: Calendar::operator!= failed"); |
368 if (!cal->equals(*cal2, status) || | 397 if (!cal->equals(*cal2, status) || |
369 cal->before(*cal2, status) || | 398 cal->before(*cal2, status) || |
370 cal->after(*cal2, status) || | 399 cal->after(*cal2, status) || |
371 U_FAILURE(status)) errln("FAIL: equals/before/after failed"); | 400 U_FAILURE(status)) errln("FAIL: equals/before/after failed"); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 const Locale* loc = Calendar::getAvailableLocales(count); | 525 const Locale* loc = Calendar::getAvailableLocales(count); |
497 if (count < 1 || loc == 0) | 526 if (count < 1 || loc == 0) |
498 { | 527 { |
499 dataerrln("FAIL: getAvailableLocales failed"); | 528 dataerrln("FAIL: getAvailableLocales failed"); |
500 } | 529 } |
501 else | 530 else |
502 { | 531 { |
503 for (i=0; i<count; ++i) | 532 for (i=0; i<count; ++i) |
504 { | 533 { |
505 cal = Calendar::createInstance(loc[i], status); | 534 cal = Calendar::createInstance(loc[i], status); |
506 if (failure(status, "Calendar::createInstance")) return; | 535 if (U_FAILURE(status)) { |
| 536 errcheckln(status, UnicodeString("FAIL: Calendar::createInstance
#3, locale ") + loc[i].getName() + " , error " + u_errorName(status)); |
| 537 return; |
| 538 } |
507 delete cal; | 539 delete cal; |
508 } | 540 } |
509 } | 541 } |
510 | 542 |
511 cal = Calendar::createInstance(TimeZone::createDefault(), Locale::getEnglish
(), status); | 543 cal = Calendar::createInstance(TimeZone::createDefault(), Locale::getEnglish
(), status); |
512 if (failure(status, "Calendar::createInstance")) return; | 544 if (failure(status, "Calendar::createInstance #4")) return; |
513 delete cal; | 545 delete cal; |
514 | 546 |
515 cal = Calendar::createInstance(*zone, Locale::getEnglish(), status); | 547 cal = Calendar::createInstance(*zone, Locale::getEnglish(), status); |
516 if (failure(status, "Calendar::createInstance")) return; | 548 if (failure(status, "Calendar::createInstance #5")) return; |
517 delete cal; | 549 delete cal; |
518 | 550 |
519 GregorianCalendar *gc = new GregorianCalendar(*zone, status); | 551 GregorianCalendar *gc = new GregorianCalendar(*zone, status); |
520 if (failure(status, "new GregorianCalendar")) return; | 552 if (failure(status, "new GregorianCalendar")) return; |
521 delete gc; | 553 delete gc; |
522 | 554 |
523 gc = new GregorianCalendar(Locale::getEnglish(), status); | 555 gc = new GregorianCalendar(Locale::getEnglish(), status); |
524 if (failure(status, "new GregorianCalendar")) return; | 556 if (failure(status, "new GregorianCalendar")) return; |
525 delete gc; | 557 delete gc; |
526 | 558 |
(...skipping 21 matching lines...) Expand all Loading... |
548 | 580 |
549 GregorianCalendar gc2(Locale::getEnglish(), status); | 581 GregorianCalendar gc2(Locale::getEnglish(), status); |
550 if (failure(status, "new GregorianCalendar")) return; | 582 if (failure(status, "new GregorianCalendar")) return; |
551 gc2 = *gc; | 583 gc2 = *gc; |
552 if (gc2 != *gc || !(gc2 == *gc)) errln("FAIL: GregorianCalendar assignment/o
perator==/operator!= failed"); | 584 if (gc2 != *gc || !(gc2 == *gc)) errln("FAIL: GregorianCalendar assignment/o
perator==/operator!= failed"); |
553 delete gc; | 585 delete gc; |
554 delete z; | 586 delete z; |
555 | 587 |
556 /* Code coverage for Calendar class. */ | 588 /* Code coverage for Calendar class. */ |
557 cal = Calendar::createInstance(status); | 589 cal = Calendar::createInstance(status); |
558 if (failure(status, "Calendar::createInstance")) { | 590 if (failure(status, "Calendar::createInstance #6")) { |
559 return; | 591 return; |
560 }else { | 592 }else { |
561 ((Calendar *)cal)->roll(UCAL_HOUR, (int32_t)100, status); | 593 ((Calendar *)cal)->roll(UCAL_HOUR, (int32_t)100, status); |
562 ((Calendar *)cal)->clear(UCAL_HOUR); | 594 ((Calendar *)cal)->clear(UCAL_HOUR); |
563 #if !UCONFIG_NO_SERVICE | 595 #if !UCONFIG_NO_SERVICE |
564 URegistryKey key = cal->registerFactory(NULL, status); | 596 URegistryKey key = cal->registerFactory(NULL, status); |
565 cal->unregister(key, status); | 597 cal->unregister(key, status); |
566 #endif | 598 #endif |
567 } | 599 } |
568 delete cal; | 600 delete cal; |
569 | 601 |
570 status = U_ZERO_ERROR; | 602 status = U_ZERO_ERROR; |
571 cal = Calendar::createInstance(Locale("he_IL@calendar=hebrew"), status); | 603 cal = Calendar::createInstance(Locale("he_IL@calendar=hebrew"), status); |
572 if (failure(status, "Calendar::createInstance")) { | 604 if (failure(status, "Calendar::createInstance #7")) { |
573 return; | 605 return; |
574 } else { | 606 } else { |
575 cal->roll(Calendar::MONTH, (int32_t)100, status); | 607 cal->roll(Calendar::MONTH, (int32_t)100, status); |
576 } | 608 } |
577 | 609 |
578 LocalPointer<StringEnumeration> values( | 610 LocalPointer<StringEnumeration> values( |
579 Calendar::getKeywordValuesForLocale("calendar", Locale("he"), FALSE, sta
tus)); | 611 Calendar::getKeywordValuesForLocale("calendar", Locale("he"), FALSE, sta
tus)); |
580 if (values.isNull() || U_FAILURE(status)) { | 612 if (values.isNull() || U_FAILURE(status)) { |
581 dataerrln("FAIL: Calendar::getKeywordValuesForLocale(he): %s", u_errorNa
me(status)); | 613 dataerrln("FAIL: Calendar::getKeywordValuesForLocale(he): %s", u_errorNa
me(status)); |
582 } else { | 614 } else { |
(...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2401 if (cal2->getRepeatedWallTimeOption() != UCAL_WALLTIME_FIRST) { | 2433 if (cal2->getRepeatedWallTimeOption() != UCAL_WALLTIME_FIRST) { |
2402 errln("Fail: Repeated wall time option was updated other than UCAL_WALLT
IME_FIRST"); | 2434 errln("Fail: Repeated wall time option was updated other than UCAL_WALLT
IME_FIRST"); |
2403 } | 2435 } |
2404 | 2436 |
2405 delete cal; | 2437 delete cal; |
2406 delete cal2; | 2438 delete cal2; |
2407 } | 2439 } |
2408 | 2440 |
2409 class CalFields { | 2441 class CalFields { |
2410 public: | 2442 public: |
2411 CalFields(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t mi
n, int32_t sec); | 2443 CalFields(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t mi
n, int32_t sec, int32_t ms = 0); |
2412 CalFields(const Calendar& cal, UErrorCode& status); | 2444 CalFields(const Calendar& cal, UErrorCode& status); |
2413 void setTo(Calendar& cal) const; | 2445 void setTo(Calendar& cal) const; |
2414 char* toString(char* buf, int32_t len) const; | 2446 char* toString(char* buf, int32_t len) const; |
2415 UBool operator==(const CalFields& rhs) const; | 2447 UBool operator==(const CalFields& rhs) const; |
2416 UBool operator!=(const CalFields& rhs) const; | 2448 UBool operator!=(const CalFields& rhs) const; |
| 2449 UBool isEquivalentTo(const Calendar& cal, UErrorCode& status) const; |
2417 | 2450 |
2418 private: | 2451 private: |
2419 int32_t year; | 2452 int32_t year; |
2420 int32_t month; | 2453 int32_t month; |
2421 int32_t day; | 2454 int32_t day; |
2422 int32_t hour; | 2455 int32_t hour; |
2423 int32_t min; | 2456 int32_t min; |
2424 int32_t sec; | 2457 int32_t sec; |
| 2458 int32_t ms; |
2425 }; | 2459 }; |
2426 | 2460 |
2427 CalFields::CalFields(int32_t year, int32_t month, int32_t day, int32_t hour, int
32_t min, int32_t sec) | 2461 CalFields::CalFields(int32_t year, int32_t month, int32_t day, int32_t hour, int
32_t min, int32_t sec, int32_t ms) |
2428 : year(year), month(month), day(day), hour(hour), min(min), sec(sec) { | 2462 : year(year), month(month), day(day), hour(hour), min(min), sec(sec), ms(ms)
{ |
2429 } | 2463 } |
2430 | 2464 |
2431 CalFields::CalFields(const Calendar& cal, UErrorCode& status) { | 2465 CalFields::CalFields(const Calendar& cal, UErrorCode& status) { |
2432 year = cal.get(UCAL_YEAR, status); | 2466 year = cal.get(UCAL_YEAR, status); |
2433 month = cal.get(UCAL_MONTH, status) + 1; | 2467 month = cal.get(UCAL_MONTH, status) + 1; |
2434 day = cal.get(UCAL_DAY_OF_MONTH, status); | 2468 day = cal.get(UCAL_DAY_OF_MONTH, status); |
2435 hour = cal.get(UCAL_HOUR_OF_DAY, status); | 2469 hour = cal.get(UCAL_HOUR_OF_DAY, status); |
2436 min = cal.get(UCAL_MINUTE, status); | 2470 min = cal.get(UCAL_MINUTE, status); |
2437 sec = cal.get(UCAL_SECOND, status); | 2471 sec = cal.get(UCAL_SECOND, status); |
| 2472 ms = cal.get(UCAL_MILLISECOND, status); |
2438 } | 2473 } |
2439 | 2474 |
2440 void | 2475 void |
2441 CalFields::setTo(Calendar& cal) const { | 2476 CalFields::setTo(Calendar& cal) const { |
2442 cal.clear(); | 2477 cal.clear(); |
2443 cal.set(year, month - 1, day, hour, min, sec); | 2478 cal.set(year, month - 1, day, hour, min, sec); |
| 2479 cal.set(UCAL_MILLISECOND, ms); |
2444 } | 2480 } |
2445 | 2481 |
2446 char* | 2482 char* |
2447 CalFields::toString(char* buf, int32_t len) const { | 2483 CalFields::toString(char* buf, int32_t len) const { |
2448 char local[32]; | 2484 char local[32]; |
2449 sprintf(local, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, min,
sec); | 2485 sprintf(local, "%04d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour,
min, sec, ms); |
2450 uprv_strncpy(buf, local, len - 1); | 2486 uprv_strncpy(buf, local, len - 1); |
2451 buf[len - 1] = 0; | 2487 buf[len - 1] = 0; |
2452 return buf; | 2488 return buf; |
2453 } | 2489 } |
2454 | 2490 |
2455 UBool | 2491 UBool |
2456 CalFields::operator==(const CalFields& rhs) const { | 2492 CalFields::operator==(const CalFields& rhs) const { |
2457 return year == rhs.year | 2493 return year == rhs.year |
2458 && month == rhs.month | 2494 && month == rhs.month |
2459 && day == rhs.day | 2495 && day == rhs.day |
2460 && hour == rhs.hour | 2496 && hour == rhs.hour |
2461 && min == rhs.min | 2497 && min == rhs.min |
2462 && sec == rhs.sec; | 2498 && sec == rhs.sec |
| 2499 && ms == rhs.ms; |
2463 } | 2500 } |
2464 | 2501 |
2465 UBool | 2502 UBool |
2466 CalFields::operator!=(const CalFields& rhs) const { | 2503 CalFields::operator!=(const CalFields& rhs) const { |
2467 return !(*this == rhs); | 2504 return !(*this == rhs); |
2468 } | 2505 } |
2469 | 2506 |
| 2507 UBool |
| 2508 CalFields::isEquivalentTo(const Calendar& cal, UErrorCode& status) const { |
| 2509 return year == cal.get(UCAL_YEAR, status) |
| 2510 && month == cal.get(UCAL_MONTH, status) + 1 |
| 2511 && day == cal.get(UCAL_DAY_OF_MONTH, status) |
| 2512 && hour == cal.get(UCAL_HOUR_OF_DAY, status) |
| 2513 && min == cal.get(UCAL_MINUTE, status) |
| 2514 && sec == cal.get(UCAL_SECOND, status) |
| 2515 && ms == cal.get(UCAL_MILLISECOND, status); |
| 2516 } |
| 2517 |
2470 typedef struct { | 2518 typedef struct { |
2471 const char* tzid; | 2519 const char* tzid; |
2472 const CalFields in; | 2520 const CalFields in; |
2473 const CalFields expLastGMT; | 2521 const CalFields expLastGMT; |
2474 const CalFields expFirstGMT; | 2522 const CalFields expFirstGMT; |
2475 } RepeatedWallTimeTestData; | 2523 } RepeatedWallTimeTestData; |
2476 | 2524 |
2477 static const RepeatedWallTimeTestData RPDATA[] = | 2525 static const RepeatedWallTimeTestData RPDATA[] = |
2478 { | 2526 { |
2479 // Time zone Input wall time WALLTIME_LAST in GMT
WALLTIME_FIRST in GMT | 2527 // Time zone Input wall time WALLTIME_LAST in GMT
WALLTIME_FIRST in GMT |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2764 } | 2812 } |
2765 } | 2813 } |
2766 } | 2814 } |
2767 | 2815 |
2768 | 2816 |
2769 void CalendarTest::TestIslamicUmAlQura() { | 2817 void CalendarTest::TestIslamicUmAlQura() { |
2770 | 2818 |
2771 UErrorCode status = U_ZERO_ERROR; | 2819 UErrorCode status = U_ZERO_ERROR; |
2772 Locale islamicLoc("ar_SA@calendar=islamic-umalqura"); | 2820 Locale islamicLoc("ar_SA@calendar=islamic-umalqura"); |
2773 Calendar* tstCal = Calendar::createInstance(islamicLoc, status); | 2821 Calendar* tstCal = Calendar::createInstance(islamicLoc, status); |
2774 | 2822 |
2775 IslamicCalendar* iCal = (IslamicCalendar*)tstCal; | 2823 IslamicCalendar* iCal = (IslamicCalendar*)tstCal; |
2776 if(strcmp(iCal->getType(), "islamic-umalqura") != 0) { | 2824 if(strcmp(iCal->getType(), "islamic-umalqura") != 0) { |
2777 errln("wrong type of calendar created - %s", iCal->getType()); | 2825 errln("wrong type of calendar created - %s", iCal->getType()); |
2778 } | 2826 } |
2779 | 2827 |
2780 | 2828 |
2781 int32_t firstYear = 1318; | 2829 int32_t firstYear = 1318; |
2782 int32_t lastYear = 1368; // just enough to be pretty sure | 2830 int32_t lastYear = 1368; // just enough to be pretty sure |
2783 //int32_t lastYear = 1480; // the whole shootin' match | 2831 //int32_t lastYear = 1480; // the whole shootin' match |
2784 | 2832 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2833 TEST_CHECK_STATUS; | 2881 TEST_CHECK_STATUS; |
2834 | 2882 |
2835 SimpleDateFormat* formatter = new SimpleDateFormat("yyyy-MM-dd", Locale::get
US(), status); | 2883 SimpleDateFormat* formatter = new SimpleDateFormat("yyyy-MM-dd", Locale::get
US(), status); |
2836 UDate date = formatter->parse("1975-05-06", status); | 2884 UDate date = formatter->parse("1975-05-06", status); |
2837 Calendar* is_cal = Calendar::createInstance(islamicLoc, status); | 2885 Calendar* is_cal = Calendar::createInstance(islamicLoc, status); |
2838 is_cal->setTime(date, status); | 2886 is_cal->setTime(date, status); |
2839 int32_t is_day = is_cal->get(UCAL_DAY_OF_MONTH,status); | 2887 int32_t is_day = is_cal->get(UCAL_DAY_OF_MONTH,status); |
2840 int32_t is_month = is_cal->get(UCAL_MONTH,status); | 2888 int32_t is_month = is_cal->get(UCAL_MONTH,status); |
2841 int32_t is_year = is_cal->get(UCAL_YEAR,status); | 2889 int32_t is_year = is_cal->get(UCAL_YEAR,status); |
2842 TEST_CHECK_STATUS; | 2890 TEST_CHECK_STATUS; |
2843 if(is_day != 29 || is_month != IslamicCalendar::RABI_2 || is_year != 1395) | 2891 if(is_day != 24 || is_month != IslamicCalendar::RABI_2 || is_year != 1395) |
2844 errln("unexpected conversion date month %i not %i or day %i not 20 or ye
ar %i not 1395", is_month, IslamicCalendar::RABI_2, is_day, is_year); | 2892 errln("unexpected conversion date month %i not %i or day %i not 24 or ye
ar %i not 1395", is_month, IslamicCalendar::RABI_2, is_day, is_year); |
2845 | 2893 |
2846 UDate date2 = is_cal->getTime(status); | 2894 UDate date2 = is_cal->getTime(status); |
2847 TEST_CHECK_STATUS; | 2895 TEST_CHECK_STATUS; |
2848 if(date2 != date) { | 2896 if(date2 != date) { |
2849 errln("before(%f) and after(%f) dates don't match up!",date, date2); | 2897 errln("before(%f) and after(%f) dates don't match up!",date, date2); |
2850 } | 2898 } |
2851 | 2899 |
2852 delete is_cal; | 2900 delete is_cal; |
2853 delete formatter; | 2901 delete formatter; |
2854 delete tstCal; | 2902 delete tstCal; |
2855 } | 2903 } |
2856 | 2904 |
2857 void CalendarTest::TestIslamicTabularDates() { | 2905 void CalendarTest::TestIslamicTabularDates() { |
2858 UErrorCode status = U_ZERO_ERROR; | 2906 UErrorCode status = U_ZERO_ERROR; |
2859 Locale islamicLoc("ar_SA@calendar=islamic-civil"); | 2907 Locale islamicLoc("ar_SA@calendar=islamic-civil"); |
2860 Locale tblaLoc("ar_SA@calendar=islamic-tbla"); | 2908 Locale tblaLoc("ar_SA@calendar=islamic-tbla"); |
2861 SimpleDateFormat* formatter = new SimpleDateFormat("yyyy-MM-dd", Locale::get
US(), status); | 2909 SimpleDateFormat* formatter = new SimpleDateFormat("yyyy-MM-dd", Locale::get
US(), status); |
2862 UDate date = formatter->parse("1975-05-06", status); | 2910 UDate date = formatter->parse("1975-05-06", status); |
2863 | 2911 |
2864 Calendar* tstCal = Calendar::createInstance(islamicLoc, status); | 2912 Calendar* tstCal = Calendar::createInstance(islamicLoc, status); |
2865 tstCal->setTime(date, status); | 2913 tstCal->setTime(date, status); |
2866 int32_t is_day = tstCal->get(UCAL_DAY_OF_MONTH,status); | 2914 int32_t is_day = tstCal->get(UCAL_DAY_OF_MONTH,status); |
2867 int32_t is_month = tstCal->get(UCAL_MONTH,status); | 2915 int32_t is_month = tstCal->get(UCAL_MONTH,status); |
2868 int32_t is_year = tstCal->get(UCAL_YEAR,status); | 2916 int32_t is_year = tstCal->get(UCAL_YEAR,status); |
2869 TEST_CHECK_STATUS; | 2917 TEST_CHECK_STATUS; |
2870 delete tstCal; | 2918 delete tstCal; |
2871 | 2919 |
2872 tstCal = Calendar::createInstance(tblaLoc, status); | 2920 tstCal = Calendar::createInstance(tblaLoc, status); |
2873 tstCal->setTime(date, status); | 2921 tstCal->setTime(date, status); |
2874 int32_t tbla_day = tstCal->get(UCAL_DAY_OF_MONTH,status); | 2922 int32_t tbla_day = tstCal->get(UCAL_DAY_OF_MONTH,status); |
2875 int32_t tbla_month = tstCal->get(UCAL_MONTH,status); | 2923 int32_t tbla_month = tstCal->get(UCAL_MONTH,status); |
2876 int32_t tbla_year = tstCal->get(UCAL_YEAR,status); | 2924 int32_t tbla_year = tstCal->get(UCAL_YEAR,status); |
2877 TEST_CHECK_STATUS; | 2925 TEST_CHECK_STATUS; |
2878 | 2926 |
2879 if(tbla_month != is_month || tbla_year != is_year) | 2927 if(tbla_month != is_month || tbla_year != is_year) |
2880 errln("unexpected difference between islamic and tbla month %d : %d and/
or year %d : %d",tbla_month,is_month,tbla_year,is_year); | 2928 errln("unexpected difference between islamic and tbla month %d : %d and/
or year %d : %d",tbla_month,is_month,tbla_year,is_year); |
2881 | 2929 |
2882 if(tbla_day - is_day != 1) | 2930 if(tbla_day - is_day != 1) |
2883 errln("unexpected day difference between islamic and tbla: %d : %d ",tbl
a_day,is_day); | 2931 errln("unexpected day difference between islamic and tbla: %d : %d ",tbl
a_day,is_day); |
2884 delete tstCal; | 2932 delete tstCal; |
2885 delete formatter; | 2933 delete formatter; |
2886 } | 2934 } |
2887 | 2935 |
| 2936 void CalendarTest::TestHebrewMonthValidation() { |
| 2937 UErrorCode status = U_ZERO_ERROR; |
| 2938 LocalPointer<Calendar> cal(Calendar::createInstance(Locale::createFromName(
"he_IL@calendar=hebrew"), status)); |
| 2939 if (failure(status, "Calendar::createInstance, locale:he_IL@calendar=hebrew"
, TRUE)) return; |
| 2940 Calendar *pCal = cal.getAlias(); |
| 2941 |
| 2942 UDate d; |
| 2943 pCal->setLenient(FALSE); |
| 2944 |
| 2945 // 5776 is a leap year and has month Adar I |
| 2946 pCal->set(5776, HebrewCalendar::ADAR_1, 1); |
| 2947 d = pCal->getTime(status); |
| 2948 if (U_FAILURE(status)) { |
| 2949 errln("Fail: 5776 Adar I 1 is a valid date."); |
| 2950 } |
| 2951 status = U_ZERO_ERROR; |
| 2952 |
| 2953 // 5777 is NOT a lear year and does not have month Adar I |
| 2954 pCal->set(5777, HebrewCalendar::ADAR_1, 1); |
| 2955 d = pCal->getTime(status); |
| 2956 (void)d; |
| 2957 if (status == U_ILLEGAL_ARGUMENT_ERROR) { |
| 2958 logln("Info: U_ILLEGAL_ARGUMENT_ERROR, because 5777 Adar I 1 is not a va
lid date."); |
| 2959 } else { |
| 2960 errln("Fail: U_ILLEGAL_ARGUMENT_ERROR should be set for input date 5777
Adar I 1."); |
| 2961 } |
| 2962 } |
| 2963 |
| 2964 void CalendarTest::TestWeekData() { |
| 2965 // Each line contains two locales using the same set of week rule data. |
| 2966 const char* LOCALE_PAIRS[] = { |
| 2967 "en", "en_US", |
| 2968 "de", "de_DE", |
| 2969 "de_DE", "en_DE", |
| 2970 "en_GB", "und_GB", |
| 2971 "ar_EG", "en_EG", |
| 2972 "ar_SA", "fr_SA", |
| 2973 0 |
| 2974 }; |
| 2975 |
| 2976 UErrorCode status; |
| 2977 |
| 2978 for (int32_t i = 0; LOCALE_PAIRS[i] != 0; i += 2) { |
| 2979 status = U_ZERO_ERROR; |
| 2980 LocalPointer<Calendar> cal1(Calendar::createInstance(LOCALE_PAIRS[i], s
tatus)); |
| 2981 LocalPointer<Calendar> cal2(Calendar::createInstance(LOCALE_PAIRS[i + 1
], status)); |
| 2982 TEST_CHECK_STATUS_LOCALE(LOCALE_PAIRS[i]); |
| 2983 |
| 2984 // First day of week |
| 2985 UCalendarDaysOfWeek dow1 = cal1->getFirstDayOfWeek(status); |
| 2986 UCalendarDaysOfWeek dow2 = cal2->getFirstDayOfWeek(status); |
| 2987 TEST_CHECK_STATUS; |
| 2988 TEST_ASSERT(dow1 == dow2); |
| 2989 |
| 2990 // Minimum days in first week |
| 2991 uint8_t minDays1 = cal1->getMinimalDaysInFirstWeek(); |
| 2992 uint8_t minDays2 = cal2->getMinimalDaysInFirstWeek(); |
| 2993 TEST_ASSERT(minDays1 == minDays2); |
| 2994 |
| 2995 // Weekdays and Weekends |
| 2996 for (int32_t d = UCAL_SUNDAY; d <= UCAL_SATURDAY; d++) { |
| 2997 status = U_ZERO_ERROR; |
| 2998 UCalendarWeekdayType wdt1 = cal1->getDayOfWeekType((UCalendarDaysOfW
eek)d, status); |
| 2999 UCalendarWeekdayType wdt2 = cal2->getDayOfWeekType((UCalendarDaysOfW
eek)d, status); |
| 3000 TEST_CHECK_STATUS; |
| 3001 TEST_ASSERT(wdt1 == wdt2); |
| 3002 } |
| 3003 } |
| 3004 } |
| 3005 |
| 3006 typedef struct { |
| 3007 const char* zone; |
| 3008 const CalFields base; |
| 3009 int32_t deltaDays; |
| 3010 UCalendarWallTimeOption skippedWTOpt; |
| 3011 const CalFields expected; |
| 3012 } TestAddAcrossZoneTransitionData; |
| 3013 |
| 3014 static const TestAddAcrossZoneTransitionData AAZTDATA[] = |
| 3015 { |
| 3016 // Time zone Base wall time day(s) Skip
ped time options |
| 3017 // Expected wall time |
| 3018 |
| 3019 // Add 1 day, from the date before DST transition |
| 3020 {"America/Los_Angeles", CalFields(2014,3,8,1,59,59,999), 1, UCAL
_WALLTIME_FIRST, |
| 3021 CalFields(2014,3,9,1,59,59,999)}, |
| 3022 |
| 3023 {"America/Los_Angeles", CalFields(2014,3,8,1,59,59,999), 1, UCAL
_WALLTIME_LAST, |
| 3024 CalFields(2014,3,9,1,59,59,999)}, |
| 3025 |
| 3026 {"America/Los_Angeles", CalFields(2014,3,8,1,59,59,999), 1, UCAL
_WALLTIME_NEXT_VALID, |
| 3027 CalFields(2014,3,9,1,59,59,999)}, |
| 3028 |
| 3029 |
| 3030 {"America/Los_Angeles", CalFields(2014,3,8,2,0,0,0), 1, UCAL
_WALLTIME_FIRST, |
| 3031 CalFields(2014,3,9,1,0,0,0)}, |
| 3032 |
| 3033 {"America/Los_Angeles", CalFields(2014,3,8,2,0,0,0), 1, UCAL
_WALLTIME_LAST, |
| 3034 CalFields(2014,3,9,3,0,0,0)}, |
| 3035 |
| 3036 {"America/Los_Angeles", CalFields(2014,3,8,2,0,0,0), 1, UCAL
_WALLTIME_NEXT_VALID, |
| 3037 CalFields(2014,3,9,3,0,0,0)}, |
| 3038 |
| 3039 |
| 3040 {"America/Los_Angeles", CalFields(2014,3,8,2,30,0,0), 1, UCAL
_WALLTIME_FIRST, |
| 3041 CalFields(2014,3,9,1,30,0,0)}, |
| 3042 |
| 3043 {"America/Los_Angeles", CalFields(2014,3,8,2,30,0,0), 1, UCAL
_WALLTIME_LAST, |
| 3044 CalFields(2014,3,9,3,30,0,0)}, |
| 3045 |
| 3046 {"America/Los_Angeles", CalFields(2014,3,8,2,30,0,0), 1, UCAL
_WALLTIME_NEXT_VALID, |
| 3047 CalFields(2014,3,9,3,0,0,0)}, |
| 3048 |
| 3049 |
| 3050 {"America/Los_Angeles", CalFields(2014,3,8,3,0,0,0), 1, UCAL
_WALLTIME_FIRST, |
| 3051 CalFields(2014,3,9,3,0,0,0)}, |
| 3052 |
| 3053 {"America/Los_Angeles", CalFields(2014,3,8,3,0,0,0), 1, UCAL
_WALLTIME_LAST, |
| 3054 CalFields(2014,3,9,3,0,0,0)}, |
| 3055 |
| 3056 {"America/Los_Angeles", CalFields(2014,3,8,3,0,0,0), 1, UCAL
_WALLTIME_NEXT_VALID, |
| 3057 CalFields(2014,3,9,3,0,0,0)}, |
| 3058 |
| 3059 // Subtract 1 day, from one day after DST transition |
| 3060 {"America/Los_Angeles", CalFields(2014,3,10,1,59,59,999), -1, UCAL
_WALLTIME_FIRST, |
| 3061 CalFields(2014,3,9,1,59,59,999)}, |
| 3062 |
| 3063 {"America/Los_Angeles", CalFields(2014,3,10,1,59,59,999), -1, UCAL
_WALLTIME_LAST, |
| 3064 CalFields(2014,3,9,1,59,59,999)}, |
| 3065 |
| 3066 {"America/Los_Angeles", CalFields(2014,3,10,1,59,59,999), -1, UCAL
_WALLTIME_NEXT_VALID, |
| 3067 CalFields(2014,3,9,1,59,59,999)}, |
| 3068 |
| 3069 |
| 3070 {"America/Los_Angeles", CalFields(2014,3,10,2,0,0,0), -1, UCAL
_WALLTIME_FIRST, |
| 3071 CalFields(2014,3,9,1,0,0,0)}, |
| 3072 |
| 3073 {"America/Los_Angeles", CalFields(2014,3,10,2,0,0,0), -1, UCAL
_WALLTIME_LAST, |
| 3074 CalFields(2014,3,9,3,0,0,0)}, |
| 3075 |
| 3076 {"America/Los_Angeles", CalFields(2014,3,10,2,0,0,0), -1, UCAL
_WALLTIME_NEXT_VALID, |
| 3077 CalFields(2014,3,9,3,0,0,0)}, |
| 3078 |
| 3079 |
| 3080 {"America/Los_Angeles", CalFields(2014,3,10,2,30,0,0), -1, UCAL
_WALLTIME_FIRST, |
| 3081 CalFields(2014,3,9,1,30,0,0)}, |
| 3082 |
| 3083 {"America/Los_Angeles", CalFields(2014,3,10,2,30,0,0), -1, UCAL
_WALLTIME_LAST, |
| 3084 CalFields(2014,3,9,3,30,0,0)}, |
| 3085 |
| 3086 {"America/Los_Angeles", CalFields(2014,3,10,2,30,0,0), -1, UCAL
_WALLTIME_NEXT_VALID, |
| 3087 CalFields(2014,3,9,3,0,0,0)}, |
| 3088 |
| 3089 |
| 3090 {"America/Los_Angeles", CalFields(2014,3,10,3,0,0,0), -1, UCAL
_WALLTIME_FIRST, |
| 3091 CalFields(2014,3,9,3,0,0,0)}, |
| 3092 |
| 3093 {"America/Los_Angeles", CalFields(2014,3,10,3,0,0,0), -1, UCAL
_WALLTIME_LAST, |
| 3094 CalFields(2014,3,9,3,0,0,0)}, |
| 3095 |
| 3096 {"America/Los_Angeles", CalFields(2014,3,10,3,0,0,0), -1, UCAL
_WALLTIME_NEXT_VALID, |
| 3097 CalFields(2014,3,9,3,0,0,0)}, |
| 3098 |
| 3099 |
| 3100 // Test case for ticket#10544 |
| 3101 {"America/Santiago", CalFields(2013,4,27,0,0,0,0), 134, UCAL
_WALLTIME_FIRST, |
| 3102 CalFields(2013,9,7,23,0,0,0)}, |
| 3103 |
| 3104 {"America/Santiago", CalFields(2013,4,27,0,0,0,0), 134, UCAL
_WALLTIME_LAST, |
| 3105 CalFields(2013,9,8,1,0,0,0)}, |
| 3106 |
| 3107 {"America/Santiago", CalFields(2013,4,27,0,0,0,0), 134, UCAL
_WALLTIME_NEXT_VALID, |
| 3108 CalFields(2013,9,8,1,0,0,0)}, |
| 3109 |
| 3110 |
| 3111 {"America/Santiago", CalFields(2013,4,27,0,30,0,0), 134, UCAL
_WALLTIME_FIRST, |
| 3112 CalFields(2013,9,7,23,30,0,0)}, |
| 3113 |
| 3114 {"America/Santiago", CalFields(2013,4,27,0,30,0,0), 134, UCAL
_WALLTIME_LAST, |
| 3115 CalFields(2013,9,8,1,30,0,0)}, |
| 3116 |
| 3117 {"America/Santiago", CalFields(2013,4,27,0,30,0,0), 134, UCAL
_WALLTIME_NEXT_VALID, |
| 3118 CalFields(2013,9,8,1,0,0,0)}, |
| 3119 |
| 3120 |
| 3121 // Extreme transition - Pacific/Apia completely skips 2011-12-30 |
| 3122 {"Pacific/Apia", CalFields(2011,12,29,0,0,0,0), 1, UCAL
_WALLTIME_FIRST, |
| 3123 CalFields(2011,12,31,0,0,0,0)}, |
| 3124 |
| 3125 {"Pacific/Apia", CalFields(2011,12,29,0,0,0,0), 1, UCAL
_WALLTIME_LAST, |
| 3126 CalFields(2011,12,31,0,0,0,0)}, |
| 3127 |
| 3128 {"Pacific/Apia", CalFields(2011,12,29,0,0,0,0), 1, UCAL
_WALLTIME_NEXT_VALID, |
| 3129 CalFields(2011,12,31,0,0,0,0)}, |
| 3130 |
| 3131 |
| 3132 {"Pacific/Apia", CalFields(2011,12,31,12,0,0,0), -1, UCAL
_WALLTIME_FIRST, |
| 3133 CalFields(2011,12,29,12,0,0,0)}, |
| 3134 |
| 3135 {"Pacific/Apia", CalFields(2011,12,31,12,0,0,0), -1, UCAL
_WALLTIME_LAST, |
| 3136 CalFields(2011,12,29,12,0,0,0)}, |
| 3137 |
| 3138 {"Pacific/Apia", CalFields(2011,12,31,12,0,0,0), -1, UCAL
_WALLTIME_NEXT_VALID, |
| 3139 CalFields(2011,12,29,12,0,0,0)}, |
| 3140 |
| 3141 |
| 3142 // 30 minutes DST - Australia/Lord_Howe |
| 3143 {"Australia/Lord_Howe", CalFields(2013,10,5,2,15,0,0), 1, UCAL
_WALLTIME_FIRST, |
| 3144 CalFields(2013,10,6,1,45,0,0)}, |
| 3145 |
| 3146 {"Australia/Lord_Howe", CalFields(2013,10,5,2,15,0,0), 1, UCAL
_WALLTIME_LAST, |
| 3147 CalFields(2013,10,6,2,45,0,0)}, |
| 3148 |
| 3149 {"Australia/Lord_Howe", CalFields(2013,10,5,2,15,0,0), 1, UCAL
_WALLTIME_NEXT_VALID, |
| 3150 CalFields(2013,10,6,2,30,0,0)}, |
| 3151 |
| 3152 {NULL, CalFields(0,0,0,0,0,0,0), 0, UCAL_WALLTIME_LAST, CalFields(0,0,0,0,0,
0,0)} |
| 3153 }; |
| 3154 |
| 3155 void CalendarTest::TestAddAcrossZoneTransition() { |
| 3156 UErrorCode status = U_ZERO_ERROR; |
| 3157 GregorianCalendar cal(status); |
| 3158 TEST_CHECK_STATUS; |
| 3159 |
| 3160 for (int32_t i = 0; AAZTDATA[i].zone; i++) { |
| 3161 status = U_ZERO_ERROR; |
| 3162 TimeZone *tz = TimeZone::createTimeZone(AAZTDATA[i].zone); |
| 3163 cal.adoptTimeZone(tz); |
| 3164 cal.setSkippedWallTimeOption(AAZTDATA[i].skippedWTOpt); |
| 3165 AAZTDATA[i].base.setTo(cal); |
| 3166 cal.add(UCAL_DATE, AAZTDATA[i].deltaDays, status); |
| 3167 TEST_CHECK_STATUS; |
| 3168 |
| 3169 if (!AAZTDATA[i].expected.isEquivalentTo(cal, status)) { |
| 3170 CalFields res(cal, status); |
| 3171 TEST_CHECK_STATUS; |
| 3172 char buf[32]; |
| 3173 const char *optDisp = AAZTDATA[i].skippedWTOpt == UCAL_WALLTIME_FIRS
T ? "FIRST" : |
| 3174 AAZTDATA[i].skippedWTOpt == UCAL_WALLTIME_LAST ? "LAST" : "N
EXT_VALID"; |
| 3175 dataerrln(UnicodeString("Error: base:") + AAZTDATA[i].base.toString(
buf, sizeof(buf)) + ", tz:" + AAZTDATA[i].zone |
| 3176 + ", delta:" + AAZTDATA[i].deltaDays + " day(s), opt:" +
optDisp |
| 3177 + ", result:" + res.toString(buf, sizeof(buf)) |
| 3178 + " - expected:" + AAZTDATA[i].expected.toString(buf, si
zeof(buf))); |
| 3179 } |
| 3180 } |
| 3181 } |
2888 | 3182 |
2889 #endif /* #if !UCONFIG_NO_FORMATTING */ | 3183 #endif /* #if !UCONFIG_NO_FORMATTING */ |
2890 | 3184 |
2891 //eof | 3185 //eof |
OLD | NEW |