mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[CI] FancyZones unit tests (#17910)
This commit is contained in:
@@ -34,7 +34,7 @@ namespace JsonUtils
|
||||
{
|
||||
try
|
||||
{
|
||||
Layout data;
|
||||
Layout data{};
|
||||
auto idStr = json.GetNamedString(NonLocalizable::AppliedLayoutsIds::UuidID);
|
||||
auto id = FancyZonesUtils::GuidFromString(idStr.c_str());
|
||||
if (!id.has_value())
|
||||
@@ -138,7 +138,7 @@ namespace JsonUtils
|
||||
|
||||
public:
|
||||
FancyZonesDataTypes::WorkAreaId workAreaId;
|
||||
Layout data;
|
||||
Layout data{};
|
||||
|
||||
static std::optional<AppliedLayoutsJSON> FromJson(const json::JsonObject& json)
|
||||
{
|
||||
|
||||
@@ -496,16 +496,6 @@ namespace JSONHelpers
|
||||
}
|
||||
}
|
||||
|
||||
json::JsonObject ZoneSetDataJSON::ToJson(const FancyZonesDataTypes::ZoneSetData& zoneSet)
|
||||
{
|
||||
json::JsonObject result{};
|
||||
|
||||
result.SetNamedValue(NonLocalizable::UuidStr, json::value(zoneSet.uuid));
|
||||
result.SetNamedValue(NonLocalizable::TypeStr, json::value(TypeToString(zoneSet.type)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::optional<FancyZonesDataTypes::ZoneSetData> ZoneSetDataJSON::FromJson(const json::JsonObject& zoneSet)
|
||||
{
|
||||
try
|
||||
@@ -563,16 +553,6 @@ namespace JSONHelpers
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
json::JsonObject LayoutQuickKeyJSON::ToJson(const LayoutQuickKeyJSON& layoutQuickKey)
|
||||
{
|
||||
json::JsonObject result{};
|
||||
|
||||
result.SetNamedValue(NonLocalizable::QuickAccessUuid, json::value(layoutQuickKey.layoutUuid));
|
||||
result.SetNamedValue(NonLocalizable::QuickAccessKey, json::value(layoutQuickKey.key));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::optional<LayoutQuickKeyJSON> LayoutQuickKeyJSON::FromJson(const json::JsonObject& layoutQuickKey)
|
||||
{
|
||||
@@ -679,18 +659,6 @@ namespace JSONHelpers
|
||||
root.SetNamedValue(NonLocalizable::AppliedLayoutsIds::AppliedLayoutsArrayID, layoutsArray);
|
||||
json::to_file(AppliedLayouts::AppliedLayoutsFileName(), root);
|
||||
}
|
||||
|
||||
json::JsonArray SerializeCustomZoneSets(const TCustomZoneSetsMap& customZoneSetsMap)
|
||||
{
|
||||
json::JsonArray customZoneSetsJSON{};
|
||||
|
||||
for (const auto& [zoneSetId, zoneSetData] : customZoneSetsMap)
|
||||
{
|
||||
customZoneSetsJSON.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ zoneSetId, zoneSetData }));
|
||||
}
|
||||
|
||||
return customZoneSetsJSON;
|
||||
}
|
||||
|
||||
std::optional<TLayoutQuickKeysMap> ParseQuickKeys(const json::JsonObject& fancyZonesDataJSON)
|
||||
{
|
||||
|
||||
@@ -63,7 +63,6 @@ namespace JSONHelpers
|
||||
|
||||
namespace ZoneSetDataJSON
|
||||
{
|
||||
json::JsonObject ToJson(const FancyZonesDataTypes::ZoneSetData& zoneSet);
|
||||
std::optional<FancyZonesDataTypes::ZoneSetData> FromJson(const json::JsonObject& zoneSet);
|
||||
};
|
||||
|
||||
@@ -80,7 +79,6 @@ namespace JSONHelpers
|
||||
std::wstring layoutUuid;
|
||||
int key;
|
||||
|
||||
static json::JsonObject ToJson(const LayoutQuickKeyJSON& device);
|
||||
static std::optional<LayoutQuickKeyJSON> FromJson(const json::JsonObject& device);
|
||||
};
|
||||
|
||||
|
||||
@@ -104,7 +104,8 @@ namespace
|
||||
WindowPool windowPool;
|
||||
}
|
||||
|
||||
WorkArea::WorkArea(HINSTANCE hinstance)
|
||||
WorkArea::WorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId) :
|
||||
m_uniqueId(uniqueId)
|
||||
{
|
||||
WNDCLASSEXW wcex{};
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
@@ -120,24 +121,6 @@ WorkArea::~WorkArea()
|
||||
windowPool.FreeZonesOverlayWindow(m_window);
|
||||
}
|
||||
|
||||
bool WorkArea::Init(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesDataTypes::WorkAreaId& parentUniqueId)
|
||||
{
|
||||
m_uniqueId = uniqueId;
|
||||
InitializeZoneSets(parentUniqueId);
|
||||
|
||||
m_window = windowPool.NewZonesOverlayWindow(m_workAreaRect, hinstance, this);
|
||||
|
||||
if (!m_window)
|
||||
{
|
||||
Logger::error(L"No work area window");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_zonesOverlay = std::make_unique<ZonesOverlay>(m_window);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
HRESULT WorkArea::MoveSizeEnter(HWND window) noexcept
|
||||
{
|
||||
m_windowMoveSize = window;
|
||||
@@ -378,7 +361,20 @@ void WorkArea::FlashZones() noexcept
|
||||
|
||||
#pragma region private
|
||||
|
||||
void WorkArea::InitializeZoneSets(const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept
|
||||
bool WorkArea::InitWindow(HINSTANCE hinstance) noexcept
|
||||
{
|
||||
m_window = windowPool.NewZonesOverlayWindow(m_workAreaRect, hinstance, this);
|
||||
if (!m_window)
|
||||
{
|
||||
Logger::error(L"No work area window");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_zonesOverlay = std::make_unique<ZonesOverlay>(m_window);
|
||||
return true;
|
||||
}
|
||||
|
||||
void WorkArea::InitLayout(const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept
|
||||
{
|
||||
Logger::info(L"Initialize layout on {}", m_uniqueId.toString());
|
||||
|
||||
|
||||
@@ -9,19 +9,30 @@ class ZonesOverlay;
|
||||
class WorkArea
|
||||
{
|
||||
public:
|
||||
WorkArea(HINSTANCE hinstance);
|
||||
WorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId);
|
||||
~WorkArea();
|
||||
|
||||
public:
|
||||
bool Init(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesDataTypes::WorkAreaId& parentUniqueId);
|
||||
inline bool Init(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& parentUniqueId)
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
if (!InitWindow(hinstance))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
InitLayout(parentUniqueId);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool InitWorkAreaRect(HMONITOR monitor)
|
||||
{
|
||||
m_monitor = monitor;
|
||||
|
||||
#if defined(UNIT_TESTS)
|
||||
m_workAreaRect = FancyZonesUtils::Rect({ 0, 0, 1920, 1080 });
|
||||
return true;
|
||||
#endif
|
||||
#else
|
||||
|
||||
if (monitor)
|
||||
{
|
||||
@@ -38,6 +49,7 @@ public:
|
||||
{
|
||||
m_workAreaRect = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFO::rcWork>();
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -72,7 +84,8 @@ protected:
|
||||
static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||
|
||||
private:
|
||||
void InitializeZoneSets(const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept;
|
||||
bool InitWindow(HINSTANCE hinstance) noexcept;
|
||||
void InitLayout(const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept;
|
||||
void CalculateZoneSet(OverlappingZonesAlgorithm overlappingAlgorithm) noexcept;
|
||||
void UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept;
|
||||
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||
@@ -81,8 +94,7 @@ private:
|
||||
|
||||
HMONITOR m_monitor{};
|
||||
FancyZonesUtils::Rect m_workAreaRect{};
|
||||
|
||||
FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
||||
const FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
||||
HWND m_window{}; // Hidden tool window used to represent current monitor desktop work area.
|
||||
HWND m_windowMoveSize{};
|
||||
winrt::com_ptr<IZoneSet> m_zoneSet;
|
||||
@@ -95,17 +107,18 @@ private:
|
||||
|
||||
inline std::shared_ptr<WorkArea> MakeWorkArea(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept
|
||||
{
|
||||
auto self = std::make_shared<WorkArea>(hinstance);
|
||||
auto self = std::make_shared<WorkArea>(hinstance, uniqueId);
|
||||
if (!self->InitWorkAreaRect(monitor))
|
||||
{
|
||||
self->LogInitializationError();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!self->Init(hinstance, uniqueId, parentUniqueId))
|
||||
if (!self->Init(hinstance, parentUniqueId))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user