Files
PowerToys/src/modules/Workspaces/WorkspacesLib.UnitTests/PwaHelperTests.cpp

101 lines
3.0 KiB
C++
Raw Normal View History

Workspaceslib ut (#40007) This pull request introduces a new unit testing framework for the `WorkspacesLib` module, adds test coverage for various utilities, and integrates the new test project into the build system. Key changes include adding the `WorkspacesLibUnitTests` project, implementing tests for `AppUtils`, `JsonUtils`, and `PwaHelper`, and updating the build configuration to include the new test project. ### Unit Tests Added: * **`AppUtilsTests`**: - Added comprehensive tests for methods such as `GetCurrentFolder`, `IsEdge`, `IsChrome`, and `IsSteamGame` to validate their behavior under various conditions. * **`JsonUtilsTests`**: - Implemented tests for reading and writing workspace data, including scenarios for invalid JSON, non-existent files, and valid workspace lists. * **`PwaHelperTests`**: - Added tests to ensure the stability of `PwaHelper` methods, such as `GetEdgeAppId`, `GetChromeAppId`, and `SearchPwaName`, even with invalid or empty inputs. ### Build System Updates: * **New Test Project Integration**: - Added the `WorkspacesLibUnitTests` project to the solution file `PowerToys.sln` with appropriate dependencies. - Updated build configurations to include the new test project for both Debug and Release builds across architectures. [[1]](diffhunk://#diff-ca837ce490070b91656ffffe31cbad8865ba9174e0f020231f77baf35ff3f811R2208-R2215) [[2]](diffhunk://#diff-ca837ce490070b91656ffffe31cbad8865ba9174e0f020231f77baf35ff3f811R2841) ### Pipeline Adjustments: * **Test Discovery**: - Updated the pipeline configuration in `.pipelines/v2/templates/job-build-project.yml` to discover the new `WorkspacesLibUnitTests.dll` during test runs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2025-06-13 10:51:22 +08:00
#include "pch.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace WorkspacesLibUnitTests
{
TEST_CLASS (PwaHelperTests)
{
public:
TEST_METHOD (PwaHelper_Constructor_DoesNotThrow)
{
// Act & Assert - Constructor should not crash when called
try
{
Utils::PwaHelper helper;
// If we get here, the constructor didn't throw
Assert::IsTrue(true);
}
catch (...)
{
Assert::Fail(L"PwaHelper constructor should not throw exceptions");
}
}
TEST_METHOD (PwaHelper_GetEdgeAppId_EmptyAumid_ReturnsEmpty)
{
// Arrange
Utils::PwaHelper helper;
std::wstring emptyAumid = L"";
// Act
auto result = helper.GetEdgeAppId(emptyAumid);
// Assert
Assert::IsFalse(result.has_value());
}
TEST_METHOD (PwaHelper_GetChromeAppId_EmptyAumid_ReturnsEmpty)
{
// Arrange
Utils::PwaHelper helper;
std::wstring emptyAumid = L"";
// Act
auto result = helper.GetChromeAppId(emptyAumid);
// Assert
Assert::IsFalse(result.has_value());
}
TEST_METHOD (PwaHelper_SearchPwaName_EmptyParameters_ReturnsEmpty)
{
// Arrange
Utils::PwaHelper helper;
std::wstring emptyPwaAppId = L"";
std::wstring emptyWindowAumid = L"";
// Act
std::wstring result = helper.SearchPwaName(emptyPwaAppId, emptyWindowAumid);
// Assert
Assert::IsTrue(result.empty());
}
TEST_METHOD (PwaHelper_SearchPwaName_NonExistentIds_ReturnsEmpty)
{
// Arrange
Utils::PwaHelper helper;
std::wstring nonExistentPwaAppId = L"nonexistent_app_id";
std::wstring nonExistentWindowAumid = L"nonexistent_aumid";
// Act
std::wstring result = helper.SearchPwaName(nonExistentPwaAppId, nonExistentWindowAumid);
// TODO: is it really expected?
Assert::IsTrue(result == nonExistentWindowAumid);
}
TEST_METHOD (PwaHelper_GetEdgeAppId_ValidConstruction_DoesNotCrash)
{
// Arrange
Utils::PwaHelper helper;
std::wstring testAumid = L"Microsoft.MicrosoftEdge_8wekyb3d8bbwe!App";
// Act & Assert - Should not crash
auto result = helper.GetEdgeAppId(testAumid);
// Result can be empty or have value, but should not crash
}
TEST_METHOD (PwaHelper_GetChromeAppId_ValidConstruction_DoesNotCrash)
{
// Arrange
Utils::PwaHelper helper;
std::wstring testAumid = L"Chrome.App.TestId";
// Act & Assert - Should not crash
auto result = helper.GetChromeAppId(testAumid);
// Result can be empty or have value, but should not crash
}
};
}