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