mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[FancyZones] Validate zone rect before adding it into layout (#6249)
* Validate zone rect before adding it into layout * Rename variables for better code readability
This commit is contained in:
@@ -85,6 +85,7 @@ namespace FancyZonesUnitTests
|
||||
TEST_METHOD (AddOne)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
Assert::IsNotNull(zone.get());
|
||||
m_set->AddZone(zone);
|
||||
auto zones = m_set->GetZones();
|
||||
Assert::AreEqual((size_t)1, zones.size());
|
||||
@@ -95,6 +96,7 @@ namespace FancyZonesUnitTests
|
||||
TEST_METHOD (AddManySame)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
Assert::IsNotNull(zone.get());
|
||||
for (size_t i = 0; i < 1024; i++)
|
||||
{
|
||||
m_set->AddZone(zone);
|
||||
@@ -110,6 +112,7 @@ namespace FancyZonesUnitTests
|
||||
for (size_t i = 0; i < 1024; i++)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
Assert::IsNotNull(zone.get());
|
||||
m_set->AddZone(zone);
|
||||
auto zones = m_set->GetZones();
|
||||
Assert::AreEqual(i + 1, zones.size());
|
||||
@@ -122,7 +125,12 @@ namespace FancyZonesUnitTests
|
||||
{
|
||||
for (size_t i = 0; i < 1024; i++)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ rand() % 10, rand() % 10, rand() % 100, rand() % 100 });
|
||||
int left = rand() % 10;
|
||||
int top = rand() % 10;
|
||||
int right = left + 1 + rand() % 100;
|
||||
int bottom = top + 1 + rand() % 100;
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ left, top, right, bottom });
|
||||
Assert::IsNotNull(zone.get());
|
||||
m_set->AddZone(zone);
|
||||
auto zones = m_set->GetZones();
|
||||
Assert::AreEqual(i + 1, zones.size());
|
||||
@@ -131,6 +139,30 @@ namespace FancyZonesUnitTests
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD (MakeZoneFromZeroRect)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 0, 0 });
|
||||
Assert::IsNotNull(zone.get());
|
||||
}
|
||||
|
||||
TEST_METHOD (MakeZoneFromInvalidRectWidth)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 100, 100, 99, 101 });
|
||||
Assert::IsNull(zone.get());
|
||||
}
|
||||
|
||||
TEST_METHOD (MakeZoneFromInvalidRectHeight)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 100, 100, 101, 99 });
|
||||
Assert::IsNull(zone.get());
|
||||
}
|
||||
|
||||
TEST_METHOD (MakeZoneFromInvalidRectCoords)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ -1, -1, -1, -1 });
|
||||
Assert::IsNull(zone.get());
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointEmpty)
|
||||
{
|
||||
auto actual = m_set->ZonesFromPoint(POINT{ 0, 0 });
|
||||
@@ -270,24 +302,6 @@ namespace FancyZonesUnitTests
|
||||
compareZones(zone4, m_set->GetZones()[actual[3]]);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointWithNotNormalizedRect)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 100, 100, 0, 0 });
|
||||
m_set->AddZone(zone);
|
||||
|
||||
auto actual = m_set->ZonesFromPoint(POINT{ 50, 50 });
|
||||
Assert::IsTrue(actual.size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneFromPointWithZeroRect)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 0, 0 });
|
||||
m_set->AddZone(zone);
|
||||
|
||||
auto actual = m_set->ZonesFromPoint(POINT{ 0, 0 });
|
||||
Assert::IsTrue(actual.size() == 0);
|
||||
}
|
||||
|
||||
TEST_METHOD (ZoneIndexFromWindowUnknown)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
|
||||
Reference in New Issue
Block a user