2020-02-10 14:59:51 +01:00
|
|
|
#include "pch.h"
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
|
|
#include <lib/JsonHelpers.h>
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
#include <CppUnitTestLogger.h>
|
|
|
|
|
|
|
|
|
|
using namespace JSONHelpers;
|
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
|
|
|
|
|
namespace FancyZonesUnitTests
|
|
|
|
|
{
|
|
|
|
|
void compareJsonObjects(const json::JsonObject& expected, const json::JsonObject& actual, bool recursive = true)
|
|
|
|
|
{
|
|
|
|
|
auto iter = expected.First();
|
|
|
|
|
while (iter.HasCurrent())
|
|
|
|
|
{
|
|
|
|
|
const auto key = iter.Current().Key();
|
|
|
|
|
Assert::IsTrue(actual.HasKey(key), key.c_str());
|
|
|
|
|
|
|
|
|
|
const std::wstring expectedStringified = iter.Current().Value().Stringify().c_str();
|
|
|
|
|
const std::wstring actualStringified = actual.GetNamedValue(key).Stringify().c_str();
|
|
|
|
|
|
|
|
|
|
if (recursive)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject expectedJson;
|
|
|
|
|
if (json::JsonObject::TryParse(expectedStringified, expectedJson))
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject actualJson;
|
|
|
|
|
if (json::JsonObject::TryParse(actualStringified, actualJson))
|
|
|
|
|
{
|
|
|
|
|
compareJsonObjects(expectedJson, actualJson, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Assert::IsTrue(false, key.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Assert::AreEqual(expectedStringified, actualStringified, key.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Assert::AreEqual(expectedStringified, actualStringified, key.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iter.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_CLASS(ZoneSetLayoutTypeUnitTest){
|
2020-02-10 14:59:51 +01:00
|
|
|
TEST_METHOD(ZoneSetLayoutTypeToString){
|
|
|
|
|
std::map<int, std::wstring> expectedMap = {
|
|
|
|
|
std::make_pair(-2, L"TypeToString_ERROR"),
|
|
|
|
|
std::make_pair(-1, L"blank"),
|
|
|
|
|
std::make_pair(0, L"focus"),
|
|
|
|
|
std::make_pair(1, L"columns"),
|
|
|
|
|
std::make_pair(2, L"rows"),
|
|
|
|
|
std::make_pair(3, L"grid"),
|
|
|
|
|
std::make_pair(4, L"priority-grid"),
|
|
|
|
|
std::make_pair(5, L"custom"),
|
|
|
|
|
std::make_pair(6, L"TypeToString_ERROR"),
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
for (const auto& expected : expectedMap)
|
|
|
|
|
{
|
|
|
|
|
auto actual = JSONHelpers::TypeToString(static_cast<ZoneSetLayoutType>(expected.first));
|
|
|
|
|
Assert::AreEqual(expected.second, actual);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(ZoneSetLayoutTypeFromString)
|
|
|
|
|
{
|
|
|
|
|
std::map<ZoneSetLayoutType, std::wstring> expectedMap = {
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Focus, L"focus"),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Columns, L"columns"),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Rows, L"rows"),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Grid, L"grid"),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::PriorityGrid, L"priority-grid"),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Custom, L"custom"),
|
|
|
|
|
};
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
for (const auto& expected : expectedMap)
|
|
|
|
|
{
|
|
|
|
|
auto actual = JSONHelpers::TypeFromString(expected.second);
|
|
|
|
|
Assert::AreEqual(static_cast<int>(expected.first), static_cast<int>(actual));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(ZoneSetLayoutTypeFromLayoutId)
|
|
|
|
|
{
|
|
|
|
|
std::map<ZoneSetLayoutType, int> expectedMap = {
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Focus, 0xFFFF),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Columns, 0xFFFD),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Rows, 0xFFFE),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Grid, 0xFFFC),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::PriorityGrid, 0xFFFB),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Blank, 0xFFFA),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Custom, 0),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Custom, 1),
|
|
|
|
|
std::make_pair(ZoneSetLayoutType::Custom, -1),
|
2020-02-10 14:59:51 +01:00
|
|
|
};
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
for (const auto& expected : expectedMap)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = JSONHelpers::TypeFromLayoutId(expected.second);
|
|
|
|
|
Assert::AreEqual(static_cast<int>(expected.first), static_cast<int>(actual));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_CLASS(CanvasLayoutInfoUnitTests)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject m_json = json::JsonObject::Parse(L"{\"ref-width\": 123, \"ref-height\": 321, \"zones\": [{\"X\": 11, \"Y\": 22, \"width\": 33, \"height\": 44}, {\"X\": 55, \"Y\": 66, \"width\": 77, \"height\": 88}]}");
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(ToJson)
|
|
|
|
|
{
|
|
|
|
|
CanvasLayoutInfo info;
|
|
|
|
|
info.referenceWidth = 123;
|
|
|
|
|
info.referenceHeight = 321;
|
|
|
|
|
info.zones = { CanvasLayoutInfo::Rect{ 11, 22, 33, 44 }, CanvasLayoutInfo::Rect{ 55, 66, 77, 88 } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = CanvasLayoutInfo::ToJson(info);
|
|
|
|
|
compareJsonObjects(m_json, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJson)
|
|
|
|
|
{
|
|
|
|
|
CanvasLayoutInfo expected;
|
|
|
|
|
expected.referenceWidth = 123;
|
|
|
|
|
expected.referenceHeight = 321;
|
|
|
|
|
expected.zones = { CanvasLayoutInfo::Rect{ 11, 22, 33, 44 }, CanvasLayoutInfo::Rect{ 55, 66, 77, 88 } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = CanvasLayoutInfo::FromJson(m_json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.referenceHeight, actual->referenceHeight);
|
|
|
|
|
Assert::AreEqual(expected.referenceWidth, actual->referenceWidth);
|
|
|
|
|
Assert::AreEqual(expected.zones.size(), actual->zones.size());
|
|
|
|
|
for (int i = 0; i < expected.zones.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
Assert::AreEqual(expected.zones[i].x, actual->zones[i].x);
|
|
|
|
|
Assert::AreEqual(expected.zones[i].y, actual->zones[i].y);
|
|
|
|
|
Assert::AreEqual(expected.zones[i].width, actual->zones[i].width);
|
|
|
|
|
Assert::AreEqual(expected.zones[i].height, actual->zones[i].height);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonMissingKeys)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
CanvasLayoutInfo info{ 123, 321, { CanvasLayoutInfo::Rect{ 11, 22, 33, 44 }, CanvasLayoutInfo::Rect{ 55, 66, 77, 88 } } };
|
|
|
|
|
const auto json = CanvasLayoutInfo::ToJson(info);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto iter = json.First();
|
|
|
|
|
while (iter.HasCurrent())
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject modifiedJson = json::JsonObject::Parse(json.Stringify());
|
|
|
|
|
modifiedJson.Remove(iter.Current().Key());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = CanvasLayoutInfo::FromJson(modifiedJson);
|
|
|
|
|
Assert::IsFalse(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
iter.MoveNext();
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
|
|
|
|
};
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_CLASS(GridLayoutInfoUnitTests)
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
GridLayoutInfo m_info = GridLayoutInfo(GridLayoutInfo::Minimal{ .rows = 3, .columns = 4 });
|
|
|
|
|
json::JsonObject m_gridJson = json::JsonObject();
|
|
|
|
|
json::JsonArray m_rowsArray, m_columnsArray, m_cells;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
void compareSizes(int expectedRows, int expectedColumns, const GridLayoutInfo& actual)
|
|
|
|
|
{
|
|
|
|
|
Assert::AreEqual(expectedRows, actual.rows());
|
|
|
|
|
Assert::AreEqual(expectedColumns, actual.columns());
|
|
|
|
|
Assert::AreEqual((size_t)expectedRows, actual.rowsPercents().size());
|
|
|
|
|
Assert::AreEqual((size_t)expectedColumns, actual.columnsPercents().size());
|
|
|
|
|
Assert::AreEqual((size_t)expectedRows, actual.cellChildMap().size());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
for (int i = 0; i < expectedRows; i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual((size_t)expectedColumns, actual.cellChildMap()[i].size());
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
void compareVectors(const std::vector<int>& expected, const std::vector<int>& actual)
|
|
|
|
|
{
|
|
|
|
|
Assert::AreEqual(expected.size(), actual.size());
|
|
|
|
|
for (int i = 0; i < expected.size(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected[i], actual[i]);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
void compareGridInfos(const GridLayoutInfo& expected, const GridLayoutInfo& actual)
|
|
|
|
|
{
|
|
|
|
|
compareSizes(expected.rows(), expected.columns(), actual);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
compareVectors(expected.rowsPercents(), actual.rowsPercents());
|
|
|
|
|
compareVectors(expected.columnsPercents(), actual.columnsPercents());
|
|
|
|
|
for (int i = 0; i < expected.cellChildMap().size(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
compareVectors(expected.cellChildMap()[i], actual.cellChildMap()[i]);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD_INITIALIZE(Init)
|
|
|
|
|
{
|
|
|
|
|
m_info = GridLayoutInfo(GridLayoutInfo::Minimal{ .rows = 3, .columns = 4 });
|
|
|
|
|
for (int i = 0; i < m_info.rows(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
int row = rand() % 100;
|
|
|
|
|
m_rowsArray.Append(json::JsonValue::CreateNumberValue(row));
|
|
|
|
|
m_info.rowsPercents()[i] = row;
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
for (int i = 0; i < m_info.columns(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
int column = rand() % 100;
|
|
|
|
|
m_columnsArray.Append(json::JsonValue::CreateNumberValue(column));
|
|
|
|
|
m_info.columnsPercents()[i] = column;
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
for (int i = 0; i < m_info.rows(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonArray cellsArray;
|
|
|
|
|
for (int j = 0; j < m_info.columns(); j++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
int cell = rand() % 100;
|
|
|
|
|
m_info.cellChildMap()[i][j] = cell;
|
|
|
|
|
cellsArray.Append(json::JsonValue::CreateNumberValue(cell));
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
m_cells.Append(cellsArray);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
m_gridJson = json::JsonObject::Parse(L"{\"rows\": 3, \"columns\": 4}");
|
|
|
|
|
m_gridJson.SetNamedValue(L"rows-percentage", m_rowsArray);
|
|
|
|
|
m_gridJson.SetNamedValue(L"columns-percentage", m_columnsArray);
|
|
|
|
|
m_gridJson.SetNamedValue(L"cell-child-map", m_cells);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD_CLEANUP(Cleanup)
|
|
|
|
|
{
|
|
|
|
|
m_rowsArray.Clear();
|
|
|
|
|
m_cells.Clear();
|
|
|
|
|
m_columnsArray.Clear();
|
|
|
|
|
m_gridJson.Clear();
|
|
|
|
|
m_info = GridLayoutInfo(GridLayoutInfo::Minimal{ .rows = 3, .columns = 4 });
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
public:
|
|
|
|
|
TEST_METHOD(CreationZero)
|
|
|
|
|
{
|
|
|
|
|
const int expectedRows = 0, expectedColumns = 0;
|
|
|
|
|
GridLayoutInfo info(GridLayoutInfo::Minimal{ .rows = expectedRows, .columns = expectedColumns });
|
|
|
|
|
compareSizes(expectedRows, expectedColumns, info);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(Creation)
|
|
|
|
|
{
|
|
|
|
|
const int expectedRows = 3, expectedColumns = 4;
|
|
|
|
|
const std::vector<int> expectedRowsPercents = { 0, 0, 0 };
|
|
|
|
|
const std::vector<int> expectedColumnsPercents = { 0, 0, 0, 0 };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
GridLayoutInfo info(GridLayoutInfo::Minimal{ .rows = expectedRows, .columns = expectedColumns });
|
|
|
|
|
compareSizes(expectedRows, expectedColumns, info);
|
|
|
|
|
|
|
|
|
|
compareVectors(expectedRowsPercents, info.rowsPercents());
|
|
|
|
|
compareVectors(expectedColumnsPercents, info.columnsPercents());
|
|
|
|
|
for (int i = 0; i < info.cellChildMap().size(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
compareVectors({ 0, 0, 0, 0 }, info.cellChildMap()[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CreationFull)
|
|
|
|
|
{
|
|
|
|
|
const int expectedRows = 3, expectedColumns = 4;
|
|
|
|
|
const std::vector<int> expectedRowsPercents = { 1, 2, 3 };
|
|
|
|
|
const std::vector<int> expectedColumnsPercents = { 4, 3, 2, 1 };
|
|
|
|
|
const std::vector<std::vector<int>> expectedCells = { expectedColumnsPercents, expectedColumnsPercents, expectedColumnsPercents };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
GridLayoutInfo info(GridLayoutInfo::Full{
|
|
|
|
|
.rows = expectedRows,
|
|
|
|
|
.columns = expectedColumns,
|
|
|
|
|
.rowsPercents = expectedRowsPercents,
|
|
|
|
|
.columnsPercents = expectedColumnsPercents,
|
|
|
|
|
.cellChildMap = expectedCells });
|
|
|
|
|
compareSizes(expectedRows, expectedColumns, info);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
compareVectors(expectedRowsPercents, info.rowsPercents());
|
|
|
|
|
compareVectors(expectedColumnsPercents, info.columnsPercents());
|
|
|
|
|
for (int i = 0; i < info.cellChildMap().size(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
compareVectors(expectedCells[i], info.cellChildMap()[i]);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CreationFullVectorsSmaller)
|
|
|
|
|
{
|
|
|
|
|
const int expectedRows = 3, expectedColumns = 4;
|
|
|
|
|
const std::vector<int> expectedRowsPercents = { 1, 2, 0 };
|
|
|
|
|
const std::vector<int> expectedColumnsPercents = { 4, 3, 0, 0 };
|
|
|
|
|
const std::vector<std::vector<int>> expectedCells = { { 0, 0, 0, 0 }, { 1, 0, 0, 0 }, { 1, 2, 0, 0 } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
GridLayoutInfo info(GridLayoutInfo::Full{
|
|
|
|
|
.rows = expectedRows,
|
|
|
|
|
.columns = expectedColumns,
|
|
|
|
|
.rowsPercents = { 1, 2 },
|
|
|
|
|
.columnsPercents = { 4, 3 },
|
|
|
|
|
.cellChildMap = { {}, { 1 }, { 1, 2 } } });
|
|
|
|
|
compareSizes(expectedRows, expectedColumns, info);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
compareVectors(expectedRowsPercents, info.rowsPercents());
|
|
|
|
|
compareVectors(expectedColumnsPercents, info.columnsPercents());
|
|
|
|
|
for (int i = 0; i < info.cellChildMap().size(); i++)
|
|
|
|
|
{
|
|
|
|
|
compareVectors(expectedCells[i], info.cellChildMap()[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CreationFullVectorsBigger)
|
|
|
|
|
{
|
|
|
|
|
const int expectedRows = 3, expectedColumns = 4;
|
|
|
|
|
const std::vector<int> expectedRowsPercents = { 1, 2, 3 };
|
|
|
|
|
const std::vector<int> expectedColumnsPercents = { 4, 3, 2, 1 };
|
|
|
|
|
const std::vector<std::vector<int>> expectedCells = { expectedColumnsPercents, expectedColumnsPercents, expectedColumnsPercents };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
GridLayoutInfo info(GridLayoutInfo::Full{
|
|
|
|
|
.rows = expectedRows,
|
|
|
|
|
.columns = expectedColumns,
|
|
|
|
|
.rowsPercents = { 1, 2, 3, 4, 5 },
|
|
|
|
|
.columnsPercents = { 4, 3, 2, 1, 0, -1 },
|
|
|
|
|
.cellChildMap = { { 4, 3, 2, 1, 0, -1 }, { 4, 3, 2, 1, 0, -1 }, { 4, 3, 2, 1, 0, -1 } } });
|
|
|
|
|
compareSizes(expectedRows, expectedColumns, info);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
compareVectors(expectedRowsPercents, info.rowsPercents());
|
|
|
|
|
compareVectors(expectedColumnsPercents, info.columnsPercents());
|
|
|
|
|
for (int i = 0; i < info.cellChildMap().size(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
compareVectors(expectedCells[i], info.cellChildMap()[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(ToJson)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject expected = json::JsonObject(m_gridJson);
|
|
|
|
|
GridLayoutInfo info = m_info;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = GridLayoutInfo::ToJson(info);
|
|
|
|
|
compareJsonObjects(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJson)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = json::JsonObject(m_gridJson);
|
|
|
|
|
GridLayoutInfo expected = m_info;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = GridLayoutInfo::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
|
|
|
|
compareGridInfos(expected, *actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonEmptyArray)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject json = json::JsonObject::Parse(L"{\"rows\": 0, \"columns\": 0}");
|
|
|
|
|
GridLayoutInfo expected(GridLayoutInfo::Minimal{ 0, 0 });
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json.SetNamedValue(L"rows-percentage", json::JsonArray());
|
|
|
|
|
json.SetNamedValue(L"columns-percentage", json::JsonArray());
|
|
|
|
|
json.SetNamedValue(L"cell-child-map", json::JsonArray());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = GridLayoutInfo::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
|
|
|
|
compareGridInfos(expected, *actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonSmallerArray)
|
|
|
|
|
{
|
|
|
|
|
GridLayoutInfo expected = m_info;
|
|
|
|
|
expected.rowsPercents().pop_back();
|
|
|
|
|
expected.columnsPercents().pop_back();
|
|
|
|
|
expected.cellChildMap().pop_back();
|
|
|
|
|
expected.cellChildMap()[0].pop_back();
|
|
|
|
|
json::JsonObject json = GridLayoutInfo::ToJson(expected);
|
|
|
|
|
|
|
|
|
|
auto actual = GridLayoutInfo::FromJson(json);
|
|
|
|
|
Assert::IsFalse(actual.has_value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(FromJsonBiggerArray)
|
|
|
|
|
{
|
|
|
|
|
GridLayoutInfo expected = m_info;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
//extra
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
expected.rowsPercents().push_back(rand() % 100);
|
|
|
|
|
expected.columnsPercents().push_back(rand() % 100);
|
|
|
|
|
expected.cellChildMap().push_back({});
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
for (int j = 0; j < 5; j++)
|
|
|
|
|
{
|
|
|
|
|
expected.cellChildMap()[i].push_back(rand() % 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto json = GridLayoutInfo::ToJson(expected);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = GridLayoutInfo::FromJson(json);
|
|
|
|
|
Assert::IsFalse(actual.has_value());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonMissingKeys)
|
|
|
|
|
{
|
|
|
|
|
GridLayoutInfo info = m_info;
|
|
|
|
|
const auto json = json::JsonObject(m_gridJson);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto iter = json.First();
|
|
|
|
|
while (iter.HasCurrent())
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject modifiedJson = json::JsonObject::Parse(json.Stringify());
|
|
|
|
|
modifiedJson.Remove(iter.Current().Key());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = GridLayoutInfo::FromJson(modifiedJson);
|
|
|
|
|
Assert::IsFalse(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
iter.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_CLASS(CustomZoneSetUnitTests){
|
|
|
|
|
TEST_METHOD(ToJsonGrid){
|
|
|
|
|
CustomZoneSetJSON zoneSet{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Grid, GridLayoutInfo(GridLayoutInfo::Minimal{}) } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject expected = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"name\": \"name\", \"type\": \"grid\"}");
|
|
|
|
|
expected.SetNamedValue(L"info", GridLayoutInfo::ToJson(std::get<GridLayoutInfo>(zoneSet.data.info)));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = CustomZoneSetJSON::ToJson(zoneSet);
|
|
|
|
|
compareJsonObjects(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(ToJsonCanvas)
|
|
|
|
|
{
|
|
|
|
|
CustomZoneSetJSON zoneSet{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{} } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject expected = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"name\": \"name\", \"type\": \"canvas\"}");
|
|
|
|
|
expected.SetNamedValue(L"info", CanvasLayoutInfo::ToJson(std::get<CanvasLayoutInfo>(zoneSet.data.info)));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = CustomZoneSetJSON::ToJson(zoneSet);
|
|
|
|
|
compareJsonObjects(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonGrid)
|
|
|
|
|
{
|
|
|
|
|
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 } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"name\": \"name\", \"type\": \"grid\"}");
|
|
|
|
|
json.SetNamedValue(L"info", GridLayoutInfo::ToJson(std::get<GridLayoutInfo>(expected.data.info)));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = CustomZoneSetJSON::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.uuid.c_str(), actual->uuid.c_str());
|
|
|
|
|
Assert::AreEqual(expected.data.name.c_str(), actual->data.name.c_str());
|
|
|
|
|
Assert::AreEqual((int)expected.data.type, (int)actual->data.type);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto expectedGrid = std::get<GridLayoutInfo>(expected.data.info);
|
|
|
|
|
auto actualGrid = std::get<GridLayoutInfo>(actual->data.info);
|
|
|
|
|
Assert::AreEqual(expectedGrid.rows(), actualGrid.rows());
|
|
|
|
|
Assert::AreEqual(expectedGrid.columns(), actualGrid.columns());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonCanvas)
|
|
|
|
|
{
|
|
|
|
|
CustomZoneSetJSON expected{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 2, 1 } } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"name\": \"name\", \"type\": \"canvas\"}");
|
|
|
|
|
json.SetNamedValue(L"info", CanvasLayoutInfo::ToJson(std::get<CanvasLayoutInfo>(expected.data.info)));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = CustomZoneSetJSON::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.uuid.c_str(), actual->uuid.c_str());
|
|
|
|
|
Assert::AreEqual(expected.data.name.c_str(), actual->data.name.c_str());
|
|
|
|
|
Assert::AreEqual((int)expected.data.type, (int)actual->data.type);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto expectedGrid = std::get<CanvasLayoutInfo>(expected.data.info);
|
|
|
|
|
auto actualGrid = std::get<CanvasLayoutInfo>(actual->data.info);
|
|
|
|
|
Assert::AreEqual(expectedGrid.referenceWidth, actualGrid.referenceWidth);
|
|
|
|
|
Assert::AreEqual(expectedGrid.referenceHeight, actualGrid.referenceHeight);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonMissingKeys)
|
|
|
|
|
{
|
|
|
|
|
CustomZoneSetJSON zoneSet{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 2, 1 } } };
|
|
|
|
|
const auto json = CustomZoneSetJSON::ToJson(zoneSet);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto iter = json.First();
|
|
|
|
|
while (iter.HasCurrent())
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject modifiedJson = json::JsonObject::Parse(json.Stringify());
|
|
|
|
|
modifiedJson.Remove(iter.Current().Key());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = CustomZoneSetJSON::FromJson(modifiedJson);
|
|
|
|
|
Assert::IsFalse(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
iter.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
TEST_CLASS(ZoneSetDataUnitTest){
|
|
|
|
|
TEST_METHOD(ToJsonGeneral){
|
|
|
|
|
json::JsonObject expected = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"type\": \"rows\"}");
|
|
|
|
|
ZoneSetData data{ L"uuid", ZoneSetLayoutType::Rows };
|
|
|
|
|
const auto actual = ZoneSetData::ToJson(data);
|
|
|
|
|
compareJsonObjects(expected, actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(FromJsonGeneral)
|
|
|
|
|
{
|
|
|
|
|
ZoneSetData expected{ L"uuid", ZoneSetLayoutType::Columns };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"type\": \"columns\"}");
|
|
|
|
|
auto actual = ZoneSetData::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.uuid.c_str(), actual->uuid.c_str());
|
|
|
|
|
Assert::AreEqual((int)expected.type, (int)actual->type);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonTypeInvalid)
|
|
|
|
|
{
|
|
|
|
|
ZoneSetData expected{ L"uuid", ZoneSetLayoutType::Blank };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = json::JsonObject::Parse(L"{\"uuid\": \"uuid\", \"type\": \"invalid_type\"}");
|
|
|
|
|
auto actual = ZoneSetData::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.uuid.c_str(), actual->uuid.c_str());
|
|
|
|
|
Assert::AreEqual((int)expected.type, (int)actual->type);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonMissingKeys)
|
|
|
|
|
{
|
|
|
|
|
ZoneSetData data{ L"uuid", ZoneSetLayoutType::Columns };
|
|
|
|
|
const auto json = ZoneSetData::ToJson(data);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto iter = json.First();
|
|
|
|
|
while (iter.HasCurrent())
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject modifiedJson = json::JsonObject::Parse(json.Stringify());
|
|
|
|
|
modifiedJson.Remove(iter.Current().Key());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = ZoneSetData::FromJson(modifiedJson);
|
|
|
|
|
Assert::IsFalse(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
iter.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_CLASS(AppZoneHistoryUnitTests){
|
|
|
|
|
TEST_METHOD(ToJson){
|
|
|
|
|
AppZoneHistoryJSON appZoneHistory{ L"appPath", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } };
|
|
|
|
|
json::JsonObject expected = json::JsonObject::Parse(L"{\"app-path\": \"appPath\", \"device-id\": \"device-id\", \"zoneset-uuid\": \"zoneset-uuid\", \"zone-index\": 54321}");
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = AppZoneHistoryJSON::ToJson(appZoneHistory);
|
|
|
|
|
compareJsonObjects(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJson)
|
|
|
|
|
{
|
|
|
|
|
AppZoneHistoryJSON expected{ L"appPath", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } };
|
|
|
|
|
json::JsonObject json = json::JsonObject::Parse(L"{\"app-path\": \"appPath\", \"device-id\": \"device-id\", \"zoneset-uuid\": \"zoneset-uuid\", \"zone-index\": 54321}");
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = AppZoneHistoryJSON::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.appPath.c_str(), actual->appPath.c_str());
|
|
|
|
|
Assert::AreEqual(expected.data.zoneIndex, actual->data.zoneIndex);
|
|
|
|
|
Assert::AreEqual(expected.data.deviceId.c_str(), actual->data.deviceId.c_str());
|
|
|
|
|
Assert::AreEqual(expected.data.zoneSetUuid.c_str(), actual->data.zoneSetUuid.c_str());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonMissingKeys)
|
|
|
|
|
{
|
|
|
|
|
AppZoneHistoryJSON appZoneHistory{ L"appPath", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } };
|
|
|
|
|
const auto json = AppZoneHistoryJSON::ToJson(appZoneHistory);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto iter = json.First();
|
|
|
|
|
while (iter.HasCurrent())
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject modifiedJson = json::JsonObject::Parse(json.Stringify());
|
|
|
|
|
modifiedJson.Remove(iter.Current().Key());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = AppZoneHistoryJSON::FromJson(modifiedJson);
|
|
|
|
|
Assert::IsFalse(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
iter.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_CLASS(DeviceInfoUnitTests)
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
DeviceInfoJSON m_defaultDeviceInfo = DeviceInfoJSON{ L"default_device_id", DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 } };
|
|
|
|
|
json::JsonObject m_defaultJson = json::JsonObject::Parse(L"{\"device-id\": \"default_device_id\", \"active-zoneset\": {\"type\": \"custom\", \"uuid\": \"uuid\"}, \"editor-show-spacing\": true, \"editor-spacing\": 16, \"editor-zone-count\": 3}");
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
public:
|
|
|
|
|
TEST_METHOD(ToJson)
|
|
|
|
|
{
|
|
|
|
|
DeviceInfoJSON deviceInfo = m_defaultDeviceInfo;
|
|
|
|
|
json::JsonObject expected = m_defaultJson;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = DeviceInfoJSON::ToJson(deviceInfo);
|
|
|
|
|
compareJsonObjects(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJson)
|
|
|
|
|
{
|
|
|
|
|
DeviceInfoJSON expected = m_defaultDeviceInfo;
|
|
|
|
|
expected.data.spacing = true;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = DeviceInfoJSON::ToJson(expected);
|
|
|
|
|
auto actual = DeviceInfoJSON::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.deviceId.c_str(), actual->deviceId.c_str(), L"device id");
|
|
|
|
|
Assert::AreEqual(expected.data.zoneCount, actual->data.zoneCount, L"zone count");
|
|
|
|
|
Assert::AreEqual((int)expected.data.activeZoneSet.type, (int)actual->data.activeZoneSet.type, L"zone set type");
|
|
|
|
|
Assert::AreEqual(expected.data.activeZoneSet.uuid.c_str(), actual->data.activeZoneSet.uuid.c_str(), L"zone set uuid");
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonSpacingTrue)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
DeviceInfoJSON expected = m_defaultDeviceInfo;
|
|
|
|
|
expected.data.spacing = true;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = DeviceInfoJSON::ToJson(expected);
|
|
|
|
|
auto actual = DeviceInfoJSON::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.data.spacing, actual->data.spacing);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonSpacingFalse)
|
|
|
|
|
{
|
|
|
|
|
DeviceInfoJSON expected = m_defaultDeviceInfo;
|
|
|
|
|
expected.data.activeZoneSet.type = ZoneSetLayoutType::Custom;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = DeviceInfoJSON::ToJson(expected);
|
|
|
|
|
auto actual = DeviceInfoJSON::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.data.spacing, actual->data.spacing);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonZoneGeneral)
|
|
|
|
|
{
|
|
|
|
|
DeviceInfoJSON expected = m_defaultDeviceInfo;
|
|
|
|
|
expected.data.activeZoneSet.type = ZoneSetLayoutType::PriorityGrid;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json = DeviceInfoJSON::ToJson(expected);
|
|
|
|
|
auto actual = DeviceInfoJSON::FromJson(json);
|
|
|
|
|
Assert::IsTrue(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual((int)expected.data.activeZoneSet.type, (int)actual->data.activeZoneSet.type, L"zone set type");
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FromJsonMissingKeys)
|
|
|
|
|
{
|
|
|
|
|
DeviceInfoJSON deviceInfo{ L"default_device_id", DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 } };
|
|
|
|
|
const auto json = DeviceInfoJSON::ToJson(deviceInfo);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto iter = json.First();
|
|
|
|
|
while (iter.HasCurrent())
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject modifiedJson = json::JsonObject::Parse(json.Stringify());
|
|
|
|
|
modifiedJson.Remove(iter.Current().Key());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = DeviceInfoJSON::FromJson(modifiedJson);
|
|
|
|
|
Assert::IsFalse(actual.has_value());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
iter.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_CLASS(FancyZonesDataUnitTests)
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
const std::wstring m_defaultCustomDeviceStr = L"{\"device-id\": \"default_device_id\", \"active-zoneset\": {\"type\": \"custom\", \"uuid\": \"uuid\"}, \"editor-show-spacing\": true, \"editor-spacing\": 16, \"editor-zone-count\": 3}";
|
|
|
|
|
const json::JsonValue m_defaultCustomDeviceValue = json::JsonValue::Parse(m_defaultCustomDeviceStr);
|
|
|
|
|
const json::JsonObject m_defaultCustomDeviceObj = json::JsonObject::Parse(m_defaultCustomDeviceStr);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
HINSTANCE m_hInst{};
|
|
|
|
|
FancyZonesData& m_fzData = FancyZonesDataInstance();
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
void compareJsonArrays(const json::JsonArray& expected, const json::JsonArray& actual)
|
|
|
|
|
{
|
|
|
|
|
Assert::AreEqual(expected.Size(), actual.Size());
|
|
|
|
|
for (uint32_t i = 0; i < expected.Size(); i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
compareJsonObjects(expected.GetObjectAt(i), actual.GetObjectAt(i));
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD_INITIALIZE(Init)
|
|
|
|
|
{
|
|
|
|
|
m_hInst = (HINSTANCE)GetModuleHandleW(nullptr);
|
|
|
|
|
m_fzData.clear_data();
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
public:
|
|
|
|
|
TEST_METHOD(FancyZonesDataPath)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
Assert::IsFalse(data.GetPersistFancyZonesJSONPath().empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FancyZonesDataJsonEmpty)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const auto jsonPath = data.GetPersistFancyZonesJSONPath();
|
|
|
|
|
auto savedJson = json::from_file(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
if (std::filesystem::exists(jsonPath))
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject expected;
|
|
|
|
|
auto actual = data.GetPersistFancyZonesJSON();
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::AreEqual(expected.Stringify().c_str(), actual.Stringify().c_str());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
if (savedJson)
|
|
|
|
|
{
|
|
|
|
|
json::to_file(jsonPath, *savedJson);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(FancyZonesDataJson)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const auto jsonPath = data.GetPersistFancyZonesJSONPath();
|
|
|
|
|
auto savedJson = json::from_file(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
if (std::filesystem::exists(jsonPath))
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject expected = json::JsonObject::Parse(L"{\"fancy-zones\":{\"custom-zonesets \":[{\"uuid\":\"uuid1\",\"name\":\"Custom1\",\"type\":\"custom\" }] } }");
|
|
|
|
|
json::to_file(jsonPath, expected);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = data.GetPersistFancyZonesJSON();
|
|
|
|
|
Assert::AreEqual(expected.Stringify().c_str(), actual.Stringify().c_str());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
if (savedJson)
|
|
|
|
|
{
|
|
|
|
|
json::to_file(jsonPath, *savedJson);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
else
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FancyZonesDataDeviceInfoMap)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const auto actual = data.GetDeviceInfoMap();
|
|
|
|
|
Assert::IsTrue(actual.empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FancyZonesDataDeviceInfoMapParseEmpty)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject json;
|
|
|
|
|
data.ParseDeviceInfos(json);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
const auto actual = data.GetDeviceInfoMap();
|
|
|
|
|
Assert::IsTrue(actual.empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FancyZonesDataDeviceInfoMapParseValidEmpty)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject expected;
|
|
|
|
|
json::JsonArray zoneSets;
|
|
|
|
|
expected.SetNamedValue(L"devices", zoneSets);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
data.ParseDeviceInfos(expected);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
const auto actual = data.GetDeviceInfoMap();
|
|
|
|
|
Assert::IsTrue(actual.empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FancyZonesDataDeviceInfoMapParseInvalid)
|
|
|
|
|
{
|
|
|
|
|
json::JsonArray devices;
|
|
|
|
|
devices.Append(json::JsonObject::Parse(m_defaultCustomDeviceStr));
|
|
|
|
|
devices.Append(json::JsonObject::Parse(L"{\"device-id\": \"device_id\"}"));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject expected;
|
|
|
|
|
expected.SetNamedValue(L"devices", devices);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
auto actual = data.ParseDeviceInfos(expected);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::IsFalse(actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FancyZonesDataDeviceInfoMapParseSingle)
|
|
|
|
|
{
|
|
|
|
|
json::JsonArray devices;
|
|
|
|
|
devices.Append(m_defaultCustomDeviceValue);
|
|
|
|
|
json::JsonObject expected;
|
|
|
|
|
expected.SetNamedValue(L"devices", devices);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseDeviceInfos(expected);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
const auto actualMap = data.GetDeviceInfoMap();
|
|
|
|
|
Assert::AreEqual((size_t)1, actualMap.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(FancyZonesDataDeviceInfoMapParseMany)
|
|
|
|
|
{
|
|
|
|
|
json::JsonArray devices;
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject obj = json::JsonObject::Parse(m_defaultCustomDeviceStr);
|
|
|
|
|
obj.SetNamedValue(L"device-id", json::JsonValue::CreateStringValue(std::to_wstring(i)));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Logger::WriteMessage(obj.Stringify().c_str());
|
|
|
|
|
Logger::WriteMessage("\n");
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
devices.Append(obj);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonObject expected;
|
|
|
|
|
expected.SetNamedValue(L"devices", devices);
|
|
|
|
|
Logger::WriteMessage(expected.Stringify().c_str());
|
|
|
|
|
Logger::WriteMessage("\n");
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseDeviceInfos(expected);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
const auto actualMap = data.GetDeviceInfoMap();
|
|
|
|
|
Assert::AreEqual((size_t)10, actualMap.size());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(FancyZonesDataSerialize)
|
|
|
|
|
{
|
|
|
|
|
json::JsonArray expectedDevices;
|
|
|
|
|
expectedDevices.Append(m_defaultCustomDeviceObj);
|
|
|
|
|
json::JsonObject expected;
|
|
|
|
|
expected.SetNamedValue(L"devices", expectedDevices);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseDeviceInfos(expected);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = data.SerializeDeviceInfos();
|
|
|
|
|
compareJsonArrays(expectedDevices, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(DeviceInfoSaveTemp)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
DeviceInfoJSON deviceInfo{ L"default_device_id", DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
const std::wstring path = data.GetPersistFancyZonesJSONPath() + L".test_tmp";
|
|
|
|
|
data.SerializeDeviceInfoToTmpFile(deviceInfo, path);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
bool actualFileExists = std::filesystem::exists(path);
|
|
|
|
|
Assert::IsTrue(actualFileExists);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto expectedData = DeviceInfoJSON::ToJson(deviceInfo);
|
|
|
|
|
auto actualSavedData = json::from_file(path);
|
|
|
|
|
std::filesystem::remove(path); //clean up before compare asserts
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::IsTrue(actualSavedData.has_value());
|
|
|
|
|
compareJsonObjects(expectedData, *actualSavedData);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(DeviceInfoReadTemp)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const std::wstring zoneUuid = L"default_device_id";
|
|
|
|
|
DeviceInfoJSON expected{ zoneUuid, DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 } };
|
|
|
|
|
const std::wstring path = data.GetPersistFancyZonesJSONPath() + L".test_tmp";
|
|
|
|
|
data.SerializeDeviceInfoToTmpFile(expected, path);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
data.ParseDeviceInfoFromTmpFile(path);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
bool actualFileExists = std::filesystem::exists(path);
|
|
|
|
|
if (actualFileExists)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(path); //clean up before compare asserts
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::IsFalse(actualFileExists);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto devices = data.GetDeviceInfoMap();
|
|
|
|
|
Assert::AreEqual((size_t)1, devices.size());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = devices.find(zoneUuid)->second;
|
|
|
|
|
Assert::AreEqual(expected.data.showSpacing, actual.showSpacing);
|
|
|
|
|
Assert::AreEqual(expected.data.spacing, actual.spacing);
|
|
|
|
|
Assert::AreEqual(expected.data.zoneCount, actual.zoneCount);
|
|
|
|
|
Assert::AreEqual((int)expected.data.activeZoneSet.type, (int)actual.activeZoneSet.type);
|
|
|
|
|
Assert::AreEqual(expected.data.activeZoneSet.uuid.c_str(), actual.activeZoneSet.uuid.c_str());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(DeviceInfoReadTempUnexsisted)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const std::wstring path = data.GetPersistFancyZonesJSONPath() + L".test_tmp";
|
|
|
|
|
data.ParseDeviceInfoFromTmpFile(path);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto devices = data.GetDeviceInfoMap();
|
|
|
|
|
Assert::AreEqual((size_t)0, devices.size());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(AppZoneHistoryParseSingle)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring expectedAppPath = L"appPath";
|
|
|
|
|
const std::wstring expectedDeviceId = L"device-id";
|
|
|
|
|
const std::wstring expectedZoneSetId = L"zone-set-id";
|
|
|
|
|
const int expectedIndex = 54321;
|
|
|
|
|
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
AppZoneHistoryJSON expected{ expectedAppPath, AppZoneHistoryData{ .zoneSetUuid = expectedZoneSetId, .deviceId = expectedDeviceId, .zoneIndex = expectedIndex } };
|
|
|
|
|
json::JsonArray zoneHistoryArray;
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(expected));
|
|
|
|
|
json.SetNamedValue(L"app-zone-history", json::JsonValue::Parse(zoneHistoryArray.Stringify()));
|
|
|
|
|
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseAppZoneHistory(json);
|
|
|
|
|
|
|
|
|
|
const auto actualProcessHistoryMap = data.GetAppZoneHistoryMap();
|
|
|
|
|
Assert::AreEqual((size_t)zoneHistoryArray.Size(), actualProcessHistoryMap.size());
|
|
|
|
|
|
|
|
|
|
const auto actualProcessHistory = actualProcessHistoryMap.begin();
|
|
|
|
|
Assert::AreEqual(expectedAppPath.c_str(), actualProcessHistory->first.c_str());
|
|
|
|
|
|
|
|
|
|
const auto actualAppZoneHistory = actualProcessHistory->second;
|
|
|
|
|
Assert::AreEqual(expectedZoneSetId.c_str(), actualAppZoneHistory.zoneSetUuid.c_str());
|
|
|
|
|
Assert::AreEqual(expectedDeviceId.c_str(), actualAppZoneHistory.deviceId.c_str());
|
|
|
|
|
Assert::AreEqual(expectedIndex, actualAppZoneHistory.zoneIndex);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(AppZoneHistoryParseManyApps)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json::JsonArray zoneHistoryArray;
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ L"app-path-1", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid-1", .deviceId = L"device-id-1", .zoneIndex = 1 } }));
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ L"app-path-2", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid-2", .deviceId = L"device-id-2", .zoneIndex = 2 } }));
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ L"app-path-3", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid-3", .deviceId = L"device-id-3", .zoneIndex = 3 } }));
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ L"app-path-4", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid-4", .deviceId = L"device-id-4", .zoneIndex = 4 } }));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json.SetNamedValue(L"app-zone-history", json::JsonValue::Parse(zoneHistoryArray.Stringify()));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseAppZoneHistory(json);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actualMap = data.GetAppZoneHistoryMap();
|
|
|
|
|
Assert::AreEqual((size_t)zoneHistoryArray.Size(), actualMap.size());
|
|
|
|
|
|
|
|
|
|
const auto actualProcessHistoryMap = data.GetAppZoneHistoryMap();
|
|
|
|
|
Assert::AreEqual((size_t)zoneHistoryArray.Size(), actualProcessHistoryMap.size());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto iter = zoneHistoryArray.First();
|
|
|
|
|
while (iter.HasCurrent())
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
auto expected = AppZoneHistoryJSON::FromJson(json::JsonObject::Parse(iter.Current().Stringify()));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
const auto actual = actualProcessHistoryMap.at(expected->appPath);
|
|
|
|
|
Assert::AreEqual(expected->data.deviceId.c_str(), actual.deviceId.c_str());
|
|
|
|
|
Assert::AreEqual(expected->data.zoneSetUuid.c_str(), actual.zoneSetUuid.c_str());
|
|
|
|
|
Assert::AreEqual(expected->data.zoneIndex, actual.zoneIndex);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
iter.MoveNext();
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(AppZoneHistoryParseManyZonesForSingleApp)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json::JsonArray zoneHistoryArray;
|
|
|
|
|
|
|
|
|
|
const auto appPath = L"app-path";
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ appPath, AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid-1", .deviceId = L"device-id-1", .zoneIndex = 1 } }));
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ appPath, AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid-2", .deviceId = L"device-id-2", .zoneIndex = 2 } }));
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ appPath, AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid-3", .deviceId = L"device-id-3", .zoneIndex = 3 } }));
|
|
|
|
|
const auto expected = AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid-4", .deviceId = L"device-id-4", .zoneIndex = 4 };
|
|
|
|
|
zoneHistoryArray.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ appPath, expected }));
|
|
|
|
|
json.SetNamedValue(L"app-zone-history", json::JsonValue::Parse(zoneHistoryArray.Stringify()));
|
|
|
|
|
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseAppZoneHistory(json);
|
|
|
|
|
|
|
|
|
|
const auto actualProcessHistoryMap = data.GetAppZoneHistoryMap();
|
|
|
|
|
Assert::AreEqual((size_t)1, actualProcessHistoryMap.size());
|
|
|
|
|
|
|
|
|
|
const auto actual = actualProcessHistoryMap.at(appPath);
|
|
|
|
|
Assert::AreEqual(expected.deviceId.c_str(), actual.deviceId.c_str());
|
|
|
|
|
Assert::AreEqual(expected.zoneSetUuid.c_str(), actual.zoneSetUuid.c_str());
|
|
|
|
|
Assert::AreEqual(expected.zoneIndex, actual.zoneIndex);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(AppZoneHistoryParseEmpty)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseAppZoneHistory(json::JsonObject());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = data.GetAppZoneHistoryMap();
|
|
|
|
|
Assert::IsTrue(actual.empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(AppZoneHistoryParseInvalid)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring appPath = L"appPath";
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
AppZoneHistoryJSON expected{ appPath, AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } };
|
|
|
|
|
json.SetNamedValue(L"app-zone-history", json::JsonValue::Parse(AppZoneHistoryJSON::ToJson(expected).Stringify()));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
bool actual = data.ParseAppZoneHistory(json);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::IsFalse(actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(AppZoneHistorySerializeSingle)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring appPath = L"appPath";
|
|
|
|
|
json::JsonArray expected;
|
|
|
|
|
expected.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ appPath, AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } }));
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json.SetNamedValue(L"app-zone-history", json::JsonValue::Parse(expected.Stringify()));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseAppZoneHistory(json);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = data.SerializeAppZoneHistory();
|
|
|
|
|
compareJsonArrays(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(AppZoneHistorySerializeMany)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json::JsonArray expected;
|
|
|
|
|
expected.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ L"app-path-1", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } }));
|
|
|
|
|
expected.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ L"app-path-2", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } }));
|
|
|
|
|
expected.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ L"app-path-3", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } }));
|
|
|
|
|
expected.Append(AppZoneHistoryJSON::ToJson(AppZoneHistoryJSON{ L"app-path-4", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } }));
|
|
|
|
|
json.SetNamedValue(L"app-zone-history", json::JsonValue::Parse(expected.Stringify()));
|
|
|
|
|
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseAppZoneHistory(json);
|
|
|
|
|
|
|
|
|
|
auto actual = data.SerializeAppZoneHistory();
|
|
|
|
|
compareJsonArrays(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(AppZoneHistorySerializeEmpty)
|
|
|
|
|
{
|
|
|
|
|
json::JsonArray expected;
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json.SetNamedValue(L"app-zone-history", json::JsonValue::Parse(expected.Stringify()));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseAppZoneHistory(json);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = data.SerializeAppZoneHistory();
|
|
|
|
|
compareJsonArrays(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CustomZoneSetsParseSingle)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneUuid = L"uuid";
|
|
|
|
|
GridLayoutInfo grid(GridLayoutInfo(JSONHelpers::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()));
|
|
|
|
|
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseCustomZoneSets(json);
|
|
|
|
|
|
|
|
|
|
auto actualMap = data.GetCustomZoneSetsMap();
|
|
|
|
|
Assert::AreEqual((size_t)array.Size(), actualMap.size());
|
|
|
|
|
|
|
|
|
|
auto actual = actualMap.find(zoneUuid)->second;
|
|
|
|
|
Assert::AreEqual(expected.data.name.c_str(), actual.name.c_str());
|
|
|
|
|
Assert::AreEqual((int)expected.data.type, (int)actual.type);
|
|
|
|
|
|
|
|
|
|
auto expectedGrid = std::get<GridLayoutInfo>(expected.data.info);
|
|
|
|
|
auto actualGrid = std::get<GridLayoutInfo>(actual.info);
|
|
|
|
|
Assert::AreEqual(expectedGrid.rows(), actualGrid.rows());
|
|
|
|
|
Assert::AreEqual(expectedGrid.columns(), actualGrid.columns());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CustomZoneSetsParseMany)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json::JsonArray array;
|
|
|
|
|
const GridLayoutInfo grid(GridLayoutInfo(JSONHelpers::GridLayoutInfo::Full{
|
|
|
|
|
.rows = 1,
|
|
|
|
|
.columns = 3,
|
|
|
|
|
.rowsPercents = { 10000 },
|
|
|
|
|
.columnsPercents = { 2500, 5000, 2500 },
|
|
|
|
|
.cellChildMap = { { 0, 1, 2 } } }));
|
|
|
|
|
array.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"zone-uuid-1", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
|
|
|
|
array.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"zone-uuid-2", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 1, 2 } } }));
|
|
|
|
|
array.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"zone-uuid-3", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
|
|
|
|
array.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"zone-uuid-4", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 1, 2 } } }));
|
|
|
|
|
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(array.Stringify()));
|
|
|
|
|
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseCustomZoneSets(json);
|
|
|
|
|
|
|
|
|
|
auto actualMap = data.GetCustomZoneSetsMap();
|
|
|
|
|
Assert::AreEqual((size_t)array.Size(), actualMap.size());
|
|
|
|
|
|
|
|
|
|
auto iter = array.First();
|
|
|
|
|
while (iter.HasCurrent())
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
auto expected = CustomZoneSetJSON::FromJson(json::JsonObject::Parse(iter.Current().Stringify()));
|
|
|
|
|
auto actual = actualMap.find(expected->uuid)->second;
|
|
|
|
|
Assert::AreEqual(expected->data.name.c_str(), actual.name.c_str(), L"name");
|
|
|
|
|
Assert::AreEqual((int)expected->data.type, (int)actual.type, L"type");
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
if (expected->data.type == CustomLayoutType::Grid)
|
|
|
|
|
{
|
|
|
|
|
auto expectedInfo = std::get<GridLayoutInfo>(expected->data.info);
|
|
|
|
|
auto actualInfo = std::get<GridLayoutInfo>(actual.info);
|
|
|
|
|
Assert::AreEqual(expectedInfo.rows(), actualInfo.rows(), L"grid rows");
|
|
|
|
|
Assert::AreEqual(expectedInfo.columns(), actualInfo.columns(), L"grid columns");
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
else
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
auto expectedInfo = std::get<CanvasLayoutInfo>(expected->data.info);
|
|
|
|
|
auto actualInfo = std::get<CanvasLayoutInfo>(actual.info);
|
|
|
|
|
Assert::AreEqual(expectedInfo.referenceWidth, actualInfo.referenceWidth, L"canvas width");
|
|
|
|
|
Assert::AreEqual(expectedInfo.referenceHeight, actualInfo.referenceHeight, L"canvas height");
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
|
|
|
|
|
iter.MoveNext();
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CustomZoneSetsParseEmpty)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseCustomZoneSets(json::JsonObject());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = data.GetCustomZoneSetsMap();
|
|
|
|
|
Assert::IsTrue(actual.empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
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()));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
auto actual = data.ParseCustomZoneSets(json);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::IsFalse(actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CustomZoneSetsSerializeSingle)
|
|
|
|
|
{
|
|
|
|
|
json::JsonArray expected;
|
|
|
|
|
const GridLayoutInfo grid(GridLayoutInfo(JSONHelpers::GridLayoutInfo::Full{
|
|
|
|
|
.rows = 1,
|
|
|
|
|
.columns = 3,
|
|
|
|
|
.rowsPercents = { 10000 },
|
|
|
|
|
.columnsPercents = { 2500, 5000, 2500 },
|
|
|
|
|
.cellChildMap = { { 0, 1, 2 } } }));
|
|
|
|
|
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"uuid", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(expected.Stringify()));
|
|
|
|
|
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseCustomZoneSets(json);
|
|
|
|
|
|
|
|
|
|
auto actual = data.SerializeCustomZoneSets();
|
|
|
|
|
compareJsonArrays(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CustomZoneSetsSerializeMany)
|
|
|
|
|
{
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json::JsonArray expected;
|
|
|
|
|
const GridLayoutInfo grid(GridLayoutInfo(JSONHelpers::GridLayoutInfo::Full{
|
|
|
|
|
.rows = 1,
|
|
|
|
|
.columns = 3,
|
|
|
|
|
.rowsPercents = { 10000 },
|
|
|
|
|
.columnsPercents = { 2500, 5000, 2500 },
|
|
|
|
|
.cellChildMap = { { 0, 1, 2 } } }));
|
|
|
|
|
|
|
|
|
|
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"zone-uuid-1", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
|
|
|
|
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"zone-uuid-2", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 1, 2 } } }));
|
|
|
|
|
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"zone-uuid-3", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } }));
|
|
|
|
|
expected.Append(CustomZoneSetJSON::ToJson(CustomZoneSetJSON{ L"zone-uuid-4", CustomZoneSetData{ L"name", CustomLayoutType::Canvas, CanvasLayoutInfo{ 1, 2 } } }));
|
|
|
|
|
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(expected.Stringify()));
|
|
|
|
|
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseCustomZoneSets(json);
|
|
|
|
|
|
|
|
|
|
auto actual = data.SerializeCustomZoneSets();
|
|
|
|
|
compareJsonArrays(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CustomZoneSetsSerializeEmpty)
|
|
|
|
|
{
|
|
|
|
|
json::JsonArray expected;
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json.SetNamedValue(L"custom-zone-sets", json::JsonValue::Parse(expected.Stringify()));
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
data.ParseCustomZoneSets(json);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = data.SerializeCustomZoneSets();
|
|
|
|
|
compareJsonArrays(expected, actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CustomZoneSetsReadTemp)
|
|
|
|
|
{
|
|
|
|
|
//prepare device data
|
|
|
|
|
const std::wstring deviceId = L"default_device_id";
|
2020-02-10 14:59:51 +01:00
|
|
|
|
|
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
DeviceInfoJSON deviceInfo{ deviceId, DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 } };
|
|
|
|
|
const std::wstring deviceInfoPath = m_fzData.GetPersistFancyZonesJSONPath() + L".device_info_tmp";
|
|
|
|
|
m_fzData.SerializeDeviceInfoToTmpFile(deviceInfo, deviceInfoPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
m_fzData.ParseDeviceInfoFromTmpFile(deviceInfoPath);
|
|
|
|
|
std::filesystem::remove(deviceInfoPath);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
const std::wstring uuid = L"uuid";
|
|
|
|
|
const GridLayoutInfo grid(GridLayoutInfo(JSONHelpers::GridLayoutInfo::Full{
|
|
|
|
|
.rows = 1,
|
|
|
|
|
.columns = 3,
|
|
|
|
|
.rowsPercents = { 10000 },
|
|
|
|
|
.columnsPercents = { 2500, 5000, 2500 },
|
|
|
|
|
.cellChildMap = { { 0, 1, 2 } } }));
|
|
|
|
|
CustomZoneSetJSON expected{ uuid, CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } };
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
FancyZonesData data;
|
|
|
|
|
const std::wstring path = data.GetPersistFancyZonesJSONPath() + L".test_tmp";
|
|
|
|
|
json::to_file(path, CustomZoneSetJSON::ToJson(expected));
|
|
|
|
|
m_fzData.ParseCustomZoneSetFromTmpFile(path);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
bool actualFileExists = std::filesystem::exists(path);
|
|
|
|
|
if (actualFileExists)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(path); //clean up before compare asserts
|
|
|
|
|
}
|
|
|
|
|
Assert::IsFalse(actualFileExists);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto devices = m_fzData.GetCustomZoneSetsMap();
|
|
|
|
|
Assert::AreEqual((size_t)1, devices.size());
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = devices.find(uuid)->second;
|
|
|
|
|
Assert::AreEqual((int)expected.data.type, (int)actual.type);
|
|
|
|
|
Assert::AreEqual(expected.data.name.c_str(), actual.name.c_str());
|
|
|
|
|
auto expectedGrid = std::get<GridLayoutInfo>(expected.data.info);
|
|
|
|
|
auto actualGrid = std::get<GridLayoutInfo>(actual.info);
|
|
|
|
|
Assert::AreEqual(expectedGrid.rows(), actualGrid.rows());
|
|
|
|
|
Assert::AreEqual(expectedGrid.columns(), actualGrid.columns());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(CustomZoneSetsReadTempUnexsisted)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring path = m_fzData.GetPersistFancyZonesJSONPath() + L".test_tmp";
|
|
|
|
|
const std::wstring deviceId = L"default_device_id";
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
m_fzData.ParseCustomZoneSetFromTmpFile(path);
|
|
|
|
|
auto devices = m_fzData.GetDeviceInfoMap();
|
|
|
|
|
Assert::AreEqual((size_t)0, devices.size());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(SetActiveZoneSet)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const std::wstring uniqueId = L"default_device_id";
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::JsonArray devices;
|
|
|
|
|
devices.Append(m_defaultCustomDeviceValue);
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json.SetNamedValue(L"devices", devices);
|
|
|
|
|
data.ParseDeviceInfos(json);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
JSONHelpers::ZoneSetData expectedZoneSetData{
|
|
|
|
|
.uuid = L"uuid",
|
|
|
|
|
.type = ZoneSetLayoutType::Focus
|
|
|
|
|
};
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
data.SetActiveZoneSet(uniqueId, expectedZoneSetData);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
auto actual = data.GetDeviceInfoMap().find(uniqueId)->second;
|
|
|
|
|
Assert::AreEqual(expectedZoneSetData.uuid.c_str(), actual.activeZoneSet.uuid.c_str());
|
|
|
|
|
Assert::IsTrue(expectedZoneSetData.type == actual.activeZoneSet.type);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(SetActiveZoneSetUuidEmpty)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const std::wstring expected = L"uuid";
|
|
|
|
|
const std::wstring uniqueId = L"default_device_id";
|
|
|
|
|
|
|
|
|
|
json::JsonArray devices;
|
|
|
|
|
devices.Append(m_defaultCustomDeviceValue);
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json.SetNamedValue(L"devices", devices);
|
|
|
|
|
data.ParseDeviceInfos(json);
|
|
|
|
|
|
|
|
|
|
JSONHelpers::ZoneSetData expectedZoneSetData{
|
|
|
|
|
.uuid = L"",
|
|
|
|
|
.type = ZoneSetLayoutType::Focus
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
data.SetActiveZoneSet(uniqueId, expectedZoneSetData);
|
|
|
|
|
|
|
|
|
|
auto actual = data.GetDeviceInfoMap().find(uniqueId)->second;
|
|
|
|
|
Assert::AreEqual(expectedZoneSetData.uuid.c_str(), actual.activeZoneSet.uuid.c_str());
|
|
|
|
|
Assert::IsTrue(expectedZoneSetData.type == actual.activeZoneSet.type);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(SetActiveZoneSetUniqueIdInvalid)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const std::wstring expected = L"uuid";
|
|
|
|
|
const std::wstring uniqueId = L"id_not_contained_by_device_info_map";
|
|
|
|
|
|
|
|
|
|
json::JsonArray devices;
|
|
|
|
|
devices.Append(m_defaultCustomDeviceValue);
|
|
|
|
|
json::JsonObject json;
|
|
|
|
|
json.SetNamedValue(L"devices", devices);
|
|
|
|
|
bool parseRes = data.ParseDeviceInfos(json);
|
|
|
|
|
Assert::IsTrue(parseRes);
|
|
|
|
|
|
|
|
|
|
JSONHelpers::ZoneSetData zoneSetData{
|
|
|
|
|
.uuid = L"new_uuid",
|
|
|
|
|
.type = ZoneSetLayoutType::Focus
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
data.SetActiveZoneSet(uniqueId, zoneSetData);
|
|
|
|
|
|
|
|
|
|
const auto& deviceInfoMap = data.GetDeviceInfoMap();
|
|
|
|
|
auto actual = deviceInfoMap.find(L"default_device_id")->second;
|
|
|
|
|
Assert::AreEqual(expected.c_str(), actual.activeZoneSet.uuid.c_str());
|
|
|
|
|
Assert::IsTrue(deviceInfoMap.end() == deviceInfoMap.find(uniqueId), L"new device info should not be added");
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(LoadFancyZonesDataFromJson)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const auto jsonPath = data.GetPersistFancyZonesJSONPath();
|
|
|
|
|
auto savedJson = json::from_file(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
if (std::filesystem::exists(jsonPath))
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
const GridLayoutInfo grid(GridLayoutInfo(JSONHelpers::GridLayoutInfo::Full{
|
|
|
|
|
.rows = 1,
|
|
|
|
|
.columns = 3,
|
|
|
|
|
.rowsPercents = { 10000 },
|
|
|
|
|
.columnsPercents = { 2500, 5000, 2500 },
|
|
|
|
|
.cellChildMap = { { 0, 1, 2 } } }));
|
|
|
|
|
CustomZoneSetJSON zoneSets{ L"zone-set-uuid", CustomZoneSetData{ L"name", CustomLayoutType::Grid, grid } };
|
|
|
|
|
AppZoneHistoryJSON appZoneHistory{ L"app-path", AppZoneHistoryData{ .zoneSetUuid = L"zoneset-uuid", .deviceId = L"device-id", .zoneIndex = 54321 } };
|
|
|
|
|
DeviceInfoJSON deviceInfo{ L"uuid", DeviceInfoData{ ZoneSetData{ L"uuid", ZoneSetLayoutType::Custom }, true, 16, 3 } };
|
|
|
|
|
json::JsonArray zoneSetsArray, appZonesArray, deviceInfoArray;
|
|
|
|
|
zoneSetsArray.Append(CustomZoneSetJSON::ToJson(zoneSets));
|
|
|
|
|
appZonesArray.Append(AppZoneHistoryJSON::ToJson(appZoneHistory));
|
|
|
|
|
deviceInfoArray.Append(DeviceInfoJSON::ToJson(deviceInfo));
|
|
|
|
|
json::JsonObject fancyZones;
|
|
|
|
|
fancyZones.SetNamedValue(L"custom-zone-sets", zoneSetsArray);
|
|
|
|
|
fancyZones.SetNamedValue(L"app-zone-history", appZonesArray);
|
|
|
|
|
fancyZones.SetNamedValue(L"devices", deviceInfoArray);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
json::to_file(jsonPath, fancyZones);
|
|
|
|
|
|
|
|
|
|
data.LoadFancyZonesData();
|
|
|
|
|
if (savedJson)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::to_file(jsonPath, *savedJson);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
else
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::IsFalse(data.GetCustomZoneSetsMap().empty());
|
|
|
|
|
Assert::IsFalse(data.GetCustomZoneSetsMap().empty());
|
|
|
|
|
Assert::IsFalse(data.GetCustomZoneSetsMap().empty());
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(LoadFancyZonesDataFromRegistry)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const auto jsonPath = data.GetPersistFancyZonesJSONPath();
|
|
|
|
|
auto savedJson = json::from_file(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
if (std::filesystem::exists(jsonPath))
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
data.LoadFancyZonesData();
|
|
|
|
|
bool actual = std::filesystem::exists(jsonPath);
|
|
|
|
|
if (savedJson)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::to_file(jsonPath, *savedJson);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
else
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
Assert::IsTrue(actual);
|
|
|
|
|
}
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
TEST_METHOD(SaveFancyZonesData)
|
|
|
|
|
{
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
const auto jsonPath = data.GetPersistFancyZonesJSONPath();
|
|
|
|
|
auto savedJson = json::from_file(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
if (std::filesystem::exists(jsonPath))
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 18:28:49 +03:00
|
|
|
data.SaveFancyZonesData();
|
|
|
|
|
bool actual = std::filesystem::exists(jsonPath);
|
|
|
|
|
|
|
|
|
|
if (savedJson)
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
json::to_file(jsonPath, *savedJson);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
else
|
2020-02-10 14:59:51 +01:00
|
|
|
{
|
2020-02-17 18:28:49 +03:00
|
|
|
std::filesystem::remove(jsonPath);
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|
2020-02-17 18:28:49 +03:00
|
|
|
|
|
|
|
|
Assert::IsTrue(actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneIndex)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
Assert::AreEqual(-1, data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
|
|
|
|
|
const int expectedZoneIndex = 10;
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId, expectedZoneIndex));
|
|
|
|
|
Assert::AreEqual(expectedZoneIndex, data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneIndexZero)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
const int expectedZoneIndex = 0;
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId, expectedZoneIndex));
|
|
|
|
|
Assert::AreEqual(expectedZoneIndex, data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneIndexNegative)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
const int expectedZoneIndex = -1;
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId, expectedZoneIndex));
|
|
|
|
|
Assert::AreEqual(expectedZoneIndex, data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneIndexOverflow)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
const long expectedZoneIndex = LONG_MAX;
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId, expectedZoneIndex));
|
|
|
|
|
Assert::AreEqual(static_cast<int>(expectedZoneIndex), data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneIndexOverride)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
const int expectedZoneIndex = 3;
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId, 1));
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId, 2));
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId, expectedZoneIndex));
|
|
|
|
|
Assert::AreEqual(expectedZoneIndex, data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneInvalidWindow)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::Window();
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
Assert::AreEqual(-1, data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
|
|
|
|
|
const int expectedZoneIndex = 1;
|
|
|
|
|
Assert::IsFalse(data.SetAppLastZone(window, deviceId, zoneSetId, expectedZoneIndex));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneNullWindow)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const auto window = nullptr;
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
const int expectedZoneIndex = 1;
|
|
|
|
|
Assert::IsFalse(data.SetAppLastZone(window, L"device-id", zoneSetId, expectedZoneIndex));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastdeviceIdTest)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId1 = L"device-id-1";
|
|
|
|
|
const std::wstring deviceId2 = L"device-id-2";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
const int expectedZoneIndex = 10;
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId1, zoneSetId, expectedZoneIndex));
|
|
|
|
|
Assert::AreEqual(expectedZoneIndex, data.GetAppLastZoneIndex(window, deviceId1, zoneSetId));
|
|
|
|
|
Assert::AreEqual(-1, data.GetAppLastZoneIndex(window, deviceId2, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneSetIdTest)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId1 = L"zoneset-uuid-1";
|
|
|
|
|
const std::wstring zoneSetId2 = L"zoneset-uuid-2";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
const int expectedZoneIndex = 10;
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId1, expectedZoneIndex));
|
|
|
|
|
Assert::AreEqual(expectedZoneIndex, data.GetAppLastZoneIndex(window, deviceId, zoneSetId1));
|
|
|
|
|
Assert::AreEqual(-1, data.GetAppLastZoneIndex(window, deviceId, zoneSetId2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneRemoveWindow)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetId, 1));
|
|
|
|
|
Assert::IsTrue(data.RemoveAppLastZone(window, deviceId, zoneSetId));
|
|
|
|
|
Assert::AreEqual(-1, data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneRemoveUnknownWindow)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
Assert::IsFalse(data.RemoveAppLastZone(window, deviceId, zoneSetId));
|
|
|
|
|
Assert::AreEqual(-1, data.GetAppLastZoneIndex(window, deviceId, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneRemoveUnknownZoneSetId)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetIdToInsert = L"zoneset-uuid-to-insert";
|
|
|
|
|
const std::wstring zoneSetIdToRemove = L"zoneset-uuid-to-remove";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceId, zoneSetIdToInsert, 1));
|
|
|
|
|
Assert::IsFalse(data.RemoveAppLastZone(window, deviceId, zoneSetIdToRemove));
|
|
|
|
|
Assert::AreEqual(1, data.GetAppLastZoneIndex(window, deviceId, zoneSetIdToInsert));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneRemoveUnknownWindowId)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceIdToInsert = L"device-id-insert";
|
|
|
|
|
const std::wstring deviceIdToRemove = L"device-id-remove";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
Assert::IsTrue(data.SetAppLastZone(window, deviceIdToInsert, zoneSetId, 1));
|
|
|
|
|
Assert::IsFalse(data.RemoveAppLastZone(window, deviceIdToRemove, zoneSetId));
|
|
|
|
|
Assert::AreEqual(1, data.GetAppLastZoneIndex(window, deviceIdToInsert, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_METHOD(AppLastZoneRemoveNullWindow)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring zoneSetId = L"zoneset-uuid";
|
|
|
|
|
const std::wstring deviceId = L"device-id";
|
|
|
|
|
const auto window = Mocks::WindowCreate(m_hInst);
|
|
|
|
|
FancyZonesData data;
|
|
|
|
|
|
|
|
|
|
Assert::IsFalse(data.RemoveAppLastZone(nullptr, deviceId, zoneSetId));
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-02-10 14:59:51 +01:00
|
|
|
}
|