From: Zhiyi Zhang zzhang@codeweavers.com
--- configure.ac | 1 + dlls/bcp47langs/Makefile.in | 3 ++ dlls/bcp47langs/bcp47langs.spec | 2 +- dlls/bcp47langs/main.c | 55 ++++++++++++++++++++++++ dlls/bcp47langs/tests/Makefile.in | 5 +++ dlls/bcp47langs/tests/bcp47langs.c | 69 ++++++++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 dlls/bcp47langs/main.c create mode 100644 dlls/bcp47langs/tests/Makefile.in create mode 100644 dlls/bcp47langs/tests/bcp47langs.c
diff --git a/configure.ac b/configure.ac index 6d093b52526..534ce5cb092 100644 --- a/configure.ac +++ b/configure.ac @@ -2467,6 +2467,7 @@ WINE_CONFIG_MAKEFILE(dlls/avifil32/tests) WINE_CONFIG_MAKEFILE(dlls/avifile.dll16) WINE_CONFIG_MAKEFILE(dlls/avrt) WINE_CONFIG_MAKEFILE(dlls/bcp47langs) +WINE_CONFIG_MAKEFILE(dlls/bcp47langs/tests) WINE_CONFIG_MAKEFILE(dlls/bcrypt) WINE_CONFIG_MAKEFILE(dlls/bcrypt/tests) WINE_CONFIG_MAKEFILE(dlls/bcryptprimitives) diff --git a/dlls/bcp47langs/Makefile.in b/dlls/bcp47langs/Makefile.in index 5eb4caaf0e7..ee013421c3b 100644 --- a/dlls/bcp47langs/Makefile.in +++ b/dlls/bcp47langs/Makefile.in @@ -1,2 +1,5 @@ MODULE = bcp47langs.dll IMPORTLIB = bcp47langs + +SOURCES = \ + main.c diff --git a/dlls/bcp47langs/bcp47langs.spec b/dlls/bcp47langs/bcp47langs.spec index a054c1486a9..c90a2b59d49 100644 --- a/dlls/bcp47langs/bcp47langs.spec +++ b/dlls/bcp47langs/bcp47langs.spec @@ -37,7 +37,7 @@ @ stub GetAppropriateUserPreferredAndDisplayLanguagesForUser @ stub GetClosestMatchingUserLanguage @ stub GetDisplayLanguagesForAllUsers -@ stub GetFontFallbackLanguageList +@ stdcall GetFontFallbackLanguageList(wstr long ptr ptr) @ stub GetHttpAcceptLanguageOptOut @ stub GetInputMethodOverrideForUser @ stub GetPendingUserDisplayLanguage diff --git a/dlls/bcp47langs/main.c b/dlls/bcp47langs/main.c new file mode 100644 index 00000000000..7ec9ebef697 --- /dev/null +++ b/dlls/bcp47langs/main.c @@ -0,0 +1,55 @@ +/* + * Copyright 2025 Zhiyi Zhang for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdarg.h> +#include <windef.h> +#include <winbase.h> +#include <winnls.h> +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(bcp47langs); + +HRESULT WINAPI GetFontFallbackLanguageList(const WCHAR *lang, size_t buffer_length, WCHAR *buffer, + size_t *required_buffer_length) +{ + WCHAR locale[LOCALE_NAME_MAX_LENGTH]; + size_t lang_length; + + FIXME("lang %s, buffer_length %Iu, buffer %p, required_buffer_length %p stub!\n", + wine_dbgstr_w(lang), buffer_length, buffer, required_buffer_length); + + if (!buffer_length || !buffer) + return E_INVALIDARG; + + if (!lang) + { + if (!GetUserDefaultLocaleName(locale, LOCALE_NAME_MAX_LENGTH)) + return E_FAIL; + + lang = locale; + } + + /* Return the original language as the fallback language list */ + lang_length = wcslen(lang) + 1; + *required_buffer_length = lang_length; + if (buffer_length < lang_length) + return E_NOT_SUFFICIENT_BUFFER; + + memcpy(buffer, lang, lang_length * sizeof(WCHAR)); + return S_OK; +} diff --git a/dlls/bcp47langs/tests/Makefile.in b/dlls/bcp47langs/tests/Makefile.in new file mode 100644 index 00000000000..3c2cee465cf --- /dev/null +++ b/dlls/bcp47langs/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = bcp47langs.dll +IMPORTS = bcp47langs + +SOURCES = \ + bcp47langs.c diff --git a/dlls/bcp47langs/tests/bcp47langs.c b/dlls/bcp47langs/tests/bcp47langs.c new file mode 100644 index 00000000000..7cdf3ed8ef4 --- /dev/null +++ b/dlls/bcp47langs/tests/bcp47langs.c @@ -0,0 +1,69 @@ +/* + * Copyright 2025 Zhiyi Zhang for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include "wine/test.h" + +HRESULT WINAPI GetFontFallbackLanguageList(const WCHAR *, size_t, WCHAR *, size_t *); + +static void test_GetFontFallbackLanguageList(void) +{ + size_t required_size; + WCHAR buffer[128]; + HRESULT hr; + + /* Parameter checks */ + required_size = 0xdeadbeef; + hr = GetFontFallbackLanguageList(NULL, ARRAY_SIZE(buffer), buffer, &required_size); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(required_size != 0xdeadbeef, "Got unexpected size %Iu.\n", required_size); + + hr = GetFontFallbackLanguageList(L"en-US", 0, buffer, &required_size); + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + required_size = 0; + hr = GetFontFallbackLanguageList(L"en-US", 1, buffer, &required_size); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "Got unexpected hr %#lx.\n", hr); + ok(required_size > 0, "Got unexpected size %Iu.\n", required_size); + + hr = GetFontFallbackLanguageList(L"en-US", ARRAY_SIZE(buffer), NULL, &required_size); + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + if (0) /* Crashes on Windows */ + { + hr = GetFontFallbackLanguageList(L"en-US", ARRAY_SIZE(buffer), buffer, NULL); + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + } + + hr = GetFontFallbackLanguageList(L"deadbeef", ARRAY_SIZE(buffer), buffer, &required_size); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + /* Normal call */ + required_size = 0; + hr = GetFontFallbackLanguageList(L"en-US", ARRAY_SIZE(buffer), buffer, &required_size); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(!wcsncmp(buffer, L"en-US", wcslen(L"en-US")), "Got unexpected %s.\n", wine_dbgstr_w(buffer)); + ok(required_size >= (wcslen(L"en-US") + 1), "Got unexpected size %Iu.\n", required_size); +} + +START_TEST(bcp47langs) +{ + test_GetFontFallbackLanguageList(); +}