File tree Expand file tree Collapse file tree 7 files changed +50
-9
lines changed
Expand file tree Collapse file tree 7 files changed +50
-9
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ namespace TestHook
44{
55 struct LayoutGuard
66 {
7+ LayoutGuard () = default ;
78 LayoutGuard (HKL layout, bool needsUnload) noexcept ;
89 ~LayoutGuard ();
910
Original file line number Diff line number Diff line change @@ -628,7 +628,17 @@ void InputTest::TerminalInputNullKeyTests()
628628{
629629 using namespace std ::string_view_literals;
630630
631- const auto layout = TestHook::SetTerminalInputKeyboardLayout (L" 00000409" ); // US English
631+ TestHook::LayoutGuard layout;
632+ try
633+ {
634+ layout = TestHook::SetTerminalInputKeyboardLayout (L" 00000409" ); // US English
635+ }
636+ catch (...)
637+ {
638+ Log::Result (TestResults::Result::Skipped);
639+ return ;
640+ }
641+
632642 unsigned int uiKeystate = LEFT_CTRL_PRESSED;
633643
634644 TerminalInput input;
Original file line number Diff line number Diff line change @@ -252,10 +252,29 @@ extern "C" HRESULT __declspec(dllexport) __cdecl KittyKeyTestDataSource(IDataSou
252252
253253class KittyKeyboardProtocolTests
254254{
255- TestHook::LayoutGuard layout = TestHook::SetTerminalInputKeyboardLayout( L" 0001040c " ); // French (Standard, AZERTY)
255+ TestHook::LayoutGuard layout;
256256
257257 TEST_CLASS (KittyKeyboardProtocolTests);
258258
259+ TEST_CLASS_SETUP (ClassSetup)
260+ {
261+ try
262+ {
263+ layout = TestHook::SetTerminalInputKeyboardLayout (L" 0001040c" ); // French (Standard, AZERTY)
264+ }
265+ catch (...)
266+ {
267+ Log::Result (TestResults::Result::Skipped);
268+ }
269+ return true ;
270+ }
271+
272+ TEST_CLASS_CLEANUP (ClassCleanup)
273+ {
274+ layout = {};
275+ return true ;
276+ }
277+
259278 TEST_METHOD (KeyPressTests)
260279 {
261280 BEGIN_TEST_METHOD_PROPERTIES ()
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT license.
3+
4+ #include " precomp.h"
5+
6+ // This default no-op implementation lives in its own .obj so that the linker
7+ // can skip it when a test DLL supplies its own definition. The classic linking
8+ // model only pulls in .obj files from a .lib if they resolve an otherwise
9+ // unresolved symbol - and nothing else in the test DLL refers to this file.
10+ // See: https://devblogs.microsoft.com/oldnewthing/20250416-00/?p=111077
11+ extern " C" HKL TestHook_TerminalInput_KeyboardLayout ()
12+ {
13+ return nullptr ;
14+ }
Original file line number Diff line number Diff line change 1313 <ItemGroup >
1414 <ClCompile Include =" ..\mouseInput.cpp" />
1515 <ClCompile Include =" ..\terminalInput.cpp" />
16+ <ClCompile Include =" ..\TestHook.cpp" />
1617 <ClCompile Include =" ..\precomp.cpp" >
1718 <PrecompiledHeader >Create</PrecompiledHeader >
1819 </ClCompile >
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ PRECOMPILED_INCLUDE = ..\precomp.h
3030SOURCES = \
3131 .. \terminalInput . cpp \
3232 .. \mouseInput . cpp \
33+ .. \TestHook . cpp \
3334
3435INCLUDES = \
3536 $(INCLUDES ); \
Original file line number Diff line number Diff line change @@ -1497,15 +1497,10 @@ void TerminalInput::KeyboardHelper::init() noexcept
14971497 }
14981498}
14991499
1500- #pragma comment(linker, "/alternatename:TestHook_TerminalInput_KeyboardLayout=TestHook_TerminalInput_KeyboardLayout_Default")
1500+ // The default no-op implementation lives in TestHook.cpp (its own .obj) so the
1501+ // linker can skip it when a test DLL supplies its own definition.
15011502extern " C" HKL TestHook_TerminalInput_KeyboardLayout ();
15021503
1503- // Thanks to LTCG this should get inlined in Release builds and the test branch removed.
1504- extern " C" HKL TestHook_TerminalInput_KeyboardLayout_Default ()
1505- {
1506- return nullptr ;
1507- }
1508-
15091504void TerminalInput::KeyboardHelper::initSlow () noexcept
15101505{
15111506 if (const auto hkl = TestHook_TerminalInput_KeyboardLayout ())
You can’t perform that action at this time.
0 commit comments