ICU-860 tests for i-, x-, @, . locales and Locale::createFromName
X-SVN-Rev: 3668
This commit is contained in:
parent
8e5d16290f
commit
900403dd5f
@ -124,6 +124,7 @@ enum {
|
||||
void addLocaleTest(TestNode** root)
|
||||
{
|
||||
addTest(root, &TestBasicGetters, "tsutil/cloctst/TestBasicGetters");
|
||||
addTest(root, &TestPrefixes, "tsutil/cloctst/TestPrefixes");
|
||||
addTest(root, &TestSimpleResourceInfo, "tsutil/cloctst/TestSimpleResourceInfo");
|
||||
addTest(root, &TestDisplayNames, "tsutil/cloctst/TestDisplayNames");
|
||||
addTest(root, &TestGetAvailableLocales, "tsutil/cloctst/TestGetAvailableLocales");
|
||||
@ -195,6 +196,8 @@ static void TestBasicGetters() {
|
||||
status=U_ZERO_ERROR;
|
||||
name=(char*)malloc(sizeof(char) * (cap+1));
|
||||
uloc_getName(testLocale, name, cap, &status);
|
||||
} else if(status==U_ZERO_ERROR) {
|
||||
log_err("ERROR: in uloc_getName(%s,NULL,0,..), expected U_BUFFER_OVERFLOW_ERROR!\n", testLocale);
|
||||
}
|
||||
if(U_FAILURE(status)){
|
||||
log_err("ERROR: in uloc_getName %s\n", myErrorName(status));
|
||||
@ -211,6 +214,112 @@ static void TestBasicGetters() {
|
||||
}
|
||||
}
|
||||
|
||||
/* Test the i- and x- and @ and . functionality
|
||||
*/
|
||||
|
||||
#define PREFIXBUFSIZ 128
|
||||
|
||||
static void TestPrefixes() {
|
||||
int row = 0;
|
||||
int n;
|
||||
const char *loc;
|
||||
|
||||
const char *testData[][5] =
|
||||
{
|
||||
{"sv", "FI", "AL", "sv-fi-al", "sv_FI_AL" },
|
||||
{"en", "GB", "", "en-gb", "en_GB" },
|
||||
{"i-hakka", "MT", "XEMXIJA", "i-hakka_MT_XEMXIJA", "i-hakka_MT_XEMXIJA"},
|
||||
{"i-hakka", "CN", "", "i-hakka_CN", "i-hakka_CN"},
|
||||
{"i-hakka", "MX", "", "I-hakka_MX", "i-hakka_MX"},
|
||||
{"x-klingon", "US", "SANJOSE", "X-KLINGON_us_SANJOSE", "x-klingon_US_SANJOSE"},
|
||||
|
||||
{"mr", "", "", "mr.utf8", "mr"},
|
||||
{"de", "TV", "", "de-tv.koi8r", "de_TV"},
|
||||
{"x-piglatin", "ML", "", "x-piglatin_ML.MBE", "x-piglatin_ML"}, /* Multibyte English */
|
||||
{"i-cherokee","US", "", "i-Cherokee_US.utf7", "i-cherokee_US"},
|
||||
{"x-filfli", "MT", "FILFLA", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA"},
|
||||
{"no", "NO", "NY", "no-no-ny.utf32@B", "no_NO_NY"}, /* @ ignored unless variant is empty */
|
||||
{"no", "NO", "B", "no-no.utf32@B", "no_NO_B" },
|
||||
{"no", "", "NY", "no__ny", "no__NY" },
|
||||
{"no", "", "NY", "no@ny", "no__NY" },
|
||||
|
||||
{ "","","","",""}
|
||||
};
|
||||
|
||||
const char *testTitles[] = { "uloc_getLanguage()", "uloc_getCountry()", "uloc_getVariant()", "name", "uloc_getName()", "country3", "lcid" };
|
||||
|
||||
char buf[PREFIXBUFSIZ];
|
||||
int len;
|
||||
UErrorCode err;
|
||||
|
||||
|
||||
for(row=0;testData[row][0][0] != 0;row++) {
|
||||
loc = testData[row][NAME];
|
||||
log_verbose("Test #%d: %s\n", row, loc);
|
||||
|
||||
err = U_ZERO_ERROR;
|
||||
len=0;
|
||||
buf[0]=0;
|
||||
for(n=0;n<=(NAME+1);n++) {
|
||||
if(n==NAME) continue;
|
||||
|
||||
for(len=0;len<PREFIXBUFSIZ;len++) {
|
||||
buf[len] = '%'; /* Set a tripwire.. */
|
||||
}
|
||||
len = 0;
|
||||
|
||||
switch(n) {
|
||||
case LANG:
|
||||
len = uloc_getLanguage(loc, buf, 526, &err);
|
||||
break;
|
||||
|
||||
case CTRY:
|
||||
len = uloc_getCountry(loc, buf, 526, &err);
|
||||
break;
|
||||
|
||||
case VAR:
|
||||
len = uloc_getVariant(loc, buf, 526, &err);
|
||||
break;
|
||||
|
||||
case NAME+1:
|
||||
len = uloc_getName(loc, buf, 526, &err);
|
||||
break;
|
||||
|
||||
default:
|
||||
strcpy(buf, "**??");
|
||||
len=4;
|
||||
}
|
||||
|
||||
if(U_FAILURE(err)) {
|
||||
log_err("#%d: %s on %s: err %s\n",
|
||||
row, testTitles[n], loc, u_errorName(err));
|
||||
} else {
|
||||
log_verbose("#%d: %s on %s: -> [%s] (length %d)\n",
|
||||
row, testTitles[n], loc, buf, len);
|
||||
|
||||
if(len != strlen(buf)+1) {
|
||||
log_err("#%d: %s on %s: -> [%s] (length returned %d, actual %d!)\n",
|
||||
row, testTitles[n], loc, buf, len, strlen(buf)+1);
|
||||
|
||||
}
|
||||
|
||||
/* see if they smashed somehting */
|
||||
if(buf[len+1] != '%') {
|
||||
log_err("#%d: %s on %s: -> [%s] - wrote [%X] out ofbounds!\n",
|
||||
row, testTitles[n], loc, buf, buf[len+1]);
|
||||
}
|
||||
|
||||
if(strcmp(buf, testData[row][n])) {
|
||||
log_err("#%d: %s on %s: -> [%s] (expected '%s'!)\n",
|
||||
row, testTitles[n], loc, buf, testData[row][n]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* testing uloc_getISO3Language(), uloc_getISO3Country(), */
|
||||
static void TestSimpleResourceInfo() {
|
||||
int32_t i;
|
||||
|
@ -22,6 +22,7 @@
|
||||
* Test functions to set and get data fields
|
||||
**/
|
||||
static void TestBasicGetters(void);
|
||||
static void TestPrefixes(void);
|
||||
/**
|
||||
* Use Locale to access Resource file data and compare against expected values
|
||||
**/
|
||||
|
@ -391,8 +391,9 @@ void LocaleTest::TestSimpleObjectStuff() {
|
||||
Locale test3(test1);
|
||||
Locale test4("zz", "ZZ");
|
||||
Locale test5("aa", "AA", "");
|
||||
Locale test6("aa", "AA", "Antares");
|
||||
Locale test7("aa", "AA", "Jupiter");
|
||||
Locale test6("aa", "AA", "ANTARES");
|
||||
Locale test7("aa", "AA", "JUPITER");
|
||||
Locale test8 = Locale::createFromName("aa-aa.utf8@jupiter");
|
||||
|
||||
// now list them all for debugging usage.
|
||||
test_dumpLocale(test1);
|
||||
@ -401,7 +402,8 @@ void LocaleTest::TestSimpleObjectStuff() {
|
||||
test_dumpLocale(test4);
|
||||
test_dumpLocale(test5);
|
||||
test_dumpLocale(test6);
|
||||
test_dumpLocale(test7)
|
||||
test_dumpLocale(test7);
|
||||
test_dumpLocale(test8);
|
||||
|
||||
// Make sure things compare to themselves!
|
||||
test_assert(test1 == test1);
|
||||
@ -411,6 +413,7 @@ void LocaleTest::TestSimpleObjectStuff() {
|
||||
test_assert(test5 == test5);
|
||||
test_assert(test6 == test6);
|
||||
test_assert(test7 == test7);
|
||||
test_assert(test8 == test8);
|
||||
|
||||
// make sure things are not equal to themselves.
|
||||
test_assert(!(test1 != test1));
|
||||
@ -420,6 +423,7 @@ void LocaleTest::TestSimpleObjectStuff() {
|
||||
test_assert(!(test5 != test5));
|
||||
test_assert(!(test6 != test6));
|
||||
test_assert(!(test7 != test7));
|
||||
test_assert(!(test8 != test8));
|
||||
|
||||
// make sure things that are equal to each other don't show up as unequal.
|
||||
test_assert(!(test1 != test2));
|
||||
@ -437,6 +441,8 @@ void LocaleTest::TestSimpleObjectStuff() {
|
||||
test_assert(!(test2 == test4));
|
||||
test_assert(!(test3 == test4));
|
||||
|
||||
test_assert(test7 == test8);
|
||||
|
||||
// test for hash codes to be the same.
|
||||
int32_t hash1 = test1.hashCode();
|
||||
int32_t hash2 = test2.hashCode();
|
||||
|
Loading…
Reference in New Issue
Block a user