mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
FancyZones and Shortcut Guide initial commit
Co-authored-by: Alexis Campailla <alexis@janeasystems.com> Co-authored-by: Bret Anderson <bretan@microsoft.com> Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Jeff Bogdan <jeffbog@microsoft.com> Co-authored-by: March Rogers <marchr@microsoft.com> Co-authored-by: Mike Harsh <mharsh@microsoft.com> Co-authored-by: Nachum Bundak <Nachum.Bundak@microsoft.com> Co-authored-by: Oliver Jones <ojones@microsoft.com> Co-authored-by: Patrick Little <plittle@microsoft.com>
This commit is contained in:
committed by
Bartosz Sosnowski
parent
10c5396099
commit
8431b80e48
@@ -0,0 +1,36 @@
|
||||
#include "pch.h"
|
||||
#include "lib\RegistryHelpers.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(RegistryHelpersUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(GetDefaultKey)
|
||||
{
|
||||
// Test the path to the key is the same string.
|
||||
wchar_t key[256];
|
||||
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(nullptr, key, ARRAYSIZE(key)), L"Software\\SuperFancyZones"));
|
||||
}
|
||||
|
||||
TEST_METHOD(GetKeyWithMonitor)
|
||||
{
|
||||
// Test the path to the key is the same string.
|
||||
wchar_t key[256];
|
||||
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(L"Monitor1", key, ARRAYSIZE(key)), L"Software\\SuperFancyZones\\Monitor1"));
|
||||
}
|
||||
|
||||
TEST_METHOD(OpenKey)
|
||||
{
|
||||
// The default key should exist.
|
||||
wil::unique_hkey key{ RegistryHelpers::OpenKey({}) };
|
||||
Assert::IsNotNull(key.get());
|
||||
|
||||
// The Monitor1 key shouldn't exist.
|
||||
wil::unique_hkey key2{ RegistryHelpers::OpenKey(L"Monitor1") };
|
||||
Assert::IsNull(key2.get());
|
||||
}
|
||||
};
|
||||
}
|
||||
131
src/modules/fancyzones/tests/UnitTests/UnitTests.vcxproj
Normal file
131
src/modules/fancyzones/tests/UnitTests/UnitTests.vcxproj
Normal file
@@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{9C6A7905-72D4-4BF5-B256-ABFDAEF68AE9}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>UnitTests</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectSubType>NativeUnitTestProject</ProjectSubType>
|
||||
<ProjectName>UnitTests-FancyZones</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\..\..\common\Telemetry;..\..\..\..\;..\..\..\..\deps\cpprestsdk\include;..\..\;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>gdiplus.lib;dwmapi.lib;shlwapi.lib;uxtheme.lib;shcore.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\..\..\common\Telemetry;..\..\..\..\;..\..\..\..\deps\cpprestsdk\include;..\..\;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>gdiplus.lib;dwmapi.lib;shlwapi.lib;uxtheme.lib;shcore.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RegistryHelpers.Spec.cpp" />
|
||||
<ClCompile Include="Util.Spec.cpp" />
|
||||
<ClCompile Include="Zone.Spec.cpp" />
|
||||
<ClCompile Include="ZoneSet.Spec.cpp" />
|
||||
<ClCompile Include="ZoneWindow.Spec.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="Util.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\lib\FancyZonesLib.vcxproj">
|
||||
<Project>{f9c68edf-ac74-4b77-9af1-005d9c9f6a99}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.190716.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.190716.2\build\native\Microsoft.Windows.ImplementationLibrary.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('..\..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.190716.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.190716.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZoneSet.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Zone.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RegistryHelpers.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Util.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZoneWindow.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Util.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
33
src/modules/fancyzones/tests/UnitTests/Util.Spec.cpp
Normal file
33
src/modules/fancyzones/tests/UnitTests/Util.Spec.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "pch.h"
|
||||
#include "lib\util.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(UtilUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestParseDeviceId)
|
||||
{
|
||||
// We're interested in the unique part between the first and last #'s
|
||||
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
|
||||
// Example output: DELA026#5&10a58c63&0&UID16777488
|
||||
PCWSTR input = L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}";
|
||||
wchar_t output[256]{};
|
||||
ParseDeviceId(input, output, ARRAYSIZE(output));
|
||||
Assert::AreEqual(0, wcscmp(output, L"DELA026#5&10a58c63&0&UID16777488"));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestParseInvalidDeviceId)
|
||||
{
|
||||
// We're interested in the unique part between the first and last #'s
|
||||
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
|
||||
// Example output: DELA026#5&10a58c63&0&UID16777488
|
||||
PCWSTR input = L"AnInvalidDeviceId";
|
||||
wchar_t output[256]{};
|
||||
ParseDeviceId(input, output, ARRAYSIZE(output));
|
||||
Assert::AreEqual(0, wcscmp(output, L"FallbackDevice"));
|
||||
}
|
||||
};
|
||||
}
|
||||
42
src/modules/fancyzones/tests/UnitTests/Util.h
Normal file
42
src/modules/fancyzones/tests/UnitTests/Util.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
namespace CustomAssert
|
||||
{
|
||||
static void AreEqual(const RECT& r1, const RECT& r2)
|
||||
{
|
||||
const bool equal = ((r1.left == r2.left) && (r1.right == r2.right) && (r1.top == r2.top) && (r1.bottom == r2.bottom));
|
||||
Microsoft::VisualStudio::CppUnitTestFramework::Assert::IsTrue(equal);
|
||||
}
|
||||
|
||||
static void AreEqual(GUID g1, GUID g2)
|
||||
{
|
||||
Microsoft::VisualStudio::CppUnitTestFramework::Assert::IsTrue(g1 == g2);
|
||||
}
|
||||
|
||||
static void AreEqual(WORD w1, WORD w2)
|
||||
{
|
||||
Microsoft::VisualStudio::CppUnitTestFramework::Assert::IsTrue(w1 == w2);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Mocks
|
||||
{
|
||||
static HWND Window()
|
||||
{
|
||||
static UINT_PTR s_nextWindow = 0;
|
||||
return reinterpret_cast<HWND>(++s_nextWindow);
|
||||
}
|
||||
|
||||
static HMONITOR Monitor()
|
||||
{
|
||||
static UINT_PTR s_nextMonitor = 0;
|
||||
return reinterpret_cast<HMONITOR>(++s_nextMonitor);
|
||||
}
|
||||
|
||||
static HINSTANCE Instance()
|
||||
{
|
||||
static UINT_PTR s_nextInstance = 0;
|
||||
return reinterpret_cast<HINSTANCE>(++s_nextInstance);
|
||||
}
|
||||
|
||||
}
|
||||
54
src/modules/fancyzones/tests/UnitTests/Zone.Spec.cpp
Normal file
54
src/modules/fancyzones/tests/UnitTests/Zone.Spec.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "pch.h"
|
||||
#include "lib\Zone.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(ZoneUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestCreateZone)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
Assert::IsNotNull(&zone);
|
||||
CustomAssert::AreEqual(zoneRect, zone->GetZoneRect());
|
||||
|
||||
constexpr size_t id = 10;
|
||||
zone->SetId(id);
|
||||
Assert::AreEqual(zone->Id(), id);
|
||||
}
|
||||
|
||||
TEST_METHOD(ContainsWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddRemoveWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
zone->AddWindowToZone(newWindow, Mocks::Window(), true);
|
||||
Assert::IsTrue(zone->ContainsWindow(newWindow));
|
||||
|
||||
zone->RemoveWindowFromZone(newWindow, false);
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestRemoveInvalidWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
zone->RemoveWindowFromZone(newWindow, false);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
336
src/modules/fancyzones/tests/UnitTests/ZoneSet.Spec.cpp
Normal file
336
src/modules/fancyzones/tests/UnitTests/ZoneSet.Spec.cpp
Normal file
@@ -0,0 +1,336 @@
|
||||
#include "pch.h"
|
||||
#include "lib\ZoneSet.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(ZoneSetUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneSet)
|
||||
{
|
||||
GUID zoneSetId{};
|
||||
CoCreateGuid(&zoneSetId);
|
||||
constexpr size_t zoneCount = 0;
|
||||
constexpr WORD layoutId = 0xFFFF;
|
||||
constexpr int outerPadding = 3;
|
||||
constexpr int innerPadding = 4;
|
||||
|
||||
ZoneSetConfig config(zoneSetId, layoutId, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, zoneCount, outerPadding, innerPadding);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
Assert::IsNotNull(&set);
|
||||
CustomAssert::AreEqual(set->Id(), zoneSetId);
|
||||
CustomAssert::AreEqual(set->LayoutId(), layoutId);
|
||||
Assert::IsTrue(set->GetLayout() == ZoneSetLayout::Grid);
|
||||
Assert::AreEqual(set->GetZones().size(), zoneCount);
|
||||
Assert::AreEqual(set->GetInnerPadding(), innerPadding);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a zone
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone, false /*front*/);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 1);
|
||||
Assert::IsTrue(zones[0] == zone);
|
||||
Assert::IsTrue(zone->Id() == 1);
|
||||
}
|
||||
|
||||
// Add a second zone at the back.
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone, false /*front*/);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 2);
|
||||
Assert::IsTrue(zones[1] == zone);
|
||||
Assert::IsTrue(zone->Id() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddZoneFront)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a zone.
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone, false /*front*/);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 1);
|
||||
Assert::IsTrue(zones[0] == zone);
|
||||
Assert::IsTrue(zone->Id() == 1);
|
||||
}
|
||||
|
||||
// Add a second zone at the front.
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone, true /*front*/);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 2);
|
||||
Assert::IsTrue(zones[0] == zone);
|
||||
Assert::IsTrue(zone->Id() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(TestRemoveZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a zone.
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone, false /*front*/);
|
||||
|
||||
// And remove it.
|
||||
set->RemoveZone(zone);
|
||||
Assert::IsTrue(set->GetZones().size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestRemoveInvalidZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
Assert::AreEqual(set->RemoveZone(zone), E_INVALIDARG);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveZoneToFront)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1, false /*front*/);
|
||||
set->AddZone(zone2, false /*front*/);
|
||||
set->AddZone(zone3, false /*front*/);
|
||||
|
||||
// And move it to the back.
|
||||
set->MoveZoneToFront(zone3);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 3);
|
||||
Assert::IsTrue(zones[0] == zone3);
|
||||
Assert::IsTrue(zones[1] == zone1);
|
||||
Assert::IsTrue(zones[2] == zone2);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveZoneToFrontWithInvalidZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1, false /*front*/);
|
||||
set->AddZone(zone2, false /*front*/);
|
||||
set->AddZone(zone3, false /*front*/);
|
||||
|
||||
// Create an invalid zone and try to move it.
|
||||
winrt::com_ptr<IZone> invalidZone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->MoveZoneToFront(invalidZone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 3);
|
||||
Assert::IsTrue(zones[0] == zone1);
|
||||
Assert::IsTrue(zones[1] == zone2);
|
||||
Assert::IsTrue(zones[2] == zone3);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveZoneToBack)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1, false /*front*/);
|
||||
set->AddZone(zone2, false /*front*/);
|
||||
set->AddZone(zone3, false /*front*/);
|
||||
|
||||
// And move it to the back.
|
||||
set->MoveZoneToBack(zone1);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 3);
|
||||
Assert::IsTrue(zones[0] == zone2);
|
||||
Assert::IsTrue(zones[1] == zone3);
|
||||
Assert::IsTrue(zones[2] == zone1);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveZoneToBackWithInvalidZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1, false /*front*/);
|
||||
set->AddZone(zone2, false /*front*/);
|
||||
set->AddZone(zone3, false /*front*/);
|
||||
|
||||
// Create an invalid zone and try to move it.
|
||||
winrt::com_ptr<IZone> invalidZone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->MoveZoneToBack(invalidZone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 3);
|
||||
Assert::IsTrue(zones[0] == zone1);
|
||||
Assert::IsTrue(zones[1] == zone2);
|
||||
Assert::IsTrue(zones[2] == zone3);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1, false /*front*/);
|
||||
set->AddZone(zone2, false /*front*/);
|
||||
set->AddZone(zone3, false /*front*/);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 1);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithNoZones)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithInvalidIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1, false /*front*/);
|
||||
set->AddZone(zone2, false /*front*/);
|
||||
set->AddZone(zone3, false /*front*/);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 100);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
};
|
||||
|
||||
// MoveWindowIntoZoneByDirection is complicated enough to warrant it's own test class
|
||||
TEST_CLASS(MoveWindowIntoZoneByDirectionUnitTests)
|
||||
{
|
||||
winrt::com_ptr<IZoneSet> set;
|
||||
winrt::com_ptr<IZone> zone1;
|
||||
winrt::com_ptr<IZone> zone2;
|
||||
winrt::com_ptr<IZone> zone3;
|
||||
|
||||
TEST_METHOD_INITIALIZE(Initialize)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn", ZoneSetLayout::Grid, 0, 3, 4);
|
||||
set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1, false /*front*/);
|
||||
set->AddZone(zone2, false /*front*/);
|
||||
set->AddZone(zone3, false /*front*/);
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRightNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeftNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
};
|
||||
}
|
||||
45
src/modules/fancyzones/tests/UnitTests/ZoneWindow.Spec.cpp
Normal file
45
src/modules/fancyzones/tests/UnitTests/ZoneWindow.Spec.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "pch.h"
|
||||
#include "lib\ZoneSet.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(ZoneWindowUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneWindow)
|
||||
{
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), Mocks::Monitor(), L"DeviceId", L"MyVirtualDesktopId", false);
|
||||
Assert::IsNotNull(zoneWindow.get());
|
||||
}
|
||||
|
||||
TEST_METHOD(TestDeviceId)
|
||||
{
|
||||
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, L"SomeRandomValue", L"MyVirtualDesktopId", false);
|
||||
// We have no way to test the correctness, just do our best and check its not an empty string.
|
||||
Assert::IsTrue(zoneWindow->DeviceId().size() > 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestUniqueId)
|
||||
{
|
||||
// Unique id of the format "ParsedMonitorDeviceId_MonitorWidth_MonitorHeight_VirtualDesktopId
|
||||
// Example: "DELA026#5&10a58c63&0&UID16777488_1024_768_MyVirtualDesktopId"
|
||||
std::wstring deviceId(L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}");
|
||||
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
MONITORINFO info;
|
||||
info.cbSize = sizeof(info);
|
||||
Assert::IsTrue(GetMonitorInfo(pimaryMonitor, &info));
|
||||
|
||||
Rect monitorRect = Rect(info.rcMonitor);
|
||||
std::wstringstream ss;
|
||||
ss << L"DELA026#5&10a58c63&0&UID16777488_" << monitorRect.width() << "_" << monitorRect.height() << "_MyVirtualDesktopId";
|
||||
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, deviceId.c_str(), L"MyVirtualDesktopId", false);
|
||||
Assert::AreEqual(zoneWindow->UniqueId().compare(ss.str()), 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
4
src/modules/fancyzones/tests/UnitTests/packages.config
Normal file
4
src/modules/fancyzones/tests/UnitTests/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.190716.2" targetFramework="native" />
|
||||
</packages>
|
||||
5
src/modules/fancyzones/tests/UnitTests/pch.cpp
Normal file
5
src/modules/fancyzones/tests/UnitTests/pch.cpp
Normal file
@@ -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.
|
||||
18
src/modules/fancyzones/tests/UnitTests/pch.h
Normal file
18
src/modules/fancyzones/tests/UnitTests/pch.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// pch.h: This is a precompiled header file.
|
||||
// Files listed below are compiled only once, improving build performance for future builds.
|
||||
// This also affects IntelliSense performance, including code completion and many code browsing features.
|
||||
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
|
||||
// Do not add files here that you will be updating frequently as this negates the performance advantage.
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
// add headers that you want to pre-compile here
|
||||
#include <Windows.h>
|
||||
#include <winrt\base.h>
|
||||
|
||||
#include "lib\pch.h"
|
||||
#include "CppUnitTest.h"
|
||||
#include "Util.h"
|
||||
|
||||
#endif //PCH_H
|
||||
Reference in New Issue
Block a user