mlang: Suppress country data in rfc1766, with tests.

This commit is contained in:
Detlef Riekenberg 2009-05-29 23:24:30 +02:00 committed by Alexandre Julliard
parent e84ae0e720
commit 596f8d67a0
2 changed files with 57 additions and 27 deletions

View File

@ -1137,29 +1137,54 @@ HRESULT WINAPI IsConvertINetStringAvailable(
static inline HRESULT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len ) static inline HRESULT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len )
{ {
INT n = GetLocaleInfoA( lcid, LOCALE_SISO639LANGNAME, rfc1766, len ); CHAR buffer[MAX_RFC1766_NAME];
INT n = GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
INT i;
if (n) if (n)
{ {
rfc1766[n - 1] = '-'; i = PRIMARYLANGID(lcid);
n += GetLocaleInfoA( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n ); if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len ); (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
return S_OK; (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
buffer[n - 1] = '-';
i = GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
if (!i)
buffer[n - 1] = '\0';
}
else
i = 0;
LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len );
return ((n + i) > len) ? E_INVALIDARG : S_OK;
} }
return E_FAIL; return E_FAIL;
} }
static inline HRESULT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len ) static inline HRESULT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
{ {
INT n = GetLocaleInfoW( lcid, LOCALE_SISO639LANGNAME, rfc1766, len ); WCHAR buffer[MAX_RFC1766_NAME];
INT save = n; INT n = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
INT i;
if (n) if (n)
{ {
rfc1766[n - 1] = '-'; i = PRIMARYLANGID(lcid);
n += GetLocaleInfoW( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n ); if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
if (n == save) (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
rfc1766[n - 1] = '\0'; (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
LCMapStringW( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
return S_OK; buffer[n - 1] = '-';
i = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
if (!i)
buffer[n - 1] = '\0';
}
else
i = 0;
LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len);
return ((n + i) > len) ? E_INVALIDARG : S_OK;
} }
return E_FAIL; return E_FAIL;
} }

View File

@ -940,25 +940,30 @@ static void test_Rfc1766ToLcid(void)
static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2) static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
{ {
CHAR expected[MAX_RFC1766_NAME];
CHAR buffer[MAX_RFC1766_NAME + 1];
DWORD i;
HRESULT hr; HRESULT hr;
BSTR rfcstr; BSTR rfcstr;
LCID lcid;
static WCHAR kok[] = {'k','o','k',0}; for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
buffer[0] = '\0';
hr = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, kok); rfcstr = NULL;
/* hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid_table[i].lcid, &rfcstr);
* S_FALSE happens when 'kok' instead matches to a different Rfc1766 name ok(hr == lcid_table[i].hr,
* for example 'ko' so it is not a failure but does not give us what "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
* we are looking for
*/ if (hr != S_OK)
if (hr != S_FALSE) continue; /* no result-string created */
{
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); WideCharToMultiByte(CP_ACP, 0, rfcstr, -1, buffer, sizeof(buffer), NULL, NULL);
LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
ok(!lstrcmpA(buffer, expected),
"#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok_w2("Expected \"%s\", got \"%s\"n", kok, rfcstr);
SysFreeString(rfcstr); SysFreeString(rfcstr);
} }
} }