[FancyZones] Revisit mutexes (#12240)

* [FancyZones] Clean up (#11893)

* [FancyZones] Virtual desktop utils refactoring (#11925)

* [FancyZones] IFancyZonesCallback refactoring (#11932)

* [FancyZones] IZoneWindowHost refactoring (#12091)

* [FancyZones] Rename ZoneWindow -> WorkArea (#12223)

* [FancyZones] Clean up mutexes (#12228)
This commit is contained in:
Seraphima Zykova
2021-07-07 13:18:52 +03:00
committed by GitHub
parent 3f70c8c889
commit d85c3f8cc9
40 changed files with 946 additions and 1389 deletions

View File

@@ -396,160 +396,6 @@ namespace FancyZonesUnitTests
}
};
TEST_CLASS (FancyZonesSettingsCallbackUnitTests)
{
winrt::com_ptr<IFancyZonesSettings> m_settings = nullptr;
PCWSTR m_moduleName = L"FancyZonesUnitTests";
PCWSTR m_moduleKey = L"FancyZonesUnitTests";
struct FZCallback : public winrt::implements<FZCallback, IFancyZonesCallback>
{
public:
FZCallback(bool* callFlag) :
m_callFlag(callFlag)
{
*m_callFlag = false;
}
IFACEMETHODIMP_(bool)
InMoveSize() noexcept { return false; }
IFACEMETHODIMP_(void)
MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen) noexcept {}
IFACEMETHODIMP_(void)
MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen) noexcept {}
IFACEMETHODIMP_(void)
MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept {}
IFACEMETHODIMP_(void)
HandleWinHookEvent(const WinHookEvent* data) noexcept {}
IFACEMETHODIMP_(void)
VirtualDesktopChanged() noexcept {}
IFACEMETHODIMP_(void)
VirtualDesktopInitialize() noexcept {}
IFACEMETHODIMP_(void)
WindowCreated(HWND window) noexcept {}
IFACEMETHODIMP_(bool)
OnKeyDown(PKBDLLHOOKSTRUCT info) noexcept { return false; }
IFACEMETHODIMP_(void)
ToggleEditor() noexcept
{
Assert::IsNotNull(m_callFlag);
*m_callFlag = true;
}
IFACEMETHODIMP_(void)
SettingsChanged() noexcept
{
Assert::IsNotNull(m_callFlag);
*m_callFlag = true;
}
private:
bool* m_callFlag = nullptr;
};
TEST_METHOD_INITIALIZE(Init)
{
HINSTANCE hInst = (HINSTANCE)GetModuleHandleW(nullptr);
const Settings expected{
.shiftDrag = false,
.mouseSwitch = false,
.displayChange_moveWindows = true,
.zoneSetChange_flashZones = true,
.zoneSetChange_moveWindows = true,
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.moveWindowsBasedOnPosition = false,
.appLastZone_moveWindows = false,
.openWindowOnActiveMonitor = false,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.spanZonesAcrossMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHighlightColor = L"#00FFD7",
.zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
.excludedApps = L"app",
.excludedAppsArray = { L"APP" },
};
PowerToysSettings::PowerToyValues values(m_moduleName, m_moduleKey);
values.add_property(L"fancyzones_shiftDrag", expected.shiftDrag);
values.add_property(L"fancyzones_mouseSwitch", expected.mouseSwitch);
values.add_property(L"fancyzones_displayChange_moveWindows", expected.displayChange_moveWindows);
values.add_property(L"fancyzones_zoneSetChange_flashZones", expected.zoneSetChange_flashZones);
values.add_property(L"fancyzones_zoneSetChange_moveWindows", expected.zoneSetChange_moveWindows);
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_moveWindowsBasedOnPosition", expected.moveWindowsBasedOnPosition);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_openWindowOnActiveMonitor", expected.openWindowOnActiveMonitor);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_multi_monitor_mode", expected.spanZonesAcrossMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneBorderColor", expected.zoneBorderColor);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHighlightColor);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
values.add_property(L"fancyzones_excluded_apps", expected.excludedApps);
values.save_to_settings_file();
m_settings = MakeFancyZonesSettings(hInst, m_moduleName, m_moduleKey);
Assert::IsTrue(m_settings != nullptr);
}
TEST_METHOD_CLEANUP(Cleanup)
{
std::filesystem::remove_all(PTSettingsHelper::get_module_save_folder_location(m_moduleName));
}
TEST_METHOD (CallbackSetConfig)
{
bool flag = false;
winrt::com_ptr<FZCallback> callback = winrt::make_self<FZCallback>(&flag);
json::JsonObject json{};
json.SetNamedValue(L"name", json::JsonValue::CreateStringValue(L"name"));
m_settings->SetCallback(callback.get());
m_settings->SetConfig(json.Stringify().c_str());
Assert::IsTrue(flag);
}
TEST_METHOD (CallbackGetConfig)
{
bool flag = false;
winrt::com_ptr<FZCallback> callback = winrt::make_self<FZCallback>(&flag);
m_settings->SetCallback(callback.get());
int bufSize = 1;
wchar_t buffer{};
m_settings->GetConfig(&buffer, &bufSize);
Assert::IsFalse(flag);
}
TEST_METHOD (CallbackGetSettings)
{
bool flag = false;
winrt::com_ptr<FZCallback> callback = winrt::make_self<FZCallback>(&flag);
m_settings->SetCallback(callback.get());
m_settings->GetSettings();
Assert::IsFalse(flag);
}
};
TEST_CLASS (FancyZonesSettingsUnitTests)
{
winrt::com_ptr<IFancyZonesSettings> m_settings = nullptr;