For React Native.
-- v2: bcp47langs: Add GetFontFallbackLanguageList() stub.
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 | 84 ++++++++++++++++++++++++++++++ 6 files changed, 149 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..b0b73e100f8 --- /dev/null +++ b/dlls/bcp47langs/tests/bcp47langs.c @@ -0,0 +1,84 @@ +/* + * 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" + +static HRESULT (WINAPI *pGetFontFallbackLanguageList)(const WCHAR *, size_t, WCHAR *, size_t *); + +static void init_function_pointers(void) +{ + HMODULE bcp47langs = LoadLibraryA("bcp47langs.dll"); + + pGetFontFallbackLanguageList = (void*)GetProcAddress(bcp47langs, "GetFontFallbackLanguageList"); +} + +static void test_GetFontFallbackLanguageList(void) +{ + size_t required_size; + WCHAR buffer[128]; + HRESULT hr; + + if (!pGetFontFallbackLanguageList) + { + win_skip("GetFontFallbackLanguageList() is unavailable.\n"); + return; + } + + /* Parameter checks */ + required_size = 0xdeadbeef; + hr = pGetFontFallbackLanguageList(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 = pGetFontFallbackLanguageList(L"en-US", 0, buffer, &required_size); + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + required_size = 0; + hr = pGetFontFallbackLanguageList(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 = pGetFontFallbackLanguageList(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 = pGetFontFallbackLanguageList(L"en-US", ARRAY_SIZE(buffer), buffer, NULL); + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + } + + hr = pGetFontFallbackLanguageList(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 = pGetFontFallbackLanguageList(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) +{ + init_function_pointers(); + + test_GetFontFallbackLanguageList(); +}
On Mon Jun 30 16:05:22 2025 +0000, Alexandre Julliard wrote:
Checking for the dll itself is not very useful, the tests won't be run if it's unavailable. Also are there platforms where `GetFontFallbackLanguageList` is missing?
Okay. I've removed the DLL check. bcp47langs.dll is not available on Windows 8 and older versions.
On Tue Jul 1 02:32:48 2025 +0000, Zhiyi Zhang wrote:
Okay. I've removed the DLL check. bcp47langs.dll is not available on Windows 8 and older versions.
The other question is which versions have bcp47langs.dll but not GetFontFallbackLanguageList?
On Tue Jul 1 07:00:07 2025 +0000, Alexandre Julliard wrote:
The other question is which versions have bcp47langs.dll but not GetFontFallbackLanguageList?
Probably none. Why? Isn't it possible that the test can be manually launched on Win7?
On Tue Jul 1 07:12:41 2025 +0000, Zhiyi Zhang wrote:
Probably none. Why? Isn't it possible that the test can be manually launched on Win7?
If there's no version that doesn't have the function, then you can import it directly and avoid all the extra work.
The behavior of the test on platforms that don't have the dll is irrelevant, there's no need to make any efforts to make the test succeed in that case.