2007-08-03 18:43:04 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2009-01-16 01:18:05 +00:00
|
|
|
* Copyright (c) 2008-2009, International Business Machines Corporation and
|
2007-08-03 18:43:04 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
|
2007-08-10 23:31:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "dtptngts.h"
|
|
|
|
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/smpdtfmt.h"
|
|
|
|
#include "unicode/dtfmtsym.h"
|
|
|
|
#include "unicode/dtptngen.h"
|
|
|
|
#include "loctest.h"
|
|
|
|
|
|
|
|
|
|
|
|
// This is an API test, not a unit test. It doesn't test very many cases, and doesn't
|
|
|
|
// try to test the full functionality. It just calls each function in the class and
|
|
|
|
// verifies that it works on a basic level.
|
|
|
|
|
|
|
|
void IntlTestDateTimePatternGeneratorAPI::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite DateTimePatternGeneratorAPI");
|
|
|
|
switch (index) {
|
2007-08-04 01:15:18 +00:00
|
|
|
TESTCASE(0, testAPI);
|
2007-08-03 18:43:04 +00:00
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-16 01:18:05 +00:00
|
|
|
#define MAX_LOCALE 8
|
2007-08-07 07:22:18 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
/**
|
|
|
|
* Test various generic API methods of DateTimePatternGenerator for API coverage.
|
|
|
|
*/
|
|
|
|
void IntlTestDateTimePatternGeneratorAPI::testAPI(/*char *par*/)
|
|
|
|
{
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString patternData[] = {
|
|
|
|
UnicodeString("yM"),
|
|
|
|
UnicodeString("yMMM"),
|
|
|
|
UnicodeString("yMd"),
|
|
|
|
UnicodeString("yMMMd"),
|
|
|
|
UnicodeString("Md"),
|
|
|
|
UnicodeString("MMMd"),
|
|
|
|
UnicodeString("yQQQ"),
|
|
|
|
UnicodeString("hhmm"),
|
|
|
|
UnicodeString("HHmm"),
|
|
|
|
UnicodeString("mmss"),
|
2008-11-19 04:19:02 +00:00
|
|
|
UnicodeString("yyyyMMMM"),
|
2007-08-11 20:32:54 +00:00
|
|
|
UnicodeString(),
|
2007-08-07 07:22:18 +00:00
|
|
|
};
|
|
|
|
|
2008-11-19 04:19:02 +00:00
|
|
|
const char* testLocale[MAX_LOCALE][4] = {
|
|
|
|
{"en", "US", "", ""},
|
2008-12-19 20:10:03 +00:00
|
|
|
{"en", "US", "", "calendar=japanese"},
|
2008-11-19 04:19:02 +00:00
|
|
|
{"zh", "Hans", "CN", ""},
|
|
|
|
{"de", "DE", "", ""},
|
|
|
|
{"fi", "", "", ""},
|
|
|
|
{"ja", "", "", ""},
|
|
|
|
{"ja", "", "", "calendar=japanese"},
|
2009-01-16 01:18:05 +00:00
|
|
|
{"zh", "TW", "", "calendar=roc"},
|
2007-08-07 07:22:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeString patternResults[] = {
|
2008-11-19 04:19:02 +00:00
|
|
|
UnicodeString("1/1999"), // en_US
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString("Jan 1999"),
|
|
|
|
UnicodeString("1/13/1999"),
|
2008-06-11 16:31:33 +00:00
|
|
|
UnicodeString("Jan 13, 1999"),
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString("1/13"),
|
|
|
|
UnicodeString("Jan 13"),
|
|
|
|
UnicodeString("Q1 1999"),
|
|
|
|
UnicodeString("11:58 PM"),
|
|
|
|
UnicodeString("23:58"),
|
|
|
|
UnicodeString("58:59"),
|
2008-11-19 04:19:02 +00:00
|
|
|
UnicodeString("January 1999"), // en_US 10: yyyyMMMM
|
|
|
|
|
2008-12-19 20:10:03 +00:00
|
|
|
// currently the following for en_US@calendar=japanese just verify the correct fallback behavior for ticket:5702;
|
|
|
|
// however some are not the "correct" results. To fix that, root needs better DateTimePatterns/availableFormats
|
|
|
|
// data; cldrbug #1994 is for that.
|
|
|
|
UnicodeString("H 11-01"), // en_US@calendar=japanese 0: yM
|
|
|
|
UnicodeString("H 11 Jan"), // en_US@calendar=japanese 1: yMMM
|
|
|
|
UnicodeString("1/13/11"), // en_US@calendar=japanese 2: yMd (fix root's DateTimePatterns/availableFormats, then fix this)
|
|
|
|
UnicodeString("Jan/13/11"), // en_US@calendar=japanese 3: yMMMd (fix root's DateTimePatterns/availableFormats, then fix this)
|
|
|
|
UnicodeString("1-13"), // en_US@calendar=japanese 4: Md
|
|
|
|
UnicodeString("Jan 13"), // en_US@calendar=japanese 5: MMMd
|
|
|
|
UnicodeString("H 11 Q1"), // en_US@calendar=japanese 6: yQQQ
|
|
|
|
UnicodeString("23:58"), // en_US@calendar=japanese 7: hhmm
|
|
|
|
UnicodeString("23:58"), // en_US@calendar=japanese 8: HHmm
|
|
|
|
UnicodeString("58:59"), // en_US@calendar=japanese 9: mmss
|
|
|
|
UnicodeString("H 0011 January"), // en_US@calendar=japanese 10: yyyyMMMM (fix root's DateTimePatterns/availableFormats, then fix this)
|
|
|
|
|
2008-11-18 18:27:40 +00:00
|
|
|
UnicodeString("1999-1", -1, US_INV), // zh_Hans_CN: yM
|
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // zh_Hans_CN: yMMM -> yyyy\u5E74MMM (fixed expected result per ticket:6626:)
|
2007-08-07 07:22:18 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E741\\u670813\\u65E5"),
|
2008-11-18 18:27:40 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E741\\u670813\\u65E5"), // zh_Hans_CN: yMMMd -> yyyy\u5E74MMMd\u65E5 (fixed expected result per ticket:6626:)
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString("1-13"),
|
2008-11-18 18:27:40 +00:00
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // zh_Hans_CN: MMMd -> MMMd\u65E5 (fixed expected result per ticket:6626:)
|
2008-05-16 15:01:02 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E741\\u5B63"),
|
2007-08-07 07:22:18 +00:00
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58"),
|
|
|
|
CharsToUnicodeString("23:58"),
|
|
|
|
UnicodeString("58:59"),
|
2008-11-19 04:19:02 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // zh_Hans_CN 10: yyyyMMMM -> yyyy\u5E74MMM
|
|
|
|
|
2008-05-16 15:01:02 +00:00
|
|
|
UnicodeString("1999-1"), // de_DE
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString("Jan 1999"),
|
|
|
|
UnicodeString("13.1.1999"),
|
|
|
|
UnicodeString("13. Jan 1999"),
|
|
|
|
UnicodeString("13.1."),
|
|
|
|
UnicodeString("13. Jan"),
|
|
|
|
UnicodeString("Q1 1999"),
|
|
|
|
UnicodeString("23:58"),
|
|
|
|
UnicodeString("23:58"),
|
|
|
|
UnicodeString("58:59"),
|
2008-11-19 04:19:02 +00:00
|
|
|
UnicodeString("Januar 1999"), // de 10: yyyyMMMM
|
|
|
|
|
|
|
|
UnicodeString("1.1999"), // fi: yM (fixed expected result per ticket:6626:)
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString("tammi 1999"),
|
|
|
|
UnicodeString("13.1.1999"),
|
2008-06-07 20:46:42 +00:00
|
|
|
UnicodeString("13. tammi 1999"),
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString("13.1."),
|
2008-06-07 20:46:42 +00:00
|
|
|
UnicodeString("13. tammi"),
|
2008-05-16 15:01:02 +00:00
|
|
|
UnicodeString("1. nelj. 1999"),
|
2007-08-07 07:22:18 +00:00
|
|
|
UnicodeString("23.58"),
|
|
|
|
UnicodeString("23.58"),
|
|
|
|
UnicodeString("58.59"),
|
2008-11-19 04:19:02 +00:00
|
|
|
UnicodeString("tammikuuta 1999"), // fi 10: yyyyMMMM
|
|
|
|
|
2008-11-18 18:27:40 +00:00
|
|
|
UnicodeString("1999/1"), // ja 0: yM -> y/M
|
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // ja 1: yMMM -> y\u5E74M\u6708
|
|
|
|
UnicodeString("1999/1/13"), // ja 2: yMd -> y/M/d
|
|
|
|
CharsToUnicodeString("1999\\u5E741\\u670813\\u65E5"), // ja 3: yMMMd -> y\u5E74M\u6708d\u65E5
|
|
|
|
UnicodeString("1/13"), // ja 4: Md -> M/d
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // ja 5: MMMd -> M\u6708d\u65E5
|
|
|
|
UnicodeString("1999Q1"), // ja 6: yQQQ -> yQQQ
|
|
|
|
UnicodeString("23:58"), // ja 7: hhmm
|
|
|
|
UnicodeString("23:58"), // ja 8: HHmm -> HH:mm
|
|
|
|
UnicodeString("58:59"), // ja 9: mmss -> mm:ss
|
2008-11-19 04:19:02 +00:00
|
|
|
CharsToUnicodeString("1999\\u5E741\\u6708"), // ja 10: yyyyMMMM -> y\u5E74M\u6708
|
|
|
|
|
|
|
|
CharsToUnicodeString("\\u5E73\\u621011/1"), // ja@japanese 0: yM -> Gy/m
|
|
|
|
CharsToUnicodeString("\\u5E73\\u621011\\u5E741\\u6708"), // ja@japanese 1: yMMM -> Gy\u5E74M\u6708
|
|
|
|
CharsToUnicodeString("\\u5E73\\u621011/1/13"), // ja@japanese 2: yMd -> Gy/m/d
|
|
|
|
CharsToUnicodeString("\\u5E73\\u621011\\u5E741\\u670813\\u65E5"), // ja@japanese 3: yMMMd -> Gy\u5E74M\u6708d\u65E5
|
|
|
|
UnicodeString("1/13"), // ja@japanese 4: Md -> M/d
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // ja@japanese 5: MMMd -> M\u6708d\u65E5
|
|
|
|
CharsToUnicodeString("\\u5E73\\u621011/Q1"), // ja@japanese 6: yQQQ -> Gy/QQQ
|
|
|
|
UnicodeString("23:58"), // ja@japanese 7: hhmm ->
|
|
|
|
UnicodeString("23:58"), // ja@japanese 8: HHmm -> HH:mm (as for ja)
|
|
|
|
UnicodeString("58:59"), // ja@japanese 9: mmss -> mm:ss (as for ja)
|
|
|
|
CharsToUnicodeString("\\u5E73\\u62100011\\u5E741\\u6708"), // ja@japanese 10: yyyyMMMM -> Gyyyy\u5E74M\u6708
|
|
|
|
|
2009-01-16 01:18:05 +00:00
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88/1"), // zh_TW@roc 0: yM -> Gy/M
|
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u6708"), // zh_TW@roc 1: yMMM -> Gy\u5E74M\u6708
|
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88/1/13"), // zh_TW@roc 2: yMd -> Gy/M/d
|
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u670813\\u65E5"), // zh_TW@roc 3: yMMMd -> Gy\u5E74M\u6708d\u65E5
|
|
|
|
UnicodeString("1/13"), // zh_TW@roc 4: Md -> M/d
|
|
|
|
CharsToUnicodeString("1\\u670813\\u65E5"), // zh_TW@roc 5: MMMd ->M\u6708d\u65E5
|
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88 1\\u5B63"), // zh_TW@roc 6: yQQQ -> Gy QQQ
|
|
|
|
CharsToUnicodeString("\\u4E0B\\u534811:58"), // zh_TW@roc 7: hhmm ->
|
|
|
|
CharsToUnicodeString("23:58"), // zh_TW@roc 8: HHmm ->
|
|
|
|
UnicodeString("58:59"), // zh_TW@roc 9: mmss ->
|
|
|
|
CharsToUnicodeString("\\u6C11\\u570B88\\u5E741\\u6708"), // zh_TW@roc 10: yyyyMMMM -> Gy\u5E74M\u670
|
|
|
|
|
2007-08-11 20:32:54 +00:00
|
|
|
UnicodeString(),
|
2007-08-07 07:22:18 +00:00
|
|
|
};
|
|
|
|
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString patternTests2[] = {
|
|
|
|
UnicodeString("yyyyMMMdd"),
|
2008-08-07 17:06:38 +00:00
|
|
|
UnicodeString("yMMMdd"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("EyyyyMMMdd"),
|
|
|
|
UnicodeString("yyyyMMdd"),
|
|
|
|
UnicodeString("yyyyMMM"),
|
|
|
|
UnicodeString("yyyyMM"),
|
|
|
|
UnicodeString("yyMM"),
|
2008-06-11 16:31:33 +00:00
|
|
|
UnicodeString("yMMMMMd"),
|
|
|
|
UnicodeString("EEEEEMMMMMd"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("MMMd"),
|
|
|
|
UnicodeString("MMMdhmm"),
|
|
|
|
UnicodeString("EMMMdhmms"),
|
|
|
|
UnicodeString("MMdhmm"),
|
|
|
|
UnicodeString("EEEEMMMdhmms"),
|
|
|
|
UnicodeString("yyyyMMMddhhmmss"),
|
|
|
|
UnicodeString("EyyyyMMMddhhmmss"),
|
|
|
|
UnicodeString("hmm"),
|
|
|
|
UnicodeString("hhmm"),
|
|
|
|
UnicodeString(""),
|
|
|
|
};
|
|
|
|
UnicodeString patternResults2[] = {
|
2008-08-07 17:06:38 +00:00
|
|
|
UnicodeString("Oct 14, 1999"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("Oct 14, 1999"),
|
|
|
|
UnicodeString("Thu, Oct 14, 1999"),
|
|
|
|
UnicodeString("10/14/1999"),
|
|
|
|
UnicodeString("Oct 1999"),
|
|
|
|
UnicodeString("10/1999"),
|
|
|
|
UnicodeString("10/99"),
|
2008-08-07 17:06:38 +00:00
|
|
|
UnicodeString("O 14, 1999"),
|
2008-06-11 16:31:33 +00:00
|
|
|
UnicodeString("T, O 14"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("Oct 14"),
|
|
|
|
UnicodeString("Oct 14 6:58 AM"),
|
2008-05-16 15:01:02 +00:00
|
|
|
UnicodeString("Thu, Oct 14 6:58:59 AM"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("10/14 6:58 AM"),
|
2008-05-16 15:01:02 +00:00
|
|
|
UnicodeString("Thursday, Oct 14 6:58:59 AM"),
|
2007-12-22 05:30:33 +00:00
|
|
|
UnicodeString("Oct 14, 1999 06:58:59 AM"),
|
|
|
|
UnicodeString("Thu, Oct 14, 1999 06:58:59 AM"),
|
|
|
|
UnicodeString("6:58 AM"),
|
|
|
|
UnicodeString("06:58 AM"),
|
|
|
|
UnicodeString(""),
|
|
|
|
};
|
|
|
|
|
2007-08-07 07:22:18 +00:00
|
|
|
// results for getSkeletons() and getPatternForSkeleton()
|
|
|
|
const UnicodeString testSkeletonsResults[] = {
|
|
|
|
UnicodeString("HH:mm"),
|
|
|
|
UnicodeString("MMMMd"),
|
|
|
|
UnicodeString("MMMMMd"),
|
|
|
|
};
|
|
|
|
|
|
|
|
const UnicodeString testBaseSkeletonsResults[] = {
|
|
|
|
UnicodeString("Hm"),
|
|
|
|
UnicodeString("MMMd"),
|
|
|
|
UnicodeString("MMMd"),
|
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeString newDecimal(" "); // space
|
|
|
|
UnicodeString newAppendItemName("hrs.");
|
|
|
|
UnicodeString newAppendItemFormat("{1} {0}");
|
|
|
|
UnicodeString newDateTimeFormat("{1} {0}");
|
2007-08-03 18:43:04 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UnicodeString conflictingPattern;
|
|
|
|
UDateTimePatternConflict conflictingStatus;
|
|
|
|
|
|
|
|
// ======= Test CreateInstance with default locale
|
|
|
|
logln("Testing DateTimePatternGenerator createInstance from default locale");
|
|
|
|
|
|
|
|
DateTimePatternGenerator *instFromDefaultLocale=DateTimePatternGenerator::createInstance(status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator (default) - exitting");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete instFromDefaultLocale;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======= Test CreateInstance with given locale
|
|
|
|
logln("Testing DateTimePatternGenerator createInstance from French locale");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
DateTimePatternGenerator *instFromLocale=DateTimePatternGenerator::createInstance(Locale::getFrench(), status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getFrench()) - exitting");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======= Test clone DateTimePatternGenerator
|
|
|
|
logln("Testing DateTimePatternGenerator::clone()");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
UnicodeString decimalSymbol = instFromLocale->getDecimal();
|
|
|
|
UnicodeString newDecimalSymbol = UnicodeString("*");
|
|
|
|
decimalSymbol = instFromLocale->getDecimal();
|
|
|
|
instFromLocale->setDecimal(newDecimalSymbol);
|
|
|
|
DateTimePatternGenerator *cloneDTPatternGen=instFromLocale->clone();
|
|
|
|
decimalSymbol = cloneDTPatternGen->getDecimal();
|
|
|
|
if (decimalSymbol != newDecimalSymbol) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: inconsistency is found in cloned object.");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2007-08-07 23:16:36 +00:00
|
|
|
if ( !(*cloneDTPatternGen == *instFromLocale) ) {
|
|
|
|
errln("ERROR: inconsistency is found in cloned object.");
|
|
|
|
}
|
2007-08-08 01:07:23 +00:00
|
|
|
|
2007-08-07 23:16:36 +00:00
|
|
|
if ( *cloneDTPatternGen != *instFromLocale ) {
|
|
|
|
errln("ERROR: inconsistency is found in cloned object.");
|
|
|
|
}
|
2007-08-08 01:07:23 +00:00
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
delete instFromLocale;
|
|
|
|
delete cloneDTPatternGen;
|
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
// ======= Test simple use cases
|
|
|
|
logln("Testing simple use cases");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
Locale deLocale=Locale::getGermany();
|
|
|
|
UDate sampleDate=LocaleTest::date(99, 9, 13, 23, 58, 59);
|
|
|
|
DateTimePatternGenerator *gen = DateTimePatternGenerator::createInstance(deLocale, status);
|
2007-08-07 03:14:19 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getGermany()) - exitting");
|
|
|
|
return;
|
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
UnicodeString findPattern = gen->getBestPattern(UnicodeString("MMMddHmm"), status);
|
|
|
|
SimpleDateFormat *format = new SimpleDateFormat(findPattern, deLocale, status);
|
2007-08-07 03:14:19 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create SimpleDateFormat (Locale::getGermany())");
|
2007-08-26 20:10:45 +00:00
|
|
|
delete gen;
|
|
|
|
return;
|
2007-08-07 03:14:19 +00:00
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
TimeZone *zone = TimeZone::createTimeZone(UnicodeString("ECT"));
|
2007-08-26 20:10:45 +00:00
|
|
|
if (zone==NULL) {
|
2007-08-07 03:14:19 +00:00
|
|
|
dataerrln("ERROR: Could not create TimeZone ECT");
|
2007-08-26 20:10:45 +00:00
|
|
|
delete gen;
|
|
|
|
delete format;
|
|
|
|
return;
|
2007-08-07 03:14:19 +00:00
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
format->setTimeZone(*zone);
|
|
|
|
UnicodeString dateReturned, expectedResult;
|
2007-08-11 20:32:54 +00:00
|
|
|
dateReturned.remove();
|
2007-08-03 18:43:04 +00:00
|
|
|
dateReturned = format->format(sampleDate, dateReturned, status);
|
2008-06-28 07:02:26 +00:00
|
|
|
expectedResult=UnicodeString("14. Okt 8:58", -1, US_INV);
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( dateReturned != expectedResult ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Simple test in getBestPattern with Locale::getGermany()).");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
// add new pattern
|
2007-08-07 03:14:19 +00:00
|
|
|
status = U_ZERO_ERROR;
|
2008-06-28 07:02:26 +00:00
|
|
|
conflictingStatus = gen->addPattern(UnicodeString("d'. von' MMMM", -1, US_INV), true, conflictingPattern, status);
|
2007-08-07 03:14:19 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln("ERROR: Could not addPattern - d\'. von\' MMMM");
|
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
UnicodeString testPattern=gen->getBestPattern(UnicodeString("MMMMdd"), status);
|
|
|
|
testPattern=gen->getBestPattern(UnicodeString("MMMddHmm"), status);
|
|
|
|
format->applyPattern(gen->getBestPattern(UnicodeString("MMMMddHmm"), status));
|
2007-08-11 20:32:54 +00:00
|
|
|
dateReturned.remove();
|
2007-08-03 18:43:04 +00:00
|
|
|
dateReturned = format->format(sampleDate, dateReturned, status);
|
2008-06-28 07:02:26 +00:00
|
|
|
expectedResult=UnicodeString("14. von Oktober 8:58", -1, US_INV);
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( dateReturned != expectedResult ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Simple test addPattern failed!: d\'. von\' MMMM ");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
delete format;
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
// get a pattern and modify it
|
|
|
|
format = (SimpleDateFormat *)DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull,
|
|
|
|
deLocale);
|
|
|
|
format->setTimeZone(*zone);
|
|
|
|
UnicodeString pattern;
|
|
|
|
pattern = format->toPattern(pattern);
|
2007-08-11 20:32:54 +00:00
|
|
|
dateReturned.remove();
|
2007-08-03 18:43:04 +00:00
|
|
|
dateReturned = format->format(sampleDate, dateReturned, status);
|
2007-08-07 03:14:19 +00:00
|
|
|
expectedResult=UnicodeString("Donnerstag, 14. Oktober 1999 08:58:59 Frankreich");
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( dateReturned != expectedResult ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Simple test uses full date format.");
|
|
|
|
errln(UnicodeString(" Got: ") + dateReturned + UnicodeString(" Expected: ") + expectedResult);
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// modify it to change the zone.
|
|
|
|
UnicodeString newPattern = gen->replaceFieldTypes(pattern, UnicodeString("vvvv"), status);
|
|
|
|
format->applyPattern(newPattern);
|
2007-08-11 20:32:54 +00:00
|
|
|
dateReturned.remove();
|
2007-08-03 18:43:04 +00:00
|
|
|
dateReturned = format->format(sampleDate, dateReturned, status);
|
2007-08-07 03:14:19 +00:00
|
|
|
expectedResult=UnicodeString("Donnerstag, 14. Oktober 1999 08:58:59 Frankreich");
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( dateReturned != expectedResult ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Simple test modify the timezone!");
|
|
|
|
errln(UnicodeString(" Got: ")+ dateReturned + UnicodeString(" Expected: ") + expectedResult);
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
// setDeciaml(), getDeciaml()
|
|
|
|
gen->setDecimal(newDecimal);
|
|
|
|
if (newDecimal != gen->getDecimal()) {
|
|
|
|
errln("ERROR: unexpected result from setDecimal() and getDecimal()!.\n");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
|
|
|
|
// setAppenItemName() , getAppendItemName()
|
|
|
|
gen->setAppendItemName(UDATPG_HOUR_FIELD, newAppendItemName);
|
|
|
|
if (newAppendItemName != gen->getAppendItemName(UDATPG_HOUR_FIELD)) {
|
|
|
|
errln("ERROR: unexpected result from setAppendItemName() and getAppendItemName()!.\n");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
|
|
|
|
// setAppenItemFormat() , getAppendItemFormat()
|
|
|
|
gen->setAppendItemFormat(UDATPG_HOUR_FIELD, newAppendItemFormat);
|
|
|
|
if (newAppendItemFormat != gen->getAppendItemFormat(UDATPG_HOUR_FIELD)) {
|
|
|
|
errln("ERROR: unexpected result from setAppendItemFormat() and getAppendItemFormat()!.\n");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
// setDateTimeFormat() , getDateTimeFormat()
|
|
|
|
gen->setDateTimeFormat(newDateTimeFormat);
|
|
|
|
if (newDateTimeFormat != gen->getDateTimeFormat()) {
|
|
|
|
errln("ERROR: unexpected result from setDateTimeFormat() and getDateTimeFormat()!.\n");
|
|
|
|
}
|
2007-08-07 23:16:36 +00:00
|
|
|
|
|
|
|
// ======== Test getSkeleton and getBaseSkeleton
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
pattern = UnicodeString("dd-MMM");
|
|
|
|
UnicodeString expectedSkeleton = UnicodeString("MMMdd");
|
|
|
|
UnicodeString expectedBaseSkeleton = UnicodeString("MMMd");
|
|
|
|
UnicodeString retSkeleton = gen->getSkeleton(pattern, status);
|
|
|
|
if(U_FAILURE(status) || retSkeleton != expectedSkeleton ) {
|
|
|
|
errln("ERROR: Unexpected result from getSkeleton().\n");
|
|
|
|
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected: ") + expectedSkeleton );
|
|
|
|
}
|
|
|
|
retSkeleton = gen->getBaseSkeleton(pattern, status);
|
|
|
|
if(U_FAILURE(status) || retSkeleton != expectedBaseSkeleton) {
|
|
|
|
errln("ERROR: Unexpected result from getBaseSkeleton().\n");
|
|
|
|
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected:")+ expectedBaseSkeleton);
|
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
|
2007-08-07 23:16:36 +00:00
|
|
|
pattern = UnicodeString("dd/MMMM/yy");
|
|
|
|
expectedSkeleton = UnicodeString("yyMMMMdd");
|
|
|
|
expectedBaseSkeleton = UnicodeString("yMMMd");
|
|
|
|
retSkeleton = gen->getSkeleton(pattern, status);
|
|
|
|
if(U_FAILURE(status) || retSkeleton != expectedSkeleton ) {
|
|
|
|
errln("ERROR: Unexpected result from getSkeleton().\n");
|
|
|
|
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected: ") + expectedSkeleton );
|
|
|
|
}
|
|
|
|
retSkeleton = gen->getBaseSkeleton(pattern, status);
|
|
|
|
if(U_FAILURE(status) || retSkeleton != expectedBaseSkeleton) {
|
|
|
|
errln("ERROR: Unexpected result from getBaseSkeleton().\n");
|
|
|
|
errln(UnicodeString(" Got: ") + retSkeleton + UnicodeString(" Expected:")+ expectedBaseSkeleton);
|
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
delete format;
|
|
|
|
delete zone;
|
|
|
|
delete gen;
|
2007-08-03 18:43:04 +00:00
|
|
|
|
2008-01-03 01:40:16 +00:00
|
|
|
{
|
|
|
|
// Trac# 6104
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
pattern = UnicodeString("YYYYMMM");
|
2008-11-18 18:27:40 +00:00
|
|
|
UnicodeString expR = CharsToUnicodeString("1999\\u5E741\\u6708"); // fixed expected result per ticket:6626:
|
2008-01-03 01:40:16 +00:00
|
|
|
Locale loc("ja");
|
|
|
|
UDate testDate1= LocaleTest::date(99, 0, 13, 23, 58, 59);
|
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
|
|
|
|
UnicodeString rDate;
|
|
|
|
SimpleDateFormat sdf(bPattern, loc, status);
|
|
|
|
rDate.remove();
|
|
|
|
rDate = sdf.format(testDate1, rDate);
|
|
|
|
|
|
|
|
logln(UnicodeString(" ja locale with skeleton: YYYYMMM Best Pattern:") + bPattern);
|
|
|
|
logln(UnicodeString(" Formatted date:") + rDate);
|
|
|
|
|
|
|
|
if ( expR!= rDate ) {
|
|
|
|
errln(UnicodeString("\nERROR: Test Japanese month hack Got: ") + rDate +
|
|
|
|
UnicodeString(" Expected: ") + expR );
|
|
|
|
}
|
2008-02-08 07:10:28 +00:00
|
|
|
|
2008-01-03 01:40:16 +00:00
|
|
|
delete patGen;
|
|
|
|
}
|
|
|
|
{ // Trac# 6104
|
|
|
|
Locale loc("zh");
|
2008-11-18 18:27:40 +00:00
|
|
|
UnicodeString expR = CharsToUnicodeString("1999\\u5E741\\u6708"); // fixed expected result per ticket:6626:
|
2008-01-03 01:40:16 +00:00
|
|
|
UDate testDate1= LocaleTest::date(99, 0, 13, 23, 58, 59);
|
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
|
|
|
|
UnicodeString rDate;
|
|
|
|
SimpleDateFormat sdf(bPattern, loc, status);
|
|
|
|
rDate.remove();
|
|
|
|
rDate = sdf.format(testDate1, rDate);
|
|
|
|
|
|
|
|
logln(UnicodeString(" zh locale with skeleton: YYYYMMM Best Pattern:") + bPattern);
|
|
|
|
logln(UnicodeString(" Formatted date:") + rDate);
|
|
|
|
if ( expR!= rDate ) {
|
|
|
|
errln(UnicodeString("\nERROR: Test Chinese month hack Got: ") + rDate +
|
|
|
|
UnicodeString(" Expected: ") + expR );
|
|
|
|
}
|
|
|
|
delete patGen;
|
|
|
|
}
|
2008-02-08 07:10:28 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Trac# 6172 duplicate time pattern
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
pattern = UnicodeString("hmv");
|
2008-11-18 18:27:40 +00:00
|
|
|
UnicodeString expR = UnicodeString("h:mm a v"); // avail formats has hm -> "h:mm a" (fixed expected result per ticket:6626:)
|
2008-02-08 07:10:28 +00:00
|
|
|
Locale loc("en");
|
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString bPattern = patGen->getBestPattern(pattern, status);
|
|
|
|
logln(UnicodeString(" en locale with skeleton: hmv Best Pattern:") + bPattern);
|
|
|
|
|
|
|
|
if ( expR!= bPattern ) {
|
|
|
|
errln(UnicodeString("\nERROR: Test EN time format Got: ") + bPattern +
|
|
|
|
UnicodeString(" Expected: ") + expR );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete patGen;
|
|
|
|
}
|
|
|
|
|
2008-01-03 01:40:16 +00:00
|
|
|
|
2007-08-03 18:43:04 +00:00
|
|
|
// ======= Test various skeletons.
|
|
|
|
logln("Testing DateTimePatternGenerator with various skeleton");
|
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
int32_t localeIndex=0;
|
|
|
|
int32_t resultIndex=0;
|
|
|
|
UnicodeString resultDate;
|
|
|
|
UDate testDate= LocaleTest::date(99, 0, 13, 23, 58, 59);
|
|
|
|
while (localeIndex < MAX_LOCALE )
|
|
|
|
{
|
|
|
|
int32_t dataIndex=0;
|
|
|
|
UnicodeString bestPattern;
|
|
|
|
|
2008-11-19 04:19:02 +00:00
|
|
|
Locale loc(testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2], testLocale[localeIndex][3]);
|
|
|
|
logln("\n\n Locale: %s_%s_%s@%s", testLocale[localeIndex][0], testLocale[localeIndex][1], testLocale[localeIndex][2], testLocale[localeIndex][3]);
|
2007-08-03 18:43:04 +00:00
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(loc, status);
|
|
|
|
if(U_FAILURE(status)) {
|
2007-08-07 03:14:19 +00:00
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator with locale index:%d . - exitting\n", localeIndex);
|
|
|
|
return;
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
while (patternData[dataIndex].length() > 0) {
|
2007-08-11 20:32:54 +00:00
|
|
|
log(patternData[dataIndex]);
|
2007-08-03 18:43:04 +00:00
|
|
|
bestPattern = patGen->getBestPattern(patternData[dataIndex++], status);
|
2007-08-11 20:32:54 +00:00
|
|
|
logln(UnicodeString(" -> ") + bestPattern);
|
2007-08-03 18:43:04 +00:00
|
|
|
|
2007-08-07 07:22:18 +00:00
|
|
|
SimpleDateFormat sdf(bestPattern, loc, status);
|
2007-08-11 20:32:54 +00:00
|
|
|
resultDate.remove();
|
2007-08-07 07:22:18 +00:00
|
|
|
resultDate = sdf.format(testDate, resultDate);
|
2007-08-03 18:43:04 +00:00
|
|
|
if ( resultDate != patternResults[resultIndex] ) {
|
2008-11-18 18:27:40 +00:00
|
|
|
errln(UnicodeString("\nERROR: Test various skeletons[") + (dataIndex-1) + UnicodeString("], localeIndex ") + localeIndex +
|
|
|
|
UnicodeString(". Got: ") + resultDate + UnicodeString(" Expected: ") + patternResults[resultIndex] );
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resultIndex++;
|
|
|
|
}
|
|
|
|
delete patGen;
|
|
|
|
localeIndex++;
|
|
|
|
}
|
2007-12-22 05:30:33 +00:00
|
|
|
|
|
|
|
// ======= More tests ticket#6110
|
|
|
|
logln("Testing DateTimePatternGenerator with various skeleton");
|
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
localeIndex=0;
|
|
|
|
resultIndex=0;
|
|
|
|
testDate= LocaleTest::date(99, 9, 13, 23, 58, 59);
|
|
|
|
{
|
|
|
|
int32_t dataIndex=0;
|
|
|
|
UnicodeString bestPattern;
|
|
|
|
logln("\n\n Test various skeletons for English locale...");
|
|
|
|
DateTimePatternGenerator *patGen=DateTimePatternGenerator::createInstance(Locale::getEnglish(), status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator with locale English . - exitting\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TimeZone *enZone = TimeZone::createTimeZone(UnicodeString("ECT/GMT"));
|
|
|
|
if (enZone==NULL) {
|
|
|
|
dataerrln("ERROR: Could not create TimeZone ECT");
|
|
|
|
delete patGen;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SimpleDateFormat *enFormat = (SimpleDateFormat *)DateFormat::createDateTimeInstance(DateFormat::kFull,
|
|
|
|
DateFormat::kFull, Locale::getEnglish());
|
|
|
|
enFormat->setTimeZone(*enZone);
|
|
|
|
while (patternTests2[dataIndex].length() > 0) {
|
|
|
|
logln(patternTests2[dataIndex]);
|
|
|
|
bestPattern = patGen->getBestPattern(patternTests2[dataIndex], status);
|
|
|
|
logln(UnicodeString(" -> ") + bestPattern);
|
|
|
|
enFormat->applyPattern(bestPattern);
|
|
|
|
resultDate.remove();
|
|
|
|
resultDate = enFormat->format(testDate, resultDate);
|
|
|
|
if ( resultDate != patternResults2[resultIndex] ) {
|
|
|
|
errln(UnicodeString("\nERROR: Test various skeletons[") + dataIndex
|
|
|
|
+ UnicodeString("]. Got: ") + resultDate + UnicodeString(" Expected: ") +
|
|
|
|
patternResults2[resultIndex] );
|
|
|
|
}
|
|
|
|
dataIndex++;
|
|
|
|
resultIndex++;
|
|
|
|
}
|
|
|
|
delete patGen;
|
|
|
|
delete enZone;
|
|
|
|
delete enFormat;
|
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ======= Test random skeleton
|
|
|
|
DateTimePatternGenerator *randDTGen= DateTimePatternGenerator::createInstance(status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
dataerrln("ERROR: Could not create DateTimePatternGenerator (Locale::getFrench()) - exitting");
|
|
|
|
return;
|
|
|
|
}
|
2007-08-07 23:16:36 +00:00
|
|
|
UChar newChar;
|
2007-09-06 18:00:08 +00:00
|
|
|
int32_t i;
|
|
|
|
for (i=0; i<10; ++i) {
|
2007-08-11 20:32:54 +00:00
|
|
|
UnicodeString randomSkeleton;
|
2007-08-03 18:43:04 +00:00
|
|
|
int32_t len = rand() % 20;
|
|
|
|
for (int32_t j=0; j<len; ++j ) {
|
2007-08-11 20:32:54 +00:00
|
|
|
while ((newChar = (UChar)(rand()%0x7f))>=(UChar)0x20) {
|
2007-08-07 23:16:36 +00:00
|
|
|
randomSkeleton += newChar;
|
|
|
|
}
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
UnicodeString bestPattern = randDTGen->getBestPattern(randomSkeleton, status);
|
|
|
|
}
|
|
|
|
delete randDTGen;
|
|
|
|
|
|
|
|
// UnicodeString randomString=Unicode
|
|
|
|
// ======= Test getStaticClassID()
|
|
|
|
|
|
|
|
logln("Testing getStaticClassID()");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
DateTimePatternGenerator *test= DateTimePatternGenerator::createInstance(status);
|
|
|
|
|
|
|
|
if(test->getDynamicClassID() != DateTimePatternGenerator::getStaticClassID()) {
|
|
|
|
errln("ERROR: getDynamicClassID() didn't return the expected value");
|
|
|
|
}
|
2007-08-07 03:14:19 +00:00
|
|
|
delete test;
|
2007-08-03 18:43:04 +00:00
|
|
|
|
|
|
|
// ====== Test createEmptyInstance()
|
|
|
|
|
|
|
|
logln("Testing createEmptyInstance()");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
test = DateTimePatternGenerator::createEmptyInstance(status);
|
|
|
|
if(U_FAILURE(status)) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Fail to create an empty instance ! - exitting.\n");
|
|
|
|
delete test;
|
|
|
|
return;
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conflictingStatus = test->addPattern(UnicodeString("MMMMd"), true, conflictingPattern, status);
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
testPattern=test->getBestPattern(UnicodeString("MMMMdd"), status);
|
|
|
|
conflictingStatus = test->addPattern(UnicodeString("HH:mm"), true, conflictingPattern, status);
|
|
|
|
conflictingStatus = test->addPattern(UnicodeString("MMMMMd"), true, conflictingPattern, status); //duplicate pattern
|
|
|
|
StringEnumeration *output=NULL;
|
|
|
|
output = test->getRedundants(status);
|
|
|
|
expectedResult=UnicodeString("MMMMd");
|
|
|
|
if (output != NULL) {
|
|
|
|
output->reset(status);
|
|
|
|
const UnicodeString *dupPattern=output->snext(status);
|
|
|
|
if ( (dupPattern==NULL) || (*dupPattern != expectedResult) ) {
|
2007-08-07 03:14:19 +00:00
|
|
|
errln("ERROR: Fail in getRedundants !\n");
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-07 03:14:19 +00:00
|
|
|
// ======== Test getSkeletons and getBaseSkeletons
|
2007-09-06 18:00:08 +00:00
|
|
|
StringEnumeration* ptrSkeletonEnum = test->getSkeletons(status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("ERROR: Fail to get skeletons !\n");
|
|
|
|
}
|
|
|
|
UnicodeString returnPattern, *ptrSkeleton;
|
|
|
|
ptrSkeletonEnum->reset(status);
|
|
|
|
int32_t count=ptrSkeletonEnum->count(status);
|
|
|
|
for (i=0; i<count; ++i) {
|
|
|
|
ptrSkeleton = (UnicodeString *)ptrSkeletonEnum->snext(status);
|
|
|
|
returnPattern = test->getPatternForSkeleton(*ptrSkeleton);
|
|
|
|
if ( returnPattern != testSkeletonsResults[i] ) {
|
|
|
|
errln(UnicodeString("ERROR: Unexpected result from getSkeletons and getPatternForSkeleton\nGot: ") + returnPattern
|
|
|
|
+ UnicodeString("\nExpected: ") + testSkeletonsResults[i]
|
|
|
|
+ UnicodeString("\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StringEnumeration* ptrBaseSkeletonEnum = test->getBaseSkeletons(status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("ERROR: Fail to get base skeletons !\n");
|
|
|
|
}
|
|
|
|
count=ptrBaseSkeletonEnum->count(status);
|
|
|
|
for (i=0; i<count; ++i) {
|
|
|
|
ptrSkeleton = (UnicodeString *)ptrBaseSkeletonEnum->snext(status);
|
|
|
|
if ( *ptrSkeleton != testBaseSkeletonsResults[i] ) {
|
|
|
|
errln("ERROR: Unexpected result from getBaseSkeletons() !\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-18 00:00:00 +00:00
|
|
|
// ========= DateTimePatternGenerator sample code in Userguide
|
|
|
|
// set up the generator
|
|
|
|
Locale locale = Locale::getFrench();
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
DateTimePatternGenerator *generator = DateTimePatternGenerator::createInstance( locale, status);
|
|
|
|
|
|
|
|
// get a pattern for an abbreviated month and day
|
|
|
|
pattern = generator->getBestPattern(UnicodeString("MMMd"), status);
|
2007-12-06 18:33:45 +00:00
|
|
|
SimpleDateFormat formatter(pattern, locale, status);
|
2007-09-18 00:00:00 +00:00
|
|
|
|
2007-10-09 20:22:16 +00:00
|
|
|
zone = TimeZone::createTimeZone(UnicodeString("GMT"));
|
2007-12-06 18:33:45 +00:00
|
|
|
formatter.setTimeZone(*zone);
|
2007-09-18 00:00:00 +00:00
|
|
|
// use it to format (or parse)
|
|
|
|
UnicodeString formatted;
|
2007-12-06 18:33:45 +00:00
|
|
|
formatted = formatter.format(Calendar::getNow(), formatted, status);
|
2007-09-18 00:00:00 +00:00
|
|
|
// for French, the result is "13 sept."
|
|
|
|
formatted.remove();
|
2007-12-22 05:30:33 +00:00
|
|
|
// cannot use the result from getNow() because the value change evreyday.
|
|
|
|
testDate= LocaleTest::date(99, 0, 13, 23, 58, 59);
|
2007-12-06 18:33:45 +00:00
|
|
|
formatted = formatter.format(testDate, formatted, status);
|
2007-10-09 20:22:16 +00:00
|
|
|
expectedResult=UnicodeString("14 janv.");
|
2007-09-18 00:00:00 +00:00
|
|
|
if ( formatted != expectedResult ) {
|
|
|
|
errln("ERROR: Userguide sample code result!");
|
|
|
|
errln(UnicodeString(" Got: ")+ formatted + UnicodeString(" Expected: ") + expectedResult);
|
|
|
|
}
|
|
|
|
|
2007-10-09 20:22:16 +00:00
|
|
|
delete zone;
|
2007-09-06 18:00:08 +00:00
|
|
|
delete output;
|
|
|
|
delete ptrSkeletonEnum;
|
|
|
|
delete ptrBaseSkeletonEnum;
|
|
|
|
delete test;
|
2007-09-18 00:00:00 +00:00
|
|
|
delete generator;
|
2007-08-03 18:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|