[FancyZones][UnitTests] Fixing TestDeviceId, and TestUniqueId to unit tests.

1. Creating a mock ZoneWindowHost.   Previously creating a ZoneWindow would throw an exception if the ZoneWindowHost is null.
2. Passing in HWND() instead of null to get rig of SAL annotation warnings.
This commit is contained in:
ryanbodrug-microsoft
2019-12-10 17:17:40 -08:00
parent 1760af50c8
commit 4f9d31e832

View File

@@ -5,8 +5,24 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace FancyZonesUnitTests namespace FancyZonesUnitTests
{ {
struct MockZoneWindowHost : public winrt::implements<MockZoneWindowHost, IZoneWindowHost>
{
IFACEMETHODIMP_(void) MoveWindowsOnActiveZoneSetChange() noexcept {};
IFACEMETHODIMP_(COLORREF) GetZoneHighlightColor() noexcept
{
return RGB(0xFF, 0xFF, 0xFF);
}
IFACEMETHODIMP_(GUID) GetCurrentMonitorZoneSetId(HMONITOR monitor) noexcept
{
return m_guid;
}
GUID m_guid;
};
TEST_CLASS(ZoneWindowUnitTests){ TEST_CLASS(ZoneWindowUnitTests){
public: public:
TEST_METHOD(TestCreateZoneWindow){ TEST_METHOD(TestCreateZoneWindow){
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), Mocks::Monitor(), L"DeviceId", L"MyVirtualDesktopId", false); winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), Mocks::Monitor(), L"DeviceId", L"MyVirtualDesktopId", false);
Assert::IsNotNull(zoneWindow.get()); Assert::IsNotNull(zoneWindow.get());
@@ -15,10 +31,12 @@ namespace FancyZonesUnitTests
TEST_METHOD(TestDeviceId) TEST_METHOD(TestDeviceId)
{ {
// Window initialization requires a valid HMONITOR - just use the primary for now. // Window initialization requires a valid HMONITOR - just use the primary for now.
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY); HMONITOR pimaryMonitor = MonitorFromWindow(HWND(), MONITOR_DEFAULTTOPRIMARY);
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, L"SomeRandomValue", L"MyVirtualDesktopId", false); MockZoneWindowHost host;
// We have no way to test the correctness, just do our best and check its not an empty string. std::wstring expectedDeviceId = L"SomeRandomValue";
Assert::IsTrue(zoneWindow->DeviceId().size() > 0); winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(dynamic_cast<IZoneWindowHost*>(&host), Mocks::Instance(), pimaryMonitor, expectedDeviceId.c_str(), L"MyVirtualDesktopId", false);
Assert::AreEqual(expectedDeviceId, zoneWindow->DeviceId());
} }
TEST_METHOD(TestUniqueId) TEST_METHOD(TestUniqueId)
@@ -27,7 +45,7 @@ TEST_METHOD(TestUniqueId)
// Example: "DELA026#5&10a58c63&0&UID16777488_1024_768_MyVirtualDesktopId" // Example: "DELA026#5&10a58c63&0&UID16777488_1024_768_MyVirtualDesktopId"
std::wstring deviceId(L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}"); 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. // Window initialization requires a valid HMONITOR - just use the primary for now.
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY); HMONITOR pimaryMonitor = MonitorFromWindow(HWND(), MONITOR_DEFAULTTOPRIMARY);
MONITORINFO info; MONITORINFO info;
info.cbSize = sizeof(info); info.cbSize = sizeof(info);
Assert::IsTrue(GetMonitorInfo(pimaryMonitor, &info)); Assert::IsTrue(GetMonitorInfo(pimaryMonitor, &info));
@@ -36,7 +54,8 @@ TEST_METHOD(TestUniqueId)
std::wstringstream ss; std::wstringstream ss;
ss << L"DELA026#5&10a58c63&0&UID16777488_" << monitorRect.width() << "_" << monitorRect.height() << "_MyVirtualDesktopId"; 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); MockZoneWindowHost host;
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(dynamic_cast<IZoneWindowHost*>(&host), Mocks::Instance(), pimaryMonitor, deviceId.c_str(), L"MyVirtualDesktopId", false);
Assert::AreEqual(zoneWindow->UniqueId().compare(ss.str()), 0); Assert::AreEqual(zoneWindow->UniqueId().compare(ss.str()), 0);
} }
} }