OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 2007-2013, International Business Machines Corporation and * | 3 * Copyright (C) 2007-2014, International Business Machines Corporation and * |
4 * others. All Rights Reserved. * | 4 * others. All Rights Reserved. * |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 */ | 6 */ |
7 #include "unicode/utypes.h" | 7 #include "unicode/utypes.h" |
8 | 8 |
9 #if !UCONFIG_NO_FORMATTING | 9 #if !UCONFIG_NO_FORMATTING |
10 | 10 |
11 #include "tzfmttst.h" | 11 #include "tzfmttst.h" |
12 | 12 |
13 #include "simplethread.h" | 13 #include "simplethread.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 { | 69 { |
70 if (exec) { | 70 if (exec) { |
71 logln("TestSuite TimeZoneFormatTest"); | 71 logln("TestSuite TimeZoneFormatTest"); |
72 } | 72 } |
73 switch (index) { | 73 switch (index) { |
74 TESTCASE(0, TestTimeZoneRoundTrip); | 74 TESTCASE(0, TestTimeZoneRoundTrip); |
75 TESTCASE(1, TestTimeRoundTrip); | 75 TESTCASE(1, TestTimeRoundTrip); |
76 TESTCASE(2, TestParse); | 76 TESTCASE(2, TestParse); |
77 TESTCASE(3, TestISOFormat); | 77 TESTCASE(3, TestISOFormat); |
78 TESTCASE(4, TestFormat); | 78 TESTCASE(4, TestFormat); |
| 79 TESTCASE(5, TestFormatTZDBNames); |
79 default: name = ""; break; | 80 default: name = ""; break; |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 void | 84 void |
84 TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { | 85 TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { |
85 UErrorCode status = U_ZERO_ERROR; | 86 UErrorCode status = U_ZERO_ERROR; |
86 | 87 |
87 SimpleTimeZone unknownZone(-31415, ETC_UNKNOWN); | 88 SimpleTimeZone unknownZone(-31415, ETC_UNKNOWN); |
88 int32_t badDstOffset = -1234; | 89 int32_t badDstOffset = -1234; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 328 } |
328 delete tz; | 329 delete tz; |
329 } | 330 } |
330 delete sdf; | 331 delete sdf; |
331 } | 332 } |
332 } | 333 } |
333 delete cal; | 334 delete cal; |
334 delete tzids; | 335 delete tzids; |
335 } | 336 } |
336 | 337 |
| 338 // Special exclusions in TestTimeZoneRoundTrip. |
| 339 // These special cases do not round trip time as designed. |
| 340 static UBool isSpecialTimeRoundTripCase(const char* loc, |
| 341 const UnicodeString& id, |
| 342 const char* pattern, |
| 343 UDate time) { |
| 344 struct { |
| 345 const char* loc; |
| 346 const char* id; |
| 347 const char* pattern; |
| 348 UDate time; |
| 349 } EXCLUSIONS[] = { |
| 350 {NULL, "Asia/Chita", "zzzz", 1414252800000.0}, |
| 351 {NULL, "Asia/Chita", "vvvv", 1414252800000.0}, |
| 352 {NULL, "Asia/Srednekolymsk", "zzzz", 1414241999999.0}, |
| 353 {NULL, "Asia/Srednekolymsk", "vvvv", 1414241999999.0}, |
| 354 {NULL, NULL, NULL, U_DATE_MIN} |
| 355 }; |
| 356 |
| 357 UBool isExcluded = FALSE; |
| 358 for (int32_t i = 0; EXCLUSIONS[i].id != NULL; i++) { |
| 359 if (EXCLUSIONS[i].loc == NULL || uprv_strcmp(loc, EXCLUSIONS[i].loc) ==
0) { |
| 360 if (id.compare(EXCLUSIONS[i].id) == 0) { |
| 361 if (EXCLUSIONS[i].pattern == NULL || uprv_strcmp(pattern, EXCLUS
IONS[i].pattern) == 0) { |
| 362 if (EXCLUSIONS[i].time == U_DATE_MIN || EXCLUSIONS[i].time =
= time) { |
| 363 isExcluded = TRUE; |
| 364 } |
| 365 } |
| 366 } |
| 367 } |
| 368 } |
| 369 return isExcluded; |
| 370 } |
| 371 |
337 struct LocaleData { | 372 struct LocaleData { |
338 int32_t index; | 373 int32_t index; |
339 int32_t testCounts; | 374 int32_t testCounts; |
340 UDate *times; | 375 UDate *times; |
341 const Locale* locales; // Static | 376 const Locale* locales; // Static |
342 int32_t nLocales; // Static | 377 int32_t nLocales; // Static |
343 UBool quick; // Static | 378 UBool quick; // Static |
344 UDate START_TIME; // Static | 379 UDate START_TIME; // Static |
345 UDate END_TIME; // Static | 380 UDate END_TIME; // Static |
346 int32_t numDone; | 381 int32_t numDone; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 } else if (uprv_strcmp(PATTERNS[patidx], "VVV") == 0) { | 485 } else if (uprv_strcmp(PATTERNS[patidx], "VVV") == 0) { |
451 // Some zones are not associated with any region, such a
s Etc/GMT+8. | 486 // Some zones are not associated with any region, such a
s Etc/GMT+8. |
452 // The time roundtrip will fail for such zone with patte
rn "VVV" (exemplar location). | 487 // The time roundtrip will fail for such zone with patte
rn "VVV" (exemplar location). |
453 // This is expected behavior. | 488 // This is expected behavior. |
454 if (tzid->indexOf((UChar)0x2F) < 0 || tzid->indexOf(ETC_
SLASH, -1, 0) >= 0 | 489 if (tzid->indexOf((UChar)0x2F) < 0 || tzid->indexOf(ETC_
SLASH, -1, 0) >= 0 |
455 || tzid->indexOf(SYSTEMV_SLASH, -1, 0) >= 0 || tzid-
>indexOf(RIYADH8, -1, 0) >= 0) { | 490 || tzid->indexOf(SYSTEMV_SLASH, -1, 0) >= 0 || tzid-
>indexOf(RIYADH8, -1, 0) >= 0) { |
456 continue; | 491 continue; |
457 } | 492 } |
458 } | 493 } |
459 | 494 |
| 495 if (*tzid == "Pacific/Apia" && uprv_strcmp(PATTERNS[patidx],
"vvvv") == 0 |
| 496 && log.logKnownIssue("11052", "Ambiguous zone name -
Samoa Time")) { |
| 497 continue; |
| 498 } |
| 499 |
460 BasicTimeZone *tz = (BasicTimeZone*) TimeZone::createTimeZon
e(*tzid); | 500 BasicTimeZone *tz = (BasicTimeZone*) TimeZone::createTimeZon
e(*tzid); |
461 sdf->setTimeZone(*tz); | 501 sdf->setTimeZone(*tz); |
462 | 502 |
463 UDate t = data.START_TIME; | 503 UDate t = data.START_TIME; |
464 TimeZoneTransition tzt; | 504 TimeZoneTransition tzt; |
465 UBool tztAvail = FALSE; | 505 UBool tztAvail = FALSE; |
466 UBool middle = TRUE; | 506 UBool middle = TRUE; |
467 | 507 |
468 while (t < data.END_TIME) { | 508 while (t < data.END_TIME) { |
469 if (!tztAvail) { | 509 if (!tztAvail) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 continue; | 559 continue; |
520 } | 560 } |
521 | 561 |
522 int32_t timeDiff = (int32_t)(parsedDate - testTimes[
testidx]); | 562 int32_t timeDiff = (int32_t)(parsedDate - testTimes[
testidx]); |
523 UBool bTimeMatch = minutesOffset ? | 563 UBool bTimeMatch = minutesOffset ? |
524 (timeDiff/60000)*60000 == 0 : timeDiff == 0; | 564 (timeDiff/60000)*60000 == 0 : timeDiff == 0; |
525 if (!bTimeMatch) { | 565 if (!bTimeMatch) { |
526 UnicodeString msg = (UnicodeString) "Time round
trip failed for " + "tzid=" + *tzid + ", locale=" + data.locales[locidx].getName
() + ", pattern=" + PATTERNS[patidx] | 566 UnicodeString msg = (UnicodeString) "Time round
trip failed for " + "tzid=" + *tzid + ", locale=" + data.locales[locidx].getName
() + ", pattern=" + PATTERNS[patidx] |
527 + ", text=" + text + ", time=" + testTim
es[testidx] + ", restime=" + parsedDate + ", diff=" + (parsedDate - testTimes[te
stidx]); | 567 + ", text=" + text + ", time=" + testTim
es[testidx] + ", restime=" + parsedDate + ", diff=" + (parsedDate - testTimes[te
stidx]); |
528 // Timebomb for TZData update | 568 // Timebomb for TZData update |
529 if (expectedRoundTrip[testidx]) { | 569 if (expectedRoundTrip[testidx] |
| 570 && !isSpecialTimeRoundTripCase(data.loca
les[locidx].getName(), *tzid, |
| 571 PATTERNS[patidx], testTimes[test
idx])) { |
530 log.errln((UnicodeString) "FAIL: " + msg); | 572 log.errln((UnicodeString) "FAIL: " + msg); |
531 } else if (REALLY_VERBOSE) { | 573 } else if (REALLY_VERBOSE) { |
532 log.logln(msg); | 574 log.logln(msg); |
533 } | 575 } |
534 } | 576 } |
535 } | 577 } |
536 tztAvail = tz->getNextTransition(t, FALSE, tzt); | 578 tztAvail = tz->getNextTransition(t, FALSE, tzt); |
537 if (!tztAvail) { | 579 if (!tztAvail) { |
538 break; | 580 break; |
539 } | 581 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 720 |
679 delete cal; | 721 delete cal; |
680 } | 722 } |
681 | 723 |
682 | 724 |
683 typedef struct { | 725 typedef struct { |
684 const char* text; | 726 const char* text; |
685 int32_t inPos; | 727 int32_t inPos; |
686 const char* locale; | 728 const char* locale; |
687 UTimeZoneFormatStyle style; | 729 UTimeZoneFormatStyle style; |
688 UBool parseAll; | 730 uint32_t parseOptions; |
689 const char* expected; | 731 const char* expected; |
690 int32_t outPos; | 732 int32_t outPos; |
691 UTimeZoneFormatTimeType timeType; | 733 UTimeZoneFormatTimeType timeType; |
692 } ParseTestData; | 734 } ParseTestData; |
693 | 735 |
694 void | 736 void |
695 TimeZoneFormatTest::TestParse(void) { | 737 TimeZoneFormatTest::TestParse(void) { |
696 const ParseTestData DATA[] = { | 738 const ParseTestData DATA[] = { |
697 // text inPos locale style
parseAll expected outPos timeType | 739 // text inPos locale style |
698 {"Z", 0, "en_US", UTZFMT_STYLE_ISO_EXTENDED_FU
LL, false, "Etc/GMT", 1, UTZFMT_TIME_TYPE_UNKNOWN}, | 740 // parseOptions expected outPos
timeType |
699 {"Z", 0, "en_US", UTZFMT_STYLE_SPECIFIC_LONG,
false, "Etc/GMT", 1, UTZFMT_TIME_TYPE_UNKNOWN}, | 741 {"Z", 0, "en_US", UTZFMT_STYLE_ISO_EXTENDED_FU
LL, |
700 {"Zambia time", 0, "en_US", UTZFMT_STYLE_ISO_EXTENDED_FU
LL, true, "Etc/GMT", 1, UTZFMT_TIME_TYPE_UNKNOWN}, | 742 UTZFMT_PARSE_OPTION_NONE, "Etc/GMT", 1,
UTZFMT_TIME_TYPE_UNKNOWN}, |
701 {"Zambia time", 0, "en_US", UTZFMT_STYLE_GENERIC_LOCATIO
N, false, "Africa/Lusaka", 11, UTZFMT_TIME_TYPE_UNKNOWN}, | 743 |
702 {"Zambia time", 0, "en_US", UTZFMT_STYLE_ISO_BASIC_LOCAL
_FULL, true, "Africa/Lusaka", 11, UTZFMT_TIME_TYPE_UNKNOWN}, | 744 {"Z", 0, "en_US", UTZFMT_STYLE_SPECIFIC_LONG, |
703 {"+00:00", 0, "en_US", UTZFMT_STYLE_ISO_EXTENDED_FU
LL, false, "Etc/GMT", 6, UTZFMT_TIME_TYPE_UNKNOWN}, | 745 UTZFMT_PARSE_OPTION_NONE, "Etc/GMT", 1,
UTZFMT_TIME_TYPE_UNKNOWN}, |
704 {"-01:30:45", 0, "en_US", UTZFMT_STYLE_ISO_EXTENDED_FU
LL, false, "GMT-01:30:45", 9, UTZFMT_TIME_TYPE_UNKNOWN}, | 746 |
705 {"-7", 0, "en_US", UTZFMT_STYLE_ISO_BASIC_LOCAL
_FULL, false, "GMT-07:00", 2, UTZFMT_TIME_TYPE_UNKNOWN}, | 747 {"Zambia time", 0, "en_US", UTZFMT_STYLE_ISO_EXTENDED_FU
LL, |
706 {"-2222", 0, "en_US", UTZFMT_STYLE_ISO_BASIC_LOCAL
_FULL, false, "GMT-22:22", 5, UTZFMT_TIME_TYPE_UNKNOWN}, | 748 UTZFMT_PARSE_OPTION_ALL_STYLES, "Etc/GMT", 1,
UTZFMT_TIME_TYPE_UNKNOWN}, |
707 {"-3333", 0, "en_US", UTZFMT_STYLE_ISO_BASIC_LOCAL
_FULL, false, "GMT-03:33", 4, UTZFMT_TIME_TYPE_UNKNOWN}, | 749 |
708 {"XXX+01:30YYY", 3, "en_US", UTZFMT_STYLE_LOCALIZED_GMT,
false, "GMT+01:30", 9, UTZFMT_TIME_TYPE_UNKNOWN}, | 750 {"Zambia time", 0, "en_US", UTZFMT_STYLE_GENERIC_LOCATIO
N, |
709 {"GMT0", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT,
false, "Etc/GMT", 3, UTZFMT_TIME_TYPE_UNKNOWN}, | 751 UTZFMT_PARSE_OPTION_NONE, "Africa/Lusaka", 11,
UTZFMT_TIME_TYPE_UNKNOWN}, |
710 {"EST", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT,
false, "America/New_York", 3, UTZFMT_TIME_TYPE_STANDARD}, | 752 |
711 {"ESTx", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT,
false, "America/New_York", 3, UTZFMT_TIME_TYPE_STANDARD}, | 753 {"Zambia time", 0, "en_US", UTZFMT_STYLE_ISO_BASIC_LOCAL
_FULL, |
712 {"EDTx", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT,
false, "America/New_York", 3, UTZFMT_TIME_TYPE_DAYLIGHT}, | 754 UTZFMT_PARSE_OPTION_ALL_STYLES, "Africa/Lusaka", 11,
UTZFMT_TIME_TYPE_UNKNOWN}, |
713 {"EST", 0, "en_US", UTZFMT_STYLE_SPECIFIC_LONG,
false, NULL, 0, UTZFMT_TIME_TYPE_UNKNOWN}, | 755 |
714 {"EST", 0, "en_US", UTZFMT_STYLE_SPECIFIC_LONG,
true, "America/New_York", 3, UTZFMT_TIME_TYPE_STANDARD}, | 756 {"+00:00", 0, "en_US", UTZFMT_STYLE_ISO_EXTENDED_FU
LL, |
715 {"EST", 0, "en_CA", UTZFMT_STYLE_SPECIFIC_SHORT,
false, "America/Toronto", 3, UTZFMT_TIME_TYPE_STANDARD}, | 757 UTZFMT_PARSE_OPTION_NONE, "Etc/GMT", 6,
UTZFMT_TIME_TYPE_UNKNOWN}, |
716 {NULL, 0, NULL, UTZFMT_STYLE_GENERIC_LOCATIO
N, false, NULL, 0, UTZFMT_TIME_TYPE_UNKNOWN} | 758 |
| 759 {"-01:30:45", 0, "en_US", UTZFMT_STYLE_ISO_EXTENDED_FU
LL, |
| 760 UTZFMT_PARSE_OPTION_NONE, "GMT-01:30:45", 9,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 761 |
| 762 {"-7", 0, "en_US", UTZFMT_STYLE_ISO_BASIC_LOCAL
_FULL, |
| 763 UTZFMT_PARSE_OPTION_NONE, "GMT-07:00", 2,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 764 |
| 765 {"-2222", 0, "en_US", UTZFMT_STYLE_ISO_BASIC_LOCAL
_FULL, |
| 766 UTZFMT_PARSE_OPTION_NONE, "GMT-22:22", 5,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 767 |
| 768 {"-3333", 0, "en_US", UTZFMT_STYLE_ISO_BASIC_LOCAL
_FULL, |
| 769 UTZFMT_PARSE_OPTION_NONE, "GMT-03:33", 4,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 770 |
| 771 {"XXX+01:30YYY", 3, "en_US", UTZFMT_STYLE_LOCALIZED_GMT, |
| 772 UTZFMT_PARSE_OPTION_NONE, "GMT+01:30", 9,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 773 |
| 774 {"GMT0", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 775 UTZFMT_PARSE_OPTION_NONE, "Etc/GMT", 3,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 776 |
| 777 {"EST", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 778 UTZFMT_PARSE_OPTION_NONE, "America/New_York", 3,
UTZFMT_TIME_TYPE_STANDARD}, |
| 779 |
| 780 {"ESTx", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 781 UTZFMT_PARSE_OPTION_NONE, "America/New_York", 3,
UTZFMT_TIME_TYPE_STANDARD}, |
| 782 |
| 783 {"EDTx", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 784 UTZFMT_PARSE_OPTION_NONE, "America/New_York", 3,
UTZFMT_TIME_TYPE_DAYLIGHT}, |
| 785 |
| 786 {"EST", 0, "en_US", UTZFMT_STYLE_SPECIFIC_LONG, |
| 787 UTZFMT_PARSE_OPTION_NONE, NULL, 0,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 788 |
| 789 {"EST", 0, "en_US", UTZFMT_STYLE_SPECIFIC_LONG, |
| 790 UTZFMT_PARSE_OPTION_ALL_STYLES, "America/New_York", 3,
UTZFMT_TIME_TYPE_STANDARD}, |
| 791 |
| 792 {"EST", 0, "en_CA", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 793 UTZFMT_PARSE_OPTION_NONE, "America/Toronto", 3,
UTZFMT_TIME_TYPE_STANDARD}, |
| 794 |
| 795 {"CST", 0, "en_US", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 796 UTZFMT_PARSE_OPTION_NONE, "America/Chicago", 3,
UTZFMT_TIME_TYPE_STANDARD}, |
| 797 |
| 798 {"CST", 0, "en_GB", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 799 UTZFMT_PARSE_OPTION_NONE, NULL, 0,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 800 |
| 801 {"CST", 0, "en_GB", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 802 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS, "America/Chicago
", 3, UTZFMT_TIME_TYPE_STANDARD}, |
| 803 |
| 804 {"--CST--", 2, "en_GB", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 805 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS, "America/Chicago
", 5, UTZFMT_TIME_TYPE_STANDARD}, |
| 806 |
| 807 {"CST", 0, "zh_CN", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 808 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS, "Asia/Shanghai",
3, UTZFMT_TIME_TYPE_STANDARD}, |
| 809 |
| 810 {"AEST", 0, "en_AU", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 811 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS, "Australia/Sydne
y", 4, UTZFMT_TIME_TYPE_STANDARD}, |
| 812 |
| 813 {"AST", 0, "ar_SA", UTZFMT_STYLE_SPECIFIC_SHORT, |
| 814 UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS, "Asia/Riyadh",
3, UTZFMT_TIME_TYPE_STANDARD}, |
| 815 |
| 816 {"AQTST", 0, "en", UTZFMT_STYLE_SPECIFIC_LONG, |
| 817 UTZFMT_PARSE_OPTION_NONE, NULL, 0,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 818 |
| 819 {"AQTST", 0, "en", UTZFMT_STYLE_SPECIFIC_LONG, |
| 820 UTZFMT_PARSE_OPTION_ALL_STYLES, NULL, 0,
UTZFMT_TIME_TYPE_UNKNOWN}, |
| 821 |
| 822 {"AQTST", 0, "en", UTZFMT_STYLE_SPECIFIC_LONG, |
| 823 UTZFMT_PARSE_OPTION_ALL_STYLES | UTZFMT_PARSE_OPTION_TZ_DATABASE
_ABBREVIATIONS, "Asia/Aqtobe", 5, UTZFMT_TIME_TYPE_DAYLIGHT}, |
| 824 |
| 825 {NULL, 0, NULL, UTZFMT_STYLE_GENERIC_LOCATIO
N, |
| 826 UTZFMT_PARSE_OPTION_NONE, NULL, 0,
UTZFMT_TIME_TYPE_UNKNOWN} |
717 }; | 827 }; |
718 | 828 |
719 for (int32_t i = 0; DATA[i].text; i++) { | 829 for (int32_t i = 0; DATA[i].text; i++) { |
720 UErrorCode status = U_ZERO_ERROR; | 830 UErrorCode status = U_ZERO_ERROR; |
721 LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(Locale
(DATA[i].locale), status)); | 831 LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(Locale
(DATA[i].locale), status)); |
722 if (U_FAILURE(status)) { | 832 if (U_FAILURE(status)) { |
723 dataerrln("Fail TimeZoneFormat::createInstance: %s", u_errorName(sta
tus)); | 833 dataerrln("Fail TimeZoneFormat::createInstance: %s", u_errorName(sta
tus)); |
724 continue; | 834 continue; |
725 } | 835 } |
726 UTimeZoneFormatTimeType ttype = UTZFMT_TIME_TYPE_UNKNOWN; | 836 UTimeZoneFormatTimeType ttype = UTZFMT_TIME_TYPE_UNKNOWN; |
727 ParsePosition pos(DATA[i].inPos); | 837 ParsePosition pos(DATA[i].inPos); |
728 int32_t parseOptions = DATA[i].parseAll ? UTZFMT_PARSE_OPTION_ALL_STYLES
: UTZFMT_PARSE_OPTION_NONE; | 838 TimeZone* tz = tzfmt->parse(DATA[i].style, DATA[i].text, pos, DATA[i].pa
rseOptions, &ttype); |
729 TimeZone* tz = tzfmt->parse(DATA[i].style, DATA[i].text, pos, parseOptio
ns, &ttype); | |
730 | 839 |
731 UnicodeString errMsg; | 840 UnicodeString errMsg; |
732 if (tz) { | 841 if (tz) { |
733 UnicodeString outID; | 842 UnicodeString outID; |
734 tz->getID(outID); | 843 tz->getID(outID); |
735 if (outID != UnicodeString(DATA[i].expected)) { | 844 if (outID != UnicodeString(DATA[i].expected)) { |
736 errMsg = (UnicodeString)"Time zone ID: " + outID + " - expected:
" + DATA[i].expected; | 845 errMsg = (UnicodeString)"Time zone ID: " + outID + " - expected:
" + DATA[i].expected; |
737 } else if (pos.getIndex() != DATA[i].outPos) { | 846 } else if (pos.getIndex() != DATA[i].outPos) { |
738 errMsg = (UnicodeString)"Parsed pos: " + pos.getIndex() + " - ex
pected: " + DATA[i].outPos; | 847 errMsg = (UnicodeString)"Parsed pos: " + pos.getIndex() + " - ex
pected: " + DATA[i].outPos; |
739 } else if (ttype != DATA[i].timeType) { | 848 } else if (ttype != DATA[i].timeType) { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 expected = expected.unescape(); | 1127 expected = expected.unescape(); |
1019 | 1128 |
1020 assertEquals(UnicodeString("Format result for ") + DATA[i].tzid + " (Tes
t Case " + i + ")", expected, out); | 1129 assertEquals(UnicodeString("Format result for ") + DATA[i].tzid + " (Tes
t Case " + i + ")", expected, out); |
1021 if (DATA[i].timeType != timeType) { | 1130 if (DATA[i].timeType != timeType) { |
1022 dataerrln(UnicodeString("Formatted time zone type (Test Case ") + i
+ "), returned=" | 1131 dataerrln(UnicodeString("Formatted time zone type (Test Case ") + i
+ "), returned=" |
1023 + timeType + ", expected=" + DATA[i].timeType); | 1132 + timeType + ", expected=" + DATA[i].timeType); |
1024 } | 1133 } |
1025 } | 1134 } |
1026 } | 1135 } |
1027 | 1136 |
| 1137 void |
| 1138 TimeZoneFormatTest::TestFormatTZDBNames(void) { |
| 1139 UDate dateJan = 1358208000000.0; // 2013-01-15T00:00:00Z |
| 1140 UDate dateJul = 1373846400000.0; // 2013-07-15T00:00:00Z |
| 1141 |
| 1142 const FormatTestData DATA[] = { |
| 1143 { |
| 1144 "en", |
| 1145 "America/Chicago", |
| 1146 dateJan, |
| 1147 UTZFMT_STYLE_SPECIFIC_SHORT, |
| 1148 "CST", |
| 1149 UTZFMT_TIME_TYPE_STANDARD |
| 1150 }, |
| 1151 { |
| 1152 "en", |
| 1153 "Asia/Shanghai", |
| 1154 dateJan, |
| 1155 UTZFMT_STYLE_SPECIFIC_SHORT, |
| 1156 "CST", |
| 1157 UTZFMT_TIME_TYPE_STANDARD |
| 1158 }, |
| 1159 { |
| 1160 "zh_Hans", |
| 1161 "Asia/Shanghai", |
| 1162 dateJan, |
| 1163 UTZFMT_STYLE_SPECIFIC_SHORT, |
| 1164 "CST", |
| 1165 UTZFMT_TIME_TYPE_STANDARD |
| 1166 }, |
| 1167 { |
| 1168 "en", |
| 1169 "America/Los_Angeles", |
| 1170 dateJul, |
| 1171 UTZFMT_STYLE_SPECIFIC_LONG, |
| 1172 "GMT-07:00", // No long display names |
| 1173 UTZFMT_TIME_TYPE_DAYLIGHT |
| 1174 }, |
| 1175 { |
| 1176 "ja", |
| 1177 "America/Los_Angeles", |
| 1178 dateJul, |
| 1179 UTZFMT_STYLE_SPECIFIC_SHORT, |
| 1180 "PDT", |
| 1181 UTZFMT_TIME_TYPE_DAYLIGHT |
| 1182 }, |
| 1183 { |
| 1184 "en", |
| 1185 "Australia/Sydney", |
| 1186 dateJan, |
| 1187 UTZFMT_STYLE_SPECIFIC_SHORT, |
| 1188 "AEDT", |
| 1189 UTZFMT_TIME_TYPE_DAYLIGHT |
| 1190 }, |
| 1191 { |
| 1192 "en", |
| 1193 "Australia/Sydney", |
| 1194 dateJul, |
| 1195 UTZFMT_STYLE_SPECIFIC_SHORT, |
| 1196 "AEST", |
| 1197 UTZFMT_TIME_TYPE_STANDARD |
| 1198 }, |
| 1199 |
| 1200 {0, 0, 0.0, UTZFMT_STYLE_GENERIC_LOCATION, 0, UTZFMT_TIME_TYPE_UNKNOWN} |
| 1201 }; |
| 1202 |
| 1203 for (int32_t i = 0; DATA[i].locale; i++) { |
| 1204 UErrorCode status = U_ZERO_ERROR; |
| 1205 Locale loc(DATA[i].locale); |
| 1206 LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(loc, s
tatus)); |
| 1207 if (U_FAILURE(status)) { |
| 1208 dataerrln("Fail TimeZoneFormat::createInstance: %s", u_errorName(sta
tus)); |
| 1209 continue; |
| 1210 } |
| 1211 TimeZoneNames *tzdbNames = TimeZoneNames::createTZDBInstance(loc, status
); |
| 1212 if (U_FAILURE(status)) { |
| 1213 dataerrln("Fail TimeZoneNames::createTZDBInstance: %s", u_errorName(
status)); |
| 1214 continue; |
| 1215 } |
| 1216 tzfmt->adoptTimeZoneNames(tzdbNames); |
| 1217 |
| 1218 LocalPointer<TimeZone> tz(TimeZone::createTimeZone(DATA[i].tzid)); |
| 1219 UnicodeString out; |
| 1220 UTimeZoneFormatTimeType timeType; |
| 1221 |
| 1222 tzfmt->format(DATA[i].style, *(tz.getAlias()), DATA[i].date, out, &timeT
ype); |
| 1223 UnicodeString expected(DATA[i].expected, -1, US_INV); |
| 1224 expected = expected.unescape(); |
| 1225 |
| 1226 assertEquals(UnicodeString("Format result for ") + DATA[i].tzid + " (Tes
t Case " + i + ")", expected, out); |
| 1227 if (DATA[i].timeType != timeType) { |
| 1228 dataerrln(UnicodeString("Formatted time zone type (Test Case ") + i
+ "), returned=" |
| 1229 + timeType + ", expected=" + DATA[i].timeType); |
| 1230 } |
| 1231 } |
| 1232 } |
| 1233 |
| 1234 |
1028 #endif /* #if !UCONFIG_NO_FORMATTING */ | 1235 #endif /* #if !UCONFIG_NO_FORMATTING */ |
OLD | NEW |