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
219 lines
8.3 KiB
C++
219 lines
8.3 KiB
C++
#include "pch.h"
|
|
#include "TestHelpers.h"
|
|
#include <gpo.h>
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
using namespace powertoys_gpo;
|
|
|
|
namespace UnitTestsCommonUtils
|
|
{
|
|
TEST_CLASS(GpoTests)
|
|
{
|
|
public:
|
|
// Helper to check if result is a valid gpo_rule_configured_t value
|
|
static constexpr bool IsValidGpoResult(gpo_rule_configured_t result)
|
|
{
|
|
return result == gpo_rule_configured_wrong_value ||
|
|
result == gpo_rule_configured_unavailable ||
|
|
result == gpo_rule_configured_not_configured ||
|
|
result == gpo_rule_configured_disabled ||
|
|
result == gpo_rule_configured_enabled;
|
|
}
|
|
|
|
// gpo_rule_configured_t enum tests
|
|
TEST_METHOD(GpoRuleConfigured_EnumValues_AreDistinct)
|
|
{
|
|
Assert::AreNotEqual(static_cast<int>(gpo_rule_configured_not_configured),
|
|
static_cast<int>(gpo_rule_configured_enabled));
|
|
Assert::AreNotEqual(static_cast<int>(gpo_rule_configured_enabled),
|
|
static_cast<int>(gpo_rule_configured_disabled));
|
|
Assert::AreNotEqual(static_cast<int>(gpo_rule_configured_not_configured),
|
|
static_cast<int>(gpo_rule_configured_disabled));
|
|
}
|
|
|
|
// getConfiguredValue tests
|
|
TEST_METHOD(GetConfiguredValue_NonExistentKey_ReturnsNotConfigured)
|
|
{
|
|
auto result = getConfiguredValue(L"NonExistentPolicyValue12345");
|
|
Assert::IsTrue(result == gpo_rule_configured_not_configured ||
|
|
result == gpo_rule_configured_unavailable);
|
|
}
|
|
|
|
// Utility enabled getters - these all follow the same pattern
|
|
TEST_METHOD(GetAllowExperimentationValue_ReturnsValidState)
|
|
{
|
|
auto result = getAllowExperimentationValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredAlwaysOnTopEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredAlwaysOnTopEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredAwakeEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredAwakeEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredColorPickerEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredColorPickerEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredFancyZonesEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredFancyZonesEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredFileLocksmithEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredFileLocksmithEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredImageResizerEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredImageResizerEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredKeyboardManagerEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredKeyboardManagerEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredPowerRenameEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredPowerRenameEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredPowerLauncherEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredPowerLauncherEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredShortcutGuideEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredShortcutGuideEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredTextExtractorEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredTextExtractorEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredHostsFileEditorEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredHostsFileEditorEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredMousePointerCrosshairsEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredMousePointerCrosshairsEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredMouseHighlighterEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredMouseHighlighterEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredMouseJumpEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredMouseJumpEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredFindMyMouseEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredFindMyMouseEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredMouseWithoutBordersEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredMouseWithoutBordersEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredAdvancedPasteEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredAdvancedPasteEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredPeekEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredPeekEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredRegistryPreviewEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredRegistryPreviewEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredScreenRulerEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredScreenRulerEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredCropAndLockEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredCropAndLockEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
TEST_METHOD(GetConfiguredEnvironmentVariablesEnabledValue_ReturnsValidState)
|
|
{
|
|
auto result = getConfiguredEnvironmentVariablesEnabledValue();
|
|
Assert::IsTrue(IsValidGpoResult(result));
|
|
}
|
|
|
|
// All GPO functions should not crash
|
|
TEST_METHOD(AllGpoFunctions_DoNotCrash)
|
|
{
|
|
getAllowExperimentationValue();
|
|
getConfiguredAlwaysOnTopEnabledValue();
|
|
getConfiguredAwakeEnabledValue();
|
|
getConfiguredColorPickerEnabledValue();
|
|
getConfiguredFancyZonesEnabledValue();
|
|
getConfiguredFileLocksmithEnabledValue();
|
|
getConfiguredImageResizerEnabledValue();
|
|
getConfiguredKeyboardManagerEnabledValue();
|
|
getConfiguredPowerRenameEnabledValue();
|
|
getConfiguredPowerLauncherEnabledValue();
|
|
getConfiguredShortcutGuideEnabledValue();
|
|
getConfiguredTextExtractorEnabledValue();
|
|
getConfiguredHostsFileEditorEnabledValue();
|
|
getConfiguredMousePointerCrosshairsEnabledValue();
|
|
getConfiguredMouseHighlighterEnabledValue();
|
|
getConfiguredMouseJumpEnabledValue();
|
|
getConfiguredFindMyMouseEnabledValue();
|
|
getConfiguredMouseWithoutBordersEnabledValue();
|
|
getConfiguredAdvancedPasteEnabledValue();
|
|
getConfiguredPeekEnabledValue();
|
|
getConfiguredRegistryPreviewEnabledValue();
|
|
getConfiguredScreenRulerEnabledValue();
|
|
getConfiguredCropAndLockEnabledValue();
|
|
getConfiguredEnvironmentVariablesEnabledValue();
|
|
|
|
Assert::IsTrue(true);
|
|
}
|
|
};
|
|
}
|