2019-09-04 18:26:26 +02:00
|
|
|
#include "pch.h"
|
|
|
|
|
|
2019-12-17 11:21:46 +03:00
|
|
|
#include <lib/util.h>
|
|
|
|
|
#include <lib/ZoneSet.h>
|
|
|
|
|
#include <lib/ZoneWindow.h>
|
|
|
|
|
#include "Util.h"
|
2019-09-04 18:26:26 +02:00
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
|
|
|
|
|
namespace FancyZonesUnitTests
|
|
|
|
|
{
|
2019-12-10 17:17:40 -08:00
|
|
|
struct MockZoneWindowHost : public winrt::implements<MockZoneWindowHost, IZoneWindowHost>
|
|
|
|
|
{
|
2019-12-11 08:34:18 -08:00
|
|
|
IFACEMETHODIMP_(void)
|
|
|
|
|
MoveWindowsOnActiveZoneSetChange() noexcept {};
|
|
|
|
|
IFACEMETHODIMP_(COLORREF)
|
|
|
|
|
GetZoneHighlightColor() noexcept
|
2019-12-10 17:17:40 -08:00
|
|
|
{
|
|
|
|
|
return RGB(0xFF, 0xFF, 0xFF);
|
|
|
|
|
}
|
2019-12-11 08:34:18 -08:00
|
|
|
IFACEMETHODIMP_(GUID)
|
|
|
|
|
GetCurrentMonitorZoneSetId(HMONITOR monitor) noexcept
|
2019-12-10 17:17:40 -08:00
|
|
|
{
|
|
|
|
|
return m_guid;
|
|
|
|
|
}
|
2020-01-06 09:59:18 -08:00
|
|
|
IFACEMETHODIMP_(int)
|
|
|
|
|
GetZoneHighlightOpacity() noexcept
|
|
|
|
|
{
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
2019-12-10 17:17:40 -08:00
|
|
|
|
|
|
|
|
GUID m_guid;
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-10 10:28:24 +03:00
|
|
|
TEST_CLASS(ZoneWindowUnitTests){
|
|
|
|
|
public:
|
2019-12-10 17:17:40 -08:00
|
|
|
|
2019-12-10 10:28:24 +03:00
|
|
|
TEST_METHOD(TestCreateZoneWindow){
|
|
|
|
|
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), Mocks::Monitor(), L"DeviceId", L"MyVirtualDesktopId", false);
|
|
|
|
|
Assert::IsNotNull(zoneWindow.get());
|
|
|
|
|
}
|
2019-09-04 18:26:26 +02:00
|
|
|
|
2019-12-10 10:28:24 +03:00
|
|
|
TEST_METHOD(TestDeviceId)
|
|
|
|
|
{
|
|
|
|
|
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
2019-12-11 08:34:18 -08:00
|
|
|
HMONITOR pimaryMonitor = MonitorFromWindow(HWND(), MONITOR_DEFAULTTOPRIMARY);
|
2019-12-10 17:17:40 -08:00
|
|
|
MockZoneWindowHost host;
|
|
|
|
|
std::wstring expectedDeviceId = L"SomeRandomValue";
|
|
|
|
|
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(dynamic_cast<IZoneWindowHost*>(&host), Mocks::Instance(), pimaryMonitor, expectedDeviceId.c_str(), L"MyVirtualDesktopId", false);
|
|
|
|
|
|
|
|
|
|
Assert::AreEqual(expectedDeviceId, zoneWindow->DeviceId());
|
2019-12-10 10:28:24 +03:00
|
|
|
}
|
2019-09-04 18:26:26 +02:00
|
|
|
|
2019-12-10 10:28:24 +03:00
|
|
|
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.
|
2019-12-10 17:17:40 -08:00
|
|
|
HMONITOR pimaryMonitor = MonitorFromWindow(HWND(), MONITOR_DEFAULTTOPRIMARY);
|
2019-12-10 10:28:24 +03:00
|
|
|
MONITORINFO info;
|
|
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
|
Assert::IsTrue(GetMonitorInfo(pimaryMonitor, &info));
|
2019-09-04 18:26:26 +02:00
|
|
|
|
2019-12-10 10:28:24 +03:00
|
|
|
Rect monitorRect = Rect(info.rcMonitor);
|
|
|
|
|
std::wstringstream ss;
|
|
|
|
|
ss << L"DELA026#5&10a58c63&0&UID16777488_" << monitorRect.width() << "_" << monitorRect.height() << "_MyVirtualDesktopId";
|
2019-09-04 18:26:26 +02:00
|
|
|
|
2019-12-11 08:34:18 -08:00
|
|
|
MockZoneWindowHost host;
|
2019-12-10 17:17:40 -08:00
|
|
|
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(dynamic_cast<IZoneWindowHost*>(&host), Mocks::Instance(), pimaryMonitor, deviceId.c_str(), L"MyVirtualDesktopId", false);
|
2019-12-10 10:28:24 +03:00
|
|
|
Assert::AreEqual(zoneWindow->UniqueId().compare(ss.str()), 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
;
|
2019-09-04 18:26:26 +02:00
|
|
|
}
|