Skip to content

Commit 2b0b817

Browse files
committed
WIP: Remove keyboard layout test logic
It wasn't ever all wired up and is too costly to maintain.
1 parent f0c4c8b commit 2b0b817

14 files changed

+84
-10178
lines changed

test/ConsoleFixture.cs

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,23 @@
11

22
using System;
3-
using System.Collections.Generic;
4-
using System.Globalization;
5-
using System.Runtime.InteropServices;
6-
using System.Threading;
7-
using Xunit;
83

94
namespace Test
105
{
11-
public class WindowsConsoleFixtureHelper
12-
{
13-
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
14-
static extern IntPtr LoadKeyboardLayout(string pwszKLID, uint Flags);
15-
16-
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
17-
static extern IntPtr GetKeyboardLayout(uint idThread);
18-
19-
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
20-
static extern int GetKeyboardLayoutList(int nBuff, [Out] IntPtr[] lpList);
21-
22-
// For set:
23-
[DllImport("user32.dll", CharSet = CharSet.Auto)]
24-
public static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
25-
26-
// For get:
27-
[DllImport("user32.dll", SetLastError = true)]
28-
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
29-
30-
[DllImport("user32.dll", SetLastError = true)]
31-
static extern IntPtr GetForegroundWindow();
32-
33-
const int WM_INPUTLANGCHANGEREQUEST = 0x0050;
34-
35-
private static string GetLayoutNameFromHKL(IntPtr hkl)
36-
{
37-
var lcid = (int)((uint)hkl & 0xffff);
38-
return (new CultureInfo(lcid)).Name;
39-
}
40-
41-
public static IEnumerable<string> GetKeyboardLayoutList()
42-
{
43-
int cnt = GetKeyboardLayoutList(0, null);
44-
var list = new IntPtr[cnt];
45-
GetKeyboardLayoutList(list.Length, list);
46-
47-
foreach (var layout in list)
48-
{
49-
yield return GetLayoutNameFromHKL(layout);
50-
}
51-
}
52-
53-
public static string GetKeyboardLayout()
54-
{
55-
// In CI environments like GitHub Actions, keyboard layout detection can fail
56-
// or return incorrect results. Default to en-US in these cases.
57-
if (Environment.GetEnvironmentVariable("GITHUB_ACTIONS") == "true" ||
58-
Environment.GetEnvironmentVariable("TF_BUILD") == "true" ||
59-
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
60-
{
61-
return "en-US";
62-
}
63-
64-
var layout = GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), out var processId));
65-
return GetLayoutNameFromHKL(layout);
66-
}
67-
68-
public static IntPtr SetKeyboardLayout(string lang)
69-
{
70-
var layoutId = (new CultureInfo(lang)).KeyboardLayoutId;
71-
var layout = LoadKeyboardLayout(layoutId.ToString("x8"), 0x80);
72-
// Hacky, but tests are probably running in a console app and the layout change
73-
// is ignored, so post the layout change to the foreground window.
74-
PostMessage(GetForegroundWindow(), WM_INPUTLANGCHANGEREQUEST, 0, layoutId);
75-
Thread.Sleep(500);
76-
return layout;
77-
}
78-
}
79-
806
public class ConsoleFixture : IDisposable
817
{
828
public KeyboardLayout KbLayout { get; private set; }
83-
public string Lang { get; private set; }
84-
public string Os { get; private set; }
859

8610
public ConsoleFixture()
8711
{
88-
Lang = "";
89-
Os = "";
9012
}
9113

92-
public void Initialize(string lang, string os)
14+
public void Initialize()
9315
{
94-
if (!string.Equals(lang, Lang) || !string.Equals(os, Os))
95-
{
96-
Lang = lang;
97-
Os = os;
98-
KbLayout = new KeyboardLayout(lang, "windows");
99-
}
16+
KbLayout = new KeyboardLayout();
10017
}
10118

10219
public void Dispose()
10320
{
10421
}
105-
106-
public override string ToString()
107-
{
108-
return Lang + "-" + Os;
109-
}
11022
}
11123
}

test/DeadKeyTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public partial class ReadLine
88
[SkippableFact]
99
public void DeadKeyShouldBeIgnored()
1010
{
11-
Skip.If(this.Fixture.Lang != "fr-FR", "The dead key test requires Keyboard layout to be set to 'fr-FR'");
11+
Skip.If(true, "The dead key test requires Keyboard layout to be set to 'fr-FR'");
1212
TestSetup(KeyMode.Cmd);
1313

1414
Test("aa", Keys("aa", _.DeadKey_Caret));

test/Get-KeyInfoData.ps1

Lines changed: 0 additions & 177 deletions
This file was deleted.

0 commit comments

Comments
 (0)