X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..refs/heads/master:/icuSources/test/intltest/dadrfmt.cpp?ds=sidebyside diff --git a/icuSources/test/intltest/dadrfmt.cpp b/icuSources/test/intltest/dadrfmt.cpp index 21238926..a382bd5e 100644 --- a/icuSources/test/intltest/dadrfmt.cpp +++ b/icuSources/test/intltest/dadrfmt.cpp @@ -1,6 +1,8 @@ +// © 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 (c) 1997-2013 International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -23,7 +25,7 @@ #include "unicode/schriter.h" #include "unicode/regex.h" #include "unicode/smpdtfmt.h" -#include "unicode/dbgutil.h" +#include "dbgutil.h" #include "fldset.h" @@ -64,7 +66,7 @@ void DataDrivenFormatTest::runIndexedTest(int32_t index, UBool exec, name = ""; } } else { - dataerrln("[DATA] format/DataDriven*Test data (format.res) not initialized!"); + dataerrln("format/DataDriven*Test data (format.res) not initialized!"); name = ""; } @@ -73,14 +75,16 @@ void DataDrivenFormatTest::runIndexedTest(int32_t index, UBool exec, /* - * Headers { "locale","spec", "date", "str"} + * Headers { "locale", "zone", "spec", "date", "str"} // locale: locale including calendar type + // zone: time zone name, or "" to not explicitly set zone // spec: either 'PATTERN=y mm h' etc, or 'DATE=SHORT,TIME=LONG' // date: either an unsigned long (millis), or a calendar spec ERA=0,YEAR=1, etc.. applied to the calendar type specified by the locale // str: the expected unicode string Cases { { - "en_US@calendar=gregorian", + "en_US@calendar=gregorian", + "", "DATE=SHORT,TIME=SHORT", "ERA=1,YEAR=2007,MONTH=AUGUST,DATE=8,HOUR=18,MINUTE=54,SECOND=12", "8/8/2007 6:54pm" @@ -99,7 +103,7 @@ void DataDrivenFormatTest::testConvertDate(TestData *testData, SimpleDateFormat basicFmt(UnicodeString("EEE MMM dd yyyy / YYYY'-W'ww-ee"), status); if (U_FAILURE(status)) { - errln("FAIL: Couldn't create basic SimpleDateFormat: %s\n", + dataerrln("FAIL: Couldn't create basic SimpleDateFormat: %s", u_errorName(status)); return; } @@ -112,6 +116,7 @@ void DataDrivenFormatTest::testConvertDate(TestData *testData, DateTimeStyleSet styleSet; UnicodeString pattern; UBool usePattern = FALSE; + (void)usePattern; // Suppress unused warning. CalendarFieldsSet fromSet; UDate fromDate = 0; UBool useDate = FALSE; @@ -130,6 +135,11 @@ void DataDrivenFormatTest::testConvertDate(TestData *testData, errln("case %d: No 'locale' line.", n); continue; } + UnicodeString zone = currentCase->getString("zone", status); + if (U_FAILURE(status)) { + errln("case %d: No 'zone' line.", n); + continue; + } UnicodeString spec = currentCase->getString("spec", status); if(U_FAILURE(status)) { errln("case %d: No 'spec' line.", n); @@ -175,16 +185,23 @@ void DataDrivenFormatTest::testConvertDate(TestData *testData, if(U_FAILURE(status)) { errln("case %d: could not create calendar from %s", n, calLoc); } + + if (zone.length() > 0) { + TimeZone * tz = TimeZone::createTimeZone(zone); + cal->setTimeZone(*tz); + format->setTimeZone(*tz); + delete tz; + } // parse 'date' if(date.startsWith(kMILLIS)) { UnicodeString millis = UnicodeString(date, kMILLIS.length()); useDate = TRUE; - fromDate = udbg_stoi(millis); + fromDate = udbg_stod(millis); } else if(date.startsWith(kRELATIVE_MILLIS)) { UnicodeString millis = UnicodeString(date, kRELATIVE_MILLIS.length()); useDate = TRUE; - fromDate = udbg_stoi(millis) + now; + fromDate = udbg_stod(millis) + now; } else if(date.startsWith(kRELATIVE_ADD)) { UnicodeString add = UnicodeString(date, kRELATIVE_ADD.length()); // "add" is a string indicating which fields to add if(fromSet.parseFrom(add, status)<0 || U_FAILURE(status)) { @@ -196,10 +213,15 @@ void DataDrivenFormatTest::testConvertDate(TestData *testData, cal->setTime(now, status); for (int q=0; qget((UCalendarDateFields)q, status); - cal->add((UCalendarDateFields)q, - fromSet.get((UCalendarDateFields)q), status); - int32_t newv = cal->get((UCalendarDateFields)q, status); + //int32_t oldv = cal->get((UCalendarDateFields)q, status); + if (q == UCAL_DATE) { + cal->add((UCalendarDateFields)q, + fromSet.get((UCalendarDateFields)q), status); + } else { + cal->set((UCalendarDateFields)q, + fromSet.get((UCalendarDateFields)q)); + } + //int32_t newv = cal->get((UCalendarDateFields)q, status); } } fromDate = cal->getTime(status);