mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
[FancyZones] Window switch shortcut fix (#21426)
* rename Layout -> LayoutData * simplify zone * split ZoneSet: Layout * refactoring * split ZoneSet: LayoutWindows * update trace * split ZoneSet: remove ZoneSet * fix initialization * split unit tests * remove unused * warning * nullptr check * use current rect * update work area tests * use current rect * simplify * more meaningful name * dismiss * safety checks * resolve conflicts * reassign windows after switching vd * avoid double-processing for window on switching vd * extend windows fix * check if window is on current desktop before cycling * separated extend * not reinit layout windows
This commit is contained in:
@@ -418,7 +418,7 @@ namespace FancyZonesUnitTests
|
||||
};
|
||||
|
||||
// test
|
||||
Layout expectedLayout {
|
||||
LayoutData expectedLayout {
|
||||
.uuid = FancyZonesUtils::GuidFromString(L"{33A2B101-06E0-437B-A61E-CDBECF502906}").value(),
|
||||
.type = FancyZonesDataTypes::ZoneSetLayoutType::Focus,
|
||||
.showSpacing = true,
|
||||
@@ -470,7 +470,7 @@ namespace FancyZonesUnitTests
|
||||
AppliedLayouts::instance().LoadData();
|
||||
|
||||
// test
|
||||
Layout expectedLayout{
|
||||
LayoutData expectedLayout{
|
||||
.uuid = FancyZonesUtils::GuidFromString(L"{33A2B101-06E0-437B-A61E-CDBECF502906}").value(),
|
||||
.type = FancyZonesDataTypes::ZoneSetLayoutType::Focus,
|
||||
.showSpacing = true,
|
||||
@@ -530,7 +530,7 @@ namespace FancyZonesUnitTests
|
||||
.monitorId = { .deviceId = { .id = L"device", .instanceId = L"instance-id" }, .serialNumber = L"serial-number" },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{E21F6F29-76FD-4FC1-8970-17AB8AD64847}").value()
|
||||
};
|
||||
AppliedLayouts::instance().ApplyLayout(id, Layout{});
|
||||
AppliedLayouts::instance().ApplyLayout(id, LayoutData{});
|
||||
|
||||
// test
|
||||
Assert::IsTrue(AppliedLayouts::instance().IsLayoutApplied(id));
|
||||
@@ -543,7 +543,7 @@ namespace FancyZonesUnitTests
|
||||
.monitorId = { .deviceId = { .id = L"device-1", .instanceId = L"instance-id-1" }, .serialNumber = L"serial-number-1" },
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{E21F6F29-76FD-4FC1-8970-17AB8AD64847}").value()
|
||||
};
|
||||
AppliedLayouts::instance().ApplyLayout(id1, Layout{});
|
||||
AppliedLayouts::instance().ApplyLayout(id1, LayoutData{});
|
||||
|
||||
// test
|
||||
FancyZonesDataTypes::WorkAreaId id2{
|
||||
|
||||
@@ -59,13 +59,13 @@ namespace FancyZonesUnitTests
|
||||
// test
|
||||
DefaultLayouts::instance().LoadData();
|
||||
|
||||
Layout horizontal{
|
||||
LayoutData horizontal{
|
||||
.uuid = FancyZonesUtils::GuidFromString(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}").value(),
|
||||
.type = FancyZonesDataTypes::ZoneSetLayoutType::Custom
|
||||
};
|
||||
Assert::IsTrue(horizontal == DefaultLayouts::instance().GetDefaultLayout(MonitorConfiguraionType::Horizontal));
|
||||
|
||||
Layout vertical{
|
||||
LayoutData vertical{
|
||||
.uuid = GUID_NULL,
|
||||
.type = FancyZonesDataTypes::ZoneSetLayoutType::Grid,
|
||||
.showSpacing = true,
|
||||
@@ -87,7 +87,7 @@ namespace FancyZonesUnitTests
|
||||
// test
|
||||
DefaultLayouts::instance().LoadData();
|
||||
|
||||
Layout priorityGrid{
|
||||
LayoutData priorityGrid{
|
||||
.uuid = GUID_NULL,
|
||||
.type = FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid,
|
||||
.showSpacing = DefaultValues::ShowSpacing,
|
||||
@@ -105,7 +105,7 @@ namespace FancyZonesUnitTests
|
||||
// test
|
||||
DefaultLayouts::instance().LoadData();
|
||||
|
||||
Layout priorityGrid{
|
||||
LayoutData priorityGrid{
|
||||
.uuid = GUID_NULL,
|
||||
.type = FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid,
|
||||
.showSpacing = DefaultValues::ShowSpacing,
|
||||
|
||||
487
src/modules/fancyzones/FancyZonesTests/UnitTests/Layout.Spec.cpp
Normal file
487
src/modules/fancyzones/FancyZonesTests/UnitTests/Layout.Spec.cpp
Normal file
@@ -0,0 +1,487 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <FancyZonesLib/FancyZonesData/LayoutDefaults.h>
|
||||
#include <FancyZonesLib/FancyZonesData/CustomLayouts.h>
|
||||
#include <FancyZonesLib/ZoneIndexSetBitmask.h>
|
||||
#include <FancyZonesLib/Layout.h>
|
||||
#include <FancyZonesLib/Settings.h>
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace FancyZonesDataTypes;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS (LayoutUnitTests)
|
||||
{
|
||||
const LayoutData m_data
|
||||
{
|
||||
.uuid = FancyZonesUtils::GuidFromString(L"{F762BAD6-DAA1-4997-9497-E11DFEB72F21}").value(),
|
||||
.type = ZoneSetLayoutType::Grid,
|
||||
.showSpacing = false,
|
||||
.spacing = 17,
|
||||
.zoneCount = 4,
|
||||
.sensitivityRadius = 33
|
||||
};
|
||||
std::unique_ptr<Layout> m_layout{};
|
||||
|
||||
TEST_METHOD_INITIALIZE(Init)
|
||||
{
|
||||
m_layout = std::make_unique<Layout>(m_data);
|
||||
}
|
||||
|
||||
TEST_METHOD_CLEANUP(CleanUp)
|
||||
{
|
||||
std::filesystem::remove_all(CustomLayouts::CustomLayoutsFileName());
|
||||
}
|
||||
|
||||
void compareZones(const Zone& expected, const Zone& actual)
|
||||
{
|
||||
Assert::AreEqual(expected.Id(), actual.Id());
|
||||
Assert::AreEqual(expected.GetZoneRect().left, actual.GetZoneRect().left);
|
||||
Assert::AreEqual(expected.GetZoneRect().right, actual.GetZoneRect().right);
|
||||
Assert::AreEqual(expected.GetZoneRect().top, actual.GetZoneRect().top);
|
||||
Assert::AreEqual(expected.GetZoneRect().bottom, actual.GetZoneRect().bottom);
|
||||
}
|
||||
|
||||
void saveCustomLayout(const std::vector<RECT>& zones)
|
||||
{
|
||||
json::JsonObject root{};
|
||||
json::JsonArray layoutsArray{};
|
||||
|
||||
json::JsonObject canvasLayoutJson{};
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::UuidID, json::value(FancyZonesUtils::GuidToString(m_data.uuid).value()));
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::NameID, json::value(L"Custom canvas layout"));
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::TypeID, json::value(NonLocalizable::CustomLayoutsIds::CanvasID));
|
||||
|
||||
json::JsonObject info{};
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::RefWidthID, json::value(1920));
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::RefHeightID, json::value(1080));
|
||||
|
||||
json::JsonArray zonesArray{};
|
||||
for (const auto& zoneRect : zones)
|
||||
{
|
||||
json::JsonObject zone{};
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::XID, json::value(zoneRect.left));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::YID, json::value(zoneRect.top));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::WidthID, json::value(zoneRect.right - zoneRect.left));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::HeightID, json::value(zoneRect.bottom - zoneRect.top));
|
||||
zonesArray.Append(zone);
|
||||
}
|
||||
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::ZonesID, zonesArray);
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::InfoID, info);
|
||||
layoutsArray.Append(canvasLayoutJson);
|
||||
root.SetNamedValue(NonLocalizable::CustomLayoutsIds::CustomLayoutsArrayID, layoutsArray);
|
||||
json::to_file(CustomLayouts::CustomLayoutsFileName(), root);
|
||||
|
||||
CustomLayouts::instance().LoadData();
|
||||
}
|
||||
|
||||
public:
|
||||
TEST_METHOD (TestCreateLayout)
|
||||
{
|
||||
CustomAssert::AreEqual(m_layout->Id(), m_data.uuid);
|
||||
CustomAssert::AreEqual(m_layout->Type(), m_data.type);
|
||||
}
|
||||
|
||||
TEST_METHOD (EmptyZones)
|
||||
{
|
||||
auto zones = m_layout->Zones();
|
||||
Assert::AreEqual((size_t)0, zones.size());
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointEmpty)
|
||||
{
|
||||
auto actual = m_layout->ZonesFromPoint(POINT{ 0, 0 });
|
||||
Assert::IsTrue(actual.size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointInner)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.spacing = 0;
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
layout->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
|
||||
auto actual = layout->ZonesFromPoint(POINT{ 1, 1 });
|
||||
Assert::IsTrue(actual.size() == 1);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointBorder)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.spacing = 0;
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
layout->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
|
||||
Assert::IsTrue(layout->ZonesFromPoint(POINT{ 0, 0 }).size() == 1);
|
||||
Assert::IsTrue(layout->ZonesFromPoint(POINT{ 1920, 1080 }).size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointOuter)
|
||||
{
|
||||
m_layout->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
|
||||
auto actual = m_layout->ZonesFromPoint(POINT{ 1921, 1080 });
|
||||
Assert::IsTrue(actual.size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointOverlapping)
|
||||
{
|
||||
// prepare layout with overlapping zones
|
||||
saveCustomLayout({ RECT{ 0, 0, 100, 100 }, RECT{ 10, 10, 90, 90 }, RECT{ 10, 10, 150, 150 }, RECT{ 10, 10, 50, 50 } });
|
||||
|
||||
LayoutData data = m_data;
|
||||
data.type = FancyZonesDataTypes::ZoneSetLayoutType::Custom;
|
||||
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 layout = std::make_unique<Layout>(data);
|
||||
layout->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
|
||||
// zone4 is expected because it's the smallest one, and it's considered to be inside
|
||||
// since Multizones support
|
||||
auto zones = layout->ZonesFromPoint(POINT{ 50, 50 });
|
||||
Assert::IsTrue(zones.size() == 1);
|
||||
|
||||
Zone expected({ 10, 10, 50, 50 }, 3);
|
||||
const auto& actual = layout->Zones().at(zones.at(0));
|
||||
compareZones(expected, actual);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointMultizone)
|
||||
{
|
||||
// prepare layout with overlapping zones
|
||||
saveCustomLayout({ RECT{ 0, 0, 100, 100 }, RECT{ 100, 0, 200, 100 }, RECT{ 0, 100, 100, 200 }, RECT{ 100, 100, 200, 200 } });
|
||||
|
||||
LayoutData data = m_data;
|
||||
data.type = FancyZonesDataTypes::ZoneSetLayoutType::Custom;
|
||||
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 layout = std::make_unique<Layout>(data);
|
||||
layout->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
|
||||
auto actual = layout->ZonesFromPoint(POINT{ 50, 100 });
|
||||
Assert::IsTrue(actual.size() == 2);
|
||||
|
||||
Zone zone1({ 0, 0, 100, 100 }, 0);
|
||||
compareZones(zone1, layout->Zones().at(actual[0]));
|
||||
|
||||
Zone zone3({ 0, 100, 100, 200 }, 2);
|
||||
compareZones(zone3, layout->Zones().at(actual[1]));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CLASS (LayoutInitUnitTests)
|
||||
{
|
||||
const LayoutData m_data{
|
||||
.uuid = FancyZonesUtils::GuidFromString(L"{33A2B101-06E0-437B-A61E-CDBECF502906}").value(),
|
||||
.type = ZoneSetLayoutType::Grid,
|
||||
.showSpacing = false,
|
||||
.spacing = 17,
|
||||
.zoneCount = 4,
|
||||
.sensitivityRadius = 33
|
||||
};
|
||||
std::unique_ptr<Layout> m_layout{};
|
||||
|
||||
HMONITOR m_monitor{};
|
||||
const std::array<RECT, 9> m_workAreaRects{
|
||||
RECT{ .left = 0, .top = 0, .right = 1024, .bottom = 768 },
|
||||
RECT{ .left = 0, .top = 0, .right = 1280, .bottom = 720 },
|
||||
RECT{ .left = 0, .top = 0, .right = 1280, .bottom = 800 },
|
||||
RECT{ .left = 0, .top = 0, .right = 1280, .bottom = 1024 },
|
||||
RECT{ .left = 0, .top = 0, .right = 1366, .bottom = 768 },
|
||||
RECT{ .left = 0, .top = 0, .right = 1440, .bottom = 900 },
|
||||
RECT{ .left = 0, .top = 0, .right = 1536, .bottom = 864 },
|
||||
RECT{ .left = 0, .top = 0, .right = 1600, .bottom = 900 },
|
||||
RECT{ .left = 0, .top = 0, .right = 1920, .bottom = 1080 }
|
||||
};
|
||||
|
||||
void checkZones(const std::unique_ptr<Layout>& layout, ZoneSetLayoutType type, size_t expectedCount, RECT rect)
|
||||
{
|
||||
const auto& zones = layout->Zones();
|
||||
Assert::AreEqual(expectedCount, zones.size());
|
||||
|
||||
int zoneId = 0;
|
||||
for (const auto& zone : zones)
|
||||
{
|
||||
const auto& zoneRect = zone.second.GetZoneRect();
|
||||
Assert::IsTrue(zoneRect.left >= 0, L"left border is less than zero");
|
||||
Assert::IsTrue(zoneRect.top >= 0, L"top border is less than zero");
|
||||
|
||||
Assert::IsTrue(zoneRect.left < zoneRect.right, L"rect.left >= rect.right");
|
||||
Assert::IsTrue(zoneRect.top < zoneRect.bottom, L"rect.top >= rect.bottom");
|
||||
|
||||
if (type != ZoneSetLayoutType::Focus)
|
||||
{
|
||||
Assert::IsTrue(zoneRect.right <= rect.right, L"right border is bigger than monitor work space");
|
||||
Assert::IsTrue(zoneRect.bottom <= rect.bottom, L"bottom border is bigger than monitor work space");
|
||||
}
|
||||
|
||||
zoneId++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD_INITIALIZE(Init)
|
||||
{
|
||||
m_layout = std::make_unique<Layout>(m_data);
|
||||
}
|
||||
|
||||
public:
|
||||
TEST_METHOD (ValidValues)
|
||||
{
|
||||
const int zoneCount = 10;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.type = static_cast<ZoneSetLayoutType>(type);
|
||||
data.spacing = 10;
|
||||
data.zoneCount = zoneCount;
|
||||
|
||||
for (const auto& rect : m_workAreaRects)
|
||||
{
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
auto result = layout->Init(rect, Mocks::Monitor());
|
||||
Assert::IsTrue(result);
|
||||
checkZones(layout, static_cast<ZoneSetLayoutType>(type), zoneCount, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (InvalidMonitorInfo)
|
||||
{
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.type = static_cast<ZoneSetLayoutType>(type);
|
||||
data.spacing = 10;
|
||||
data.zoneCount = 10;
|
||||
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
|
||||
auto result = layout->Init(RECT{0,0,0,0}, Mocks::Monitor());
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (ZeroSpacing)
|
||||
{
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.type = static_cast<ZoneSetLayoutType>(type);
|
||||
data.spacing = 0;
|
||||
data.zoneCount = 10;
|
||||
|
||||
for (const auto& rect : m_workAreaRects)
|
||||
{
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
auto result = layout->Init(rect, Mocks::Monitor());
|
||||
Assert::IsTrue(result);
|
||||
checkZones(layout, static_cast<ZoneSetLayoutType>(type), data.zoneCount, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (LargeNegativeSpacing)
|
||||
{
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.type = static_cast<ZoneSetLayoutType>(type);
|
||||
data.zoneCount = 10;
|
||||
data.spacing = ZoneConstants::MAX_NEGATIVE_SPACING - 1;
|
||||
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
|
||||
for (const auto& rect : m_workAreaRects)
|
||||
{
|
||||
auto result = layout->Init(rect, Mocks::Monitor());
|
||||
if (type == static_cast<int>(ZoneSetLayoutType::Focus))
|
||||
{
|
||||
//Focus doesn't depends on spacing
|
||||
Assert::IsTrue(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (HorizontallyBigSpacing)
|
||||
{
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.type = static_cast<ZoneSetLayoutType>(type);
|
||||
data.zoneCount = 10;
|
||||
|
||||
for (const auto& rect : m_workAreaRects)
|
||||
{
|
||||
data.spacing = rect.right;
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
|
||||
auto result = layout->Init(rect, Mocks::Monitor());
|
||||
if (type == static_cast<int>(ZoneSetLayoutType::Focus))
|
||||
{
|
||||
//Focus doesn't depend on spacing
|
||||
Assert::IsTrue(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (VerticallyBigSpacing)
|
||||
{
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.type = static_cast<ZoneSetLayoutType>(type);
|
||||
data.zoneCount = 10;
|
||||
|
||||
for (const auto& rect : m_workAreaRects)
|
||||
{
|
||||
data.spacing = rect.bottom;
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
|
||||
auto result = layout->Init(rect, Mocks::Monitor());
|
||||
if (type == static_cast<int>(ZoneSetLayoutType::Focus))
|
||||
{
|
||||
//Focus doesn't depend on spacing
|
||||
Assert::IsTrue(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (ZeroZoneCount)
|
||||
{
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.type = static_cast<ZoneSetLayoutType>(type);
|
||||
data.zoneCount = 0;
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
|
||||
for (const auto& rect : m_workAreaRects)
|
||||
{
|
||||
auto result = layout->Init(rect, Mocks::Monitor());
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (BigZoneCount)
|
||||
{
|
||||
const int zoneCount = 128; //editor limit
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
LayoutData data = m_data;
|
||||
data.type = static_cast<ZoneSetLayoutType>(type);
|
||||
data.zoneCount = zoneCount;
|
||||
data.spacing = 0;
|
||||
|
||||
for (const auto& rect : m_workAreaRects)
|
||||
{
|
||||
auto layout = std::make_unique<Layout>(data);
|
||||
auto result = layout->Init(rect, Mocks::Monitor());
|
||||
Assert::IsTrue(result);
|
||||
checkZones(layout, static_cast<ZoneSetLayoutType>(type), zoneCount, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CLASS (ZoneIndexSetUnitTests)
|
||||
{
|
||||
TEST_METHOD (BitmaskFromIndexSetTest)
|
||||
{
|
||||
// prepare
|
||||
ZoneIndexSet set{ 0, 64 };
|
||||
|
||||
// test
|
||||
ZoneIndexSetBitmask bitmask = ZoneIndexSetBitmask::FromIndexSet(set);
|
||||
Assert::AreEqual(static_cast<uint64_t>(1), bitmask.part1);
|
||||
Assert::AreEqual(static_cast<uint64_t>(1), bitmask.part2);
|
||||
}
|
||||
|
||||
TEST_METHOD (BitmaskToIndexSet)
|
||||
{
|
||||
// prepare
|
||||
ZoneIndexSetBitmask bitmask{
|
||||
.part1 = 1,
|
||||
.part2 = 1,
|
||||
};
|
||||
|
||||
// test
|
||||
ZoneIndexSet set = bitmask.ToIndexSet();
|
||||
Assert::AreEqual(static_cast<size_t>(2), set.size());
|
||||
Assert::AreEqual(static_cast<ZoneIndex>(0), set[0]);
|
||||
Assert::AreEqual(static_cast<ZoneIndex>(64), set[1]);
|
||||
}
|
||||
|
||||
TEST_METHOD (BitmaskConvertTest)
|
||||
{
|
||||
// prepare
|
||||
ZoneIndexSet set{ 53, 54, 55, 65, 66, 67 };
|
||||
|
||||
ZoneIndexSetBitmask bitmask = ZoneIndexSetBitmask::FromIndexSet(set);
|
||||
|
||||
// test
|
||||
ZoneIndexSet actual = bitmask.ToIndexSet();
|
||||
Assert::AreEqual(set.size(), actual.size());
|
||||
for (int i = 0; i < set.size(); i++)
|
||||
{
|
||||
Assert::AreEqual(set[i], actual[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (BitmaskConvert2Test)
|
||||
{
|
||||
// prepare
|
||||
ZoneIndexSet set;
|
||||
for (int i = 0; i < 128; i++)
|
||||
{
|
||||
set.push_back(i);
|
||||
}
|
||||
|
||||
ZoneIndexSetBitmask bitmask = ZoneIndexSetBitmask::FromIndexSet(set);
|
||||
|
||||
// test
|
||||
ZoneIndexSet actual = bitmask.ToIndexSet();
|
||||
|
||||
Assert::AreEqual(set.size(), actual.size());
|
||||
for (int i = 0; i < set.size(); i++)
|
||||
{
|
||||
Assert::AreEqual(set[i], actual[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <FancyZonesLib/FancyZonesData/LayoutDefaults.h>
|
||||
#include <FancyZonesLib/FancyZonesData/CustomLayouts.h>
|
||||
#include <FancyZonesLib/ZoneIndexSetBitmask.h>
|
||||
#include <FancyZonesLib/LayoutAssignedWindows.h>
|
||||
#include <FancyZonesLib/Settings.h>
|
||||
#include <FancyZonesLib/util.h>
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace FancyZonesDataTypes;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS (LayoutAssignedWindowsUnitTests)
|
||||
{
|
||||
TEST_METHOD (ZoneIndexFromWindowUnknown)
|
||||
{
|
||||
LayoutAssignedWindows layoutWindows{};
|
||||
|
||||
layoutWindows.Assign(Mocks::Window(), { 0 });
|
||||
|
||||
auto actual = layoutWindows.GetZoneIndexSetFromWindow(Mocks::Window());
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == actual);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneIndexFromWindowNull)
|
||||
{
|
||||
LayoutAssignedWindows layoutWindows{};
|
||||
|
||||
layoutWindows.Assign(Mocks::Window(), { 0 });
|
||||
|
||||
auto actual = layoutWindows.GetZoneIndexSetFromWindow(nullptr);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == actual);
|
||||
}
|
||||
|
||||
TEST_METHOD (Assign)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
|
||||
LayoutAssignedWindows layoutWindows{};
|
||||
layoutWindows.Assign(window, { 1, 2, 3 });
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1, 2, 3 } == layoutWindows.GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (AssignEmpty)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
|
||||
LayoutAssignedWindows layoutWindows{};
|
||||
layoutWindows.Assign(window, {});
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == layoutWindows.GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (AssignSeveralTimesSameWindow)
|
||||
{
|
||||
LayoutAssignedWindows layoutWindows{};
|
||||
HWND window = Mocks::Window();
|
||||
|
||||
layoutWindows.Assign(window, { 0 });
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == layoutWindows.GetZoneIndexSetFromWindow(window));
|
||||
|
||||
layoutWindows.Assign(window, { 1 });
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == layoutWindows.GetZoneIndexSetFromWindow(window));
|
||||
|
||||
layoutWindows.Assign(window, { 2 });
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == layoutWindows.GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (DismissWindow)
|
||||
{
|
||||
LayoutAssignedWindows layoutWindows{};
|
||||
HWND window = Mocks::Window();
|
||||
|
||||
layoutWindows.Assign(window, { 0 });
|
||||
|
||||
layoutWindows.Dismiss(window);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == layoutWindows.GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (Empty)
|
||||
{
|
||||
LayoutAssignedWindows layoutWindows{};
|
||||
HWND window = Mocks::Window();
|
||||
|
||||
layoutWindows.Assign(window, { 0 });
|
||||
Assert::IsFalse(layoutWindows.IsZoneEmpty(0));
|
||||
Assert::IsTrue(layoutWindows.IsZoneEmpty(1));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -47,8 +47,10 @@
|
||||
<ClCompile Include="DefaultLayoutsTests.Spec.cpp" />
|
||||
<ClCompile Include="FancyZonesSettings.Spec.cpp" />
|
||||
<ClCompile Include="JsonHelpers.Tests.cpp" />
|
||||
<ClCompile Include="Layout.Spec.cpp" />
|
||||
<ClCompile Include="LayoutHotkeysTests.Spec.cpp" />
|
||||
<ClCompile Include="LayoutTemplatesTests.Spec.cpp" />
|
||||
<ClCompile Include="LayoutAssignedWindows.Spec.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(CIBuild)'!='true'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
@@ -57,7 +59,6 @@
|
||||
<ClCompile Include="WorkArea.Spec.cpp" />
|
||||
<ClCompile Include="WorkAreaIdTests.Spec.cpp" />
|
||||
<ClCompile Include="Zone.Spec.cpp" />
|
||||
<ClCompile Include="ZoneSet.Spec.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
<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>
|
||||
@@ -57,6 +54,12 @@
|
||||
<ClCompile Include="WorkAreaIdTests.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Layout.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayoutAssignedWindows.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DefaultLayoutsTests.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <FancyZonesLib/FancyZonesData/AppliedLayouts.h>
|
||||
#include <FancyZonesLib/FancyZonesData/AppZoneHistory.h>
|
||||
#include <FancyZonesLib/FancyZonesData/DefaultLayouts.h>
|
||||
#include <FancyZonesLib/LayoutAssignedWindows.h>
|
||||
#include "Util.h"
|
||||
|
||||
#include <common/utils/process_path.h>
|
||||
@@ -53,10 +54,11 @@ namespace FancyZonesUnitTests
|
||||
Assert::IsFalse(workArea == nullptr);
|
||||
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
||||
|
||||
auto* zoneSet{ workArea->ZoneSet() };
|
||||
Assert::IsNotNull(zoneSet);
|
||||
Assert::AreEqual(static_cast<int>(defaultLayout.type), static_cast<int>(zoneSet->LayoutType()));
|
||||
Assert::AreEqual(static_cast<size_t>(defaultLayout.zoneCount), zoneSet->GetZones().size());
|
||||
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()));
|
||||
}
|
||||
|
||||
TEST_METHOD (CreateCombinedWorkArea)
|
||||
@@ -67,10 +69,11 @@ namespace FancyZonesUnitTests
|
||||
Assert::IsFalse(workArea == nullptr);
|
||||
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
||||
|
||||
auto* zoneSet{ workArea->ZoneSet() };
|
||||
Assert::IsNotNull(zoneSet);
|
||||
Assert::AreEqual(static_cast<int>(defaultLayout.type), static_cast<int>(zoneSet->LayoutType()));
|
||||
Assert::AreEqual(static_cast<size_t>(defaultLayout.zoneCount), zoneSet->GetZones().size());
|
||||
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()));
|
||||
}
|
||||
|
||||
TEST_METHOD (CreateWorkAreaClonedFromParent)
|
||||
@@ -83,7 +86,7 @@ namespace FancyZonesUnitTests
|
||||
parentUniqueId.monitorId.serialNumber = L"serial-number";
|
||||
parentUniqueId.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC57}").value();
|
||||
|
||||
Layout layout{
|
||||
LayoutData layout{
|
||||
.uuid = FancyZonesUtils::GuidFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC58}").value(),
|
||||
.type = ZoneSetLayoutType::Rows,
|
||||
.showSpacing = true,
|
||||
@@ -96,10 +99,11 @@ namespace FancyZonesUnitTests
|
||||
AppliedLayouts::instance().ApplyLayout(parentUniqueId, layout);
|
||||
|
||||
auto actualWorkArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, parentUniqueId);
|
||||
Assert::IsNotNull(actualWorkArea->ZoneSet());
|
||||
Assert::IsNotNull(actualWorkArea->GetLayout().get());
|
||||
Assert::IsNotNull(actualWorkArea->GetLayoutWindows().get());
|
||||
|
||||
Assert::IsTrue(AppliedLayouts::instance().GetAppliedLayoutMap().contains(m_uniqueId));
|
||||
auto actualLayout = AppliedLayouts::instance().GetAppliedLayoutMap().at(m_uniqueId);
|
||||
const auto& actualLayout = AppliedLayouts::instance().GetAppliedLayoutMap().at(m_uniqueId);
|
||||
|
||||
Assert::AreEqual(static_cast<int>(layout.type), static_cast<int>(actualLayout.type));
|
||||
Assert::AreEqual(FancyZonesUtils::GuidToString(layout.uuid).value(), FancyZonesUtils::GuidToString(actualLayout.uuid).value());
|
||||
@@ -131,10 +135,11 @@ namespace FancyZonesUnitTests
|
||||
Assert::IsFalse(workArea == nullptr);
|
||||
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
||||
|
||||
auto* zoneSet{ workArea->ZoneSet() };
|
||||
Assert::IsNotNull(zoneSet);
|
||||
Assert::AreEqual(static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::Custom), static_cast<int>(zoneSet->LayoutType()));
|
||||
Assert::IsTrue(FancyZonesUtils::GuidFromString(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}").value() == zoneSet->Id());
|
||||
Assert::IsNotNull(workArea->GetLayout().get());
|
||||
|
||||
const auto& actualLayout = workArea->GetLayout();
|
||||
Assert::AreEqual(static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::Custom), static_cast<int>(actualLayout->Type()));
|
||||
Assert::IsTrue(FancyZonesUtils::GuidFromString(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}").value() == actualLayout->Id());
|
||||
}
|
||||
|
||||
TEST_METHOD (CreateWorkAreaWithTemplateDefault)
|
||||
@@ -163,11 +168,12 @@ namespace FancyZonesUnitTests
|
||||
Assert::IsFalse(workArea == nullptr);
|
||||
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
||||
|
||||
auto* zoneSet{ workArea->ZoneSet() };
|
||||
Assert::IsNotNull(zoneSet);
|
||||
Assert::AreEqual(static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::Grid), static_cast<int>(zoneSet->LayoutType()));
|
||||
Assert::AreEqual(static_cast<size_t>(4), zoneSet->GetZones().size());
|
||||
Assert::IsTrue(GUID_NULL == zoneSet->Id());
|
||||
Assert::IsNotNull(workArea->GetLayout().get());
|
||||
|
||||
const auto& actualLayout = workArea->GetLayout();
|
||||
Assert::AreEqual(static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::Grid), static_cast<int>(actualLayout->Type()));
|
||||
Assert::AreEqual(static_cast<size_t>(4), actualLayout->Zones().size());
|
||||
Assert::IsTrue(GUID_NULL == actualLayout->Id());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -255,33 +261,17 @@ namespace FancyZonesUnitTests
|
||||
|
||||
const auto window = Mocks::Window();
|
||||
workArea->MoveSizeEnter(window);
|
||||
workArea->MoveSizeUpdate({ 20, 20 }, true, true);
|
||||
|
||||
const auto expected = S_OK;
|
||||
const auto actual = workArea->MoveSizeEnd(window, POINT{ 0, 0 });
|
||||
const auto actual = workArea->MoveSizeEnd(window);
|
||||
Assert::AreEqual(expected, actual);
|
||||
|
||||
const auto zoneSet = workArea->ZoneSet();
|
||||
zoneSet->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
const auto actualZoneIndexSet = zoneSet->GetZoneIndexSetFromWindow(window);
|
||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||
const auto actualZoneIndexSet = layoutWindows->GetZoneIndexSetFromWindow(window);
|
||||
Assert::IsFalse(std::vector<ZoneIndex>{} == actualZoneIndexSet);
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveSizeEndWindowNotAdded)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
|
||||
const auto window = Mocks::Window();
|
||||
workArea->MoveSizeEnter(window);
|
||||
|
||||
const auto expected = S_OK;
|
||||
const auto actual = workArea->MoveSizeEnd(window, POINT{ -100, -100 });
|
||||
Assert::AreEqual(expected, actual);
|
||||
|
||||
const auto zoneSet = workArea->ZoneSet();
|
||||
const auto actualZoneIndexSet = zoneSet->GetZoneIndexSetFromWindow(window);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == actualZoneIndexSet);
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveSizeEndDifferentWindows)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
@@ -290,7 +280,7 @@ namespace FancyZonesUnitTests
|
||||
workArea->MoveSizeEnter(window);
|
||||
|
||||
const auto expected = E_INVALIDARG;
|
||||
const auto actual = workArea->MoveSizeEnd(Mocks::Window(), POINT{ 0, 0 });
|
||||
const auto actual = workArea->MoveSizeEnd(Mocks::Window());
|
||||
|
||||
Assert::AreEqual(expected, actual);
|
||||
}
|
||||
@@ -300,74 +290,14 @@ namespace FancyZonesUnitTests
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
|
||||
const auto expected = E_INVALIDARG;
|
||||
const auto actual = workArea->MoveSizeEnd(Mocks::Window(), POINT{ 0, 0 });
|
||||
const auto actual = workArea->MoveSizeEnd(Mocks::Window());
|
||||
|
||||
Assert::AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveSizeEndInvalidPoint)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
|
||||
const auto window = Mocks::Window();
|
||||
workArea->MoveSizeEnter(window);
|
||||
|
||||
const auto expected = S_OK;
|
||||
const auto actual = workArea->MoveSizeEnd(window, POINT{ -1, -1 });
|
||||
Assert::AreEqual(expected, actual);
|
||||
|
||||
const auto zoneSet = workArea->ZoneSet();
|
||||
zoneSet->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
const auto actualZoneIndex = zoneSet->GetZoneIndexSetFromWindow(window);
|
||||
Assert::IsFalse(std::vector<ZoneIndex>{} == actualZoneIndex); // with invalid point zone remains the same
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByIndex)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
Assert::IsNotNull(workArea->ZoneSet());
|
||||
|
||||
workArea->MoveWindowIntoZoneByIndex(Mocks::Window(), 0);
|
||||
|
||||
const auto actual = workArea->ZoneSet();
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByDirectionAndIndex)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
Assert::IsNotNull(workArea->ZoneSet());
|
||||
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
const auto& appHistoryArray = actualAppZoneHistory.begin()->second;
|
||||
Assert::AreEqual((size_t)1, appHistoryArray.size());
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray[0].zoneIndexSet);
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByDirectionManyTimes)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
Assert::IsNotNull(workArea->ZoneSet());
|
||||
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
const auto& appHistoryArray = actualAppZoneHistory.begin()->second;
|
||||
Assert::AreEqual((size_t)1, appHistoryArray.size());
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == appHistoryArray[0].zoneIndexSet);
|
||||
}
|
||||
|
||||
TEST_METHOD (SaveWindowProcessToZoneIndexNullptrWindow)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
Assert::IsNotNull(workArea->ZoneSet());
|
||||
|
||||
workArea->SaveWindowProcessToZoneIndex(nullptr);
|
||||
|
||||
@@ -378,10 +308,9 @@ namespace FancyZonesUnitTests
|
||||
TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAdded)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
Assert::IsNotNull(workArea->ZoneSet());
|
||||
|
||||
auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->ZoneSet()->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
workArea->GetLayout()->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
|
||||
workArea->SaveWindowProcessToZoneIndex(window);
|
||||
|
||||
@@ -392,22 +321,21 @@ namespace FancyZonesUnitTests
|
||||
TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAddedWithFilledAppZoneHistory)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
Assert::IsNotNull(workArea->ZoneSet());
|
||||
|
||||
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
const auto processPath = get_process_path(window);
|
||||
const auto deviceId = workArea->UniqueId();
|
||||
const auto zoneSetId = workArea->ZoneSet()->Id();
|
||||
const auto& layoutId = workArea->GetLayout()->Id();
|
||||
|
||||
// fill app zone history map
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, deviceId, Helpers::GuidToString(zoneSetId), { 0 }));
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, deviceId, Helpers::GuidToString(layoutId), { 0 }));
|
||||
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
||||
const auto& appHistoryArray1 = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
||||
Assert::AreEqual((size_t)1, appHistoryArray1.size());
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray1[0].zoneIndexSet);
|
||||
|
||||
// add zone without window
|
||||
workArea->ZoneSet()->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
workArea->GetLayout()->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
|
||||
workArea->SaveWindowProcessToZoneIndex(window);
|
||||
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
||||
@@ -419,18 +347,16 @@ namespace FancyZonesUnitTests
|
||||
TEST_METHOD (SaveWindowProcessToZoneIndexWindowAdded)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
Assert::IsNotNull(workArea->ZoneSet());
|
||||
|
||||
|
||||
auto window = Mocks::WindowCreate(m_hInst);
|
||||
const auto processPath = get_process_path(window);
|
||||
const auto deviceId = workArea->UniqueId();
|
||||
const auto zoneSetId = workArea->ZoneSet()->Id();
|
||||
const auto& layoutId = workArea->GetLayout()->Id();
|
||||
|
||||
workArea->ZoneSet()->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
workArea->MoveWindowIntoZoneByIndex(window, 0);
|
||||
|
||||
//fill app zone history map
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, deviceId, Helpers::GuidToString(zoneSetId), { 2 }));
|
||||
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, deviceId, Helpers::GuidToString(layoutId), { 2 }));
|
||||
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
||||
const auto& appHistoryArray = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
||||
Assert::AreEqual((size_t)1, appHistoryArray.size());
|
||||
@@ -440,7 +366,7 @@ namespace FancyZonesUnitTests
|
||||
|
||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||
const auto& expected = workArea->ZoneSet()->GetZoneIndexSetFromWindow(window);
|
||||
const auto& expected = workArea->GetLayoutWindows()->GetZoneIndexSetFromWindow(window);
|
||||
const auto& actual = appHistoryArray[0].zoneIndexSet;
|
||||
Assert::IsTrue(expected == actual);
|
||||
}
|
||||
@@ -448,8 +374,7 @@ namespace FancyZonesUnitTests
|
||||
TEST_METHOD (WhenWindowIsNotResizablePlacingItIntoTheZoneShouldNotResizeIt)
|
||||
{
|
||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
||||
Assert::IsNotNull(workArea->ZoneSet());
|
||||
|
||||
|
||||
auto window = Mocks::WindowCreate(m_hInst);
|
||||
|
||||
int originalWidth = 450;
|
||||
@@ -458,7 +383,7 @@ namespace FancyZonesUnitTests
|
||||
SetWindowPos(window, nullptr, 150, 150, originalWidth, originalHeight, SWP_SHOWWINDOW);
|
||||
SetWindowLong(window, GWL_STYLE, GetWindowLong(window, GWL_STYLE) & ~WS_SIZEBOX);
|
||||
|
||||
workArea->ZoneSet()->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
workArea->GetLayout()->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_LEFT, true);
|
||||
|
||||
RECT inZoneRect;
|
||||
@@ -467,4 +392,425 @@ namespace FancyZonesUnitTests
|
||||
Assert::AreEqual(originalHeight, (int)inZoneRect.bottom - (int)inZoneRect.top);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CLASS (WorkAreaMoveWindowUnitTests)
|
||||
{
|
||||
const std::wstring m_virtualDesktopIdStr = L"{A998CA86-F08D-4BCA-AED8-77F5C8FC9925}";
|
||||
const FancyZonesDataTypes::WorkAreaId m_uniqueId{
|
||||
.monitorId = {
|
||||
.monitor = Mocks::Monitor(),
|
||||
.deviceId = {
|
||||
.id = L"DELA026",
|
||||
.instanceId = L"5&10a58c63&0&UID16777488",
|
||||
.number = 1,
|
||||
},
|
||||
.serialNumber = L"serial-number"
|
||||
},
|
||||
.virtualDesktopId = FancyZonesUtils::GuidFromString(m_virtualDesktopIdStr).value()
|
||||
};
|
||||
|
||||
FancyZonesDataTypes::WorkAreaId m_parentUniqueId; // default empty
|
||||
|
||||
HINSTANCE m_hInst{};
|
||||
HMONITOR m_monitor{};
|
||||
|
||||
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_uniqueId.monitorId.deviceId.id));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorInstanceID, json::value(m_uniqueId.monitorId.deviceId.instanceId));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorSerialNumberID, json::value(m_uniqueId.monitorId.serialNumber));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorNumberID, json::value(m_uniqueId.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_uniqueId.monitorId.deviceId.id));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorInstanceID, json::value(m_uniqueId.monitorId.deviceId.instanceId));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorSerialNumberID, json::value(m_uniqueId.monitorId.serialNumber));
|
||||
workAreaId.SetNamedValue(NonLocalizable::AppliedLayoutsIds::MonitorNumberID, json::value(m_uniqueId.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)
|
||||
{
|
||||
AppZoneHistory::instance().LoadData();
|
||||
AppliedLayouts::instance().LoadData();
|
||||
}
|
||||
|
||||
TEST_METHOD_CLEANUP(CleanUp)
|
||||
{
|
||||
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
||||
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
||||
}
|
||||
|
||||
TEST_METHOD (EmptyZonesMoveLeftByIndex)
|
||||
{
|
||||
// prepare
|
||||
PrepareEmptyLayout();
|
||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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{ (ZoneIndex)workArea->GetLayout()->Zones().size() - 1 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveAppliedWindowByIndexNoCycle)
|
||||
{
|
||||
// prepare
|
||||
PrepareGridLayout();
|
||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
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->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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 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 = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
||||
const auto window = Mocks::WindowCreate(m_hInst);
|
||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,25 +22,38 @@ namespace FancyZonesUnitTests
|
||||
public:
|
||||
TEST_METHOD(TestCreateZone)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone(m_zoneRect, 1);
|
||||
Assert::IsNotNull(&zone);
|
||||
CustomAssert::AreEqual(m_zoneRect, zone->GetZoneRect());
|
||||
Zone zone(m_zoneRect, 1);
|
||||
Assert::IsTrue(zone.IsValid());
|
||||
CustomAssert::AreEqual(m_zoneRect, zone.GetZoneRect());
|
||||
}
|
||||
|
||||
TEST_METHOD(TestCreateZoneZeroRect)
|
||||
{
|
||||
RECT zoneRect{ 0, 0, 0, 0 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect, 1);
|
||||
Assert::IsNotNull(&zone);
|
||||
CustomAssert::AreEqual(zoneRect, zone->GetZoneRect());
|
||||
Zone zone(zoneRect, 1);
|
||||
Assert::IsTrue(zone.IsValid());
|
||||
CustomAssert::AreEqual(zoneRect, zone.GetZoneRect());
|
||||
}
|
||||
|
||||
TEST_METHOD(GetSetId)
|
||||
{
|
||||
constexpr ZoneIndex zoneId = 123;
|
||||
winrt::com_ptr<IZone> zone = MakeZone(m_zoneRect, zoneId);
|
||||
Zone zone(m_zoneRect, zoneId);
|
||||
|
||||
Assert::AreEqual(zone->Id(), zoneId);
|
||||
Assert::IsTrue(zone.IsValid());
|
||||
Assert::AreEqual(zone.Id(), zoneId);
|
||||
}
|
||||
|
||||
TEST_METHOD(InvalidId)
|
||||
{
|
||||
Zone zone(m_zoneRect, -1);
|
||||
Assert::IsFalse(zone.IsValid());
|
||||
}
|
||||
|
||||
TEST_METHOD (InvalidRect)
|
||||
{
|
||||
Zone zone({ 100, 100, 99, 101 }, 1);
|
||||
Assert::IsFalse(zone.IsValid());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,851 +0,0 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <FancyZonesLib/FancyZonesData/LayoutDefaults.h>
|
||||
#include <FancyZonesLib/FancyZonesData/CustomLayouts.h>
|
||||
#include "FancyZonesLib\ZoneIndexSetBitmask.h"
|
||||
#include "FancyZonesLib\ZoneSet.h"
|
||||
#include <FancyZonesLib/util.h>
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace FancyZonesDataTypes;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS (ZoneSetUnitTests)
|
||||
{
|
||||
GUID m_id;
|
||||
const ZoneSetLayoutType m_layoutType = ZoneSetLayoutType::Grid;
|
||||
|
||||
winrt::com_ptr<IZoneSet> m_set;
|
||||
|
||||
TEST_METHOD_INITIALIZE(Init)
|
||||
{
|
||||
auto hres = CoCreateGuid(&m_id);
|
||||
Assert::AreEqual(S_OK, hres);
|
||||
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, m_layoutType, Mocks::Monitor(), DefaultValues::SensitivityRadius, OverlappingZonesAlgorithm::Smallest);
|
||||
m_set = MakeZoneSet(m_config);
|
||||
}
|
||||
|
||||
TEST_METHOD_CLEANUP(CleanUp)
|
||||
{
|
||||
std::filesystem::remove_all(CustomLayouts::CustomLayoutsFileName());
|
||||
}
|
||||
|
||||
void compareZones(const winrt::com_ptr<IZone>& expected, const winrt::com_ptr<IZone>& actual)
|
||||
{
|
||||
Assert::AreEqual(expected->Id(), actual->Id());
|
||||
Assert::AreEqual(expected->GetZoneRect().left, actual->GetZoneRect().left);
|
||||
Assert::AreEqual(expected->GetZoneRect().right, actual->GetZoneRect().right);
|
||||
Assert::AreEqual(expected->GetZoneRect().top, actual->GetZoneRect().top);
|
||||
Assert::AreEqual(expected->GetZoneRect().bottom, actual->GetZoneRect().bottom);
|
||||
}
|
||||
|
||||
void saveCustomLayout(const std::vector<RECT>& zones)
|
||||
{
|
||||
json::JsonObject root{};
|
||||
json::JsonArray layoutsArray{};
|
||||
|
||||
json::JsonObject canvasLayoutJson{};
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::UuidID, json::value(FancyZonesUtils::GuidToString(m_id).value()));
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::NameID, json::value(L"Custom canvas layout"));
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::TypeID, json::value(NonLocalizable::CustomLayoutsIds::CanvasID));
|
||||
|
||||
json::JsonObject info{};
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::RefWidthID, json::value(1920));
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::RefHeightID, json::value(1080));
|
||||
|
||||
json::JsonArray zonesArray{};
|
||||
for (const auto& zoneRect : zones)
|
||||
{
|
||||
json::JsonObject zone{};
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::XID, json::value(zoneRect.left));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::YID, json::value(zoneRect.top));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::WidthID, json::value(zoneRect.right - zoneRect.left));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::HeightID, json::value(zoneRect.bottom - zoneRect.top));
|
||||
zonesArray.Append(zone);
|
||||
}
|
||||
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::ZonesID, zonesArray);
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::InfoID, info);
|
||||
layoutsArray.Append(canvasLayoutJson);
|
||||
root.SetNamedValue(NonLocalizable::CustomLayoutsIds::CustomLayoutsArrayID, layoutsArray);
|
||||
json::to_file(CustomLayouts::CustomLayoutsFileName(), root);
|
||||
|
||||
CustomLayouts::instance().LoadData();
|
||||
}
|
||||
|
||||
public:
|
||||
TEST_METHOD (TestCreateZoneSet)
|
||||
{
|
||||
Assert::IsNotNull(&m_set);
|
||||
CustomAssert::AreEqual(m_set->Id(), m_id);
|
||||
CustomAssert::AreEqual(m_set->LayoutType(), m_layoutType);
|
||||
}
|
||||
|
||||
TEST_METHOD (TestCreateZoneSetGuidEmpty)
|
||||
{
|
||||
GUID zoneSetId{};
|
||||
ZoneSetConfig config(zoneSetId, m_layoutType, Mocks::Monitor(), DefaultValues::SensitivityRadius);
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
Assert::IsNotNull(&set);
|
||||
CustomAssert::AreEqual(set->Id(), zoneSetId);
|
||||
CustomAssert::AreEqual(set->LayoutType(), m_layoutType);
|
||||
}
|
||||
|
||||
TEST_METHOD (EmptyZones)
|
||||
{
|
||||
auto zones = m_set->GetZones();
|
||||
Assert::AreEqual((size_t)0, zones.size());
|
||||
}
|
||||
|
||||
TEST_METHOD (MakeZoneFromZeroRect)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 0, 0 }, 1);
|
||||
Assert::IsNotNull(zone.get());
|
||||
}
|
||||
|
||||
TEST_METHOD (MakeZoneFromInvalidRectWidth)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 100, 100, 99, 101 }, 1);
|
||||
Assert::IsNull(zone.get());
|
||||
}
|
||||
|
||||
TEST_METHOD (MakeZoneFromInvalidRectHeight)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 100, 100, 101, 99 }, 1);
|
||||
Assert::IsNull(zone.get());
|
||||
}
|
||||
|
||||
TEST_METHOD (MakeZoneFromInvalidRectCoords)
|
||||
{
|
||||
const int invalid = ZoneConstants::MAX_NEGATIVE_SPACING - 1;
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ invalid, invalid, invalid, invalid }, 1);
|
||||
Assert::IsNull(zone.get());
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointEmpty)
|
||||
{
|
||||
auto actual = m_set->ZonesFromPoint(POINT{ 0, 0 });
|
||||
Assert::IsTrue(actual.size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointInner)
|
||||
{
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
|
||||
auto actual = m_set->ZonesFromPoint(POINT{ 1, 1 });
|
||||
Assert::IsTrue(actual.size() == 1);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointBorder)
|
||||
{
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
|
||||
Assert::IsTrue(m_set->ZonesFromPoint(POINT{ 0, 0 }).size() == 1);
|
||||
Assert::IsTrue(m_set->ZonesFromPoint(POINT{ 1920, 1080 }).size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointOuter)
|
||||
{
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
|
||||
auto actual = m_set->ZonesFromPoint(POINT{ 1921, 1080 });
|
||||
Assert::IsTrue(actual.size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointOverlapping)
|
||||
{
|
||||
// prepare layout with overlapping zones
|
||||
saveCustomLayout({ RECT{ 0, 0, 100, 100 }, RECT{ 10, 10, 90, 90 }, RECT{ 10, 10, 150, 150 }, RECT{ 10, 10, 50, 50 } });
|
||||
|
||||
ZoneSetConfig config = ZoneSetConfig(m_id, FancyZonesDataTypes::ZoneSetLayoutType::Custom, Mocks::Monitor(), DefaultValues::SensitivityRadius, OverlappingZonesAlgorithm::Smallest);
|
||||
auto set = MakeZoneSet(config);
|
||||
set->CalculateZones(RECT{0,0,1920,1080}, 4, 0);
|
||||
|
||||
// zone4 is expected because it's the smallest one, and it's considered to be inside
|
||||
// since Multizones support
|
||||
auto zones = set->ZonesFromPoint(POINT{ 50, 50 });
|
||||
Assert::IsTrue(zones.size() == 1);
|
||||
|
||||
auto expected = MakeZone({ 10, 10, 50, 50 }, 3);
|
||||
auto actual = set->GetZones()[zones[0]];
|
||||
compareZones(expected, actual);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointMultizone)
|
||||
{
|
||||
// prepare layout with overlapping zones
|
||||
saveCustomLayout({ RECT{ 0, 0, 100, 100 }, RECT{ 100, 0, 200, 100 }, RECT{ 0, 100, 100, 200 }, RECT{ 100, 100, 200, 200 } });
|
||||
|
||||
ZoneSetConfig config = ZoneSetConfig(m_id, FancyZonesDataTypes::ZoneSetLayoutType::Custom, Mocks::Monitor(), DefaultValues::SensitivityRadius, OverlappingZonesAlgorithm::Smallest);
|
||||
auto set = MakeZoneSet(config);
|
||||
set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 4, 0);
|
||||
|
||||
auto actual = set->ZonesFromPoint(POINT{ 50, 100 });
|
||||
Assert::IsTrue(actual.size() == 2);
|
||||
|
||||
auto zone1 = MakeZone({ 0, 0, 100, 100 }, 0);
|
||||
compareZones(zone1, set->GetZones()[actual[0]]);
|
||||
|
||||
auto zone3 = MakeZone({ 0, 100, 100, 200 }, 2);
|
||||
compareZones(zone3, set->GetZones()[actual[1]]);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneIndexFromWindowUnknown)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
HWND workArea = Mocks::Window();
|
||||
m_set->CalculateZones(RECT{0,0,1920, 1080}, 1, 0);
|
||||
m_set->MoveWindowIntoZoneByIndexSet(window, workArea, { 0 });
|
||||
|
||||
auto actual = m_set->GetZoneIndexSetFromWindow(Mocks::Window());
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == actual);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneIndexFromWindowNull)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
HWND workArea = Mocks::Window();
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
m_set->MoveWindowIntoZoneByIndexSet(window, workArea, { 0 });
|
||||
|
||||
auto actual = m_set->GetZoneIndexSetFromWindow(nullptr);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == actual);
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByIndex)
|
||||
{
|
||||
// prepare layout with overlapping zones
|
||||
saveCustomLayout({ RECT{ 0, 0, 100, 100 }, RECT{ 0, 0, 100, 100 }, RECT{ 0, 0, 100, 100 } });
|
||||
|
||||
ZoneSetConfig config = ZoneSetConfig(m_id, FancyZonesDataTypes::ZoneSetLayoutType::Custom, Mocks::Monitor(), DefaultValues::SensitivityRadius, OverlappingZonesAlgorithm::Smallest);
|
||||
auto set = MakeZoneSet(config);
|
||||
set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 3, 0);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 1);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByIndexWithNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByIndexWithInvalidIndex)
|
||||
{
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 100);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByIndexSeveralTimesSameWindow)
|
||||
{
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 3, 0);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 1);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 2);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByIndexSeveralTimesSameIndex)
|
||||
{
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 3, 0);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByPointEmpty)
|
||||
{
|
||||
m_set->MoveWindowIntoZoneByPoint(Mocks::Window(), Mocks::Window(), POINT{ 0, 0 });
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByPointOuterPoint)
|
||||
{
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
|
||||
auto window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByPoint(window, Mocks::Window(), POINT{ 1921, 1081 });
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{} == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByPointInnerPoint)
|
||||
{
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
||||
|
||||
auto window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByPoint(window, Mocks::Window(), POINT{ 50, 50 });
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByPointInnerPointOverlappingZones)
|
||||
{
|
||||
saveCustomLayout({ RECT{ 0, 0, 100, 100 }, RECT{ 10, 10, 90, 90 } });
|
||||
|
||||
ZoneSetConfig config = ZoneSetConfig(m_id, FancyZonesDataTypes::ZoneSetLayoutType::Custom, Mocks::Monitor(), DefaultValues::SensitivityRadius, OverlappingZonesAlgorithm::Smallest);
|
||||
auto set = MakeZoneSet(config);
|
||||
set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 3, 0);
|
||||
|
||||
auto window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByPoint(window, Mocks::Window(), POINT{ 50, 50 });
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByPointDropAddWindow)
|
||||
{
|
||||
saveCustomLayout({ RECT{ 0, 0, 100, 100 }, RECT{ 10, 10, 90, 90 } });
|
||||
|
||||
ZoneSetConfig config = ZoneSetConfig(m_id, FancyZonesDataTypes::ZoneSetLayoutType::Custom, Mocks::Monitor(), DefaultValues::SensitivityRadius, OverlappingZonesAlgorithm::Smallest);
|
||||
auto set = MakeZoneSet(config);
|
||||
set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 3, 0);
|
||||
|
||||
const auto window = Mocks::Window();
|
||||
const auto workArea = Mocks::Window();
|
||||
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
set->MoveWindowIntoZoneByPoint(window, Mocks::Window(), POINT{ 50, 50 });
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
};
|
||||
|
||||
// MoveWindowIntoZoneByDirectionAndIndex is complicated enough to warrant it's own test class
|
||||
TEST_CLASS (ZoneSetsMoveWindowIntoZoneByDirectionUnitTests)
|
||||
{
|
||||
winrt::com_ptr<IZoneSet> m_set;
|
||||
winrt::com_ptr<IZone> m_zone1;
|
||||
winrt::com_ptr<IZone> m_zone2;
|
||||
winrt::com_ptr<IZone> m_zone3;
|
||||
|
||||
TEST_METHOD_INITIALIZE(Initialize)
|
||||
{
|
||||
ZoneSetConfig config({}, ZoneSetLayoutType::Grid, Mocks::Monitor(), DefaultValues::SensitivityRadius);
|
||||
m_set = MakeZoneSet(config);
|
||||
m_set->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 3, 10);
|
||||
}
|
||||
|
||||
TEST_METHOD (EmptyZonesLeft)
|
||||
{
|
||||
ZoneSetConfig config({}, ZoneSetLayoutType::Custom, Mocks::Monitor(), DefaultValues::SensitivityRadius);
|
||||
auto set = MakeZoneSet(config);
|
||||
|
||||
set->MoveWindowIntoZoneByDirectionAndIndex(Mocks::Window(), Mocks::Window(), VK_LEFT, true);
|
||||
}
|
||||
|
||||
TEST_METHOD (EmptyZonesRight)
|
||||
{
|
||||
ZoneSetConfig config({}, ZoneSetLayoutType::Custom, Mocks::Monitor(), DefaultValues::SensitivityRadius);
|
||||
auto set = MakeZoneSet(config);
|
||||
|
||||
set->MoveWindowIntoZoneByDirectionAndIndex(Mocks::Window(), Mocks::Window(), VK_RIGHT, true);
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveRightNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveLeftNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveRightTwice)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveLeftTwice)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveRightMoreThanZonesCount)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
for (int i = 0; i <= m_set->GetZones().size(); i++)
|
||||
{
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
}
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveLeftMoreThanZonesCount)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
for (int i = 0; i <= m_set->GetZones().size(); i++)
|
||||
{
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
}
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByDirectionRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveRightWithSameWindowAdded)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndexSet(window, Mocks::Window(), { 0, 1 });
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0, 1 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveRightWithDifferentWindowsAdded)
|
||||
{
|
||||
HWND window1 = Mocks::Window();
|
||||
HWND window2 = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window1, Mocks::Window(), { 0 });
|
||||
m_set->MoveWindowIntoZoneByIndex(window2, Mocks::Window(), { 1 });
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window2));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window1, Mocks::Window(), VK_RIGHT, true);
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window2));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window1, Mocks::Window(), VK_RIGHT, true);
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window2));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByDirectionLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 2);
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveLeftWithSameWindowAdded)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndexSet(window, Mocks::Window(), { 1, 2 });
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1, 2 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveLeftWithDifferentWindowsAdded)
|
||||
{
|
||||
HWND window1 = Mocks::Window();
|
||||
HWND window2 = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window1, Mocks::Window(), 1);
|
||||
m_set->MoveWindowIntoZoneByIndex(window2, Mocks::Window(), 2);
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window2));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window2, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window2));
|
||||
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window2, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 1 } == m_set->GetZoneIndexSetFromWindow(window1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window2));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByDirectionWrapAroundRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 2);
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveWindowIntoZoneByDirectionWrapAroundLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, true);
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == m_set->GetZoneIndexSetFromWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveSecondWindowIntoSameZone)
|
||||
{
|
||||
HWND window1 = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window1, Mocks::Window(), 0);
|
||||
|
||||
HWND window2 = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window2, Mocks::Window(), VK_RIGHT, true);
|
||||
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window1));
|
||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == m_set->GetZoneIndexSetFromWindow(window2));
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveRightMoreThanZoneCountReturnsFalse)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
for (size_t i = 0; i < m_set->GetZones().size() - 1; ++i)
|
||||
{
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, false);
|
||||
}
|
||||
bool moreZonesInLayout = m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_RIGHT, false);
|
||||
Assert::IsFalse(moreZonesInLayout);
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveLeftMoreThanZoneCountReturnsFalse)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
m_set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 2);
|
||||
for (size_t i = 0; i < m_set->GetZones().size() - 1; ++i)
|
||||
{
|
||||
m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, false);
|
||||
}
|
||||
bool moreZonesInLayout = m_set->MoveWindowIntoZoneByDirectionAndIndex(window, Mocks::Window(), VK_LEFT, false);
|
||||
Assert::IsFalse(moreZonesInLayout);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CLASS (ZoneSetCalculateZonesUnitTests)
|
||||
{
|
||||
GUID m_id;
|
||||
const ZoneSetLayoutType m_layoutType = ZoneSetLayoutType::Custom;
|
||||
winrt::com_ptr<IZoneSet> m_set;
|
||||
|
||||
HMONITOR m_monitor{};
|
||||
const std::array<MONITORINFO, 9> m_popularMonitors{
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1024, .bottom = 768 } },
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1280, .bottom = 720 } },
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1280, .bottom = 800 } },
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1280, .bottom = 1024 } },
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1366, .bottom = 768 } },
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1440, .bottom = 900 } },
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1536, .bottom = 864 } },
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1600, .bottom = 900 } },
|
||||
MONITORINFO{ .cbSize = sizeof(MONITORINFO), .rcWork{ .left = 0, .top = 0, .right = 1920, .bottom = 1080 } }
|
||||
};
|
||||
|
||||
void checkZones(const winrt::com_ptr<IZoneSet>& set, ZoneSetLayoutType type, size_t expectedCount, MONITORINFO monitorInfo)
|
||||
{
|
||||
auto zones = set->GetZones();
|
||||
Assert::AreEqual(expectedCount, zones.size());
|
||||
|
||||
int zoneId = 0;
|
||||
for (const auto& zone : zones)
|
||||
{
|
||||
Assert::IsTrue(set->IsZoneEmpty(zoneId));
|
||||
|
||||
const auto& zoneRect = zone.second->GetZoneRect();
|
||||
Assert::IsTrue(zoneRect.left >= 0, L"left border is less than zero");
|
||||
Assert::IsTrue(zoneRect.top >= 0, L"top border is less than zero");
|
||||
|
||||
Assert::IsTrue(zoneRect.left < zoneRect.right, L"rect.left >= rect.right");
|
||||
Assert::IsTrue(zoneRect.top < zoneRect.bottom, L"rect.top >= rect.bottom");
|
||||
|
||||
if (type != ZoneSetLayoutType::Focus)
|
||||
{
|
||||
Assert::IsTrue(zoneRect.right <= monitorInfo.rcWork.right, L"right border is bigger than monitor work space");
|
||||
Assert::IsTrue(zoneRect.bottom <= monitorInfo.rcWork.bottom, L"bottom border is bigger than monitor work space");
|
||||
}
|
||||
|
||||
zoneId++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD_INITIALIZE(Init)
|
||||
{
|
||||
m_id = FancyZonesUtils::GuidFromString(L"{33A2B101-06E0-437B-A61E-CDBECF502906}").value();
|
||||
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, m_layoutType, m_monitor, DefaultValues::SensitivityRadius);
|
||||
m_set = MakeZoneSet(m_config);
|
||||
}
|
||||
|
||||
public:
|
||||
TEST_METHOD (ValidValues)
|
||||
{
|
||||
const int spacing = 10;
|
||||
const int zoneCount = 10;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, static_cast<ZoneSetLayoutType>(type), m_monitor, DefaultValues::SensitivityRadius);
|
||||
|
||||
for (const auto& monitorInfo : m_popularMonitors)
|
||||
{
|
||||
auto set = MakeZoneSet(m_config);
|
||||
auto result = set->CalculateZones(monitorInfo.rcWork, zoneCount, spacing);
|
||||
Assert::IsTrue(result);
|
||||
checkZones(set, static_cast<ZoneSetLayoutType>(type), zoneCount, monitorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_METHOD (InvalidMonitorInfo)
|
||||
{
|
||||
const int spacing = 10;
|
||||
const int zoneCount = 10;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, static_cast<ZoneSetLayoutType>(type), m_monitor, DefaultValues::SensitivityRadius);
|
||||
auto set = MakeZoneSet(m_config);
|
||||
|
||||
MONITORINFO info{};
|
||||
auto result = set->CalculateZones(info.rcWork, zoneCount, spacing);
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (ZeroSpacing)
|
||||
{
|
||||
const int spacing = 0;
|
||||
const int zoneCount = 10;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, static_cast<ZoneSetLayoutType>(type), m_monitor, DefaultValues::SensitivityRadius);
|
||||
|
||||
for (const auto& monitorInfo : m_popularMonitors)
|
||||
{
|
||||
auto set = MakeZoneSet(m_config);
|
||||
auto result = set->CalculateZones(monitorInfo.rcWork, zoneCount, spacing);
|
||||
Assert::IsTrue(result);
|
||||
checkZones(set, static_cast<ZoneSetLayoutType>(type), zoneCount, monitorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (LargeNegativeSpacing)
|
||||
{
|
||||
const int spacing = ZoneConstants::MAX_NEGATIVE_SPACING - 1;
|
||||
const int zoneCount = 10;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, static_cast<ZoneSetLayoutType>(type), m_monitor, DefaultValues::SensitivityRadius);
|
||||
auto set = MakeZoneSet(m_config);
|
||||
|
||||
for (const auto& monitorInfo : m_popularMonitors)
|
||||
{
|
||||
auto result = set->CalculateZones(monitorInfo.rcWork, zoneCount, spacing);
|
||||
if (type == static_cast<int>(ZoneSetLayoutType::Focus))
|
||||
{
|
||||
//Focus doesn't depends on spacing
|
||||
Assert::IsTrue(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (HorizontallyBigSpacing)
|
||||
{
|
||||
const int zoneCount = 10;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, static_cast<ZoneSetLayoutType>(type), m_monitor, DefaultValues::SensitivityRadius);
|
||||
auto set = MakeZoneSet(m_config);
|
||||
|
||||
for (const auto& monitorInfo : m_popularMonitors)
|
||||
{
|
||||
const int spacing = monitorInfo.rcWork.right;
|
||||
auto result = set->CalculateZones(monitorInfo.rcWork, zoneCount, spacing);
|
||||
if (type == static_cast<int>(ZoneSetLayoutType::Focus))
|
||||
{
|
||||
//Focus doesn't depend on spacing
|
||||
Assert::IsTrue(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (VerticallyBigSpacing)
|
||||
{
|
||||
const int zoneCount = 10;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, static_cast<ZoneSetLayoutType>(type), m_monitor, DefaultValues::SensitivityRadius);
|
||||
auto set = MakeZoneSet(m_config);
|
||||
|
||||
for (const auto& monitorInfo : m_popularMonitors)
|
||||
{
|
||||
const int spacing = monitorInfo.rcWork.bottom;
|
||||
auto result = set->CalculateZones(monitorInfo.rcWork, zoneCount, spacing);
|
||||
if (type == static_cast<int>(ZoneSetLayoutType::Focus))
|
||||
{
|
||||
//Focus doesn't depend on spacing
|
||||
Assert::IsTrue(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (ZeroZoneCount)
|
||||
{
|
||||
const int spacing = 10;
|
||||
const int zoneCount = 0;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, static_cast<ZoneSetLayoutType>(type), m_monitor, DefaultValues::SensitivityRadius);
|
||||
auto set = MakeZoneSet(m_config);
|
||||
|
||||
for (const auto& monitorInfo : m_popularMonitors)
|
||||
{
|
||||
auto result = set->CalculateZones(monitorInfo.rcWork, zoneCount, spacing);
|
||||
Assert::IsFalse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (BigZoneCount)
|
||||
{
|
||||
const int zoneCount = 128; //editor limit
|
||||
const int spacing = 0;
|
||||
|
||||
for (int type = static_cast<int>(ZoneSetLayoutType::Focus); type < static_cast<int>(ZoneSetLayoutType::Custom); type++)
|
||||
{
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, static_cast<ZoneSetLayoutType>(type), m_monitor, DefaultValues::SensitivityRadius);
|
||||
|
||||
for (const auto& monitorInfo : m_popularMonitors)
|
||||
{
|
||||
auto set = MakeZoneSet(m_config);
|
||||
auto result = set->CalculateZones(monitorInfo.rcWork, zoneCount, spacing);
|
||||
Assert::IsTrue(result);
|
||||
checkZones(set, static_cast<ZoneSetLayoutType>(type), zoneCount, monitorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CLASS(ZoneIndexSetUnitTests)
|
||||
{
|
||||
TEST_METHOD (BitmaskFromIndexSetTest)
|
||||
{
|
||||
// prepare
|
||||
ZoneIndexSet set {0, 64};
|
||||
|
||||
// test
|
||||
ZoneIndexSetBitmask bitmask = ZoneIndexSetBitmask::FromIndexSet(set);
|
||||
Assert::AreEqual(static_cast<uint64_t>(1), bitmask.part1);
|
||||
Assert::AreEqual(static_cast<uint64_t>(1), bitmask.part2);
|
||||
}
|
||||
|
||||
TEST_METHOD(BitmaskToIndexSet)
|
||||
{
|
||||
// prepare
|
||||
ZoneIndexSetBitmask bitmask{
|
||||
.part1 = 1,
|
||||
.part2 = 1,
|
||||
};
|
||||
|
||||
// test
|
||||
ZoneIndexSet set = bitmask.ToIndexSet();
|
||||
Assert::AreEqual(static_cast<size_t>(2), set.size());
|
||||
Assert::AreEqual(static_cast<ZoneIndex>(0), set[0]);
|
||||
Assert::AreEqual(static_cast<ZoneIndex>(64), set[1]);
|
||||
}
|
||||
|
||||
TEST_METHOD (BitmaskConvertTest)
|
||||
{
|
||||
// prepare
|
||||
ZoneIndexSet set{ 53, 54, 55, 65, 66, 67 };
|
||||
|
||||
ZoneIndexSetBitmask bitmask = ZoneIndexSetBitmask::FromIndexSet(set);
|
||||
|
||||
// test
|
||||
ZoneIndexSet actual = bitmask.ToIndexSet();
|
||||
Assert::AreEqual(set.size(), actual.size());
|
||||
for (int i = 0; i < set.size(); i++)
|
||||
{
|
||||
Assert::AreEqual(set[i], actual[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (BitmaskConvert2Test)
|
||||
{
|
||||
// prepare
|
||||
ZoneIndexSet set;
|
||||
for (int i = 0; i < 128; i++)
|
||||
{
|
||||
set.push_back(i);
|
||||
}
|
||||
|
||||
ZoneIndexSetBitmask bitmask = ZoneIndexSetBitmask::FromIndexSet(set);
|
||||
|
||||
// test
|
||||
ZoneIndexSet actual = bitmask.ToIndexSet();
|
||||
|
||||
Assert::AreEqual(set.size(), actual.size());
|
||||
for (int i = 0; i < set.size(); i++)
|
||||
{
|
||||
Assert::AreEqual(set[i], actual[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user