Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com>
---
Sending this instead, as GetKeyboardLayout(Name) looks harder to fix
properly than anticipated.
dlls/user32/tests/input.c | 78 ++++++++++++++++++++++++++++++++++++---
1 file changed, 72 insertions(+), 6 deletions(-)
diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c
index 382e124e1f4..a0c31dcf607 100644
--- a/dlls/user32/tests/input.c
+++ b/dlls/user32/tests/input.c
@@ -3036,9 +3036,10 @@ static void test_get_async_key_state(void)
static void test_keyboard_layout_name(void)
{
WCHAR klid[KL_NAMELENGTH], tmpklid[KL_NAMELENGTH], layout_path[MAX_PATH], value[5];
- HKL layout, tmplayout, layouts[64];
- DWORD status, value_size;
- int i, len;
+ HKL layout, tmplayout, *layouts, *layouts_preload;
+ DWORD status, value_size, klid_size, type, id;
+ int i, j, len;
+ HKEY hkey;
BOOL ret;
if (0) /* crashes on native system */
@@ -3051,15 +3052,77 @@ static void test_keyboard_layout_name(void)
layout = GetKeyboardLayout(0);
- len = GetKeyboardLayoutList(ARRAY_SIZE(layouts), layouts);
+ len = GetKeyboardLayoutList(0, NULL);
+ ok(len > 0, "GetKeyboardLayoutList returned %d\n", len);
+
+ layouts = malloc(len * sizeof(HKL));
+ ok(layouts != NULL, "Could not allocate memory\n");
+
+ len = GetKeyboardLayoutList(len, layouts);
ok(len > 0, "GetKeyboardLayoutList returned %d\n", len);
+ layouts_preload = calloc(len, sizeof(HKL));
+ ok(layouts_preload != NULL, "Could not allocate memory\n");
+
+ if (!RegOpenKeyW( HKEY_CURRENT_USER, L"Keyboard Layout\\Preload", &hkey ))
+ {
+ i = 0;
+ type = REG_SZ;
+ klid_size = sizeof(klid);
+ value_size = ARRAY_SIZE(value);
+ while (i < len && !RegEnumValueW( hkey, i++, value, &value_size, NULL, &type, (void *)&klid, &klid_size ))
+ {
+ klid_size = sizeof(klid);
+ value_size = ARRAY_SIZE(value);
+ layouts_preload[i - 1] = UlongToHandle( wcstoul( klid, NULL, 16 ) );
+
+ id = (DWORD_PTR)layouts_preload[i - 1];
+ if (id & 0x80000000) ok((id & 0xf0000000) == 0xd0000000, "Unexpected preloaded keyboard layout high bits %#x\n", id);
+ else ok(!(id & 0xf0000000), "Unexpected preloaded keyboard layout high bits %#x\n", id);
+ }
+
+ ok(i <= len, "Unexpected keyboard count %d in preload list\n", i);
+ RegCloseKey( hkey );
+ }
+
+ if (!RegOpenKeyW( HKEY_CURRENT_USER, L"Keyboard Layout\\Substitutes", &hkey ))
+ {
+ for (i = 0; i < len && layouts_preload[i]; ++i)
+ {
+ type = REG_SZ;
+ klid_size = sizeof(klid);
+ swprintf( tmpklid, KL_NAMELENGTH, L"%08x", HandleToUlong( layouts_preload[i] ) );
+ if (!RegQueryValueExW( hkey, tmpklid, NULL, &type, (void *)&klid, &klid_size ))
+ {
+ layouts_preload[i] = UlongToHandle( wcstoul( klid, NULL, 16 ) );
+
+ /* Substitute should contain the keyboard layout id, not the HKL high word */
+ id = (DWORD_PTR)layouts_preload[i];
+ ok(!(id & 0xf0000000), "Unexpected substitute keyboard layout high bits %#x\n", id);
+ }
+ else
+ {
+ id = (DWORD_PTR)layouts_preload[i];
+ ok(!(id & 0xf0000000), "Unexpected preloaded keyboard layout high bits %#x\n", id);
+ }
+ }
+
+ RegCloseKey( hkey );
+ }
+
for (i = len - 1; i >= 0; --i)
{
- UINT id = (UINT_PTR)layouts[i];
+ id = (DWORD_PTR)layouts[i];
ActivateKeyboardLayout(layouts[i], 0);
GetKeyboardLayoutNameW(klid);
+ for (j = 0; j < len; ++j)
+ {
+ swprintf( tmpklid, KL_NAMELENGTH, L"%08X", layouts_preload[j] );
+ if (!wcscmp( tmpklid, klid )) break;
+ }
+ ok(j < len, "Could not find keyboard layout %p in preload list\n", layout);
+
if (id & 0x80000000)
{
todo_wine ok((id >> 28) == 0xf, "hkl high bits %#x, expected 0xf\n", id >> 28);
@@ -3084,7 +3147,7 @@ static void test_keyboard_layout_name(void)
tmplayout = LoadKeyboardLayoutW(klid, KLF_ACTIVATE);
/* The low word of HKL is the selected user lang and may be different as LoadKeyboardLayoutW also selects the default lang from the layout */
- ok(((UINT_PTR)tmplayout & ~0xffff) == ((UINT_PTR)layouts[i] & ~0xffff), "GetKeyboardLayout returned %p, expected %p\n", tmplayout, layouts[i]);
+ ok(((UINT_PTR)tmplayout & ~0xffff) == ((UINT_PTR)layouts[i] & ~0xffff), "LoadKeyboardLayoutW returned %p, expected %p\n", tmplayout, layouts[i]);
/* The layout name only depends on the keyboard layout: the high word of HKL. */
GetKeyboardLayoutNameW(tmpklid);
@@ -3092,6 +3155,9 @@ static void test_keyboard_layout_name(void)
}
ActivateKeyboardLayout(layout, 0);
+
+ free(layouts);
+ free(layouts_preload);
}
static void test_key_names(void)
--
2.31.0