From 9dc37beb84ebdce3c3bf36a1c65c3e212dc06dd6 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Thu, 8 May 2003 23:17:49 +0000 Subject: [PATCH] ICU-2039 Add a special hard to find test case when decimal format symbols are requested from a locale that causes the ures_* API to fail. X-SVN-Rev: 11848 --- icu4c/source/test/intltest/numfmtst.cpp | 33 +++++++++++++++++++++++++ icu4c/source/test/intltest/numfmtst.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 8570ce9505f..975f98eb599 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -18,6 +18,7 @@ #include "unicode/ucurr.h" #include "unicode/ustring.h" #include +#include #include "digitlst.h" static const UChar EUR[] = {69,85,82,0}; // "EUR" @@ -59,6 +60,8 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n CASE(18,TestComplexCurrency); CASE(19,TestRegCurrency); + + CASE(20,TestSymbolsWithBadLocale); default: name = ""; break; } } @@ -1209,6 +1212,36 @@ void NumberFormatTest::TestRegCurrency(void) { status = U_ZERO_ERROR; // reset } +void NumberFormatTest::TestSymbolsWithBadLocale(void) { + Locale locDefault; + Locale locBad("x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME"); + UErrorCode status = U_ZERO_ERROR; + UnicodeString intlCurrencySymbol((UChar)0xa4); + + intlCurrencySymbol.append((UChar)0xa4); + + logln("Current locale is %s", Locale::getDefault().getName()); + Locale::setDefault(locBad, status); + logln("Current locale is %s", Locale::getDefault().getName()); + DecimalFormatSymbols mySymbols(status); + if (status != U_USING_FALLBACK_WARNING) { + errln("DecimalFormatSymbols should returned U_USING_FALLBACK_WARNING."); + } + if (strcmp(mySymbols.getLocale().getName(), locBad.getName()) != 0) { + errln("DecimalFormatSymbols does not have the right locale."); + } + DecimalFormatSymbols::ENumberFormatSymbol symbolEnum; + int *symbolEnumPtr = (int*)(&symbolEnum); + for (symbolEnum = DecimalFormatSymbols::kDecimalSeparatorSymbol; symbolEnum < DecimalFormatSymbols::kFormatSymbolCount; (*symbolEnumPtr)++) { + if (mySymbols.getSymbol(symbolEnum).length() == 0 && symbolEnum != DecimalFormatSymbols::kGroupingSeparatorSymbol) { + errln("DecimalFormatSymbols has an empty string at index %d.", symbolEnum); + } + } + status = U_ZERO_ERROR; + Locale::setDefault(locDefault, status); + logln("Current locale is %s", Locale::getDefault().getName()); +} + //---------------------------------------------------------------------- // Support methods //---------------------------------------------------------------------- diff --git a/icu4c/source/test/intltest/numfmtst.h b/icu4c/source/test/intltest/numfmtst.h index 467661fe299..cf9d3be2f8e 100644 --- a/icu4c/source/test/intltest/numfmtst.h +++ b/icu4c/source/test/intltest/numfmtst.h @@ -94,6 +94,8 @@ class NumberFormatTest: public CalendarTimeZoneTest { */ void TestRegCurrency(void); + void TestSymbolsWithBadLocale(void); + private: static UBool equalValue(const Formattable& a, const Formattable& b);