ICU-3591 uloc_acceptLanguage tests
X-SVN-Rev: 16751
This commit is contained in:
parent
ec27958921
commit
59ac27a504
@ -216,6 +216,7 @@ void addLocaleTest(TestNode** root)
|
||||
TESTCASE(TestGetLocale);
|
||||
TESTCASE(TestDisplayNameWarning);
|
||||
TESTCASE(TestNonexistentLanguageExemplars);
|
||||
TESTCASE(TestAcceptLanguage);
|
||||
}
|
||||
|
||||
|
||||
@ -2262,3 +2263,53 @@ static void TestNonexistentLanguageExemplars(void) {
|
||||
u_errorName(ec));
|
||||
}
|
||||
}
|
||||
|
||||
static void TestAcceptLanguage(void) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UAcceptResult outResult;
|
||||
UEnumeration *available;
|
||||
char tmp[200];
|
||||
int i;
|
||||
int32_t rc = 0;
|
||||
|
||||
struct {
|
||||
int32_t httpSet;
|
||||
const char *icuSet;
|
||||
const char *expect;
|
||||
UAcceptResult res;
|
||||
} tests[] = {
|
||||
/*0*/{ 0, NULL, "mt_MT", ULOC_ACCEPT_VALID },
|
||||
/*1*/{ 1, NULL, "en", ULOC_ACCEPT_VALID },
|
||||
/*2*/{ 2, NULL, "en", ULOC_ACCEPT_FALLBACK },
|
||||
/*3*/{ 3, NULL, "", ULOC_ACCEPT_FAILED },
|
||||
};
|
||||
const int32_t numTests = sizeof(tests)/sizeof(tests[0]);
|
||||
const char *http[] = { /*0*/ "mt-mt, ja;q=0.76, en-us;q=0.95, en;q=0.92, en-gb;q=0.89, fr;q=0.87, iu-ca;q=0.84, iu;q=0.82, ja-jp;q=0.79, mt;q=0.97, de-de;q=0.74, de;q=0.71, es;q=0.68, it-it;q=0.66, it;q=0.63, vi-vn;q=0.61, vi;q=0.58, nl-nl;q=0.55, nl;q=0.53, th-th-traditional;q=.01",
|
||||
/*1*/ "ja;q=0.5, en;q=0.8, tlh",
|
||||
/*2*/ "en-wf, de-lx;q=0.8",
|
||||
/*3*/ "mga-ie;q=0.9, tlh",
|
||||
};
|
||||
|
||||
for(i=0;i<numTests;i++) {
|
||||
outResult = -3;
|
||||
status=U_ZERO_ERROR;
|
||||
log_verbose("test #%d: http[%s], ICU[%s], expect %s, %d\n",
|
||||
i, http[tests[i].httpSet], tests[i].icuSet, tests[i].expect, tests[i].res);
|
||||
|
||||
available = ures_openAvailableLocales(tests[i].icuSet, &status);
|
||||
tmp[0]=0;
|
||||
rc = uloc_acceptLanguageFromHTTP(tmp, 199, &outResult, http[tests[i].httpSet], available, &status);
|
||||
uenum_close(available);
|
||||
log_verbose(" got %s, %d [%s]\n", tmp[0]?tmp:"(EMPTY)", outResult, u_errorName(status));
|
||||
if(outResult != tests[i].res) {
|
||||
log_err("FAIL: #%d: expected outResult of %d but got %d\n", i, tests[i].res, outResult);
|
||||
log_info("test #%d: http[%s], ICU[%s], expect %s, %d\n",
|
||||
i, http[tests[i].httpSet], tests[i].icuSet, tests[i].expect, tests[i].res);
|
||||
}
|
||||
if((outResult>0)&&uprv_strcmp(tmp, tests[i].expect)) {
|
||||
log_err("FAIL: #%d: expected %s but got %s\n", i, tests[i].expect, tmp);
|
||||
log_info("test #%d: http[%s], ICU[%s], expect %s, %d\n",
|
||||
i, http[tests[i].httpSet], tests[i].icuSet, tests[i].expect, tests[i].res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -97,5 +97,6 @@ static void TestGetLocale(void);
|
||||
static void setUpDataTable(void);
|
||||
static void cleanUpDataTable(void);
|
||||
/*static void displayDataTable(void);*/
|
||||
static void TestAcceptLanguage(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user