/********************************************************************
- * 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"
#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");
TESTCASE(2,TestGetMonths2);
TESTCASE(3,TestGetWeekdays2);
TESTCASE(4,TestGetEraNames);
+ TESTCASE(5,TestGetSetSpecificItems);
default: name = ""; break;
}
}
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.
*/
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) ) {
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)) {
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");
}
-
}
}