mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-4084 Sync the C and C++ API, and move internal function to internal headers.
X-SVN-Rev: 16232
This commit is contained in:
parent
15ea893568
commit
32a46bedba
3 changed files with 148 additions and 150 deletions
|
@ -102,8 +102,6 @@ void addResourceBundleTest(TestNode** root)
|
|||
addTest(root, &TestFileStream, "tsutil/crestst/TestFileStream");
|
||||
addTest(root, &TestGetSize, "tsutil/crestst/TestGetSize");
|
||||
addTest(root, &TestGetLocaleByType, "tsutil/crestst/TestGetLocaleByType");
|
||||
addTest(root, &TestGetKeywordValues, "tsutil/crestst/TestGetKeywordValues");
|
||||
addTest(root, &TestGetFunctionalEquivalent, "tsutil/crestst/TestGetFunctionalEquivalent");
|
||||
}
|
||||
|
||||
|
||||
|
@ -933,147 +931,3 @@ static void TestGetLocaleByType(void) {
|
|||
ures_close(res);
|
||||
}
|
||||
|
||||
static void TestGetKeywordValues(void) {
|
||||
UEnumeration *kwVals;
|
||||
UBool foundStandard = FALSE;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const char *kw;
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
kwVals = ures_getKeywordValues( U_ICUDATA_COLL, "collations", &status);
|
||||
|
||||
log_verbose("Testing getting collation keyword values:\n");
|
||||
|
||||
while((kw=uenum_next(kwVals, NULL, &status))) {
|
||||
log_verbose(" %s\n", kw);
|
||||
if(!strcmp(kw,"standard")) {
|
||||
if(foundStandard == FALSE) {
|
||||
foundStandard = TRUE;
|
||||
} else {
|
||||
log_err("'standard' was found twice in the keyword list.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(foundStandard == FALSE) {
|
||||
log_err("'standard' was not found in the keyword list.\n");
|
||||
}
|
||||
uenum_close(kwVals);
|
||||
if(U_FAILURE(status)) {
|
||||
log_err("err %s getting collation values\n", u_errorName(status));
|
||||
}
|
||||
status = U_ZERO_ERROR;
|
||||
#endif
|
||||
foundStandard = FALSE;
|
||||
kwVals = ures_getKeywordValues( "ICUDATA", "calendar", &status);
|
||||
|
||||
log_verbose("Testing getting calendar keyword values:\n");
|
||||
|
||||
while((kw=uenum_next(kwVals, NULL, &status))) {
|
||||
log_verbose(" %s\n", kw);
|
||||
if(!strcmp(kw,"japanese")) {
|
||||
if(foundStandard == FALSE) {
|
||||
foundStandard = TRUE;
|
||||
} else {
|
||||
log_err("'japanese' was found twice in the calendar keyword list.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(foundStandard == FALSE) {
|
||||
log_err("'japanese' was not found in the calendar keyword list.\n");
|
||||
}
|
||||
uenum_close(kwVals);
|
||||
if(U_FAILURE(status)) {
|
||||
log_err("err %s getting calendar values\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
|
||||
static void TestGetFunctionalEquivalentOf(const char *path, const char *resName, const char *keyword, UBool truncate, const char *testCases[]) {
|
||||
int32_t i;
|
||||
for(i=0;testCases[i];i+=3) {
|
||||
UBool expectAvail = (testCases[i][0]=='t')?TRUE:FALSE;
|
||||
UBool gotAvail = FALSE;
|
||||
const char *inLocale = testCases[i+1];
|
||||
const char *expectLocale = testCases[i+2];
|
||||
char equivLocale[256];
|
||||
int32_t len;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
log_verbose("%d: %c %s\texpect %s\n",i/3, expectAvail?'t':'f', inLocale, expectLocale);
|
||||
len = ures_getFunctionalEquivalent(equivLocale, 255, path,
|
||||
resName, keyword, inLocale,
|
||||
&gotAvail, truncate, &status);
|
||||
if(U_FAILURE(status) || (len <= 0)) {
|
||||
log_err("FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n",
|
||||
len, u_errorName(status),
|
||||
i/3,expectAvail?'t':'f', inLocale, expectLocale);
|
||||
} else {
|
||||
log_verbose("got: %c %s\n", expectAvail?'t':'f',equivLocale);
|
||||
|
||||
if((gotAvail != expectAvail) || strcmp(equivLocale, expectLocale)) {
|
||||
log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n",
|
||||
gotAvail?'t':'f', equivLocale,
|
||||
i/3,
|
||||
expectAvail?'t':'f', inLocale, expectLocale);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestGetFunctionalEquivalent(void) {
|
||||
static const char *collCases[] = {
|
||||
/* avail locale equiv */
|
||||
"f", "de_US_CALIFORNIA", "de",
|
||||
"t", "zh_TW@collation=stroke", "zh@collation=stroke",
|
||||
"f", "de_CN@collation=pinyin", "de",
|
||||
"f", "de_CN@calendar=japanese", "de",
|
||||
"t", "de@calendar=japanese", "de",
|
||||
"t", "zh_TW@collation=standard", "zh@collation=standard",
|
||||
"t", "zh_TW@collation=traditional", "zh@collation=traditional",
|
||||
"f", "zh_CN@collation=standard", "zh",
|
||||
"f", "zh_CN@collation=traditional", "zh@collation=traditional",
|
||||
"t", "zh@collation=standard", "zh",
|
||||
"t", "zh@collation=traditional", "zh@collation=traditional",
|
||||
"f", "hi_IN@collation=direct", "hi@collation=direct",
|
||||
"t", "hi@collation=standard", "hi",
|
||||
"t", "hi@collation=direct", "hi@collation=direct",
|
||||
"f", "hi_AU@collation=direct;currency=CHF;calendar=buddhist", "hi@collation=direct",
|
||||
"f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *calCases[] = {
|
||||
/* avail locale equiv */
|
||||
"t", "en_US", "en@calendar=gregorian",
|
||||
"f", "ja_JP_TOKYO", "ja@calendar=gregorian",
|
||||
"f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese",
|
||||
"t", "sr@calendar=gregorian", "sr@calendar=gregorian",
|
||||
"t", "en", "en@calendar=gregorian",
|
||||
NULL
|
||||
};
|
||||
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
TestGetFunctionalEquivalentOf(U_ICUDATA_COLL, "collations", "collation", TRUE, collCases);
|
||||
#endif
|
||||
TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE, calCases);
|
||||
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
log_verbose("Testing error conditions:\n");
|
||||
{
|
||||
char equivLocale[256] = "???";
|
||||
int32_t len;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBool gotAvail = FALSE;
|
||||
|
||||
len = ures_getFunctionalEquivalent(equivLocale, 255, U_ICUDATA_COLL,
|
||||
"calendar", "calendar", "ar_EG@calendar=islamic",
|
||||
&gotAvail, FALSE, &status);
|
||||
|
||||
if(status == U_MISSING_RESOURCE_ERROR) {
|
||||
log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n");
|
||||
} else {
|
||||
log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n",
|
||||
equivLocale, gotAvail?'t':'f', u_errorName(status));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -39,10 +39,6 @@
|
|||
|
||||
static void TestGetLocaleByType(void);
|
||||
|
||||
static void TestGetFunctionalEquivalent(void);
|
||||
|
||||
static void TestGetKeywordValues(void);
|
||||
|
||||
/**
|
||||
* extensive subtests called by TestResourceBundles
|
||||
**/
|
||||
|
|
|
@ -159,6 +159,8 @@ static int32_t bundles_count = sizeof(param) / sizeof(param[0]);
|
|||
|
||||
static void printUChars(UChar*);
|
||||
static void TestDecodedBundle(void);
|
||||
static void TestGetKeywordValues(void);
|
||||
static void TestGetFunctionalEquivalent(void);
|
||||
|
||||
/***************************************************************************************/
|
||||
|
||||
|
@ -182,6 +184,8 @@ void addNEWResourceBundleTest(TestNode** root)
|
|||
addTest(root, &TestDecodedBundle, "tsutil/creststn/TestDecodedBundle");
|
||||
addTest(root, &TestResourceLevelAliasing, "tsutil/creststn/TestResourceLevelAliasing");
|
||||
addTest(root, &TestDirectAccess, "tsutil/creststn/TestDirectAccess");
|
||||
addTest(root, &TestGetKeywordValues, "tsutil/creststn/TestGetKeywordValues");
|
||||
addTest(root, &TestGetFunctionalEquivalent, "tsutil/creststn/TestGetFunctionalEquivalent");
|
||||
|
||||
}
|
||||
|
||||
|
@ -2275,3 +2279,147 @@ static void TestDirectAccess(void) {
|
|||
ures_close(t2);
|
||||
}
|
||||
|
||||
static void TestGetKeywordValues(void) {
|
||||
UEnumeration *kwVals;
|
||||
UBool foundStandard = FALSE;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const char *kw;
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
kwVals = ures_getKeywordValues( U_ICUDATA_COLL, "collations", &status);
|
||||
|
||||
log_verbose("Testing getting collation keyword values:\n");
|
||||
|
||||
while((kw=uenum_next(kwVals, NULL, &status))) {
|
||||
log_verbose(" %s\n", kw);
|
||||
if(!strcmp(kw,"standard")) {
|
||||
if(foundStandard == FALSE) {
|
||||
foundStandard = TRUE;
|
||||
} else {
|
||||
log_err("'standard' was found twice in the keyword list.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(foundStandard == FALSE) {
|
||||
log_err("'standard' was not found in the keyword list.\n");
|
||||
}
|
||||
uenum_close(kwVals);
|
||||
if(U_FAILURE(status)) {
|
||||
log_err("err %s getting collation values\n", u_errorName(status));
|
||||
}
|
||||
status = U_ZERO_ERROR;
|
||||
#endif
|
||||
foundStandard = FALSE;
|
||||
kwVals = ures_getKeywordValues( "ICUDATA", "calendar", &status);
|
||||
|
||||
log_verbose("Testing getting calendar keyword values:\n");
|
||||
|
||||
while((kw=uenum_next(kwVals, NULL, &status))) {
|
||||
log_verbose(" %s\n", kw);
|
||||
if(!strcmp(kw,"japanese")) {
|
||||
if(foundStandard == FALSE) {
|
||||
foundStandard = TRUE;
|
||||
} else {
|
||||
log_err("'japanese' was found twice in the calendar keyword list.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(foundStandard == FALSE) {
|
||||
log_err("'japanese' was not found in the calendar keyword list.\n");
|
||||
}
|
||||
uenum_close(kwVals);
|
||||
if(U_FAILURE(status)) {
|
||||
log_err("err %s getting calendar values\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
|
||||
static void TestGetFunctionalEquivalentOf(const char *path, const char *resName, const char *keyword, UBool truncate, const char *testCases[]) {
|
||||
int32_t i;
|
||||
for(i=0;testCases[i];i+=3) {
|
||||
UBool expectAvail = (testCases[i][0]=='t')?TRUE:FALSE;
|
||||
UBool gotAvail = FALSE;
|
||||
const char *inLocale = testCases[i+1];
|
||||
const char *expectLocale = testCases[i+2];
|
||||
char equivLocale[256];
|
||||
int32_t len;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
log_verbose("%d: %c %s\texpect %s\n",i/3, expectAvail?'t':'f', inLocale, expectLocale);
|
||||
len = ures_getFunctionalEquivalent(equivLocale, 255, path,
|
||||
resName, keyword, inLocale,
|
||||
&gotAvail, truncate, &status);
|
||||
if(U_FAILURE(status) || (len <= 0)) {
|
||||
log_err("FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n",
|
||||
len, u_errorName(status),
|
||||
i/3,expectAvail?'t':'f', inLocale, expectLocale);
|
||||
} else {
|
||||
log_verbose("got: %c %s\n", expectAvail?'t':'f',equivLocale);
|
||||
|
||||
if((gotAvail != expectAvail) || strcmp(equivLocale, expectLocale)) {
|
||||
log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n",
|
||||
gotAvail?'t':'f', equivLocale,
|
||||
i/3,
|
||||
expectAvail?'t':'f', inLocale, expectLocale);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestGetFunctionalEquivalent(void) {
|
||||
static const char *collCases[] = {
|
||||
/* avail locale equiv */
|
||||
"f", "de_US_CALIFORNIA", "de",
|
||||
"t", "zh_TW@collation=stroke", "zh@collation=stroke",
|
||||
"f", "de_CN@collation=pinyin", "de",
|
||||
"f", "de_CN@calendar=japanese", "de",
|
||||
"t", "de@calendar=japanese", "de",
|
||||
"t", "zh_TW@collation=standard", "zh@collation=standard",
|
||||
"t", "zh_TW@collation=traditional", "zh@collation=traditional",
|
||||
"f", "zh_CN@collation=standard", "zh",
|
||||
"f", "zh_CN@collation=traditional", "zh@collation=traditional",
|
||||
"t", "zh@collation=standard", "zh",
|
||||
"t", "zh@collation=traditional", "zh@collation=traditional",
|
||||
"f", "hi_IN@collation=direct", "hi@collation=direct",
|
||||
"t", "hi@collation=standard", "hi",
|
||||
"t", "hi@collation=direct", "hi@collation=direct",
|
||||
"f", "hi_AU@collation=direct;currency=CHF;calendar=buddhist", "hi@collation=direct",
|
||||
"f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *calCases[] = {
|
||||
/* avail locale equiv */
|
||||
"t", "en_US", "en@calendar=gregorian",
|
||||
"f", "ja_JP_TOKYO", "ja@calendar=gregorian",
|
||||
"f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese",
|
||||
"t", "sr@calendar=gregorian", "sr@calendar=gregorian",
|
||||
"t", "en", "en@calendar=gregorian",
|
||||
NULL
|
||||
};
|
||||
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
TestGetFunctionalEquivalentOf(U_ICUDATA_COLL, "collations", "collation", TRUE, collCases);
|
||||
#endif
|
||||
TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE, calCases);
|
||||
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
log_verbose("Testing error conditions:\n");
|
||||
{
|
||||
char equivLocale[256] = "???";
|
||||
int32_t len;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBool gotAvail = FALSE;
|
||||
|
||||
len = ures_getFunctionalEquivalent(equivLocale, 255, U_ICUDATA_COLL,
|
||||
"calendar", "calendar", "ar_EG@calendar=islamic",
|
||||
&gotAvail, FALSE, &status);
|
||||
|
||||
if(status == U_MISSING_RESOURCE_ERROR) {
|
||||
log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n");
|
||||
} else {
|
||||
log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n",
|
||||
equivLocale, gotAvail?'t':'f', u_errorName(status));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue