ICU-3748 add canonicalization test
X-SVN-Rev: 15377
This commit is contained in:
parent
cc9a806769
commit
cba9347376
@ -1,6 +1,6 @@
|
|||||||
/********************************************************************
|
/********************************************************************
|
||||||
* COPYRIGHT:
|
* COPYRIGHT:
|
||||||
* Copyright (c) 1997-2003, International Business Machines Corporation and
|
* Copyright (c) 1997-2004, International Business Machines Corporation and
|
||||||
* others. All Rights Reserved.
|
* others. All Rights Reserved.
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
@ -227,6 +227,7 @@ void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, c
|
|||||||
TESTCASE(26, TestGetBaseName);
|
TESTCASE(26, TestGetBaseName);
|
||||||
TESTCASE(27, TestGetLocale);
|
TESTCASE(27, TestGetLocale);
|
||||||
TESTCASE(28, TestVariantWithOutCountry);
|
TESTCASE(28, TestVariantWithOutCountry);
|
||||||
|
TESTCASE(29, TestCanonicalization);
|
||||||
|
|
||||||
// keep the last index in sync with the condition in default:
|
// keep the last index in sync with the condition in default:
|
||||||
|
|
||||||
@ -1977,3 +1978,122 @@ void LocaleTest::TestVariantWithOutCountry(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Locale _canonicalize(int32_t selector, /* 0==createFromName, 1==createCanonical, 2==Locale ct */
|
||||||
|
const char* localeID) {
|
||||||
|
switch (selector) {
|
||||||
|
case 0:
|
||||||
|
return Locale::createFromName(localeID);
|
||||||
|
case 1:
|
||||||
|
return Locale::createCanonical(localeID);
|
||||||
|
case 2:
|
||||||
|
return Locale(localeID);
|
||||||
|
default:
|
||||||
|
U_ASSERT(FALSE);
|
||||||
|
return Locale("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocaleTest::TestCanonicalization(void)
|
||||||
|
{
|
||||||
|
static struct {
|
||||||
|
const char *localeID; /* input */
|
||||||
|
const char *getNameID; /* expected getName() result */
|
||||||
|
const char *canonicalID; /* expected canonicalize() result */
|
||||||
|
} testCases[] = {
|
||||||
|
/* { "ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage",
|
||||||
|
"ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE"}, */
|
||||||
|
{ "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" },
|
||||||
|
{ "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" },
|
||||||
|
{ "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" },
|
||||||
|
{ "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=EUR" },
|
||||||
|
{ "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" },
|
||||||
|
{ "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" },
|
||||||
|
{ "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" },
|
||||||
|
{ "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" },
|
||||||
|
{ "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" },
|
||||||
|
{ "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" },
|
||||||
|
{ "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" },
|
||||||
|
{ "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" },
|
||||||
|
{ "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" },
|
||||||
|
{ "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" },
|
||||||
|
{ "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" },
|
||||||
|
{ "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" },
|
||||||
|
{ "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" },
|
||||||
|
{ "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" },
|
||||||
|
{ "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" },
|
||||||
|
{ "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" },
|
||||||
|
{ "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" },
|
||||||
|
{ "en_GB@EURO", "en_GB@EURO", "en_GB@currency=EUR" }, /* POSIX ID */
|
||||||
|
{ "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" },
|
||||||
|
{ "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" },
|
||||||
|
{ "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" },
|
||||||
|
{ "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" },
|
||||||
|
{ "zh_TW_STROKE", "zh_TW_STROKE", "zh_TW@collation=stroke" },
|
||||||
|
{ "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" },
|
||||||
|
{ "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" },
|
||||||
|
{ "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" },
|
||||||
|
{ "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" },
|
||||||
|
{ "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" },
|
||||||
|
{ "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" },
|
||||||
|
{ "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ },
|
||||||
|
{ "no@ny", "no@ny", "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */
|
||||||
|
{ "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */
|
||||||
|
{ "qz-qz@Euro", "qz_QZ@Euro", "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */
|
||||||
|
// NOTE: uloc_getName() works on en-BOONT, but Locale() parser considers it BOGUS
|
||||||
|
// TODO: unify this behavior
|
||||||
|
{ "en-BOONT", "BOGUS", "en__BOONT" }, /* registered name */
|
||||||
|
{ "de-1901", "de_1901", "de__1901" }, /* registered name */
|
||||||
|
{ "de-1906", "de_1906", "de__1906" }, /* registered name */
|
||||||
|
{ "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_SP" }, /* .NET name */
|
||||||
|
{ "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_SP" }, /* .NET name */
|
||||||
|
{ "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */
|
||||||
|
{ "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */
|
||||||
|
{ "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */
|
||||||
|
{ "zh-CHT", "zh_CHT", "zh_TW" }, /* .NET name This may change back to zh_Hant */
|
||||||
|
|
||||||
|
/* posix behavior that used to be performed by getName */
|
||||||
|
{ "mr.utf8", "mr.utf8", "mr" },
|
||||||
|
{ "de-tv.koi8r", "de_TV.koi8r", "de_TV" },
|
||||||
|
{ "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML" },
|
||||||
|
{ "i-cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US" },
|
||||||
|
{ "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA" },
|
||||||
|
{ "no-no-ny.utf8@B", "no_NO_NY.utf8@B", "no_NO_NY_B" /* not: "nn_NO" [alan ICU3.0] */ }, /* @ ignored unless variant is empty */
|
||||||
|
|
||||||
|
/* fleshing out canonicalization */
|
||||||
|
/* trim space and sort keywords, ';' is separator so not present at end in canonical form */
|
||||||
|
{ "en_Hant_IL_VALLEY_GIRL@ currency = EUR; calendar = Japanese ;", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR" },
|
||||||
|
/* already-canonical ids are not changed */
|
||||||
|
{ "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR" },
|
||||||
|
/* PRE_EURO and EURO conversions don't affect other keywords */
|
||||||
|
{ "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" },
|
||||||
|
{ "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" },
|
||||||
|
/* currency keyword overrides PRE_EURO and EURO currency */
|
||||||
|
{ "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" },
|
||||||
|
{ "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" },
|
||||||
|
/* norwegian is just too weird, if we handle things in their full generality */
|
||||||
|
{ "no-Hant-GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$" /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ },
|
||||||
|
|
||||||
|
/* test cases reflecting internal resource bundle usage */
|
||||||
|
{ "root@kw=foo", "root@kw=foo", "root@kw=foo" },
|
||||||
|
{ "@calendar=gregorian", "@calendar=gregorian", "en_US_POSIX@calendar=gregorian" }
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* label[] = { "createFromName", "crateCanonical", "Locale" };
|
||||||
|
|
||||||
|
int32_t i, j;
|
||||||
|
|
||||||
|
for (i=0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
|
||||||
|
for (j=0; j<3; ++j) {
|
||||||
|
const char* expected = (j==1) ? testCases[i].canonicalID : testCases[i].getNameID;
|
||||||
|
Locale loc = _canonicalize(j, testCases[i].localeID);
|
||||||
|
const char* getName = loc.isBogus() ? "BOGUS" : loc.getName();
|
||||||
|
if(uprv_strcmp(expected, getName) != 0) {
|
||||||
|
errln("FAIL: %s(%s).getName() => \"%s\", expected \"%s\"",
|
||||||
|
label[j], testCases[i].localeID, getName, expected);
|
||||||
|
} else {
|
||||||
|
logln("Ok: %s(%s) => \"%s\"",
|
||||||
|
label[j], testCases[i].localeID, getName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/********************************************************************
|
/********************************************************************
|
||||||
* COPYRIGHT:
|
* COPYRIGHT:
|
||||||
* Copyright (c) 1997-2003, International Business Machines Corporation and
|
* Copyright (c) 1997-2004, International Business Machines Corporation and
|
||||||
* others. All Rights Reserved.
|
* others. All Rights Reserved.
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
@ -89,6 +89,8 @@ public:
|
|||||||
|
|
||||||
void TestVariantWithOutCountry(void);
|
void TestVariantWithOutCountry(void);
|
||||||
|
|
||||||
|
void TestCanonicalization(void);
|
||||||
|
|
||||||
#if !UCONFIG_NO_FORMATTING
|
#if !UCONFIG_NO_FORMATTING
|
||||||
static UDate date(int32_t y, int32_t m, int32_t d, int32_t hr = 0, int32_t min = 0, int32_t sec = 0);
|
static UDate date(int32_t y, int32_t m, int32_t d, int32_t hr = 0, int32_t min = 0, int32_t sec = 0);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user