/** * Test for CollationElementIterator previous and next for the whole set of * unicode characters with normalization on. */ static void TestNormalizedUnicodeChar() { UChar source[0x100]; UCollator *th_th; UCollationElements *iter; UErrorCode status = U_ZERO_ERROR; UChar codepoint; UChar *test; /* thai should have normalization on */ th_th = ucol_open("th_TH", &status); if (U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of thai collation using ucol_open()\n %s\n", myErrorName(status)); return; } for (codepoint = 1; codepoint < 0xFFFE;) { test = source; while (codepoint % 0xFF != 0) { if (u_isdefined(codepoint)) *(test ++) = codepoint; codepoint ++; } if (u_isdefined(codepoint)) *(test ++) = codepoint; if (codepoint != 0xFFFF) codepoint ++; *test = 0; iter=ucol_openElements(th_th, source, u_strlen(source), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(th_th); return; } backAndForth(iter); ucol_closeElements(iter); iter=ucol_openElements(th_th, source, -1, &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(th_th); return; } backAndForth(iter); ucol_closeElements(iter); } ucol_close(th_th); }
void Test_GEec(void) { UErrorCode status = U_ZERO_ERROR; UDateFormat * dtfmt = udat_open(UDAT_LONG, UDAT_LONG, "en", zonePST, -1, NULL, 0, &status); if ( U_SUCCESS(status) ) { const DatePatternAndText *patTextPtr; for (patTextPtr = datePatternsAndText; patTextPtr->pattern != NULL; ++patTextPtr) { UChar dmyGnText[DATE_TEXT_MAX_CHARS]; char byteText[3*DATE_TEXT_MAX_CHARS]; int32_t dmyGnTextLen; UDate dateResult; udat_applyPattern(dtfmt, FALSE, patTextPtr->pattern, -1); dmyGnTextLen = udat_format(dtfmt, july022008, dmyGnText, DATE_TEXT_MAX_CHARS, NULL, &status); if ( U_FAILURE(status) ) { log_err("FAIL: udat_format with %s: %s\n", patTextPtr->label, myErrorName(status) ); status = U_ZERO_ERROR; } else if ( u_strcmp(dmyGnText, patTextPtr->text) != 0 ) { log_err("FAIL: udat_format with %s: wrong UChar[] result %s\n", patTextPtr->label, u_austrcpy(byteText,dmyGnText) ); } dateResult = udat_parse(dtfmt, patTextPtr->text, -1, NULL, &status); /* no time, dateResult != july022008 by some hours */ if ( U_FAILURE(status) ) { log_err("FAIL: udat_parse with %s: %s\n", patTextPtr->label, myErrorName(status) ); status = U_ZERO_ERROR; } else if ( patTextPtr->label[0] != '*' && july022008 - dateResult > dayMillisec ) { log_err("FAIL: udat_parse with %s: wrong UDate result\n", patTextPtr->label ); } } udat_close(dtfmt); } else { log_data_err("FAIL: udat_open fails: %s (Are you missing data?)\n", myErrorName(status)); } }
static void TestSecondary() { int32_t i,j, testAcuteSize; UCollationResult expected=UCOL_EQUAL; UErrorCode status = U_ZERO_ERROR; myCollation = ucol_open("fr_CA", &status); if(U_FAILURE(status)) { log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); return; } ucol_setAttribute(myCollation, UCOL_STRENGTH, UCOL_SECONDARY, &status); if(U_FAILURE(status)) { log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status)); return; } log_verbose("Testing fr_CA Collation with Secondary strength\n"); /*test acute and grave ordering (compare to french collation)*/ testAcuteSize = UPRV_LENGTHOF(testAcute); for (i = 0; i < testAcuteSize; i++) { for (j = 0; j < testAcuteSize; j++) { if (i < j) expected = UCOL_LESS; if (i == j) expected = UCOL_EQUAL; if (i > j) expected = UCOL_GREATER; doTest(myCollation, testAcute[i], testAcute[j], expected ); } } ucol_close(myCollation); }
/** * @bug 4162071 **/ void Test4162071() { int32_t pos; UDate x; UErrorCode status = U_ZERO_ERROR; UDateFormat *df; UChar datestr[30]; UChar format[50]; u_uastrcpy(datestr, "Thu, 30-Jul-1999 11:51:14 GMT"); u_uastrcpy(format, "EEE', 'dd-MMM-yyyy HH:mm:ss z"); /* RFC 822/1123 */ status = U_ZERO_ERROR; /* Can't hardcode the result to assume the default locale is "en_US". */ df = udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US",NULL,0,format, u_strlen(format),&status); if(U_FAILURE(status)) { log_data_err("ERROR: couldn't create date format: %s\n", myErrorName(status)); return; } pos=0; x = udat_parse(df, datestr, u_strlen(datestr), &pos, &status); if(U_FAILURE(status)) { log_data_err("ERROR : parse format %s fails : %s\n", austrdup(format), myErrorName(status)); } else { log_verbose("Parse format \"%s \" ok.\n", austrdup(format) ); } /*log_verbose("date= %s\n", austrdup(myFormatit(df, x)) );*/ udat_close(df); }
static void TestCombineDateTime() { const CombineDateTimeTestItem *itemPtr; log_verbose("\nTesting ureldatefmt_combineDateAndTime() with various parameters\n"); for (itemPtr = combTestItems; itemPtr->locale != NULL; itemPtr++) { URelativeDateTimeFormatter *reldatefmt = NULL; UErrorCode status = U_ZERO_ERROR; UChar ubufreldate[kUBufMax]; UChar ubuftime[kUBufMax]; UChar ubufget[kUBufMax]; int32_t ulenreldate, ulentime, ulenget; reldatefmt = ureldatefmt_open(itemPtr->locale, NULL, itemPtr->width, itemPtr->capContext, &status); if ( U_FAILURE(status) ) { log_data_err("FAIL: ureldatefmt_open() for locale %s, width %d, capContext %d: %s\n", itemPtr->locale, (int)itemPtr->width, (int)itemPtr->capContext, myErrorName(status) ); continue; } ulenreldate = u_unescape(itemPtr->relativeDateString, ubufreldate, kUBufMax); ulentime = u_unescape(itemPtr->timeString, ubuftime, kUBufMax); ulenget = ureldatefmt_combineDateAndTime(reldatefmt, ubufreldate, ulenreldate, ubuftime, ulentime, ubufget, kUBufMax, &status); if ( U_FAILURE(status) ) { log_err("FAIL: ureldatefmt_combineDateAndTime() for locale %s, width %d, capContext %d: %s\n", itemPtr->locale, (int)itemPtr->width, (int)itemPtr->capContext, myErrorName(status) ); } else { UChar ubufexp[kUBufMax]; int32_t ulenexp = u_unescape(itemPtr->expectedResult, ubufexp, kUBufMax); if (ulenget != ulenexp || u_strncmp(ubufget, ubufexp, ulenexp) != 0) { char bbufget[kBBufMax]; u_austrncpy(bbufget, ubufget, kUBufMax); log_err("ERROR: ureldatefmt_combineDateAndTime() for locale %s, width %d, capContext %d;\n expected %s\n get %s\n", itemPtr->locale, (int)itemPtr->width, (int)itemPtr->capContext, itemPtr->expectedResult, bbufget ); } } // preflight test status = U_ZERO_ERROR; ulenget = ureldatefmt_combineDateAndTime(reldatefmt, ubufreldate, ulenreldate, ubuftime, ulentime, NULL, 0, &status); if ( status != U_BUFFER_OVERFLOW_ERROR) { log_err("FAIL: ureldatefmt_combineDateAndTime() preflight for locale %s, width %d, capContext %d: expected U_BUFFER_OVERFLOW_ERROR, got %s\n", itemPtr->locale, (int)itemPtr->width, (int)itemPtr->capContext, myErrorName(status) ); } else { UChar ubufexp[kUBufMax]; int32_t ulenexp = u_unescape(itemPtr->expectedResult, ubufexp, kUBufMax); if (ulenget != ulenexp) { log_err("ERROR: ureldatefmt_combineDateAndTime() preflight for locale %s, width %d, capContext %d;\n expected len %d, get len %d\n", itemPtr->locale, (int)itemPtr->width, (int)itemPtr->capContext, ulenexp, ulenget ); } } ureldatefmt_close(reldatefmt); } }
static void VerifygetsetSymbols(UDateFormat* from, UDateFormat* to, UDateFormatSymbolType type, int32_t idx) { UChar *result=NULL; UChar *value=NULL; int32_t resultlength, resultlengthout; UErrorCode status = U_ZERO_ERROR; resultlength=0; resultlengthout=udat_getSymbols(from, type, idx , NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; resultlength=resultlengthout+1; result=(UChar*)malloc(sizeof(UChar) * resultlength); udat_getSymbols(from, type, idx, result, resultlength, &status); } if(U_FAILURE(status)){ log_err("FAIL: error in getSymbols() %s\n", myErrorName(status) ); return; } resultlength=resultlengthout+1; udat_setSymbols(to, type, idx, result, resultlength, &status); if(U_FAILURE(status)) { log_err("FAIL: Error in udat_setSymbols() : %s\n", myErrorName(status) ); return; } resultlength=0; resultlengthout=udat_getSymbols(to, type, idx, NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; resultlength=resultlengthout+1; value=(UChar*)malloc(sizeof(UChar) * resultlength); udat_getSymbols(to, type, idx, value, resultlength, &status); } if(U_FAILURE(status)){ log_err("FAIL: error in retrieving the value using getSymbols i.e roundtrip\n %s\n", myErrorName(status) ); return; } if(u_strcmp(result, value)!=0){ log_data_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", austrdup(result), austrdup(value) ); } else log_verbose("PASS: setSymbols successful\n"); free(value); free(result); }
void TestQuotePattern161() { UDateFormat *format; UCalendar *cal; UDate currentTime_1; UChar *pattern, *tzID, *exp; UChar *dateString; UErrorCode status = U_ZERO_ERROR; const char* expStr = "04/13/1999 at 10:42:28 AM "; ctest_setTimeZone(NULL, &status); pattern=(UChar*)malloc(sizeof(UChar) * (strlen("MM/dd/yyyy 'at' hh:mm:ss a zzz")+1) ); u_uastrcpy(pattern, "MM/dd/yyyy 'at' hh:mm:ss a zzz"); /* this is supposed to open default date format, but later on it treats it like it is "en_US" - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ /* format= udat_openPattern(pattern, u_strlen(pattern), NULL, &status); */ format= udat_open(UDAT_IGNORE, UDAT_IGNORE,"en_US", NULL, 0,pattern, u_strlen(pattern), &status); if(U_FAILURE(status)){ log_err_status(status, "error in udat_open: %s\n", myErrorName(status)); return; } tzID=(UChar*)malloc(sizeof(UChar) * 4); u_uastrcpy(tzID, "PST"); /* this is supposed to open default date format, but later on it treats it like it is "en_US" - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ /* cal=ucal_open(tzID, u_strlen(tzID), NULL, UCAL_TRADITIONAL, &status); */ cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status); if(U_FAILURE(status)){ log_err("error in ucal_open cal : %s\n", myErrorName(status)); } ucal_setDateTime(cal, 1999, UCAL_APRIL, 13, 10, 42, 28, &status); currentTime_1 = ucal_getMillis(cal, &status); dateString = myDateFormat(format, currentTime_1); exp=(UChar*)malloc(sizeof(UChar) * (strlen(expStr) + 1) ); u_uastrcpy(exp, expStr); log_verbose("%s\n", austrdup(dateString) ); if(u_strncmp(dateString, exp, (int32_t)strlen(expStr)) !=0) log_err("Error in formatting a pattern with single quotes\n"); udat_close(format); ucal_close(cal); free(exp); free(tzID); free(pattern); ctest_resetTimeZone(); }
void aux917( UDateFormat *fmt, UChar* str) { int32_t resultlength, resultlengthneeded; UErrorCode status = U_ZERO_ERROR; UChar* formatted=NULL; UChar *pat=NULL; UDate d1=1000000000.0; resultlength=0; resultlengthneeded=udat_toPattern(fmt, TRUE, NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR) { status=U_ZERO_ERROR; resultlength=resultlengthneeded + 1; pat=(UChar*)malloc(sizeof(UChar) * (resultlength)); udat_toPattern(fmt, TRUE, pat, resultlength, &status); } if(U_FAILURE(status)) { log_err("failure in retrieving the pattern: %s\n", myErrorName(status)); } log_verbose("pattern: %s\n", austrdup(pat) ); status = U_ZERO_ERROR; formatted = myFormatit(fmt, d1); if( u_strcmp(formatted,str)!=0) { log_err("Fail: Want %s Got: %s\n", austrdup(str), austrdup(formatted) ); } free(pat); }
static void TestFractionDigitOverride(void) { UErrorCode status = U_ZERO_ERROR; UNumberFormat *fmt = unum_open(UNUM_CURRENCY, NULL, 0, "hu_HU", NULL, &status); UChar buffer[256]; UChar expectedBuf[256]; const char expectedFirst[] = "123\\u00A0Ft"; const char expectedSecond[] = "123,46\\u00A0Ft"; const char expectedThird[] = "123,456\\u00A0Ft"; if (U_FAILURE(status)) { log_data_err("Error: unum_open returned %s (Are you missing data?)\n", myErrorName(status)); return; } /* Make sure that you can format normal fraction digits. */ unum_formatDouble(fmt, 123.456, buffer, sizeof(buffer)/sizeof(buffer[0]), NULL, &status); u_unescape(expectedFirst, expectedBuf, strlen(expectedFirst)+1); if (u_strcmp(buffer, expectedBuf) != 0) { log_err("Error: unum_formatDouble didn't return %s\n", expectedFirst); } /* Make sure that you can format 2 fraction digits. */ unum_setAttribute(fmt, UNUM_FRACTION_DIGITS, 2); unum_formatDouble(fmt, 123.456, buffer, sizeof(buffer)/sizeof(buffer[0]), NULL, &status); u_unescape(expectedSecond, expectedBuf, strlen(expectedSecond)+1); if (u_strcmp(buffer, expectedBuf) != 0) { log_err("Error: unum_formatDouble didn't return %s\n", expectedSecond); } /* Make sure that you can format more fraction digits. */ unum_setAttribute(fmt, UNUM_FRACTION_DIGITS, 3); unum_formatDouble(fmt, 123.456, buffer, sizeof(buffer)/sizeof(buffer[0]), NULL, &status); u_unescape(expectedThird, expectedBuf, strlen(expectedThird)+1); if (u_strcmp(buffer, expectedBuf) != 0) { log_err("Error: unum_formatDouble didn't return %s\n", expectedThird); } unum_close(fmt); }
static int32_t checkItemCount(uint32_t currencyType) { UErrorCode status = U_ZERO_ERROR; int32_t originalCount, count; UEnumeration *en = ucurr_openISOCurrencies(currencyType, &status); int32_t expectedLen = 3, len; if (U_FAILURE(status)) { log_err("Error: ucurr_openISOCurrencies returned %s\n", myErrorName(status)); return -1; } originalCount = uenum_count(en, &status); for (count=0;;count++) { const char *str = uenum_next(en, &len, &status); if (str == NULL || len != expectedLen || strlen(str) != expectedLen) { break; } } if (originalCount != count) { log_err("Error: uenum_count returned the wrong value (type = 0x%X). Got: %d Expected %d\n", currencyType, count, originalCount); } if (U_FAILURE(status)) { log_err("Error: uenum_next got an error: %s\n", u_errorName(status)); } uenum_close(en); return count; }
static void TestPrimary( ) { int32_t len,i; UCollator *myCollation; UErrorCode status=U_ZERO_ERROR; static const char str[]="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 "; UChar rules[sizeof(str)]; len = strlen(str); u_uastrcpy(rules, str); myCollation=ucol_openRules(rules, len, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status); if(U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of rule based collator :%s\n", myErrorName(status)); return; } ucol_setStrength(myCollation, UCOL_PRIMARY); for (i = 17; i < 26 ; i++) { doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); } ucol_close(myCollation); myCollation = 0; }
/*Test Various format patterns*/ static void TestPatterns(void) { int32_t pat_length, i, lneed; UNumberFormat *fmt; UChar upat[5]; UChar unewpat[5]; UChar unum[5]; UChar *unewp=NULL; UChar *str=NULL; UErrorCode status = U_ZERO_ERROR; const char* pat[] = { "#.#", "#.", ".#", "#" }; const char* newpat[] = { "0.#", "0.", "#.0", "0" }; const char* num[] = { "0", "0.", ".0", "0" }; log_verbose("\nTesting different format patterns\n"); pat_length = UPRV_LENGTHOF(pat); for (i=0; i < pat_length; ++i) { status = U_ZERO_ERROR; u_uastrcpy(upat, pat[i]); fmt= unum_open(UNUM_IGNORE,upat, u_strlen(upat), "en_US",NULL, &status); if (U_FAILURE(status)) { log_err_status(status, "FAIL: Number format constructor failed for pattern %s -> %s\n", pat[i], u_errorName(status)); continue; } lneed=0; lneed=unum_toPattern(fmt, FALSE, NULL, lneed, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status= U_ZERO_ERROR; unewp=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); unum_toPattern(fmt, FALSE, unewp, lneed+1, &status); } if(U_FAILURE(status)){ log_err("FAIL: Number format extracting the pattern failed for %s\n", pat[i]); } u_uastrcpy(unewpat, newpat[i]); if(u_strcmp(unewp, unewpat) != 0) log_err("FAIL: Pattern %s should be transmute to %s; %s seen instead\n", pat[i], newpat[i], austrdup(unewp) ); lneed=0; lneed=unum_format(fmt, 0, NULL, lneed, NULL, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); unum_format(fmt, 0, str, lneed+1, NULL, &status); } if(U_FAILURE(status)) { log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status) ); } u_uastrcpy(unum, num[i]); if (u_strcmp(str, unum) != 0) { log_err("FAIL: Pattern %s should format zero as %s; %s Seen instead\n", pat[i], num[i], austrdup(str) ); } free(unewp); free(str); unum_close(fmt); } }
static void roundingTest(UNumberFormat* nf, double x, int32_t maxFractionDigits, const char* expected) { UChar *out = NULL; UChar *res; UFieldPosition pos; UErrorCode status; int32_t lneed; status=U_ZERO_ERROR; unum_setAttribute(nf, UNUM_MAX_FRACTION_DIGITS, maxFractionDigits); lneed=0; lneed=unum_formatDouble(nf, x, NULL, lneed, NULL, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; out=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); pos.field=0; unum_formatDouble(nf, x, out, lneed+1, &pos, &status); } if(U_FAILURE(status)) { log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) ); } /*Need to use log_verbose here. Problem with the float*/ /*printf("%f format with %d fraction digits to %s\n", x, maxFractionDigits, austrdup(out) );*/ res=(UChar*)malloc(sizeof(UChar) * (strlen(expected)+1) ); u_uastrcpy(res, expected); if (u_strcmp(out, res) != 0) log_err("FAIL: Expected: %s or %s\n", expected, austrdup(res) ); free(res); if(out != NULL) { free(out); } }
void Test714(void) { UDate d=978103543000.0; UChar temp[20]; UErrorCode status = U_ZERO_ERROR; UDateFormat *fmt; UChar *result; const char* expect = "7:25:43 AM"; ctest_setTimeZone(NULL, &status); fmt= udat_open(UDAT_MEDIUM,UDAT_NONE ,"en_US_CA", NULL, -1, NULL, 0, &status); if(U_FAILURE(status)) { log_data_err("FAIL: error in creating the dateformat using medium time style and NO date style: %s (Are you missing data?)\n", myErrorName(status)); return; } result =myFormatit(fmt, d); if(!result) { log_data_err("Fail: could not format - exitting test\n"); return; } u_uastrcpy(temp, expect); if (u_strcmp(result, temp)!=0) { log_err("Fail: %s != %s\n", austrdup(result), expect); } else { log_verbose("Ok: %s == %s\n", austrdup(result), expect ); } udat_close(fmt); ctest_resetTimeZone(); }
static void TestSecondary() { int32_t i; int32_t len; UChar *rules; UCollator *myCollation; UErrorCode status=U_ZERO_ERROR; const char* str="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 "; len = strlen(str); rules=(UChar*)malloc(sizeof(UChar*) * (len+1)); u_uastrcpy(rules, str); myCollation=ucol_openRules(rules, len, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status)); } ucol_setStrength(myCollation, UCOL_SECONDARY); for (i = 26; i < 34 ; i++) { doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); } free(rules); ucol_close(myCollation); myCollation = 0; }
static void TestExtra() { int32_t i, j; int32_t len; UChar *rules; UCollator *myCollation; UErrorCode status = U_ZERO_ERROR; const char* str="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 "; len = strlen(str); rules=(UChar*)malloc(sizeof(UChar*) * (len+1)); u_uastrcpy(rules, str); myCollation=ucol_openRules(rules, len, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status)); } ucol_setStrength(myCollation, UCOL_TERTIARY); for (i = 0; i < COUNT_TEST_CASES-1 ; i++) { for (j = i + 1; j < COUNT_TEST_CASES; j += 1) { doTest(myCollation, testCases[i], testCases[j], UCOL_LESS); } } free(rules); ucol_close(myCollation); myCollation = 0; }
void tryPat994(UDateFormat* format, const char* pattern, const char* s, UDate expected) { UChar *f; UChar *str, *pat; UDate date; UDate null=0; int32_t pos; UErrorCode status = U_ZERO_ERROR; str=(UChar*)malloc(sizeof(UChar) * (strlen(s) + 1) ); u_uastrcpy(str, s); pat=(UChar*)malloc(sizeof(UChar) * (strlen(pattern) + 1) ); u_uastrcpy(pat, pattern); log_verbose("Pattern : %s ; String : %s\n", austrdup(pat), austrdup(str)); udat_applyPattern(format, FALSE, pat, u_strlen(pat)); pos=0; date = udat_parse(format, str, u_strlen(str), &pos, &status); if(U_FAILURE(status) || date == null) { log_verbose("ParseException: : %s\n", myErrorName(status) ); if (expected != null) log_err("FAIL: Expected: %s\n", austrdup(myDateFormat(format, expected)) ); } else { f=myDateFormat(format, date); log_verbose(" parse( %s ) -> %s\n", austrdup(str), austrdup(f)); if (expected == null || date != expected) log_err("FAIL: Expected null for \"%s\"\n", s); if (u_strcmp(f, str) !=0) log_err("FAIL: Expected : %s\n", austrdup(str) ); } free(str); free(pat); }
static void TestSecondary() { UCollationResult expected=UCOL_EQUAL; int32_t i,j, testAcuteSize; UErrorCode status = U_ZERO_ERROR; myCollation = ucol_open("en_US", &status); if(U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); return; } ucol_setStrength(myCollation, UCOL_SECONDARY); log_verbose("Testing English Collation with Secondary strength\n"); for (i = 43; i < 49 ; i++) { doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); } /*test acute and grave ordering (compare to french collation) */ testAcuteSize = UPRV_LENGTHOF(testAcute); for (i = 0; i < testAcuteSize; i++) { for (j = 0; j < testAcuteSize; j++) { if (i < j) expected = UCOL_LESS; if (i == j) expected = UCOL_EQUAL; if (i > j) expected = UCOL_GREATER; doTest(myCollation, testAcute[i], testAcute[j], expected ); } } ucol_close(myCollation); }
UChar* myFormatit(UDateFormat* datdef, UDate d1) { UChar *result1=NULL; int32_t resultlength, resultlengthneeded; UErrorCode status = U_ZERO_ERROR; resultlength=0; resultlengthneeded=udat_format(datdef, d1, NULL, resultlength, NULL, &status); if(status==U_BUFFER_OVERFLOW_ERROR) { status=U_ZERO_ERROR; resultlength=resultlengthneeded+1; /*result1=(UChar*)malloc(sizeof(UChar) * resultlength);*/ /*this leaks*/ result1=(UChar*)ctst_malloc(sizeof(UChar) * resultlength); /*this won't*/ udat_format(datdef, d1, result1, resultlength, NULL, &status); } if(U_FAILURE(status)) { log_err("FAIL: Error in formatting using udat_format(.....): %s\n", myErrorName(status)); return 0; } return result1; }
/* N.B.: use idx instead of index to avoid 'shadow' warnings in strict mode. */ static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, int32_t idx, const char* expected) { UChar *pattern=NULL; UErrorCode status = U_ZERO_ERROR; UChar *result=NULL; int32_t resultlength, resultlengthout; pattern=(UChar*)malloc(sizeof(UChar) * (strlen(expected)+1)); u_uastrcpy(pattern, expected); resultlength=0; resultlengthout=udat_getSymbols(datfor, type, idx , NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR) { status=U_ZERO_ERROR; resultlength=resultlengthout+1; result=(UChar*)malloc(sizeof(UChar) * resultlength); udat_getSymbols(datfor, type, idx, result, resultlength, &status); } if(U_FAILURE(status)) { log_err("FAIL: Error in udat_getSymbols()... %s\n", myErrorName(status) ); return; } 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) ); } free(result); free(pattern); }
void TestTwoDigitYearDSTParse() { UDateFormat *fullFmt, *fmt; UErrorCode status = U_ZERO_ERROR; UChar *pattern; UDate d; UChar *s; int32_t pos; ctest_setTimeZone(NULL, &status); pattern=(UChar*)malloc(sizeof(UChar) * (strlen("EEE MMM dd HH:mm:ss.SSS zzz yyyy G")+1 )); u_uastrcpy(pattern, "EEE MMM dd HH:mm:ss.SSS zzz yyyy G"); fullFmt= udat_open(UDAT_IGNORE, UDAT_IGNORE,"en_US",NULL,0,pattern, u_strlen(pattern),&status); if(U_FAILURE(status)) { log_err_status(status, "FAIL: Error in creating a date format using udat_openPattern %s\n", myErrorName(status) ); } else { log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n"); u_uastrcpy(pattern, "dd-MMM-yy h:mm:ss 'o''clock' a z"); fmt= udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US", NULL, 0,pattern, u_strlen(pattern), &status); s=(UChar*)malloc(sizeof(UChar) * (strlen("03-Apr-04 2:20:47 o'clock AM PST")+1) ); u_uastrcpy(s, "03-Apr-04 2:20:47 o'clock AM PST"); pos=0; d = udat_parse(fmt, s, u_strlen(s), &pos, &status); if (U_FAILURE(status)) { log_err("FAIL: Could not parse \"%s\"\n", austrdup(s)); } else { UCalendar *cal = ucal_open(NULL, 0, uloc_getDefault(), UCAL_TRADITIONAL, &status); if (U_FAILURE(status)) { log_err_status(status, "FAIL: Could not open calendar: %s\n", u_errorName(status)); } else { int32_t h; ucal_setMillis(cal, d, &status); h = ucal_get(cal, UCAL_HOUR_OF_DAY, &status); if (U_FAILURE(status)) { log_err("FAIL: Some calendar operations failed"); } else if (h != 2) { log_err("FAIL: Parse of \"%s\" returned HOUR_OF_DAY %d\n", austrdup(s), h); } ucal_close(cal); } } udat_close(fullFmt); udat_close(fmt); free(s); } free(pattern); ctest_resetTimeZone(); }
/** * Test localized currency patterns. */ static void TestCurrency(void) { UNumberFormat *currencyFmt; UChar *str; int32_t lneed, i; UFieldPosition pos; UChar res[100]; UErrorCode status = U_ZERO_ERROR; const char* locale[]={"fr_CA", "de_DE_PREEURO", "fr_FR_PREEURO"}; const char* result[]={"1,50\\u00a0$", "1,50\\u00a0DM", "1,50\\u00a0F"}; log_verbose("\nTesting the number format with different currency patterns\n"); for(i=0; i < 3; i++) { str=NULL; currencyFmt = unum_open(UNUM_CURRENCY, NULL,0,locale[i],NULL, &status); if(U_FAILURE(status)){ log_data_err("Error in the construction of number format with style currency: %s (Are you missing data?)\n", myErrorName(status)); } else { lneed=0; lneed= unum_formatDouble(currencyFmt, 1.50, NULL, lneed, NULL, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); pos.field = 0; unum_formatDouble(currencyFmt, 1.50, str, lneed+1, &pos, &status); } if(U_FAILURE(status)) { log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) ); } else { u_unescape(result[i], res, (int32_t)strlen(result[i])+1); if (u_strcmp(str, res) != 0){ log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i], aescstrdup(str, -1), locale[i]); } } } unum_close(currencyFmt); free(str); } }
/*test u_parseMessage() with various test patterns */ static void TestParseMessage() { UChar pattern[100]; UChar source[100]; UErrorCode status = U_ZERO_ERROR; int32_t value; UChar str[10]; UChar res[10]; log_verbose("\nTesting a sample for parse Message test#9\n"); u_uastrcpy(source, "You deposited an amount of $500.00"); u_uastrcpy(pattern, "You {0} an amount of {1,number,currency}"); u_uastrcpy(res,"deposited"); u_parseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, str, &value); if(U_FAILURE(status)) { log_err("ERROR: failure in parse Message on test#9: %s\n", myErrorName(status)); } if(value==500.00 && u_strcmp(str,res)==0) log_verbose("PASS: parseMessage successful on test#9\n"); else log_err("FAIL: Error in parseMessage on test#9 \n"); log_verbose("\nTesting a sample for parse Message test#10\n"); u_uastrcpy(source, "There are 123 files on MyDisk created"); u_uastrcpy(pattern, "There are {0,number,integer} files on {1} created"); u_uastrcpy(res,"MyDisk"); u_parseMessage( "en_US", pattern, u_strlen(pattern), source, u_strlen(source), &status, &value, str); if(U_FAILURE(status)) { log_err("ERROR: failure in parse Message on test#10: %s\n", myErrorName(status)); } if(value==123.00 && u_strcmp(str,res)==0) log_verbose("PASS: parseMessage successful on test#10\n"); else log_err("FAIL: Error in parseMessage on test#10 \n"); }
void TestAliasConflict(void) { UErrorCode status = U_ZERO_ERROR; UResourceBundle *he = NULL; UResourceBundle *iw = NULL; const UChar *result = NULL; int32_t resultLen; he = ures_open(NULL, "he", &status); iw = ures_open(NULL, "iw", &status); if(U_FAILURE(status)) { log_err_status(status, "Failed to get resource with %s\n", myErrorName(status)); } ures_close(iw); result = ures_getStringByKey(he, "ExemplarCharacters", &resultLen, &status); if(U_FAILURE(status) || result == NULL) { log_err_status(status, "Failed to get resource with %s\n", myErrorName(status)); } ures_close(he); }
/** * @bug 4060212 */ void Test4060212() { int32_t pos; UCalendar *cal; UDateFormat *formatter, *fmt; UErrorCode status = U_ZERO_ERROR; UDate myDate; UChar *myString; UChar dateString[30], pattern[20], tzID[4]; u_uastrcpy(dateString, "1995-040.05:01:29 -8"); u_uastrcpy(pattern, "yyyy-DDD.hh:mm:ss z"); log_verbose( "dateString= %s Using yyyy-DDD.hh:mm:ss\n", austrdup(dateString) ); status = U_ZERO_ERROR; u_uastrcpy(tzID, "PST"); formatter = udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US",tzID,-1,pattern, u_strlen(pattern), &status); pos=0; myDate = udat_parse(formatter, dateString, u_strlen(dateString), &pos, &status); fmt = udat_open(UDAT_FULL,UDAT_LONG ,NULL, tzID, -1, NULL, 0, &status); if(U_FAILURE(status)) { log_data_err("FAIL: error in creating the dateformat using default date and time style: %s - (Are you missing data?)\n", myErrorName(status) ); return; } myString = myFormatit(fmt, myDate); cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status); if(U_FAILURE(status)) { log_err("FAIL: error in ucal_open caldef : %s\n", myErrorName(status)); } ucal_setMillis(cal, myDate, &status); if ((ucal_get(cal, UCAL_DAY_OF_YEAR, &status) != 40)) { log_err("Fail: Got %d Expected 40\n", ucal_get(cal, UCAL_DAY_OF_YEAR, &status)); } udat_close(formatter); ucal_close(cal); udat_close(fmt); }
static void TestUDataOpenChoiceDemo2() { UDataMemory *result; UErrorCode status=U_ZERO_ERROR; int i; int p=2; const char* name="test"; const char* type="icu"; const char* path = loadTestData(&status); result=udata_openChoice(path, type, name, isAcceptable, &p, &status); if(U_FAILURE(status)){ log_err("failed to load data at p=%s t=%s n=%s, isAcceptable", path, type, name); } if(U_SUCCESS(status) ) { udata_close(result); } p=0; for(i=0;i<2; i++){ result=udata_openChoice(path, type, name, isAcceptable, &p, &status); if(p<2) { if(U_FAILURE(status) && status==U_INVALID_FORMAT_ERROR){ log_verbose("Loads the data but rejects it as expected %s\n", myErrorName(status)); status=U_ZERO_ERROR; p++; } else { log_err("FAIL: failed to either load the data or to reject the loaded data. ERROR=%s\n", myErrorName(status) ); } } else if(p == 2) { if(U_FAILURE(status)) { log_err("FAIL: failed to load the data and accept it. ERROR=%s\n", myErrorName(status) ); } else { log_verbose("Loads the data and accepts it for p==2 as expected\n"); udata_close(result); } } } }
static void VerifysetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, int32_t idx, const char* expected) { UChar *result=NULL; UChar *value=NULL; int32_t resultlength, resultlengthout; UErrorCode status = U_ZERO_ERROR; value=(UChar*)malloc(sizeof(UChar) * (strlen(expected) + 1)); u_uastrcpy(value, expected); udat_setSymbols(datfor, type, idx, value, u_strlen(value), &status); if(U_FAILURE(status)) { log_err("FAIL: Error in udat_setSymbols() %s\n", myErrorName(status) ); return; } resultlength=0; resultlengthout=udat_getSymbols(datfor, type, idx, NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; resultlength=resultlengthout+1; result=(UChar*)malloc(sizeof(UChar) * resultlength); udat_getSymbols(datfor, type, idx, result, resultlength, &status); } if(U_FAILURE(status)){ log_err("FAIL: error in retrieving the value using getSymbols after setting it previously\n %s\n", myErrorName(status) ); return; } 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) ); } else log_verbose("PASS: setSymbols successful\n"); free(value); free(result); }
static void TestEnumListReset(void) { UErrorCode status = U_ZERO_ERROR; const char *currency1; const char *currency2; UEnumeration *en = ucurr_openISOCurrencies(UCURR_ALL, &status); if (U_FAILURE(status)) { log_err("Error: ucurr_openISOCurrencies returned %s\n", myErrorName(status)); return; } currency1 = uenum_next(en, NULL, &status); uenum_reset(en, &status); currency2 = uenum_next(en, NULL, &status); if (U_FAILURE(status)) { log_err("Error: uenum_next or uenum_reset returned %s\n", myErrorName(status)); return; } /* The first item's pointer in the list should be the same between resets. */ if (currency1 != currency2) { log_err("Error: reset doesn't work %s != %s\n", currency1, currency2); } uenum_close(en); }
static void TestDateIntervalFormat() { const DateIntervalFormatTestItem * testItemPtr; UErrorCode status = U_ZERO_ERROR; ctest_setTimeZone(NULL, &status); log_verbose("\nTesting udtitvfmt_open() and udtitvfmt_format() with various parameters\n"); for ( testItemPtr = testItems; testItemPtr->locale != NULL; ++testItemPtr ) { UDateIntervalFormat* udtitvfmt; int32_t tzidLen; UChar skelBuf[kSkelBufLen]; UChar tzidBuf[kTZIDBufLen]; const char * tzidForLog = (testItemPtr->tzid)? testItemPtr->tzid: "NULL"; status = U_ZERO_ERROR; u_unescape(testItemPtr->skeleton, skelBuf, kSkelBufLen); if ( testItemPtr->tzid ) { u_unescape(testItemPtr->tzid, tzidBuf, kTZIDBufLen); tzidLen = -1; } else { tzidLen = 0; } udtitvfmt = udtitvfmt_open(testItemPtr->locale, skelBuf, -1, tzidBuf, tzidLen, &status); if ( U_SUCCESS(status) ) { UChar result[kFormatBufLen]; UChar resultExpected[kFormatBufLen]; int32_t fmtLen = udtitvfmt_format(udtitvfmt, testItemPtr->from, testItemPtr->to, result, kFormatBufLen, NULL, &status); if (fmtLen >= kFormatBufLen) { result[kFormatBufLen-1] = 0; } if ( U_SUCCESS(status) ) { u_unescape(testItemPtr->resultExpected, resultExpected, kFormatBufLen); if ( u_strcmp(result, resultExpected) != 0 ) { char bcharBuf[kFormatBufLen]; log_err("ERROR: udtitvfmt_format for locale %s, skeleton %s, tzid %s, from %.1f, to %.1f: expect %s, get %s\n", testItemPtr->locale, testItemPtr->skeleton, tzidForLog, testItemPtr->from, testItemPtr->to, testItemPtr->resultExpected, u_austrcpy(bcharBuf,result) ); } } else { log_err("FAIL: udtitvfmt_format for locale %s, skeleton %s, tzid %s, from %.1f, to %.1f: %s\n", testItemPtr->locale, testItemPtr->skeleton, tzidForLog, testItemPtr->from, testItemPtr->to, myErrorName(status) ); } udtitvfmt_close(udtitvfmt); } else { log_data_err("FAIL: udtitvfmt_open for locale %s, skeleton %s, tzid %s - %s\n", testItemPtr->locale, testItemPtr->skeleton, tzidForLog, myErrorName(status) ); } } ctest_resetTimeZone(); }
static void TestTertiary( ) { int32_t i; UErrorCode status = U_ZERO_ERROR; myCollation = ucol_open("fr_CA", &status); if(U_FAILURE(status) || !myCollation) { log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); return; } ucol_setAttribute(myCollation, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status); if(U_FAILURE(status)) { log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status)); return; } log_verbose("Testing fr_CA Collation with Tertiary strength\n"); ucol_setStrength(myCollation, UCOL_QUATERNARY); for (i = 0; i < 12 ; i++) { doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); } ucol_close(myCollation); }