Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: source/test/intltest/dtfmrgts.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/intltest/dtfmrgts.h ('k') | source/test/intltest/dtfmtrtts.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 1997-2012, International Business Machines Corporation and 3 * Copyright (c) 1997-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
11 #include "dtfmrgts.h" 10 #include "dtfmrgts.h"
12 11
13 #include "unicode/timezone.h" 12 #include "unicode/timezone.h"
14 #include "unicode/gregocal.h" 13 #include "unicode/gregocal.h"
15 #include "unicode/smpdtfmt.h" 14 #include "unicode/smpdtfmt.h"
16 #include "unicode/datefmt.h" 15 #include "unicode/datefmt.h"
17 #include "unicode/simpletz.h" 16 #include "unicode/simpletz.h"
18 #include "unicode/resbund.h" 17 #include "unicode/resbund.h"
19 18
20 // ***************************************************************************** 19 // *****************************************************************************
(...skipping 29 matching lines...) Expand all
50 CASE(19,Test4151631) 49 CASE(19,Test4151631)
51 CASE(20,Test4151706) 50 CASE(20,Test4151706)
52 CASE(21,Test4162071) 51 CASE(21,Test4162071)
53 CASE(22,Test4182066) 52 CASE(22,Test4182066)
54 CASE(23,Test4210209) 53 CASE(23,Test4210209)
55 CASE(24,Test714) 54 CASE(24,Test714)
56 CASE(25,Test1684) 55 CASE(25,Test1684)
57 CASE(26,Test5554) 56 CASE(26,Test5554)
58 CASE(27,Test9237) 57 CASE(27,Test9237)
59 CASE(28,TestParsing) 58 CASE(28,TestParsing)
59 CASE(29,TestT10334)
60 CASE(30,TestT10619)
61 CASE(31,TestT10855)
62 CASE(32,TestT10906)
60 default: name = ""; break; 63 default: name = ""; break;
61 } 64 }
62 } 65 }
63 66
64 /** 67 /**
65 * @bug 4029195 68 * @bug 4029195
66 */ 69 */
67 void DateFormatRegressionTest::Test4029195(void) 70 void DateFormatRegressionTest::Test4029195(void)
68 { 71 {
69 UErrorCode status = U_ZERO_ERROR; 72 UErrorCode status = U_ZERO_ERROR;
70 73
71 UDate today = Calendar::getNow(); 74 UDate today = Calendar::getNow();
72 logln((UnicodeString) "today: " + today); 75 logln((UnicodeString) "today: " + today);
73 76
74 SimpleDateFormat *sdf = (SimpleDateFormat*) DateFormat::createDateInstance() ; 77 SimpleDateFormat *sdf = (SimpleDateFormat*) DateFormat::createDateInstance() ;
75 if (failure(status, "SimpleDateFormat::createDateInstance")) { 78 if (failure(status, "SimpleDateFormat::createDateInstance")) {
76 return; 79 return;
77 } 80 }
78 UnicodeString pat; 81 UnicodeString pat;
79 if(sdf == NULL){ 82 if(sdf == NULL){
80 dataerrln("Error calling DateFormat::createDateTimeInstance"); 83 dataerrln("Error calling DateFormat::createDateTimeInstance");
81 return; 84 return;
82 } 85 }
83 86
84 pat = sdf->toPattern(pat); 87 pat = sdf->toPattern(pat);
85 logln("pattern: " + pat); 88 logln("pattern: " + pat);
86 UnicodeString fmtd; 89 UnicodeString fmtd;
90
87 FieldPosition pos(FieldPosition::DONT_CARE); 91 FieldPosition pos(FieldPosition::DONT_CARE);
88 fmtd = sdf->format(today, fmtd, pos); 92 fmtd = sdf->format(today, fmtd, pos);
89 logln("today: " + fmtd); 93 logln("today: " + fmtd);
90 94
91 sdf->applyPattern("G yyyy DDD"); 95 sdf->applyPattern("G yyyy DDD");
92 UnicodeString todayS; 96 UnicodeString todayS;
93 todayS = sdf->format(today, todayS, pos); 97 todayS = sdf->format(today, todayS, pos);
94 logln("today: " + todayS); 98 logln("today: " + todayS);
95 //try { 99 //try {
96 today = sdf->parse(todayS, status); 100 today = sdf->parse(todayS, status);
(...skipping 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 ParsePosition pos(0); 1522 ParsePosition pos(0);
1519 format.parse(text, *cal, pos); 1523 format.parse(text, *cal, pos);
1520 1524
1521 if (cal->get(UCAL_DAY_OF_MONTH, status) != expectedDay) { 1525 if (cal->get(UCAL_DAY_OF_MONTH, status) != expectedDay) {
1522 errln("Parsing failed: day of month should be '7' with pattern: \"" + pa ttern + "\" for text: \"" + text + "\""); 1526 errln("Parsing failed: day of month should be '7' with pattern: \"" + pa ttern + "\" for text: \"" + text + "\"");
1523 } 1527 }
1524 1528
1525 delete cal; 1529 delete cal;
1526 } 1530 }
1527 1531
1532 void DateFormatRegressionTest::TestT10334(void) {
1533 UErrorCode status = U_ZERO_ERROR;
1534 UnicodeString pattern("--: EEE-WW-MMMM-yyyy");
1535 UnicodeString text("--mon-02-march-2011");
1536 SimpleDateFormat format(pattern, status);
1537
1538 logln("pattern["+pattern+"] text["+text+"]");
1539
1540 if (U_FAILURE(status)) {
1541 dataerrln("Fail creating SimpleDateFormat object - %s", u_errorName(stat us));
1542 return;
1543 }
1544
1545 format.setBooleanAttribute(UDAT_PARSE_PARTIAL_MATCH, FALSE, status);
1546 format.parse(text, status);
1547 if (!U_FAILURE(status)) {
1548 errln("parse partial match did NOT fail in strict mode - %s", u_errorNam e(status));
1549 }
1550
1551 status = U_ZERO_ERROR;
1552 format.setBooleanAttribute(UDAT_PARSE_PARTIAL_MATCH, TRUE, status);
1553 format.parse(text, status);
1554 if (U_FAILURE(status)) {
1555 errln("parse partial match failure in lenient mode - %s", u_errorName(st atus));
1556 }
1557
1558 status = U_ZERO_ERROR;
1559 pattern = UnicodeString("YYYY MM dd");
1560 text = UnicodeString("2013 12 10");
1561 format.applyPattern(pattern);
1562 UDate referenceDate = format.parse(text, status);
1563
1564 FieldPosition fp(0);
1565 UnicodeString formattedString("");
1566 pattern = UnicodeString("YYYY LL dd ee cc qq QQ");
1567 format.applyPattern(pattern);
1568 format.format(referenceDate, formattedString, fp, status);
1569 logln("ref date: " + formattedString);
1570
1571
1572 char patternArray[] = "YYYY LLL dd eee ccc qqq QQQ";
1573 pattern = UnicodeString(patternArray);
1574 text = UnicodeString("2013 12 10 03 3 04 04");
1575 status = U_ZERO_ERROR;
1576 format.setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, TRUE, status);
1577 format.applyPattern(pattern);
1578 ParsePosition pp(0);
1579 format.parse(text, pp);
1580 if (pp.getErrorIndex() != -1) {
1581 errln("numeric parse error");
1582 }
1583
1584 status = U_ZERO_ERROR;
1585 format.setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, FALSE, status);
1586 format.parse(text, status);
1587 if (!U_FAILURE(status)) {
1588 errln("numeric parse did NOT fail in strict mode", u_errorName(status));
1589 }
1590
1591 }
1592
1593
1594 typedef struct {
1595 const char * locale;
1596 UBool leniency;
1597 UnicodeString parseString;
1598 UnicodeString pattern;
1599 UnicodeString expectedResult; // null indicates expected error
1600 } TestDateFormatLeniencyItem;
1601
1602
1603 void DateFormatRegressionTest::TestT10619(void) {
1604 const UDate july022008 = 1215000001979.0;
1605 const TestDateFormatLeniencyItem items[] = {
1606 //locale leniency parse String pattern expected result
1607 { "en", true, UnicodeString("2008-07 02"), UnicodeString("y yyy-LLLL dd"), UnicodeString("2008-July 02") },
1608 { "en", false, UnicodeString("2008-07 03"), UnicodeString("y yyy-LLLL dd"), UnicodeString("") },
1609 { "en", true, UnicodeString("2008-Jan. 04"), UnicodeString("y yyy-LLL dd"), UnicodeString("2008-Jan 04") },
1610 { "en", false, UnicodeString("2008-Jan. 05"), UnicodeString("y yyy-LLL dd"), UnicodeString("") },
1611 { "en", true, UnicodeString("2008-Jan--06"), UnicodeString("y yyy-MMM -- dd"), UnicodeString("2008-Jan 06") },
1612 { "en", false, UnicodeString("2008-Jan--07"), UnicodeString("y yyy-MMM -- dd"), UnicodeString("") },
1613 { "en", true, UnicodeString("6 Jan 08 2008"), UnicodeString("e ee MMM dd yyyy"), UnicodeString("Sat Jan 08 2008") },
1614 { "en", false, UnicodeString("6 Jan 09 2008"), UnicodeString("e ee MMM dd yyyy"), UnicodeString("") },
1615 // terminator
1616 { NULL, true, UnicodeString(""), UnicodeString("" ), UnicodeString("") }
1617 };
1618 UErrorCode status = U_ZERO_ERROR;
1619 Calendar* cal = Calendar::createInstance(status);
1620 if (U_FAILURE(status)) {
1621 dataerrln(UnicodeString("FAIL: Unable to create Calendar for default tim ezone and locale."));
1622 } else {
1623 cal->setTime(july022008, status);
1624 const TestDateFormatLeniencyItem * itemPtr;
1625 for (itemPtr = items; itemPtr->locale != NULL; itemPtr++ ) {
1626
1627 Locale locale = Locale::createFromName(itemPtr->locale);
1628 status = U_ZERO_ERROR;
1629 ParsePosition pos(0);
1630 SimpleDateFormat * sdmft = new SimpleDateFormat(itemPtr->pattern, lo cale, status);
1631 if (U_FAILURE(status)) {
1632 dataerrln("Unable to create SimpleDateFormat - %s", u_errorName( status));
1633 continue;
1634 }
1635 logln("parsing " + itemPtr->parseString);
1636 sdmft->setLenient(itemPtr->leniency);
1637 sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->len iency, status);
1638 sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->lenien cy, status);
1639 sdmft->setBooleanAttribute(UDAT_PARSE_PARTIAL_MATCH, itemPtr->lenien cy, status);
1640 sdmft->parse(itemPtr->parseString, pos);
1641
1642 delete sdmft;
1643 if(pos.getErrorIndex() > -1) {
1644 if(itemPtr->expectedResult.length() != 0) {
1645 errln("error: unexpected error - " + itemPtr->parseString + " - error index " + pos.getErrorIndex() +
1646 " - leniency " + itemPtr->leniency);
1647 continue;
1648 } else {
1649 continue;
1650 }
1651 }
1652 }
1653 }
1654 delete cal;
1655
1656 }
1657
1658
1659 typedef struct {
1660 UnicodeString text;
1661 UnicodeString pattern;
1662 int initialParsePos;
1663 } T10855Data;
1664
1665 void DateFormatRegressionTest::TestT10855(void) {
1666 // NOTE: these should NOT parse
1667 const T10855Data items[] = {
1668 //parse String pattern initial parse pos
1669 { UnicodeString("September 30, 1998"), UnicodeString("MM-dd-yyyy"), 0},
1670 { UnicodeString("123-73-1950"), UnicodeString("MM-dd-yyyy"), -1},
1671 { UnicodeString("12-23-1950"), UnicodeString("MM-dd-yyyy"), -1},
1672 // terminator
1673 { UnicodeString(""), UnicodeString(""), 0}
1674 };
1675 UErrorCode status = U_ZERO_ERROR;
1676
1677 int x = 0;
1678 while(items[x].pattern.length() > 0)
1679 {
1680 status = U_ZERO_ERROR;
1681 logln("Date to parse: \""+items[x].text+"\"");
1682 logln("Starting Index: %d", items[x].initialParsePos);
1683
1684 SimpleDateFormat dateFmt(items[x].pattern, status);
1685 if(U_FAILURE(status)) {
1686 errcheckln(status, "Failed dateFmt: %s", u_errorName(status));
1687 ++x;
1688 continue;
1689 }
1690 status = U_ZERO_ERROR;
1691
1692 dateFmt.setLenient(false);
1693 dateFmt.setTimeZone(*TimeZone::getGMT());
1694
1695 ParsePosition position(items[x].initialParsePos);
1696 logln("set position is now: %d", position.getIndex());
1697 UDate d = dateFmt.parse(items[x].text, position);
1698 if (position.getErrorIndex() != -1 || position.getIndex() == items[x].in itialParsePos) {
1699 logln("Parse Failed. ErrorIndex is %d - Index is %d", position.getEr rorIndex(), position.getIndex());
1700 } else {
1701 errln("Parse Succeeded...should have failed. Index is %d - ErrorInde x is %d", position.getIndex(), position.getErrorIndex());
1702 }
1703 logln("Parsed date returns %d\n", d);
1704
1705 ++x;
1706 }
1707 }
1708
1709 void DateFormatRegressionTest::TestT10906(void) {
1710
1711 UErrorCode status = U_ZERO_ERROR;
1712 UnicodeString pattern = "MM-dd-yyyy";
1713 UnicodeString text = "06-10-2014";
1714 SimpleDateFormat format(pattern, status);
1715 int32_t errorIdx = 0;
1716 ParsePosition pp(-1);
1717 format.parse(text, pp);
1718 errorIdx = pp.getErrorIndex();
1719 if (errorIdx == -1) {
1720 errln("failed to report invalid (negative) starting parse position");
1721 }
1722 }
1723
1528 #endif /* #if !UCONFIG_NO_FORMATTING */ 1724 #endif /* #if !UCONFIG_NO_FORMATTING */
1529 1725
1530 //eof 1726 //eof
OLDNEW
« no previous file with comments | « source/test/intltest/dtfmrgts.h ('k') | source/test/intltest/dtfmtrtts.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698