Fix compilation errors for VS 16.8.1 (#8024)

* fix compilation issues for VS 16.8.* release

* - VS 16.8 changed its template instantiation model, so now the compiler checks the syntax used in template even when it's not instantiated. we were relying on that behavior to declare the list of required localized strings from a shared header => replacing that template with a macro.

* - fix 3 C++ `const auto&` bugs the new compiler was able to uncover

* - enabled /Zc:twoPhase- for bootstrapper and PowerToysSetupCustomActions to workaround 10.0.17134.0 headers' issue.

- PowerToysSetupCustomActions.vcxproj now uses 10.0.17134.0 instead of "latest" SDK

* - PowerToysSetupCustomActions project leverages `goto` operator's power extensively, and the new compiler was able to uncover new uninitialized variables behavior, restructured declarations and changed `NULL`s to `nullptr`s.

* - Fix unit FZ unit test compiler error

* - format FZS unit test source file

* fixup fz tests

* use /Zc:twoPhase- for common-md as well
This commit is contained in:
Andrey Nekrasov
2020-11-13 15:57:01 +03:00
committed by GitHub
parent 1826b38aa9
commit c1b1fe6371
11 changed files with 143 additions and 136 deletions

View File

@@ -79,7 +79,7 @@ namespace
if (json.HasKey(NonLocalizable::ZoneIndexSetStr))
{
data.zoneIndexSet = {};
for (auto& value : json.GetNamedArray(NonLocalizable::ZoneIndexSetStr))
for (const auto& value : json.GetNamedArray(NonLocalizable::ZoneIndexSetStr))
{
data.zoneIndexSet.push_back(static_cast<size_t>(value.GetNumber()));
}

View File

@@ -420,7 +420,7 @@ namespace FancyZonesUnitTests
IFACEMETHODIMP_(void)
MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept {}
IFACEMETHODIMP_(void)
HandleWinHookEvent(const WinHookEvent * data) noexcept {}
HandleWinHookEvent(const WinHookEvent* data) noexcept {}
IFACEMETHODIMP_(void)
VirtualDesktopChanged() noexcept {}
IFACEMETHODIMP_(void)
@@ -559,8 +559,9 @@ namespace FancyZonesUnitTests
m_settings->SetCallback(callback.get());
int bufSize = 0;
m_settings->GetConfig(L"", &bufSize);
int bufSize = 1;
wchar_t buffer{};
m_settings->GetConfig(&buffer, &bufSize);
Assert::IsFalse(flag);
}
@@ -622,93 +623,93 @@ namespace FancyZonesUnitTests
}
TEST_METHOD_INITIALIZE(Init)
{
HINSTANCE hInst = (HINSTANCE)GetModuleHandleW(nullptr);
{
HINSTANCE hInst = (HINSTANCE)GetModuleHandleW(nullptr);
m_settings = MakeFancyZonesSettings(hInst, m_moduleName, m_moduleKey);
Assert::IsTrue(m_settings != nullptr);
}
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_CLEANUP(Cleanup)
{
std::filesystem::remove_all(PTSettingsHelper::get_module_save_folder_location(m_moduleName));
}
TEST_METHOD (GetConfig)
{
int expectedSize = 0;
m_settings->GetConfig(nullptr, &expectedSize);
Assert::AreNotEqual(0, expectedSize);
TEST_METHOD (GetConfig)
{
int expectedSize = 0;
m_settings->GetConfig(nullptr, &expectedSize);
Assert::AreNotEqual(0, expectedSize);
int actualBufferSize = expectedSize;
PWSTR actualBuffer = new wchar_t[actualBufferSize];
int actualBufferSize = expectedSize;
PWSTR actualBuffer = new wchar_t[actualBufferSize];
Assert::IsTrue(m_settings->GetConfig(actualBuffer, &actualBufferSize));
Assert::AreEqual(expectedSize, actualBufferSize);
}
Assert::IsTrue(m_settings->GetConfig(actualBuffer, &actualBufferSize));
Assert::AreEqual(expectedSize, actualBufferSize);
}
TEST_METHOD (GetConfigSmallBuffer)
{
int size = 0;
m_settings->GetConfig(nullptr, &size);
Assert::AreNotEqual(0, size);
TEST_METHOD (GetConfigSmallBuffer)
{
int size = 0;
m_settings->GetConfig(nullptr, &size);
Assert::AreNotEqual(0, size);
int actualBufferSize = size - 1;
PWSTR actualBuffer = new wchar_t[actualBufferSize];
int actualBufferSize = size - 1;
PWSTR actualBuffer = new wchar_t[actualBufferSize];
Assert::IsFalse(m_settings->GetConfig(actualBuffer, &actualBufferSize));
Assert::AreEqual(size, actualBufferSize);
}
Assert::IsFalse(m_settings->GetConfig(actualBuffer, &actualBufferSize));
Assert::AreEqual(size, actualBufferSize);
}
TEST_METHOD (GetConfigNullBuffer)
{
int expectedSize = 0;
m_settings->GetConfig(nullptr, &expectedSize);
Assert::AreNotEqual(0, expectedSize);
TEST_METHOD (GetConfigNullBuffer)
{
int expectedSize = 0;
m_settings->GetConfig(nullptr, &expectedSize);
Assert::AreNotEqual(0, expectedSize);
int actualBufferSize = 0;
int actualBufferSize = 0;
Assert::IsFalse(m_settings->GetConfig(nullptr, &actualBufferSize));
Assert::AreEqual(expectedSize, actualBufferSize);
}
Assert::IsFalse(m_settings->GetConfig(nullptr, &actualBufferSize));
Assert::AreEqual(expectedSize, actualBufferSize);
}
TEST_METHOD (SetConfig)
{
//cleanup file before call set config
const auto settingsFile = PTSettingsHelper::get_module_save_folder_location(m_moduleName) + L"\\settings.json";
std::filesystem::remove(settingsFile);
TEST_METHOD (SetConfig)
{
//cleanup file before call set config
const auto settingsFile = PTSettingsHelper::get_module_save_folder_location(m_moduleName) + L"\\settings.json";
std::filesystem::remove(settingsFile);
const Settings expected{
.shiftDrag = true,
.mouseSwitch = true,
.displayChange_moveWindows = true,
.zoneSetChange_flashZones = false,
.zoneSetChange_moveWindows = true,
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = true,
.openWindowOnActiveMonitor = false,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.spanZonesAcrossMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"#FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHighlightColor = L"#00AABB",
.zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3),
.excludedApps = L"app\r\napp2",
.excludedAppsArray = { L"APP", L"APP2" },
};
const Settings expected{
.shiftDrag = true,
.mouseSwitch = true,
.displayChange_moveWindows = true,
.zoneSetChange_flashZones = false,
.zoneSetChange_moveWindows = true,
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = true,
.openWindowOnActiveMonitor = false,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.spanZonesAcrossMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"#FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHighlightColor = L"#00AABB",
.zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3),
.excludedApps = L"app\r\napp2",
.excludedAppsArray = { L"APP", L"APP2" },
};
auto config = serializedPowerToySettings(expected);
m_settings->SetConfig(config.c_str());
auto config = serializedPowerToySettings(expected);
m_settings->SetConfig(config.c_str());
auto actual = m_settings->GetSettings();
compareSettings(expected, *actual);
auto actual = m_settings->GetSettings();
compareSettings(expected, *actual);
Assert::IsTrue(std::filesystem::exists(settingsFile));
}
Assert::IsTrue(std::filesystem::exists(settingsFile));
}
};
}

View File

@@ -16,7 +16,7 @@ namespace KeyboardEventHandlers
// Check if the key event was generated by KeyboardManager to avoid remapping events generated by us.
if (!(data->lParam->dwExtraInfo & CommonSharedConstants::KEYBOARDMANAGER_INJECTED_FLAG))
{
auto& remapping = keyboardManagerState.GetSingleKeyRemap(data->lParam->vkCode);
const auto remapping = keyboardManagerState.GetSingleKeyRemap(data->lParam->vkCode);
if (remapping)
{
auto it = remapping.value();
@@ -187,7 +187,7 @@ namespace KeyboardEventHandlers
// Iterate through the shortcut remaps and apply whichever has been pressed
for (auto& itShortcut : keyboardManagerState.GetSortedShortcutRemapVector(activatedApp))
{
auto& it = reMap.find(itShortcut);
const auto it = reMap.find(itShortcut);
// If a shortcut is currently in the invoked state then skip till the shortcut that is currently invoked
if (isShortcutInvoked && !it->second.isShortcutInvoked)