void DateFormatRoundTripTest::TestDateFormatRoundTrip() { UErrorCode status = U_ZERO_ERROR; getFieldCal = Calendar::createInstance(status); failure(status, "Calendar::createInstance"); if(!assertSuccess("trying to construct", status))return; int32_t locCount = 0; const Locale *avail = DateFormat::getAvailableLocales(locCount); logln("DateFormat available locales: %d", locCount); if(quick) { SPARSENESS = 18; logln("Quick mode: only testing SPARSENESS = 18"); } TimeZone *tz = TimeZone::createDefault(); UnicodeString temp; logln("Default TimeZone: " + tz->getID(temp)); delete tz; #ifdef TEST_ONE_LOC // define this to just test ONE locale. Locale loc(TEST_ONE_LOC); test(loc); #if INFINITE for(;;) { test(loc); } #endif #else # if INFINITE // Special infinite loop test mode for finding hard to reproduce errors Locale loc = Locale::getDefault(); logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName(temp)); for(;;) test(loc); # else test(Locale::getDefault()); #if 1 // installed locales for (int i=0; i < locCount; ++i) { test(avail[i]); } #endif #if 1 // special locales int32_t jCount = CalendarTest::testLocaleCount(); for (int32_t j=0; j < jCount; ++j) { test(Locale(CalendarTest::testLocaleID(j))); } #endif # endif #endif delete getFieldCal; }
// ------------------------------------- // Gets the objectLocale display name in the displayLocale language. UnicodeString& U_EXPORT2 BreakIterator::getDisplayName(const Locale& objectLocale, const Locale& displayLocale, UnicodeString& name) { return objectLocale.getDisplayName(displayLocale, name); }
UnicodeString& CollatorInfo::getDisplayName(const Locale& displayLocale, UnicodeString& name) const { if (displayNames) { UnicodeString* val = (UnicodeString*)displayNames->get(displayLocale.getName()); if (val) { name = *val; return name; } } return locale.getDisplayName(displayLocale, name); }
UnicodeString& U_EXPORT2 Collator::getDisplayName(const Locale& objectLocale, const Locale& displayLocale, UnicodeString& name) { #if !UCONFIG_NO_SERVICE if (hasService()) { UnicodeString locNameStr; LocaleUtility::initNameFromLocale(objectLocale, locNameStr); return gService->getDisplayName(locNameStr, name, displayLocale); } #endif return objectLocale.getDisplayName(displayLocale, name); }
UnicodeString& LocaleKeyFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const { if ((_coverage & 0x1) == 0) { //UErrorCode status = U_ZERO_ERROR; // assume if this is called on us, we support some fallback of this id // if (isSupportedID(id, status)) { Locale loc; LocaleUtility::initLocaleFromName(id, loc); return loc.getDisplayName(locale, result); // } } result.setToBogus(); return result; }
void StaticUnicodeSetsTest::testSetCoverage() { UErrorCode status = U_ZERO_ERROR; // Lenient comma/period should be supersets of strict comma/period; // it also makes the coverage logic cheaper. assertTrue( "COMMA should be superset of STRICT_COMMA", get(unisets::COMMA)->containsAll(*get(unisets::STRICT_COMMA))); assertTrue( "PERIOD should be superset of STRICT_PERIOD", get(unisets::PERIOD)->containsAll(*get(unisets::STRICT_PERIOD))); UnicodeSet decimals; decimals.addAll(*get(unisets::STRICT_COMMA)); decimals.addAll(*get(unisets::STRICT_PERIOD)); decimals.freeze(); UnicodeSet grouping; grouping.addAll(decimals); grouping.addAll(*get(unisets::OTHER_GROUPING_SEPARATORS)); decimals.freeze(); const UnicodeSet &plusSign = *get(unisets::PLUS_SIGN); const UnicodeSet &minusSign = *get(unisets::MINUS_SIGN); const UnicodeSet &percent = *get(unisets::PERCENT_SIGN); const UnicodeSet &permille = *get(unisets::PERMILLE_SIGN); const UnicodeSet &infinity = *get(unisets::INFINITY_KEY); int32_t localeCount; const Locale* allAvailableLocales = Locale::getAvailableLocales(localeCount); for (int32_t i = 0; i < localeCount; i++) { Locale locale = allAvailableLocales[i]; DecimalFormatSymbols dfs(locale, status); UnicodeString localeName; locale.getDisplayName(localeName); assertSuccess(UnicodeString("Making DFS for ") + localeName, status); #define ASSERT_IN_SET(name, foo) assertInSet(localeName, UnicodeString("" #name ""), name, foo) ASSERT_IN_SET(decimals, dfs.getConstSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol)); ASSERT_IN_SET(grouping, dfs.getConstSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol)); ASSERT_IN_SET(plusSign, dfs.getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol)); ASSERT_IN_SET(minusSign, dfs.getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol)); ASSERT_IN_SET(percent, dfs.getConstSymbol(DecimalFormatSymbols::kPercentSymbol)); ASSERT_IN_SET(permille, dfs.getConstSymbol(DecimalFormatSymbols::kPerMillSymbol)); ASSERT_IN_SET(infinity, dfs.getConstSymbol(DecimalFormatSymbols::kInfinitySymbol)); } }
UnicodeString& getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const { if (U_SUCCESS(_status) && _ids.contains((void*)&id)) { char buffer[128]; UErrorCode status = U_ZERO_ERROR; int32_t len = id.extract(buffer, sizeof(buffer), NULL, status); if (U_SUCCESS(status)) { if (len == sizeof(buffer)) { --len; } buffer[len] = 0; Locale loc = Locale::createFromName(buffer); loc.getDisplayName(locale, result); return result; } } result.setToBogus(); // shouldn't happen return result; }
void DateFormatRoundTripTest::test(const Locale& loc) { UnicodeString temp; #if !INFINITE logln("Locale: " + loc.getDisplayName(temp)); #endif // Total possibilities = 24 // 4 date // 4 time // 16 date-time UBool TEST_TABLE [24];//= new boolean[24]; int32_t i = 0; for(i = 0; i < 24; ++i) TEST_TABLE[i] = TRUE; // If we have some sparseness, implement it here. Sparseness decreases // test time by eliminating some tests, up to 23. for(i = 0; i < SPARSENESS; ) { int random = (int)(randFraction() * 24); if (random >= 0 && random < 24 && TEST_TABLE[i]) { TEST_TABLE[i] = FALSE; ++i; } } int32_t itable = 0; int32_t style = 0; for(style = DateFormat::FULL; style <= DateFormat::SHORT; ++style) { if(TEST_TABLE[itable++]) { logln("Testing style " + UnicodeString(styleName((DateFormat::EStyle)style))); DateFormat *df = DateFormat::createDateInstance((DateFormat::EStyle)style, loc); if(df == NULL) { errln(UnicodeString("Could not DF::createDateInstance ") + UnicodeString(styleName((DateFormat::EStyle)style)) + " Locale: " + loc.getDisplayName(temp)); } else { test(df, loc); delete df; } } } for(style = DateFormat::FULL; style <= DateFormat::SHORT; ++style) { if (TEST_TABLE[itable++]) { logln("Testing style " + UnicodeString(styleName((DateFormat::EStyle)style))); DateFormat *df = DateFormat::createTimeInstance((DateFormat::EStyle)style, loc); if(df == NULL) { errln(UnicodeString("Could not DF::createTimeInstance ") + UnicodeString(styleName((DateFormat::EStyle)style)) + " Locale: " + loc.getDisplayName(temp)); } else { test(df, loc, TRUE); delete df; } } } for(int32_t dstyle = DateFormat::FULL; dstyle <= DateFormat::SHORT; ++dstyle) { for(int32_t tstyle = DateFormat::FULL; tstyle <= DateFormat::SHORT; ++tstyle) { if(TEST_TABLE[itable++]) { logln("Testing dstyle" + UnicodeString(styleName((DateFormat::EStyle)dstyle)) + ", tstyle" + UnicodeString(styleName((DateFormat::EStyle)tstyle)) ); DateFormat *df = DateFormat::createDateTimeInstance((DateFormat::EStyle)dstyle, (DateFormat::EStyle)tstyle, loc); if(df == NULL) { dataerrln(UnicodeString("Could not DF::createDateTimeInstance ") + UnicodeString(styleName((DateFormat::EStyle)dstyle)) + ", tstyle" + UnicodeString(styleName((DateFormat::EStyle)tstyle)) + "Locale: " + loc.getDisplayName(temp)); } else { test(df, loc); delete df; } } } } }