Commit 596f8d67 authored by Detlef Riekenberg's avatar Detlef Riekenberg Committed by Alexandre Julliard

mlang: Suppress country data in rfc1766, with tests.

parent e84ae0e7
......@@ -1137,29 +1137,54 @@ HRESULT WINAPI IsConvertINetStringAvailable(
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)
{
rfc1766[n - 1] = '-';
n += GetLocaleInfoA( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n );
LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
return S_OK;
i = PRIMARYLANGID(lcid);
if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
(SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
(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;
}
static inline HRESULT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
{
INT n = GetLocaleInfoW( lcid, LOCALE_SISO639LANGNAME, rfc1766, len );
INT save = n;
WCHAR buffer[MAX_RFC1766_NAME];
INT n = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
INT i;
if (n)
{
rfc1766[n - 1] = '-';
n += GetLocaleInfoW( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n );
if (n == save)
rfc1766[n - 1] = '\0';
LCMapStringW( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
return S_OK;
i = PRIMARYLANGID(lcid);
if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
(SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
(SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
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;
}
......
......@@ -940,25 +940,30 @@ static void test_Rfc1766ToLcid(void)
static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
{
CHAR expected[MAX_RFC1766_NAME];
CHAR buffer[MAX_RFC1766_NAME + 1];
DWORD i;
HRESULT hr;
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);
/*
* S_FALSE happens when 'kok' instead matches to a different Rfc1766 name
* for example 'ko' so it is not a failure but does not give us what
* we are looking for
*/
if (hr != S_FALSE)
{
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
rfcstr = NULL;
hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid_table[i].lcid, &rfcstr);
ok(hr == lcid_table[i].hr,
"#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
if (hr != S_OK)
continue; /* no result-string created */
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);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment