X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..3d1f044b704633e2e541231cd17ae9ecf9ad5c7a:/icuSources/test/intltest/sdtfmtts.cpp diff --git a/icuSources/test/intltest/sdtfmtts.cpp b/icuSources/test/intltest/sdtfmtts.cpp index f687499d..ba48346b 100644 --- a/icuSources/test/intltest/sdtfmtts.cpp +++ b/icuSources/test/intltest/sdtfmtts.cpp @@ -1,7 +1,9 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** - * COPYRIGHT: - * Copyright (c) 1997-2001, International Business Machines Corporation and + * COPYRIGHT: + * Copyright (c) 1997-2016, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -22,15 +24,17 @@ void IntlTestSimpleDateFormatAPI::runIndexedTest( int32_t index, UBool exec, con { if (exec) logln("TestSuite SimpleDateFormatAPI"); switch (index) { - case 0: name = "SimpleDateFormat API test"; + case 0: name = "SimpleDateFormat API test"; if (exec) { logln("SimpleDateFormat API test---"); logln(""); UErrorCode status = U_ZERO_ERROR; + Locale saveLocale; Locale::setDefault(Locale::getEnglish(), status); if(U_FAILURE(status)) { errln("ERROR: Could not set default locale, test may not give correct results"); } testAPI(/*par*/); + Locale::setDefault(saveLocale, status); } break; @@ -51,14 +55,18 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) SimpleDateFormat def(status); if(U_FAILURE(status)) { - errln("ERROR: Could not create SimpleDateFormat (default)"); + dataerrln("ERROR: Could not create SimpleDateFormat (default) - exitting"); + return; } status = U_ZERO_ERROR; - const UnicodeString pattern("yyyy.MM.dd G 'at' hh:mm:ss z"); + const UnicodeString pattern("yyyy.MM.dd G 'at' hh:mm:ss z", ""); + const UnicodeString override("y=hebr;d=thai;s=arab", ""); /* use invariant converter */ + const UnicodeString override_bogus("y=hebr;d=thai;s=bogus", ""); + SimpleDateFormat pat(pattern, status); if(U_FAILURE(status)) { - errln("ERROR: Could not create SimpleDateFormat (pattern)"); + errln("ERROR: Could not create SimpleDateFormat (pattern) - %s", u_errorName(status)); } status = U_ZERO_ERROR; @@ -76,7 +84,8 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) status = U_ZERO_ERROR; SimpleDateFormat cust1(pattern, symbols, status); if(U_FAILURE(status)) { - errln("ERROR: Could not create SimpleDateFormat (pattern, symbols*)"); + dataerrln("ERROR: Could not create SimpleDateFormat (pattern, symbols*) - exitting"); + return; } status = U_ZERO_ERROR; @@ -85,6 +94,27 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) errln("ERROR: Could not create SimpleDateFormat (pattern, symbols)"); } + status = U_ZERO_ERROR; + logln(UnicodeString("Override with: ") + override); + SimpleDateFormat ovr1(pattern, override, status); + if(U_FAILURE(status)) { + errln("ERROR: Could not create SimpleDateFormat (pattern, override) - %s", u_errorName(status)); + } + + status = U_ZERO_ERROR; + SimpleDateFormat ovr2(pattern, override, Locale::getGerman(), status); + if(U_FAILURE(status)) { + errln("ERROR: Could not create SimpleDateFormat (pattern, override, locale) - %s", u_errorName(status)); + } + + status = U_ZERO_ERROR; + logln(UnicodeString("Override with: ") + override_bogus); + SimpleDateFormat ovr3(pattern, override_bogus, Locale::getGerman(), status); + if(U_SUCCESS(status)) { + errln("ERROR: Should not have been able to create SimpleDateFormat (pattern, override, locale) with a bogus override"); + } + + SimpleDateFormat copy(pat); // ======= Test clone(), assignment, and equality @@ -114,7 +144,7 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) Formattable fD(d, Formattable::kIsDate); UnicodeString res1, res2; - FieldPosition pos1(0), pos2(0); + FieldPosition pos1(FieldPosition::DONT_CARE), pos2(FieldPosition::DONT_CARE); res1 = def.format(d, res1, pos1); logln( (UnicodeString) "" + d + " formatted to " + res1); @@ -201,7 +231,7 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) status = U_ZERO_ERROR; pat.applyLocalizedPattern(p1, status); if(U_FAILURE(status)) { - errln("ERROR: applyPattern() failed with " + (int32_t) status); + errln("ERROR: applyPattern() failed with %s", u_errorName(status)); } UnicodeString s3; status = U_ZERO_ERROR; @@ -227,8 +257,26 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) if(test->getDynamicClassID() != SimpleDateFormat::getStaticClassID()) { errln("ERROR: getDynamicClassID() didn't return the expected value"); } - + delete test; + +// ======= Test Ticket 5684 (Parsing with 'e' and 'Y') + SimpleDateFormat object(UNICODE_STRING_SIMPLE("YYYY'W'wwe"), status); + if(U_FAILURE(status)) { + errln("ERROR: Couldn't create a SimpleDateFormat"); + } + object.setLenient(false); + ParsePosition pp(0); + UDate udDate = object.parse("2007W014", pp); + if ((double)udDate == 0.0) { + errln("ERROR: Parsing failed using 'Y' and 'e'"); + } + +// ====== Test ticket 11295 getNumberFormatForField returns wild pointer + if (object.getNumberFormatForField('N') != NULL) { + errln("N is not a valid field, " + "getNumberFormatForField should return NULL"); + } } #endif /* #if !UCONFIG_NO_FORMATTING */