void LocaleDisplayNamesTest::TestUldnDisplayContext() { const LocNameDispContextItem * ctxtItemPtr; for (ctxtItemPtr = ctxtItems; ctxtItemPtr->displayLocale != NULL; ctxtItemPtr++) { UDisplayContext contexts[2] = {ctxtItemPtr->dialectHandling, ctxtItemPtr->capitalization}; UErrorCode status = U_ZERO_ERROR; ULocaleDisplayNames * uldn = uldn_openForContext(ctxtItemPtr->displayLocale, contexts, 2, &status); if (U_FAILURE(status)) { errln(UnicodeString("FAIL: uldn_openForContext failed for locale ") + ctxtItemPtr->displayLocale + ", dialectHandling " + ctxtItemPtr->dialectHandling + ", capitalization " + ctxtItemPtr->capitalization); } else { UDisplayContext dialectHandling = uldn_getContext(uldn, UDISPCTX_TYPE_DIALECT_HANDLING, &status); UDisplayContext capitalization = uldn_getContext(uldn, UDISPCTX_TYPE_CAPITALIZATION, &status); if (U_FAILURE(status)) { errln(UnicodeString("FAIL: uldn_getContext status ") + (int)status); } else if (dialectHandling != ctxtItemPtr->dialectHandling || capitalization != ctxtItemPtr->capitalization) { errln("FAIL: uldn_getContext retrieved incorrect dialectHandling or capitalization"); } else { UChar nameBuf[ULOC_FULLNAME_CAPACITY]; int32_t len = uldn_localeDisplayName(uldn, ctxtItemPtr->localeToBeNamed, nameBuf, ULOC_FULLNAME_CAPACITY, &status); if (U_FAILURE(status)) { dataerrln(UnicodeString("FAIL: uldn_localeDisplayName status: ") + u_errorName(status)); } else if (u_strcmp(ctxtItemPtr->result, nameBuf) != 0) { UnicodeString exp(ctxtItemPtr->result, u_strlen(ctxtItemPtr->result)); UnicodeString got(nameBuf, len); dataerrln(UnicodeString("FAIL: uldn_localeDisplayName, capitalization ") + ctxtItemPtr->capitalization + ", expected " + exp + ", got " + got ); } } uldn_close(uldn); } } }
void TimeZoneBoundaryTest::verifyDST(UDate d, TimeZone* time_zone, UBool expUseDaylightTime, UBool expInDaylightTime, UDate expZoneOffset, UDate expDSTOffset) { UnicodeString str; UErrorCode status = U_ZERO_ERROR; logln("-- Verifying time " + dateToString(d) + " in zone " + time_zone->getID(str)); if (time_zone->inDaylightTime(d, status) == expInDaylightTime) logln(UnicodeString("PASS: inDaylightTime = ") + (time_zone->inDaylightTime(d, status)?"true":"false")); else dataerrln(UnicodeString("FAIL: inDaylightTime = ") + (time_zone->inDaylightTime(d, status)?"true":"false")); if (failure(status, "TimeZone::inDaylightTime", TRUE)) return; if (time_zone->useDaylightTime() == expUseDaylightTime) logln(UnicodeString("PASS: useDaylightTime = ") + (time_zone->useDaylightTime()?"true":"false")); else dataerrln(UnicodeString("FAIL: useDaylightTime = ") + (time_zone->useDaylightTime()?"true":"false")); if (time_zone->getRawOffset() == expZoneOffset) logln(UnicodeString("PASS: getRawOffset() = ") + (expZoneOffset / ONE_HOUR)); else dataerrln(UnicodeString("FAIL: getRawOffset() = ") + (time_zone->getRawOffset() / ONE_HOUR) + "; expected " + (expZoneOffset / ONE_HOUR)); GregorianCalendar *gc = new GregorianCalendar(time_zone->clone(), status); gc->setTime(d, status); if (failure(status, "GregorianCalendar::setTime")) return; int32_t offset = time_zone->getOffset((uint8_t)gc->get(UCAL_ERA, status), gc->get(UCAL_YEAR, status), gc->get(UCAL_MONTH, status), gc->get(UCAL_DATE, status), (uint8_t)gc->get(UCAL_DAY_OF_WEEK, status), ((gc->get(UCAL_HOUR_OF_DAY, status) * 60 + gc->get(UCAL_MINUTE, status)) * 60 + gc->get(UCAL_SECOND, status)) * 1000 + gc->get(UCAL_MILLISECOND, status), status); if (failure(status, "GregorianCalendar::get")) return; if (offset == expDSTOffset) logln(UnicodeString("PASS: getOffset() = ") + (offset / ONE_HOUR)); else dataerrln(UnicodeString("FAIL: getOffset() = ") + (offset / ONE_HOUR) + "; expected " + (expDSTOffset / ONE_HOUR)); delete gc; }
void AlphabeticIndexTest::TestChineseUnihan() { UErrorCode status = U_ZERO_ERROR; AlphabeticIndex index("zh-u-co-unihan", status); if(U_FAILURE(status)) { dataerrln("unable create an AlphabeticIndex for Chinese/unihan: %s", u_errorName(status)); return; } index.setMaxLabelCount(500, status); // ICU 54 default is 99. LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableIndex(status)); TEST_CHECK_STATUS; int32_t bucketCount = immIndex->getBucketCount(); if(bucketCount < 216) { // There should be at least an underflow and overflow label, // and one for each of 214 radicals, // and maybe additional labels for simplified radicals. dataerrln("too few buckets/labels for Chinese/unihan: %d (is zh/unihan data available?)", bucketCount); return; } else { logln("Chinese/unihan has %d buckets/labels", bucketCount); } // bucketIndex = radical number, adjusted for simplified radicals in lower buckets. int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x4e5d), status); assertEquals("getBucketIndex(U+4E5D)", 5, bucketIndex); // radical 100, and there is a 90' since Unicode 8 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x7527), status); assertEquals("getBucketIndex(U+7527)", 101, bucketIndex); }
void TimeUnitTest::test10219Plurals() { Locale usLocale("en_US"); double values[2] = {1.588, 1.011}; UnicodeString expected[2][3] = { {"1 minute", "1.5 minutes", "1.58 minutes"}, {"1 minute", "1.0 minutes", "1.01 minutes"} }; UErrorCode status = U_ZERO_ERROR; TimeUnitFormat tuf(usLocale, status); if (U_FAILURE(status)) { dataerrln("generating TimeUnitFormat Object failed: %s", u_errorName(status)); return; } LocalPointer<DecimalFormat> nf((DecimalFormat *) NumberFormat::createInstance(usLocale, status)); if (U_FAILURE(status)) { dataerrln("generating NumberFormat Object failed: %s", u_errorName(status)); return; } for (int32_t j = 0; j < UPRV_LENGTHOF(values); ++j) { for (int32_t i = 0; i < UPRV_LENGTHOF(expected[j]); ++i) { nf->setMinimumFractionDigits(i); nf->setMaximumFractionDigits(i); nf->setRoundingMode(DecimalFormat::kRoundDown); tuf.setNumberFormat(*nf, status); if (U_FAILURE(status)) { dataerrln("setting NumberFormat failed: %s", u_errorName(status)); return; } UnicodeString actual; Formattable fmt; LocalPointer<TimeUnitAmount> tamt( new TimeUnitAmount(values[j], TimeUnit::UTIMEUNIT_MINUTE, status), status); if (U_FAILURE(status)) { dataerrln("generating TimeUnitAmount Object failed: %s", u_errorName(status)); return; } fmt.adoptObject(tamt.orphan()); tuf.format(fmt, actual, status); if (U_FAILURE(status)) { dataerrln("Actual formatting failed: %s", u_errorName(status)); return; } if (expected[j][i] != actual) { errln("Expected " + expected[j][i] + ", got " + actual); } } } // test parsing Formattable result; ParsePosition pos; UnicodeString formattedString = "1 minutes"; tuf.parseObject(formattedString, result, pos); if (formattedString.length() != pos.getIndex()) { errln("Expect parsing to go all the way to the end of the string."); } }
void SSearchTest::sharpSTest() { UErrorCode status = U_ZERO_ERROR; UCollator *coll = NULL; UnicodeString lp = "fuss"; UnicodeString sp = "fu\\u00DF"; UnicodeString targets[] = {"fu\\u00DF", "fu\\u00DFball", "1fu\\u00DFball", "12fu\\u00DFball", "123fu\\u00DFball", "1234fu\\u00DFball", "ffu\\u00DF", "fufu\\u00DF", "fusfu\\u00DF", "fuss", "ffuss", "fufuss", "fusfuss", "1fuss", "12fuss", "123fuss", "1234fuss", "fu\\u00DF", "1fu\\u00DF", "12fu\\u00DF", "123fu\\u00DF", "1234fu\\u00DF"}; int32_t start = -1, end = -1; coll = ucol_openFromShortString("LEN_S1", FALSE, NULL, &status); TEST_ASSERT_SUCCESS(status); UnicodeString lpUnescaped = lp.unescape(); UnicodeString spUnescaped = sp.unescape(); LocalUStringSearchPointer ussLong(usearch_openFromCollator(lpUnescaped.getBuffer(), lpUnescaped.length(), lpUnescaped.getBuffer(), lpUnescaped.length(), // actual test data will be set later coll, NULL, // the break iterator &status)); LocalUStringSearchPointer ussShort(usearch_openFromCollator(spUnescaped.getBuffer(), spUnescaped.length(), spUnescaped.getBuffer(), spUnescaped.length(), // actual test data will be set later coll, NULL, // the break iterator &status)); TEST_ASSERT_SUCCESS(status); for (uint32_t t = 0; t < (sizeof(targets)/sizeof(targets[0])); t += 1) { UBool bFound; UnicodeString target = targets[t].unescape(); start = end = -1; usearch_setText(ussLong.getAlias(), target.getBuffer(), target.length(), &status); bFound = usearch_search(ussLong.getAlias(), 0, &start, &end, &status); TEST_ASSERT_SUCCESS(status); if (bFound) { logln("Test %d: found long pattern at [%d, %d].", t, start, end); } else { dataerrln("Test %d: did not find long pattern.", t); } usearch_setText(ussShort.getAlias(), target.getBuffer(), target.length(), &status); bFound = usearch_search(ussShort.getAlias(), 0, &start, &end, &status); TEST_ASSERT_SUCCESS(status); if (bFound) { logln("Test %d: found long pattern at [%d, %d].", t, start, end); } else { dataerrln("Test %d: did not find long pattern.", t); } } ucol_close(coll); }
void TransliteratorAPITest::TestTransliterate1(){ UnicodeString Data[]={ //ID, input string, transliterated string "Any-Hex", "hello", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", "") , "Hex-Any", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), "hello" , "Latin-Devanagari",CharsToUnicodeString("bha\\u0304rata"), CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924") , "Latin-Devanagari",UnicodeString("kra ksha khra gra cra dya dhya",""), CharsToUnicodeString("\\u0915\\u094D\\u0930 \\u0915\\u094D\\u0936 \\u0916\\u094D\\u0930 \\u0917\\u094D\\u0930 \\u091a\\u094D\\u0930 \\u0926\\u094D\\u092F \\u0927\\u094D\\u092F") , "Devanagari-Latin", CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), CharsToUnicodeString("bh\\u0101rata"), // "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"), CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042") , // "Expanded-Contracted", CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042"), CharsToUnicodeString("\\u00C0\\u00C1\\u0042") , //"Latin-Arabic", "aap", CharsToUnicodeString("\\u0627\\u06A4") , //"Arabic-Latin", CharsToUnicodeString("\\u0627\\u06A4"), "aap" }; UnicodeString gotResult; UnicodeString temp; UnicodeString message; Transliterator* t; logln("Testing transliterate"); UErrorCode status = U_ZERO_ERROR; UParseError parseError; for(uint32_t i=0;i<sizeof(Data)/sizeof(Data[0]); i=i+3){ t=Transliterator::createInstance(Data[i+0], UTRANS_FORWARD, parseError, status); if(t==0){ dataerrln("FAIL: construction: " + Data[i+0] + " Error: " + u_errorName(status)); dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); status = U_ZERO_ERROR; continue; } gotResult = Data[i+1]; t->transliterate(gotResult); message=t->getID() + "->transliterate(UnicodeString, UnicodeString) for\n\t Source:" + prettify(Data[i+1]); doTest(message, gotResult, Data[i+2]); //doubt here temp=Data[i+1]; t->transliterate(temp); message.remove(); message.append(t->getID()); message.append("->transliterate(Replaceable) for \n\tSource:"); message.append(Data[i][1]); doTest(message, temp, Data[i+2]); callEverything(t, __LINE__); delete t; } }
void TransliteratorAPITest::TestKeyboardTransliterator2(){ UnicodeString Data[]={ //insertion, buffer, index[START], index[LIMIT], index[CURSOR] //data for Any-Hex "abc", UnicodeString("Initial String: add-\\u0061\\u0062\\u0063-", ""), "19", "20", "20", "a", UnicodeString("In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "2", "3", "2" , "b", UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0", "0", "0" , "", UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0", "0", "0" , //data for Latin-Devanagiri CharsToUnicodeString("a\\u0304"), CharsToUnicodeString("Hindi -\\u0906-"), "6", "7", "6", CharsToUnicodeString("ma\\u0304"), CharsToUnicodeString("Hindi -\\u0906\\u092E\\u093E-"), "7", "8", "7", CharsToUnicodeString("ra\\u0304"), CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"),"1", "2", "2", CharsToUnicodeString(""), CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"),"1", "2", "2" //data for contracted-Expanded // CharsToUnicodeString("\\u00C1"), CharsToUnicodeString("Ad\\u0041\\u0301d here:"), "1", "2", "1" , // CharsToUnicodeString("\\u00C0"), CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11", // "", CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11", }; Transliterator *t; UnicodeString rs; UnicodeString dataStr; logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)"); UErrorCode status = U_ZERO_ERROR; UParseError parseError; rs="Initial String: add--"; t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); if(t == 0) dataerrln("FAIL : construction - %s", u_errorName(status)); else { keyboardAux(t, Data, rs, 0, 20); delete t; } rs="Hindi --"; t=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); if(t == 0) dataerrln("FAIL : construction - %s", u_errorName(status)); else keyboardAux(t, Data, rs, 20, 40); // rs="Add here:"; // t=Transliterator::createInstance("Contracted-Expanded"); // keyboardAux(t, Data, rs, 35, 55); delete t; }
/** * @bug 4103341 */ 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)) { dataerrln("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; }
/** * @bug 4089106 */ 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)) { dataerrln("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; }
/** * @bug 4073003 */ void DateFormatRegressionTest::Test4073003(void) { //try { UErrorCode ec = U_ZERO_ERROR; SimpleDateFormat fmt("MM/dd/yy", Locale::getUK(), ec); if (U_FAILURE(ec)) { dataerrln("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); } }
/** * @bug 4061287 */ void DateFormatRegressionTest::Test4061287(void) { UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("dd/MM/yyyy"), status); if (U_FAILURE(status)) { dataerrln("Fail new SimpleDateFormat: %s", u_errorName(status)); delete df; return; } failure(status, "new SimpleDateFormat"); //try { logln(UnicodeString("") + df->parse("35/01/1971", status)); failure(status, "df->parse(\"35/01/1971\")"); //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; }
DateFormat* CalendarTimeZoneTest::getDateFormat() { DateFormat *theFormat = 0; if (fgDateFormat != 0) // if there's something in the cache { Mutex lock; if (fgDateFormat != 0) // Someone might have grabbed it. { theFormat = fgDateFormat; fgDateFormat = 0; // We have exclusive right to this formatter. } } if(theFormat == 0) // If we weren't able to pull it out of the cache, then we have to create it. { UErrorCode status = U_ZERO_ERROR; theFormat = new SimpleDateFormat(UnicodeString("EEE MMM dd HH:mm:ss zzz yyyy"), status); if (U_FAILURE(status)) { delete theFormat; theFormat = 0; dataerrln("FAIL: Could not create SimpleDateFormat - %s", u_errorName(status)); } } return theFormat; }
void TimeZoneBoundaryTest::findDaylightBoundaryUsingDate(UDate d, const char* startMode, UDate expectedBoundary) { UnicodeString str; if (dateToString(d, str).indexOf(startMode) == - 1) { logln(UnicodeString("Error: ") + startMode + " not present in " + str); } UDate min = d; UDate max = min + SIX_MONTHS; while ((max - min) > INTERVAL) { UDate mid = (min + max) / 2; UnicodeString* s = &dateToString(mid, str); if (s->indexOf(startMode) != - 1) { min = mid; } else { max = mid; } } logln("Date Before: " + showDate(min)); logln("Date After: " + showDate(max)); UDate mindelta = expectedBoundary - min; UDate maxdelta = max - expectedBoundary; if (mindelta >= 0 && mindelta <= INTERVAL && maxdelta >= 0 && maxdelta <= INTERVAL) logln(UnicodeString("PASS: Expected boundary at ") + expectedBoundary); else dataerrln(UnicodeString("FAIL: Expected boundary at ") + expectedBoundary); }
void AlphabeticIndexTest::TestPinyinFirst() { UErrorCode status = U_ZERO_ERROR; LocalPointer<RuleBasedCollator> coll( static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getChinese(), status))); if (U_FAILURE(status)) { dataerrln("Failed Collator::createInstance call - %s", u_errorName(status)); return; } int32_t reorderCodes[] = { USCRIPT_HAN }; coll->setReorderCodes(reorderCodes, LENGTHOF(reorderCodes), status); TEST_CHECK_STATUS; AlphabeticIndex index(coll.orphan(), status); TEST_CHECK_STATUS; assertEquals("getBucketCount()", 28, index.getBucketCount(status)); // ... A-Z ... index.addLabels(Locale::getChinese(), status); assertEquals("getBucketCount()", 28, index.getBucketCount(status)); // ... A-Z ... int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x897f), status); assertEquals("getBucketIndex(U+897F)", (int32_t)((UChar)0x0058/*X*/ - (UChar)0x0041/*A*/ + 1), (int32_t)bucketIndex); bucketIndex = index.getBucketIndex("i", status); assertEquals("getBucketIndex(i)", 9, bucketIndex); bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x03B1), status); assertEquals("getBucketIndex(Greek alpha)", (int32_t)27, bucketIndex); // U+50005 is an unassigned code point which sorts at the end, independent of the Hani group. bucketIndex = index.getBucketIndex(UnicodeString(0x50005), status); assertEquals("getBucketIndex(U+50005)", 27, bucketIndex); bucketIndex = index.getBucketIndex(UnicodeString((UChar)0xFFFF), status); assertEquals("getBucketIndex(U+FFFF)", 27, bucketIndex); }
void NewResourceBundleTest::TestResourceBundles() { UErrorCode status = U_ZERO_ERROR; loadTestData(status); if(U_FAILURE(status)) { dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status))); return; } /* Make sure that users using te_IN for the default locale don't get test failures. */ Locale originalDefault; if (Locale::getDefault() == Locale("te_IN")) { Locale::setDefault(Locale("en_US"), status); } testTag("only_in_Root", TRUE, FALSE, FALSE); testTag("only_in_te", FALSE, TRUE, FALSE); testTag("only_in_te_IN", FALSE, FALSE, TRUE); testTag("in_Root_te", TRUE, TRUE, FALSE); testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE); testTag("in_Root_te_IN", TRUE, FALSE, TRUE); testTag("in_te_te_IN", FALSE, TRUE, TRUE); testTag("nonexistent", FALSE, FALSE, FALSE); logln("Passed: %d\nFailed: %d", pass, fail); /* Restore the default locale for the other tests. */ Locale::setDefault(originalDefault, status); }
void CanonicalIteratorTest::TestExhaustive() { UErrorCode status = U_ZERO_ERROR; CanonicalIterator it("", status); if (U_FAILURE(status)) { dataerrln("Error creating CanonicalIterator: %s", u_errorName(status)); return; } UChar32 i = 0; UnicodeString s; // Test static and dynamic class IDs if(it.getDynamicClassID() != CanonicalIterator::getStaticClassID()){ errln("CanonicalIterator::getStaticClassId ! = CanonicalIterator.getDynamicClassID"); } for (i = 0; i < 0x10FFFF; quick?i+=0x10:++i) { //for (i = 0xae00; i < 0xaf00; ++i) { if ((i % 0x100) == 0) { logln("Testing U+%06X", i); } // skip characters we know don't have decomps int8_t type = u_charType(i); if (type == U_UNASSIGNED || type == U_PRIVATE_USE_CHAR || type == U_SURROGATE) continue; s = i; characterTest(s, i, it); s += (UChar32)0x0345; //"\\u0345"; characterTest(s, i, it); } }
void CanonicalIteratorTest::TestAPI() { UErrorCode status = U_ZERO_ERROR; // Test reset and getSource UnicodeString start("ljubav"); logln("Testing CanonicalIterator::getSource"); logln("Instantiating canonical iterator with string "+start); CanonicalIterator can(start, status); if (U_FAILURE(status)) { dataerrln("Error creating CanonicalIterator: %s", u_errorName(status)); return; } UnicodeString source = can.getSource(); logln("CanonicalIterator::getSource returned "+source); if(start != source) { errln("CanonicalIterator.getSource() didn't return the starting string. Expected "+start+", got "+source); } logln("Testing CanonicalIterator::reset"); UnicodeString next = can.next(); logln("CanonicalIterator::next returned "+next); can.reset(); UnicodeString afterReset = can.next(); logln("After reset, CanonicalIterator::next returned "+afterReset); if(next != afterReset) { errln("Next after instantiation ("+next+") is different from next after reset ("+afterReset+")."); } logln("Testing getStaticClassID and getDynamicClassID"); if(can.getDynamicClassID() != CanonicalIterator::getStaticClassID()){ errln("RTTI failed for CanonicalIterator getDynamicClassID != getStaticClassID"); } }
UObject *UObjectTest::testClassNoClassID(UObject *obj, const char *className, const char *factory) { if (!obj) { return NULL; } UnicodeString what = UnicodeString(className) + " * x= " + UnicodeString(factory?factory:" ABSTRACT ") + "; "; UClassID dynamicID = obj->getDynamicClassID(); { char tmp[500]; sprintf(tmp, " [dynamic=%p] ", dynamicID); logln(what + tmp); } if(factory != NULL) { /* NULL factory means: abstract */ if(!obj) { dataerrln( "FAIL: ==NULL! " + what); return obj; } if(dynamicID != NULL) { errln("FAIL: dynamicID != NULL! for non-poor-man's-RTTI " + what); } } return obj; }
void ResourceBundleTest::TestGetLocaleByType(void) { const struct { const char *requestedLocale; const char *resourceKey; const char *validLocale; const char *actualLocale; } test[] = { { "te_IN_BLAH", "string_only_in_te_IN", "te_IN", "te_IN" }, { "te_IN_BLAH", "string_only_in_te", "te_IN", "te" }, { "te_IN_BLAH", "string_only_in_Root", "te_IN", "root" }, { "te_IN_BLAH_01234567890_01234567890_01234567890_01234567890_01234567890_01234567890", "array_2d_only_in_Root", "te_IN", "root" }, { "te_IN_BLAH@currency=euro", "array_2d_only_in_te_IN", "te_IN", "te_IN" }, { "te_IN_BLAH@calendar=thai;collation=phonebook", "array_2d_only_in_te", "te_IN", "te" } }; UErrorCode status = U_ZERO_ERROR; const char* testdatapath = loadTestData(status); int32_t i = 0; Locale locale; if(U_FAILURE(status)) { dataerrln("Could not load testdata.dat %s\n", u_errorName(status)); return; } for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) { ResourceBundle rb(testdatapath, test[i].requestedLocale, status); if(U_FAILURE(status)) { err("Could not open resource bundle %s (error %s)\n", test[i].requestedLocale, u_errorName(status)); status = U_ZERO_ERROR; continue; } ResourceBundle res = rb.get(test[i].resourceKey, status); if(U_FAILURE(status)) { err("Couldn't find the key %s. Error: %s\n", test[i].resourceKey, u_errorName(status)); status = U_ZERO_ERROR; continue; } locale = res.getLocale(ULOC_REQUESTED_LOCALE, status); if(locale != Locale::getDefault()) { err("Expected requested locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); } locale = res.getLocale(ULOC_VALID_LOCALE, status); if(strcmp(locale.getName(), test[i].validLocale) != 0) { err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); } locale = res.getLocale(ULOC_ACTUAL_LOCALE, status); if(strcmp(locale.getName(), test[i].actualLocale) != 0) { err("Expected actual locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); } } }
/** * @bug 4104522 * CANNOT REPRODUCE * According to the bug report, this test should throw a * StringIndexOutOfBoundsException during the second parse. However, * this is not seen. */ void DateFormatRegressionTest::Test4104522(void) { UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *sdf = new SimpleDateFormat(status); if(U_FAILURE(status)) { dataerrln("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 DataDrivenCalendarTest::runIndexedTest(int32_t index, UBool exec, const char* &name, char* /*par */) { if (driver != NULL) { if (exec) { // logln("Begin "); } const DataMap *info= NULL; UErrorCode status= U_ZERO_ERROR; TestData *testData = driver->createTestData(index, status); if (U_SUCCESS(status)) { name = testData->getName(); if (testData->getInfo(info, status)) { log(info->getString("Description", status)); } if (exec) { log(name); logln("---"); logln(""); processTest(testData); } delete testData; } else { name = ""; } } else { dataerrln("format/DataDriven*Test data (calendar.res) not initialized!"); name = ""; } }
void RelativeDateTimeFormatterTest::TestCustomNumberFormat() { NumberFormat *nf; UErrorCode status = U_ZERO_ERROR; { RelativeDateTimeFormatter fmt("en", status); if (U_FAILURE(status)) { dataerrln( "Failure creating format object - %s", u_errorName(status)); return; } nf = (NumberFormat *) fmt.getNumberFormat().clone(); } nf->setMinimumFractionDigits(1); nf->setMaximumFractionDigits(1); RelativeDateTimeFormatter fmt("en", nf, status); // Test copy constructor. RelativeDateTimeFormatter fmt2(fmt); RunTest(fmt2, kEnglishDecimal, UPRV_LENGTHOF(kEnglishDecimal), "en decimal digits"); // Test assignment fmt = RelativeDateTimeFormatter("es", status); RunTest(fmt, kSpanishNoQuantity, UPRV_LENGTHOF(kSpanishNoQuantity), "assignment operator"); }
void NewResourceBundleTest::TestGetByFallback() { UErrorCode status = U_ZERO_ERROR; ResourceBundle heRes(NULL, "he", status); heRes.getWithFallback("calendar", status).getWithFallback("islamic-civil", status).getWithFallback("DateTime", status); if(U_SUCCESS(status)) { errln("he locale's Islamic-civil DateTime resource exists. How did it get here?\n"); } status = U_ZERO_ERROR; heRes.getWithFallback("calendar", status).getWithFallback("islamic-civil", status).getWithFallback("eras", status); if(U_FAILURE(status)) { dataerrln("Didn't get Islamic Eras. I know they are there! - %s", u_errorName(status)); } status = U_ZERO_ERROR; ResourceBundle rootRes(NULL, "root", status); rootRes.getWithFallback("calendar", status).getWithFallback("islamic-civil", status).getWithFallback("DateTime", status); if(U_SUCCESS(status)) { errln("Root's Islamic-civil's DateTime resource exists. How did it get here?\n"); } status = U_ZERO_ERROR; }
Calendar* CalendarTimeZoneTest::getCalendar() { Calendar *theCalendar = 0; if (fgCalendar != 0) // if there's something in the cache { Mutex lock; if (fgCalendar != 0) // Someone might have grabbed it. { theCalendar = fgCalendar; fgCalendar = 0; // We have exclusive right to this calendar. } } if(theCalendar == 0) // If we weren't able to pull it out of the cache, then we have to create it. { UErrorCode status = U_ZERO_ERROR; theCalendar = Calendar::createInstance(status); if (U_FAILURE(status)) { delete theCalendar; theCalendar = 0; dataerrln("FAIL: Calendar::createInstance failed: %s", u_errorName(status)); } } return theCalendar; }
/** * Test that the equals method works correctly. */ void IntlTestDateFormatAPI::TestEquals(void) { UErrorCode status = U_ZERO_ERROR; // Create two objects at different system times DateFormat *a = DateFormat::createInstance(); UDate start = Calendar::getNow(); while (Calendar::getNow() == start) ; // Wait for time to change DateFormat *b = DateFormat::createInstance(); if (a == NULL || b == NULL){ dataerrln("Error calling DateFormat::createInstance()"); delete a; delete b; return; } if (!(*a == *b)) errln("FAIL: DateFormat objects created at different times are unequal."); if (b->getDynamicClassID() == SimpleDateFormat::getStaticClassID()) { double ONE_YEAR = 365*24*60*60*1000.0; ((SimpleDateFormat*)b)->set2DigitYearStart(start + 50*ONE_YEAR, status); if (U_FAILURE(status)) errln("FAIL: setTwoDigitStartDate failed."); else if (*a == *b) errln("FAIL: DateFormat objects with different two digit start dates are equal."); } delete a; delete b; }
/** * @bug 4162071 * Cannot reproduce this bug under 1.2 FCS -- it may be a convoluted duplicate * of some other bug that has been fixed. */ 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)) { dataerrln("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 IntlTestDateFormat::testFormat(/* char* par */) { if (fFormat == 0) { dataerrln("FAIL: DateFormat creation failed"); return; } describeTest(); UDate now = Calendar::getNow(); tryDate(0); tryDate(1278161801778.0); tryDate(5264498352317.0); // Sunday, October 28, 2136 8:39:12 AM PST tryDate(9516987689250.0); // In the year 2271 tryDate(now); // Shift 6 months into the future, AT THE SAME TIME OF DAY. // This will test the DST handling. tryDate(now + 6.0*30*ONEDAY); UDate limit = now * 10; // Arbitrary limit for (int32_t i=0; i<3; ++i) tryDate(uprv_floor(randDouble() * limit)); delete fFormat; }
void DateFormatRegressionTest::Test714(void) { //try { UDate d(978103543000.); DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::NONE, DateFormat::MEDIUM, Locale::getUS()); if (fmt == NULL) { dataerrln("Error calling DateFormat::createDateTimeInstance"); return; } UnicodeString s; UnicodeString tests = (UnicodeString) "7:25:43 AM" ; UErrorCode status = U_ZERO_ERROR; fmt->format (d,s); if(U_FAILURE(status)) { errln((UnicodeString) "Fail, errmsg " + u_errorName(status)); return; } if(s != tests) { errln((UnicodeString) "Fail: " + s + " != " + tests); } else { logln("OK: " + s + " == " + tests); } delete fmt; }
void SSearchTest::goodSuffixTest() { UErrorCode status = U_ZERO_ERROR; UCollator *coll = NULL; UnicodeString pat = /*"gcagagag"*/ "fxeld"; UnicodeString target = /*"gcatcgcagagagtatacagtacg"*/ "cloveldfxeld"; int32_t start = -1, end = -1; UBool bFound; coll = ucol_open(NULL, &status); TEST_ASSERT_SUCCESS(status); LocalUStringSearchPointer ss(usearch_openFromCollator(pat.getBuffer(), pat.length(), target.getBuffer(), target.length(), coll, NULL, // the break iterator &status)); TEST_ASSERT_SUCCESS(status); bFound = usearch_search(ss.getAlias(), 0, &start, &end, &status); TEST_ASSERT_SUCCESS(status); if (bFound) { logln("Found pattern at [%d, %d].", start, end); } else { dataerrln("Did not find pattern."); } ucol_close(coll); }
void DateFormatRegressionTest::Test5554(void) { UErrorCode status = U_ZERO_ERROR; UnicodeString pattern("Z",""); UnicodeString newfoundland("Canada/Newfoundland", ""); TimeZone *zone = TimeZone::createTimeZone(newfoundland); Calendar *cal = new GregorianCalendar(zone, status); SimpleDateFormat *sdf = new SimpleDateFormat(pattern,status); if (U_FAILURE(status)) { dataerrln("Error constructing SimpleDateFormat"); delete cal; delete sdf; return; } cal->set(2007, 1, 14); UDate date = cal->getTime(status); if (U_FAILURE(status)) { errln("Error getting time to format"); return; }; sdf->adoptCalendar(cal); UnicodeString result; UnicodeString correct("-0330", ""); sdf->format(date, result); if (result != correct) { errln("\nError: Newfoundland Z of Jan 14, 2007 gave '" + result + "', expected '" + correct + "'"); } delete sdf; }