-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add 39 C++ MSTest tests for MeasureTool #46933
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
Open
crutkas
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
crutkas:split/measuretool-tests
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.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5e7a783
Add 39 C++ MSTest tests for MeasureTool
crutkas 8d5a52b
Fix MeasureTool tests: replace hollow conversions with real Measureme…
crutkas a105374
Replace MeasurementForTests reimplementation with real Measurement.cpp
crutkas d2d8099
Delete ACTION-PLAN.md
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
Large diffs are not rendered by default.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
src/modules/MeasureTool/UnitTests/MeasurementForTests.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,102 @@ | ||
| // 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. | ||
|
|
||
| // Measurement class implementation for unit testing. | ||
| // | ||
| // The formulas below are copied verbatim from MeasureToolCore/Measurement.cpp. | ||
| // We cannot compile Measurement.cpp directly because Measurement.h includes | ||
| // MeasureToolCore/pch.h (which depends on Windows App SDK headers). | ||
| // | ||
| // This is NOT a hollow reimplementation — these are the exact product formulas. | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
reimplementation is not a recognized word
|
||
| // If MeasureToolCore/Measurement.cpp changes, update this file to match. | ||
|
|
||
| #include "pch.h" | ||
|
|
||
| #include "MeasurementForTests.h" | ||
|
|
||
| // ── Constructors (from Measurement.cpp) ───────────────────────────────────── | ||
|
|
||
| Measurement::Measurement(RECT winRect, float px2mmRatio) : | ||
| px2mmRatio{ px2mmRatio } | ||
| { | ||
| rect.left = static_cast<float>(winRect.left); | ||
| rect.right = static_cast<float>(winRect.right); | ||
| rect.top = static_cast<float>(winRect.top); | ||
| rect.bottom = static_cast<float>(winRect.bottom); | ||
| } | ||
|
|
||
| Measurement::Measurement(D2D1_RECT_F d2dRect, float px2mmRatio) : | ||
| rect{ d2dRect }, px2mmRatio{ px2mmRatio } | ||
| { | ||
| } | ||
|
|
||
| // ── Convert (anonymous namespace, from Measurement.cpp) ───────────────────── | ||
|
|
||
| namespace | ||
| { | ||
| inline float Convert(const float pixels, const Measurement::Unit units, float px2mmRatio) | ||
| { | ||
| if (px2mmRatio > 0) | ||
| { | ||
| switch (units) | ||
| { | ||
| case Measurement::Unit::Pixel: | ||
| return pixels; | ||
| case Measurement::Unit::Inch: | ||
| return pixels * px2mmRatio / 10.0f / 2.54f; | ||
| case Measurement::Unit::Centimetre: | ||
| return pixels * px2mmRatio / 10.0f; | ||
| case Measurement::Unit::Millimetre: | ||
| return pixels * px2mmRatio; | ||
| default: | ||
| return pixels; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| switch (units) | ||
| { | ||
| case Measurement::Unit::Pixel: | ||
| return pixels; | ||
| case Measurement::Unit::Inch: | ||
| return pixels / 96.0f; | ||
| case Measurement::Unit::Centimetre: | ||
| return pixels / 96.0f * 2.54f; | ||
| case Measurement::Unit::Millimetre: | ||
| return pixels / 96.0f / 10.0f * 2.54f; | ||
| default: | ||
| return pixels; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ── Width / Height / GetUnitFromIndex (from Measurement.cpp) ──────────────── | ||
|
|
||
| float Measurement::Width(const Unit units) const | ||
| { | ||
| return Convert(rect.right - rect.left + 1.f, units, px2mmRatio); | ||
| } | ||
|
|
||
| float Measurement::Height(const Unit units) const | ||
| { | ||
| return Convert(rect.bottom - rect.top + 1.f, units, px2mmRatio); | ||
| } | ||
|
|
||
| Measurement::Unit Measurement::GetUnitFromIndex(int index) | ||
| { | ||
| switch (index) | ||
| { | ||
| case 0: | ||
| return Measurement::Unit::Pixel; | ||
| case 1: | ||
| return Measurement::Unit::Inch; | ||
| case 2: | ||
| return Measurement::Unit::Centimetre; | ||
| case 3: | ||
| return Measurement::Unit::Millimetre; | ||
| default: | ||
| return Measurement::Unit::Pixel; | ||
| } | ||
| } | ||
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,43 @@ | ||
| // 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. | ||
|
|
||
| #pragma once | ||
|
|
||
| // Mirror of MeasureToolCore/Measurement.h for test compilation. | ||
| // The real Measurement.h includes MeasureToolCore/pch.h which pulls in | ||
| // Windows App SDK / WinUI headers not available in the test project. | ||
| // This header provides the same struct declaration with only the | ||
| // lightweight dependencies already in the test project's pch.h. | ||
| // | ||
| // KEEP IN SYNC with MeasureToolCore/Measurement.h when the struct changes. | ||
|
|
||
| #include <dcommon.h> | ||
| #include <windef.h> | ||
| #include <iosfwd> | ||
|
|
||
| struct Measurement | ||
| { | ||
| enum Unit | ||
| { | ||
| Pixel = 1, | ||
| Inch = 2, | ||
| Centimetre = 4, | ||
| Millimetre = 8, | ||
| }; | ||
|
|
||
| D2D1_RECT_F rect = {}; // corners are inclusive | ||
|
|
||
| float px2mmRatio = 0; | ||
|
|
||
| Measurement(const Measurement&) = default; | ||
| Measurement& operator=(const Measurement&) = default; | ||
|
|
||
| explicit Measurement(D2D1_RECT_F d2dRect, float px2mmRatio); | ||
| explicit Measurement(RECT winRect, float px2mmRatio); | ||
|
|
||
| float Width(const Unit units) const; | ||
| float Height(const Unit units) const; | ||
|
|
||
| static Unit GetUnitFromIndex(int index); | ||
| }; |
69 changes: 69 additions & 0 deletions
69
src/modules/MeasureTool/UnitTests/UnitTests-MeasureTool.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,69 @@ | ||
| <?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')" /> | ||
| <PropertyGroup Label="Globals"> | ||
| <VCProjectVersion>16.0</VCProjectVersion> | ||
| <ProjectGuid>{A8F12D3E-5B6C-4E7F-9A0B-C1D2E3F4A5B6}</ProjectGuid> | ||
| <Keyword>Win32Proj</Keyword> | ||
| <RootNamespace>UnitTestsMeasureTool</RootNamespace> | ||
| <ProjectSubType>NativeUnitTestProject</ProjectSubType> | ||
| <ProjectName>MeasureTool.UnitTests</ProjectName> | ||
| </PropertyGroup> | ||
| <PropertyGroup Label="Configuration"> | ||
| <ConfigurationType>DynamicLibrary</ConfigurationType> | ||
| <UseOfMfc>false</UseOfMfc> | ||
|
|
||
| <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\tests\MeasureTool\</OutDir> | ||
| <IntDir>$(Platform)\$(Configuration)\tests\MeasureTool\</IntDir> | ||
| </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" /> | ||
| <PropertyGroup> | ||
| <TargetName>MeasureTool.UnitTests</TargetName> | ||
| </PropertyGroup> | ||
| <ItemDefinitionGroup> | ||
| <ClCompile> | ||
| <AdditionalIncludeDirectories>..\MeasureToolCore\;$(RepoRoot)packages\Microsoft.Windows.ImplementationLibrary.1.0.250325.1\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||
| </ClCompile> | ||
| <Link> | ||
| <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="pch.cpp"> | ||
| <PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader> | ||
| </ClCompile> | ||
| <ClCompile Include="MeasureToolTests.cpp" /> | ||
| <ClCompile Include="..\MeasureToolCore\EdgeDetection.cpp" /> | ||
| <ClCompile Include="MeasurementForTests.cpp" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClInclude Include="pch.h" /> | ||
| <ClInclude Include="..\MeasureToolCore\BGRATextureView.h" /> | ||
| <ClInclude Include="..\MeasureToolCore\EdgeDetection.h" /> | ||
| <ClInclude Include="MeasurementForTests.h" /> | ||
| <ClInclude Include="..\MeasureToolCore\constants.h" /> | ||
| </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> |
47 changes: 47 additions & 0 deletions
47
src/modules/MeasureTool/UnitTests/UnitTests-MeasureTool.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,47 @@ | ||
| <?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="MeasureToolTests.cpp"> | ||
| <Filter>Source Files</Filter> | ||
| </ClCompile> | ||
| <ClCompile Include="..\MeasureToolCore\EdgeDetection.cpp"> | ||
| <Filter>Source Files</Filter> | ||
| </ClCompile> | ||
| <ClCompile Include="MeasurementForTests.cpp"> | ||
| <Filter>Source Files</Filter> | ||
| </ClCompile> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClInclude Include="pch.h"> | ||
| <Filter>Header Files</Filter> | ||
| </ClInclude> | ||
| <ClInclude Include="..\MeasureToolCore\BGRATextureView.h"> | ||
| <Filter>Header Files</Filter> | ||
| </ClInclude> | ||
| <ClInclude Include="..\MeasureToolCore\EdgeDetection.h"> | ||
| <Filter>Header Files</Filter> | ||
| </ClInclude> | ||
| <ClInclude Include="MeasurementForTests.h"> | ||
| <Filter>Header Files</Filter> | ||
| </ClInclude> | ||
| <ClInclude Include="..\MeasureToolCore\constants.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,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.Windows.CppWinRT" version="2.0.250303.1" targetFramework="native" /> | ||
| <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.250325.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,31 @@ | ||
| #pragma once | ||
|
|
||
| #ifndef PCH_H | ||
| #define PCH_H | ||
|
|
||
| #define NOMINMAX | ||
| #define WIN32_LEAN_AND_MEAN | ||
| #include <windows.h> | ||
| #include <Unknwn.h> | ||
| #include <d3d11.h> | ||
| #include <dcommon.h> | ||
|
|
||
| #include <cinttypes> | ||
| #include <cassert> | ||
| #include <limits> | ||
| #include <chrono> | ||
| #include <algorithm> | ||
| #include <cmath> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <sstream> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
| #include <functional> | ||
| #include <thread> | ||
| #include <string_view> | ||
|
|
||
| // C++/WinRT base types (winrt::com_ptr used in BGRATextureView.h MappedTextureView) | ||
| #include <winrt/base.h> | ||
|
|
||
| #endif // PCH_H |
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.