diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index 409676a8fc..c93400e68b 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -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;i0)&&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); + } + } +} diff --git a/icu4c/source/test/cintltst/cloctst.h b/icu4c/source/test/cintltst/cloctst.h index 2f069bc1af..b419119804 100644 --- a/icu4c/source/test/cintltst/cloctst.h +++ b/icu4c/source/test/cintltst/cloctst.h @@ -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