mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Format unittests (#906)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
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\" }";
|
||||
|
||||
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);
|
||||
}
|
||||
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(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(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(LoadFromJsonString)
|
||||
{
|
||||
PowerToyValues values = PowerToyValues::from_json_string(m_json);
|
||||
auto value = values.get_string_value(L"string_text");
|
||||
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);
|
||||
}
|
||||
|
||||
Assert::IsTrue(value.has_value());
|
||||
std::wstring expected = L"a quick fox";
|
||||
Assert::AreEqual(expected, *value);
|
||||
}
|
||||
TEST_METHOD(LoadFromJsonString)
|
||||
{
|
||||
PowerToyValues values = PowerToyValues::from_json_string(m_json);
|
||||
auto value = values.get_string_value(L"string_text");
|
||||
|
||||
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"a quick fox";
|
||||
Assert::AreEqual(expected, *value);
|
||||
}
|
||||
|
||||
Assert::IsTrue(value.has_value());
|
||||
std::wstring expected = L"#ff8d12";
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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_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());
|
||||
|
||||
// The Monitor1 key shouldn't exist.
|
||||
wil::unique_hkey key2{ RegistryHelpers::OpenKey(L"Monitor1") };
|
||||
Assert::IsNull(key2.get());
|
||||
}
|
||||
};
|
||||
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(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());
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -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_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_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"));
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
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);
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -5,187 +5,186 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(ZoneSetUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneSet)
|
||||
{
|
||||
GUID zoneSetId{};
|
||||
CoCreateGuid(&zoneSetId);
|
||||
constexpr WORD layoutId = 0xFFFF;
|
||||
TEST_CLASS(ZoneSetUnitTests){
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneSet){
|
||||
GUID zoneSetId{};
|
||||
CoCreateGuid(&zoneSetId);
|
||||
constexpr WORD layoutId = 0xFFFF;
|
||||
|
||||
ZoneSetConfig config(zoneSetId, layoutId, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
Assert::IsNotNull(&set);
|
||||
CustomAssert::AreEqual(set->Id(), zoneSetId);
|
||||
CustomAssert::AreEqual(set->LayoutId(), layoutId);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a zone
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 1);
|
||||
Assert::IsTrue(zones[0] == zone);
|
||||
Assert::IsTrue(zone->Id() == 1);
|
||||
}
|
||||
|
||||
// Add a second zone at the back.
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 2);
|
||||
Assert::IsTrue(zones[1] == zone);
|
||||
Assert::IsTrue(zone->Id() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 1);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithNoZones)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithInvalidIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 100);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
};
|
||||
|
||||
// MoveWindowIntoZoneByDirection is complicated enough to warrant it's own test class
|
||||
TEST_CLASS(MoveWindowIntoZoneByDirectionUnitTests)
|
||||
{
|
||||
winrt::com_ptr<IZoneSet> set;
|
||||
winrt::com_ptr<IZone> zone1;
|
||||
winrt::com_ptr<IZone> zone2;
|
||||
winrt::com_ptr<IZone> zone3;
|
||||
|
||||
TEST_METHOD_INITIALIZE(Initialize)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRightNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeftNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
};
|
||||
ZoneSetConfig config(zoneSetId, layoutId, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
Assert::IsNotNull(&set);
|
||||
CustomAssert::AreEqual(set->Id(), zoneSetId);
|
||||
CustomAssert::AreEqual(set->LayoutId(), layoutId);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestAddZone)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a zone
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 1);
|
||||
Assert::IsTrue(zones[0] == zone);
|
||||
Assert::IsTrue(zone->Id() == 1);
|
||||
}
|
||||
|
||||
// Add a second zone at the back.
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone);
|
||||
auto zones = set->GetZones();
|
||||
Assert::IsTrue(zones.size() == 2);
|
||||
Assert::IsTrue(zones[1] == zone);
|
||||
Assert::IsTrue(zone->Id() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 1);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithNoZones)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestMoveWindowIntoZoneByIndexWithInvalidIndex)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
winrt::com_ptr<IZoneSet> set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
winrt::com_ptr<IZone> zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
winrt::com_ptr<IZone> zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByIndex(window, Mocks::Window(), 100);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
// MoveWindowIntoZoneByDirection is complicated enough to warrant it's own test class
|
||||
TEST_CLASS(MoveWindowIntoZoneByDirectionUnitTests)
|
||||
{
|
||||
winrt::com_ptr<IZoneSet> set;
|
||||
winrt::com_ptr<IZone> zone1;
|
||||
winrt::com_ptr<IZone> zone2;
|
||||
winrt::com_ptr<IZone> zone3;
|
||||
|
||||
TEST_METHOD_INITIALIZE(Initialize)
|
||||
{
|
||||
ZoneSetConfig config({}, 0xFFFF, Mocks::Monitor(), L"WorkAreaIn");
|
||||
set = MakeZoneSet(config);
|
||||
|
||||
// Add a couple of zones.
|
||||
zone1 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone2 = MakeZone({ 0, 0, 100, 100 });
|
||||
zone3 = MakeZone({ 0, 0, 100, 100 });
|
||||
set->AddZone(zone1);
|
||||
set->AddZone(zone2);
|
||||
set->AddZone(zone3);
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRightNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeftNoZones)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsTrue(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundRight)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone3->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_RIGHT);
|
||||
Assert::IsTrue(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsFalse(zone3->ContainsWindow(window));
|
||||
}
|
||||
|
||||
TEST_METHOD(MoveWindowIntoZoneByDirectionWrapAroundLeft)
|
||||
{
|
||||
HWND window = Mocks::Window();
|
||||
zone1->AddWindowToZone(window, Mocks::Window(), false /*stampZone*/);
|
||||
set->MoveWindowIntoZoneByDirection(window, Mocks::Window(), VK_LEFT);
|
||||
Assert::IsFalse(zone1->ContainsWindow(window));
|
||||
Assert::IsFalse(zone2->ContainsWindow(window));
|
||||
Assert::IsTrue(zone3->ContainsWindow(window));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,41 +5,40 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace FancyZonesUnitTests
|
||||
{
|
||||
TEST_CLASS(ZoneWindowUnitTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneWindow)
|
||||
{
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), Mocks::Monitor(), L"DeviceId", L"MyVirtualDesktopId", false);
|
||||
Assert::IsNotNull(zoneWindow.get());
|
||||
}
|
||||
|
||||
TEST_METHOD(TestDeviceId)
|
||||
{
|
||||
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, L"SomeRandomValue", L"MyVirtualDesktopId", false);
|
||||
// We have no way to test the correctness, just do our best and check its not an empty string.
|
||||
Assert::IsTrue(zoneWindow->DeviceId().size() > 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestUniqueId)
|
||||
{
|
||||
// Unique id of the format "ParsedMonitorDeviceId_MonitorWidth_MonitorHeight_VirtualDesktopId
|
||||
// Example: "DELA026#5&10a58c63&0&UID16777488_1024_768_MyVirtualDesktopId"
|
||||
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.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
MONITORINFO info;
|
||||
info.cbSize = sizeof(info);
|
||||
Assert::IsTrue(GetMonitorInfo(pimaryMonitor, &info));
|
||||
|
||||
Rect monitorRect = Rect(info.rcMonitor);
|
||||
std::wstringstream ss;
|
||||
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);
|
||||
Assert::AreEqual(zoneWindow->UniqueId().compare(ss.str()), 0);
|
||||
}
|
||||
};
|
||||
TEST_CLASS(ZoneWindowUnitTests){
|
||||
public:
|
||||
TEST_METHOD(TestCreateZoneWindow){
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), Mocks::Monitor(), L"DeviceId", L"MyVirtualDesktopId", false);
|
||||
Assert::IsNotNull(zoneWindow.get());
|
||||
}
|
||||
|
||||
TEST_METHOD(TestDeviceId)
|
||||
{
|
||||
// Window initialization requires a valid HMONITOR - just use the primary for now.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
winrt::com_ptr<IZoneWindow> zoneWindow = MakeZoneWindow(nullptr, Mocks::Instance(), pimaryMonitor, L"SomeRandomValue", L"MyVirtualDesktopId", false);
|
||||
// We have no way to test the correctness, just do our best and check its not an empty string.
|
||||
Assert::IsTrue(zoneWindow->DeviceId().size() > 0);
|
||||
}
|
||||
|
||||
TEST_METHOD(TestUniqueId)
|
||||
{
|
||||
// Unique id of the format "ParsedMonitorDeviceId_MonitorWidth_MonitorHeight_VirtualDesktopId
|
||||
// Example: "DELA026#5&10a58c63&0&UID16777488_1024_768_MyVirtualDesktopId"
|
||||
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.
|
||||
HMONITOR pimaryMonitor = MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY);
|
||||
MONITORINFO info;
|
||||
info.cbSize = sizeof(info);
|
||||
Assert::IsTrue(GetMonitorInfo(pimaryMonitor, &info));
|
||||
|
||||
Rect monitorRect = Rect(info.rcMonitor);
|
||||
std::wstringstream ss;
|
||||
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);
|
||||
Assert::AreEqual(zoneWindow->UniqueId().compare(ss.str()), 0);
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -31,4 +31,3 @@ void CMockPowerRenameItem::Init(_In_opt_ PCWSTR path, _In_opt_ PCWSTR originalNa
|
||||
m_depth = depth;
|
||||
m_isFolder = isFolder;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,20 +4,21 @@
|
||||
// IUnknown
|
||||
IFACEMETHODIMP CMockPowerRenameManagerEvents::QueryInterface(__in REFIID riid, __deref_out void** ppv)
|
||||
{
|
||||
static const QITAB qit[] =
|
||||
{
|
||||
static const QITAB qit[] = {
|
||||
QITABENT(CMockPowerRenameManagerEvents, IPowerRenameManagerEvents),
|
||||
{ 0 },
|
||||
};
|
||||
return QISearch(this, qit, riid, ppv);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) CMockPowerRenameManagerEvents::AddRef()
|
||||
IFACEMETHODIMP_(ULONG)
|
||||
CMockPowerRenameManagerEvents::AddRef()
|
||||
{
|
||||
return InterlockedIncrement(&m_refCount);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) CMockPowerRenameManagerEvents::Release()
|
||||
IFACEMETHODIMP_(ULONG)
|
||||
CMockPowerRenameManagerEvents::Release()
|
||||
{
|
||||
long refCount = InterlockedDecrement(&m_refCount);
|
||||
if (refCount == 0)
|
||||
@@ -89,4 +90,3 @@ HRESULT CMockPowerRenameManagerEvents::s_CreateInstance(_In_ IPowerRenameManager
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,11 @@ public:
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHODIMP QueryInterface(__in REFIID riid, __deref_out void** ppv);
|
||||
IFACEMETHODIMP_(ULONG) AddRef();
|
||||
IFACEMETHODIMP_(ULONG) Release();
|
||||
|
||||
IFACEMETHODIMP_(ULONG)
|
||||
AddRef();
|
||||
IFACEMETHODIMP_(ULONG)
|
||||
Release();
|
||||
|
||||
// IPowerRenameManagerEvents
|
||||
IFACEMETHODIMP OnItemAdded(_In_ IPowerRenameItem* renameItem);
|
||||
IFACEMETHODIMP OnUpdate(_In_ IPowerRenameItem* renameItem);
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#include "stdafx.h"
|
||||
#include "MockPowerRenameRegExEvents.h"
|
||||
|
||||
IFACEMETHODIMP_(ULONG) CMockPowerRenameRegExEvents::AddRef()
|
||||
IFACEMETHODIMP_(ULONG)
|
||||
CMockPowerRenameRegExEvents::AddRef()
|
||||
{
|
||||
return InterlockedIncrement(&m_refCount);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) CMockPowerRenameRegExEvents::Release()
|
||||
IFACEMETHODIMP_(ULONG)
|
||||
CMockPowerRenameRegExEvents::Release()
|
||||
{
|
||||
long refCount = InterlockedDecrement(&m_refCount);
|
||||
|
||||
@@ -66,4 +68,3 @@ HRESULT CMockPowerRenameRegExEvents::s_CreateInstance(_Outptr_ IPowerRenameRegEx
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
#include <vector>
|
||||
#include "srwlock.h"
|
||||
|
||||
class CMockPowerRenameRegExEvents:
|
||||
class CMockPowerRenameRegExEvents :
|
||||
public IPowerRenameRegExEvents
|
||||
{
|
||||
public:
|
||||
// IUnknown
|
||||
IFACEMETHODIMP QueryInterface(_In_ REFIID iid, _Outptr_ void** resultInterface);
|
||||
IFACEMETHODIMP_(ULONG) AddRef();
|
||||
IFACEMETHODIMP_(ULONG) Release();
|
||||
IFACEMETHODIMP QueryInterface(_In_ REFIID iid, _Outptr_ void** resultInterface);
|
||||
IFACEMETHODIMP_(ULONG)
|
||||
AddRef();
|
||||
IFACEMETHODIMP_(ULONG)
|
||||
Release();
|
||||
|
||||
// IPowerRenameRegExEvents
|
||||
IFACEMETHODIMP OnSearchTermChanged(_In_ PCWSTR searchTerm);
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace PowerRenameManagerTests
|
||||
TEST_CLASS(SimpleTests)
|
||||
{
|
||||
public:
|
||||
|
||||
struct rename_pairs
|
||||
{
|
||||
std::wstring originalName;
|
||||
@@ -32,7 +31,7 @@ namespace PowerRenameManagerTests
|
||||
int depth;
|
||||
};
|
||||
|
||||
void RenameHelper(_In_ rename_pairs* renamePairs, _In_ int numPairs, _In_ std::wstring searchTerm, _In_ std::wstring replaceTerm, _In_ DWORD flags)
|
||||
void RenameHelper(_In_ rename_pairs * renamePairs, _In_ int numPairs, _In_ std::wstring searchTerm, _In_ std::wstring replaceTerm, _In_ DWORD flags)
|
||||
{
|
||||
// Create a single item (in a temp directory) and verify rename works as expected
|
||||
CTestFileHelper testFileHelper;
|
||||
@@ -60,11 +59,12 @@ namespace PowerRenameManagerTests
|
||||
{
|
||||
CComPtr<IPowerRenameItem> item;
|
||||
CMockPowerRenameItem::CreateInstance(testFileHelper.GetFullPath(
|
||||
renamePairs[i].originalName).c_str(),
|
||||
renamePairs[i].originalName.c_str(),
|
||||
renamePairs[i].depth,
|
||||
!renamePairs[i].isFile,
|
||||
&item);
|
||||
renamePairs[i].originalName)
|
||||
.c_str(),
|
||||
renamePairs[i].originalName.c_str(),
|
||||
renamePairs[i].depth,
|
||||
!renamePairs[i].isFile,
|
||||
&item);
|
||||
|
||||
int itemId = 0;
|
||||
Assert::IsTrue(item->get_id(&itemId) == S_OK);
|
||||
@@ -153,9 +153,8 @@ namespace PowerRenameManagerTests
|
||||
TEST_METHOD(VerifySingleRename)
|
||||
{
|
||||
// Create a single item and verify rename works as expected
|
||||
rename_pairs renamePairs[] =
|
||||
{
|
||||
{L"foo.txt", L"bar.txt", true, true}
|
||||
rename_pairs renamePairs[] = {
|
||||
{ L"foo.txt", L"bar.txt", true, true }
|
||||
};
|
||||
|
||||
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", DEFAULT_FLAGS);
|
||||
@@ -164,14 +163,13 @@ namespace PowerRenameManagerTests
|
||||
TEST_METHOD(VerifyMultiRename)
|
||||
{
|
||||
// Create a single item and verify rename works as expected
|
||||
rename_pairs renamePairs[] =
|
||||
{
|
||||
{L"foo1.txt", L"bar1.txt", true, true, 0},
|
||||
{L"foo2.txt", L"bar2.txt", true, true, 0},
|
||||
{L"foo3.txt", L"bar3.txt", true, true, 0},
|
||||
{L"foo4.txt", L"bar4.txt", true, true, 0},
|
||||
{L"foo5.txt", L"bar5.txt", true, true, 0},
|
||||
{L"baa.txt", L"baa_norename.txt", true, false, 0}
|
||||
rename_pairs renamePairs[] = {
|
||||
{ L"foo1.txt", L"bar1.txt", true, true, 0 },
|
||||
{ L"foo2.txt", L"bar2.txt", true, true, 0 },
|
||||
{ L"foo3.txt", L"bar3.txt", true, true, 0 },
|
||||
{ L"foo4.txt", L"bar4.txt", true, true, 0 },
|
||||
{ L"foo5.txt", L"bar5.txt", true, true, 0 },
|
||||
{ L"baa.txt", L"baa_norename.txt", true, false, 0 }
|
||||
};
|
||||
|
||||
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", DEFAULT_FLAGS);
|
||||
@@ -180,10 +178,9 @@ namespace PowerRenameManagerTests
|
||||
TEST_METHOD(VerifyFilesOnlyRename)
|
||||
{
|
||||
// Verify only files are renamed when folders match too
|
||||
rename_pairs renamePairs[] =
|
||||
{
|
||||
{L"foo.txt", L"bar.txt", true, true, 0},
|
||||
{L"foo", L"foo_norename", false, false, 0}
|
||||
rename_pairs renamePairs[] = {
|
||||
{ L"foo.txt", L"bar.txt", true, true, 0 },
|
||||
{ L"foo", L"foo_norename", false, false, 0 }
|
||||
};
|
||||
|
||||
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", DEFAULT_FLAGS | ExcludeFolders);
|
||||
@@ -192,10 +189,9 @@ namespace PowerRenameManagerTests
|
||||
TEST_METHOD(VerifyFoldersOnlyRename)
|
||||
{
|
||||
// Verify only folders are renamed when files match too
|
||||
rename_pairs renamePairs[] =
|
||||
{
|
||||
{L"foo.txt", L"foo_norename.txt", true, false, 0},
|
||||
{L"foo", L"bar", false, true, 0}
|
||||
rename_pairs renamePairs[] = {
|
||||
{ L"foo.txt", L"foo_norename.txt", true, false, 0 },
|
||||
{ L"foo", L"bar", false, true, 0 }
|
||||
};
|
||||
|
||||
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", DEFAULT_FLAGS | ExcludeFiles);
|
||||
@@ -204,10 +200,9 @@ namespace PowerRenameManagerTests
|
||||
TEST_METHOD(VerifyFileNameOnlyRename)
|
||||
{
|
||||
// Verify only file name is renamed, not extension
|
||||
rename_pairs renamePairs[] =
|
||||
{
|
||||
{L"foo.foo", L"bar.foo", true, true, 0},
|
||||
{L"test.foo", L"test.foo_norename", true, false, 0}
|
||||
rename_pairs renamePairs[] = {
|
||||
{ L"foo.foo", L"bar.foo", true, true, 0 },
|
||||
{ L"test.foo", L"test.foo_norename", true, false, 0 }
|
||||
};
|
||||
|
||||
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", DEFAULT_FLAGS | NameOnly);
|
||||
@@ -216,10 +211,9 @@ namespace PowerRenameManagerTests
|
||||
TEST_METHOD(VerifyFileExtensionOnlyRename)
|
||||
{
|
||||
// Verify only file extension is renamed, not name
|
||||
rename_pairs renamePairs[] =
|
||||
{
|
||||
{L"foo.foo", L"foo.bar", true, true, 0},
|
||||
{L"test.foo", L"test.bar", true, true, 0}
|
||||
rename_pairs renamePairs[] = {
|
||||
{ L"foo.foo", L"foo.bar", true, true, 0 },
|
||||
{ L"test.foo", L"test.bar", true, true, 0 }
|
||||
};
|
||||
|
||||
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", DEFAULT_FLAGS | ExtensionOnly);
|
||||
@@ -228,14 +222,12 @@ namespace PowerRenameManagerTests
|
||||
TEST_METHOD(VerifySubFoldersRename)
|
||||
{
|
||||
// Verify subfolders do not get renamed
|
||||
rename_pairs renamePairs[] =
|
||||
{
|
||||
{L"foo1", L"bar1", false, true, 0},
|
||||
{L"foo2", L"foo2_norename", false, false, 1}
|
||||
rename_pairs renamePairs[] = {
|
||||
{ L"foo1", L"bar1", false, true, 0 },
|
||||
{ L"foo2", L"foo2_norename", false, false, 1 }
|
||||
};
|
||||
|
||||
RenameHelper(renamePairs, ARRAYSIZE(renamePairs), L"foo", L"bar", DEFAULT_FLAGS | ExcludeSubfolders);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
@@ -16,316 +16,306 @@ namespace PowerRenameRegExTests
|
||||
PCWSTR expected;
|
||||
};
|
||||
|
||||
TEST_CLASS(SimpleTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(GeneralReplaceTest)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"foo") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(L"big") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, L"bigbar") == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
TEST_CLASS(SimpleTests){
|
||||
public:
|
||||
TEST_METHOD(GeneralReplaceTest){
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"foo") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(L"big") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, L"bigbar") == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
|
||||
TEST_METHOD(ReplaceNoMatch)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"notfound") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(L"big") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, L"foobar") == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
TEST_METHOD(ReplaceNoMatch)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"notfound") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(L"big") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, L"foobar") == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
|
||||
TEST_METHOD(ReplaceNoSearchOrReplaceTerm)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) != S_OK);
|
||||
Assert::IsTrue(result == nullptr);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
TEST_METHOD(ReplaceNoSearchOrReplaceTerm)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) != S_OK);
|
||||
Assert::IsTrue(result == nullptr);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
|
||||
TEST_METHOD(ReplaceNoReplaceTerm)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"foo") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, L"bar") == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
TEST_METHOD(ReplaceNoReplaceTerm)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"foo") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, L"bar") == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
|
||||
TEST_METHOD(ReplaceEmptyStringReplaceTerm)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"foo") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(L"") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, L"bar") == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
TEST_METHOD(ReplaceEmptyStringReplaceTerm)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"foo") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(L"") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(L"foobar", &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, L"bar") == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyDefaultFlags)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = 0;
|
||||
Assert::IsTrue(renameRegEx->get_flags(&flags) == S_OK);
|
||||
Assert::IsTrue(flags == MatchAllOccurences);
|
||||
}
|
||||
TEST_METHOD(VerifyDefaultFlags)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = 0;
|
||||
Assert::IsTrue(renameRegEx->get_flags(&flags) == S_OK);
|
||||
Assert::IsTrue(flags == MatchAllOccurences);
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyCaseSensitiveSearch)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = CaseSensitive;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
TEST_METHOD(VerifyCaseSensitiveSearch)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = CaseSensitive;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L"Foo", L"Foo", L"FooBar", L"FooBar" },
|
||||
{ L"Foo", L"boo", L"FooBar", L"booBar" },
|
||||
{ L"Foo", L"boo", L"foobar", L"foobar" },
|
||||
{ L"123", L"654", L"123456", L"654456" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceFirstOnly)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = 0;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AABBA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABAB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceAll)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AAAAA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABBBABBB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceAllCaseInsensitive)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | CaseSensitive;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AAAAA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABBBABBB" },
|
||||
{ L"b", L"BBB", L"AbABAb", L"ABBBABABBB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceFirstOnlyUseRegEx)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = UseRegularExpressions;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AABBA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABAB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceAllUseRegEx)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | UseRegularExpressions;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AAAAA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABBBABBB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceAllUseRegExCaseSensitive)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | UseRegularExpressions | CaseSensitive;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AAAAA" },
|
||||
{ L"b", L"BBB", L"AbABAb", L"ABBBABABBB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyMatchAllWildcardUseRegEx)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | UseRegularExpressions;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L".*", L"Foo", L"AAAAAA", L"Foo" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceFirstWildcardUseRegEx)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = UseRegularExpressions;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] =
|
||||
{
|
||||
{ L".*", L"Foo", L"AAAAAA", L"FooAAAA" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyEventsFire)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
CMockPowerRenameRegExEvents* mockEvents = new CMockPowerRenameRegExEvents();
|
||||
CComPtr<IPowerRenameRegExEvents> regExEvents;
|
||||
Assert::IsTrue(mockEvents->QueryInterface(IID_PPV_ARGS(®ExEvents)) == S_OK);
|
||||
DWORD cookie = 0;
|
||||
Assert::IsTrue(renameRegEx->Advise(regExEvents, &cookie) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | UseRegularExpressions | CaseSensitive;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"FOO") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(L"BAR") == S_OK);
|
||||
Assert::IsTrue(lstrcmpi(L"FOO", mockEvents->m_searchTerm) == 0);
|
||||
Assert::IsTrue(lstrcmpi(L"BAR", mockEvents->m_replaceTerm) == 0);
|
||||
Assert::IsTrue(flags == mockEvents->m_flags);
|
||||
Assert::IsTrue(renameRegEx->UnAdvise(cookie) == S_OK);
|
||||
mockEvents->Release();
|
||||
}
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L"Foo", L"Foo", L"FooBar", L"FooBar" },
|
||||
{ L"Foo", L"boo", L"FooBar", L"booBar" },
|
||||
{ L"Foo", L"boo", L"foobar", L"foobar" },
|
||||
{ L"123", L"654", L"123456", L"654456" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceFirstOnly)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = 0;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AABBA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABAB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceAll)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AAAAA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABBBABBB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceAllCaseInsensitive)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | CaseSensitive;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AAAAA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABBBABBB" },
|
||||
{ L"b", L"BBB", L"AbABAb", L"ABBBABABBB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceFirstOnlyUseRegEx)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = UseRegularExpressions;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AABBA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABAB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceAllUseRegEx)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | UseRegularExpressions;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AAAAA" },
|
||||
{ L"B", L"BBB", L"ABABAB", L"ABBBABBBABBB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceAllUseRegExCaseSensitive)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | UseRegularExpressions | CaseSensitive;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L"B", L"BB", L"ABA", L"ABBA" },
|
||||
{ L"B", L"A", L"ABBBA", L"AAAAA" },
|
||||
{ L"b", L"BBB", L"AbABAb", L"ABBBABABBB" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyMatchAllWildcardUseRegEx)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | UseRegularExpressions;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L".*", L"Foo", L"AAAAAA", L"Foo" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyReplaceFirstWildcardUseRegEx)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
DWORD flags = UseRegularExpressions;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
|
||||
SearchReplaceExpected sreTable[] = {
|
||||
{ L".*", L"Foo", L"AAAAAA", L"FooAAAA" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(sreTable); i++)
|
||||
{
|
||||
PWSTR result = nullptr;
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(sreTable[i].search) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(sreTable[i].replace) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->Replace(sreTable[i].test, &result) == S_OK);
|
||||
Assert::IsTrue(wcscmp(result, sreTable[i].expected) == 0);
|
||||
CoTaskMemFree(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(VerifyEventsFire)
|
||||
{
|
||||
CComPtr<IPowerRenameRegEx> renameRegEx;
|
||||
Assert::IsTrue(CPowerRenameRegEx::s_CreateInstance(&renameRegEx) == S_OK);
|
||||
CMockPowerRenameRegExEvents* mockEvents = new CMockPowerRenameRegExEvents();
|
||||
CComPtr<IPowerRenameRegExEvents> regExEvents;
|
||||
Assert::IsTrue(mockEvents->QueryInterface(IID_PPV_ARGS(®ExEvents)) == S_OK);
|
||||
DWORD cookie = 0;
|
||||
Assert::IsTrue(renameRegEx->Advise(regExEvents, &cookie) == S_OK);
|
||||
DWORD flags = MatchAllOccurences | UseRegularExpressions | CaseSensitive;
|
||||
Assert::IsTrue(renameRegEx->put_flags(flags) == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_searchTerm(L"FOO") == S_OK);
|
||||
Assert::IsTrue(renameRegEx->put_replaceTerm(L"BAR") == S_OK);
|
||||
Assert::IsTrue(lstrcmpi(L"FOO", mockEvents->m_searchTerm) == 0);
|
||||
Assert::IsTrue(lstrcmpi(L"BAR", mockEvents->m_replaceTerm) == 0);
|
||||
Assert::IsTrue(flags == mockEvents->m_flags);
|
||||
Assert::IsTrue(renameRegEx->UnAdvise(cookie) == S_OK);
|
||||
mockEvents->Release();
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
||||
|
||||
CTestFileHelper::CTestFileHelper()
|
||||
{
|
||||
_CreateTempDirectory();
|
||||
@@ -70,4 +68,3 @@ void CTestFileHelper::_DeleteTempDirectory()
|
||||
{
|
||||
fs::remove_all(_tempDirectory);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
class CTestFileHelper
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -6,4 +6,3 @@
|
||||
|
||||
// Headers for CppUnitTest
|
||||
#include "CppUnitTest.h"
|
||||
|
||||
|
||||
@@ -6,5 +6,3 @@
|
||||
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
||||
|
||||
#include <SDKDDKVer.h>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user