Skip to content

Commit

Permalink
[FancyZones] Unit-tests fix: keeping user settings unchanged (#3500)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphimaZykova committed May 27, 2020
1 parent ac6b971 commit 5db1f91
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/modules/fancyzones/lib/JsonHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ namespace JSONHelpers
{
deviceInfoMap[deviceId] = data;
}

inline void SetSettingsModulePath(std::wstring_view moduleName)
{
std::wstring result = PTSettingsHelper::get_module_save_folder_location(moduleName);
jsonFilePath = result + L"\\" + std::wstring(L"zones-settings.json");
}
#endif

inline void SetActiveDeviceId(const std::wstring& deviceId)
Expand Down
8 changes: 7 additions & 1 deletion src/modules/fancyzones/tests/UnitTests/FancyZones.Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ namespace FancyZonesUnitTests
{
HINSTANCE m_hInst;
winrt::com_ptr<IFancyZonesSettings> m_settings;
const std::wstring_view m_moduleName = L"FancyZonesUnitTests";

TEST_METHOD_INITIALIZE(Init)
{
m_hInst = (HINSTANCE)GetModuleHandleW(nullptr);
m_settings = MakeFancyZonesSettings(m_hInst, L"FancyZonesUnitTests");
m_settings = MakeFancyZonesSettings(m_hInst, m_moduleName.data());
Assert::IsTrue(m_settings != nullptr);
}

TEST_METHOD_CLEANUP(CleanUp)
{
std::filesystem::remove_all(PTSettingsHelper::get_module_save_folder_location(m_moduleName));
}

TEST_METHOD (Create)
{
auto actual = MakeFancyZones(m_hInst, m_settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace FancyZonesUnitTests
TEST_CLASS (FancyZonesSettingsCreationUnitTest)
{
HINSTANCE m_hInst;
PCWSTR m_moduleName = L"FancyZonesTest";
PCWSTR m_moduleName = L"FancyZonesUnitTests";
std::wstring m_tmpName;

const PowerToysSettings::HotkeyObject m_defaultHotkeyObject = PowerToysSettings::HotkeyObject::from_settings(true, false, false, false, VK_OEM_3);
Expand All @@ -67,8 +67,7 @@ namespace FancyZonesUnitTests
}
TEST_METHOD_CLEANUP(Cleanup)
{
std::filesystem::remove(m_tmpName);
std::filesystem::remove(PTSettingsHelper::get_module_save_folder_location(m_moduleName));
std::filesystem::remove_all(PTSettingsHelper::get_module_save_folder_location(m_moduleName));
}

TEST_METHOD (CreateWithHinstanceDefault)
Expand Down Expand Up @@ -367,7 +366,7 @@ namespace FancyZonesUnitTests
TEST_CLASS (FancyZonesSettingsCallbackUnitTests)
{
winrt::com_ptr<IFancyZonesSettings> m_settings = nullptr;
PCWSTR m_moduleName = L"FancyZonesTest";
PCWSTR m_moduleName = L"FancyZonesUnitTests";

struct FZCallback : public winrt::implements<FZCallback, IFancyZonesCallback>
{
Expand Down Expand Up @@ -466,8 +465,7 @@ namespace FancyZonesUnitTests

TEST_METHOD_CLEANUP(Cleanup)
{
const auto settingsFile = PTSettingsHelper::get_module_save_folder_location(m_moduleName) + L"\\settings.json";
std::filesystem::remove(settingsFile);
std::filesystem::remove_all(PTSettingsHelper::get_module_save_folder_location(m_moduleName));
}

TEST_METHOD (CallbackSetConfig)
Expand Down Expand Up @@ -541,7 +539,7 @@ namespace FancyZonesUnitTests
{
winrt::com_ptr<IFancyZonesSettings> m_settings = nullptr;
PowerToysSettings::Settings* m_ptSettings = nullptr;
PCWSTR m_moduleName = L"FancyZonesTest";
PCWSTR m_moduleName = L"FancyZonesUnitTests";

std::wstring serializedPowerToySettings(const Settings& settings)
{
Expand Down Expand Up @@ -640,8 +638,7 @@ namespace FancyZonesUnitTests

TEST_METHOD_CLEANUP(Cleanup)
{
const auto settingsFile = PTSettingsHelper::get_module_save_folder_location(m_moduleName) + L"\\settings.json";
std::filesystem::remove(settingsFile);
std::filesystem::remove_all(PTSettingsHelper::get_module_save_folder_location(m_moduleName));
}

TEST_METHOD (GetConfig)
Expand Down

0 comments on commit 5db1f91

Please sign in to comment.