2019-09-04 18:26:26 +02:00
|
|
|
#include "pch.h"
|
|
|
|
|
|
2020-02-10 14:59:51 +01:00
|
|
|
#include <filesystem>
|
|
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
#include <FancyZonesLib/WorkArea.h>
|
2022-01-27 15:21:15 +03:00
|
|
|
#include <FancyZonesLib/FancyZonesData/AppliedLayouts.h>
|
2022-01-24 14:54:17 +03:00
|
|
|
#include <FancyZonesLib/FancyZonesData/AppZoneHistory.h>
|
2022-10-25 17:55:36 +02:00
|
|
|
#include <FancyZonesLib/FancyZonesData/DefaultLayouts.h>
|
2019-12-17 11:21:46 +03:00
|
|
|
#include "Util.h"
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
#include <common/utils/process_path.h>
|
|
|
|
|
|
2019-09-04 18:26:26 +02:00
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
|
|
|
|
|
namespace FancyZonesUnitTests
|
|
|
|
|
{
|
2020-08-21 08:56:25 +03:00
|
|
|
const std::wstring m_deviceId = L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}";
|
|
|
|
|
const std::wstring m_virtualDesktopId = L"MyVirtualDesktopId";
|
|
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
TEST_CLASS (WorkAreaCreationUnitTests)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2022-07-01 17:29:02 +02:00
|
|
|
FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
|
|
|
|
FancyZonesDataTypes::WorkAreaId m_emptyUniqueId;
|
2020-08-21 08:56:25 +03:00
|
|
|
|
2022-08-15 16:40:10 +03:00
|
|
|
HINSTANCE m_hInst{};
|
|
|
|
|
HMONITOR m_monitor{};
|
|
|
|
|
|
2020-02-10 14:59:51 +01:00
|
|
|
TEST_METHOD_INITIALIZE(Init)
|
2022-01-27 15:21:15 +03:00
|
|
|
{
|
2022-07-01 17:29:02 +02:00
|
|
|
m_uniqueId.monitorId.deviceId.id = L"DELA026";
|
|
|
|
|
m_uniqueId.monitorId.deviceId.instanceId = L"5&10a58c63&0&UID16777488";
|
|
|
|
|
m_uniqueId.monitorId.serialNumber = L"serial-number";
|
2022-08-15 16:40:10 +03:00
|
|
|
m_uniqueId.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value();
|
2022-01-27 15:21:15 +03:00
|
|
|
|
|
|
|
|
AppZoneHistory::instance().LoadData();
|
|
|
|
|
AppliedLayouts::instance().LoadData();
|
2022-10-25 17:55:36 +02:00
|
|
|
DefaultLayouts::instance().LoadData();
|
2022-01-27 15:21:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD_CLEANUP(CleanUp)
|
|
|
|
|
{
|
|
|
|
|
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
|
|
|
|
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
2022-10-25 17:55:36 +02:00
|
|
|
|
|
|
|
|
std::filesystem::remove(DefaultLayouts::DefaultLayoutsFileName());
|
2022-01-27 15:21:15 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
TEST_METHOD (CreateWorkArea)
|
|
|
|
|
{
|
2022-10-25 17:55:36 +02:00
|
|
|
const auto defaultLayout = DefaultLayouts::instance().GetDefaultLayout();
|
|
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea({}, Mocks::Monitor(), m_uniqueId, m_emptyUniqueId);
|
|
|
|
|
Assert::IsFalse(workArea == nullptr);
|
|
|
|
|
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
2021-09-23 00:39:48 +03:00
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
auto* zoneSet{ workArea->ZoneSet() };
|
|
|
|
|
Assert::IsNotNull(zoneSet);
|
2022-10-25 17:55:36 +02:00
|
|
|
Assert::AreEqual(static_cast<int>(defaultLayout.type), static_cast<int>(zoneSet->LayoutType()));
|
|
|
|
|
Assert::AreEqual(static_cast<size_t>(defaultLayout.zoneCount), zoneSet->GetZones().size());
|
2022-06-14 16:45:45 +02:00
|
|
|
}
|
2020-12-15 15:16:09 +03:00
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
TEST_METHOD (CreateCombinedWorkArea)
|
|
|
|
|
{
|
2022-10-25 17:55:36 +02:00
|
|
|
const auto defaultLayout = DefaultLayouts::instance().GetDefaultLayout();
|
|
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea({}, {}, m_uniqueId, m_emptyUniqueId);
|
|
|
|
|
Assert::IsFalse(workArea == nullptr);
|
|
|
|
|
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
2020-12-15 15:16:09 +03:00
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
auto* zoneSet{ workArea->ZoneSet() };
|
|
|
|
|
Assert::IsNotNull(zoneSet);
|
2022-10-25 17:55:36 +02:00
|
|
|
Assert::AreEqual(static_cast<int>(defaultLayout.type), static_cast<int>(zoneSet->LayoutType()));
|
|
|
|
|
Assert::AreEqual(static_cast<size_t>(defaultLayout.zoneCount), zoneSet->GetZones().size());
|
2022-06-14 16:45:45 +02:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
TEST_METHOD (CreateWorkAreaClonedFromParent)
|
2021-01-27 21:33:52 +03:00
|
|
|
{
|
|
|
|
|
using namespace FancyZonesDataTypes;
|
2022-08-15 16:40:10 +03:00
|
|
|
|
2022-07-01 17:29:02 +02:00
|
|
|
FancyZonesDataTypes::WorkAreaId parentUniqueId;
|
|
|
|
|
parentUniqueId.monitorId.deviceId.id = L"DELA026";
|
|
|
|
|
parentUniqueId.monitorId.deviceId.instanceId = L"5&10a58c63&0&UID16777488";
|
|
|
|
|
parentUniqueId.monitorId.serialNumber = L"serial-number";
|
2022-06-14 16:45:45 +02:00
|
|
|
parentUniqueId.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC57}").value();
|
|
|
|
|
|
|
|
|
|
Layout layout{
|
|
|
|
|
.uuid = FancyZonesUtils::GuidFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC58}").value(),
|
|
|
|
|
.type = ZoneSetLayoutType::Rows,
|
|
|
|
|
.showSpacing = true,
|
|
|
|
|
.spacing = 10,
|
|
|
|
|
.zoneCount = 10,
|
|
|
|
|
.sensitivityRadius = 20,
|
|
|
|
|
};
|
2020-12-15 15:16:09 +03:00
|
|
|
|
2022-08-15 16:40:10 +03:00
|
|
|
auto parentWorkArea = MakeWorkArea(m_hInst, m_monitor, parentUniqueId, m_emptyUniqueId);
|
2022-06-14 16:45:45 +02:00
|
|
|
AppliedLayouts::instance().ApplyLayout(parentUniqueId, layout);
|
|
|
|
|
|
2022-08-15 16:40:10 +03:00
|
|
|
auto actualWorkArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, parentUniqueId);
|
2022-01-27 15:21:15 +03:00
|
|
|
Assert::IsNotNull(actualWorkArea->ZoneSet());
|
|
|
|
|
|
|
|
|
|
Assert::IsTrue(AppliedLayouts::instance().GetAppliedLayoutMap().contains(m_uniqueId));
|
2022-06-14 16:45:45 +02:00
|
|
|
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());
|
|
|
|
|
Assert::AreEqual(layout.sensitivityRadius, actualLayout.sensitivityRadius);
|
|
|
|
|
Assert::AreEqual(layout.showSpacing, actualLayout.showSpacing);
|
|
|
|
|
Assert::AreEqual(layout.spacing, actualLayout.spacing);
|
|
|
|
|
Assert::AreEqual(layout.zoneCount, actualLayout.zoneCount);
|
2022-01-27 15:21:15 +03:00
|
|
|
}
|
2022-10-25 17:55:36 +02:00
|
|
|
|
|
|
|
|
TEST_METHOD (CreateWorkAreaWithCustomDefault)
|
|
|
|
|
{
|
|
|
|
|
// prepare
|
|
|
|
|
json::JsonObject root{};
|
|
|
|
|
json::JsonArray layoutsArray{};
|
|
|
|
|
json::JsonObject layout{};
|
|
|
|
|
layout.SetNamedValue(NonLocalizable::DefaultLayoutsIds::UuidID, json::value(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}"));
|
|
|
|
|
layout.SetNamedValue(NonLocalizable::DefaultLayoutsIds::TypeID, json::value(L"custom"));
|
|
|
|
|
json::JsonObject item{};
|
|
|
|
|
item.SetNamedValue(NonLocalizable::DefaultLayoutsIds::MonitorConfigurationTypeID, json::value(L"horizontal"));
|
|
|
|
|
item.SetNamedValue(NonLocalizable::DefaultLayoutsIds::LayoutID, layout);
|
|
|
|
|
layoutsArray.Append(item);
|
|
|
|
|
root.SetNamedValue(NonLocalizable::DefaultLayoutsIds::DefaultLayoutsArrayID, layoutsArray);
|
|
|
|
|
|
|
|
|
|
json::to_file(DefaultLayouts::DefaultLayoutsFileName(), root);
|
|
|
|
|
DefaultLayouts::instance().LoadData();
|
|
|
|
|
|
|
|
|
|
// test
|
|
|
|
|
auto workArea = MakeWorkArea({}, Mocks::Monitor(), m_uniqueId, m_emptyUniqueId);
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD (CreateWorkAreaWithTemplateDefault)
|
|
|
|
|
{
|
|
|
|
|
// prepare
|
|
|
|
|
json::JsonObject root{};
|
|
|
|
|
json::JsonArray layoutsArray{};
|
|
|
|
|
json::JsonObject layout{};
|
|
|
|
|
layout.SetNamedValue(NonLocalizable::DefaultLayoutsIds::TypeID, json::value(L"grid"));
|
|
|
|
|
layout.SetNamedValue(NonLocalizable::DefaultLayoutsIds::ShowSpacingID, json::value(true));
|
|
|
|
|
layout.SetNamedValue(NonLocalizable::DefaultLayoutsIds::SpacingID, json::value(1));
|
|
|
|
|
layout.SetNamedValue(NonLocalizable::DefaultLayoutsIds::ZoneCountID, json::value(4));
|
|
|
|
|
layout.SetNamedValue(NonLocalizable::DefaultLayoutsIds::SensitivityRadiusID, json::value(30));
|
|
|
|
|
|
|
|
|
|
json::JsonObject item{};
|
|
|
|
|
item.SetNamedValue(NonLocalizable::DefaultLayoutsIds::MonitorConfigurationTypeID, json::value(L"horizontal"));
|
|
|
|
|
item.SetNamedValue(NonLocalizable::DefaultLayoutsIds::LayoutID, layout);
|
|
|
|
|
layoutsArray.Append(item);
|
|
|
|
|
root.SetNamedValue(NonLocalizable::DefaultLayoutsIds::DefaultLayoutsArrayID, layoutsArray);
|
|
|
|
|
|
|
|
|
|
json::to_file(DefaultLayouts::DefaultLayoutsFileName(), root);
|
|
|
|
|
DefaultLayouts::instance().LoadData();
|
|
|
|
|
|
|
|
|
|
// test
|
|
|
|
|
auto workArea = MakeWorkArea({}, Mocks::Monitor(), m_uniqueId, m_emptyUniqueId);
|
|
|
|
|
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());
|
|
|
|
|
}
|
2020-08-21 08:56:25 +03:00
|
|
|
};
|
2020-04-10 16:29:18 +02:00
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
TEST_CLASS (WorkAreaUnitTests)
|
2020-08-21 08:56:25 +03:00
|
|
|
{
|
2022-07-01 17:29:02 +02:00
|
|
|
FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
|
|
|
|
FancyZonesDataTypes::WorkAreaId m_parentUniqueId; // default empty
|
2020-08-21 08:56:25 +03:00
|
|
|
|
|
|
|
|
HINSTANCE m_hInst{};
|
|
|
|
|
HMONITOR m_monitor{};
|
|
|
|
|
|
|
|
|
|
TEST_METHOD_INITIALIZE(Init)
|
2022-01-24 14:54:17 +03:00
|
|
|
{
|
2022-07-01 17:29:02 +02:00
|
|
|
m_uniqueId.monitorId.deviceId.id = L"DELA026";
|
|
|
|
|
m_uniqueId.monitorId.deviceId.instanceId = L"5&10a58c63&0&UID16777488";
|
|
|
|
|
m_uniqueId.monitorId.serialNumber = L"serial-number";
|
2022-08-15 16:40:10 +03:00
|
|
|
m_uniqueId.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}").value();
|
2022-01-24 14:54:17 +03:00
|
|
|
|
|
|
|
|
AppZoneHistory::instance().LoadData();
|
2022-01-27 15:21:15 +03:00
|
|
|
AppliedLayouts::instance().LoadData();
|
2022-01-24 14:54:17 +03:00
|
|
|
}
|
2021-07-07 13:18:52 +03:00
|
|
|
|
2022-01-24 14:54:17 +03:00
|
|
|
TEST_METHOD_CLEANUP(CleanUp)
|
|
|
|
|
{
|
|
|
|
|
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
2022-01-27 15:21:15 +03:00
|
|
|
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
2022-01-24 14:54:17 +03:00
|
|
|
}
|
2020-08-21 08:56:25 +03:00
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
public:
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeEnter)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = S_OK;
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto actual = workArea->MoveSizeEnter(Mocks::Window());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeEnterTwice)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = S_OK;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveSizeEnter(Mocks::Window());
|
|
|
|
|
const auto actual = workArea->MoveSizeEnter(Mocks::Window());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeUpdate)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = S_OK;
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto actual = workArea->MoveSizeUpdate(POINT{ 0, 0 }, true, false);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeUpdatePointNegativeCoordinates)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = S_OK;
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto actual = workArea->MoveSizeUpdate(POINT{ -10, -10 }, true, false);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeUpdatePointBigCoordinates)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = S_OK;
|
2022-06-14 16:45:45 +02:00
|
|
|
const auto actual = workArea->MoveSizeUpdate(POINT{ LONG_MAX, LONG_MAX }, true, false);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeEnd)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-08-21 12:53:03 +02:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto window = Mocks::Window();
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveSizeEnter(window);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = S_OK;
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto actual = workArea->MoveSizeEnd(window, POINT{ 0, 0 });
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-11-11 19:23:22 +02:00
|
|
|
const auto zoneSet = workArea->ZoneSet();
|
2020-12-15 15:16:09 +03:00
|
|
|
zoneSet->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
|
|
|
|
const auto actualZoneIndexSet = zoneSet->GetZoneIndexSetFromWindow(window);
|
2021-08-11 17:05:03 +03:00
|
|
|
Assert::IsFalse(std::vector<ZoneIndex>{} == actualZoneIndexSet);
|
2020-12-15 15:16:09 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeEndWindowNotAdded)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto window = Mocks::Window();
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveSizeEnter(window);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = S_OK;
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto actual = workArea->MoveSizeEnd(window, POINT{ -100, -100 });
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-11-11 19:23:22 +02:00
|
|
|
const auto zoneSet = workArea->ZoneSet();
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto actualZoneIndexSet = zoneSet->GetZoneIndexSetFromWindow(window);
|
2021-08-11 17:05:03 +03:00
|
|
|
Assert::IsTrue(std::vector<ZoneIndex>{} == actualZoneIndexSet);
|
2020-12-15 15:16:09 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeEndDifferentWindows)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto window = Mocks::Window();
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveSizeEnter(window);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = E_INVALIDARG;
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto actual = workArea->MoveSizeEnd(Mocks::Window(), POINT{ 0, 0 });
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeEndWindowNotSet)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = E_INVALIDARG;
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto actual = workArea->MoveSizeEnd(Mocks::Window(), POINT{ 0, 0 });
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveSizeEndInvalidPoint)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto window = Mocks::Window();
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveSizeEnter(window);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto expected = S_OK;
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto actual = workArea->MoveSizeEnd(window, POINT{ -1, -1 });
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual(expected, actual);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-11-11 19:23:22 +02:00
|
|
|
const auto zoneSet = workArea->ZoneSet();
|
2020-12-15 15:16:09 +03:00
|
|
|
zoneSet->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
|
|
|
|
const auto actualZoneIndex = zoneSet->GetZoneIndexSetFromWindow(window);
|
2021-08-11 17:05:03 +03:00
|
|
|
Assert::IsFalse(std::vector<ZoneIndex>{} == actualZoneIndex); // with invalid point zone remains the same
|
2020-12-15 15:16:09 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveWindowIntoZoneByIndex)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2021-11-11 19:23:22 +02:00
|
|
|
Assert::IsNotNull(workArea->ZoneSet());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveWindowIntoZoneByIndex(Mocks::Window(), 0);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-11-11 19:23:22 +02:00
|
|
|
const auto actual = workArea->ZoneSet();
|
2020-12-15 15:16:09 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveWindowIntoZoneByDirectionAndIndex)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2021-11-11 19:23:22 +02:00
|
|
|
Assert::IsNotNull(workArea->ZoneSet());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2022-01-24 14:54:17 +03:00
|
|
|
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
|
|
|
|
const auto& appHistoryArray = actualAppZoneHistory.begin()->second;
|
|
|
|
|
Assert::AreEqual((size_t)1, appHistoryArray.size());
|
2021-08-11 17:05:03 +03:00
|
|
|
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray[0].zoneIndexSet);
|
2020-12-15 15:16:09 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (MoveWindowIntoZoneByDirectionManyTimes)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2021-11-11 19:23:22 +02:00
|
|
|
Assert::IsNotNull(workArea->ZoneSet());
|
2020-12-15 15:16:09 +03:00
|
|
|
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
|
|
|
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
|
|
|
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true);
|
2020-12-15 15:16:09 +03:00
|
|
|
|
2022-01-24 14:54:17 +03:00
|
|
|
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
|
|
|
|
const auto& appHistoryArray = actualAppZoneHistory.begin()->second;
|
|
|
|
|
Assert::AreEqual((size_t)1, appHistoryArray.size());
|
2021-08-11 17:05:03 +03:00
|
|
|
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == appHistoryArray[0].zoneIndexSet);
|
2020-12-15 15:16:09 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (SaveWindowProcessToZoneIndexNullptrWindow)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2021-11-11 19:23:22 +02:00
|
|
|
Assert::IsNotNull(workArea->ZoneSet());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->SaveWindowProcessToZoneIndex(nullptr);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2022-01-24 14:54:17 +03:00
|
|
|
const auto actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::IsTrue(actualAppZoneHistory.empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAdded)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2021-11-11 19:23:22 +02:00
|
|
|
Assert::IsNotNull(workArea->ZoneSet());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
auto window = Mocks::WindowCreate(m_hInst);
|
2022-03-25 19:09:59 +03:00
|
|
|
workArea->ZoneSet()->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->SaveWindowProcessToZoneIndex(window);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2022-01-24 14:54:17 +03:00
|
|
|
const auto actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::IsTrue(actualAppZoneHistory.empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAddedWithFilledAppZoneHistory)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2021-11-11 19:23:22 +02:00
|
|
|
Assert::IsNotNull(workArea->ZoneSet());
|
2020-12-15 15:16:09 +03:00
|
|
|
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
const auto processPath = get_process_path(window);
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto deviceId = workArea->UniqueId();
|
2021-11-11 19:23:22 +02:00
|
|
|
const auto zoneSetId = workArea->ZoneSet()->Id();
|
2020-12-15 15:16:09 +03:00
|
|
|
|
|
|
|
|
// fill app zone history map
|
2022-01-24 14:54:17 +03:00
|
|
|
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, deviceId, Helpers::GuidToString(zoneSetId), { 0 }));
|
|
|
|
|
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
|
|
|
|
const auto& appHistoryArray1 = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual((size_t)1, appHistoryArray1.size());
|
2021-08-11 17:05:03 +03:00
|
|
|
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray1[0].zoneIndexSet);
|
2020-12-15 15:16:09 +03:00
|
|
|
|
|
|
|
|
// add zone without window
|
2022-03-25 19:09:59 +03:00
|
|
|
workArea->ZoneSet()->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
2020-12-15 15:16:09 +03:00
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->SaveWindowProcessToZoneIndex(window);
|
2022-01-24 14:54:17 +03:00
|
|
|
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
|
|
|
|
const auto& appHistoryArray2 = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual((size_t)1, appHistoryArray2.size());
|
2021-08-11 17:05:03 +03:00
|
|
|
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray2[0].zoneIndexSet);
|
2020-12-15 15:16:09 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (SaveWindowProcessToZoneIndexWindowAdded)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2021-11-11 19:23:22 +02:00
|
|
|
Assert::IsNotNull(workArea->ZoneSet());
|
2020-12-15 15:16:09 +03:00
|
|
|
|
|
|
|
|
auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
const auto processPath = get_process_path(window);
|
2021-07-07 13:18:52 +03:00
|
|
|
const auto deviceId = workArea->UniqueId();
|
2021-11-11 19:23:22 +02:00
|
|
|
const auto zoneSetId = workArea->ZoneSet()->Id();
|
2020-12-15 15:16:09 +03:00
|
|
|
|
2022-03-25 19:09:59 +03:00
|
|
|
workArea->ZoneSet()->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveWindowIntoZoneByIndex(window, 0);
|
2020-12-15 15:16:09 +03:00
|
|
|
|
|
|
|
|
//fill app zone history map
|
2022-01-24 14:54:17 +03:00
|
|
|
Assert::IsTrue(AppZoneHistory::instance().SetAppLastZones(window, deviceId, Helpers::GuidToString(zoneSetId), { 2 }));
|
|
|
|
|
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
|
|
|
|
const auto& appHistoryArray = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual((size_t)1, appHistoryArray.size());
|
2021-08-11 17:05:03 +03:00
|
|
|
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == appHistoryArray[0].zoneIndexSet);
|
2020-12-15 15:16:09 +03:00
|
|
|
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->SaveWindowProcessToZoneIndex(window);
|
2020-12-15 15:16:09 +03:00
|
|
|
|
2022-01-24 14:54:17 +03:00
|
|
|
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
2020-12-15 15:16:09 +03:00
|
|
|
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
2021-11-11 19:23:22 +02:00
|
|
|
const auto& expected = workArea->ZoneSet()->GetZoneIndexSetFromWindow(window);
|
2020-12-15 15:16:09 +03:00
|
|
|
const auto& actual = appHistoryArray[0].zoneIndexSet;
|
|
|
|
|
Assert::IsTrue(expected == actual);
|
|
|
|
|
}
|
2020-04-14 10:40:30 +02:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
TEST_METHOD (WhenWindowIsNotResizablePlacingItIntoTheZoneShouldNotResizeIt)
|
|
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
2021-11-11 19:23:22 +02:00
|
|
|
Assert::IsNotNull(workArea->ZoneSet());
|
2020-04-14 10:40:30 +02:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
auto window = Mocks::WindowCreate(m_hInst);
|
2020-04-14 10:40:30 +02:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
int originalWidth = 450;
|
|
|
|
|
int originalHeight = 550;
|
2020-04-14 10:40:30 +02:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
SetWindowPos(window, nullptr, 150, 150, originalWidth, originalHeight, SWP_SHOWWINDOW);
|
|
|
|
|
SetWindowLong(window, GWL_STYLE, GetWindowLong(window, GWL_STYLE) & ~WS_SIZEBOX);
|
2020-04-14 10:40:30 +02:00
|
|
|
|
2022-03-25 19:09:59 +03:00
|
|
|
workArea->ZoneSet()->CalculateZones(RECT{ 0, 0, 1920, 1080 }, 1, 0);
|
2021-07-07 13:18:52 +03:00
|
|
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_LEFT, true);
|
2020-04-14 10:40:30 +02:00
|
|
|
|
2020-12-15 15:16:09 +03:00
|
|
|
RECT inZoneRect;
|
|
|
|
|
GetWindowRect(window, &inZoneRect);
|
|
|
|
|
Assert::AreEqual(originalWidth, (int)inZoneRect.right - (int)inZoneRect.left);
|
|
|
|
|
Assert::AreEqual(originalHeight, (int)inZoneRect.bottom - (int)inZoneRect.top);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
};
|
2019-09-04 18:26:26 +02:00
|
|
|
}
|