From 021ca6aee0aadded3f1731f4d030f79b0ef78963 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Tue, 28 Jul 2026 07:45:20 -0700 Subject: [PATCH] Add Runner C++ hotkey conflict unit test seed (#48352) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the C++ counterpart to #48346: a focused Runner native unit-test seed for core hotkey conflict behavior. Why this one: - Runner is core infrastructure rather than another C# module test. - It adds the missing native C++ test-project path for Runner. - The seed test is deterministic and covers in-app hotkey conflict detection. - It keeps the active rollout to two PRs: one C# module-services PR (#48346) and one C++ core/runner PR. Validation: - `tools\build\build.ps1 -Platform x64 -Configuration Debug -Path src\runner\UnitTests` - `vstest.console.exe x64\Debug\tests\Runner\Runner.UnitTests.dll /Tests:HasConflict_TwoModulesSameHotkey_InAppConflict` → 1 passed --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- PowerToys.slnx | 1 + src/runner/UnitTests/HotkeyConflictTests.cpp | 46 ++++++++++++++++ src/runner/UnitTests/UnitTests-Runner.vcxproj | 55 +++++++++++++++++++ .../UnitTests-Runner.vcxproj.filters | 32 +++++++++++ src/runner/UnitTests/pch.cpp | 5 ++ src/runner/UnitTests/pch.h | 50 +++++++++++++++++ 6 files changed, 189 insertions(+) create mode 100644 src/runner/UnitTests/HotkeyConflictTests.cpp create mode 100644 src/runner/UnitTests/UnitTests-Runner.vcxproj create mode 100644 src/runner/UnitTests/UnitTests-Runner.vcxproj.filters create mode 100644 src/runner/UnitTests/pch.cpp create mode 100644 src/runner/UnitTests/pch.h diff --git a/PowerToys.slnx b/PowerToys.slnx index a950316aaf..28b849d64e 100644 --- a/PowerToys.slnx +++ b/PowerToys.slnx @@ -1200,6 +1200,7 @@ + diff --git a/src/runner/UnitTests/HotkeyConflictTests.cpp b/src/runner/UnitTests/HotkeyConflictTests.cpp new file mode 100644 index 0000000000..e34cdca8f5 --- /dev/null +++ b/src/runner/UnitTests/HotkeyConflictTests.cpp @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include "pch.h" +#include "CppUnitTest.h" + +#include "../hotkey_conflict_detector.h" + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace RunnerUnitTests +{ + TEST_CLASS(HotkeyConflictTests) + { + public: + TEST_METHOD_INITIALIZE(ClearHotkeyConflictManagerBeforeTest) + { + ClearTestModules(); + } + + TEST_METHOD_CLEANUP(ClearHotkeyConflictManagerAfterTest) + { + ClearTestModules(); + } + + TEST_METHOD(HasConflict_TwoModulesSameHotkey_InAppConflict) + { + using namespace HotkeyConflictDetector; + + auto& manager = HotkeyConflictManager::GetInstance(); + const Hotkey hotkey{ .win = false, .ctrl = false, .shift = false, .alt = false, .key = 'T' }; + + Assert::IsTrue(manager.AddHotkey(hotkey, L"ModuleA", 1, true)); + Assert::AreEqual(static_cast(InAppConflict), static_cast(manager.HasConflict(hotkey, L"ModuleB", 1))); + } + + private: + static void ClearTestModules() + { + auto& manager = HotkeyConflictDetector::HotkeyConflictManager::GetInstance(); + manager.RemoveHotkeyByModule(L"ModuleA"); + manager.RemoveHotkeyByModule(L"ModuleB"); + } + }; +} diff --git a/src/runner/UnitTests/UnitTests-Runner.vcxproj b/src/runner/UnitTests/UnitTests-Runner.vcxproj new file mode 100644 index 0000000000..74cdc64818 --- /dev/null +++ b/src/runner/UnitTests/UnitTests-Runner.vcxproj @@ -0,0 +1,55 @@ + + + + + {97BDACF8-261D-4E23-A708-A27E0B60E444} + Win32Proj + UnitTestsRunner + NativeUnitTestProject + Runner.UnitTests + 10.0 + + + DynamicLibrary + Unicode + + + + + + + + + + + + $(RepoRoot)$(Platform)\$(Configuration)\tests\Runner\ + + + + ..\;..\..\;..\..\common\inc;..\..\common\os-detection;..\..\common\Telemetry;..\..\modules;$(RepoRoot)packages\Microsoft.Windows.ImplementationLibrary.1.0.260126.7\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;UNIT_TEST;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + 26466;26495;%(DisableSpecificWarnings) + + + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + RuntimeObject.lib;User32.lib;%(AdditionalDependencies) + + + + + Create + + + + + + + + + + diff --git a/src/runner/UnitTests/UnitTests-Runner.vcxproj.filters b/src/runner/UnitTests/UnitTests-Runner.vcxproj.filters new file mode 100644 index 0000000000..bb9b1b7b88 --- /dev/null +++ b/src/runner/UnitTests/UnitTests-Runner.vcxproj.filters @@ -0,0 +1,32 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + diff --git a/src/runner/UnitTests/pch.cpp b/src/runner/UnitTests/pch.cpp new file mode 100644 index 0000000000..64b7eef6d6 --- /dev/null +++ b/src/runner/UnitTests/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/src/runner/UnitTests/pch.h b/src/runner/UnitTests/pch.h new file mode 100644 index 0000000000..83ff3989d5 --- /dev/null +++ b/src/runner/UnitTests/pch.h @@ -0,0 +1,50 @@ +#pragma once + +#ifndef PCH_H +#define PCH_H + +// Mirror the runner's pch.h includes so that when hotkey_conflict_detector.h +// includes the runner's pch.h, all headers are already present (#pragma once). +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#endif // PCH_H