void RBBIAPITest::TestBoilerPlate() { UErrorCode status = U_ZERO_ERROR; BreakIterator* a = BreakIterator::createWordInstance(Locale("hi"), status); BreakIterator* b = BreakIterator::createWordInstance(Locale("hi_IN"),status); if (U_FAILURE(status)) { errcheckln(status, "Creation of break iterator failed %s", u_errorName(status)); return; } if(*a!=*b){ errln("Failed: boilerplate method operator!= does not return correct results"); } // Japanese word break iterators are identical to root with // a dictionary-based break iterator BreakIterator* c = BreakIterator::createCharacterInstance(Locale("ja"),status); BreakIterator* d = BreakIterator::createCharacterInstance(Locale("root"),status); if(c && d){ if(*c!=*d){ errln("Failed: boilerplate method operator== does not return correct results"); } }else{ errln("creation of break iterator failed"); } delete a; delete b; delete c; delete d; }
void DateFormatRegressionTest::Test4104522(void) { UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *sdf = new SimpleDateFormat(status); if(U_FAILURE(status)) { errcheckln(status, "Couldn't create SimpleDateFormat, error %s", u_errorName(status)); delete sdf; return; } failure(status, "new SimpleDateFormat"); UnicodeString pattern = "'time' hh:mm"; sdf->applyPattern(pattern); logln("pattern: \"" + pattern + "\""); // works correctly ParsePosition pp(0); UnicodeString text = "time "; UDate dt = sdf->parse(text, pp); logln(" text: \"" + text + "\"" + " date: " + dt); // works wrong pp.setIndex(0); text = "time"; dt = sdf->parse(text, pp); logln(" text: \"" + text + "\"" + " date: " + dt); delete sdf; }
void DateFormatRegressionTest::Test4162071(void) { UnicodeString dateString("Thu, 30-Jul-1999 11:51:14 GMT"); UnicodeString format("EEE', 'dd-MMM-yyyy HH:mm:ss z"); // RFC 822/1123 UErrorCode status = U_ZERO_ERROR; SimpleDateFormat df(format, Locale::getUS(), status); if(U_FAILURE(status)) { errcheckln(status, "Couldn't create SimpleDateFormat - %s", u_errorName(status)); return; } //try { UDate x = df.parse(dateString, status); if(U_SUCCESS(status)) logln("Parse format \"" + format + "\" ok"); else errln("Parse format \"" + format + "\" failed."); UnicodeString temp; FieldPosition pos(0); logln(dateString + " -> " + df.format(x, temp, pos)); //} catch (Exception e) { // errln("Parse format \"" + format + "\" failed."); //} }
void DateFormatRegressionTest::Test4103341(void) { TimeZone *saveZone =TimeZone::createDefault(); //try { // {sfb} changed from setDefault to adoptDefault TimeZone::adoptDefault(TimeZone::createTimeZone("CST")); UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *simple = new SimpleDateFormat(UnicodeString("MM/dd/yyyy HH:mm"), status); if(U_FAILURE(status)) { errcheckln(status, "Couldn't create SimpleDateFormat, error %s", u_errorName(status)); delete simple; return; } failure(status, "new SimpleDateFormat"); TimeZone *temp = TimeZone::createDefault(); if(simple->getTimeZone() != *temp) errln("Fail: SimpleDateFormat not using default zone"); //} //finally { TimeZone::adoptDefault(saveZone); //} delete temp; delete simple; }
void DateFormatRegressionTest::Test4073003(void) { //try { UErrorCode ec = U_ZERO_ERROR; SimpleDateFormat fmt("dd/MM/yy", Locale::getUK(), ec); if (U_FAILURE(ec)) { errcheckln(ec, "FAIL: SimpleDateFormat constructor - %s", u_errorName(ec)); return; } UnicodeString tests [] = { (UnicodeString) "12/25/61", (UnicodeString) "12/25/1961", (UnicodeString) "4/3/2010", (UnicodeString) "4/3/10" }; UErrorCode status = U_ZERO_ERROR; for(int i= 0; i < 4; i+=2) { UDate d = fmt.parse(tests[i], status); failure(status, "fmt.parse"); UDate dd = fmt.parse(tests[i+1], status); failure(status, "fmt.parse"); UnicodeString s; s = fmt.format(d, s); UnicodeString ss; ss = fmt.format(dd, ss); if (d != dd) errln((UnicodeString) "Fail: " + d + " != " + dd); if (s != ss) errln((UnicodeString)"Fail: " + s + " != " + ss); logln("Ok: " + s + " " + d); } }
void DateFormatRegressionTest::Test4089106(void) { TimeZone *def = TimeZone::createDefault(); //try { TimeZone *z = new SimpleTimeZone((int)(1.25 * 3600000), "FAKEZONE"); TimeZone::setDefault(*z); UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *f = new SimpleDateFormat(status); if(U_FAILURE(status)) { errcheckln(status, "Couldn't create SimpleDateFormat, error %s", u_errorName(status)); delete f; delete def; delete z; return; } failure(status, "new SimpleDateFormat"); if (f->getTimeZone()!= *z) errln("Fail: SimpleTimeZone should use TimeZone.getDefault()"); //} //finally { TimeZone::setDefault(*def); //} delete z; delete f; delete def; }
void RBBIAPITest::TestgetRules() { UErrorCode status=U_ZERO_ERROR; RuleBasedBreakIterator* bi1=(RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); RuleBasedBreakIterator* bi2=(RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status); if(U_FAILURE(status)){ errcheckln(status, "FAIL: in construction - %s", u_errorName(status)); delete bi1; delete bi2; return; } logln((UnicodeString)"Testing toString()"); bi1->setText((UnicodeString)"Hello there"); RuleBasedBreakIterator* bi3 =(RuleBasedBreakIterator*)bi1->clone(); UnicodeString temp=bi1->getRules(); UnicodeString temp2=bi2->getRules(); UnicodeString temp3=bi3->getRules(); if( temp2.compare(temp3) ==0 || temp.compare(temp2) == 0 || temp.compare(temp3) != 0) errln((UnicodeString)"ERROR: error in getRules() method"); delete bi1; delete bi2; delete bi3; }
void DateFormatRegressionTest::Test4061287(void) { UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("dd/MM/yyyy"), status); if(U_FAILURE(status)) { errcheckln(status, "Couldn't create SimpleDateFormat, error: %s", u_errorName(status)); delete df; return; } failure(status, "new SimpleDateFormat"); //try { logln(UnicodeString("") + df->parse("35/01/1971", status)); failure(status, "df->parse"); //logln(df.parse("35/01/1971").toString()); //} /*catch (ParseException e) { errln("Fail: " + e); e.printStackTrace(); }*/ df->setLenient(FALSE); UBool ok = FALSE; //try { logln(UnicodeString("") + df->parse("35/01/1971", status)); if(U_FAILURE(status)) ok = TRUE; //logln(df.parse("35/01/1971").toString()); //} catch (ParseException e) {ok=TRUE;} if(!ok) errln("Fail: Lenient not working"); delete df; }
void IntlTestDecimalFormatAPI::testRoundingInc(/*char *par*/) { UErrorCode status = U_ZERO_ERROR; DecimalFormat pat(UnicodeString("#,##0.00"),status); if(U_FAILURE(status)) { errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s", u_errorName(status)); return; } // get default rounding increment double roundingInc = pat.getRoundingIncrement(); if (roundingInc != 0.0) { errln((UnicodeString)"ERROR: Rounding increment not zero"); return; } // With rounding now being handled by decNumber, we no longer // set a rounding increment to enable non-default mode rounding, // checking of which was the original point of this test. // set rounding mode with zero increment. Rounding // increment should not be set by this operation pat.setRoundingMode((DecimalFormat::ERoundingMode)0); roundingInc = pat.getRoundingIncrement(); if (roundingInc != 0.0) { errln((UnicodeString)"ERROR: Rounding increment not zero after setRoundingMode"); return; } }
void G7CollationTest::TestDemo3(/* char* par */) { logln("Demo Test 3 : Create a new table collation with rules \"& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'\""); UErrorCode status = U_ZERO_ERROR; Collator *col = Collator::createInstance("en_US", status); if(U_FAILURE(status)) { errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); delete col; return; } const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); UnicodeString newRules = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"; newRules.insert(0, baseRules); RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); if (U_FAILURE(status)) { errln("Demo Test 3 Table Collation object creation failed."); return; } int32_t j, n; for (j = 0; j < TOTALTESTSET; j++) { for (n = j+1; n < TOTALTESTSET; n++) { doTest(myCollation, testCases[results[10][j]], testCases[results[10][n]], Collator::LESS); } } delete myCollation; delete col; }
void G7CollationTest::TestDemo4(/* char* par */) { logln("Demo Test 4 : Create a new table collation with rules \" & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' \""); UErrorCode status = U_ZERO_ERROR; Collator *col = Collator::createInstance("en_US", status); if(U_FAILURE(status)) { delete col; errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); return; } const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); UnicodeString newRules = " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "; newRules.insert(0, baseRules); RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); int32_t j, n; for (j = 0; j < TOTALTESTSET; j++) { for (n = j+1; n < TOTALTESTSET; n++) { doTest(myCollation, testCases[results[11][j]], testCases[results[11][n]], Collator::LESS); } } delete myCollation; delete col; }
void IntlTestDecimalFormatAPI::testRoundingInc(/*char *par*/) { UErrorCode status = U_ZERO_ERROR; DecimalFormat pat(UnicodeString("#,##0.00"),status); if(U_FAILURE(status)) { errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s", u_errorName(status)); return; } // get default rounding increment double roundingInc = pat.getRoundingIncrement(); if (roundingInc != 0.0) { errln((UnicodeString)"ERROR: Rounding increment not zero"); return; } // set rounding mode with zero increment. Rounding // increment should be set by this operation pat.setRoundingMode((DecimalFormat::ERoundingMode)0); roundingInc = pat.getRoundingIncrement(); if (roundingInc == 0.0) { errln((UnicodeString)"ERROR: Rounding increment zero"); return; } }
void RBBIAPITest::RoundtripRule(const char *dataFile) { UErrorCode status = U_ZERO_ERROR; UParseError parseError; parseError.line = 0; parseError.offset = 0; LocalUDataMemoryPointer data(udata_open(U_ICUDATA_BRKITR, "brk", dataFile, &status)); uint32_t length; const UChar *builtSource; const uint8_t *rbbiRules; const uint8_t *builtRules; if (U_FAILURE(status)) { errcheckln(status, "Can't open \"%s\" - %s", dataFile, u_errorName(status)); return; } builtRules = (const uint8_t *)udata_getMemory(data.getAlias()); builtSource = (const UChar *)(builtRules + ((RBBIDataHeader*)builtRules)->fRuleSource); RuleBasedBreakIterator *brkItr = new RuleBasedBreakIterator(builtSource, parseError, status); if (U_FAILURE(status)) { errln("createRuleBasedBreakIterator: ICU Error \"%s\" at line %d, column %d\n", u_errorName(status), parseError.line, parseError.offset); return; }; rbbiRules = brkItr->getBinaryRules(length); logln("Comparing \"%s\" len=%d", dataFile, length); if (memcmp(builtRules, rbbiRules, (int32_t)length) != 0) { errln("Built rules and rebuilt rules are different %s", dataFile); return; } delete brkItr; }
void DateFormatRegressionTest::Test4104136(void) { UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *sdf = new SimpleDateFormat(status); if(U_FAILURE(status)) { errcheckln(status, "Couldn't create SimpleDateFormat, error %s", u_errorName(status)); delete sdf; return; } if(failure(status, "new SimpleDateFormat")) return; UnicodeString pattern = "'time' hh:mm"; sdf->applyPattern(pattern); logln("pattern: \"" + pattern + "\""); UnicodeString strings [] = { (UnicodeString)"time 10:30", (UnicodeString) "time 10:x", (UnicodeString) "time 10x" }; ParsePosition ppos [] = { ParsePosition(10), ParsePosition(0), ParsePosition(0) }; UDate dates [] = { date(70, UCAL_JANUARY, 1, 10, 30), -1, -1 }; /*Object[] DATA = { "time 10:30", new ParsePosition(10), new Date(70, Calendar.JANUARY, 1, 10, 30), "time 10:x", new ParsePosition(0), null, "time 10x", new ParsePosition(0), null, };*/ for(int i = 0; i < 3; i++) { UnicodeString text = strings[i]; ParsePosition finish = ppos[i]; UDate exp = dates[i]; ParsePosition pos(0); UDate d = sdf->parse(text, pos); logln(" text: \"" + text + "\""); logln(" index: %d", pos.getIndex()); logln((UnicodeString) " result: " + d); if(pos.getIndex() != finish.getIndex()) errln("Fail: Expected pos " + finish.getIndex()); if (! ((d == 0 && exp == -1) || (d == exp))) errln((UnicodeString) "Fail: Expected result " + exp); } delete sdf; }
UBool DateFormatMiscTests::failure(UErrorCode status, const char* msg) { if(U_FAILURE(status)) { errcheckln(status, UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status)); return TRUE; } return FALSE; }
void IdnaConfTest::Call(){ if (type == -1 || option == -1 || passfail == -1 || namebase.isBogus() || namezone.isBogus()){ errln("Incomplete record"); } else { UErrorCode status = U_ZERO_ERROR; UChar result[200] = {0,}; // simple life const UChar *p = namebase.getTerminatedBuffer(); const int p_len = namebase.length(); if (type == 0 && option == 0){ uidna_IDNToASCII(p, p_len, result, 200, UIDNA_USE_STD3_RULES, NULL, &status); } else if (type == 0 && option == 1){ uidna_IDNToASCII(p, p_len, result, 200, UIDNA_ALLOW_UNASSIGNED, NULL, &status); } else if (type == 1 && option == 0){ uidna_IDNToUnicode(p, p_len, result, 200, UIDNA_USE_STD3_RULES, NULL, &status); } else if (type == 1 && option == 1){ uidna_IDNToUnicode(p, p_len, result, 200, UIDNA_ALLOW_UNASSIGNED, NULL, &status); } if (passfail == 0){ if (U_FAILURE(status)){ id.append(" should pass, but failed. - "); id.append(u_errorName(status)); errcheckln(status, id); } else{ if (namezone.compare(result, -1) == 0){ // expected logln(UnicodeString("namebase: ") + prettify(namebase) + UnicodeString(" result: ") + prettify(result)); } else { id.append(" no error, but result is not as expected."); errln(id); } } } else if (passfail == 1){ if (U_FAILURE(status)){ // expected // TODO: Uncomment this when U_IDNA_ZERO_LENGTH_LABEL_ERROR is added to u_errorName //logln("Got the expected error: " + UnicodeString(u_errorName(status))); } else{ if (namebase.compare(result, -1) == 0){ // garbage in -> garbage out logln(UnicodeString("ICU will not recognize malformed ACE-Prefixes or incorrect ACE-Prefixes. ") + UnicodeString("namebase: ") + prettify(namebase) + UnicodeString(" result: ") + prettify(result)); } else { id.append(" should fail, but not failed. "); id.append(u_errorName(status)); errln(id); } } } } type = option = passfail = -1; namebase.setToBogus(); namezone.setToBogus(); id.remove(); return; }
CollationGermanTest::CollationGermanTest() : myCollation(0) { UErrorCode status = U_ZERO_ERROR; myCollation = Collator::createInstance(Locale::getGermany(), status); if(!myCollation || U_FAILURE(status)) { errcheckln(status, __FILE__ "failed to create! err " + UnicodeString(u_errorName(status))); /* if it wasn't already: */ delete myCollation; myCollation = NULL; } }
CollationRegressionTest::CollationRegressionTest() { UErrorCode status = U_ZERO_ERROR; en_us = (RuleBasedCollator *)Collator::createInstance(Locale::getUS(), status); if(U_FAILURE(status)) { delete en_us; en_us = 0; errcheckln(status, "Collator creation failed with %s", u_errorName(status)); return; } }
UBool CalendarTimeZoneTest::failure(UErrorCode status, const char* msg, UBool possibleDataError) { if (U_FAILURE(status)) { if (possibleDataError) { dataerrln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status)); } else { errcheckln(status, UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status)); } return TRUE; } return FALSE; }
CollationIteratorTest::CollationIteratorTest() : test1("What subset of all possible test cases?", ""), test2("has the highest probability of detecting", "") { en_us = (RuleBasedCollator *)Collator::createInstance(Locale::getUS(), status); if(U_FAILURE(status)) { delete en_us; en_us = 0; errcheckln(status, "Collator creation failed with %s", u_errorName(status)); return; } }
void IntlTestDecimalFormatAPI::testRounding(/*char *par*/) { UErrorCode status = U_ZERO_ERROR; double Roundingnumber = 2.55; double Roundingnumber1 = -2.55; //+2.55 results -2.55 results double result[]={ 3.0, -2.0, // kRoundCeiling 0, 2.0, -3.0, // kRoundFloor 1, 2.0, -2.0, // kRoundDown 2, 3.0, -3.0, // kRoundUp 3, 3.0, -3.0, // kRoundHalfEven 4, 3.0, -3.0, // kRoundHalfDown 5, 3.0, -3.0 // kRoundHalfUp 6 }; DecimalFormat pat(status); if(U_FAILURE(status)) { errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s", u_errorName(status)); return; } uint16_t mode; uint16_t i=0; UnicodeString message; UnicodeString resultStr; for(mode=0;mode < 7;mode++){ pat.setRoundingMode((DecimalFormat::ERoundingMode)mode); if(pat.getRoundingMode() != (DecimalFormat::ERoundingMode)mode){ errln((UnicodeString)"SetRoundingMode or GetRoundingMode failed for mode=" + mode); } //for +2.55 with RoundingIncrement=1.0 pat.setRoundingIncrement(1.0); pat.format(Roundingnumber, resultStr); message= (UnicodeString)"Round() failed: round(" + (double)Roundingnumber + UnicodeString(",") + mode + UnicodeString(",FALSE) with RoundingIncrement=1.0==>"); verify(message, resultStr, result[i++]); message.remove(); resultStr.remove(); //for -2.55 with RoundingIncrement=1.0 pat.format(Roundingnumber1, resultStr); message= (UnicodeString)"Round() failed: round(" + (double)Roundingnumber1 + UnicodeString(",") + mode + UnicodeString(",FALSE) with RoundingIncrement=1.0==>"); verify(message, resultStr, result[i++]); message.remove(); resultStr.remove(); } }
void IntlTestDecimalFormatAPI::TestScale() { typedef struct TestData { double inputValue; int inputScale; const char *expectedOutput; } TestData; static TestData testData[] = { { 100.0, 3, "100,000" }, { 10034.0, -2, "100.34" }, { 0.86, -3, "0.0009" }, { -0.000455, 1, "-0%" }, { -0.000555, 1, "-1%" }, { 0.000455, 1, "0%" }, { 0.000555, 1, "1%" }, }; UErrorCode status = U_ZERO_ERROR; DecimalFormat pat(status); if(U_FAILURE(status)) { errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s", u_errorName(status)); return; } UnicodeString message; UnicodeString resultStr; UnicodeString exp; UnicodeString percentPattern("#,##0%"); pat.setMaximumFractionDigits(4); for(int32_t i=0; i < UPRV_LENGTHOF(testData); i++) { if ( i > 2 ) { pat.applyPattern(percentPattern,status); } pat.setAttribute(UNUM_SCALE,testData[i].inputScale,status); pat.format(testData[i].inputValue, resultStr); message = UnicodeString("Unexpected output for ") + testData[i].inputValue + UnicodeString(" and scale ") + testData[i].inputScale + UnicodeString(". Got: "); exp = testData[i].expectedOutput; verifyString(message, resultStr, exp); message.remove(); resultStr.remove(); exp.remove(); } }
void DateFormatRegressionTest::Test4210209(void) { UErrorCode status = U_ZERO_ERROR; UnicodeString pattern("MMM d, yyyy"); SimpleDateFormat sfmt(pattern, Locale::getUS(), status); SimpleDateFormat sdisp("MMM dd yyyy GG", Locale::getUS(), status); DateFormat& fmt = *(DateFormat*)&sfmt; // Yuck: See j25 DateFormat& disp = *(DateFormat*)&sdisp; // Yuck: See j25 if (U_FAILURE(status)) { errcheckln(status, "Couldn't create SimpleDateFormat - %s", u_errorName(status)); return; } Calendar* calx = (Calendar*)fmt.getCalendar(); // cast away const! calx->setLenient(FALSE); UDate d = date(2000-1900, UCAL_FEBRUARY, 29); UnicodeString s, ss; fmt.format(d, s); logln(disp.format(d, ss.remove()) + " f> " + pattern + " => \"" + s + "\""); ParsePosition pos(0); d = fmt.parse(s, pos); logln(UnicodeString("\"") + s + "\" p> " + pattern + " => " + disp.format(d, ss.remove())); logln(UnicodeString("Parse pos = ") + pos.getIndex() + ", error pos = " + pos.getErrorIndex()); if (pos.getErrorIndex() != -1) { errln(UnicodeString("FAIL: Error index should be -1")); } // The underlying bug is in GregorianCalendar. If the following lines // succeed, the bug is fixed. If the bug isn't fixed, they will throw // an exception. GregorianCalendar cal(status); if (U_FAILURE(status)) { errln("FAIL: Unable to create Calendar"); return; } cal.clear(); cal.setLenient(FALSE); cal.set(2000, UCAL_FEBRUARY, 29); // This should work! logln(UnicodeString("Attempt to set Calendar to Feb 29 2000: ") + disp.format(cal.getTime(status), ss.remove())); if (U_FAILURE(status)) { errln("FAIL: Unable to set Calendar to Feb 29 2000"); } }
void IntlTestDecimalFormatAPI::TestCurrencyPluralInfo(){ UErrorCode status = U_ZERO_ERROR; CurrencyPluralInfo *cpi = new CurrencyPluralInfo(status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: CurrencyPluralInfo(UErrorCode) could not be created"); } CurrencyPluralInfo cpi1 = *cpi; if(cpi->getDynamicClassID() != CurrencyPluralInfo::getStaticClassID()){ errln((UnicodeString)"ERROR: CurrencyPluralInfo::getDynamicClassID() didn't return the expected value"); } cpi->setCurrencyPluralPattern("","",status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: CurrencyPluralInfo::setCurrencyPluralPattern"); } cpi->setLocale(Locale::getCanada(), status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: CurrencyPluralInfo::setLocale"); } cpi->setPluralRules("",status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: CurrencyPluralInfo::setPluralRules"); } DecimalFormat *df = new DecimalFormat(status); if(U_FAILURE(status)) { errcheckln(status, "ERROR: Could not create DecimalFormat - %s", u_errorName(status)); } df->adoptCurrencyPluralInfo(cpi); df->getCurrencyPluralInfo(); df->setCurrencyPluralInfo(cpi1); delete df; }
void RBBIAPITest::TestHashCode() { UErrorCode status=U_ZERO_ERROR; RuleBasedBreakIterator* bi1 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); RuleBasedBreakIterator* bi3 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status); RuleBasedBreakIterator* bi2 = (RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status); if(U_FAILURE(status)){ errcheckln(status, "Fail : in construction - %s", u_errorName(status)); delete bi1; delete bi2; delete bi3; return; } logln((UnicodeString)"Testing hashCode()"); bi1->setText((UnicodeString)"Hash code"); bi2->setText((UnicodeString)"Hash code"); bi3->setText((UnicodeString)"Hash code"); RuleBasedBreakIterator* bi1clone= (RuleBasedBreakIterator*)bi1->clone(); RuleBasedBreakIterator* bi2clone= (RuleBasedBreakIterator*)bi2->clone(); if(bi1->hashCode() != bi1clone->hashCode() || bi1->hashCode() != bi3->hashCode() || bi1clone->hashCode() != bi3->hashCode() || bi2->hashCode() != bi2clone->hashCode()) errln((UnicodeString)"ERROR: identical objects have different hashcodes"); if(bi1->hashCode() == bi2->hashCode() || bi2->hashCode() == bi3->hashCode() || bi1clone->hashCode() == bi2clone->hashCode() || bi1clone->hashCode() == bi2->hashCode()) errln((UnicodeString)"ERROR: different objects have same hashcodes"); delete bi1clone; delete bi2clone; delete bi1; delete bi2; delete bi3; }
void RBBIAPITest::TestBoilerPlate() { UErrorCode status = U_ZERO_ERROR; BreakIterator* a = BreakIterator::createWordInstance(Locale("hi"), status); BreakIterator* b = BreakIterator::createWordInstance(Locale("hi_IN"),status); if (U_FAILURE(status)) { errcheckln(status, "Creation of break iterator failed %s", u_errorName(status)); return; } if(*a!=*b){ errln("Failed: boilerplate method operator!= does not return correct results"); } BreakIterator* c = BreakIterator::createWordInstance(Locale("ja"),status); if(a && c){ if(*c==*a){ errln("Failed: boilerplate method opertator== does not return correct results"); } }else{ errln("creation of break iterator failed"); } delete a; delete b; delete c; }
void SSearchTest::offsetTest() { const char *test[] = { // The sequence \u0FB3\u0F71\u0F71\u0F80 contains a discontiguous // contraction (\u0FB3\u0F71\u0F80) logically followed by \u0F71. "\\u1E33\\u0FB3\\u0F71\\u0F71\\u0F80\\uD835\\uDF6C\\u01B0", "\\ua191\\u16ef\\u2036\\u017a", #if 0 // This results in a complex interaction between contraction, // expansion and normalization that confuses the backwards offset fixups. "\\u0F7F\\u0F80\\u0F81\\u0F82\\u0F83\\u0F84\\u0F85", #endif "\\u0F80\\u0F81\\u0F82\\u0F83\\u0F84\\u0F85", "\\u07E9\\u07EA\\u07F1\\u07F2\\u07F3", "\\u02FE\\u02FF" "\\u0300\\u0301\\u0302\\u0303\\u0304\\u0305\\u0306\\u0307\\u0308\\u0309\\u030A\\u030B\\u030C\\u030D\\u030E\\u030F" "\\u0310\\u0311\\u0312\\u0313\\u0314\\u0315\\u0316\\u0317\\u0318\\u0319\\u031A\\u031B\\u031C\\u031D\\u031E\\u031F" "\\u0320\\u0321\\u0322\\u0323\\u0324\\u0325\\u0326\\u0327\\u0328\\u0329\\u032A\\u032B\\u032C\\u032D\\u032E\\u032F" "\\u0330\\u0331\\u0332\\u0333\\u0334\\u0335\\u0336\\u0337\\u0338\\u0339\\u033A\\u033B\\u033C\\u033D\\u033E\\u033F" "\\u0340\\u0341\\u0342\\u0343\\u0344\\u0345\\u0346\\u0347\\u0348\\u0349\\u034A\\u034B\\u034C\\u034D\\u034E", // currently not working, see #8081 "\\u02FE\\u02FF\\u0300\\u0301\\u0302\\u0303\\u0316\\u0317\\u0318", // currently not working, see #8081 "a\\u02FF\\u0301\\u0316", // currently not working, see #8081 "a\\u02FF\\u0316\\u0301", "a\\u0430\\u0301\\u0316", "a\\u0430\\u0316\\u0301", "abc\\u0E41\\u0301\\u0316", "abc\\u0E41\\u0316\\u0301", "\\u0E41\\u0301\\u0316", "\\u0E41\\u0316\\u0301", "a\\u0301\\u0316", "a\\u0316\\u0301", "\\uAC52\\uAC53", "\\u34CA\\u34CB", "\\u11ED\\u11EE", "\\u30C3\\u30D0", "p\\u00E9ch\\u00E9", "a\\u0301\\u0325", "a\\u0300\\u0325", "a\\u0325\\u0300", "A\\u0323\\u0300B", "A\\u0300\\u0323B", "A\\u0301\\u0323B", "A\\u0302\\u0301\\u0323B", "abc", "ab\\u0300c", "ab\\u0300\\u0323c", " \\uD800\\uDC00\\uDC00", "a\\uD800\\uDC00\\uDC00", "A\\u0301\\u0301", "A\\u0301\\u0323", "A\\u0301\\u0323B", "B\\u0301\\u0323C", "A\\u0300\\u0323B", "\\u0301A\\u0301\\u0301", "abcd\\r\\u0301", "p\\u00EAche", "pe\\u0302che", }; int32_t testCount = ARRAY_SIZE(test); UErrorCode status = U_ZERO_ERROR; RuleBasedCollator *col = (RuleBasedCollator *) Collator::createInstance(Locale::getEnglish(), status); if (U_FAILURE(status)) { errcheckln(status, "Failed to create collator in offsetTest! - %s", u_errorName(status)); return; } char buffer[4096]; // A bit of a hack... just happens to be long enough for all the test cases... // We could allocate one that's the right size by (CE_count * 10) + 2 // 10 chars is enough room for 8 hex digits plus ", ". 2 extra chars for "[" and "]" col->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status); for(int32_t i = 0; i < testCount; i += 1) { if (i>=4 && i<=6 && logKnownIssue("9156", "was 8081")) { continue; // timebomb until ticket #9156 (was #8081) is resolved } UnicodeString ts = CharsToUnicodeString(test[i]); CollationElementIterator *iter = col->createCollationElementIterator(ts); OrderList forwardList; OrderList backwardList; int32_t order, low, high; do { low = iter->getOffset(); order = iter->next(status); high = iter->getOffset(); forwardList.add(order, low, high); } while (order != CollationElementIterator::NULLORDER); iter->reset(); iter->setOffset(ts.length(), status); backwardList.add(CollationElementIterator::NULLORDER, iter->getOffset(), iter->getOffset()); do { high = iter->getOffset(); order = iter->previous(status); low = iter->getOffset(); if (order == CollationElementIterator::NULLORDER) { break; } backwardList.add(order, low, high); } while (TRUE); backwardList.reverse(); if (forwardList.compare(backwardList)) { logln("Works with \"%s\"", test[i]); logln("Forward offsets: [%s]", printOffsets(buffer, forwardList)); // logln("Backward offsets: [%s]", printOffsets(buffer, backwardList)); logln("Forward CEs: [%s]", printOrders(buffer, forwardList)); // logln("Backward CEs: [%s]", printOrders(buffer, backwardList)); logln(); } else { errln("Fails with \"%s\"", test[i]); infoln("Forward offsets: [%s]", printOffsets(buffer, forwardList)); infoln("Backward offsets: [%s]", printOffsets(buffer, backwardList)); infoln("Forward CEs: [%s]", printOrders(buffer, forwardList)); infoln("Backward CEs: [%s]", printOrders(buffer, backwardList)); infoln(); } delete iter; } delete col; }
void StringCaseTest::TestCasingImpl(const UnicodeString &input, const UnicodeString &output, int32_t whichCase, void *iter, const char *localeID, uint32_t options) { // UnicodeString UnicodeString result; const char *name; Locale locale(localeID); result=input; switch(whichCase) { case TEST_LOWER: name="toLower"; result.toLower(locale); break; case TEST_UPPER: name="toUpper"; result.toUpper(locale); break; #if !UCONFIG_NO_BREAK_ITERATION case TEST_TITLE: name="toTitle"; result.toTitle((BreakIterator *)iter, locale, options); break; #endif case TEST_FOLD: name="foldCase"; result.foldCase(options); break; default: name=""; break; // won't happen } if(result!=output) { dataerrln("error: UnicodeString.%s() got a wrong result for a test case from casing.res", name); } #if !UCONFIG_NO_BREAK_ITERATION if(whichCase==TEST_TITLE && options==0) { result=input; result.toTitle((BreakIterator *)iter, locale); if(result!=output) { dataerrln("error: UnicodeString.toTitle(options=0) got a wrong result for a test case from casing.res"); } } #endif // UTF-8 char utf8In[100], utf8Out[100]; int32_t utf8InLength, utf8OutLength, resultLength; UChar *buffer; IcuTestErrorCode errorCode(*this, "TestCasingImpl"); LocalUCaseMapPointer csm(ucasemap_open(localeID, options, errorCode)); #if !UCONFIG_NO_BREAK_ITERATION if(iter!=NULL) { // Clone the break iterator so that the UCaseMap can safely adopt it. UBreakIterator *clone=ubrk_safeClone((UBreakIterator *)iter, NULL, NULL, errorCode); ucasemap_setBreakIterator(csm.getAlias(), clone, errorCode); } #endif u_strToUTF8(utf8In, (int32_t)sizeof(utf8In), &utf8InLength, input.getBuffer(), input.length(), errorCode); switch(whichCase) { case TEST_LOWER: name="ucasemap_utf8ToLower"; utf8OutLength=ucasemap_utf8ToLower(csm.getAlias(), utf8Out, (int32_t)sizeof(utf8Out), utf8In, utf8InLength, errorCode); break; case TEST_UPPER: name="ucasemap_utf8ToUpper"; utf8OutLength=ucasemap_utf8ToUpper(csm.getAlias(), utf8Out, (int32_t)sizeof(utf8Out), utf8In, utf8InLength, errorCode); break; #if !UCONFIG_NO_BREAK_ITERATION case TEST_TITLE: name="ucasemap_utf8ToTitle"; utf8OutLength=ucasemap_utf8ToTitle(csm.getAlias(), utf8Out, (int32_t)sizeof(utf8Out), utf8In, utf8InLength, errorCode); break; #endif case TEST_FOLD: name="ucasemap_utf8FoldCase"; utf8OutLength=ucasemap_utf8FoldCase(csm.getAlias(), utf8Out, (int32_t)sizeof(utf8Out), utf8In, utf8InLength, errorCode); break; default: name=""; utf8OutLength=0; break; // won't happen } buffer=result.getBuffer(utf8OutLength); u_strFromUTF8(buffer, result.getCapacity(), &resultLength, utf8Out, utf8OutLength, errorCode); result.releaseBuffer(errorCode.isSuccess() ? resultLength : 0); if(errorCode.isFailure()) { errcheckln(errorCode, "error: %s() got an error for a test case from casing.res - %s", name, u_errorName(errorCode)); errorCode.reset(); } else if(result!=output) { errln("error: %s() got a wrong result for a test case from casing.res", name); errln("expected \"" + output + "\" got \"" + result + "\"" ); } }
void SSearchTest::monkeyTest(char *params) { // ook! UErrorCode status = U_ZERO_ERROR; //UCollator *coll = ucol_open(NULL, &status); UCollator *coll = ucol_openFromShortString("S1", FALSE, NULL, &status); if (U_FAILURE(status)) { errcheckln(status, "Failed to create collator in MonkeyTest! - %s", u_errorName(status)); return; } CollData *monkeyData = new CollData(coll, status); USet *expansions = uset_openEmpty(); USet *contractions = uset_openEmpty(); ucol_getContractionsAndExpansions(coll, contractions, expansions, FALSE, &status); U_STRING_DECL(letter_pattern, "[[:letter:]-[:ideographic:]-[:hangul:]]", 39); U_STRING_INIT(letter_pattern, "[[:letter:]-[:ideographic:]-[:hangul:]]", 39); USet *letters = uset_openPattern(letter_pattern, 39, &status); SetMonkey letterMonkey(letters); StringSetMonkey contractionMonkey(contractions, coll, monkeyData); StringSetMonkey expansionMonkey(expansions, coll, monkeyData); UnicodeString testCase; UnicodeString alternate; UnicodeString pattern, altPattern; UnicodeString prefix, altPrefix; UnicodeString suffix, altSuffix; Monkey *monkeys[] = { &letterMonkey, &contractionMonkey, &expansionMonkey, &contractionMonkey, &expansionMonkey, &contractionMonkey, &expansionMonkey, &contractionMonkey, &expansionMonkey}; int32_t monkeyCount = sizeof(monkeys) / sizeof(monkeys[0]); // int32_t nonMatchCount = 0; UCollationStrength strengths[] = {UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY}; const char *strengthNames[] = {"primary", "secondary", "tertiary"}; int32_t strengthCount = sizeof(strengths) / sizeof(strengths[0]); int32_t loopCount = quick? 1000 : 10000; int32_t firstStrength = 0; int32_t lastStrength = strengthCount - 1; //*/ 0; if (params != NULL) { #if !UCONFIG_NO_REGULAR_EXPRESSIONS UnicodeString p(params); loopCount = getIntParam("loop", p, loopCount); m_seed = getIntParam("seed", p, m_seed); RegexMatcher m(" *strength *= *(primary|secondary|tertiary) *", p, 0, status); if (m.find()) { UnicodeString breakType = m.group(1, status); for (int32_t s = 0; s < strengthCount; s += 1) { if (breakType == strengthNames[s]) { firstStrength = lastStrength = s; break; } } m.reset(); p = m.replaceFirst("", status); } if (RegexMatcher("\\S", p, 0, status).find()) { // Each option is stripped out of the option string as it is processed. // All options have been checked. The option string should have been completely emptied.. char buf[100]; p.extract(buf, sizeof(buf), NULL, status); buf[sizeof(buf)-1] = 0; errln("Unrecognized or extra parameter: %s\n", buf); return; } #else infoln("SSearchTest built with UCONFIG_NO_REGULAR_EXPRESSIONS: ignoring parameters."); #endif } for(int32_t s = firstStrength; s <= lastStrength; s += 1) { int32_t notFoundCount = 0; logln("Setting strength to %s.", strengthNames[s]); ucol_setStrength(coll, strengths[s]); // TODO: try alternate prefix and suffix too? // TODO: alterntaes are only equal at primary strength. Is this OK? for(int32_t t = 0; t < loopCount; t += 1) { uint32_t seed = m_seed; // int32_t nmc = 0; generateTestCase(coll, monkeys, monkeyCount, pattern, altPattern); generateTestCase(coll, monkeys, monkeyCount, prefix, altPrefix); generateTestCase(coll, monkeys, monkeyCount, suffix, altSuffix); // pattern notFoundCount += monkeyTestCase(coll, pattern, pattern, altPattern, "pattern", strengthNames[s], seed); testCase.remove(); testCase.append(prefix); testCase.append(/*alt*/pattern); // prefix + pattern notFoundCount += monkeyTestCase(coll, testCase, pattern, altPattern, "prefix + pattern", strengthNames[s], seed); testCase.append(suffix); // prefix + pattern + suffix notFoundCount += monkeyTestCase(coll, testCase, pattern, altPattern, "prefix + pattern + suffix", strengthNames[s], seed); testCase.remove(); testCase.append(pattern); testCase.append(suffix); // pattern + suffix notFoundCount += monkeyTestCase(coll, testCase, pattern, altPattern, "pattern + suffix", strengthNames[s], seed); } logln("For strength %s the not found count is %d.", strengthNames[s], notFoundCount); } uset_close(contractions); uset_close(expansions); uset_close(letters); delete monkeyData; ucol_close(coll); }
void DateFormatMiscTests::test4117335() { //UnicodeString bc = "\u7d00\u5143\u524d"; UChar bcC [] = { 0x7D00, 0x5143, 0x524D }; UnicodeString bc(bcC, 3, 3); //UnicodeString ad = "\u897f\u66a6"; UChar adC [] = { 0x897F, 0x66A6 }; UnicodeString ad(adC, 2, 2); //UnicodeString jstLong = "\u65e5\u672c\u6a19\u6e96\u6642"; UChar jstLongC [] = { 0x65e5, 0x672c, 0x6a19, 0x6e96, 0x6642 }; UChar jdtLongC [] = {0x65E5, 0x672C, 0x590F, 0x6642, 0x9593}; UnicodeString jstLong(jstLongC, 5, 5); UnicodeString jstShort = "JST"; UnicodeString tzID = "Asia/Tokyo"; UnicodeString jdtLong(jdtLongC, 5, 5); UnicodeString jdtShort = "JDT"; UErrorCode status = U_ZERO_ERROR; DateFormatSymbols *symbols = new DateFormatSymbols(Locale::getJapan(), status); if(U_FAILURE(status)) { errcheckln(status, "Failure creating DateFormatSymbols, %s", u_errorName(status)); delete symbols; return; } failure(status, "new DateFormatSymbols"); int32_t eraCount = 0; const UnicodeString *eras = symbols->getEraNames(eraCount); logln(UnicodeString("BC = ") + eras[0]); if (eras[0] != bc) { errln("*** Should have been " + bc); //throw new Exception("Error in BC"); } logln(UnicodeString("AD = ") + eras[1]); if (eras[1] != ad) { errln("*** Should have been " + ad); //throw new Exception("Error in AD"); } int32_t rowCount, colCount; const UnicodeString **zones = symbols->getZoneStrings(rowCount, colCount); //don't hard code the index .. compute it. int32_t index = -1; for (int32_t i = 0; i < rowCount; ++i) { if (tzID == (zones[i][0])) { index = i; break; } } logln(UnicodeString("Long zone name = ") + zones[index][1]); if (zones[index][1] != jstLong) { errln("*** Should have been " + prettify(jstLong)+ " but it is: " + prettify(zones[index][1])); //throw new Exception("Error in long TZ name"); } logln(UnicodeString("Short zone name = ") + zones[index][2]); if (zones[index][2] != jstShort) { errln("*** Should have been " + prettify(jstShort) + " but it is: " + prettify(zones[index][2])); //throw new Exception("Error in short TZ name"); } logln(UnicodeString("Long zone name = ") + zones[index][3]); if (zones[index][3] != jdtLong) { errln("*** Should have been " + prettify(jstLong) + " but it is: " + prettify(zones[index][3])); //throw new Exception("Error in long TZ name"); } logln(UnicodeString("SHORT zone name = ") + zones[index][4]); if (zones[index][4] != jdtShort) { errln("*** Should have been " + prettify(jstShort)+ " but it is: " + prettify(zones[index][4])); //throw new Exception("Error in short TZ name"); } delete symbols; }