mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Format unittests (#906)
This commit is contained in:
@@ -5,32 +5,31 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(RegistryHelpersUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(GetDefaultKey)
|
||||
{
|
||||
// Test the path to the key is the same string.
|
||||
wchar_t key[256];
|
||||
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(nullptr, key, ARRAYSIZE(key)), L"Software\\SuperFancyZones"));
|
||||
}
|
||||
|
||||
TEST_METHOD(GetKeyWithMonitor)
|
||||
{
|
||||
// Test the path to the key is the same string.
|
||||
wchar_t key[256];
|
||||
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(L"Monitor1", key, ARRAYSIZE(key)), L"Software\\SuperFancyZones\\Monitor1"));
|
||||
}
|
||||
|
||||
TEST_METHOD(OpenKey)
|
||||
{
|
||||
// The default key should exist.
|
||||
wil::unique_hkey key{ RegistryHelpers::OpenKey({}) };
|
||||
Assert::IsNotNull(key.get());
|
||||
|
||||
// The Monitor1 key shouldn't exist.
|
||||
wil::unique_hkey key2{ RegistryHelpers::OpenKey(L"Monitor1") };
|
||||
Assert::IsNull(key2.get());
|
||||
}
|
||||
};
|
||||
TEST_CLASS(RegistryHelpersUnitTests){
|
||||
public:
|
||||
TEST_METHOD(GetDefaultKey){
|
||||
// Test the path to the key is the same string.
|
||||
wchar_t key[256];
|
||||
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(nullptr, key, ARRAYSIZE(key)), L"Software\\SuperFancyZones"));
|
||||
}
|
||||
|
||||
TEST_METHOD(GetKeyWithMonitor)
|
||||
{
|
||||
// Test the path to the key is the same string.
|
||||
wchar_t key[256];
|
||||
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(L"Monitor1", key, ARRAYSIZE(key)), L"Software\\SuperFancyZones\\Monitor1"));
|
||||
}
|
||||
|
||||
TEST_METHOD(OpenKey)
|
||||
{
|
||||
// The default key should exist.
|
||||
wil::unique_hkey key{ RegistryHelpers::OpenKey({}) };
|
||||
Assert::IsNotNull(key.get());
|
||||
|
||||
// The Monitor1 key shouldn't exist.
|
||||
wil::unique_hkey key2{ RegistryHelpers::OpenKey(L"Monitor1") };
|
||||
Assert::IsNull(key2.get());
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -5,29 +5,28 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(UtilUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestParseDeviceId)
|
||||
{
|
||||
// We're interested in the unique part between the first and last #'s
|
||||
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
|
||||
// Example output: DELA026#5&10a58c63&0&UID16777488
|
||||
PCWSTR input = L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}";
|
||||
wchar_t output[256]{};
|
||||
ParseDeviceId(input, output, ARRAYSIZE(output));
|
||||
Assert::AreEqual(0, wcscmp(output, L"DELA026#5&10a58c63&0&UID16777488"));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestParseInvalidDeviceId)
|
||||
{
|
||||
// We're interested in the unique part between the first and last #'s
|
||||
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
|
||||
// Example output: DELA026#5&10a58c63&0&UID16777488
|
||||
PCWSTR input = L"AnInvalidDeviceId";
|
||||
wchar_t output[256]{};
|
||||
ParseDeviceId(input, output, ARRAYSIZE(output));
|
||||
Assert::AreEqual(0, wcscmp(output, L"FallbackDevice"));
|
||||
}
|
||||
};
|
||||
TEST_CLASS(UtilUnitTests){
|
||||
public:
|
||||
TEST_METHOD(TestParseDeviceId){
|
||||
// We're interested in the unique part between the first and last #'s
|
||||
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
|
||||
// Example output: DELA026#5&10a58c63&0&UID16777488
|
||||
PCWSTR input = L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}";
|
||||
wchar_t output[256]{};
|
||||
ParseDeviceId(input, output, ARRAYSIZE(output));
|
||||
Assert::AreEqual(0, wcscmp(output, L"DELA026#5&10a58c63&0&UID16777488"));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestParseInvalidDeviceId)
|
||||
{
|
||||
// We're interested in the unique part between the first and last #'s
|
||||
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
|
||||
// Example output: DELA026#5&10a58c63&0&UID16777488
|
||||
PCWSTR input = L"AnInvalidDeviceId";
|
||||
wchar_t output[256]{};
|
||||
ParseDeviceId(input, output, ARRAYSIZE(output));
|
||||
Assert::AreEqual(0, wcscmp(output, L"FallbackDevice"));
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -5,50 +5,48 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(ZoneUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestCreateZone)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
Assert::IsNotNull(&zone);
|
||||
CustomAssert::AreEqual(zoneRect, zone->GetZoneRect());
|
||||
TEST_CLASS(ZoneUnitTests){
|
||||
public:
|
||||
TEST_METHOD(TestCreateZone){
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
Assert::IsNotNull(&zone);
|
||||
CustomAssert::AreEqual(zoneRect, zone->GetZoneRect());
|
||||
|
||||
constexpr size_t id = 10;
|
||||
zone->SetId(id);
|
||||
Assert::AreEqual(zone->Id(), id);
|
||||
}
|
||||
|
||||
TEST_METHOD(ContainsWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddRemoveWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
zone->AddWindowToZone(newWindow, Mocks::Window(), true);
|
||||
Assert::IsTrue(zone->ContainsWindow(newWindow));
|
||||
|
||||
zone->RemoveWindowFromZone(newWindow, false);
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestRemoveInvalidWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
zone->RemoveWindowFromZone(newWindow, false);
|
||||
}
|
||||
|
||||
};
|
||||
constexpr size_t id = 10;
|
||||
zone->SetId(id);
|
||||
Assert::AreEqual(zone->Id(), id);
|
||||
}
|
||||
|
||||
TEST_METHOD(ContainsWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddRemoveWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
zone->AddWindowToZone(newWindow, Mocks::Window(), true);
|
||||
Assert::IsTrue(zone->ContainsWindow(newWindow));
|
||||
|
||||
zone->RemoveWindowFromZone(newWindow, false);
|
||||
Assert::IsFalse(zone->ContainsWindow(newWindow));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestRemoveInvalidWindow)
|
||||
{
|
||||
RECT zoneRect{ 10, 10, 200, 200 };
|
||||
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
|
||||
HWND newWindow = Mocks::Window();
|
||||
zone->RemoveWindowFromZone(newWindow, false);
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -5,187 +5,186 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(ZoneSetUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneSet)
|
||||
{
|
||||
GUID zoneSetId{};
|
||||
CoCreateGuid(&zoneSetId);
|
||||
constexpr WORD layoutId = 0xFFFF;
|
||||
TEST_CLASS(ZoneSetUnitTests){
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneSet){
|
||||
GUID zoneSetId{};
|
||||
CoCreateGuid(&zoneSetId);
|
||||
constexpr WORD layoutId = 0xFFFF;
|
||||
|
||||
ZoneSetConfig config(zoneSetId, layoutId, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
Assert::IsNotNull(&set);
|
||||
CustomAssert::AreEqual(set->Id(), zoneSetId);
|
||||
CustomAssert::AreEqual(set->LayoutId(), layoutId);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a zone
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 1);
|
||||
Assert::IsTrue(zones[0] == zone);
|
||||
Assert::IsTrue(zone->Id() == 1);
|
||||
}
|
||||
|
||||
// Add a second zone at the back.
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 2);
|
||||
Assert::IsTrue(zones[1] == zone);
|
||||
Assert::IsTrue(zone->Id() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 1);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithNoZones)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithInvalidIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 100);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
};
|
||||
|
||||
// MoveWindowIntoZoneByDirection is complicated enough to warrant it's own test class
|
||||
TEST_CLASS(MoveWindowIntoZoneByDirectionUnitTests)
|
||||
{
|
||||
winrt::com_ptr<IZoneSet> set;
|
||||
winrt::com_ptr<IZone> zone1;
|
||||
winrt::com_ptr<IZone> zone2;
|
||||
winrt::com_ptr<IZone> zone3;
|
||||
|
||||
TEST_METHOD_INITIALIZE(Initialize)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRightNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeftNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
};
|
||||
ZoneSetConfig config(zoneSetId, layoutId, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
Assert::IsNotNull(&set);
|
||||
CustomAssert::AreEqual(set->Id(), zoneSetId);
|
||||
CustomAssert::AreEqual(set->LayoutId(), layoutId);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a zone
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 1);
|
||||
Assert::IsTrue(zones[0] == zone);
|
||||
Assert::IsTrue(zone->Id() == 1);
|
||||
}
|
||||
|
||||
// Add a second zone at the back.
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 2);
|
||||
Assert::IsTrue(zones[1] == zone);
|
||||
Assert::IsTrue(zone->Id() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 1);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithNoZones)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithInvalidIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 100);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
// MoveWindowIntoZoneByDirection is complicated enough to warrant it's own test class
|
||||
TEST_CLASS(MoveWindowIntoZoneByDirectionUnitTests)
|
||||
{
|
||||
winrt::com_ptr<IZoneSet> set;
|
||||
winrt::com_ptr<IZone> zone1;
|
||||
winrt::com_ptr<IZone> zone2;
|
||||
winrt::com_ptr<IZone> zone3;
|
||||
|
||||
TEST_METHOD_INITIALIZE(Initialize)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRightNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeftNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,41 +5,40 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(ZoneWindowUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneWindow)
|
||||
{
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), Mocks::Monitor(), L"DeviceId", L"MyVirtualDesktopId", false);
|
||||
Assert::IsNotNull(zoneWindow.get());
|
||||
}
|
||||
|
||||
TEST_METHOD(TestDeviceId)
|
||||
{
|
||||
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, L"SomeRandomValue", L"MyVirtualDesktopId", false);
|
||||
// We have no way to test the correctness, just do our best and check its not an empty string.
|
||||
Assert::IsTrue(zoneWindow->DeviceId().size() > 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestUniqueId)
|
||||
{
|
||||
// Unique id of the format "ParsedMonitorDeviceId_MonitorWidth_MonitorHeight_VirtualDesktopId
|
||||
// Example: "DELA026#5&10a58c63&0&UID16777488_1024_768_MyVirtualDesktopId"
|
||||
std::wstring deviceId(L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}");
|
||||
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
MONITORINFO info;
|
||||
info.cbSize = sizeof(info);
|
||||
Assert::IsTrue(GetMonitorInfo(pimaryMonitor, &info));
|
||||
|
||||
Rect monitorRect = Rect(info.rcMonitor);
|
||||
std::wstringstream ss;
|
||||
ss << L"DELA026#5&10a58c63&0&UID16777488_" << monitorRect.width() << "_" << monitorRect.height() << "_MyVirtualDesktopId";
|
||||
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, deviceId.c_str(), L"MyVirtualDesktopId", false);
|
||||
Assert::AreEqual(zoneWindow->UniqueId().compare(ss.str()), 0);
|
||||
}
|
||||
};
|
||||
TEST_CLASS(ZoneWindowUnitTests){
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneWindow){
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), Mocks::Monitor(), L"DeviceId", L"MyVirtualDesktopId", false);
|
||||
Assert::IsNotNull(zoneWindow.get());
|
||||
}
|
||||
|
||||
TEST_METHOD(TestDeviceId)
|
||||
{
|
||||
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, L"SomeRandomValue", L"MyVirtualDesktopId", false);
|
||||
// We have no way to test the correctness, just do our best and check its not an empty string.
|
||||
Assert::IsTrue(zoneWindow->DeviceId().size() > 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestUniqueId)
|
||||
{
|
||||
// Unique id of the format "ParsedMonitorDeviceId_MonitorWidth_MonitorHeight_VirtualDesktopId
|
||||
// Example: "DELA026#5&10a58c63&0&UID16777488_1024_768_MyVirtualDesktopId"
|
||||
std::wstring deviceId(L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}");
|
||||
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
MONITORINFO info;
|
||||
info.cbSize = sizeof(info);
|
||||
Assert::IsTrue(GetMonitorInfo(pimaryMonitor, &info));
|
||||
|
||||
Rect monitorRect = Rect(info.rcMonitor);
|
||||
std::wstringstream ss;
|
||||
ss << L"DELA026#5&10a58c63&0&UID16777488_" << monitorRect.width() << "_" << monitorRect.height() << "_MyVirtualDesktopId";
|
||||
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, deviceId.c_str(), L"MyVirtualDesktopId", false);
|
||||
Assert::AreEqual(zoneWindow->UniqueId().compare(ss.str()), 0);
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user