OLD | NEW |
1 /******************************************************************** | 1 /******************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2014, International Business Machines | 3 * Copyright (c) 1997-2015, International Business Machines |
4 * Corporation and others. All Rights Reserved. | 4 * Corporation and 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 "dtfmttst.h" | 11 #include "dtfmttst.h" |
12 #include "unicode/localpointer.h" | 12 #include "unicode/localpointer.h" |
13 #include "unicode/timezone.h" | 13 #include "unicode/timezone.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 TESTCASE_AUTO(TestCzechMonths459); | 51 TESTCASE_AUTO(TestCzechMonths459); |
52 TESTCASE_AUTO(TestLetterDPattern212); | 52 TESTCASE_AUTO(TestLetterDPattern212); |
53 TESTCASE_AUTO(TestDayOfYearPattern195); | 53 TESTCASE_AUTO(TestDayOfYearPattern195); |
54 TESTCASE_AUTO(TestQuotePattern161); | 54 TESTCASE_AUTO(TestQuotePattern161); |
55 TESTCASE_AUTO(TestBadInput135); | 55 TESTCASE_AUTO(TestBadInput135); |
56 TESTCASE_AUTO(TestBadInput135a); | 56 TESTCASE_AUTO(TestBadInput135a); |
57 TESTCASE_AUTO(TestTwoDigitYear); | 57 TESTCASE_AUTO(TestTwoDigitYear); |
58 TESTCASE_AUTO(TestDateFormatZone061); | 58 TESTCASE_AUTO(TestDateFormatZone061); |
59 TESTCASE_AUTO(TestDateFormatZone146); | 59 TESTCASE_AUTO(TestDateFormatZone146); |
60 TESTCASE_AUTO(TestLocaleDateFormat); | 60 TESTCASE_AUTO(TestLocaleDateFormat); |
| 61 TESTCASE_AUTO(TestFormattingLocaleTimeSeparator); |
61 TESTCASE_AUTO(TestWallyWedel); | 62 TESTCASE_AUTO(TestWallyWedel); |
62 TESTCASE_AUTO(TestDateFormatCalendar); | 63 TESTCASE_AUTO(TestDateFormatCalendar); |
63 TESTCASE_AUTO(TestSpaceParsing); | 64 TESTCASE_AUTO(TestSpaceParsing); |
64 TESTCASE_AUTO(TestExactCountFormat); | 65 TESTCASE_AUTO(TestExactCountFormat); |
65 TESTCASE_AUTO(TestWhiteSpaceParsing); | 66 TESTCASE_AUTO(TestWhiteSpaceParsing); |
66 TESTCASE_AUTO(TestInvalidPattern); | 67 TESTCASE_AUTO(TestInvalidPattern); |
67 TESTCASE_AUTO(TestGeneral); | 68 TESTCASE_AUTO(TestGeneral); |
68 TESTCASE_AUTO(TestGreekMay); | 69 TESTCASE_AUTO(TestGreekMay); |
69 TESTCASE_AUTO(TestGenericTime); | 70 TESTCASE_AUTO(TestGenericTime); |
70 TESTCASE_AUTO(TestGenericTimeZoneOrder); | 71 TESTCASE_AUTO(TestGenericTimeZoneOrder); |
71 TESTCASE_AUTO(TestHost); | 72 TESTCASE_AUTO(TestHost); |
72 TESTCASE_AUTO(TestEras); | 73 TESTCASE_AUTO(TestEras); |
73 TESTCASE_AUTO(TestNarrowNames); | 74 TESTCASE_AUTO(TestNarrowNames); |
74 TESTCASE_AUTO(TestShortDays); | 75 TESTCASE_AUTO(TestShortDays); |
75 TESTCASE_AUTO(TestStandAloneDays); | 76 TESTCASE_AUTO(TestStandAloneDays); |
76 TESTCASE_AUTO(TestStandAloneMonths); | 77 TESTCASE_AUTO(TestStandAloneMonths); |
77 TESTCASE_AUTO(TestQuarters); | 78 TESTCASE_AUTO(TestQuarters); |
78 TESTCASE_AUTO(TestZTimeZoneParsing); | 79 TESTCASE_AUTO(TestZTimeZoneParsing); |
79 TESTCASE_AUTO(TestRelative); | 80 TESTCASE_AUTO(TestRelative); |
80 TESTCASE_AUTO(TestRelativeClone); | 81 TESTCASE_AUTO(TestRelativeClone); |
81 TESTCASE_AUTO(TestHostClone); | 82 TESTCASE_AUTO(TestHostClone); |
| 83 TESTCASE_AUTO(TestHebrewClone); |
| 84 TESTCASE_AUTO(TestDateFormatSymbolsClone); |
82 TESTCASE_AUTO(TestTimeZoneDisplayName); | 85 TESTCASE_AUTO(TestTimeZoneDisplayName); |
83 TESTCASE_AUTO(TestRoundtripWithCalendar); | 86 TESTCASE_AUTO(TestRoundtripWithCalendar); |
84 TESTCASE_AUTO(Test6338); | 87 TESTCASE_AUTO(Test6338); |
85 TESTCASE_AUTO(Test6726); | 88 TESTCASE_AUTO(Test6726); |
86 TESTCASE_AUTO(TestGMTParsing); | 89 TESTCASE_AUTO(TestGMTParsing); |
87 TESTCASE_AUTO(Test6880); | 90 TESTCASE_AUTO(Test6880); |
88 TESTCASE_AUTO(TestISOEra); | 91 TESTCASE_AUTO(TestISOEra); |
89 TESTCASE_AUTO(TestFormalChineseDate); | 92 TESTCASE_AUTO(TestFormalChineseDate); |
90 TESTCASE_AUTO(TestNumberAsStringParsing); | 93 TESTCASE_AUTO(TestNumberAsStringParsing); |
91 TESTCASE_AUTO(TestStandAloneGMTParse); | 94 TESTCASE_AUTO(TestStandAloneGMTParse); |
92 TESTCASE_AUTO(TestParsePosition); | 95 TESTCASE_AUTO(TestParsePosition); |
93 TESTCASE_AUTO(TestMonthPatterns); | 96 TESTCASE_AUTO(TestMonthPatterns); |
94 TESTCASE_AUTO(TestContext); | 97 TESTCASE_AUTO(TestContext); |
95 TESTCASE_AUTO(TestNonGregoFmtParse); | 98 TESTCASE_AUTO(TestNonGregoFmtParse); |
96 /* | 99 /* |
97 TESTCASE_AUTO(TestRelativeError); | 100 TESTCASE_AUTO(TestRelativeError); |
98 TESTCASE_AUTO(TestRelativeOther); | 101 TESTCASE_AUTO(TestRelativeOther); |
99 */ | 102 */ |
100 TESTCASE_AUTO(TestDotAndAtLeniency); | 103 TESTCASE_AUTO(TestDotAndAtLeniency); |
101 TESTCASE_AUTO(TestDateFormatLeniency); | 104 TESTCASE_AUTO(TestDateFormatLeniency); |
102 TESTCASE_AUTO(TestParseMultiPatternMatch); | 105 TESTCASE_AUTO(TestParseMultiPatternMatch); |
103 | 106 |
104 TESTCASE_AUTO(TestParseLeniencyAPIs); | 107 TESTCASE_AUTO(TestParseLeniencyAPIs); |
105 TESTCASE_AUTO(TestNumberFormatOverride); | 108 TESTCASE_AUTO(TestNumberFormatOverride); |
| 109 TESTCASE_AUTO(TestCreateInstanceForSkeleton); |
| 110 TESTCASE_AUTO(TestCreateInstanceForSkeletonDefault); |
| 111 TESTCASE_AUTO(TestCreateInstanceForSkeletonWithCalendar); |
| 112 TESTCASE_AUTO(TestDFSCreateForLocaleNonGregorianLocale); |
| 113 TESTCASE_AUTO(TestDFSCreateForLocaleWithCalendarInLocale); |
| 114 TESTCASE_AUTO(TestChangeCalendar); |
106 | 115 |
107 TESTCASE_AUTO_END; | 116 TESTCASE_AUTO_END; |
108 } | 117 } |
109 | 118 |
110 void DateFormatTest::TestPatterns() { | 119 void DateFormatTest::TestPatterns() { |
111 static const struct { | 120 static const struct { |
112 const char *actualPattern; | 121 const char *actualPattern; |
113 const char *expectedPattern; | 122 const char *expectedPattern; |
114 const char *localeID; | 123 const char *localeID; |
115 const char *expectedLocalPattern; | 124 const char *expectedLocalPattern; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 426 } |
418 } | 427 } |
419 return (s = buf); | 428 return (s = buf); |
420 } | 429 } |
421 | 430 |
422 // ------------------------------------- | 431 // ------------------------------------- |
423 | 432 |
424 /** | 433 /** |
425 * This MUST be kept in sync with DateFormatSymbols.gPatternChars. | 434 * This MUST be kept in sync with DateFormatSymbols.gPatternChars. |
426 */ | 435 */ |
| 436 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
| 437 static const char* PATTERN_CHARS = "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr:"; |
| 438 #else |
427 static const char* PATTERN_CHARS = "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr"; | 439 static const char* PATTERN_CHARS = "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr"; |
| 440 #endif |
428 | 441 |
429 /** | 442 /** |
430 * A list of the names of all the fields in DateFormat. | 443 * A list of the names of all the fields in DateFormat. |
431 * This MUST be kept in sync with DateFormat. | 444 * This MUST be kept in sync with DateFormat. |
432 */ | 445 */ |
433 static const char* DATEFORMAT_FIELD_NAMES[] = { | 446 static const char* DATEFORMAT_FIELD_NAMES[] = { |
434 "ERA_FIELD", | 447 "ERA_FIELD", |
435 "YEAR_FIELD", | 448 "YEAR_FIELD", |
436 "MONTH_FIELD", | 449 "MONTH_FIELD", |
437 "DATE_FIELD", | 450 "DATE_FIELD", |
(...skipping 21 matching lines...) Expand all Loading... |
459 "STAND_ALONE_DAY_FIELD", | 472 "STAND_ALONE_DAY_FIELD", |
460 "STAND_ALONE_MONTH_FIELD", | 473 "STAND_ALONE_MONTH_FIELD", |
461 "QUARTER_FIELD", | 474 "QUARTER_FIELD", |
462 "STAND_ALONE_QUARTER_FIELD", | 475 "STAND_ALONE_QUARTER_FIELD", |
463 "TIMEZONE_SPECIAL_FIELD", | 476 "TIMEZONE_SPECIAL_FIELD", |
464 "YEAR_NAME_FIELD", | 477 "YEAR_NAME_FIELD", |
465 "TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD", | 478 "TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD", |
466 "TIMEZONE_ISO_FIELD", | 479 "TIMEZONE_ISO_FIELD", |
467 "TIMEZONE_ISO_LOCAL_FIELD", | 480 "TIMEZONE_ISO_LOCAL_FIELD", |
468 "RELATED_YEAR_FIELD", | 481 "RELATED_YEAR_FIELD", |
| 482 "UDAT_TIME_SEPARATOR_FIELD", |
469 }; | 483 }; |
470 | 484 |
471 static const int32_t DATEFORMAT_FIELD_NAMES_LENGTH = | 485 static const int32_t DATEFORMAT_FIELD_NAMES_LENGTH = |
472 sizeof(DATEFORMAT_FIELD_NAMES) / sizeof(DATEFORMAT_FIELD_NAMES[0]); | 486 sizeof(DATEFORMAT_FIELD_NAMES) / sizeof(DATEFORMAT_FIELD_NAMES[0]); |
473 | 487 |
474 /** | 488 /** |
475 * Verify that returned field position indices are correct. | 489 * Verify that returned field position indices are correct. |
476 */ | 490 */ |
477 void DateFormatTest::TestFieldPosition() { | 491 void DateFormatTest::TestFieldPosition() { |
478 UErrorCode ec = U_ZERO_ERROR; | 492 UErrorCode ec = U_ZERO_ERROR; |
479 int32_t i, j, exp; | 493 int32_t i, j, exp; |
480 UnicodeString buf; | 494 UnicodeString buf; |
481 | 495 |
482 // Verify data | 496 // Verify data |
483 DateFormatSymbols rootSyms(Locale(""), ec); | 497 DateFormatSymbols rootSyms(Locale(""), ec); |
484 if (U_FAILURE(ec)) { | 498 if (U_FAILURE(ec)) { |
485 dataerrln("Unable to create DateFormatSymbols - %s", u_errorName(ec)); | 499 dataerrln("Unable to create DateFormatSymbols - %s", u_errorName(ec)); |
486 return; | 500 return; |
487 } | 501 } |
488 | 502 |
489 // local pattern chars data is not longer loaded | 503 // local pattern chars data is not longer loaded |
490 // from icu locale bundle | 504 // from icu locale bundle |
491 assertEquals("patternChars", PATTERN_CHARS, rootSyms.getLocalPatternChars(bu
f)); | 505 assertEquals("patternChars", PATTERN_CHARS, rootSyms.getLocalPatternChars(bu
f)); |
492 assertEquals("patternChars", PATTERN_CHARS, DateFormatSymbols::getPatternUCh
ars()); | 506 assertEquals("patternChars", PATTERN_CHARS, DateFormatSymbols::getPatternUCh
ars()); |
493 assertTrue("DATEFORMAT_FIELD_NAMES", DATEFORMAT_FIELD_NAMES_LENGTH == UDAT_F
IELD_COUNT); | 507 assertTrue("DATEFORMAT_FIELD_NAMES", DATEFORMAT_FIELD_NAMES_LENGTH == UDAT_F
IELD_COUNT); |
| 508 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
494 assertTrue("Data", UDAT_FIELD_COUNT == uprv_strlen(PATTERN_CHARS)); | 509 assertTrue("Data", UDAT_FIELD_COUNT == uprv_strlen(PATTERN_CHARS)); |
| 510 #else |
| 511 assertTrue("Data", UDAT_FIELD_COUNT == uprv_strlen(PATTERN_CHARS) + 1); // +
1 for missing TIME_SEPARATOR pattern char |
| 512 #endif |
495 | 513 |
496 // Create test formatters | 514 // Create test formatters |
497 const int32_t COUNT = 4; | 515 const int32_t COUNT = 4; |
498 DateFormat* dateFormats[COUNT]; | 516 DateFormat* dateFormats[COUNT]; |
499 dateFormats[0] = DateFormat::createDateTimeInstance(DateFormat::kFull, DateF
ormat::kFull, Locale::getUS()); | 517 dateFormats[0] = DateFormat::createDateTimeInstance(DateFormat::kFull, DateF
ormat::kFull, Locale::getUS()); |
500 dateFormats[1] = DateFormat::createDateTimeInstance(DateFormat::kFull, DateF
ormat::kFull, Locale::getFrance()); | 518 dateFormats[1] = DateFormat::createDateTimeInstance(DateFormat::kFull, DateF
ormat::kFull, Locale::getFrance()); |
501 // Make the pattern "G y M d..." | 519 // Make the pattern "G y M d..." |
502 buf.remove().append(PATTERN_CHARS); | 520 buf.remove().append(PATTERN_CHARS); |
503 for (j=buf.length()-1; j>=0; --j) buf.insert(j, (UChar)32/*' '*/); | 521 for (j=buf.length()-1; j>=0; --j) buf.insert(j, (UChar)32/*' '*/); |
504 dateFormats[2] = new SimpleDateFormat(buf, Locale::getUS(), ec); | 522 dateFormats[2] = new SimpleDateFormat(buf, Locale::getUS(), ec); |
505 // Make the pattern "GGGG yyyy MMMM dddd..." | 523 // Make the pattern "GGGG yyyy MMMM dddd..." |
506 for (j=buf.length()-1; j>=0; j-=2) { | 524 for (j=buf.length()-1; j>=0; j-=2) { |
507 for (i=0; i<3; ++i) { | 525 for (i=0; i<3; ++i) { |
508 buf.insert(j, buf.charAt(j)); | 526 buf.insert(j, buf.charAt(j)); |
509 } | 527 } |
510 } | 528 } |
511 dateFormats[3] = new SimpleDateFormat(buf, Locale::getUS(), ec); | 529 dateFormats[3] = new SimpleDateFormat(buf, Locale::getUS(), ec); |
512 if(U_FAILURE(ec)){ | 530 if(U_FAILURE(ec)){ |
513 errln(UnicodeString("Could not create SimpleDateFormat object for locale
en_US. Error: " )+ UnicodeString(u_errorName(ec))); | 531 errln(UnicodeString("Could not create SimpleDateFormat object for locale
en_US. Error: " )+ UnicodeString(u_errorName(ec))); |
514 return; | 532 return; |
515 } | 533 } |
516 UDate aug13 = 871508052513.0; | 534 UDate aug13 = 871508052513.0; |
517 | 535 |
518 // Expected output field values for above DateFormats on aug13 | 536 // Expected output field values for above DateFormats on aug13 |
519 // Fields are given in order of DateFormat field number | 537 // Fields are given in order of DateFormat field number |
520 const char* EXPECTED[] = { | 538 const char* EXPECTED[] = { |
521 "", "1997", "August", "13", "", "", "34", "12", "", "Wednesday", | 539 "", "1997", "August", "13", "", "", "34", "12", "", "Wednesday", |
522 "", "", "", "", "PM", "2", "", "Pacific Daylight Time", "", "", | 540 "", "", "", "", "PM", "2", "", "Pacific Daylight Time", "", "", |
523 "", "", "", "", "", "", "", "", "", "", | 541 "", "", "", "", "", "", "", "", "", "", |
524 "", "", "", "", "", | 542 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
| 543 "", "", "", "", "", ":", |
| 544 #else |
| 545 "", "", "", "", "", "", |
| 546 #endif |
525 | 547 |
526 "", "1997", "ao\\u00FBt", "13", "", "14", "34", "12", "", "mercredi", | 548 "", "1997", "ao\\u00FBt", "13", "", "14", "34", "12", "", "mercredi", |
527 "", "", "", "", "", "", "", "heure d\\u2019\\u00E9t\\u00E9 du Pacifique"
, "", "", | 549 "", "", "", "", "", "", "", "heure d\\u2019\\u00E9t\\u00E9 du Pacifique"
, "", "", |
528 "", "", "", "", "", "", "", "", "", "", | 550 "", "", "", "", "", "", "", "", "", "", |
529 "", "", "", "", "", | 551 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
| 552 "", "", "", "", "", ":", |
| 553 #else |
| 554 "", "", "", "", "", "", |
| 555 #endif |
530 | 556 |
531 "AD", "1997", "8", "13", "14", "14", "34", "12", "5", "Wed", | 557 "AD", "1997", "8", "13", "14", "14", "34", "12", "5", "Wed", |
532 "225", "2", "33", "3", "PM", "2", "2", "PDT", "1997", "4", | 558 "225", "2", "33", "3", "PM", "2", "2", "PDT", "1997", "4", |
533 "1997", "2450674", "52452513", "-0700", "PT", "4", "8", "3", "3", "usla
x", | 559 "1997", "2450674", "52452513", "-0700", "PT", "4", "8", "3", "3", "usla
x", |
534 "1997", "GMT-7", "-07", "-07", "1997", | 560 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
| 561 "1997", "GMT-7", "-07", "-07", "1997", ":", |
| 562 #else |
| 563 "1997", "GMT-7", "-07", "-07", "1997", "", |
| 564 #endif |
535 | 565 |
536 "Anno Domini", "1997", "August", "0013", "0014", "0014", "0034", "0012",
"5130", "Wednesday", | 566 "Anno Domini", "1997", "August", "0013", "0014", "0014", "0034", "0012",
"5130", "Wednesday", |
537 "0225", "0002", "0033", "0003", "PM", "0002", "0002", "Pacific Daylight
Time", "1997", "Wednesday", | 567 "0225", "0002", "0033", "0003", "PM", "0002", "0002", "Pacific Daylight
Time", "1997", "Wednesday", |
538 "1997", "2450674", "52452513", "GMT-07:00", "Pacific Time", "Wednesday"
, "August", "3rd quarter", "3rd quarter", "Los Angeles Time", | 568 "1997", "2450674", "52452513", "GMT-07:00", "Pacific Time", "Wednesday"
, "August", "3rd quarter", "3rd quarter", "Los Angeles Time", |
539 "1997", "GMT-07:00", "-0700", "-0700","1997", | 569 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
| 570 "1997", "GMT-07:00", "-0700", "-0700", "1997", ":", |
| 571 #else |
| 572 "1997", "GMT-07:00", "-0700", "-0700", "1997", "", |
| 573 #endif |
540 }; | 574 }; |
541 | 575 |
542 const int32_t EXPECTED_LENGTH = sizeof(EXPECTED)/sizeof(EXPECTED[0]); | 576 const int32_t EXPECTED_LENGTH = sizeof(EXPECTED)/sizeof(EXPECTED[0]); |
543 | 577 |
544 assertTrue("data size", EXPECTED_LENGTH == COUNT * UDAT_FIELD_COUNT); | 578 assertTrue("data size", EXPECTED_LENGTH == COUNT * UDAT_FIELD_COUNT); |
545 | 579 |
546 TimeZone* PT = TimeZone::createTimeZone("America/Los_Angeles"); | 580 TimeZone* PT = TimeZone::createTimeZone("America/Los_Angeles"); |
547 for (j = 0, exp = 0; j < COUNT; ++j) { | 581 for (j = 0, exp = 0; j < COUNT; ++j) { |
548 // String str; | 582 // String str; |
549 DateFormat* df = dateFormats[j]; | 583 DateFormat* df = dateFormats[j]; |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 * Test the formatting of dates in different locales. | 1307 * Test the formatting of dates in different locales. |
1274 */ | 1308 */ |
1275 void | 1309 void |
1276 DateFormatTest::TestLocaleDateFormat() // Bug 495 | 1310 DateFormatTest::TestLocaleDateFormat() // Bug 495 |
1277 { | 1311 { |
1278 UDate testDate = date(97, UCAL_SEPTEMBER, 15); | 1312 UDate testDate = date(97, UCAL_SEPTEMBER, 15); |
1279 DateFormat *dfFrench = DateFormat::createDateTimeInstance(DateFormat::FULL, | 1313 DateFormat *dfFrench = DateFormat::createDateTimeInstance(DateFormat::FULL, |
1280 DateFormat::FULL, Locale::getFrench()); | 1314 DateFormat::FULL, Locale::getFrench()); |
1281 DateFormat *dfUS = DateFormat::createDateTimeInstance(DateFormat::FULL, | 1315 DateFormat *dfUS = DateFormat::createDateTimeInstance(DateFormat::FULL, |
1282 DateFormat::FULL, Locale::getUS()); | 1316 DateFormat::FULL, Locale::getUS()); |
1283 UnicodeString expectedFRENCH ( "lundi 15 septembre 1997 00:00:00 heure d\\u2
019\\u00E9t\\u00E9 du Pacifique", -1, US_INV ); | 1317 UnicodeString expectedFRENCH ( "lundi 15 septembre 1997 \\u00E0 00:00:00 heu
re d\\u2019\\u00E9t\\u00E9 du Pacifique", -1, US_INV ); |
1284 expectedFRENCH = expectedFRENCH.unescape(); | 1318 expectedFRENCH = expectedFRENCH.unescape(); |
1285 UnicodeString expectedUS ( "Monday, September 15, 1997 at 12:00:00 AM Pacifi
c Daylight Time" ); | 1319 UnicodeString expectedUS ( "Monday, September 15, 1997 at 12:00:00 AM Pacifi
c Daylight Time" ); |
1286 logln((UnicodeString)"Date set to : " + dateToString(testDate)); | 1320 logln((UnicodeString)"Date set to : " + dateToString(testDate)); |
1287 UnicodeString out; | 1321 UnicodeString out; |
1288 if (dfUS == NULL || dfFrench == NULL){ | 1322 if (dfUS == NULL || dfFrench == NULL){ |
1289 dataerrln("Error calling DateFormat::createDateTimeInstance)"); | 1323 dataerrln("Error calling DateFormat::createDateTimeInstance)"); |
1290 delete dfUS; | 1324 delete dfUS; |
1291 delete dfFrench; | 1325 delete dfFrench; |
1292 return; | 1326 return; |
1293 } | 1327 } |
1294 | 1328 |
1295 dfFrench->format(testDate, out); | 1329 dfFrench->format(testDate, out); |
1296 logln((UnicodeString)"Date Formated with French Locale " + out); | 1330 logln((UnicodeString)"Date Formated with French Locale " + out); |
1297 if (!(out == expectedFRENCH)) | 1331 if (!(out == expectedFRENCH)) |
1298 errln((UnicodeString)"FAIL: Expected " + expectedFRENCH); | 1332 errln((UnicodeString)"FAIL: Expected " + expectedFRENCH); |
1299 out.truncate(0); | 1333 out.truncate(0); |
1300 dfUS->format(testDate, out); | 1334 dfUS->format(testDate, out); |
1301 logln((UnicodeString)"Date Formated with US Locale " + out); | 1335 logln((UnicodeString)"Date Formated with US Locale " + out); |
1302 if (!(out == expectedUS)) | 1336 if (!(out == expectedUS)) |
1303 errln((UnicodeString)"FAIL: Expected " + expectedUS); | 1337 errln((UnicodeString)"FAIL: Expected " + expectedUS); |
1304 delete dfUS; | 1338 delete dfUS; |
1305 delete dfFrench; | 1339 delete dfFrench; |
1306 } | 1340 } |
1307 | 1341 |
| 1342 void |
| 1343 DateFormatTest::TestFormattingLocaleTimeSeparator() |
| 1344 { |
| 1345 // This test not as useful is it once was, since timeSeparator |
| 1346 // in the Arabic is changed back to ":" in CLDR 28. |
| 1347 const UDate testDate = 874266720000.; // Sun Sep 14 21:52:00 CET 1997 |
| 1348 logln((UnicodeString)"Date set to : " + dateToString(testDate)); |
| 1349 |
| 1350 const LocalPointer<const TimeZone> tz(TimeZone::createTimeZone("CET")); |
| 1351 |
| 1352 const LocalPointer<DateFormat> dfArab(DateFormat::createTimeInstance( |
| 1353 DateFormat::SHORT, Locale("ar"))); |
| 1354 |
| 1355 const LocalPointer<DateFormat> dfLatn(DateFormat::createTimeInstance( |
| 1356 DateFormat::SHORT, Locale("ar", NULL, NULL, "numbers=latn"))); |
| 1357 |
| 1358 if (dfLatn.isNull() || dfArab.isNull()) { |
| 1359 dataerrln("Error calling DateFormat::createTimeInstance()"); |
| 1360 return; |
| 1361 } |
| 1362 |
| 1363 dfArab->setTimeZone(*tz); |
| 1364 dfLatn->setTimeZone(*tz); |
| 1365 |
| 1366 const UnicodeString expectedArab = UnicodeString( |
| 1367 "\\u0669:\\u0665\\u0662 \\u0645", -1, US_INV).unescape(); |
| 1368 |
| 1369 const UnicodeString expectedLatn = UnicodeString( |
| 1370 "9:52 \\u0645", -1, US_INV).unescape(); |
| 1371 |
| 1372 UnicodeString actualArab; |
| 1373 UnicodeString actualLatn; |
| 1374 |
| 1375 dfArab->format(testDate, actualArab); |
| 1376 dfLatn->format(testDate, actualLatn); |
| 1377 |
| 1378 assertEquals("Arab", expectedArab, actualArab); |
| 1379 assertEquals("Latn", expectedLatn, actualLatn); |
| 1380 } |
| 1381 |
1308 /** | 1382 /** |
1309 * Test DateFormat(Calendar) API | 1383 * Test DateFormat(Calendar) API |
1310 */ | 1384 */ |
1311 void DateFormatTest::TestDateFormatCalendar() { | 1385 void DateFormatTest::TestDateFormatCalendar() { |
1312 DateFormat *date=0, *time=0, *full=0; | 1386 DateFormat *date=0, *time=0, *full=0; |
1313 Calendar *cal=0; | 1387 Calendar *cal=0; |
1314 UnicodeString str; | 1388 UnicodeString str; |
1315 ParsePosition pos; | 1389 ParsePosition pos; |
1316 UDate when; | 1390 UDate when; |
1317 UErrorCode ec = U_ZERO_ERROR; | 1391 UErrorCode ec = U_ZERO_ERROR; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 NULL, "Apr-05-06", "2006 04 05 00:00:00", | 1484 NULL, "Apr-05-06", "2006 04 05 00:00:00", |
1411 NULL, "Apr 05, 2006", "2006 04 05 00:00:00", | 1485 NULL, "Apr 05, 2006", "2006 04 05 00:00:00", |
1412 | 1486 |
1413 "MMMM d yy", " Apr 05 06", "2006 04 05 00:00:00", | 1487 "MMMM d yy", " Apr 05 06", "2006 04 05 00:00:00", |
1414 NULL, "Apr 05 06", "2006 04 05 00:00:00", | 1488 NULL, "Apr 05 06", "2006 04 05 00:00:00", |
1415 NULL, "Apr05 06", "2006 04 05 00:00:00", | 1489 NULL, "Apr05 06", "2006 04 05 00:00:00", |
1416 | 1490 |
1417 "hh:mm:ss a", "12:34:56 PM", "1970 01 01 12:34:56", | 1491 "hh:mm:ss a", "12:34:56 PM", "1970 01 01 12:34:56", |
1418 NULL, "12:34:56PM", "1970 01 01 12:34:56", | 1492 NULL, "12:34:56PM", "1970 01 01 12:34:56", |
1419 NULL, "12.34.56PM", "1970 01 01 12:34:56", | 1493 NULL, "12.34.56PM", "1970 01 01 12:34:56", |
1420 NULL, "12-34-56 PM", "1970 01 01 12:34:56", | |
1421 NULL, "12 : 34 : 56 PM", "1970 01 01 12:34:56", | 1494 NULL, "12 : 34 : 56 PM", "1970 01 01 12:34:56", |
1422 | 1495 |
1423 "MM d yy 'at' hh:mm:ss a", "04/05/06 12:34:56 PM", "2006 04 05 12:34:56"
, | 1496 "MM d yy 'at' hh:mm:ss a", "04/05/06 12:34:56 PM", "2006 04 05 12:34:56"
, |
1424 | 1497 |
1425 "MMMM dd yyyy hh:mm a", "September 27, 1964 21:56 PM", "1964 09 28 09:56
:00", | 1498 "MMMM dd yyyy hh:mm a", "September 27, 1964 21:56 PM", "1964 09 28 09:56
:00", |
1426 NULL, "November 4, 2008 0:13 AM", "2008 11 04 00:13
:00", | 1499 NULL, "November 4, 2008 0:13 AM", "2008 11 04 00:13
:00", |
1427 | 1500 |
1428 "HH'h'mm'min'ss's'", "12h34min56s", "1970 01 01 12:34:56", | 1501 "HH'h'mm'min'ss's'", "12h34min56s", "1970 01 01 12:34:56", |
1429 NULL, "12h34mi56s", "1970 01 01 12:34:56", | 1502 NULL, "12h34mi56s", "1970 01 01 12:34:56", |
1430 NULL, "12h34m56s", "1970 01 01 12:34:56", | 1503 NULL, "12h34m56s", "1970 01 01 12:34:56", |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 "EEEEEE d", "fp", "1970 01 17 0:00:00", "Sa 17", "1970
01 17 0:00:00", | 1715 "EEEEEE d", "fp", "1970 01 17 0:00:00", "Sa 17", "1970
01 17 0:00:00", |
1643 "cccccc d", "fp", "1970 01 17 0:00:00", "Sa 17", "1970
01 17 0:00:00", | 1716 "cccccc d", "fp", "1970 01 17 0:00:00", "Sa 17", "1970
01 17 0:00:00", |
1644 "cccccc", "fp", "1970 01 03 0:00:00", "Sa", "1970
01 03 0:00:00", | 1717 "cccccc", "fp", "1970 01 03 0:00:00", "Sa", "1970
01 03 0:00:00", |
1645 }; | 1718 }; |
1646 const char *SV_DATA[] = { | 1719 const char *SV_DATA[] = { |
1647 "yyyy MM dd HH:mm:ss", | 1720 "yyyy MM dd HH:mm:ss", |
1648 | 1721 |
1649 "EEEEEE d MMM y", "fp", "2013 01 13 0:00:00", "s\\u00F6 13 jan. 2013",
"2013 01 13 0:00:00", | 1722 "EEEEEE d MMM y", "fp", "2013 01 13 0:00:00", "s\\u00F6 13 jan. 2013",
"2013 01 13 0:00:00", |
1650 "EEEEEE d MMM y", "fp", "2013 01 16 0:00:00", "on 16 jan. 2013",
"2013 01 16 0:00:00", | 1723 "EEEEEE d MMM y", "fp", "2013 01 16 0:00:00", "on 16 jan. 2013",
"2013 01 16 0:00:00", |
1651 "EEEEEE d", "fp", "1970 01 17 0:00:00", "l\\u00F6 17", "
1970 01 17 0:00:00", | 1724 "EEEEEE d", "fp", "1970 01 17 0:00:00", "l\\u00F6 17", "
1970 01 17 0:00:00", |
1652 "cccccc d", "fp", "1970 01 17 0:00:00", "L\\u00F6 17", "
1970 01 17 0:00:00", | 1725 "cccccc d", "fp", "1970 01 17 0:00:00", "l\\u00F6 17", "
1970 01 17 0:00:00", |
1653 "cccccc", "fp", "1970 01 03 0:00:00", "L\\u00F6", "
1970 01 03 0:00:00", | 1726 "cccccc", "fp", "1970 01 03 0:00:00", "l\\u00F6", "
1970 01 03 0:00:00", |
1654 }; | 1727 }; |
1655 expect(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", "")); | 1728 expect(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", "")); |
1656 expect(SV_DATA, ARRAY_SIZE(SV_DATA), Locale("sv", "", "")); | 1729 expect(SV_DATA, ARRAY_SIZE(SV_DATA), Locale("sv", "", "")); |
1657 } | 1730 } |
1658 | 1731 |
1659 void DateFormatTest::TestNarrowNames() | 1732 void DateFormatTest::TestNarrowNames() |
1660 { | 1733 { |
1661 const char *EN_DATA[] = { | 1734 const char *EN_DATA[] = { |
1662 "yyyy MM dd HH:mm:ss", | 1735 "yyyy MM dd HH:mm:ss", |
1663 | 1736 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 "EEEEE", "1970 01 02 0:00:00", "F", | 1771 "EEEEE", "1970 01 02 0:00:00", "F", |
1699 "EEEEE", "1970 01 03 0:00:00", "S", | 1772 "EEEEE", "1970 01 03 0:00:00", "S", |
1700 | 1773 |
1701 "ccccc", "1970 01 04 0:00:00", "S", | 1774 "ccccc", "1970 01 04 0:00:00", "S", |
1702 "ccccc", "1970 01 05 0:00:00", "M", | 1775 "ccccc", "1970 01 05 0:00:00", "M", |
1703 "ccccc", "1970 01 06 0:00:00", "T", | 1776 "ccccc", "1970 01 06 0:00:00", "T", |
1704 "ccccc", "1970 01 07 0:00:00", "W", | 1777 "ccccc", "1970 01 07 0:00:00", "W", |
1705 "ccccc", "1970 01 01 0:00:00", "T", | 1778 "ccccc", "1970 01 01 0:00:00", "T", |
1706 "ccccc", "1970 01 02 0:00:00", "F", | 1779 "ccccc", "1970 01 02 0:00:00", "F", |
1707 "ccccc", "1970 01 03 0:00:00", "S", | 1780 "ccccc", "1970 01 03 0:00:00", "S", |
| 1781 |
| 1782 "h:mm a", "2015 01 01 10:00:00", "10:00 AM", |
| 1783 "h:mm a", "2015 01 01 22:00:00", "10:00 PM", |
| 1784 "h:mm aaaaa", "2015 01 01 10:00:00", "10:00 a", |
| 1785 "h:mm aaaaa", "2015 01 01 22:00:00", "10:00 p", |
1708 }; | 1786 }; |
1709 | 1787 |
1710 const char *CS_DATA[] = { | 1788 const char *CS_DATA[] = { |
1711 "yyyy MM dd HH:mm:ss", | 1789 "yyyy MM dd HH:mm:ss", |
1712 | 1790 |
1713 "yyyy LLLLL dd H:mm:ss", "2004 04 10 16:36:31", "2004 4 10 16:36:31"
, | 1791 "yyyy LLLLL dd H:mm:ss", "2004 04 10 16:36:31", "2004 4 10 16:36:31"
, |
1714 "yyyy MMMMM dd H:mm:ss", "2004 04 10 16:36:31", "2004 4 10 16:36:31"
, | 1792 "yyyy MMMMM dd H:mm:ss", "2004 04 10 16:36:31", "2004 4 10 16:36:31"
, |
1715 | 1793 |
1716 "MMMMM", "1970 01 01 0:00:00", "1", | 1794 "MMMMM", "1970 01 01 0:00:00", "1", |
1717 "MMMMM", "1970 02 01 0:00:00", "2", | 1795 "MMMMM", "1970 02 01 0:00:00", "2", |
(...skipping 29 matching lines...) Expand all Loading... |
1747 "EEEEE", "1970 01 02 0:00:00", "P", | 1825 "EEEEE", "1970 01 02 0:00:00", "P", |
1748 "EEEEE", "1970 01 03 0:00:00", "S", | 1826 "EEEEE", "1970 01 03 0:00:00", "S", |
1749 | 1827 |
1750 "ccccc", "1970 01 04 0:00:00", "N", | 1828 "ccccc", "1970 01 04 0:00:00", "N", |
1751 "ccccc", "1970 01 05 0:00:00", "P", | 1829 "ccccc", "1970 01 05 0:00:00", "P", |
1752 "ccccc", "1970 01 06 0:00:00", "\\u00DA", | 1830 "ccccc", "1970 01 06 0:00:00", "\\u00DA", |
1753 "ccccc", "1970 01 07 0:00:00", "S", | 1831 "ccccc", "1970 01 07 0:00:00", "S", |
1754 "ccccc", "1970 01 01 0:00:00", "\\u010C", | 1832 "ccccc", "1970 01 01 0:00:00", "\\u010C", |
1755 "ccccc", "1970 01 02 0:00:00", "P", | 1833 "ccccc", "1970 01 02 0:00:00", "P", |
1756 "ccccc", "1970 01 03 0:00:00", "S", | 1834 "ccccc", "1970 01 03 0:00:00", "S", |
| 1835 |
| 1836 "h:mm a", "2015 01 01 10:00:00", "10:00 dop.", |
| 1837 "h:mm a", "2015 01 01 22:00:00", "10:00 odp.", |
| 1838 "h:mm aaaaa", "2015 01 01 10:00:00", "10:00 dop.", |
| 1839 "h:mm aaaaa", "2015 01 01 22:00:00", "10:00 odp.", |
| 1840 }; |
| 1841 |
| 1842 const char *CA_DATA[] = { |
| 1843 "yyyy MM dd HH:mm:ss", |
| 1844 |
| 1845 "h:mm a", "2015 01 01 10:00:00", "10:00 a. m.", |
| 1846 "h:mm a", "2015 01 01 22:00:00", "10:00 p. m.", |
| 1847 "h:mm aaaaa", "2015 01 01 10:00:00", "10:00 a. m.", |
| 1848 "h:mm aaaaa", "2015 01 01 22:00:00", "10:00 p. m.", |
1757 }; | 1849 }; |
1758 | 1850 |
1759 expectFormat(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", "")); | 1851 expectFormat(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", "")); |
1760 expectFormat(CS_DATA, ARRAY_SIZE(CS_DATA), Locale("cs", "", "")); | 1852 expectFormat(CS_DATA, ARRAY_SIZE(CS_DATA), Locale("cs", "", "")); |
| 1853 expectFormat(CA_DATA, ARRAY_SIZE(CA_DATA), Locale("ca", "", "")); |
1761 } | 1854 } |
1762 | 1855 |
1763 void DateFormatTest::TestEras() | 1856 void DateFormatTest::TestEras() |
1764 { | 1857 { |
1765 const char *EN_DATA[] = { | 1858 const char *EN_DATA[] = { |
1766 "yyyy MM dd", | 1859 "yyyy MM dd", |
1767 | 1860 |
1768 "MMMM dd yyyy G", "fp", "1951 07 17", "July 17 1951 AD", "19
51 07 17", | 1861 "MMMM dd yyyy G", "fp", "1951 07 17", "July 17 1951 AD", "19
51 07 17", |
1769 "MMMM dd yyyy GG", "fp", "1951 07 17", "July 17 1951 AD", "19
51 07 17", | 1862 "MMMM dd yyyy GG", "fp", "1951 07 17", "July 17 1951 AD", "19
51 07 17", |
1770 "MMMM dd yyyy GGG", "fp", "1951 07 17", "July 17 1951 AD", "19
51 07 17", | 1863 "MMMM dd yyyy GGG", "fp", "1951 07 17", "July 17 1951 AD", "19
51 07 17", |
(...skipping 15 matching lines...) Expand all Loading... |
1786 | 1879 |
1787 "Q", "fp", "1970 01 01", "1", "1970 01 01", | 1880 "Q", "fp", "1970 01 01", "1", "1970 01 01", |
1788 "QQ", "fp", "1970 04 01", "02", "1970 04 01", | 1881 "QQ", "fp", "1970 04 01", "02", "1970 04 01", |
1789 "QQQ", "fp", "1970 07 01", "Q3", "1970 07 01", | 1882 "QQQ", "fp", "1970 07 01", "Q3", "1970 07 01", |
1790 "QQQQ", "fp", "1970 10 01", "4th quarter", "1970 10 01", | 1883 "QQQQ", "fp", "1970 10 01", "4th quarter", "1970 10 01", |
1791 | 1884 |
1792 "q", "fp", "1970 01 01", "1", "1970 01 01", | 1885 "q", "fp", "1970 01 01", "1", "1970 01 01", |
1793 "qq", "fp", "1970 04 01", "02", "1970 04 01", | 1886 "qq", "fp", "1970 04 01", "02", "1970 04 01", |
1794 "qqq", "fp", "1970 07 01", "Q3", "1970 07 01", | 1887 "qqq", "fp", "1970 07 01", "Q3", "1970 07 01", |
1795 "qqqq", "fp", "1970 10 01", "4th quarter", "1970 10 01", | 1888 "qqqq", "fp", "1970 10 01", "4th quarter", "1970 10 01", |
| 1889 |
| 1890 "Qyy", "fp", "2015 04 01", "215", "2015 04 01", |
| 1891 "QQyy", "fp", "2015 07 01", "0315", "2015 07 01", |
1796 }; | 1892 }; |
1797 | 1893 |
1798 expect(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", "")); | 1894 expect(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", "")); |
1799 } | 1895 } |
1800 | 1896 |
1801 /** | 1897 /** |
1802 * Test parsing. Input is an array that starts with the following | 1898 * Test parsing. Input is an array that starts with the following |
1803 * header: | 1899 * header: |
1804 * | 1900 * |
1805 * [0] = pattern string to parse [i+2] with | 1901 * [0] = pattern string to parse [i+2] with |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2415 /* | 2511 /* |
2416 Verify that a cloned formatter gives the same results | 2512 Verify that a cloned formatter gives the same results |
2417 and is useable after the original has been deleted. | 2513 and is useable after the original has been deleted. |
2418 */ | 2514 */ |
2419 // This is mainly important on Windows. | 2515 // This is mainly important on Windows. |
2420 UErrorCode status = U_ZERO_ERROR; | 2516 UErrorCode status = U_ZERO_ERROR; |
2421 Locale loc("en_US@compat=host"); | 2517 Locale loc("en_US@compat=host"); |
2422 UDate now = Calendar::getNow(); | 2518 UDate now = Calendar::getNow(); |
2423 DateFormat *full = DateFormat::createDateInstance(DateFormat::kFull, loc); | 2519 DateFormat *full = DateFormat::createDateInstance(DateFormat::kFull, loc); |
2424 if (full == NULL) { | 2520 if (full == NULL) { |
2425 dataerrln("FAIL: Can't create Relative date instance"); | 2521 dataerrln("FAIL: Can't create host date instance"); |
2426 return; | 2522 return; |
2427 } | 2523 } |
2428 UnicodeString result1; | 2524 UnicodeString result1; |
2429 full->format(now, result1, status); | 2525 full->format(now, result1, status); |
2430 Format *fullClone = full->clone(); | 2526 Format *fullClone = full->clone(); |
2431 delete full; | 2527 delete full; |
2432 full = NULL; | 2528 full = NULL; |
2433 | 2529 |
2434 UnicodeString result2; | 2530 UnicodeString result2; |
2435 fullClone->format(now, result2, status); | 2531 fullClone->format(now, result2, status); |
2436 ASSERT_OK(status); | 2532 ASSERT_OK(status); |
2437 if (result1 != result2) { | 2533 if (result1 != result2) { |
2438 errln("FAIL: Clone returned different result from non-clone."); | 2534 errln("FAIL: Clone returned different result from non-clone."); |
2439 } | 2535 } |
2440 delete fullClone; | 2536 delete fullClone; |
2441 } | 2537 } |
2442 | 2538 |
| 2539 void DateFormatTest::TestHebrewClone(void) |
| 2540 { |
| 2541 /* |
| 2542 Verify that a cloned formatter gives the same results |
| 2543 and is useable after the original has been deleted. |
| 2544 */ |
| 2545 UErrorCode status = U_ZERO_ERROR; |
| 2546 Locale loc("he@calendar=hebrew"); |
| 2547 UDate now = Calendar::getNow(); |
| 2548 LocalPointer<DateFormat> fmt( |
| 2549 DateFormat::createDateInstance(DateFormat::kLong, loc)); |
| 2550 if (fmt.isNull()) { |
| 2551 dataerrln("FAIL: Can't create Hebrew date instance"); |
| 2552 return; |
| 2553 } |
| 2554 UnicodeString result1; |
| 2555 fmt->format(now, result1, status); |
| 2556 LocalPointer<Format> fmtClone(fmt->clone()); |
| 2557 |
| 2558 // free fmt to be sure that fmtClone is independent of fmt. |
| 2559 fmt.adoptInstead(NULL); |
| 2560 |
| 2561 UnicodeString result2; |
| 2562 fmtClone->format(now, result2, status); |
| 2563 ASSERT_OK(status); |
| 2564 if (result1 != result2) { |
| 2565 errln("FAIL: Clone returned different result from non-clone."); |
| 2566 } |
| 2567 } |
| 2568 |
| 2569 static UBool getActualAndValidLocales( |
| 2570 const Format &fmt, Locale &valid, Locale &actual) { |
| 2571 const SimpleDateFormat* dat = dynamic_cast<const SimpleDateFormat*>(&fmt); |
| 2572 if (dat == NULL) { |
| 2573 return FALSE; |
| 2574 } |
| 2575 const DateFormatSymbols *sym = dat->getDateFormatSymbols(); |
| 2576 if (sym == NULL) { |
| 2577 return FALSE; |
| 2578 } |
| 2579 UErrorCode status = U_ZERO_ERROR; |
| 2580 valid = sym->getLocale(ULOC_VALID_LOCALE, status); |
| 2581 actual = sym->getLocale(ULOC_ACTUAL_LOCALE, status); |
| 2582 return U_SUCCESS(status); |
| 2583 } |
| 2584 |
| 2585 void DateFormatTest::TestDateFormatSymbolsClone(void) |
| 2586 { |
| 2587 /* |
| 2588 Verify that a cloned formatter gives the same results |
| 2589 and is useable after the original has been deleted. |
| 2590 */ |
| 2591 Locale loc("de_CH_LUCERNE"); |
| 2592 LocalPointer<DateFormat> fmt( |
| 2593 DateFormat::createDateInstance(DateFormat::kDefault, loc)); |
| 2594 Locale valid1; |
| 2595 Locale actual1; |
| 2596 if (!getActualAndValidLocales(*fmt, valid1, actual1)) { |
| 2597 dataerrln("FAIL: Could not fetch valid + actual locales"); |
| 2598 return; |
| 2599 } |
| 2600 LocalPointer<Format> fmtClone(fmt->clone()); |
| 2601 |
| 2602 // Free fmt to be sure that fmtClone is really independent of fmt. |
| 2603 fmt.adoptInstead(NULL); |
| 2604 Locale valid2; |
| 2605 Locale actual2; |
| 2606 if (!getActualAndValidLocales(*fmtClone, valid2, actual2)) { |
| 2607 errln("FAIL: Could not fetch valid + actual locales"); |
| 2608 return; |
| 2609 } |
| 2610 if (valid1 != valid2 || actual1 != actual2) { |
| 2611 errln("Date format symbol locales of clone don't match original"); |
| 2612 } |
| 2613 } |
| 2614 |
2443 void DateFormatTest::TestTimeZoneDisplayName() | 2615 void DateFormatTest::TestTimeZoneDisplayName() |
2444 { | 2616 { |
2445 // This test data was ported from ICU4J. Don't know why the 6th column in t
here because it's not being | 2617 // This test data was ported from ICU4J. Don't know why the 6th column in t
here because it's not being |
2446 // used currently. | 2618 // used currently. |
2447 const char *fallbackTests[][6] = { | 2619 const char *fallbackTests[][6] = { |
2448 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "Z", "-0800", "-8
:00" }, | 2620 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "Z", "-0800", "-8
:00" }, |
2449 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "ZZZZ", "GMT-08:0
0", "-8:00" }, | 2621 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "ZZZZ", "GMT-08:0
0", "-8:00" }, |
2450 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "ZZZZZ", "-08:00"
, "-8:00" }, | 2622 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "ZZZZZ", "-08:00"
, "-8:00" }, |
2451 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "z", "PST", "Amer
ica/Los_Angeles" }, | 2623 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "z", "PST", "Amer
ica/Los_Angeles" }, |
2452 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "zzzz", "Pacific
Standard Time", "America/Los_Angeles" }, | 2624 { "en", "America/Los_Angeles", "2004-01-15T00:00:00Z", "zzzz", "Pacific
Standard Time", "America/Los_Angeles" }, |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2955 { "bg", "Australia/Sydney", "2004-07-15T00:00:00Z", "vvvv", "\\u0410\\u0
432\\u0441\\u0442\\u0440\\u0430\\u043B\\u0438\\u044F \\u2013 \\u0438\\u0437\\u04
42\\u043E\\u0447\\u043D\\u043E \\u0432\\u0440\\u0435\\u043C\\u0435", "Australia/
Sydney" }, | 3127 { "bg", "Australia/Sydney", "2004-07-15T00:00:00Z", "vvvv", "\\u0410\\u0
432\\u0441\\u0442\\u0440\\u0430\\u043B\\u0438\\u044F \\u2013 \\u0438\\u0437\\u04
42\\u043E\\u0447\\u043D\\u043E \\u0432\\u0440\\u0435\\u043C\\u0435", "Australia/
Sydney" }, |
2956 | 3128 |
2957 { "bg", "Europe/London", "2004-01-15T00:00:00Z", "Z", "+0000", "+0:00" }
, | 3129 { "bg", "Europe/London", "2004-01-15T00:00:00Z", "Z", "+0000", "+0:00" }
, |
2958 { "bg", "Europe/London", "2004-01-15T00:00:00Z", "ZZZZ", "\\u0413\\u0440
\\u0438\\u043D\\u0443\\u0438\\u0447", "+0:00" }, | 3130 { "bg", "Europe/London", "2004-01-15T00:00:00Z", "ZZZZ", "\\u0413\\u0440
\\u0438\\u043D\\u0443\\u0438\\u0447", "+0:00" }, |
2959 { "bg", "Europe/London", "2004-01-15T00:00:00Z", "z", "\\u0413\\u0440\\u
0438\\u043D\\u0443\\u0438\\u0447", "+0:00" }, | 3131 { "bg", "Europe/London", "2004-01-15T00:00:00Z", "z", "\\u0413\\u0440\\u
0438\\u043D\\u0443\\u0438\\u0447", "+0:00" }, |
2960 { "bg", "Europe/London", "2004-01-15T00:00:00Z", "zzzz", "\\u0421\\u0440
\\u0435\\u0434\\u043d\\u043e \\u0433\\u0440\\u0438\\u043d\\u0443\\u0438\\u0447\\
u043a\\u043e \\u0432\\u0440\\u0435\\u043c\\u0435", "+0:00" }, | 3132 { "bg", "Europe/London", "2004-01-15T00:00:00Z", "zzzz", "\\u0421\\u0440
\\u0435\\u0434\\u043d\\u043e \\u0433\\u0440\\u0438\\u043d\\u0443\\u0438\\u0447\\
u043a\\u043e \\u0432\\u0440\\u0435\\u043c\\u0435", "+0:00" }, |
2961 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "Z", "+0100", "+1:00" }
, | 3133 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "Z", "+0100", "+1:00" }
, |
2962 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "ZZZZ", "\\u0413\\u0440
\\u0438\\u043D\\u0443\\u0438\\u0447+01:00", "+1:00" }, | 3134 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "ZZZZ", "\\u0413\\u0440
\\u0438\\u043D\\u0443\\u0438\\u0447+01:00", "+1:00" }, |
2963 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "z", "\\u0413\\u0440\\u
0438\\u043D\\u0443\\u0438\\u0447+1", "+1:00" }, | 3135 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "z", "\\u0413\\u0440\\u
0438\\u043D\\u0443\\u0438\\u0447+1", "+1:00" }, |
2964 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "zzzz", "\\u0411\\u0440
\\u0438\\u0442\\u0430\\u043d\\u0441\\u043a\\u043e \\u043b\\u044f\\u0442\\u043d\\
u043e \\u0447\\u0430\\u0441\\u043e\\u0432\\u043e \\u0432\\u0440\\u0435\\u043c\\u
0435", "+1:00" }, | 3136 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "zzzz", "\\u0411\\u0440
\\u0438\\u0442\\u0430\\u043d\\u0441\\u043a\\u043e \\u043b\\u044f\\u0442\\u043d\\
u043e \\u0447\\u0430\\u0441\\u043e\\u0432\\u043e \\u0432\\u0440\\u0435\\u043c\\u
0435", "+1:00" }, |
2965 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "v", "\\u0412\\u0435\\u
043b\\u0438\\u043a\\u043e\\u0431\\u0440\\u0438\\u0442\\u0430\\u043d\\u0438\\u044
f", "Europe/London" }, | 3137 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "v", "\\u041E\\u0431\\u
0435\\u0434\\u0438\\u043D\\u0435\\u043D\\u043E\\u0442\\u043E \\u043A\\u0440\\u04
30\\u043B\\u0441\\u0442\\u0432\\u043E", "Europe/London" }, |
2966 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "vvvv", "\\u0412\\u0435
\\u043b\\u0438\\u043a\\u043e\\u0431\\u0440\\u0438\\u0442\\u0430\\u043d\\u0438\\u
044f", "Europe/London" }, | 3138 { "bg", "Europe/London", "2004-07-15T00:00:00Z", "vvvv", "\\u041E\\u0431
\\u0435\\u0434\\u0438\\u043D\\u0435\\u043D\\u043E\\u0442\\u043E \\u043A\\u0440\\
u0430\\u043B\\u0441\\u0442\\u0432\\u043E", "Europe/London" }, |
2967 | 3139 |
2968 { "bg", "Etc/GMT+3", "2004-01-15T00:00:00Z", "Z", "-0300", "-3:00" }, | 3140 { "bg", "Etc/GMT+3", "2004-01-15T00:00:00Z", "Z", "-0300", "-3:00" }, |
2969 { "bg", "Etc/GMT+3", "2004-01-15T00:00:00Z", "ZZZZ", "\\u0413\\u0440\\u0
438\\u043D\\u0443\\u0438\\u0447-03:00", "-3:00" }, | 3141 { "bg", "Etc/GMT+3", "2004-01-15T00:00:00Z", "ZZZZ", "\\u0413\\u0440\\u0
438\\u043D\\u0443\\u0438\\u0447-03:00", "-3:00" }, |
2970 { "bg", "Etc/GMT+3", "2004-01-15T00:00:00Z", "z", "\\u0413\\u0440\\u0438
\\u043D\\u0443\\u0438\\u0447-3", "-3:00" }, | 3142 { "bg", "Etc/GMT+3", "2004-01-15T00:00:00Z", "z", "\\u0413\\u0440\\u0438
\\u043D\\u0443\\u0438\\u0447-3", "-3:00" }, |
2971 { "bg", "Etc/GMT+3", "2004-01-15T00:00:00Z", "zzzz", "\\u0413\\u0440\\u0
438\\u043D\\u0443\\u0438\\u0447-03:00", "-3:00" }, | 3143 { "bg", "Etc/GMT+3", "2004-01-15T00:00:00Z", "zzzz", "\\u0413\\u0440\\u0
438\\u043D\\u0443\\u0438\\u0447-03:00", "-3:00" }, |
2972 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "Z", "-0300", "-3:00" }, | 3144 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "Z", "-0300", "-3:00" }, |
2973 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "ZZZZ", "\\u0413\\u0440\\u0
438\\u043D\\u0443\\u0438\\u0447-03:00", "-3:00" }, | 3145 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "ZZZZ", "\\u0413\\u0440\\u0
438\\u043D\\u0443\\u0438\\u0447-03:00", "-3:00" }, |
2974 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "z", "\\u0413\\u0440\\u0438
\\u043D\\u0443\\u0438\\u0447-3", "-3:00" }, | 3146 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "z", "\\u0413\\u0440\\u0438
\\u043D\\u0443\\u0438\\u0447-3", "-3:00" }, |
2975 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "zzzz", "\\u0413\\u0440\\u0
438\\u043D\\u0443\\u0438\\u0447-03:00", "-3:00" }, | 3147 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "zzzz", "\\u0413\\u0440\\u0
438\\u043D\\u0443\\u0438\\u0447-03:00", "-3:00" }, |
2976 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "v", "\\u0413\\u0440\\u0438
\\u043D\\u0443\\u0438\\u0447-3", "-3:00" }, | 3148 { "bg", "Etc/GMT+3", "2004-07-15T00:00:00Z", "v", "\\u0413\\u0440\\u0438
\\u043D\\u0443\\u0438\\u0447-3", "-3:00" }, |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3744 } | 3916 } |
3745 void DateFormatTest::TestFormalChineseDate() { | 3917 void DateFormatTest::TestFormalChineseDate() { |
3746 | 3918 |
3747 UErrorCode status = U_ZERO_ERROR; | 3919 UErrorCode status = U_ZERO_ERROR; |
3748 UnicodeString pattern ("y\\u5e74M\\u6708d\\u65e5", -1, US_INV ); | 3920 UnicodeString pattern ("y\\u5e74M\\u6708d\\u65e5", -1, US_INV ); |
3749 pattern = pattern.unescape(); | 3921 pattern = pattern.unescape(); |
3750 UnicodeString override ("y=hanidec;M=hans;d=hans", -1, US_INV ); | 3922 UnicodeString override ("y=hanidec;M=hans;d=hans", -1, US_INV ); |
3751 | 3923 |
3752 // create formatter | 3924 // create formatter |
3753 SimpleDateFormat *sdf = new SimpleDateFormat(pattern,override,Locale::getChi
na(),status); | 3925 SimpleDateFormat *sdf = new SimpleDateFormat(pattern,override,Locale::getChi
na(),status); |
3754 failure(status, "new SimpleDateFormat with override", TRUE); | 3926 if (failure(status, "new SimpleDateFormat with override", TRUE)) { |
| 3927 return; |
| 3928 } |
3755 | 3929 |
3756 UDate thedate = date(2009-1900, UCAL_JULY, 28); | 3930 UDate thedate = date(2009-1900, UCAL_JULY, 28); |
3757 FieldPosition pos(0); | 3931 FieldPosition pos(0); |
3758 UnicodeString result; | 3932 UnicodeString result; |
3759 sdf->format(thedate,result,pos); | 3933 sdf->format(thedate,result,pos); |
3760 | 3934 |
3761 UnicodeString expected = "\\u4e8c\\u3007\\u3007\\u4e5d\\u5e74\\u4e03\\u6708\
\u4e8c\\u5341\\u516b\\u65e5"; | 3935 UnicodeString expected = "\\u4e8c\\u3007\\u3007\\u4e5d\\u5e74\\u4e03\\u6708\
\u4e8c\\u5341\\u516b\\u65e5"; |
3762 expected = expected.unescape(); | 3936 expected = expected.unescape(); |
3763 if (result != expected) { | 3937 if (result != expected) { |
3764 dataerrln((UnicodeString)"FAIL: -> " + result + " expected -> " + expect
ed); | 3938 dataerrln((UnicodeString)"FAIL: -> " + result + " expected -> " + expect
ed); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3869 { | 4043 { |
3870 const ChineseCalTestDate dates[NUM_TEST_DATES] = { | 4044 const ChineseCalTestDate dates[NUM_TEST_DATES] = { |
3871 // era yr mo lp da | 4045 // era yr mo lp da |
3872 { 78, 29, 4, 0, 2 }, // (in chinese era 78) gregorian 2012-4-22 | 4046 { 78, 29, 4, 0, 2 }, // (in chinese era 78) gregorian 2012-4-22 |
3873 { 78, 29, 4, 1, 2 }, // (in chinese era 78) gregorian 2012-5-22 | 4047 { 78, 29, 4, 1, 2 }, // (in chinese era 78) gregorian 2012-5-22 |
3874 { 78, 29, 5, 0, 2 }, // (in chinese era 78) gregorian 2012-6-20 | 4048 { 78, 29, 5, 0, 2 }, // (in chinese era 78) gregorian 2012-6-20 |
3875 }; | 4049 }; |
3876 | 4050 |
3877 const MonthPatternItem items[] = { | 4051 const MonthPatternItem items[] = { |
3878 // locale date style; expected formats for
the 3 dates above | 4052 // locale date style; expected formats for
the 3 dates above |
3879 { "root@calendar=chinese", DateFormat::kLong, { UnicodeString("ren-c
hen M04 2"), UnicodeString("ren-chen M04bis 2"), UnicodeString("ren-chen M05 2
") } }, | 4053 { "root@calendar=chinese", DateFormat::kLong, { UnicodeString("2012(
ren-chen) M04 2"), UnicodeString("2012(ren-chen) M04bis 2"), UnicodeString("20
12(ren-chen) M05 2") } }, |
3880 { "root@calendar=chinese", DateFormat::kShort, { UnicodeString("29-04
-02"), UnicodeString("29-04bis-02"), UnicodeString("29-05-02") }
}, | 4054 { "root@calendar=chinese", DateFormat::kShort, { UnicodeString("2012-
04-02"), UnicodeString("2012-04bis-02"), UnicodeString("2012-05-02")
} }, |
3881 { "root@calendar=chinese", -1, { UnicodeString("29-4-
2"), UnicodeString("29-4bis-2"), UnicodeString("29-5-2") } }, | 4055 { "root@calendar=chinese", -1, { UnicodeString("29-4-
2"), UnicodeString("29-4bis-2"), UnicodeString("29-5-2") } }, |
3882 { "root@calendar=chinese", -2, { UnicodeString("78x29
-4-2"), UnicodeString("78x29-4bis-2"), UnicodeString("78x29-5-2") }
}, | 4056 { "root@calendar=chinese", -2, { UnicodeString("78x29
-4-2"), UnicodeString("78x29-4bis-2"), UnicodeString("78x29-5-2") }
}, |
3883 { "root@calendar=chinese", -3, { UnicodeString("ren-c
hen-4-2"), UnicodeString("ren-chen-4bis-2"), UnicodeString("ren-chen-5-2"
) } }, | 4057 { "root@calendar=chinese", -3, { UnicodeString("ren-c
hen-4-2"), UnicodeString("ren-chen-4bis-2"), UnicodeString("ren-chen-5-2"
) } }, |
3884 { "root@calendar=chinese", -4, { UnicodeString("ren-c
hen M04 2"), UnicodeString("ren-chen M04bis 2"), UnicodeString("ren-chen M05
2") } }, | 4058 { "root@calendar=chinese", -4, { UnicodeString("ren-c
hen M04 2"), UnicodeString("ren-chen M04bis 2"), UnicodeString("ren-chen M05
2") } }, |
3885 { "en@calendar=gregorian", -3, { UnicodeString("2012-
4-22"), UnicodeString("2012-5-22"), UnicodeString("2012-6-20") }
}, | 4059 { "en@calendar=gregorian", -3, { UnicodeString("2012-
4-22"), UnicodeString("2012-5-22"), UnicodeString("2012-6-20") }
}, |
3886 { "en@calendar=chinese", DateFormat::kLong, { UnicodeString("Month
4 2, ren-chen"), UnicodeString("Month4bis 2, ren-chen"), UnicodeString("Month5 2
, ren-chen") } }, | 4060 { "en@calendar=chinese", DateFormat::kLong, { UnicodeString("Month
4 2, 2012(ren-chen)"), UnicodeString("Month4bis 2, 2012(ren-chen)"), UnicodeStri
ng("Month5 2, 2012(ren-chen)") } }, |
3887 { "en@calendar=chinese", DateFormat::kShort, { UnicodeString("4/2/2
9"), UnicodeString("4bis/2/29"), UnicodeString("5/2/29") } }, | 4061 { "en@calendar=chinese", DateFormat::kShort, { UnicodeString("4/2/2
012"), UnicodeString("4bis/2/2012"), UnicodeString("5/2/2012") }
}, |
3888 { "zh@calendar=chinese", DateFormat::kLong, { CharsToUnicodeString
("\\u58EC\\u8FB0\\u5E74\\u56DB\\u6708\\u521D\\u4E8C"), | 4062 { "zh@calendar=chinese", DateFormat::kLong, { CharsToUnicodeString
("2012\\u58EC\\u8FB0\\u5E74\\u56DB\\u6708\\u521D\\u4E8C"), |
3889 CharsToUnicodeString
("\\u58EC\\u8FB0\\u5E74\\u95F0\\u56DB\\u6708\\u521D\\u4E8C"), | 4063 CharsToUnicodeString
("2012\\u58EC\\u8FB0\\u5E74\\u95F0\\u56DB\\u6708\\u521D\\u4E8C"), |
3890 CharsToUnicodeString
("\\u58EC\\u8FB0\\u5E74\\u4E94\\u6708\\u521D\\u4E8C") } }, | 4064 CharsToUnicodeString
("2012\\u58EC\\u8FB0\\u5E74\\u4E94\\u6708\\u521D\\u4E8C") } }, |
3891 { "zh@calendar=chinese", DateFormat::kShort, { CharsToUnicodeString
("\\u58EC\\u8FB0-4-2"), | 4065 { "zh@calendar=chinese", DateFormat::kShort, { CharsToUnicodeString
("2012-4-2"), |
3892 CharsToUnicodeString
("\\u58EC\\u8FB0-\\u95F04-2"), | 4066 CharsToUnicodeString
("2012-\\u95F04-2"), |
3893 CharsToUnicodeString
("\\u58EC\\u8FB0-5-2") } }, | 4067 CharsToUnicodeString
("2012-5-2") } }, |
3894 { "zh@calendar=chinese", -3, { CharsToUnicodeString
("\\u58EC\\u8FB0-4-2"), | 4068 { "zh@calendar=chinese", -3, { CharsToUnicodeString
("\\u58EC\\u8FB0-4-2"), |
3895 CharsToUnicodeString
("\\u58EC\\u8FB0-\\u95F04-2"), | 4069 CharsToUnicodeString
("\\u58EC\\u8FB0-\\u95F04-2"), |
3896 CharsToUnicodeString
("\\u58EC\\u8FB0-5-2") } }, | 4070 CharsToUnicodeString
("\\u58EC\\u8FB0-5-2") } }, |
3897 { "zh@calendar=chinese", -4, { CharsToUnicodeString
("\\u58EC\\u8FB0 \\u56DB\\u6708 2"), | 4071 { "zh@calendar=chinese", -4, { CharsToUnicodeString
("\\u58EC\\u8FB0 \\u56DB\\u6708 2"), |
3898 CharsToUnicodeString
("\\u58EC\\u8FB0 \\u95F0\\u56DB\\u6708 2"), | 4072 CharsToUnicodeString
("\\u58EC\\u8FB0 \\u95F0\\u56DB\\u6708 2"), |
3899 CharsToUnicodeString
("\\u58EC\\u8FB0 \\u4E94\\u6708 2") } }, | 4073 CharsToUnicodeString
("\\u58EC\\u8FB0 \\u4E94\\u6708 2") } }, |
3900 { "zh_Hant@calendar=chinese", DateFormat::kLong, { CharsToUnicodeString
("\\u58EC\\u8FB0\\u5E74\\u56DB\\u6708\\u521D\\u4E8C"), | 4074 { "zh_Hant@calendar=chinese", DateFormat::kLong, { CharsToUnicodeString
("2012\\u58EC\\u8FB0\\u5E74\\u56DB\\u6708\\u521D\\u4E8C"), |
3901 CharsToUnicodeString
("\\u58EC\\u8FB0\\u5E74\\u958F\\u56DB\\u6708\\u521D\\u4E8C"), | 4075 CharsToUnicodeString
("2012\\u58EC\\u8FB0\\u5E74\\u958F\\u56DB\\u6708\\u521D\\u4E8C"), |
3902 CharsToUnicodeString
("\\u58EC\\u8FB0\\u5E74\\u4E94\\u6708\\u521D\\u4E8C") } }, | 4076 CharsToUnicodeString
("2012\\u58EC\\u8FB0\\u5E74\\u4E94\\u6708\\u521D\\u4E8C") } }, |
3903 { "zh_Hant@calendar=chinese", DateFormat::kShort, { CharsToUnicodeString
("\\u58EC\\u8FB0/4/2"), | 4077 { "zh_Hant@calendar=chinese", DateFormat::kShort, { CharsToUnicodeString
("2012/4/2"), |
3904 CharsToUnicodeString
("\\u58EC\\u8FB0/\\u958F4/2"), | 4078 CharsToUnicodeString
("2012/\\u958F4/2"), |
3905 CharsToUnicodeString
("\\u58EC\\u8FB0/5/2") } }, | 4079 CharsToUnicodeString
("2012/5/2") } }, |
3906 { "fr@calendar=chinese", DateFormat::kLong, { CharsToUnicodeString
("2 s\\u00ECyu\\u00E8 ren-chen"), | 4080 { "fr@calendar=chinese", DateFormat::kLong, { CharsToUnicodeString
("2 s\\u00ECyu\\u00E8 ren-chen"), |
3907 CharsToUnicodeString
("2 s\\u00ECyu\\u00E8bis ren-chen"), | 4081 CharsToUnicodeString
("2 s\\u00ECyu\\u00E8bis ren-chen"), |
3908 CharsToUnicodeString
("2 w\\u01D4yu\\u00E8 ren-chen") } }, | 4082 CharsToUnicodeString
("2 w\\u01D4yu\\u00E8 ren-chen") } }, |
3909 { "fr@calendar=chinese", DateFormat::kShort, { UnicodeString("2/4/2
9"), UnicodeString("2/4bis/29"), UnicodeString("2/5/29") } }, | 4083 { "fr@calendar=chinese", DateFormat::kShort, { UnicodeString("2/4/2
9"), UnicodeString("2/4bis/29"), UnicodeString("2/5/29") } }, |
3910 { "en@calendar=dangi", DateFormat::kLong, { UnicodeString("Month
3bis 2, 29"), UnicodeString("Month4 2, 29"), UnicodeString("Month5 1, 29"
) } }, | 4084 { "en@calendar=dangi", DateFormat::kLong, { UnicodeString("Month
3bis 2, 2012(29)"), UnicodeString("Month4 2, 2012(29)"), UnicodeString("M
onth5 1, 2012(29)") } }, |
3911 { "en@calendar=dangi", DateFormat::kShort, { UnicodeString("3bis/
2/29"), UnicodeString("4/2/29"), UnicodeString("5/1/29") } }, | 4085 { "en@calendar=dangi", DateFormat::kShort, { UnicodeString("3bis/
2/2012"), UnicodeString("4/2/2012"), UnicodeString("5/1/2012") }
}, |
3912 { "en@calendar=dangi", -2, { UnicodeString("78x29
-3bis-2"), UnicodeString("78x29-4-2"), UnicodeString("78x29-5-1") }
}, | 4086 { "en@calendar=dangi", -2, { UnicodeString("78x29
-3bis-2"), UnicodeString("78x29-4-2"), UnicodeString("78x29-5-1") }
}, |
3913 { "ko@calendar=dangi", DateFormat::kLong, { CharsToUnicodeString
("\\uC784\\uC9C4\\uB144 \\uC7243\\uC6D4 2\\uC77C"), | 4087 { "ko@calendar=dangi", DateFormat::kLong, { CharsToUnicodeString
("\\uC784\\uC9C4\\uB144 \\uC7243\\uC6D4 2\\uC77C"), |
3914 CharsToUnicodeString
("\\uC784\\uC9C4\\uB144 4\\uC6D4 2\\uC77C"), | 4088 CharsToUnicodeString
("\\uC784\\uC9C4\\uB144 4\\uC6D4 2\\uC77C"), |
3915 CharsToUnicodeString
("\\uC784\\uC9C4\\uB144 5\\uC6D4 1\\uC77C") } }, | 4089 CharsToUnicodeString
("\\uC784\\uC9C4\\uB144 5\\uC6D4 1\\uC77C") } }, |
3916 { "ko@calendar=dangi", DateFormat::kShort, { CharsToUnicodeString
("29. \\uC7243. 2."), | 4090 { "ko@calendar=dangi", DateFormat::kShort, { CharsToUnicodeString
("29. \\uC7243. 2."), |
3917 CharsToUnicodeString
("29. 4. 2."), | 4091 CharsToUnicodeString
("29. 4. 2."), |
3918 CharsToUnicodeString
("29. 5. 1.") } }, | 4092 CharsToUnicodeString
("29. 5. 1.") } }, |
3919 // terminator | 4093 // terminator |
3920 { NULL, 0, { UnicodeString(""), U
nicodeString(""), UnicodeString("") } } | 4094 { NULL, 0, { UnicodeString(""), U
nicodeString(""), UnicodeString("") } } |
3921 }; | 4095 }; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4269 return; | 4443 return; |
4270 } | 4444 } |
4271 cal->setTime(july022008, status); | 4445 cal->setTime(july022008, status); |
4272 const TestDateFormatLeniencyItem * itemPtr; | 4446 const TestDateFormatLeniencyItem * itemPtr; |
4273 LocalPointer<SimpleDateFormat> sdmft; | 4447 LocalPointer<SimpleDateFormat> sdmft; |
4274 for (itemPtr = items; itemPtr->locale != NULL; itemPtr++ ) { | 4448 for (itemPtr = items; itemPtr->locale != NULL; itemPtr++ ) { |
4275 | 4449 |
4276 Locale locale = Locale::createFromName(itemPtr->locale); | 4450 Locale locale = Locale::createFromName(itemPtr->locale); |
4277 status = U_ZERO_ERROR; | 4451 status = U_ZERO_ERROR; |
4278 ParsePosition pos(0); | 4452 ParsePosition pos(0); |
4279 sdmft.adoptInstead(new SimpleDateFormat(itemPtr->pattern, locale, status)
); | 4453 sdmft.adoptInsteadAndCheckErrorCode(new SimpleDateFormat(itemPtr->pattern
, locale, status), status); |
4280 if (U_FAILURE(status)) { | 4454 if (U_FAILURE(status)) { |
4281 dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(statu
s)); | 4455 dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(statu
s)); |
4282 continue; | 4456 continue; |
4283 } | 4457 } |
4284 sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->leniency
, status). | 4458 sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->leniency
, status). |
4285 setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->leniency, s
tatus). | 4459 setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->leniency, s
tatus). |
4286 setBooleanAttribute(UDAT_PARSE_PARTIAL_MATCH, itemPtr->leniency, s
tatus); | 4460 setBooleanAttribute(UDAT_PARSE_PARTIAL_LITERAL_MATCH, itemPtr->len
iency, status); |
4287 UDate d = sdmft->parse(itemPtr->parseString, pos); | 4461 UDate d = sdmft->parse(itemPtr->parseString, pos); |
4288 | 4462 |
4289 if(itemPtr->expectedResult.length() == 0) { | 4463 if(itemPtr->expectedResult.length() == 0) { |
4290 if(pos.getErrorIndex() != -1) { | 4464 if(pos.getErrorIndex() != -1) { |
4291 continue; | 4465 continue; |
4292 } else { | 4466 } else { |
4293 errln("error: unexpected parse success - " + itemPtr->parseStrin
g + | 4467 errln("error: unexpected parse success - " + itemPtr->parseStrin
g + |
4294 " - pattern " + itemPtr->pattern + | 4468 " - pattern " + itemPtr->pattern + |
4295 " - error index " + pos.getErrorIndex() + | 4469 " - error index " + pos.getErrorIndex() + |
4296 " - leniency " + itemPtr->leniency); | 4470 " - leniency " + itemPtr->leniency); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4416 DateFormat *fmt = dateFormat.getAlias(); | 4590 DateFormat *fmt = dateFormat.getAlias(); |
4417 if (fmt == NULL) { | 4591 if (fmt == NULL) { |
4418 dataerrln("Failed calling dateFormat.getAlias()"); | 4592 dataerrln("Failed calling dateFormat.getAlias()"); |
4419 return; | 4593 return; |
4420 } | 4594 } |
4421 | 4595 |
4422 assertTrue("isLenient default", fmt->isLenient()); | 4596 assertTrue("isLenient default", fmt->isLenient()); |
4423 assertTrue("isCalendarLenient default", fmt->isCalendarLenient()); | 4597 assertTrue("isCalendarLenient default", fmt->isCalendarLenient()); |
4424 assertTrue("ALLOW_WHITESPACE default", fmt->getBooleanAttribute(UDAT_PARSE_A
LLOW_WHITESPACE, status)); | 4598 assertTrue("ALLOW_WHITESPACE default", fmt->getBooleanAttribute(UDAT_PARSE_A
LLOW_WHITESPACE, status)); |
4425 assertTrue("ALLOW_NUMERIC default", fmt->getBooleanAttribute(UDAT_PARSE_ALLO
W_NUMERIC, status)); | 4599 assertTrue("ALLOW_NUMERIC default", fmt->getBooleanAttribute(UDAT_PARSE_ALLO
W_NUMERIC, status)); |
4426 assertTrue("PARTIAL_MATCH default", fmt->getBooleanAttribute(UDAT_PARSE_PART
IAL_MATCH, status)); | 4600 assertTrue("PARTIAL_MATCH default", fmt->getBooleanAttribute(UDAT_PARSE_PART
IAL_LITERAL_MATCH, status)); |
4427 assertTrue("MULTIPLE_PATTERNS default", fmt->getBooleanAttribute(UDAT_PARSE_
MULTIPLE_PATTERNS_FOR_MATCH, status)); | 4601 assertTrue("MULTIPLE_PATTERNS default", fmt->getBooleanAttribute(UDAT_PARSE_
MULTIPLE_PATTERNS_FOR_MATCH, status)); |
4428 | 4602 |
4429 // Set calendar to strict | 4603 // Set calendar to strict |
4430 fmt->setCalendarLenient(FALSE); | 4604 fmt->setCalendarLenient(FALSE); |
4431 | 4605 |
4432 assertFalse("isLeninent after setCalendarLenient(FALSE)", fmt->isLenient()); | 4606 assertFalse("isLeninent after setCalendarLenient(FALSE)", fmt->isLenient()); |
4433 assertFalse("isCalendarLenient after setCalendarLenient(FALSE)", fmt->isCale
ndarLenient()); | 4607 assertFalse("isCalendarLenient after setCalendarLenient(FALSE)", fmt->isCale
ndarLenient()); |
4434 assertTrue("ALLOW_WHITESPACE after setCalendarLenient(FALSE)", fmt->getBoole
anAttribute(UDAT_PARSE_ALLOW_WHITESPACE, status)); | 4608 assertTrue("ALLOW_WHITESPACE after setCalendarLenient(FALSE)", fmt->getBoole
anAttribute(UDAT_PARSE_ALLOW_WHITESPACE, status)); |
4435 assertTrue("ALLOW_NUMERIC after setCalendarLenient(FALSE)", fmt->getBoolean
Attribute(UDAT_PARSE_ALLOW_NUMERIC, status)); | 4609 assertTrue("ALLOW_NUMERIC after setCalendarLenient(FALSE)", fmt->getBoolean
Attribute(UDAT_PARSE_ALLOW_NUMERIC, status)); |
4436 | 4610 |
4437 // Set to strict | 4611 // Set to strict |
4438 fmt->setLenient(FALSE); | 4612 fmt->setLenient(FALSE); |
4439 | 4613 |
4440 assertFalse("isLeninent after setLenient(FALSE)", fmt->isLenient()); | 4614 assertFalse("isLeninent after setLenient(FALSE)", fmt->isLenient()); |
4441 assertFalse("isCalendarLenient after setLenient(FALSE)", fmt->isCalendarLeni
ent()); | 4615 assertFalse("isCalendarLenient after setLenient(FALSE)", fmt->isCalendarLeni
ent()); |
4442 assertFalse("ALLOW_WHITESPACE after setLenient(FALSE)", fmt->getBooleanAttri
bute(UDAT_PARSE_ALLOW_WHITESPACE, status)); | 4616 assertFalse("ALLOW_WHITESPACE after setLenient(FALSE)", fmt->getBooleanAttri
bute(UDAT_PARSE_ALLOW_WHITESPACE, status)); |
4443 assertFalse("ALLOW_NUMERIC after setLenient(FALSE)", fmt->getBooleanAttribu
te(UDAT_PARSE_ALLOW_NUMERIC, status)); | 4617 assertFalse("ALLOW_NUMERIC after setLenient(FALSE)", fmt->getBooleanAttribu
te(UDAT_PARSE_ALLOW_NUMERIC, status)); |
4444 // These two boolean attributes are NOT affected according to the API specif
ication | 4618 // These two boolean attributes are NOT affected according to the API specif
ication |
4445 assertTrue("PARTIAL_MATCH after setLenient(FALSE)", fmt->getBooleanAttribute
(UDAT_PARSE_PARTIAL_MATCH, status)); | 4619 assertTrue("PARTIAL_MATCH after setLenient(FALSE)", fmt->getBooleanAttribute
(UDAT_PARSE_PARTIAL_LITERAL_MATCH, status)); |
4446 assertTrue("MULTIPLE_PATTERNS after setLenient(FALSE)", fmt->getBooleanAttri
bute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status)); | 4620 assertTrue("MULTIPLE_PATTERNS after setLenient(FALSE)", fmt->getBooleanAttri
bute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status)); |
4447 | 4621 |
4448 // Allow white space leniency | 4622 // Allow white space leniency |
4449 fmt->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, TRUE, status); | 4623 fmt->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, TRUE, status); |
4450 | 4624 |
4451 assertFalse("isLeninent after ALLOW_WHITESPACE/TRUE", fmt->isLenient()); | 4625 assertFalse("isLeninent after ALLOW_WHITESPACE/TRUE", fmt->isLenient()); |
4452 assertFalse("isCalendarLenient after ALLOW_WHITESPACE/TRUE", fmt->isCalendar
Lenient()); | 4626 assertFalse("isCalendarLenient after ALLOW_WHITESPACE/TRUE", fmt->isCalendar
Lenient()); |
4453 assertTrue("ALLOW_WHITESPACE after ALLOW_WHITESPACE/TRUE", fmt->getBooleanAt
tribute(UDAT_PARSE_ALLOW_WHITESPACE, status)); | 4627 assertTrue("ALLOW_WHITESPACE after ALLOW_WHITESPACE/TRUE", fmt->getBooleanAt
tribute(UDAT_PARSE_ALLOW_WHITESPACE, status)); |
4454 assertFalse("ALLOW_NUMERIC after ALLOW_WHITESPACE/TRUE", fmt->getBooleanAtt
ribute(UDAT_PARSE_ALLOW_NUMERIC, status)); | 4628 assertFalse("ALLOW_NUMERIC after ALLOW_WHITESPACE/TRUE", fmt->getBooleanAtt
ribute(UDAT_PARSE_ALLOW_NUMERIC, status)); |
4455 | 4629 |
4456 // Set to lenient | 4630 // Set to lenient |
4457 fmt->setLenient(TRUE); | 4631 fmt->setLenient(TRUE); |
4458 | 4632 |
4459 assertTrue("isLenient after setLenient(TRUE)", fmt->isLenient()); | 4633 assertTrue("isLenient after setLenient(TRUE)", fmt->isLenient()); |
4460 assertTrue("isCalendarLenient after setLenient(TRUE)", fmt->isCalendarLenien
t()); | 4634 assertTrue("isCalendarLenient after setLenient(TRUE)", fmt->isCalendarLenien
t()); |
4461 assertTrue("ALLOW_WHITESPACE after setLenient(TRUE)", fmt->getBooleanAttribu
te(UDAT_PARSE_ALLOW_WHITESPACE, status)); | 4635 assertTrue("ALLOW_WHITESPACE after setLenient(TRUE)", fmt->getBooleanAttribu
te(UDAT_PARSE_ALLOW_WHITESPACE, status)); |
4462 assertTrue("ALLOW_NUMERIC after setLenient(TRUE)", fmt->getBooleanAttribute(
UDAT_PARSE_ALLOW_NUMERIC, status)); | 4636 assertTrue("ALLOW_NUMERIC after setLenient(TRUE)", fmt->getBooleanAttribute(
UDAT_PARSE_ALLOW_NUMERIC, status)); |
4463 } | 4637 } |
4464 | 4638 |
4465 void DateFormatTest::TestNumberFormatOverride() { | 4639 void DateFormatTest::TestNumberFormatOverride() { |
4466 UErrorCode status = U_ZERO_ERROR; | 4640 UErrorCode status = U_ZERO_ERROR; |
4467 UnicodeString fields = (UnicodeString) "M"; | 4641 UnicodeString fields = (UnicodeString) "M"; |
4468 | 4642 |
4469 LocalPointer<SimpleDateFormat> fmt; | 4643 LocalPointer<SimpleDateFormat> fmt; |
4470 fmt.adoptInstead(new SimpleDateFormat((UnicodeString)"MM d", status)); | 4644 fmt.adoptInsteadAndCheckErrorCode(new SimpleDateFormat((UnicodeString)"MM d"
, status), status); |
4471 if (!assertSuccess("SimpleDateFormat with pattern MM d", status)) { | 4645 if (!assertSuccess("SimpleDateFormat with pattern MM d", status)) { |
4472 return; | 4646 return; |
4473 } | 4647 } |
4474 | 4648 |
4475 NumberFormat* check_nf = NumberFormat::createInstance(Locale("en_US"), statu
s); | |
4476 assertSuccess("NumberFormat en_US", status); | |
4477 | 4649 |
4478 // loop 100 times to test setter/getter | 4650 for(int i=0; i<3; i++){ |
4479 for(int i=0; i<100; i++){ | 4651 NumberFormat* check_nf = NumberFormat::createInstance(Locale("en_US"), s
tatus); |
| 4652 assertSuccess("NumberFormat en_US", status); |
4480 fmt->adoptNumberFormat(fields, check_nf, status); | 4653 fmt->adoptNumberFormat(fields, check_nf, status); |
4481 assertSuccess("adoptNumberFormat check_nf", status); | 4654 assertSuccess("adoptNumberFormat check_nf", status); |
4482 | 4655 |
4483 const NumberFormat* get_nf = fmt->getNumberFormatForField('M'); | 4656 const NumberFormat* get_nf = fmt->getNumberFormatForField('M'); |
4484 if (get_nf != check_nf) errln("FAIL: getter and setter do not work"); | 4657 if (get_nf != check_nf) errln("FAIL: getter and setter do not work"); |
4485 } | 4658 } |
| 4659 NumberFormat* check_nf = NumberFormat::createInstance(Locale("en_US"), statu
s); |
| 4660 assertSuccess("NumberFormat en_US", status); |
4486 fmt->adoptNumberFormat(check_nf); // make sure using the same NF will not cr
ash | 4661 fmt->adoptNumberFormat(check_nf); // make sure using the same NF will not cr
ash |
4487 | 4662 |
4488 const char * DATA [][2] = { | 4663 const char * DATA [][2] = { |
4489 { "", "\\u521D\\u516D \\u5341\\u4E94"}, | 4664 { "", "\\u521D\\u516D \\u5341\\u4E94"}, |
4490 { "M", "\\u521D\\u516D 15"}, | 4665 { "M", "\\u521D\\u516D 15"}, |
4491 { "Mo", "\\u521D\\u516D 15"}, | 4666 { "Mo", "\\u521D\\u516D 15"}, |
4492 { "Md", "\\u521D\\u516D \\u5341\\u4E94"}, | 4667 { "Md", "\\u521D\\u516D \\u5341\\u4E94"}, |
4493 { "MdMMd", "\\u521D\\u516D \\u5341\\u4E94"}, | 4668 { "MdMMd", "\\u521D\\u516D \\u5341\\u4E94"}, |
4494 { "mixed", "\\u521D\\u516D \\u5341\\u4E94"} | 4669 { "mixed", "\\u521D\\u516D \\u5341\\u4E94"} |
4495 }; | 4670 }; |
4496 | 4671 |
4497 UDate test_date = date(97, 6 - 1, 15); | 4672 UDate test_date = date(97, 6 - 1, 15); |
4498 | 4673 |
4499 for(int i=0; i < (int)(sizeof(DATA)/sizeof(DATA[0])); i++){ | 4674 for(int i=0; i < (int)(sizeof(DATA)/sizeof(DATA[0])); i++){ |
4500 fields = DATA[i][0]; | 4675 fields = DATA[i][0]; |
4501 | 4676 |
4502 LocalPointer<SimpleDateFormat> fmt; | 4677 LocalPointer<SimpleDateFormat> fmt; |
4503 fmt.adoptInstead(new SimpleDateFormat((UnicodeString)"MM d", status)); | 4678 fmt.adoptInsteadAndCheckErrorCode(new SimpleDateFormat((UnicodeString)"M
M d", status), status); |
4504 assertSuccess("SimpleDateFormat with pattern MM d", status); | 4679 assertSuccess("SimpleDateFormat with pattern MM d", status); |
4505 NumberFormat* overrideNF = NumberFormat::createInstance(Locale::createFr
omName("zh@numbers=hanidays"),status); | 4680 NumberFormat* overrideNF = NumberFormat::createInstance(Locale::createFr
omName("zh@numbers=hanidays"),status); |
4506 assertSuccess("NumberFormat zh@numbers=hanidays", status); | 4681 assertSuccess("NumberFormat zh@numbers=hanidays", status); |
4507 | 4682 |
4508 if (fields == (UnicodeString) "") { // use the one w/o fields | 4683 if (fields == (UnicodeString) "") { // use the one w/o fields |
4509 fmt->adoptNumberFormat(overrideNF); | 4684 fmt->adoptNumberFormat(overrideNF); |
4510 } else if (fields == (UnicodeString) "mixed") { // set 1 field at first
but then full override, both(M & d) should be override | 4685 } else if (fields == (UnicodeString) "mixed") { // set 1 field at first
but then full override, both(M & d) should be override |
4511 NumberFormat* singleOverrideNF = NumberFormat::createInstance(Locale
::createFromName("en@numbers=hebr"),status); | 4686 NumberFormat* singleOverrideNF = NumberFormat::createInstance(Locale
::createFromName("en@numbers=hebr"),status); |
4512 assertSuccess("NumberFormat en@numbers=hebr", status); | 4687 assertSuccess("NumberFormat en@numbers=hebr", status); |
4513 | 4688 |
(...skipping 16 matching lines...) Expand all Loading... |
4530 UnicodeString result; | 4705 UnicodeString result; |
4531 FieldPosition pos(0); | 4706 FieldPosition pos(0); |
4532 fmt->format(test_date,result, pos); | 4707 fmt->format(test_date,result, pos); |
4533 | 4708 |
4534 UnicodeString expected = ((UnicodeString)DATA[i][1]).unescape();; | 4709 UnicodeString expected = ((UnicodeString)DATA[i][1]).unescape();; |
4535 | 4710 |
4536 if (result != expected) | 4711 if (result != expected) |
4537 errln("FAIL: Expected " + expected + " get: " + result); | 4712 errln("FAIL: Expected " + expected + " get: " + result); |
4538 } | 4713 } |
4539 } | 4714 } |
| 4715 |
| 4716 void DateFormatTest::TestCreateInstanceForSkeleton() { |
| 4717 UErrorCode status = U_ZERO_ERROR; |
| 4718 LocalPointer<DateFormat> fmt(DateFormat::createInstanceForSkeleton( |
| 4719 "yMMMMd", "en", status)); |
| 4720 if (!assertSuccess("Create with pattern yMMMMd", status)) { |
| 4721 return; |
| 4722 } |
| 4723 UnicodeString result; |
| 4724 FieldPosition pos(0); |
| 4725 fmt->format(date(98, 5-1, 25), result, pos); |
| 4726 assertEquals("format yMMMMd", "May 25, 1998", result); |
| 4727 fmt.adoptInstead(DateFormat::createInstanceForSkeleton( |
| 4728 "yMd", "en", status)); |
| 4729 if (!assertSuccess("Create with pattern yMd", status)) { |
| 4730 return; |
| 4731 } |
| 4732 result.remove(); |
| 4733 fmt->format(date(98, 5-1, 25), result, pos); |
| 4734 assertEquals("format yMd", "5/25/1998", result); |
| 4735 } |
| 4736 |
| 4737 void DateFormatTest::TestCreateInstanceForSkeletonDefault() { |
| 4738 UErrorCode status = U_ZERO_ERROR; |
| 4739 Locale savedLocale; |
| 4740 Locale::setDefault(Locale::getUS(), status); |
| 4741 LocalPointer<DateFormat> fmt(DateFormat::createInstanceForSkeleton( |
| 4742 "yMMMd", status)); |
| 4743 Locale::setDefault(savedLocale, status); |
| 4744 if (!assertSuccess("Create with pattern yMMMd", status)) { |
| 4745 return; |
| 4746 } |
| 4747 UnicodeString result; |
| 4748 FieldPosition pos(0); |
| 4749 fmt->format(date(98, 5-1, 25), result, pos); |
| 4750 assertEquals("format yMMMd", "May 25, 1998", result); |
| 4751 } |
| 4752 |
| 4753 void DateFormatTest::TestCreateInstanceForSkeletonWithCalendar() { |
| 4754 UErrorCode status = U_ZERO_ERROR; |
| 4755 LocalPointer<DateFormat> fmt( |
| 4756 DateFormat::createInstanceForSkeleton( |
| 4757 Calendar::createInstance( |
| 4758 TimeZone::createTimeZone("GMT-3:00"), |
| 4759 status), |
| 4760 "yMdHm", "en", status)); |
| 4761 if (!assertSuccess("Create with pattern yMMMMd", status)) { |
| 4762 return; |
| 4763 } |
| 4764 UnicodeString result; |
| 4765 FieldPosition pos(0); |
| 4766 |
| 4767 LocalPointer<Calendar> cal(Calendar::createInstance( |
| 4768 TimeZone::createTimeZone("GMT-7:00"), |
| 4769 status)); |
| 4770 if (!assertSuccess("Creating GMT-7 time zone failed", status)) { |
| 4771 return; |
| 4772 } |
| 4773 cal->clear(); |
| 4774 cal->set(1998, 5-1, 25, 0, 0, 0); |
| 4775 |
| 4776 // date format time zone should be 4 hours ahead. |
| 4777 fmt->format(cal->getTime(status), result, pos); |
| 4778 assertEquals("format yMdHm", "5/25/1998, 04:00", result); |
| 4779 assertSuccess("", status); |
| 4780 } |
| 4781 |
| 4782 void DateFormatTest::TestDFSCreateForLocaleNonGregorianLocale() { |
| 4783 UErrorCode status = U_ZERO_ERROR; |
| 4784 Locale fa("fa"); |
| 4785 LocalPointer<DateFormatSymbols> sym( |
| 4786 DateFormatSymbols::createForLocale(fa, status)); |
| 4787 if (!assertSuccess("", status)) { |
| 4788 return; |
| 4789 } |
| 4790 |
| 4791 // Farsi should default to the persian calendar, not gregorian |
| 4792 int32_t count; |
| 4793 const UnicodeString *months = sym->getShortMonths(count); |
| 4794 |
| 4795 // First persian month. |
| 4796 UnicodeString expected("\\u0641\\u0631\\u0648\\u0631\\u062f\\u06cc\\u0646"); |
| 4797 assertEquals("", expected.unescape(), months[0]); |
| 4798 } |
| 4799 |
| 4800 void DateFormatTest::TestDFSCreateForLocaleWithCalendarInLocale() { |
| 4801 UErrorCode status = U_ZERO_ERROR; |
| 4802 Locale en_heb("en@calendar=hebrew"); |
| 4803 LocalPointer<DateFormatSymbols> sym( |
| 4804 DateFormatSymbols::createForLocale(en_heb, status)); |
| 4805 if (!assertSuccess("", status)) { |
| 4806 return; |
| 4807 } |
| 4808 |
| 4809 // We should get the months of the hebrew calendar, not the gregorian |
| 4810 // calendar. |
| 4811 int32_t count; |
| 4812 const UnicodeString *months = sym->getShortMonths(count); |
| 4813 |
| 4814 // First hebrew month. |
| 4815 UnicodeString expected("Tishri"); |
| 4816 assertEquals("", expected, months[0]); |
| 4817 } |
| 4818 |
| 4819 void DateFormatTest::TestChangeCalendar() { |
| 4820 UErrorCode status = U_ZERO_ERROR; |
| 4821 Locale en("en"); |
| 4822 Locale en_heb("en@calendar=hebrew"); |
| 4823 LocalPointer<DateFormat> fmt( |
| 4824 DateFormat::createInstanceForSkeleton("yMMMd", en, status)); |
| 4825 if (!assertSuccess("", status)) { |
| 4826 return; |
| 4827 } |
| 4828 fmt->adoptCalendar(Calendar::createInstance(en_heb, status)); |
| 4829 if (!assertSuccess("", status)) { |
| 4830 return; |
| 4831 } |
| 4832 UnicodeString result; |
| 4833 FieldPosition pos(0); |
| 4834 fmt->format(date(98, 5-1, 25), result, pos); |
| 4835 assertEquals("format yMMMd", "Iyar 29, 5758", result); |
| 4836 } |
| 4837 |
| 4838 |
4540 #endif /* #if !UCONFIG_NO_FORMATTING */ | 4839 #endif /* #if !UCONFIG_NO_FORMATTING */ |
4541 | 4840 |
4542 //eof | 4841 //eof |
OLD | NEW |