Skip to content

Commit

Permalink
Format unittests (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyoyuppe committed Dec 10, 2019
1 parent 776a4d6 commit 1760af5
Show file tree
Hide file tree
Showing 17 changed files with 703 additions and 730 deletions.
98 changes: 49 additions & 49 deletions src/common/UnitTests-CommonLib/Settings.Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,54 @@ using namespace PowerToysSettings;

namespace UnitTestsCommonLib
{
TEST_CLASS(SettingsUnitTests)
{
private:
const std::wstring m_json = L"{\"name\":\"Module Name\",\"properties\" : {\"bool_toggle_true\":{\"value\":true},\"bool_toggle_false\":{\"value\":false},\"color_picker\" : {\"value\":\"#ff8d12\"},\"int_spinner\" : {\"value\":10},\"string_text\" : {\"value\":\"a quick fox\"}},\"version\" : \"1.0\" }";

public:
TEST_METHOD(LoadFromJsonBoolTrue)
TEST_CLASS(SettingsUnitTests)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_bool_value(L"bool_toggle_true");
Assert::IsTrue(value.has_value());
Assert::AreEqual(true, *value);
}

TEST_METHOD(LoadFromJsonBoolFalse)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_bool_value(L"bool_toggle_false");
Assert::IsTrue(value.has_value());
Assert::AreEqual(false, *value);
}

TEST_METHOD(LoadFromJsonInt)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_int_value(L"int_spinner");
Assert::IsTrue(value.has_value());
Assert::AreEqual(10, *value);
}

TEST_METHOD(LoadFromJsonString)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_string_value(L"string_text");

Assert::IsTrue(value.has_value());
std::wstring expected = L"a quick fox";
Assert::AreEqual(expected, *value);
}

TEST_METHOD(LoadFromJsonColorPicker)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_string_value(L"color_picker");

Assert::IsTrue(value.has_value());
std::wstring expected = L"#ff8d12";
Assert::AreEqual(expected, *value);
}
};
private:
const std::wstring m_json = L"{\"name\":\"Module Name\",\"properties\" : {\"bool_toggle_true\":{\"value\":true},\"bool_toggle_false\":{\"value\":false},\"color_picker\" : {\"value\":\"#ff8d12\"},\"int_spinner\" : {\"value\":10},\"string_text\" : {\"value\":\"a quick fox\"}},\"version\" : \"1.0\" }";

public:
TEST_METHOD(LoadFromJsonBoolTrue)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_bool_value(L"bool_toggle_true");
Assert::IsTrue(value.has_value());
Assert::AreEqual(true, *value);
}

TEST_METHOD(LoadFromJsonBoolFalse)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_bool_value(L"bool_toggle_false");
Assert::IsTrue(value.has_value());
Assert::AreEqual(false, *value);
}

TEST_METHOD(LoadFromJsonInt)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_int_value(L"int_spinner");
Assert::IsTrue(value.has_value());
Assert::AreEqual(10, *value);
}

TEST_METHOD(LoadFromJsonString)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_string_value(L"string_text");

Assert::IsTrue(value.has_value());
std::wstring expected = L"a quick fox";
Assert::AreEqual(expected, *value);
}

TEST_METHOD(LoadFromJsonColorPicker)
{
PowerToyValues values = PowerToyValues::from_json_string(m_json);
auto value = values.get_string_value(L"color_picker");

Assert::IsTrue(value.has_value());
std::wstring expected = L"#ff8d12";
Assert::AreEqual(expected, *value);
}
};
}
49 changes: 24 additions & 25 deletions src/modules/fancyzones/tests/UnitTests/RegistryHelpers.Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,31 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace FancyZonesUnitTests
{
TEST_CLASS(RegistryHelpersUnitTests)
{
public:
TEST_METHOD(GetDefaultKey)
{
// Test the path to the key is the same string.
wchar_t key[256];
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(nullptr, key, ARRAYSIZE(key)), L"Software\\SuperFancyZones"));
}
TEST_CLASS(RegistryHelpersUnitTests){
public:
TEST_METHOD(GetDefaultKey){
// Test the path to the key is the same string.
wchar_t key[256];
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(nullptr, key, ARRAYSIZE(key)), L"Software\\SuperFancyZones"));
}

TEST_METHOD(GetKeyWithMonitor)
{
// Test the path to the key is the same string.
wchar_t key[256];
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(L"Monitor1", key, ARRAYSIZE(key)), L"Software\\SuperFancyZones\\Monitor1"));
}
TEST_METHOD(GetKeyWithMonitor)
{
// Test the path to the key is the same string.
wchar_t key[256];
Assert::AreEqual(0, wcscmp(RegistryHelpers::GetKey(L"Monitor1", key, ARRAYSIZE(key)), L"Software\\SuperFancyZones\\Monitor1"));
}

