Fix compilation failures?

This commit is contained in:
Leonard Hecker
2026-04-17 14:39:27 +02:00
parent 51416799f3
commit 6e3bb0ead4
7 changed files with 50 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ namespace TestHook
{
struct LayoutGuard
{
LayoutGuard() = default;
LayoutGuard(HKL layout, bool needsUnload) noexcept;
~LayoutGuard();

View File

@@ -628,7 +628,17 @@ void InputTest::TerminalInputNullKeyTests()
{
using namespace std::string_view_literals;
const auto layout = TestHook::SetTerminalInputKeyboardLayout(L"00000409"); // US English
TestHook::LayoutGuard layout;
try
{
layout = TestHook::SetTerminalInputKeyboardLayout(L"00000409"); // US English
}
catch (...)
{
Log::Result(TestResults::Result::Skipped);
return;
}
unsigned int uiKeystate = LEFT_CTRL_PRESSED;
TerminalInput input;

View File

@@ -252,10 +252,29 @@ extern "C" HRESULT __declspec(dllexport) __cdecl KittyKeyTestDataSource(IDataSou
class KittyKeyboardProtocolTests
{
TestHook::LayoutGuard layout = TestHook::SetTerminalInputKeyboardLayout(L"0001040c"); // French (Standard, AZERTY)
TestHook::LayoutGuard layout;
TEST_CLASS(KittyKeyboardProtocolTests);
TEST_CLASS_SETUP(ClassSetup)
{
try
{
layout = TestHook::SetTerminalInputKeyboardLayout(L"0001040c"); // French (Standard, AZERTY)
}
catch (...)
{
Log::Result(TestResults::Result::Skipped);
}
return true;
}
TEST_CLASS_CLEANUP(ClassCleanup)
{
layout = {};
return true;
}
TEST_METHOD(KeyPressTests)
{
BEGIN_TEST_METHOD_PROPERTIES()

View File

@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
// This default no-op implementation lives in its own .obj so that the linker
// can skip it when a test DLL supplies its own definition. The classic linking
// model only pulls in .obj files from a .lib if they resolve an otherwise
// unresolved symbol - and nothing else in the test DLL refers to this file.
// See: https://devblogs.microsoft.com/oldnewthing/20250416-00/?p=111077
extern "C" HKL TestHook_TerminalInput_KeyboardLayout()
{
return nullptr;
}

View File

@@ -13,6 +13,7 @@
<ItemGroup>
<ClCompile Include="..\mouseInput.cpp" />
<ClCompile Include="..\terminalInput.cpp" />
<ClCompile Include="..\TestHook.cpp" />
<ClCompile Include="..\precomp.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>

View File

@@ -30,6 +30,7 @@ PRECOMPILED_INCLUDE = ..\precomp.h
SOURCES= \
..\terminalInput.cpp \
..\mouseInput.cpp \
..\TestHook.cpp \
INCLUDES = \
$(INCLUDES); \

View File

@@ -1497,15 +1497,10 @@ void TerminalInput::KeyboardHelper::init() noexcept
}
}
#pragma comment(linker, "/alternatename:TestHook_TerminalInput_KeyboardLayout=TestHook_TerminalInput_KeyboardLayout_Default")
// The default no-op implementation lives in TestHook.cpp (its own .obj) so the
// linker can skip it when a test DLL supplies its own definition.
extern "C" HKL TestHook_TerminalInput_KeyboardLayout();
// Thanks to LTCG this should get inlined in Release builds and the test branch removed.
extern "C" HKL TestHook_TerminalInput_KeyboardLayout_Default()
{
return nullptr;
}
void TerminalInput::KeyboardHelper::initSlow() noexcept
{
if (const auto hkl = TestHook_TerminalInput_KeyboardLayout())