mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request As title <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Tests should be picked up and run and pass
183 lines
7.0 KiB
C++
183 lines
7.0 KiB
C++
#include "pch.h"
|
|
#include "TestHelpers.h"
|
|
#include <excluded_apps.h>
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
namespace UnitTestsCommonUtils
|
|
{
|
|
TEST_CLASS(ExcludedAppsTests)
|
|
{
|
|
public:
|
|
// find_app_name_in_path tests
|
|
TEST_METHOD(FindAppNameInPath_ExactMatch_ReturnsTrue)
|
|
{
|
|
std::wstring path = L"C:\\Program Files\\App\\notepad.exe";
|
|
std::vector<std::wstring> apps = { L"notepad.exe" };
|
|
Assert::IsTrue(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_NoMatch_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"C:\\Program Files\\App\\notepad.exe";
|
|
std::vector<std::wstring> apps = { L"calc.exe" };
|
|
Assert::IsFalse(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_MultipleApps_FindsMatch)
|
|
{
|
|
std::wstring path = L"C:\\Program Files\\App\\notepad.exe";
|
|
std::vector<std::wstring> apps = { L"calc.exe", L"notepad.exe", L"word.exe" };
|
|
Assert::IsTrue(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_EmptyPath_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"";
|
|
std::vector<std::wstring> apps = { L"notepad.exe" };
|
|
Assert::IsFalse(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_EmptyApps_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"C:\\Program Files\\App\\notepad.exe";
|
|
std::vector<std::wstring> apps = {};
|
|
Assert::IsFalse(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_PartialMatchInFolder_ReturnsFalse)
|
|
{
|
|
// "notepad" appears in folder name but not as the exe name
|
|
std::wstring path = L"C:\\notepad\\other.exe";
|
|
std::vector<std::wstring> apps = { L"notepad.exe" };
|
|
Assert::IsFalse(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_CaseSensitive_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"C:\\Program Files\\App\\NOTEPAD.EXE";
|
|
std::vector<std::wstring> apps = { L"notepad.exe" };
|
|
// The function does rfind which is case-sensitive
|
|
Assert::IsFalse(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_MatchWithDifferentExtension_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"C:\\Program Files\\App\\notepad.com";
|
|
std::vector<std::wstring> apps = { L"notepad.exe" };
|
|
Assert::IsFalse(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_MatchAtEndOfPath_ReturnsTrue)
|
|
{
|
|
std::wstring path = L"C:\\Windows\\System32\\notepad.exe";
|
|
std::vector<std::wstring> apps = { L"notepad.exe" };
|
|
Assert::IsTrue(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_UNCPath_Works)
|
|
{
|
|
std::wstring path = L"\\\\server\\share\\folder\\app.exe";
|
|
std::vector<std::wstring> apps = { L"app.exe" };
|
|
Assert::IsTrue(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
// find_folder_in_path tests
|
|
TEST_METHOD(FindFolderInPath_FolderExists_ReturnsTrue)
|
|
{
|
|
std::wstring path = L"C:\\Program Files\\MyApp\\app.exe";
|
|
std::vector<std::wstring> folders = { L"Program Files" };
|
|
Assert::IsTrue(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_FolderNotExists_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"C:\\Windows\\System32\\app.exe";
|
|
std::vector<std::wstring> folders = { L"Program Files" };
|
|
Assert::IsFalse(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_MultipleFolders_FindsMatch)
|
|
{
|
|
std::wstring path = L"C:\\Windows\\System32\\app.exe";
|
|
std::vector<std::wstring> folders = { L"Program Files", L"System32", L"Users" };
|
|
Assert::IsTrue(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_EmptyPath_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"";
|
|
std::vector<std::wstring> folders = { L"Windows" };
|
|
Assert::IsFalse(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_EmptyFolders_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"C:\\Windows\\app.exe";
|
|
std::vector<std::wstring> folders = {};
|
|
Assert::IsFalse(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_PartialMatch_ReturnsTrue)
|
|
{
|
|
// find_folder_in_path uses rfind which finds substrings
|
|
std::wstring path = L"C:\\Windows\\System32\\app.exe";
|
|
std::vector<std::wstring> folders = { L"System" };
|
|
Assert::IsTrue(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_NestedFolder_ReturnsTrue)
|
|
{
|
|
std::wstring path = L"C:\\Program Files\\Company\\Product\\bin\\app.exe";
|
|
std::vector<std::wstring> folders = { L"Product" };
|
|
Assert::IsTrue(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_RootDrive_ReturnsTrue)
|
|
{
|
|
std::wstring path = L"C:\\folder\\app.exe";
|
|
std::vector<std::wstring> folders = { L"C:\\" };
|
|
Assert::IsTrue(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_UNCPath_Works)
|
|
{
|
|
std::wstring path = L"\\\\server\\share\\folder\\app.exe";
|
|
std::vector<std::wstring> folders = { L"share" };
|
|
Assert::IsTrue(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_CaseSensitive_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"C:\\WINDOWS\\app.exe";
|
|
std::vector<std::wstring> folders = { L"windows" };
|
|
// rfind is case-sensitive
|
|
Assert::IsFalse(find_folder_in_path(path, folders));
|
|
}
|
|
|
|
// Edge case tests
|
|
TEST_METHOD(FindAppNameInPath_AppNameInMiddleOfPath_HandlesCorrectly)
|
|
{
|
|
// The app name appears both in folder and as filename
|
|
std::wstring path = L"C:\\notepad\\bin\\notepad.exe";
|
|
std::vector<std::wstring> apps = { L"notepad.exe" };
|
|
Assert::IsTrue(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindAppNameInPath_JustFilename_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"notepad.exe";
|
|
std::vector<std::wstring> apps = { L"notepad.exe" };
|
|
// find_app_name_in_path expects a path separator to validate the executable segment
|
|
Assert::IsFalse(find_app_name_in_path(path, apps));
|
|
}
|
|
|
|
TEST_METHOD(FindFolderInPath_JustFilename_ReturnsFalse)
|
|
{
|
|
std::wstring path = L"app.exe";
|
|
std::vector<std::wstring> folders = { L"Windows" };
|
|
Assert::IsFalse(find_folder_in_path(path, folders));
|
|
}
|
|
};
|
|
}
|