Skip to content

Commit 6e3bb0e

Browse files
committed
Fix compilation failures?
1 parent 5141679 commit 6e3bb0e

File tree

7 files changed

+50
-9
lines changed

7 files changed

+50
-9
lines changed

src/terminal/adapter/ut_adapter/TestHook.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

src/terminal/adapter/ut_adapter/inputTest.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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;

src/terminal/adapter/ut_adapter/kittyKeyboardProtocol.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,29 @@ extern "C" HRESULT __declspec(dllexport) __cdecl KittyKeyTestDataSource(IDataSou
252252

253253
class 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()

src/terminal/input/TestHook.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

src/terminal/input/lib/terminalinput.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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>

src/terminal/input/sources.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ PRECOMPILED_INCLUDE = ..\precomp.h
3030
SOURCES= \
3131
..\terminalInput.cpp \
3232
..\mouseInput.cpp \
33+
..\TestHook.cpp \
3334

3435
INCLUDES = \
3536
$(INCLUDES); \

src/terminal/input/terminalInput.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff 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.
15011502
extern "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-
15091504
void TerminalInput::KeyboardHelper::initSlow() noexcept
15101505
{
15111506
if (const auto hkl = TestHook_TerminalInput_KeyboardLayout())

0 commit comments

Comments
 (0)