X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..340931cb2e044a2141d11567dd0f782524e32994:/icuSources/test/intltest/sdtfmtts.cpp?ds=sidebyside diff --git a/icuSources/test/intltest/sdtfmtts.cpp b/icuSources/test/intltest/sdtfmtts.cpp index 9bad8145..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-2008, International Business Machines Corporation and + * COPYRIGHT: + * Copyright (c) 1997-2016, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -22,7 +24,7 @@ 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; @@ -58,10 +60,13 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) } 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; @@ -89,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 @@ -118,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); @@ -205,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; @@ -235,17 +261,22 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) delete test; // ======= Test Ticket 5684 (Parsing with 'e' and 'Y') - SimpleDateFormat object("en", "us", status); + 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); - object.applyPattern("YYYY'W'wwe"); 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 */