Index: source/test/cintltst/cdattst.c |
diff --git a/source/test/cintltst/cdattst.c b/source/test/cintltst/cdattst.c |
index 0b10f5e063d61ad2b31f83bceda3aeb6da5ea8b9..ac3a1b27577686a86d2cb36959bc87d46868a7ee 100644 |
--- a/source/test/cintltst/cdattst.c |
+++ b/source/test/cintltst/cdattst.c |
@@ -1,6 +1,6 @@ |
/******************************************************************** |
* COPYRIGHT: |
- * Copyright (c) 1997-2013, International Business Machines Corporation and |
+ * Copyright (c) 1997-2014, International Business Machines Corporation and |
* others. All Rights Reserved. |
********************************************************************/ |
/******************************************************************************** |
@@ -55,6 +55,7 @@ void addDateForTest(TestNode** root) |
TESTCASE(TestRelativeCrash); |
TESTCASE(TestContext); |
TESTCASE(TestCalendarDateParse); |
+ TESTCASE(TestOverrideNumberFormat); |
} |
/* Testing the DateFormat API */ |
static void TestDateFormat() |
@@ -66,6 +67,7 @@ static void TestDateFormat() |
UChar* result = NULL; |
const UCalendar *cal; |
const UNumberFormat *numformat1, *numformat2; |
+ UNumberFormat *adoptNF; |
UChar temp[50]; |
int32_t numlocales; |
UDate d1; |
@@ -185,7 +187,7 @@ static void TestDateFormat() |
} |
/*format using fr */ |
- u_unescape("10 juil. 1996 16:05:28 heure avanc\\u00E9e du Pacifique", temp, 50); |
+ u_unescape("10 juil. 1996 16:05:28 heure d\\u2019\\u00E9t\\u00E9 du Pacifique", temp, 50); |
if(result != NULL) { |
free(result); |
result = NULL; |
@@ -197,7 +199,7 @@ static void TestDateFormat() |
log_data_err("FAIL: Date Format for french locale failed using udat_format().\n" ); |
/*format using it */ |
- u_uastrcpy(temp, "10/lug/1996 16:05:28"); |
+ u_uastrcpy(temp, "10 lug 1996, 16:05:28"); |
{ |
UChar *fmtted; |
@@ -338,6 +340,16 @@ static void TestDateFormat() |
log_err("FAIL: error in setNumberFormat or getNumberFormat()\n"); |
else |
log_verbose("PASS:setNumberFormat and getNumberFormat succesful\n"); |
+ |
+ /*Test getNumberFormat() and adoptNumberFormat() */ |
+ log_verbose("\nTesting the get and adopt NumberFormat properties of date format\n"); |
+ adoptNF= unum_open(UNUM_DEFAULT, NULL, 0, NULL, NULL, &status); |
+ udat_adoptNumberFormat(def1, adoptNF); |
+ numformat2=udat_getNumberFormat(def1); |
+ if(u_strcmp(myNumformat(adoptNF, num), myNumformat(numformat2, num)) !=0) |
+ log_err("FAIL: error in adoptNumberFormat or getNumberFormat()\n"); |
+ else |
+ log_verbose("PASS:adoptNumberFormat and getNumberFormat succesful\n"); |
/*try setting the number format to another format */ |
numformat1=udat_getNumberFormat(def); |
@@ -553,7 +565,7 @@ static void TestRelativeDateFormat() |
/*Testing udat_getSymbols() and udat_setSymbols() and udat_countSymbols()*/ |
static void TestSymbols() |
{ |
- UDateFormat *def, *fr; |
+ UDateFormat *def, *fr, *zhChiCal; |
UErrorCode status = U_ZERO_ERROR; |
UChar *value=NULL; |
UChar *result = NULL; |
@@ -583,6 +595,15 @@ static void TestSymbols() |
myErrorName(status) ); |
return; |
} |
+ /*creating a dateformat with zh locale */ |
+ log_verbose("\ncreating a date format with zh locale for chinese calendar\n"); |
+ zhChiCal = udat_open(UDAT_NONE, UDAT_FULL, "zh@calendar=chinese", NULL, 0, NULL, 0, &status); |
+ if(U_FAILURE(status)) |
+ { |
+ log_data_err("error in creating the dateformat using full date, no time, locale zh@calendar=chinese -> %s (Are you missing data?)\n", |
+ myErrorName(status) ); |
+ return; |
+ } |
/*Testing countSymbols, getSymbols and setSymbols*/ |
@@ -592,7 +613,8 @@ static void TestSymbols() |
udat_countSymbols(def, UDAT_SHORT_MONTHS)!=12 || udat_countSymbols(def, UDAT_WEEKDAYS)!=8 || |
udat_countSymbols(def, UDAT_SHORT_WEEKDAYS)!=8 || udat_countSymbols(def, UDAT_AM_PMS)!=2 || |
udat_countSymbols(def, UDAT_QUARTERS) != 4 || udat_countSymbols(def, UDAT_SHORT_QUARTERS) != 4 || |
- udat_countSymbols(def, UDAT_LOCALIZED_CHARS)!=1 || udat_countSymbols(def, UDAT_SHORTER_WEEKDAYS)!=8) |
+ udat_countSymbols(def, UDAT_LOCALIZED_CHARS)!=1 || udat_countSymbols(def, UDAT_SHORTER_WEEKDAYS)!=8 || |
+ udat_countSymbols(zhChiCal, UDAT_CYCLIC_YEARS_NARROW)!=60 || udat_countSymbols(zhChiCal, UDAT_ZODIAC_NAMES_NARROW)!=12) |
{ |
log_err("FAIL: error in udat_countSymbols\n"); |
} |
@@ -647,7 +669,11 @@ static void TestSymbols() |
VerifygetSymbols(def, UDAT_QUARTERS, 3, "4th quarter"); |
VerifygetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "T2"); |
VerifygetSymbols(def, UDAT_SHORT_QUARTERS, 2, "Q3"); |
- VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXx"); |
+ VerifygetSymbols(zhChiCal, UDAT_CYCLIC_YEARS_ABBREVIATED, 0, "\\u7532\\u5B50"); |
+ VerifygetSymbols(zhChiCal, UDAT_CYCLIC_YEARS_NARROW, 59, "\\u7678\\u4EA5"); |
+ VerifygetSymbols(zhChiCal, UDAT_ZODIAC_NAMES_ABBREVIATED, 0, "\\u9F20"); |
+ VerifygetSymbols(zhChiCal, UDAT_ZODIAC_NAMES_WIDE, 11, "\\u732A"); |
+ VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr"); |
if(result != NULL) { |
@@ -761,8 +787,10 @@ free(pattern); |
VerifysetSymbols(fr, UDAT_SHORT_QUARTERS, 1, "QQ2"); |
VerifysetSymbols(fr, UDAT_STANDALONE_QUARTERS, 2, "3rd Quar."); |
VerifysetSymbols(fr, UDAT_STANDALONE_SHORT_QUARTERS, 3, "4QQ"); |
+ VerifysetSymbols(zhChiCal, UDAT_CYCLIC_YEARS_ABBREVIATED, 1, "yi-chou"); |
+ VerifysetSymbols(zhChiCal, UDAT_ZODIAC_NAMES_ABBREVIATED, 1, "Ox"); |
+ |
- |
/*run series of tests to test get and setSymbols regressively*/ |
log_verbose("\nTesting get and set symbols regressively\n"); |
VerifygetsetSymbols(fr, def, UDAT_WEEKDAYS, 1); |
@@ -780,6 +808,7 @@ free(pattern); |
udat_close(fr); |
udat_close(def); |
+ udat_close(zhChiCal); |
if(result != NULL) { |
free(result); |
result = NULL; |
@@ -990,10 +1019,10 @@ static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in |
UErrorCode status = U_ZERO_ERROR; |
UChar *result=NULL; |
int32_t resultlength, resultlengthout; |
- |
+ int32_t patternSize = strlen(expected) + 1; |
- pattern=(UChar*)malloc(sizeof(UChar) * (strlen(expected)+1)); |
- u_uastrcpy(pattern, expected); |
+ pattern=(UChar*)malloc(sizeof(UChar) * patternSize); |
+ u_unescape(expected, pattern, patternSize); |
resultlength=0; |
resultlengthout=udat_getSymbols(datfor, type, idx , NULL, resultlength, &status); |
if(status==U_BUFFER_OVERFLOW_ERROR) |
@@ -1012,8 +1041,8 @@ static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in |
if(u_strcmp(result, pattern)==0) |
log_verbose("PASS: getSymbols retrieved the right value\n"); |
else{ |
- log_data_err("FAIL: getSymbols retrieved the wrong value\n Expected %s Got %s\n", austrdup(pattern), |
- austrdup(result) ); |
+ log_data_err("FAIL: getSymbols retrieved the wrong value\n Expected %s Got %s\n", expected, |
+ aescstrdup(result,-1) ); |
} |
free(result); |
free(pattern); |
@@ -1025,10 +1054,11 @@ static void VerifysetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in |
UChar *value=NULL; |
int32_t resultlength, resultlengthout; |
UErrorCode status = U_ZERO_ERROR; |
+ int32_t valueLen, valueSize = strlen(expected) + 1; |
- value=(UChar*)malloc(sizeof(UChar) * (strlen(expected) + 1)); |
- u_uastrcpy(value, expected); |
- udat_setSymbols(datfor, type, idx, value, u_strlen(value), &status); |
+ value=(UChar*)malloc(sizeof(UChar) * valueSize); |
+ valueLen = u_unescape(expected, value, valueSize); |
+ udat_setSymbols(datfor, type, idx, value, valueLen, &status); |
if(U_FAILURE(status)) |
{ |
log_err("FAIL: Error in udat_setSymbols() %s\n", myErrorName(status) ); |
@@ -1050,8 +1080,8 @@ static void VerifysetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in |
} |
if(u_strcmp(result, value)!=0){ |
- log_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", austrdup(value), |
- austrdup(result) ); |
+ log_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", expected, |
+ aescstrdup(result,-1) ); |
} |
else |
log_verbose("PASS: setSymbols successful\n"); |
@@ -1390,32 +1420,58 @@ static const TestContextItem textContextItems[] = { |
{ NULL, NULL, (UDisplayContext)0, NULL } |
}; |
-static const UDate july022008 = 1215000001979.0; |
+static const UChar today_enDefault[] = { 0x74,0x6F,0x64,0x61,0x79,0 }; /* "today" */ |
+static const UChar today_enTitle[] = { 0x54,0x6F,0x64,0x61,0x79,0 }; /* "Today" sentence-begin, uiListOrMenu, standalone */ |
+static const UChar yesterday_enDefault[] = { 0x79,0x65,0x73,0x74,0x65,0x72,0x64,0x61,0x79,0 }; /* "yesterday" */ |
+static const UChar yesterday_enTitle[] = { 0x59,0x65,0x73,0x74,0x65,0x72,0x64,0x61,0x79,0 }; /* "Yesterday" sentence-begin, uiListOrMenu, standalone */ |
+static const UChar today_nbDefault[] = { 0x69,0x20,0x64,0x61,0x67,0 }; /* "i dag" */ |
+static const UChar today_nbTitle[] = { 0x49,0x20,0x64,0x61,0x67,0 }; /* "I dag" sentence-begin, standalone */ |
+static const UChar yesterday_nbDefault[] = { 0x69,0x20,0x67,0xE5,0x72,0 }; |
+static const UChar yesterday_nbTitle[] = { 0x49,0x20,0x67,0xE5,0x72,0 }; |
+ |
+typedef struct { |
+ const char * locale; |
+ UDisplayContext capitalizationContext; |
+ const UChar * expectedFormatToday; |
+ const UChar * expectedFormatYesterday; |
+} TestRelativeContextItem; |
+ |
+static const TestRelativeContextItem textContextRelativeItems[] = { |
+ { "en", UDISPCTX_CAPITALIZATION_NONE, today_enDefault, yesterday_enDefault }, |
+#if !UCONFIG_NO_BREAK_ITERATION |
+ { "en", UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, today_enDefault, yesterday_enDefault }, |
+ { "en", UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, today_enTitle, yesterday_enTitle }, |
+ { "en", UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, today_enTitle, yesterday_enTitle }, |
+ { "en", UDISPCTX_CAPITALIZATION_FOR_STANDALONE, today_enTitle, yesterday_enTitle }, |
+#endif |
+ { "nb", UDISPCTX_CAPITALIZATION_NONE, today_nbDefault, yesterday_nbDefault }, |
+#if !UCONFIG_NO_BREAK_ITERATION |
+ { "nb", UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, today_nbDefault, yesterday_nbDefault }, |
+ { "nb", UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, today_nbTitle, yesterday_nbTitle }, |
+ { "nb", UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, today_nbDefault, yesterday_nbDefault }, |
+ { "nb", UDISPCTX_CAPITALIZATION_FOR_STANDALONE, today_nbTitle, yesterday_nbTitle }, |
+#endif |
+ { NULL, (UDisplayContext)0, NULL, NULL } |
+}; |
+ |
+static const UChar zoneGMT[] = { 0x47,0x4D,0x54,0 }; /* "GMT" */ |
+static const UDate july022008 = 1215000000000.0; |
enum { kUbufMax = 64, kBbufMax = 3*kUbufMax }; |
static void TestContext(void) { |
- const TestContextItem* textContextItemPtr = textContextItems; |
- for (; textContextItemPtr->locale != NULL; ++textContextItemPtr) { |
+ const TestContextItem* textContextItemPtr; |
+ const TestRelativeContextItem* textRelContextItemPtr; |
+ for (textContextItemPtr = textContextItems; textContextItemPtr->locale != NULL; ++textContextItemPtr) { |
UErrorCode status = U_ZERO_ERROR; |
- UDateFormat* udfmt = udat_open(UDAT_NONE, UDAT_MEDIUM, textContextItemPtr->locale, NULL, 0, NULL, 0, &status); |
- if ( U_FAILURE(status) ) { |
- log_data_err("FAIL: udat_open for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); |
- } else { |
- UDateTimePatternGenerator* udtpg = udatpg_open(textContextItemPtr->locale, &status); |
- if ( U_FAILURE(status) ) { |
- log_err("FAIL: udatpg_open for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); |
- } else { |
- UChar ubuf[kUbufMax]; |
- int32_t len = udatpg_getBestPattern(udtpg, textContextItemPtr->skeleton, -1, ubuf, kUbufMax, &status); |
- if ( U_FAILURE(status) ) { |
- log_err("FAIL: udatpg_getBestPattern for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); |
- } else { |
- udat_applyPattern(udfmt, FALSE, ubuf, len); |
+ UDateTimePatternGenerator* udtpg = udatpg_open(textContextItemPtr->locale, &status); |
+ if ( U_SUCCESS(status) ) { |
+ UChar ubuf[kUbufMax]; |
+ int32_t len = udatpg_getBestPattern(udtpg, textContextItemPtr->skeleton, -1, ubuf, kUbufMax, &status); |
+ if ( U_SUCCESS(status) ) { |
+ UDateFormat* udfmt = udat_open(UDAT_PATTERN, UDAT_PATTERN, textContextItemPtr->locale, zoneGMT, -1, ubuf, len, &status); |
+ if ( U_SUCCESS(status) ) { |
udat_setContext(udfmt, textContextItemPtr->capitalizationContext, &status); |
- if ( U_FAILURE(status) ) { |
- log_err("FAIL: udat_setContext for locale %s, capitalizationContext %d, status %s\n", |
- textContextItemPtr->locale, (int)textContextItemPtr->capitalizationContext, u_errorName(status) ); |
- } else { |
+ if ( U_SUCCESS(status) ) { |
UDisplayContext getContext; |
len = udat_format(udfmt, july022008, ubuf, kUbufMax, NULL, &status); |
if ( U_FAILURE(status) ) { |
@@ -1437,13 +1493,187 @@ static void TestContext(void) { |
log_err("FAIL: udat_getContext for locale %s, capitalizationContext %d, got context %d\n", |
textContextItemPtr->locale, (int)textContextItemPtr->capitalizationContext, (int)getContext ); |
} |
+ } else { |
+ log_err("FAIL: udat_setContext for locale %s, capitalizationContext %d, status %s\n", |
+ textContextItemPtr->locale, (int)textContextItemPtr->capitalizationContext, u_errorName(status) ); |
} |
+ udat_close(udfmt); |
+ } else { |
+ log_data_err("FAIL: udat_open for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); |
} |
- udatpg_close(udtpg); |
+ } else { |
+ log_err("FAIL: udatpg_getBestPattern for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); |
} |
- udat_close(udfmt); |
+ udatpg_close(udtpg); |
+ } else { |
+ log_data_err("FAIL: udatpg_open for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); |
} |
} |
+ for (textRelContextItemPtr = textContextRelativeItems; textRelContextItemPtr->locale != NULL; ++textRelContextItemPtr) { |
+ UErrorCode status = U_ZERO_ERROR; |
+ UCalendar* ucal = ucal_open(zoneGMT, -1, "root", UCAL_GREGORIAN, &status); |
+ if ( U_SUCCESS(status) ) { |
+ UDateFormat* udfmt = udat_open(UDAT_NONE, UDAT_LONG_RELATIVE, textRelContextItemPtr->locale, zoneGMT, -1, NULL, 0, &status); |
+ if ( U_SUCCESS(status) ) { |
+ udat_setContext(udfmt, textRelContextItemPtr->capitalizationContext, &status); |
+ if ( U_SUCCESS(status) ) { |
+ UDate yesterday, today = ucal_getNow(); |
+ UChar ubuf[kUbufMax]; |
+ char bbuf1[kBbufMax]; |
+ char bbuf2[kBbufMax]; |
+ int32_t len = udat_format(udfmt, today, ubuf, kUbufMax, NULL, &status); |
+ (void)len; |
+ if ( U_FAILURE(status) ) { |
+ log_err("FAIL: udat_format today for locale %s, capitalizationContext %d, status %s\n", |
+ textRelContextItemPtr->locale, (int)textRelContextItemPtr->capitalizationContext, u_errorName(status) ); |
+ } else if (u_strncmp(ubuf, textRelContextItemPtr->expectedFormatToday, kUbufMax) != 0) { |
+ log_err("FAIL: udat_format today for locale %s, capitalizationContext %d, expected %s, got %s\n", |
+ textRelContextItemPtr->locale, (int)textRelContextItemPtr->capitalizationContext, |
+ u_austrncpy(bbuf1,textRelContextItemPtr->expectedFormatToday,kUbufMax), u_austrncpy(bbuf2,ubuf,kUbufMax) ); |
+ } |
+ status = U_ZERO_ERROR; |
+ ucal_setMillis(ucal, today, &status); |
+ ucal_add(ucal, UCAL_DATE, -1, &status); |
+ yesterday = ucal_getMillis(ucal, &status); |
+ if ( U_SUCCESS(status) ) { |
+ len = udat_format(udfmt, yesterday, ubuf, kUbufMax, NULL, &status); |
+ if ( U_FAILURE(status) ) { |
+ log_err("FAIL: udat_format yesterday for locale %s, capitalizationContext %d, status %s\n", |
+ textRelContextItemPtr->locale, (int)textRelContextItemPtr->capitalizationContext, u_errorName(status) ); |
+ } else if (u_strncmp(ubuf, textRelContextItemPtr->expectedFormatYesterday, kUbufMax) != 0) { |
+ log_err("FAIL: udat_format yesterday for locale %s, capitalizationContext %d, expected %s, got %s\n", |
+ textRelContextItemPtr->locale, (int)textRelContextItemPtr->capitalizationContext, |
+ u_austrncpy(bbuf1,textRelContextItemPtr->expectedFormatYesterday,kUbufMax), u_austrncpy(bbuf2,ubuf,kUbufMax) ); |
+ } |
+ } |
+ } else { |
+ log_err("FAIL: udat_setContext relative for locale %s, capitalizationContext %d, status %s\n", |
+ textRelContextItemPtr->locale, (int)textRelContextItemPtr->capitalizationContext, u_errorName(status) ); |
+ } |
+ udat_close(udfmt); |
+ } else { |
+ log_data_err("FAIL: udat_open relative for locale %s, status %s\n", textRelContextItemPtr->locale, u_errorName(status) ); |
+ } |
+ ucal_close(ucal); |
+ } else { |
+ log_data_err("FAIL: ucal_open for locale root, status %s\n", u_errorName(status) ); |
+ } |
+ } |
+} |
+ |
+ |
+// overrideNumberFormat[i][0] is to tell which field to set, |
+// overrideNumberFormat[i][1] is the expected result |
+static const char * overrideNumberFormat[][2] = { |
+ {"", "\\u521D\\u4E03 \\u521D\\u4E8C"}, |
+ {"d", "07 \\u521D\\u4E8C"}, |
+ {"do", "07 \\u521D\\u4E8C"}, |
+ {"Md", "\\u521D\\u4E03 \\u521D\\u4E8C"}, |
+ {"MdMMd", "\\u521D\\u4E03 \\u521D\\u4E8C"}, |
+ {"mixed", "\\u521D\\u4E03 \\u521D\\u4E8C"} |
+}; |
+ |
+static void TestOverrideNumberFormat(void) { |
+ UErrorCode status = U_ZERO_ERROR; |
+ UChar pattern[50]; |
+ UChar* expected; |
+ UChar* fields; |
+ char bbuf1[kBbufMax]; |
+ char bbuf2[kBbufMax]; |
+ const char* localeString = "zh@numbers=hanidays"; |
+ UDateFormat* fmt; |
+ const UNumberFormat* getter_result; |
+ int32_t i; |
+ unsigned j; |
+ |
+ expected=(UChar*)malloc(sizeof(UChar) * 10); |
+ fields=(UChar*)malloc(sizeof(UChar) * 10); |
+ u_uastrcpy(fields, "d"); |
+ u_uastrcpy(pattern,"MM d"); |
+ |
+ fmt=udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US",NULL,0,pattern, u_strlen(pattern), &status); |
+ if (!assertSuccess("udat_open()", &status)) { |
+ return; |
+ } |
+ |
+ |
+ // loop 50 times to check getter/setter |
+ for (i = 0; i < 5; i++){ |
+ UNumberFormat* overrideFmt; |
+ overrideFmt = unum_open(UNUM_DEFAULT, NULL, 0, localeString, NULL, &status); |
+ assertSuccess("unum_open()", &status); |
+ |
+ udat_adoptNumberFormatForFields(fmt, fields, overrideFmt, &status); |
+ overrideFmt = NULL; // no longer valid |
+ assertSuccess("udat_setNumberFormatForField()", &status); |
+ |
+ getter_result = udat_getNumberFormatForField(fmt, 'd'); |
+ if(getter_result == NULL) { |
+ log_err("FAIL: udat_getNumberFormatForField did not return a valid pointer\n"); |
+ } |
+ } |
+ |
+ { |
+ UNumberFormat* overrideFmt; |
+ overrideFmt = unum_open(UNUM_DEFAULT, NULL, 0, localeString, NULL, &status); |
+ assertSuccess("unum_open()", &status); |
+ udat_setNumberFormat(fmt, overrideFmt); // test the same override NF will not crash |
+ unum_close(overrideFmt); |
+ } |
+ udat_close(fmt); |
+ |
+ for (j=0; i<sizeof(overrideNumberFormat)/sizeof(overrideNumberFormat[0]); i++){ |
+ UChar ubuf[kUbufMax]; |
+ UDateFormat* fmt2; |
+ UNumberFormat* overrideFmt2; |
+ |
+ fmt2 =udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US",NULL,0,pattern, u_strlen(pattern), &status); |
+ assertSuccess("udat_open() with en_US", &status); |
+ |
+ overrideFmt2 = unum_open(UNUM_DEFAULT, NULL, 0, localeString, NULL, &status); |
+ assertSuccess("unum_open() in loop", &status); |
+ |
+ u_uastrcpy(fields, overrideNumberFormat[i][0]); |
+ u_unescape(overrideNumberFormat[i][1], expected, 50); |
+ |
+ if ( strcmp(overrideNumberFormat[i][0], "") == 0 ) { // use the one w/o field |
+ udat_setNumberFormat(fmt2, overrideFmt2); |
+ } else if ( strcmp(overrideNumberFormat[i][0], "mixed") == 0 ) { // set 1 field at first but then full override, both(M & d) should be override |
+ const char* singleLocale = "en@numbers=hebr"; |
+ UNumberFormat* singleOverrideFmt; |
+ u_uastrcpy(fields, "d"); |
+ |
+ singleOverrideFmt = unum_open(UNUM_DEFAULT, NULL, 0, singleLocale, NULL, &status); |
+ assertSuccess("unum_open() in mixed", &status); |
+ |
+ udat_adoptNumberFormatForFields(fmt2, fields, singleOverrideFmt, &status); |
+ assertSuccess("udat_setNumberFormatForField() in mixed", &status); |
+ |
+ udat_setNumberFormat(fmt2, overrideFmt2); |
+ } else if ( strcmp(overrideNumberFormat[i][0], "do") == 0 ) { // o is an invalid field |
+ udat_adoptNumberFormatForFields(fmt2, fields, overrideFmt2, &status); |
+ if(status == U_INVALID_FORMAT_ERROR) { |
+ udat_close(fmt2); |
+ status = U_ZERO_ERROR; |
+ continue; |
+ } |
+ } else { |
+ udat_adoptNumberFormatForFields(fmt2, fields, overrideFmt2, &status); |
+ assertSuccess("udat_setNumberFormatForField() in loop", &status); |
+ } |
+ |
+ udat_format(fmt2, july022008, ubuf, kUbufMax, NULL, &status); |
+ assertSuccess("udat_format() july022008", &status); |
+ |
+ if (u_strncmp(ubuf, expected, kUbufMax) != 0) |
+ log_err("fail: udat_format for locale, expected %s, got %s\n", |
+ u_austrncpy(bbuf1,expected,kUbufMax), u_austrncpy(bbuf2,ubuf,kUbufMax) ); |
+ |
+ udat_close(overrideFmt2); |
+ udat_close(fmt2); |
+ } |
+ free(expected); |
+ free(fields); |
} |
#endif /* #if !UCONFIG_NO_FORMATTING */ |