mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[FancyZones] Improve code quality (part 6) (#28034)
This commit is contained in:
@@ -207,22 +207,22 @@ namespace FancyZonesUnitTests
|
||||
|
||||
TEST_METHOD (AppLastZoneInvalidWindow)
|
||||
{
|
||||
const std::wstring zoneSetId = L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}";
|
||||
const auto layoutId = FancyZonesUtils::GuidFromString(L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaId{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
};
|
||||
const auto window = Mocks::Window();
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, zoneSetId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, layoutId));
|
||||
|
||||
const int expectedZoneIndex = 1;
|
||||
Assert::IsFalse(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, zoneSetId, { expectedZoneIndex }));
|
||||
Assert::IsFalse(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, layoutId, { expectedZoneIndex }));
|
||||
}
|
||||
|
||||
TEST_METHOD (AppLastZoneNullWindow)
|
||||
{
|
||||
const std::wstring zoneSetId = L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}";
|
||||
const auto layoutId = FancyZonesUtils::GuidFromString(L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaId{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
@@ -230,12 +230,12 @@ namespace FancyZonesUnitTests
|
||||
const auto window = nullptr;
|
||||
|
||||
const int expectedZoneIndex = 1;
|
||||
Assert::IsFalse(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, zoneSetId, { expectedZoneIndex }));
|
||||
Assert::IsFalse(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, layoutId, { expectedZoneIndex }));
|
||||
}
|
||||
|
||||
TEST_METHOD (AppLastdeviceIdTest)
|
||||
{
|
||||
const std::wstring zoneSetId = L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}";
|
||||
const auto layoutId = FancyZonesUtils::GuidFromString(L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaId1{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
@@ -247,15 +247,15 @@ namespace FancyZonesUnitTests
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
const int expectedZoneIndex = 10;
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaId1, zoneSetId, { expectedZoneIndex }));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ expectedZoneIndex } == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId1, zoneSetId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId2, zoneSetId));
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaId1, layoutId, { expectedZoneIndex }));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ expectedZoneIndex } == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId1, layoutId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId2, layoutId));
|
||||
}
|
||||
|
||||
TEST_METHOD (AppLastZoneSetIdTest)
|
||||
{
|
||||
const std::wstring zoneSetId1 = L"{B7A1F5A9-9DC2-4505-84AB-993253839093}";
|
||||
const std::wstring zoneSetId2 = L"{B7A1F5A9-9DC2-4505-84AB-993253839094}";
|
||||
const auto layoutId1 = FancyZonesUtils::GuidFromString(L"{B7A1F5A9-9DC2-4505-84AB-993253839093}").value();
|
||||
const auto layoutId2 = FancyZonesUtils::GuidFromString(L"{B7A1F5A9-9DC2-4505-84AB-993253839094}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaId{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
@@ -263,56 +263,56 @@ namespace FancyZonesUnitTests
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
const int expectedZoneIndex = 10;
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, zoneSetId1, { expectedZoneIndex }));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ expectedZoneIndex } == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, zoneSetId1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, zoneSetId2));
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, layoutId1, { expectedZoneIndex }));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ expectedZoneIndex } == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, layoutId1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, layoutId2));
|
||||
}
|
||||
|
||||
TEST_METHOD (AppLastZoneRemoveWindow)
|
||||
{
|
||||
const std::wstring zoneSetId = L"{B7A1F5A9-9DC2-4505-84AB-993253839093}";
|
||||
const auto layoutId = FancyZonesUtils::GuidFromString(L"{B7A1F5A9-9DC2-4505-84AB-993253839093}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaId{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
};
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, zoneSetId, { 1 }));
|
||||
Assert::IsTrue(AppZoneHistory::instance().RemoveAppLastZone(window, workAreaId, zoneSetId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, zoneSetId));
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, layoutId, { 1 }));
|
||||
Assert::IsTrue(AppZoneHistory::instance().RemoveAppLastZone(window, workAreaId, layoutId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, layoutId));
|
||||
}
|
||||
|
||||
TEST_METHOD (AppLastZoneRemoveUnknownWindow)
|
||||
{
|
||||
const std::wstring zoneSetId = L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}";
|
||||
const auto layoutId = FancyZonesUtils::GuidFromString(L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaId{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
};
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(window, workAreaId, zoneSetId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, zoneSetId));
|
||||
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(window, workAreaId, layoutId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, layoutId));
|
||||
}
|
||||
|
||||
TEST_METHOD (AppLastZoneRemoveUnknownZoneSetId)
|
||||
{
|
||||
const std::wstring zoneSetIdToInsert = L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}";
|
||||
const std::wstring zoneSetIdToRemove = L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F1}";
|
||||
const auto layoutIdToInsert = FancyZonesUtils::GuidFromString(L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}").value();
|
||||
const auto layoutIdToRemove = FancyZonesUtils::GuidFromString(L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F1}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaId{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
};
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, zoneSetIdToInsert, { 1 }));
|
||||
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(window, workAreaId, zoneSetIdToRemove));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, zoneSetIdToInsert));
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaId, layoutIdToInsert, { 1 }));
|
||||
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(window, workAreaId, layoutIdToRemove));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaId, layoutIdToInsert));
|
||||
}
|
||||
|
||||
TEST_METHOD (AppLastZoneRemoveUnknownWindowId)
|
||||
{
|
||||
const std::wstring zoneSetId = L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}";
|
||||
const auto layoutId = FancyZonesUtils::GuidFromString(L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaIdToInsert{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
@@ -323,20 +323,20 @@ namespace FancyZonesUnitTests
|
||||
};
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaIdToInsert, zoneSetId, { 1 }));
|
||||
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(window, workAreaIdToRemove, zoneSetId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaIdToInsert, zoneSetId));
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, workAreaIdToInsert, layoutId, { 1 }));
|
||||
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(window, workAreaIdToRemove, layoutId));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == AppZoneHistory::instance().GetAppLastZoneIndexSet(window, workAreaIdToInsert, layoutId));
|
||||
}
|
||||
|
||||
TEST_METHOD (AppLastZoneRemoveNullWindow)
|
||||
{
|
||||
const std::wstring zoneSetId = L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}";
|
||||
const auto layoutId = FancyZonesUtils::GuidFromString(L"{2FEC41DA-3A0B-4E31-9CE1-9473C65D99F2}").value();
|
||||
const FancyZonesDataTypes::WorkAreaId workAreaId{
|
||||
.monitorId = { .deviceId = { .id = L"DELA026", .instanceId = L"5&10a58c63&0&UID16777488" } },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value()
|
||||
};
|
||||
|
||||
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(nullptr, workAreaId, zoneSetId));
|
||||
Assert::IsFalse(AppZoneHistory::instance().RemoveAppLastZone(nullptr, workAreaId, layoutId));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -140,10 +140,9 @@ namespace FancyZonesUnitTests
|
||||
data.zoneCount = 4;
|
||||
|
||||
// prepare settings
|
||||
PowerToysSettings::PowerToyValues values(NonLocalizable::ModuleKey, NonLocalizable::ModuleKey);
|
||||
values.add_property(L"fancyzones_overlappingZonesAlgorithm", json::value(static_cast<int>(OverlappingZonesAlgorithm::Smallest)));
|
||||
json::to_file(FancyZonesSettings::GetSettingsFileName(), values.get_raw_json());
|
||||
FancyZonesSettings::instance().LoadSettings();
|
||||
auto settings = FancyZonesSettings::settings();
|
||||
settings.overlappingZonesAlgorithm = OverlappingZonesAlgorithm::Smallest;
|
||||
FancyZonesSettings::instance().SetSettings(settings);
|
||||
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
layout->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
@@ -168,10 +167,9 @@ namespace FancyZonesUnitTests
|
||||
data.zoneCount = 4;
|
||||
|
||||
// prepare settings
|
||||
PowerToysSettings::PowerToyValues values(NonLocalizable::ModuleKey, NonLocalizable::ModuleKey);
|
||||
values.add_property(L"fancyzones_overlappingZonesAlgorithm", json::value(static_cast<int>(OverlappingZonesAlgorithm::Smallest)));
|
||||
json::to_file(FancyZonesSettings::GetSettingsFileName(), values.get_raw_json());
|
||||
FancyZonesSettings::instance().LoadSettings();
|
||||
auto settings = FancyZonesSettings::settings();
|
||||
settings.overlappingZonesAlgorithm = OverlappingZonesAlgorithm::Smallest;
|
||||
FancyZonesSettings::instance().SetSettings(settings);
|
||||
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
layout->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="Util.Spec.cpp" />
|
||||
<ClCompile Include="Util.cpp" />
|
||||
<ClCompile Include="WindowKeyboardSnap.Spec.cpp" />
|
||||
<ClCompile Include="WorkArea.Spec.cpp" />
|
||||
<ClCompile Include="WorkAreaIdTests.Spec.cpp" />
|
||||
<ClCompile Include="Zone.Spec.cpp" />
|
||||
|
||||
@@ -63,6 +63,9 @@
|
||||
<ClCompile Include="DefaultLayoutsTests.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="WindowKeyboardSnap.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -44,7 +44,6 @@ namespace FancyZonesUnitTests
|
||||
{
|
||||
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
||||
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
||||
|
||||
std::filesystem::remove(DefaultLayouts::DefaultLayoutsFileName());
|
||||
}
|
||||
|
||||
@@ -58,7 +57,6 @@ namespace FancyZonesUnitTests
|
||||
|
||||
const auto& layout = workArea->GetLayout();
|
||||
Assert::IsNotNull(layout.get());
|
||||
Assert::IsNotNull(workArea->GetLayoutWindows().get());
|
||||
Assert::AreEqual(static_cast<int>(defaultLayout.type), static_cast<int>(layout->Type()));
|
||||
Assert::AreEqual(defaultLayout.zoneCount, static_cast<int>(layout->Zones().size()));
|
||||
}
|
||||
@@ -73,7 +71,6 @@ namespace FancyZonesUnitTests
|
||||
|
||||
const auto& layout = workArea->GetLayout();
|
||||
Assert::IsNotNull(layout.get());
|
||||
Assert::IsNotNull(workArea->GetLayoutWindows().get());
|
||||
Assert::AreEqual(static_cast<int>(defaultLayout.type), static_cast<int>(layout->Type()));
|
||||
Assert::AreEqual(defaultLayout.zoneCount, static_cast<int>(layout->Zones().size()));
|
||||
}
|
||||
@@ -102,7 +99,6 @@ namespace FancyZonesUnitTests
|
||||
|
||||
auto actualWorkArea = WorkArea::Create(m_hInst, m_workAreaId, parentUniqueId, m_workAreaRect);
|
||||
Assert::IsNotNull(actualWorkArea->GetLayout().get());
|
||||
Assert::IsNotNull(actualWorkArea->GetLayoutWindows().get());
|
||||
|
||||
Assert::IsTrue(AppliedLayouts::instance().GetAppliedLayoutMap().contains(m_workAreaId));
|
||||
const auto& actualLayout = AppliedLayouts::instance().GetAppliedLayoutMap().at(m_workAreaId);
|
||||
@@ -179,428 +175,46 @@ namespace FancyZonesUnitTests
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CLASS (WorkAreaMoveWindowUnitTests)
|
||||
TEST_CLASS (WorkAreaSnapUnitTests)
|
||||
{
|
||||
const std::wstring m_virtualDesktopIdStr = L"{A998CA86-F08D-4BCA-AED8-77F5C8FC9925}";
|
||||
const FancyZonesDataTypes::WorkAreaId m_workAreaId{
|
||||
HINSTANCE m_hInst{};
|
||||
const HMONITOR m_monitor = Mocks::Monitor();
|
||||
const FancyZonesUtils::Rect m_workAreaRect{ RECT(0, 0, 1920, 1080) };
|
||||
const FancyZonesDataTypes::WorkAreaId m_parentUniqueId = {};
|
||||
const FancyZonesDataTypes::WorkAreaId m_workAreaId = {
|
||||
.monitorId = {
|
||||
.monitor = Mocks::Monitor(),
|
||||
.deviceId = {
|
||||
.id = L"DELA026",
|
||||
.monitor = m_monitor,
|
||||
.deviceId = {
|
||||
.id = L"device-id-1",
|
||||
.instanceId = L"5&10a58c63&0&UID16777488",
|
||||
.number = 1,
|
||||
},
|
||||
.serialNumber = L"serial-number"
|
||||
},
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(m_virtualDesktopIdStr).value()
|
||||
.serialNumber = L"serial-number-1" },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{310F2924-B587-4D87-97C2-90031BDBE3F1}").value()
|
||||
};
|
||||
|
||||
FancyZonesDataTypes::WorkAreaId m_parentUniqueId; // default empty
|
||||
|
||||
HINSTANCE m_hInst{};
|
||||
FancyZonesUtils::Rect m_workAreaRect{ RECT(0, 0, 1920, 1080) };
|
||||
|
||||
void PrepareEmptyLayout()
|
||||
{
|
||||
json::JsonObject root{};
|
||||
json::JsonArray layoutsArray{};
|
||||
|
||||
{
|
||||
json::JsonObject layout{};
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::UuidID, json::value(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}"));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::TypeID, json::value(FancyZonesDataTypes::TypeToString(FancyZonesDataTypes::ZoneSetLayoutType::Blank)));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::ShowSpacingID, json::value(false));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::SpacingID, json::value(0));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::ZoneCountID, json::value(0));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::SensitivityRadiusID, json::value(0));
|
||||
|
||||
json::JsonObject workAreaId{};
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorID, json::value(m_workAreaId.monitorId.deviceId.id));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorInstanceID, json::value(m_workAreaId.monitorId.deviceId.instanceId));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorSerialNumberID, json::value(m_workAreaId.monitorId.serialNumber));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorNumberID, json::value(m_workAreaId.monitorId.deviceId.number));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::VirtualDesktopID, json::value(m_virtualDesktopIdStr));
|
||||
|
||||
json::JsonObject obj{};
|
||||
obj.SetNamedValue(NonLocalizable::AppliedLayoutsIds::DeviceID, workAreaId);
|
||||
obj.SetNamedValue(NonLocalizable::AppliedLayoutsIds::AppliedLayoutID, layout);
|
||||
|
||||
layoutsArray.Append(obj);
|
||||
}
|
||||
|
||||
root.SetNamedValue(NonLocalizable::AppliedLayoutsIds::AppliedLayoutsArrayID, layoutsArray);
|
||||
json::to_file(AppliedLayouts::AppliedLayoutsFileName(), root);
|
||||
|
||||
AppliedLayouts::instance().LoadData();
|
||||
}
|
||||
|
||||
void PrepareGridLayout()
|
||||
{
|
||||
json::JsonObject root{};
|
||||
json::JsonArray layoutsArray{};
|
||||
|
||||
{
|
||||
json::JsonObject layout{};
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::UuidID, json::value(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}"));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::TypeID, json::value(FancyZonesDataTypes::TypeToString(FancyZonesDataTypes::ZoneSetLayoutType::Grid)));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::ShowSpacingID, json::value(false));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::SpacingID, json::value(0));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::ZoneCountID, json::value(4));
|
||||
layout.SetNamedValue(NonLocalizable::AppliedLayoutsIds::SensitivityRadiusID, json::value(20));
|
||||
|
||||
json::JsonObject workAreaId{};
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorID, json::value(m_workAreaId.monitorId.deviceId.id));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorInstanceID, json::value(m_workAreaId.monitorId.deviceId.instanceId));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorSerialNumberID, json::value(m_workAreaId.monitorId.serialNumber));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorNumberID, json::value(m_workAreaId.monitorId.deviceId.number));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::VirtualDesktopID, json::value(m_virtualDesktopIdStr));
|
||||
|
||||
json::JsonObject obj{};
|
||||
obj.SetNamedValue(NonLocalizable::AppliedLayoutsIds::DeviceID, workAreaId);
|
||||
obj.SetNamedValue(NonLocalizable::AppliedLayoutsIds::AppliedLayoutID, layout);
|
||||
|
||||
layoutsArray.Append(obj);
|
||||
}
|
||||
|
||||
root.SetNamedValue(NonLocalizable::AppliedLayoutsIds::AppliedLayoutsArrayID, layoutsArray);
|
||||
json::to_file(AppliedLayouts::AppliedLayoutsFileName(), root);
|
||||
|
||||
AppliedLayouts::instance().LoadData();
|
||||
}
|
||||
|
||||
TEST_METHOD_INITIALIZE(Init) noexcept
|
||||
{
|
||||
AppZoneHistory::instance().LoadData();
|
||||
AppliedLayouts::instance().LoadData();
|
||||
}
|
||||
|
||||
TEST_METHOD_CLEANUP(CleanUp) noexcept
|
||||
{
|
||||
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
||||
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
||||
}
|
||||
|
||||
TEST_METHOD (EmptyZonesMoveLeftByIndex)
|
||||
{
|
||||
// prepare
|
||||
PrepareEmptyLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_LEFT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)0, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{} == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (EmptyZonesRightByIndex)
|
||||
{
|
||||
// prepare
|
||||
PrepareEmptyLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)0, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{} == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveLeftNonAppliedWindowByIndex)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_LEFT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 3 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveRightNonAppliedWindowByIndex)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 0 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowByIndex)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||
Assert::IsTrue(ZoneIndexSet{ 0 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
||||
Assert::IsTrue(ZoneIndexSet{ 1 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowByIndexCycle)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_LEFT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ static_cast<ZoneIndex>(workArea->GetLayout()->Zones().size() - 1) } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowByIndexNoCycle)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_LEFT, false);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 0 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (EmptyZonesMoveByPosition)
|
||||
{
|
||||
// prepare
|
||||
PrepareEmptyLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_LEFT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)0, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{} == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveLeftNonAppliedWindowByPosition)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_LEFT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 1 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveRightNonAppliedWindowByPosition)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_RIGHT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 0 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowHorizontallyByPosition)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByIndexSet(window, { 0 }, true); // snap to the 1st zone
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_RIGHT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 1 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowVerticallyByPosition)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByIndexSet(window, { 0 }, true); // snap to the 1st zone
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_DOWN, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 2 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowByPositionHorizontallyCycle)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByIndexSet(window, { 0 }, true); // snap to the 1st zone
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_LEFT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 1 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowByPositionHorizontallyNoCycle)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_LEFT, false);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 0 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowByPositionVerticallyCycle)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
workArea->MoveWindowIntoZoneByIndexSet(window, { 0 }, true); // snap to the 1st zone
|
||||
Assert::IsTrue(ZoneIndexSet{ 0 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_UP, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
Assert::IsTrue(ZoneIndexSet{ 2 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowByPositionVerticallyNoCycle)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByIndexSet(window, { 0 }, true); // snap to the 1st zone
|
||||
|
||||
// test
|
||||
workArea->MoveWindowIntoZoneByDirectionAndPosition(window, VK_UP, false);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 0 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (ExtendZoneHorizontally)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByIndexSet(window, { 0 }, true); // snap to the 1st zone
|
||||
|
||||
// test
|
||||
workArea->ExtendWindowByDirectionAndPosition(window, VK_RIGHT);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 0, 1 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (ExtendZoneVertically)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByIndexSet(window, { 0 }, true); // snap to the 1st zone
|
||||
|
||||
// test
|
||||
workArea->ExtendWindowByDirectionAndPosition(window, VK_DOWN);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(ZoneIndexSet{ 0, 2 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (WhenWindowIsNotResizablePlacingItIntoTheZoneShouldNotResizeIt)
|
||||
{
|
||||
LayoutData layout{
|
||||
.uuid = FancyZonesUtils::GuidFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC58}").value(),
|
||||
.type = FancyZonesDataTypes::ZoneSetLayoutType::Grid,
|
||||
.showSpacing = false,
|
||||
.spacing = 0,
|
||||
.zoneCount = 4,
|
||||
.sensitivityRadius = 20,
|
||||
};
|
||||
AppliedLayouts::instance().ApplyLayout(m_workAreaId, layout);
|
||||
|
||||
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
@@ -610,7 +224,10 @@ namespace FancyZonesUnitTests
|
||||
SetWindowPos(window, nullptr, 150, 150, originalWidth, originalHeight, SWP_SHOWWINDOW);
|
||||
SetWindowLong(window, GWL_STYLE, GetWindowLong(window, GWL_STYLE) & ~WS_SIZEBOX);
|
||||
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_LEFT, true);
|
||||
Assert::IsTrue(workArea->Snap(window, { 1 }, true));
|
||||
|
||||
// wait for the window to be resized
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
RECT inZoneRect;
|
||||
GetWindowRect(window, &inZoneRect);
|
||||
@@ -619,13 +236,46 @@ namespace FancyZonesUnitTests
|
||||
Assert::AreEqual(originalHeight, (int)inZoneRect.bottom - (int)inZoneRect.top);
|
||||
}
|
||||
|
||||
TEST_METHOD (WhenWindowIsResizablePlacingItIntoTheZoneShouldResizeIt)
|
||||
{
|
||||
LayoutData layout{
|
||||
.uuid = FancyZonesUtils::GuidFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC58}").value(),
|
||||
.type = FancyZonesDataTypes::ZoneSetLayoutType::Grid,
|
||||
.showSpacing = false,
|
||||
.spacing = 0,
|
||||
.zoneCount = 4,
|
||||
.sensitivityRadius = 20,
|
||||
};
|
||||
AppliedLayouts::instance().ApplyLayout(m_workAreaId, layout);
|
||||
|
||||
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
SetWindowPos(window, nullptr, 150, 150, 450, 550, SWP_SHOWWINDOW);
|
||||
|
||||
Assert::IsTrue(workArea->Snap(window, { 1 }, true));
|
||||
|
||||
// wait for the window to be resized
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
RECT zonedWindowRect;
|
||||
GetWindowRect(window, &zonedWindowRect);
|
||||
|
||||
RECT zoneRect = workArea->GetLayout()->Zones().at(1).GetZoneRect();
|
||||
|
||||
Assert::AreEqual(zoneRect.left, zonedWindowRect.left);
|
||||
Assert::AreEqual(zoneRect.right, zonedWindowRect.right);
|
||||
Assert::AreEqual(zoneRect.top, zonedWindowRect.top);
|
||||
Assert::AreEqual(zoneRect.bottom, zonedWindowRect.bottom);
|
||||
}
|
||||
|
||||
TEST_METHOD (SnapWindowPropertyTest)
|
||||
{
|
||||
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
const ZoneIndexSet expected = { 1, 2 };
|
||||
workArea->SnapWindow(window, expected);
|
||||
Assert::IsTrue(workArea->Snap(window, expected));
|
||||
|
||||
const auto actual = FancyZonesWindowProperties::RetrieveZoneIndexProperty(window);
|
||||
Assert::AreEqual(expected.size(), actual.size());
|
||||
@@ -641,7 +291,7 @@ namespace FancyZonesUnitTests
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
const ZoneIndexSet expected = { 1, 2 };
|
||||
workArea->SnapWindow(window, expected);
|
||||
Assert::IsTrue(workArea->Snap(window, expected));
|
||||
|
||||
const auto processPath = get_process_path(window);
|
||||
const auto history = AppZoneHistory::instance().GetZoneHistory(processPath, m_workAreaId);
|
||||
@@ -654,13 +304,25 @@ namespace FancyZonesUnitTests
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (SnapLayoutAssignedWindowsTest)
|
||||
{
|
||||
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
const ZoneIndexSet expected = { 1, 2 };
|
||||
Assert::IsTrue(workArea->Snap(window, expected));
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(expected == layoutWindows.GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (UnsnapPropertyTest)
|
||||
{
|
||||
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
workArea->SnapWindow(window, { 1, 2 });
|
||||
workArea->UnsnapWindow(window);
|
||||
Assert::IsTrue(workArea->Snap(window, { 1, 2 }));
|
||||
Assert::IsTrue(workArea->Unsnap(window));
|
||||
|
||||
const auto actual = FancyZonesWindowProperties::RetrieveZoneIndexProperty(window);
|
||||
Assert::IsTrue(actual.empty());
|
||||
@@ -671,13 +333,25 @@ namespace FancyZonesUnitTests
|
||||
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
workArea->SnapWindow(window, { 1, 2 });
|
||||
workArea->UnsnapWindow(window);
|
||||
Assert::IsTrue(workArea->Snap(window, { 1, 2 }));
|
||||
Assert::IsTrue(workArea->Unsnap(window));
|
||||
|
||||
const auto processPath = get_process_path(window);
|
||||
const auto history = AppZoneHistory::instance().GetZoneHistory(processPath, m_workAreaId);
|
||||
|
||||
Assert::IsFalse(history.has_value());
|
||||
}
|
||||
|
||||
TEST_METHOD (UnsnapLayoutAssignedWindowsTest)
|
||||
{
|
||||
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
Assert::IsTrue(workArea->Snap(window, { 1, 2 }));
|
||||
Assert::IsTrue(workArea->Unsnap(window));
|
||||
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
Assert::IsTrue(layoutWindows.GetZoneIndexSetFromWindow(window).empty());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user