X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..4f1e1a09ce4daed860e35d359ce2fceccb0764e8:/icuSources/test/intltest/tsdtfmsy.cpp diff --git a/icuSources/test/intltest/tsdtfmsy.cpp b/icuSources/test/intltest/tsdtfmsy.cpp index e281505b..c1efcc2a 100644 --- a/icuSources/test/intltest/tsdtfmsy.cpp +++ b/icuSources/test/intltest/tsdtfmsy.cpp @@ -1,7 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** - * COPYRIGHT: - * Copyright (c) 1997-2006, International Business Machines Corporation and - * others. All Rights Reserved. + * Copyright (c) 1997-2013, International Business Machines + * Corporation and others. All Rights Reserved. ********************************************************************/ #include "unicode/utypes.h" @@ -13,6 +14,11 @@ #include "unicode/dtfmtsym.h" +//-------------------------------------------------------------------- +// Time bomb - allows temporary behavior that expires at a given +// release +//-------------------------------------------------------------------- + void IntlTestDateFormatSymbols::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) { if (exec) logln("TestSuite DateFormatSymbols"); @@ -22,6 +28,7 @@ void IntlTestDateFormatSymbols::runIndexedTest( int32_t index, UBool exec, const TESTCASE(2,TestGetMonths2); TESTCASE(3,TestGetWeekdays2); TESTCASE(4,TestGetEraNames); + TESTCASE(5,TestGetSetSpecificItems); default: name = ""; break; } } @@ -122,6 +129,41 @@ void IntlTestDateFormatSymbols::TestGetEraNames() delete symbol; } +UBool IntlTestDateFormatSymbols::UnicodeStringsArePrefixes(int32_t count, int32_t prefixLen, const UnicodeString *prefixArray, const UnicodeString *baseArray) +{ + int32_t i; + for (i = 0; i < count; i++) { + if (baseArray[i].compare(0, prefixLen, prefixArray[i]) != 0) { + errln("ERROR: Mismatch example: expect prefix \"" + prefixArray[i] + "\" of base \"" + baseArray[i] + "\"."); + return FALSE; + } + } + return TRUE; +} + +void IntlTestDateFormatSymbols::TestGetSetSpecificItems() +{ + UErrorCode status = U_ZERO_ERROR; + DateFormatSymbols *symbol=new DateFormatSymbols(Locale::getEnglish(), status); + if(U_FAILURE(status)) { + dataerrln("ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString)u_errorName(status)); + return; + } + int32_t cntFmtAbbrev, cntFmtShort, cntStdAloneShort; + const UnicodeString * wdFmtAbbrev = symbol->getWeekdays(cntFmtAbbrev,DateFormatSymbols::FORMAT,DateFormatSymbols::ABBREVIATED); + const UnicodeString * wdFmtShort = symbol->getWeekdays(cntFmtShort,DateFormatSymbols::FORMAT,DateFormatSymbols::SHORT); + const UnicodeString * wdStdAloneShort = symbol->getWeekdays(cntStdAloneShort,DateFormatSymbols::STANDALONE,DateFormatSymbols::SHORT); + // Expect that English short names are prefixes of abbreviated names + if (cntFmtShort != cntFmtAbbrev || !UnicodeStringsArePrefixes(cntFmtAbbrev, 2, wdFmtShort, wdFmtAbbrev)) { + errln("ERROR: English format short weekday names don't match prefixes of format abbreviated names"); + } + if (cntStdAloneShort != cntFmtAbbrev || !UnicodeStringsArePrefixes(cntFmtAbbrev, 2, wdStdAloneShort, wdFmtAbbrev)) { + errln("ERROR: English standalone short weekday names don't match prefixes of format abbreviated names"); + } + + delete symbol; +} + /** * Test the API of DateFormatSymbols; primarily a simple get/set set. */ @@ -131,19 +173,22 @@ void IntlTestDateFormatSymbols::TestSymbols(/* char *par */) DateFormatSymbols fr(Locale::getFrench(), status); if(U_FAILURE(status)) { - errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status)); + dataerrln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status)); + return; } status = U_ZERO_ERROR; DateFormatSymbols fr2(Locale::getFrench(), status); if(U_FAILURE(status)) { - errln("ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status)); + errcheckln(status, "ERROR: Couldn't create French DateFormatSymbols " + (UnicodeString)u_errorName(status)); + return; } status = U_ZERO_ERROR; DateFormatSymbols en(Locale::getEnglish(), status); if(U_FAILURE(status)) { - errln("ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString)u_errorName(status)); + errcheckln(status, "ERROR: Couldn't create English DateFormatSymbols " + (UnicodeString)u_errorName(status)); + return; } if(en == fr || ! (en != fr) ) { @@ -155,9 +200,25 @@ void IntlTestDateFormatSymbols::TestSymbols(/* char *par */) int32_t count = 0; const UnicodeString *eras = en.getEras(count); if(count == 0) { - errln("ERROR: 0 english eras.. exitting..\n"); + errln("ERROR: 0 english eras.. exiting..\n"); return; } + int32_t eraNamesCount = 0; + const UnicodeString *eraNames = en.getEraNames(eraNamesCount); + if(eraNamesCount == 0) { + errln("ERROR: 0 english eraNames\n"); + } else if ( eraNames[0].length() <= eras[0].length() ) { + // At least for English we know a wide eraName should be longer than an abbrev era + errln("ERROR: english eraNames[0] not longer than eras[0]\n"); + } + int32_t narrowErasCount = 0; + const UnicodeString *narrowEras = en.getNarrowEras(narrowErasCount); + if(narrowErasCount == 0) { + errln("ERROR: 0 english narrowEras\n"); + } else if ( narrowEras[0].length() >= eras[0].length() ) { + // At least for English we know a narrowEra should be shorter than an abbrev era + errln("ERROR: english narrowEras[0] not shorter than eras[0]\n"); + } fr.setEras(eras, count); if( *en.getEras(count) != *fr.getEras(count)) { @@ -311,11 +372,10 @@ void IntlTestDateFormatSymbols::TestSymbols(/* char *par */) fr.setZoneStrings(strings, rowCount, columnCount); const UnicodeString **strings1 = fr.getZoneStrings(rowCount, columnCount); for(int32_t i = 0; i < rowCount; i++) { - for(int32_t j = 0; j < columnCount; j++) { + for(int32_t j = 0; j < columnCount; j++) { if( strings[i][j] != strings1[i][j] ) { errln("ERROR: setZoneStrings() failed"); } - } }