-
Notifications
You must be signed in to change notification settings - Fork 7.9k
(Broken up) - Add 340 C++ MSTest tests across 10 modules #46905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
crutkas
wants to merge
11
commits into
microsoft:main
Choose a base branch
from
crutkas:rust-port-tests-cherry-pick
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
201165c
Add 155 new C++ MSTest tests + spelling fixes
crutkas 84f5c2a
Add vcxproj test projects for 4 C++ test suites
crutkas 21f934f
Add new words to spell-check expectations
crutkas 03d97bf
Address PR #46905 review comments
crutkas 8fac3cb
Address remaining PR #46905 review comments (round 2)
crutkas a3880bf
Fix build: Replace Assert::Inconclusive with Logger::WriteMessage
crutkas d5ea431
Address remaining PR #46905 review comments (round 3)
crutkas c73deba
Add 124 C++ MSTest tests for LightSwitch, PowerAccent, FileLocksmith
crutkas d2d5e89
Update expect.txt
crutkas c54932f
Add 63 C++ MSTest tests: MeasureTool, FindMyMouse, PowerAccent OSK fix
crutkas bc9870e
Remove 'AAAAs' from spell-check expectations
crutkas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2341,3 +2341,8 @@ YTimer | |
| zamora | ||
| zonability | ||
| Zorder | ||
| aaaa | ||
| hpa | ||
| LOCALDISPLAY | ||
| LShaped | ||
| normalises | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
367 changes: 367 additions & 0 deletions
367
src/modules/MouseUtils/CursorWrap/UnitTests/TopologyTests.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
src/modules/MouseUtils/CursorWrap/UnitTests/UnitTests-CursorWrap.vcxproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
| <Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" /> | ||
| <Import Project="$(RepoRoot)deps\spdlog.props" /> | ||
| <PropertyGroup Label="Globals"> | ||
| <VCProjectVersion>16.0</VCProjectVersion> | ||
| <ProjectGuid>{C1F0FE89-A695-472E-9DF5-F793B88EE220}</ProjectGuid> | ||
| <Keyword>Win32Proj</Keyword> | ||
| <RootNamespace>UnitTestsCursorWrap</RootNamespace> | ||
| <ProjectSubType>NativeUnitTestProject</ProjectSubType> | ||
| <ProjectName>CursorWrap.UnitTests</ProjectName> | ||
| </PropertyGroup> | ||
| <PropertyGroup Label="Configuration"> | ||
| <ConfigurationType>DynamicLibrary</ConfigurationType> | ||
| <UseOfMfc>false</UseOfMfc> | ||
|
|
||
| <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\tests\UnitTestsCursorWrap\</OutDir> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
| <ImportGroup Label="ExtensionSettings"> | ||
| </ImportGroup> | ||
| <ImportGroup Label="Shared"> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <PropertyGroup Label="UserMacros" /> | ||
| <ItemDefinitionGroup> | ||
| <ClCompile> | ||
| <AdditionalIncludeDirectories>..\;..\..\..\..\;..\..\..\..\common\Telemetry;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||
| </ClCompile> | ||
| <Link> | ||
| <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
| <AdditionalDependencies>RuntimeObject.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="pch.cpp"> | ||
| <PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader> | ||
| </ClCompile> | ||
| <ClCompile Include="TopologyTests.cpp" /> | ||
| <ClCompile Include="..\MonitorTopology.cpp" /> | ||
| <ClCompile Include="..\CursorWrapCore.cpp" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClInclude Include="pch.h" /> | ||
| <ClInclude Include="..\MonitorTopology.h" /> | ||
| <ClInclude Include="..\CursorWrapCore.h" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(RepoRoot)src\common\logger\logger.vcxproj"> | ||
| <Project>{d9b8fc84-322a-4f9f-bbb9-20915c47ddfd}</Project> | ||
| </ProjectReference> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="packages.config" /> | ||
| </ItemGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
| <ImportGroup Label="ExtensionTargets"> | ||
| <Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets')" /> | ||
| </ImportGroup> | ||
| <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
| <PropertyGroup> | ||
| <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
| </PropertyGroup> | ||
| <Error Condition="!Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props'))" /> | ||
| <Error Condition="!Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets'))" /> | ||
| </Target> | ||
| </Project> |
41 changes: 41 additions & 0 deletions
41
src/modules/MouseUtils/CursorWrap/UnitTests/UnitTests-CursorWrap.vcxproj.filters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup> | ||
| <Filter Include="Source Files"> | ||
| <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
| <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
| </Filter> | ||
| <Filter Include="Header Files"> | ||
| <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
| <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> | ||
| </Filter> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="pch.cpp"> | ||
| <Filter>Source Files</Filter> | ||
| </ClCompile> | ||
| <ClCompile Include="TopologyTests.cpp"> | ||
| <Filter>Source Files</Filter> | ||
| </ClCompile> | ||
| <ClCompile Include="..\MonitorTopology.cpp"> | ||
| <Filter>Source Files</Filter> | ||
| </ClCompile> | ||
| <ClCompile Include="..\CursorWrapCore.cpp"> | ||
| <Filter>Source Files</Filter> | ||
| </ClCompile> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClInclude Include="pch.h"> | ||
| <Filter>Header Files</Filter> | ||
| </ClInclude> | ||
| <ClInclude Include="..\MonitorTopology.h"> | ||
| <Filter>Header Files</Filter> | ||
| </ClInclude> | ||
| <ClInclude Include="..\CursorWrapCore.h"> | ||
| <Filter>Header Files</Filter> | ||
| </ClInclude> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="packages.config" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Windows.CppWinRT" version="2.0.250303.1" targetFramework="native" /> | ||
| </packages> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #pragma once | ||
|
|
||
| #ifndef PCH_H | ||
| #define PCH_H | ||
|
|
||
| #define WIN32_LEAN_AND_MEAN | ||
| #include <windows.h> | ||
|
|
||
| #include <atomic> | ||
| #include <thread> | ||
| #include <vector> | ||
| #include <map> | ||
| #include <string> | ||
| #include <sstream> | ||
| #include <iomanip> | ||
| #include <ctime> | ||
| #include <algorithm> | ||
| #include <cmath> | ||
|
|
||
| #endif // PCH_H |
181 changes: 181 additions & 0 deletions
181
src/modules/MouseUtils/MouseHighlighter/UnitTests/HighlighterTests.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| // 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. | ||
|
|
||
| // Unit tests for MouseHighlighter lifecycle logic, mirroring the Rust test suite | ||
| // in src/rust/libs/highlighter-core/src/highlight_manager.rs. | ||
| // | ||
| // The C++ implementation drives highlights through Windows Composition APIs, | ||
| // but the settings and colour/fade constants are testable without a window. | ||
| // These tests verify defaults, fade timing arithmetic, and the alpha==0 | ||
| // disabled behavior at the configuration level. | ||
|
|
||
| #include "pch.h" | ||
|
|
||
| #pragma warning(push) | ||
| #pragma warning(disable : 26466) | ||
| #include "CppUnitTest.h" | ||
| #pragma warning(pop) | ||
|
|
||
| #include "../MouseHighlighter.h" | ||
|
|
||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||
|
|
||
| namespace MouseHighlighterUnitTests | ||
| { | ||
| TEST_CLASS(HighlighterTests) | ||
| { | ||
| public: | ||
| // ── Default settings ──────────────────────────────────────────── | ||
|
|
||
| // Left-click highlight should be semi-transparent yellow (a=166, r=255, g=255, b=0). | ||
| TEST_METHOD(LeftClick_DefaultColor_IsYellow) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| auto c = settings.leftButtonColor; | ||
| Assert::AreEqual(static_cast<uint8_t>(166), c.A, L"Alpha should be 166"); | ||
| Assert::AreEqual(static_cast<uint8_t>(255), c.R, L"Red should be 255"); | ||
| Assert::AreEqual(static_cast<uint8_t>(255), c.G, L"Green should be 255"); | ||
| Assert::AreEqual(static_cast<uint8_t>(0), c.B, L"Blue should be 0"); | ||
| } | ||
|
|
||
| // Right-click highlight should be semi-transparent blue (a=166, r=0, g=0, b=255). | ||
| TEST_METHOD(RightClick_DefaultColor_IsBlue) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| auto c = settings.rightButtonColor; | ||
| Assert::AreEqual(static_cast<uint8_t>(166), c.A); | ||
| Assert::AreEqual(static_cast<uint8_t>(0), c.R); | ||
| Assert::AreEqual(static_cast<uint8_t>(0), c.G); | ||
| Assert::AreEqual(static_cast<uint8_t>(255), c.B); | ||
| } | ||
|
|
||
| // ── Fade timing constants ─────────────────────────────────────── | ||
|
|
||
| // The fade delay should default to 500ms. | ||
| TEST_METHOD(FadeDelay_Default_Is500ms) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| Assert::AreEqual(MOUSE_HIGHLIGHTER_DEFAULT_DELAY_MS, settings.fadeDelayMs); | ||
| Assert::AreEqual(500, settings.fadeDelayMs); | ||
| } | ||
|
|
||
| // The fade duration should default to 250ms. | ||
| TEST_METHOD(FadeDuration_Default_Is250ms) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| Assert::AreEqual(MOUSE_HIGHLIGHTER_DEFAULT_DURATION_MS, settings.fadeDurationMs); | ||
| Assert::AreEqual(250, settings.fadeDurationMs); | ||
| } | ||
|
|
||
| // Verify the full fade lifecycle timing: | ||
| // Press → Release → (delay)500ms → (duration)250ms → fully transparent. | ||
| // A highlight released at t=0 should be fully opaque at t=499, | ||
| // mid-fade at t=625, and gone at t=750. | ||
| TEST_METHOD(FadeDelay_HoldsOpacity) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| // 500ms delay means highlight stays at full opacity for 500ms | ||
| // after release before starting to fade. | ||
| int totalVisibleMs = settings.fadeDelayMs + settings.fadeDurationMs; | ||
| Assert::AreEqual(750, totalVisibleMs, | ||
| L"Total visible time should be delay + duration = 750ms"); | ||
| } | ||
|
|
||
| TEST_METHOD(FadeDuration_ReducesToZero) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| // At the end of delay + duration the opacity should be 0. | ||
| // Opacity formula (from Rust): | ||
| // elapsed = now - fade_started_at | ||
| // if elapsed < delay: 1.0 | ||
| // else: 1.0 - (elapsed - delay) / duration | ||
| // clamped to [0.0, 1.0] | ||
| // At elapsed == delay + duration: 1.0 - duration/duration = 0.0 | ||
| int elapsed = settings.fadeDelayMs + settings.fadeDurationMs; | ||
| double opacity = 1.0 - (static_cast<double>(elapsed) - static_cast<double>(settings.fadeDelayMs)) / static_cast<double>(settings.fadeDurationMs); | ||
| Assert::AreEqual(0.0, opacity, 1e-10, | ||
| L"Opacity should be 0.0 at delay+duration"); | ||
| } | ||
|
|
||
| // ── Alpha=0 disables button highlight ─────────────────────────── | ||
|
|
||
| // If the alpha channel of the always-colour is 0 (default), that | ||
| // highlight source is disabled. | ||
| TEST_METHOD(AlphaZero_DisablesAlwaysHighlight) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| Assert::AreEqual(static_cast<uint8_t>(0), settings.alwaysColor.A, | ||
| L"Default always-colour alpha should be 0 (disabled)"); | ||
| } | ||
|
|
||
| // A custom left-button colour with alpha=0 should be considered disabled. | ||
| TEST_METHOD(AlphaZero_DisablesLeftButton) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| settings.leftButtonColor = winrt::Windows::UI::ColorHelper::FromArgb(0, 255, 255, 0); | ||
| Assert::AreEqual(static_cast<uint8_t>(0), settings.leftButtonColor.A, | ||
| L"Alpha=0 should disable this button's highlight"); | ||
| } | ||
|
|
||
| // A custom right-button colour with alpha=0 should be considered disabled. | ||
| TEST_METHOD(AlphaZero_DisablesRightButton) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| settings.rightButtonColor = winrt::Windows::UI::ColorHelper::FromArgb(0, 0, 0, 255); | ||
| Assert::AreEqual(static_cast<uint8_t>(0), settings.rightButtonColor.A, | ||
| L"Alpha=0 should disable right button highlight"); | ||
| } | ||
|
|
||
| // ── Multiple-click highlight arithmetic ───────────────────────── | ||
|
|
||
| // Each click should create an independent highlight. We test the | ||
| // settings don't restrict the number of concurrent highlights. | ||
| TEST_METHOD(MultipleClicks_SettingsAllowMultiple) | ||
| { | ||
| // The implementation uses a per-click visual; there is no cap | ||
| // in MouseHighlighterSettings. Verify by constructing settings | ||
| // and checking radius > 0 (i.e., highlights are visible). | ||
| MouseHighlighterSettings settings; | ||
| Assert::IsTrue(settings.radius > 0, | ||
| L"Radius should be positive to allow visible highlights"); | ||
| } | ||
|
|
||
| // ── Cleanup: expired highlights ───────────────────────────────── | ||
|
|
||
| // After the fade is complete (delay + duration), the highlight should | ||
| // be removed. We test the arithmetic that determines expiry. | ||
| TEST_METHOD(Cleanup_ExpirationArithmetic) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| int fadeStartMs = 1000; | ||
| int nowMs = fadeStartMs + settings.fadeDelayMs + settings.fadeDurationMs + 1; | ||
|
|
||
| // Elapsed since fade started. | ||
| int elapsed = nowMs - fadeStartMs; | ||
| bool expired = elapsed > (settings.fadeDelayMs + settings.fadeDurationMs); | ||
| Assert::IsTrue(expired, | ||
| L"Highlight should be expired after delay + duration"); | ||
| } | ||
|
|
||
| // ── Default values ────────────────────────────────────────────── | ||
|
|
||
| TEST_METHOD(DefaultRadius_Is20) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| Assert::AreEqual(20, settings.radius); | ||
| } | ||
|
|
||
| TEST_METHOD(DefaultAutoActivate_IsFalse) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| Assert::IsFalse(settings.autoActivate); | ||
| } | ||
|
|
||
| TEST_METHOD(DefaultSpotlightMode_IsFalse) | ||
| { | ||
| MouseHighlighterSettings settings; | ||
| Assert::IsFalse(settings.spotlightMode); | ||
| } | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.