TEST_METHOD(OpenKey)
{
// The default key should exist.
wil::unique_hkey key{ RegistryHelpers::OpenKey({}) };
Assert::IsNotNull(key.get());
TEST_METHOD(OpenKey)
{
// The default key should exist.
wil::unique_hkey key{ RegistryHelpers::OpenKey({}) };
Assert::IsNotNull(key.get());

// The Monitor1 key shouldn't exist.
wil::unique_hkey key2{ RegistryHelpers::OpenKey(L"Monitor1") };
Assert::IsNull(key2.get());
}
};
// The Monitor1 key shouldn't exist.
wil::unique_hkey key2{ RegistryHelpers::OpenKey(L"Monitor1") };
Assert::IsNull(key2.get());
}
}
;
}
47 changes: 23 additions & 24 deletions src/modules/fancyzones/tests/UnitTests/Util.Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace FancyZonesUnitTests
{
TEST_CLASS(UtilUnitTests)
{
public:
TEST_METHOD(TestParseDeviceId)
{
// We're interested in the unique part between the first and last #'s
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
// Example output: DELA026#5&10a58c63&0&UID16777488
PCWSTR input = L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}";
wchar_t output[256]{};
ParseDeviceId(input, output, ARRAYSIZE(output));
Assert::AreEqual(0, wcscmp(output, L"DELA026#5&10a58c63&0&UID16777488"));
}
TEST_CLASS(UtilUnitTests){
public:
TEST_METHOD(TestParseDeviceId){
// We're interested in the unique part between the first and last #'s
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
// Example output: DELA026#5&10a58c63&0&UID16777488
PCWSTR input = L"\\\\?\\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}";
wchar_t output[256]{};
ParseDeviceId(input, output, ARRAYSIZE(output));
Assert::AreEqual(0, wcscmp(output, L"DELA026#5&10a58c63&0&UID16777488"));
}

TEST_METHOD(TestParseInvalidDeviceId)
{
// We're interested in the unique part between the first and last #'s
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
// Example output: DELA026#5&10a58c63&0&UID16777488
PCWSTR input = L"AnInvalidDeviceId";
wchar_t output[256]{};
ParseDeviceId(input, output, ARRAYSIZE(output));
Assert::AreEqual(0, wcscmp(output, L"FallbackDevice"));
}
};
TEST_METHOD(TestParseInvalidDeviceId)
{
// We're interested in the unique part between the first and last #'s
// Example input: \\?\DISPLAY#DELA026#5&10a58c63&0&UID16777488#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
// Example output: DELA026#5&10a58c63&0&UID16777488
PCWSTR input = L"AnInvalidDeviceId";
wchar_t output[256]{};
ParseDeviceId(input, output, ARRAYSIZE(output));
Assert::AreEqual(0, wcscmp(output, L"FallbackDevice"));
}
}
;
}
90 changes: 44 additions & 46 deletions src/modules/fancyzones/tests/UnitTests/Zone.Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,48 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace FancyZonesUnitTests
{
TEST_CLASS(ZoneUnitTests)
{
public:
TEST_METHOD(TestCreateZone)
{
RECT zoneRect{ 10, 10, 200, 200 };
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
Assert::IsNotNull(&zone);
CustomAssert::AreEqual(zoneRect, zone->GetZoneRect());

constexpr size_t id = 10;
zone->SetId(id);
Assert::AreEqual(zone->Id(), id);
}

TEST_METHOD(ContainsWindow)
{
RECT zoneRect{ 10, 10, 200, 200 };
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
HWND newWindow = Mocks::Window();
Assert::IsFalse(zone->ContainsWindow(newWindow));
}

TEST_METHOD(TestAddRemoveWindow)
{
RECT zoneRect{ 10, 10, 200, 200 };
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
HWND newWindow = Mocks::Window();

Assert::IsFalse(zone->ContainsWindow(newWindow));
zone->AddWindowToZone(newWindow, Mocks::Window(), true);
Assert::IsTrue(zone->ContainsWindow(newWindow));

zone->RemoveWindowFromZone(newWindow, false);
Assert::IsFalse(zone->ContainsWindow(newWindow));
}

TEST_METHOD(TestRemoveInvalidWindow)
{
RECT zoneRect{ 10, 10, 200, 200 };
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
HWND newWindow = Mocks::Window();
zone->RemoveWindowFromZone(newWindow, false);
}

};
TEST_CLASS(ZoneUnitTests){
public:
TEST_METHOD(TestCreateZone){
RECT zoneRect{ 10, 10, 200, 200 };
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
Assert::IsNotNull(&zone);
CustomAssert::AreEqual(zoneRect, zone->GetZoneRect());

constexpr size_t id = 10;
zone->SetId(id);
Assert::AreEqual(zone->Id(), id);
}

TEST_METHOD(ContainsWindow)
{
RECT zoneRect{ 10, 10, 200, 200 };
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
HWND newWindow = Mocks::Window();
Assert::IsFalse(zone->ContainsWindow(newWindow));
}

TEST_METHOD(TestAddRemoveWindow)
{
RECT zoneRect{ 10, 10, 200, 200 };
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
HWND newWindow = Mocks::Window();

Assert::IsFalse(zone->ContainsWindow(newWindow));
zone->AddWindowToZone(newWindow, Mocks::Window(), true);
Assert::IsTrue(zone->ContainsWindow(newWindow));

zone->RemoveWindowFromZone(newWindow, false);
Assert::IsFalse(zone->ContainsWindow(newWindow));
}

TEST_METHOD(TestRemoveInvalidWindow)
{
RECT zoneRect{ 10, 10, 200, 200 };
winrt::com_ptr<IZone> zone = MakeZone(zoneRect);
HWND newWindow = Mocks::Window();
zone->RemoveWindowFromZone(newWindow, false);
}
}
;
}

0 comments on commit 1760af5

Please sign in to comment.