mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
[FancyZones] Split zones-settings: custom layouts (#15642)
This commit is contained in:
@@ -0,0 +1,194 @@
|
||||
#include "pch.h"
|
||||
#include <filesystem>
|
||||
|
||||
#include <FancyZonesLib/FancyZonesData.h>
|
||||
#include <FancyZonesLib/FancyZonesData/CustomLayouts.h>
|
||||
#include <FancyZonesLib/util.h>
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS (CustomLayoutsUnitTests)
|
||||
{
|
||||
FancyZonesData& m_fzData = FancyZonesDataInstance();
|
||||
std::wstring m_testFolder = L"FancyZonesUnitTests";
|
||||
|
||||
json::JsonObject CanvasLayoutJson()
|
||||
{
|
||||
json::JsonObject canvasLayoutJson{};
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::UuidID, json::value(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}"));
|
||||
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{};
|
||||
{
|
||||
json::JsonObject zone{};
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::XID, json::value(0));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::YID, json::value(0));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::WidthID, json::value(1140));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::HeightID, json::value(1040));
|
||||
zonesArray.Append(zone);
|
||||
}
|
||||
{
|
||||
json::JsonObject zone{};
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::XID, json::value(1140));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::YID, json::value(649));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::WidthID, json::value(780));
|
||||
zone.SetNamedValue(NonLocalizable::CustomLayoutsIds::HeightID, json::value(391));
|
||||
zonesArray.Append(zone);
|
||||
}
|
||||
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::ZonesID, zonesArray);
|
||||
canvasLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::InfoID, info);
|
||||
return canvasLayoutJson;
|
||||
}
|
||||
|
||||
json::JsonObject GridLayoutJson()
|
||||
{
|
||||
json::JsonObject gridLayoutJson{};
|
||||
gridLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::UuidID, json::value(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17D}"));
|
||||
gridLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::NameID, json::value(L"Custom grid layout"));
|
||||
gridLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::TypeID, json::value(NonLocalizable::CustomLayoutsIds::GridID));
|
||||
|
||||
json::JsonArray rowsPercentage{};
|
||||
rowsPercentage.Append(json::value(5000));
|
||||
rowsPercentage.Append(json::value(5000));
|
||||
|
||||
json::JsonArray columnsPercentage{};
|
||||
columnsPercentage.Append(json::value(3333));
|
||||
columnsPercentage.Append(json::value(5000));
|
||||
columnsPercentage.Append(json::value(1667));
|
||||
|
||||
json::JsonArray cells{};
|
||||
{
|
||||
json::JsonArray cellsRow{};
|
||||
cellsRow.Append(json::value(0));
|
||||
cellsRow.Append(json::value(1));
|
||||
cellsRow.Append(json::value(2));
|
||||
cells.Append(cellsRow);
|
||||
}
|
||||
{
|
||||
json::JsonArray cellsRow{};
|
||||
cellsRow.Append(json::value(3));
|
||||
cellsRow.Append(json::value(1));
|
||||
cellsRow.Append(json::value(4));
|
||||
cells.Append(cellsRow);
|
||||
}
|
||||
|
||||
json::JsonObject info{};
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::RowsID, json::value(2));
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::ColumnsID, json::value(3));
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::RowsPercentageID, rowsPercentage);
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::ColumnsPercentageID, columnsPercentage);
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::CellChildMapID, cells);
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::SensitivityRadiusID, json::value(20));
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::ShowSpacingID, json::value(false));
|
||||
info.SetNamedValue(NonLocalizable::CustomLayoutsIds::SpacingID, json::value(16));
|
||||
|
||||
gridLayoutJson.SetNamedValue(NonLocalizable::CustomLayoutsIds::InfoID, info);
|
||||
return gridLayoutJson;
|
||||
}
|
||||
|
||||
TEST_METHOD_INITIALIZE(Init)
|
||||
{
|
||||
m_fzData.clear_data();
|
||||
m_fzData.SetSettingsModulePath(L"FancyZonesUnitTests");
|
||||
}
|
||||
|
||||
TEST_METHOD_CLEANUP(CleanUp)
|
||||
{
|
||||
std::filesystem::remove_all(CustomLayouts::CustomLayoutsFileName());
|
||||
std::filesystem::remove_all(PTSettingsHelper::get_module_save_folder_location(m_testFolder));
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomLayoutsParse)
|
||||
{
|
||||
// prepare
|
||||
json::JsonObject root{};
|
||||
json::JsonArray layoutsArray{};
|
||||
|
||||
layoutsArray.Append(CanvasLayoutJson());
|
||||
layoutsArray.Append(GridLayoutJson());
|
||||
|
||||
root.SetNamedValue(NonLocalizable::CustomLayoutsIds::CustomLayoutsArrayID, layoutsArray);
|
||||
json::to_file(CustomLayouts::CustomLayoutsFileName(), root);
|
||||
|
||||
// test
|
||||
CustomLayouts::instance().LoadData();
|
||||
Assert::AreEqual((size_t)2, CustomLayouts::instance().GetAllLayouts().size());
|
||||
Assert::IsTrue(CustomLayouts::instance().GetLayout(FancyZonesUtils::GuidFromString(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}").value()).has_value());
|
||||
Assert::IsTrue(CustomLayouts::instance().GetLayout(FancyZonesUtils::GuidFromString(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17D}").value()).has_value());
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomLayoutsParseEmpty)
|
||||
{
|
||||
// prepare
|
||||
json::JsonObject root{};
|
||||
json::JsonArray layoutsArray{};
|
||||
root.SetNamedValue(NonLocalizable::CustomLayoutsIds::CustomLayoutsArrayID, layoutsArray);
|
||||
json::to_file(CustomLayouts::CustomLayoutsFileName(), root);
|
||||
|
||||
// test
|
||||
CustomLayouts::instance().LoadData();
|
||||
Assert::IsTrue(CustomLayouts::instance().GetAllLayouts().empty());
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomsLayoutsNoFile)
|
||||
{
|
||||
// test
|
||||
CustomLayouts::instance().LoadData();
|
||||
Assert::IsTrue(CustomLayouts::instance().GetAllLayouts().empty());
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveCustomLayoutsFromZonesSettings)
|
||||
{
|
||||
// prepare
|
||||
json::JsonObject root{};
|
||||
json::JsonArray devicesArray{}, customLayoutsArray{}, templateLayoutsArray{}, quickLayoutKeysArray{};
|
||||
customLayoutsArray.Append(GridLayoutJson());
|
||||
customLayoutsArray.Append(CanvasLayoutJson());
|
||||
|
||||
root.SetNamedValue(L"devices", devicesArray);
|
||||
root.SetNamedValue(L"custom-zone-sets", customLayoutsArray);
|
||||
root.SetNamedValue(L"templates", templateLayoutsArray);
|
||||
root.SetNamedValue(L"quick-layout-keys", quickLayoutKeysArray);
|
||||
json::to_file(m_fzData.GetZoneSettingsPath(m_testFolder), root);
|
||||
|
||||
// test
|
||||
m_fzData.ReplaceZoneSettingsFileFromOlderVersions();
|
||||
CustomLayouts::instance().LoadData();
|
||||
Assert::AreEqual((size_t)2, CustomLayouts::instance().GetAllLayouts().size());
|
||||
Assert::IsTrue(CustomLayouts::instance().GetLayout(FancyZonesUtils::GuidFromString(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17C}").value()).has_value());
|
||||
Assert::IsTrue(CustomLayouts::instance().GetLayout(FancyZonesUtils::GuidFromString(L"{ACE817FD-2C51-4E13-903A-84CAB86FD17D}").value()).has_value());
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveCustomLayoutsFromZonesSettingsNoCustomLayoutsData)
|
||||
{
|
||||
// prepare
|
||||
json::JsonObject root{};
|
||||
json::JsonArray devicesArray{}, templateLayoutsArray{}, quickLayoutKeysArray{};
|
||||
root.SetNamedValue(L"devices", devicesArray);
|
||||
root.SetNamedValue(L"templates", templateLayoutsArray);
|
||||
root.SetNamedValue(L"quick-layout-keys", quickLayoutKeysArray);
|
||||
json::to_file(m_fzData.GetZoneSettingsPath(m_testFolder), root);
|
||||
|
||||
// test
|
||||
m_fzData.ReplaceZoneSettingsFileFromOlderVersions();
|
||||
CustomLayouts::instance().LoadData();
|
||||
Assert::IsTrue(CustomLayouts::instance().GetAllLayouts().empty());
|
||||
}
|
||||
|
||||
TEST_METHOD (MoveCustomLayoutsFromZonesSettingsNoFile)
|
||||
{
|
||||
// test
|
||||
m_fzData.ReplaceZoneSettingsFileFromOlderVersions();
|
||||
CustomLayouts::instance().LoadData();
|
||||
Assert::IsTrue(CustomLayouts::instance().GetAllLayouts().empty());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -562,7 +562,7 @@ namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_METHOD (ToJsonGrid)
|
||||
{
|
||||
CustomZoneSetJSON zoneSet{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Grid, GridLayoutInfo(GridLayoutInfo::Minimal{}) } };
|
||||
CustomZoneSetJSON zoneSet{ L"uuid", CustomLayoutData{ L"name", CustomLayoutType::Grid, GridLayoutInfo(GridLayoutInfo::Minimal{}) } };
|
||||
|
||||
json::JsonObject expected = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"name\": \"name\", \"type\": \"grid\"}");
|
||||
expected.SetNamedValue(L"info", GridLayoutInfoJSON::ToJson(std::get<GridLayoutInfo>(zoneSet.data.info)));
|
||||
@@ -574,7 +574,7 @@ namespace FancyZonesUnitTests
|
||||
|
||||
TEST_METHOD (ToJsonCanvas)
|
||||
{
|
||||
CustomZoneSetJSON zoneSet{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{} } };
|
||||
CustomZoneSetJSON zoneSet{ L"uuid", CustomLayoutData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{} } };
|
||||
|
||||
json::JsonObject expected = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"name\": \"name\", \"type\": \"canvas\"}");
|
||||
expected.SetNamedValue(L"info", CanvasLayoutInfoJSON::ToJson(std::get<CanvasLayoutInfo>(zoneSet.data.info)));
|
||||
@@ -587,7 +587,7 @@ namespace FancyZonesUnitTests
|
||||
TEST_METHOD (FromJsonGrid)
|
||||
{
|
||||
const auto grid = GridLayoutInfo(GridLayoutInfo::Full{ 1, 3, { 10000 }, { 2500, 5000, 2500 }, { { 0, 1, 2 } } });
|
||||
CustomZoneSetJSON expected{ L"{33A2B101-06E0-437B-A61E-CDBECF502906}", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
CustomZoneSetJSON expected{ L"{33A2B101-06E0-437B-A61E-CDBECF502906}", CustomLayoutData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
|
||||
json::JsonObject json = json::JsonObject::Parse(L"{\"uuid\": \"{33A2B101-06E0-437B-A61E-CDBECF502906}\", \"name\": \"name\", \"type\": \"grid\"}");
|
||||
json.SetNamedValue(L"info", GridLayoutInfoJSON::ToJson(std::get<GridLayoutInfo>(expected.data.info)));
|
||||
@@ -607,7 +607,7 @@ namespace FancyZonesUnitTests
|
||||
|
||||
TEST_METHOD (FromJsonCanvas)
|
||||
{
|
||||
CustomZoneSetJSON expected{ L"{33A2B101-06E0-437B-A61E-CDBECF502906}", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 2, 1 } } };
|
||||
CustomZoneSetJSON expected{ L"{33A2B101-06E0-437B-A61E-CDBECF502906}", CustomLayoutData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 2, 1 } } };
|
||||
|
||||
json::JsonObject json = json::JsonObject::Parse(L"{\"uuid\": \"{33A2B101-06E0-437B-A61E-CDBECF502906}\", \"name\": \"name\", \"type\": \"canvas\"}");
|
||||
json.SetNamedValue(L"info", CanvasLayoutInfoJSON::ToJson(std::get<CanvasLayoutInfo>(expected.data.info)));
|
||||
@@ -628,7 +628,7 @@ namespace FancyZonesUnitTests
|
||||
TEST_METHOD (FromJsonGridInvalidUuid)
|
||||
{
|
||||
const auto grid = GridLayoutInfo(GridLayoutInfo::Full{ 1, 3, { 10000 }, { 2500, 5000, 2500 }, { { 0, 1, 2 } } });
|
||||
CustomZoneSetJSON expected{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
CustomZoneSetJSON expected{ L"uuid", CustomLayoutData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
|
||||
json::JsonObject json = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"name\": \"name\", \"type\": \"grid\"}");
|
||||
json.SetNamedValue(L"info", GridLayoutInfoJSON::ToJson(std::get<GridLayoutInfo>(expected.data.info)));
|
||||
@@ -639,7 +639,7 @@ namespace FancyZonesUnitTests
|
||||
|
||||
TEST_METHOD (FromJsonCanvasInvalidUuid)
|
||||
{
|
||||
CustomZoneSetJSON expected{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 2, 1 } } };
|
||||
CustomZoneSetJSON expected{ L"uuid", CustomLayoutData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 2, 1 } } };
|
||||
|
||||
json::JsonObject json = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"name\": \"name\", \"type\": \"canvas\"}");
|
||||
json.SetNamedValue(L"info", CanvasLayoutInfoJSON::ToJson(std::get<CanvasLayoutInfo>(expected.data.info)));
|
||||
@@ -650,7 +650,7 @@ namespace FancyZonesUnitTests
|
||||
|
||||
TEST_METHOD (FromJsonMissingKeys)
|
||||
{
|
||||
CustomZoneSetJSON zoneSet{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 2, 1 } } };
|
||||
CustomZoneSetJSON zoneSet{ L"uuid", CustomLayoutData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 2, 1 } } };
|
||||
const auto json = CustomZoneSetJSON::ToJson(zoneSet);
|
||||
|
||||
auto iter = json.First();
|
||||
@@ -1371,158 +1371,6 @@ namespace FancyZonesUnitTests
|
||||
auto res = CustomAssert::CompareJsonArrays(expected, actual);
|
||||
Assert::IsTrue(res.first, res.second.c_str());
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneSetsParseSingle)
|
||||
{
|
||||
const std::wstring zoneUuid = L"{33A2B101-06E0-437B-A61E-CDBECF502906}";
|
||||
GridLayoutInfo grid(GridLayoutInfo(FancyZonesDataTypes::GridLayoutInfo::Full{
|
||||
.rows = 1,
|
||||
.columns = 3,
|
||||
.rowsPercents = { 10000 },
|
||||
.columnsPercents = { 2500, 5000, 2500 },
|
||||
.cellChildMap = { { 0, 1, 2 } } }));
|
||||
|
||||
json::JsonObject json;
|
||||
CustomZoneSetJSON expected{ zoneUuid, CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
json::JsonArray array;
|
||||
array.Append(CustomZoneSetJSON::ToJson(expected));
|
||||
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(array.Stringify()));
|
||||
|
||||
const auto& customZoneSetsMap = ParseCustomZoneSets(json);
|
||||
|
||||
Assert::AreEqual((size_t)array.Size(), customZoneSetsMap.size());
|
||||
|
||||
auto entry = customZoneSetsMap.find(zoneUuid)->second;
|
||||
Assert::AreEqual(expected.data.name.c_str(), entry.name.c_str());
|
||||
Assert::AreEqual((int)expected.data.type, (int)entry.type);
|
||||
|
||||
auto expectedGrid = std::get<GridLayoutInfo>(expected.data.info);
|
||||
auto actualGrid = std::get<GridLayoutInfo>(entry.info);
|
||||
Assert::AreEqual(expectedGrid.rows(), actualGrid.rows());
|
||||
Assert::AreEqual(expectedGrid.columns(), actualGrid.columns());
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneSetsParseMany)
|
||||
{
|
||||
json::JsonObject json;
|
||||
json::JsonArray array;
|
||||
const GridLayoutInfo grid(GridLayoutInfo(FancyZonesDataTypes::GridLayoutInfo::Full{
|
||||
.rows = 1,
|
||||
.columns = 3,
|
||||
.rowsPercents = { 10000 },
|
||||
.columnsPercents = { 2500, 5000, 2500 },
|
||||
.cellChildMap = { { 0, 1, 2 } } }));
|
||||
array.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502900}", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
||||
array.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502901}", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 1, 2 } } }));
|
||||
array.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502902}", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
||||
array.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502903}", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 1, 2 } } }));
|
||||
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(array.Stringify()));
|
||||
|
||||
const auto& customZoneSetsMap = ParseCustomZoneSets(json);
|
||||
|
||||
Assert::AreEqual((size_t)array.Size(), customZoneSetsMap.size());
|
||||
|
||||
auto iter = array.First();
|
||||
while (iter.HasCurrent())
|
||||
{
|
||||
auto expected = CustomZoneSetJSON::FromJson(json::JsonObject::Parse(iter.Current().Stringify()));
|
||||
auto entry = customZoneSetsMap.find(expected->uuid)->second;
|
||||
Assert::AreEqual(expected->data.name.c_str(), entry.name.c_str(), L"name");
|
||||
Assert::AreEqual((int)expected->data.type, (int)entry.type, L"type");
|
||||
|
||||
if (expected->data.type == CustomLayoutType::Grid)
|
||||
{
|
||||
auto expectedInfo = std::get<GridLayoutInfo>(expected->data.info);
|
||||
auto actualInfo = std::get<GridLayoutInfo>(entry.info);
|
||||
Assert::AreEqual(expectedInfo.rows(), actualInfo.rows(), L"grid rows");
|
||||
Assert::AreEqual(expectedInfo.columns(), actualInfo.columns(), L"grid columns");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto expectedInfo = std::get<CanvasLayoutInfo>(expected->data.info);
|
||||
auto actualInfo = std::get<CanvasLayoutInfo>(entry.info);
|
||||
Assert::AreEqual(expectedInfo.lastWorkAreaWidth, actualInfo.lastWorkAreaWidth, L"canvas width");
|
||||
Assert::AreEqual(expectedInfo.lastWorkAreaHeight, actualInfo.lastWorkAreaHeight, L"canvas height");
|
||||
}
|
||||
|
||||
iter.MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneSetsParseEmpty)
|
||||
{
|
||||
const auto& customZoneSetsMap = ParseCustomZoneSets(json::JsonObject());
|
||||
|
||||
Assert::IsTrue(customZoneSetsMap.empty());
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneSetsParseInvalid)
|
||||
{
|
||||
json::JsonObject json;
|
||||
CustomZoneSetJSON expected{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Grid, GridLayoutInfo(GridLayoutInfo::Minimal{ 1, 2 }) } };
|
||||
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(CustomZoneSetJSON::ToJson(expected).Stringify()));
|
||||
|
||||
const auto& customZoneSetsMap = ParseCustomZoneSets(json);
|
||||
|
||||
Assert::IsTrue(customZoneSetsMap.empty());
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneSetsSerializeSingle)
|
||||
{
|
||||
json::JsonArray expected;
|
||||
const GridLayoutInfo grid(GridLayoutInfo(FancyZonesDataTypes::GridLayoutInfo::Full{
|
||||
.rows = 1,
|
||||
.columns = 3,
|
||||
.rowsPercents = { 10000 },
|
||||
.columnsPercents = { 2500, 5000, 2500 },
|
||||
.cellChildMap = { { 0, 1, 2 } } }));
|
||||
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502906}", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
||||
json::JsonObject json;
|
||||
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(expected.Stringify()));
|
||||
|
||||
const auto& customZoneSetsMap = ParseCustomZoneSets(json);
|
||||
|
||||
auto actual = SerializeCustomZoneSets(customZoneSetsMap);
|
||||
auto res = CustomAssert::CompareJsonArrays(expected, actual);
|
||||
Assert::IsTrue(res.first, res.second.c_str());
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneSetsSerializeMany)
|
||||
{
|
||||
json::JsonObject json;
|
||||
json::JsonArray expected;
|
||||
const GridLayoutInfo grid(GridLayoutInfo(FancyZonesDataTypes::GridLayoutInfo::Full{
|
||||
.rows = 1,
|
||||
.columns = 3,
|
||||
.rowsPercents = { 10000 },
|
||||
.columnsPercents = { 2500, 5000, 2500 },
|
||||
.cellChildMap = { { 0, 1, 2 } } }));
|
||||
|
||||
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502900}", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
||||
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502901}", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 1, 2 } } }));
|
||||
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502902}", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
||||
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"{33A2B101-06E0-437B-A61E-CDBECF502903}", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 1, 2 } } }));
|
||||
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(expected.Stringify()));
|
||||
|
||||
const auto& customZoneSetsMap = ParseCustomZoneSets(json);
|
||||
|
||||
auto actual = SerializeCustomZoneSets(customZoneSetsMap);
|
||||
auto res = CustomAssert::CompareJsonArrays(expected, actual);
|
||||
Assert::IsTrue(res.first, res.second.c_str());
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneSetsSerializeEmpty)
|
||||
{
|
||||
json::JsonArray expected;
|
||||
json::JsonObject json;
|
||||
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(expected.Stringify()));
|
||||
|
||||
const auto& customZoneSetsMap = ParseCustomZoneSets(json);
|
||||
|
||||
auto actual = SerializeCustomZoneSets(customZoneSetsMap);
|
||||
auto res = CustomAssert::CompareJsonArrays(expected, actual);
|
||||
Assert::IsTrue(res.first, res.second.c_str());
|
||||
}
|
||||
|
||||
TEST_METHOD (SetActiveZoneSet)
|
||||
{
|
||||
@@ -1620,13 +1468,13 @@ namespace FancyZonesUnitTests
|
||||
.rowsPercents = { 10000 },
|
||||
.columnsPercents = { 2500, 5000, 2500 },
|
||||
.cellChildMap = { { 0, 1, 2 } } }));
|
||||
CustomZoneSetJSON zoneSets{ L"{33A2B101-06E0-437B-A61E-CDBECF502906}", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
CustomZoneSetJSON zoneSets{ L"{33A2B101-06E0-437B-A61E-CDBECF502906}", CustomLayoutData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
AppZoneHistoryData data{
|
||||
.zoneSetUuid = L"{33A2B101-06E0-437B-A61E-CDBECF502906}", .deviceId = L"device-id", .zoneIndexSet = { 54321 }
|
||||
};
|
||||
AppZoneHistoryJSON appZoneHistory{ L"app-path", std::vector<AppZoneHistoryData>{ data } };
|
||||
|
||||
DeviceInfoJSON deviceInfo { FancyZonesDataTypes::DeviceIdData{ L"device-id", 0, 0, m_defaultVDId }, DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 } };
|
||||
DeviceInfoJSON deviceInfo { FancyZonesDataTypes::DeviceIdData{ L"device-id", 0, 0, m_defaultVDId }, DeviceInfoData{ ZoneSetData{ L"{33A2B101-16E1-437B-A61E-CDBECF502906}", ZoneSetLayoutType::Custom }, true, 16, 3 } };
|
||||
LayoutQuickKeyJSON quickKeys{ L"{33A2B101-06E0-437B-A61E-CDBECF502906}", 1 };
|
||||
json::JsonArray zoneSetsArray, appZonesArray, deviceInfoArray, quickKeysArray;
|
||||
zoneSetsArray.Append(CustomZoneSetJSON::ToJson(zoneSets));
|
||||
@@ -1651,9 +1499,8 @@ namespace FancyZonesUnitTests
|
||||
std::filesystem::remove(jsonPath);
|
||||
}
|
||||
|
||||
Assert::IsFalse(fancyZonesData.GetCustomZoneSetsMap().empty());
|
||||
Assert::IsFalse(fancyZonesData.GetCustomZoneSetsMap().empty());
|
||||
Assert::IsFalse(fancyZonesData.GetCustomZoneSetsMap().empty());
|
||||
Assert::IsFalse(fancyZonesData.GetAppZoneHistoryMap().empty());
|
||||
Assert::IsFalse(fancyZonesData.GetDeviceInfoMap().empty());
|
||||
}
|
||||
|
||||
TEST_METHOD (LoadFancyZonesDataFromCroppedJson)
|
||||
@@ -1666,7 +1513,6 @@ namespace FancyZonesUnitTests
|
||||
|
||||
data.LoadFancyZonesData();
|
||||
|
||||
Assert::IsTrue(data.GetCustomZoneSetsMap().empty());
|
||||
Assert::IsTrue(data.GetAppZoneHistoryMap().empty());
|
||||
Assert::IsTrue(data.GetDeviceInfoMap().empty());
|
||||
}
|
||||
@@ -1680,7 +1526,6 @@ namespace FancyZonesUnitTests
|
||||
std::wofstream{ jsonPath.data(), std::ios::binary } << L"{ \"app-zone-history\": [], \"devices\": [{\"device-id\": \"кириллица\"}], \"custom-zone-sets\": []}";
|
||||
data.LoadFancyZonesData();
|
||||
|
||||
Assert::IsTrue(data.GetCustomZoneSetsMap().empty());
|
||||
Assert::IsTrue(data.GetAppZoneHistoryMap().empty());
|
||||
Assert::IsTrue(data.GetDeviceInfoMap().empty());
|
||||
}
|
||||
@@ -1694,7 +1539,6 @@ namespace FancyZonesUnitTests
|
||||
std::wofstream{ jsonPath.data(), std::ios::binary } << L"{ \"app-zone-history\": null, \"devices\": [{\"device-id\":\"AOC2460#4&fe3a015&0&UID65793_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{568EBC3A-C09C-483E-A64D-6F1F2AF4E48D}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}], \"custom-zone-sets\": []}";
|
||||
data.LoadFancyZonesData();
|
||||
|
||||
Assert::IsTrue(data.GetCustomZoneSetsMap().empty());
|
||||
Assert::IsTrue(data.GetAppZoneHistoryMap().empty());
|
||||
Assert::IsFalse(data.GetDeviceInfoMap().empty());
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CustomLayoutsTests.Spec.cpp" />
|
||||
<ClCompile Include="FancyZones.Spec.cpp" />
|
||||
<ClCompile Include="FancyZonesSettings.Spec.cpp" />
|
||||
<ClCompile Include="JsonHelpers.Tests.cpp" />
|
||||
|
||||
@@ -48,6 +48,9 @@
|
||||
<ClCompile Include="LayoutTemplatesTests.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CustomLayoutsTests.Spec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
|
||||
@@ -1000,7 +1000,7 @@ namespace FancyZonesUnitTests
|
||||
{
|
||||
const std::wstring uuid = L"uuid";
|
||||
const CanvasLayoutInfo info{ -1, 100, { CanvasLayoutInfo::Rect{ -10, -10, 100, 100 }, CanvasLayoutInfo::Rect{ 50, 50, 150, 150 } } };
|
||||
JSONHelpers::CustomZoneSetJSON expected{ uuid, CustomZoneSetData{ L"name", CustomLayoutType::Canvas, info } };
|
||||
JSONHelpers::CustomZoneSetJSON expected{ uuid, CustomLayoutData{ L"name", CustomLayoutType::Canvas, info } };
|
||||
json::to_file(m_path, JSONHelpers::CustomZoneSetJSON::ToJson(expected));
|
||||
Assert::IsTrue(std::filesystem::exists(m_path));
|
||||
|
||||
@@ -1026,7 +1026,7 @@ namespace FancyZonesUnitTests
|
||||
.rowsPercents = { -100 }, //rows percents are negative
|
||||
.columnsPercents = { 2500, 2500 }, //column percents count is invalid
|
||||
.cellChildMap = { { 0, 1, 2 } } }));
|
||||
JSONHelpers::CustomZoneSetJSON expected{ uuid, CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
JSONHelpers::CustomZoneSetJSON expected{ uuid, CustomLayoutData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
json::to_file(m_path, JSONHelpers::CustomZoneSetJSON::ToJson(expected));
|
||||
Assert::IsTrue(std::filesystem::exists(m_path));
|
||||
|
||||
@@ -1043,69 +1043,13 @@ namespace FancyZonesUnitTests
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneFromValidCanvasLayoutInfo)
|
||||
{
|
||||
//prepare device data
|
||||
FancyZonesDataInstance().SetDeviceInfo(FancyZonesDataTypes::DeviceIdData{ L"default_device_id" }, DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 });
|
||||
|
||||
//prepare expected data
|
||||
wil::unique_cotaskmem_string uuid;
|
||||
Assert::AreEqual(S_OK, StringFromCLSID(m_id, &uuid));
|
||||
const CanvasLayoutInfo info{ 123, 321, { CanvasLayoutInfo::Rect{ 0, 0, 100, 100 }, CanvasLayoutInfo::Rect{ 50, 50, 150, 150 } } };
|
||||
CustomZoneSetData zoneSetData{ L"name", CustomLayoutType::Canvas, info };
|
||||
FancyZonesDataInstance().SetCustomZonesets(uuid.get(), zoneSetData);
|
||||
|
||||
//test
|
||||
const int spacing = 10;
|
||||
const int zoneCount = static_cast<int>(info.zones.size());
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, ZoneSetLayoutType::Custom, 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, ZoneSetLayoutType::Custom, zoneCount, monitorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneFromValidGridFullLayoutInfo)
|
||||
{
|
||||
//prepare device data
|
||||
FancyZonesDataInstance().SetDeviceInfo(FancyZonesDataTypes::DeviceIdData{ L"default_device_id" }, DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 });
|
||||
|
||||
//prepare expected data
|
||||
wil::unique_cotaskmem_string uuid;
|
||||
Assert::AreEqual(S_OK, StringFromCLSID(m_id, &uuid));
|
||||
const GridLayoutInfo grid(GridLayoutInfo(GridLayoutInfo::Full{
|
||||
.rows = 1,
|
||||
.columns = 3,
|
||||
.rowsPercents = { 10000 },
|
||||
.columnsPercents = { 2500, 5000, 2500 },
|
||||
.cellChildMap = { { 0, 1, 2 } } }));
|
||||
CustomZoneSetData zoneSetData{ L"name", CustomLayoutType::Grid, grid };
|
||||
FancyZonesDataInstance().SetCustomZonesets(uuid.get(), zoneSetData);
|
||||
|
||||
const int spacing = 10;
|
||||
const int zoneCount = grid.rows() * grid.columns();
|
||||
|
||||
ZoneSetConfig m_config = ZoneSetConfig(m_id, ZoneSetLayoutType::Custom, 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, ZoneSetLayoutType::Custom, zoneCount, monitorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (CustomZoneFromValidGridMinimalLayoutInfo)
|
||||
{
|
||||
const std::wstring uuid = L"uuid";
|
||||
const GridLayoutInfo grid(GridLayoutInfo(GridLayoutInfo::Minimal{
|
||||
.rows = 1,
|
||||
.columns = 3 }));
|
||||
JSONHelpers::CustomZoneSetJSON expected{ uuid, CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
JSONHelpers::CustomZoneSetJSON expected{ uuid, CustomLayoutData{ L"name", CustomLayoutType::Grid, grid } };
|
||||
json::to_file(m_path, JSONHelpers::CustomZoneSetJSON::ToJson(expected));
|
||||
Assert::IsTrue(std::filesystem::exists(m_path));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user