From 21b6d994d2ebd09026208b04ea58e44f331f53a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Hentschel?= Date: Sun, 18 Mar 2012 19:28:41 +0100 Subject: [PATCH] kernel32: Handle LOCALE_NAME_USER_DEFAULT with tests. --- dlls/kernel32/locale.c | 4 ++++ dlls/kernel32/tests/locale.c | 42 ++++++++++++++++++++++++++++++++++++ include/winnls.h | 19 ++++++++++++++++ include/winnt.h | 1 + 4 files changed, 66 insertions(+) diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c index 2c3760caa2c..20451ffdcbe 100644 --- a/dlls/kernel32/locale.c +++ b/dlls/kernel32/locale.c @@ -976,6 +976,10 @@ LCID WINAPI LocaleNameToLCID( LPCWSTR name, DWORD flags ) if (flags) FIXME( "unsupported flags %x\n", flags ); + if (name == LOCALE_NAME_USER_DEFAULT) + return GetUserDefaultLCID(); + + /* string parsing */ parse_locale_name( name, &locale_name ); TRACE( "found lcid %x for %s, matches %d\n", diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c index f5b77f71373..49678cef0c5 100644 --- a/dlls/kernel32/tests/locale.c +++ b/dlls/kernel32/tests/locale.c @@ -71,6 +71,8 @@ static BOOL (WINAPI *pEnumSystemLanguageGroupsA)(LANGUAGEGROUP_ENUMPROC, DWORD, static BOOL (WINAPI *pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROC, LGRPID, DWORD, LONG_PTR); static BOOL (WINAPI *pEnumUILanguagesA)(UILANGUAGE_ENUMPROC, DWORD, LONG_PTR); static BOOL (WINAPI *pEnumSystemLocalesEx)(LOCALE_ENUMPROCEX, DWORD, LPARAM, LPVOID); +static LCID (WINAPI *pLocaleNameToLCID)(LPCWSTR, DWORD); +static INT (WINAPI *pLCIDToLocaleName)(LCID, LPWSTR, INT, DWORD); static INT (WINAPI *pFoldStringA)(DWORD, LPCSTR, INT, LPSTR, INT); static INT (WINAPI *pFoldStringW)(DWORD, LPCWSTR, INT, LPWSTR, INT); static BOOL (WINAPI *pIsValidLanguageGroup)(LGRPID, DWORD); @@ -80,6 +82,8 @@ static void InitFunctionPointers(void) hKernel32 = GetModuleHandleA("kernel32"); pEnumSystemLanguageGroupsA = (void*)GetProcAddress(hKernel32, "EnumSystemLanguageGroupsA"); pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA"); + pLocaleNameToLCID = (void*)GetProcAddress(hKernel32, "LocaleNameToLCID"); + pLCIDToLocaleName = (void*)GetProcAddress(hKernel32, "LCIDToLocaleName"); pFoldStringA = (void*)GetProcAddress(hKernel32, "FoldStringA"); pFoldStringW = (void*)GetProcAddress(hKernel32, "FoldStringW"); pIsValidLanguageGroup = (void*)GetProcAddress(hKernel32, "IsValidLanguageGroup"); @@ -1637,6 +1641,43 @@ static void test_LCMapStringW(void) "unexpected error code %d\n", GetLastError()); } +static void test_LocaleNames(void) +{ + LCID lcid; + INT ret; + WCHAR buffer[LOCALE_NAME_MAX_LENGTH]; + + if (!pLocaleNameToLCID) + { + win_skip( "LocaleNameToLCID not available\n" ); + return; + } + + /* special cases */ + buffer[0] = 0; + lcid = pLocaleNameToLCID(LOCALE_NAME_USER_DEFAULT, 0); + ok(lcid == GetUserDefaultLCID() || broken(GetLastError() == ERROR_INVALID_PARAMETER /* Vista */), + "Expected lcid == %08x, got %08x, error %d\n", lcid, GetUserDefaultLCID(), GetLastError()); + ret = pLCIDToLocaleName(lcid, buffer, LOCALE_NAME_MAX_LENGTH, 0); + ok(ret > 0, "Expected ret > 0, got %d, error %d\n", ret, GetLastError()); + trace("%08x, %s\n", lcid, wine_dbgstr_w(buffer)); + + buffer[0] = 0; + lcid = pLocaleNameToLCID(LOCALE_NAME_SYSTEM_DEFAULT, 0); + todo_wine ok(!lcid && GetLastError() == ERROR_INVALID_PARAMETER, + "Expected lcid != 0, got %08x, error %d\n", lcid, GetLastError()); + ret = pLCIDToLocaleName(lcid, buffer, LOCALE_NAME_MAX_LENGTH, 0); + ok(ret > 0, "Expected ret > 0, got %d, error %d\n", ret, GetLastError()); + trace("%08x, %s\n", lcid, wine_dbgstr_w(buffer)); + + buffer[0] = 0; + lcid = pLocaleNameToLCID(LOCALE_NAME_INVARIANT, 0); + todo_wine ok(lcid == 0x7F, "Expected lcid = 0x7F, got %08x, error %d\n", lcid, GetLastError()); + ret = pLCIDToLocaleName(lcid, buffer, LOCALE_NAME_MAX_LENGTH, 0); + ok(ret > 0, "Expected ret > 0, got %d, error %d\n", ret, GetLastError()); + trace("%08x, %s\n", lcid, wine_dbgstr_w(buffer)); +} + /* this requires collation table patch to make it MS compatible */ static const char * const strings_sorted[] = { @@ -2782,6 +2823,7 @@ START_TEST(locale) test_CompareStringA(); test_LCMapStringA(); test_LCMapStringW(); + test_LocaleNames(); test_FoldStringA(); test_FoldStringW(); test_ConvertDefaultLocale(); diff --git a/include/winnls.h b/include/winnls.h index de6f875d63b..c7da119190f 100644 --- a/include/winnls.h +++ b/include/winnls.h @@ -321,6 +321,25 @@ extern "C" { #define LOCALE_SSORTNAME 0x1013 #define LOCALE_IDIGITSUBSTITUTION 0x1014 +/* Locale name special values */ +#if defined(__GNUC__) +# define LOCALE_NAME_INVARIANT (const WCHAR []){ 0 } +#elif defined(_MSC_VER) +# define LOCALE_NAME_INVARIANT L"" +#else +static const WCHAR LOCALE_NAME_INVARIANT[] = { 0 }; +#endif + +#if defined(__GNUC__) +# define LOCALE_NAME_SYSTEM_DEFAULT (const WCHAR []){'!','s','y','s','-','d','e','f','a','u','l','t','-','l','o','c','a','l','e',0} +#elif defined(_MSC_VER) +# define LOCALE_NAME_SYSTEM_DEFAULT L"!sys-default-locale" +#else +static const WCHAR LOCALE_NAME_SYSTEM_DEFAULT[] = {'!','s','y','s','-','d','e','f','a','u','l','t','-','l','o','c','a','l','e',0}; +#endif + +#define LOCALE_NAME_USER_DEFAULT NULL + #define LOCALE_IDEFAULTUNIXCODEPAGE 0x1030 /* Wine extension */ #define NORM_IGNORECASE 0x00001 diff --git a/include/winnt.h b/include/winnt.h index fc471b83a40..5cde0f4cc7a 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -1985,6 +1985,7 @@ NTSYSAPI void WINAPI RtlCaptureContext(CONTEXT*); #define LOCALE_CUSTOM_DEFAULT (MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_CUSTOM_DEFAULT),SORT_DEFAULT)) #define LOCALE_CUSTOM_UNSPECIFIED (MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_CUSTOM_UNSPECIFIED),SORT_DEFAULT)) #define LOCALE_CUSTOM_UI_DEFAULT (MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_UI_CUSTOM_DEFAULT),SORT_DEFAULT)) +#define LOCALE_NAME_MAX_LENGTH 85 #define UNREFERENCED_PARAMETER(u) (void)(u)