/ src / common / UnitTests-CommonUtils / Gpo.Tests.cpp
Gpo.Tests.cpp
  1  #include "pch.h"
  2  #include "TestHelpers.h"
  3  #include <gpo.h>
  4  
  5  using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  6  using namespace powertoys_gpo;
  7  
  8  namespace UnitTestsCommonUtils
  9  {
 10      TEST_CLASS(GpoTests)
 11      {
 12      public:
 13          // Helper to check if result is a valid gpo_rule_configured_t value
 14          static constexpr bool IsValidGpoResult(gpo_rule_configured_t result)
 15          {
 16              return result == gpo_rule_configured_wrong_value ||
 17                     result == gpo_rule_configured_unavailable ||
 18                     result == gpo_rule_configured_not_configured ||
 19                     result == gpo_rule_configured_disabled ||
 20                     result == gpo_rule_configured_enabled;
 21          }
 22  
 23          // gpo_rule_configured_t enum tests
 24          TEST_METHOD(GpoRuleConfigured_EnumValues_AreDistinct)
 25          {
 26              Assert::AreNotEqual(static_cast<int>(gpo_rule_configured_not_configured),
 27                                 static_cast<int>(gpo_rule_configured_enabled));
 28              Assert::AreNotEqual(static_cast<int>(gpo_rule_configured_enabled),
 29                                 static_cast<int>(gpo_rule_configured_disabled));
 30              Assert::AreNotEqual(static_cast<int>(gpo_rule_configured_not_configured),
 31                                 static_cast<int>(gpo_rule_configured_disabled));
 32          }
 33  
 34          // getConfiguredValue tests
 35          TEST_METHOD(GetConfiguredValue_NonExistentKey_ReturnsNotConfigured)
 36          {
 37              auto result = getConfiguredValue(L"NonExistentPolicyValue12345");
 38              Assert::IsTrue(result == gpo_rule_configured_not_configured ||
 39                            result == gpo_rule_configured_unavailable);
 40          }
 41  
 42          // Utility enabled getters - these all follow the same pattern
 43          TEST_METHOD(GetAllowExperimentationValue_ReturnsValidState)
 44          {
 45              auto result = getAllowExperimentationValue();
 46              Assert::IsTrue(IsValidGpoResult(result));
 47          }
 48  
 49          TEST_METHOD(GetConfiguredAlwaysOnTopEnabledValue_ReturnsValidState)
 50          {
 51              auto result = getConfiguredAlwaysOnTopEnabledValue();
 52              Assert::IsTrue(IsValidGpoResult(result));
 53          }
 54  
 55          TEST_METHOD(GetConfiguredAwakeEnabledValue_ReturnsValidState)
 56          {
 57              auto result = getConfiguredAwakeEnabledValue();
 58              Assert::IsTrue(IsValidGpoResult(result));
 59          }
 60  
 61          TEST_METHOD(GetConfiguredColorPickerEnabledValue_ReturnsValidState)
 62          {
 63              auto result = getConfiguredColorPickerEnabledValue();
 64              Assert::IsTrue(IsValidGpoResult(result));
 65          }
 66  
 67          TEST_METHOD(GetConfiguredFancyZonesEnabledValue_ReturnsValidState)
 68          {
 69              auto result = getConfiguredFancyZonesEnabledValue();
 70              Assert::IsTrue(IsValidGpoResult(result));
 71          }
 72  
 73          TEST_METHOD(GetConfiguredFileLocksmithEnabledValue_ReturnsValidState)
 74          {
 75              auto result = getConfiguredFileLocksmithEnabledValue();
 76              Assert::IsTrue(IsValidGpoResult(result));
 77          }
 78  
 79          TEST_METHOD(GetConfiguredImageResizerEnabledValue_ReturnsValidState)
 80          {
 81              auto result = getConfiguredImageResizerEnabledValue();
 82              Assert::IsTrue(IsValidGpoResult(result));
 83          }
 84  
 85          TEST_METHOD(GetConfiguredKeyboardManagerEnabledValue_ReturnsValidState)
 86          {
 87              auto result = getConfiguredKeyboardManagerEnabledValue();
 88              Assert::IsTrue(IsValidGpoResult(result));
 89          }
 90  
 91          TEST_METHOD(GetConfiguredPowerRenameEnabledValue_ReturnsValidState)
 92          {
 93              auto result = getConfiguredPowerRenameEnabledValue();
 94              Assert::IsTrue(IsValidGpoResult(result));
 95          }
 96  
 97          TEST_METHOD(GetConfiguredPowerLauncherEnabledValue_ReturnsValidState)
 98          {
 99              auto result = getConfiguredPowerLauncherEnabledValue();
100              Assert::IsTrue(IsValidGpoResult(result));
101          }
102  
103          TEST_METHOD(GetConfiguredShortcutGuideEnabledValue_ReturnsValidState)
104          {
105              auto result = getConfiguredShortcutGuideEnabledValue();
106              Assert::IsTrue(IsValidGpoResult(result));
107          }
108  
109          TEST_METHOD(GetConfiguredTextExtractorEnabledValue_ReturnsValidState)
110          {
111              auto result = getConfiguredTextExtractorEnabledValue();
112              Assert::IsTrue(IsValidGpoResult(result));
113          }
114  
115          TEST_METHOD(GetConfiguredHostsFileEditorEnabledValue_ReturnsValidState)
116          {
117              auto result = getConfiguredHostsFileEditorEnabledValue();
118              Assert::IsTrue(IsValidGpoResult(result));
119          }
120  
121          TEST_METHOD(GetConfiguredMousePointerCrosshairsEnabledValue_ReturnsValidState)
122          {
123              auto result = getConfiguredMousePointerCrosshairsEnabledValue();
124              Assert::IsTrue(IsValidGpoResult(result));
125          }
126  
127          TEST_METHOD(GetConfiguredMouseHighlighterEnabledValue_ReturnsValidState)
128          {
129              auto result = getConfiguredMouseHighlighterEnabledValue();
130              Assert::IsTrue(IsValidGpoResult(result));
131          }
132  
133          TEST_METHOD(GetConfiguredMouseJumpEnabledValue_ReturnsValidState)
134          {
135              auto result = getConfiguredMouseJumpEnabledValue();
136              Assert::IsTrue(IsValidGpoResult(result));
137          }
138  
139          TEST_METHOD(GetConfiguredFindMyMouseEnabledValue_ReturnsValidState)
140          {
141              auto result = getConfiguredFindMyMouseEnabledValue();
142              Assert::IsTrue(IsValidGpoResult(result));
143          }
144  
145          TEST_METHOD(GetConfiguredMouseWithoutBordersEnabledValue_ReturnsValidState)
146          {
147              auto result = getConfiguredMouseWithoutBordersEnabledValue();
148              Assert::IsTrue(IsValidGpoResult(result));
149          }
150  
151          TEST_METHOD(GetConfiguredAdvancedPasteEnabledValue_ReturnsValidState)
152          {
153              auto result = getConfiguredAdvancedPasteEnabledValue();
154              Assert::IsTrue(IsValidGpoResult(result));
155          }
156  
157          TEST_METHOD(GetConfiguredPeekEnabledValue_ReturnsValidState)
158          {
159              auto result = getConfiguredPeekEnabledValue();
160              Assert::IsTrue(IsValidGpoResult(result));
161          }
162  
163          TEST_METHOD(GetConfiguredRegistryPreviewEnabledValue_ReturnsValidState)
164          {
165              auto result = getConfiguredRegistryPreviewEnabledValue();
166              Assert::IsTrue(IsValidGpoResult(result));
167          }
168  
169          TEST_METHOD(GetConfiguredScreenRulerEnabledValue_ReturnsValidState)
170          {
171              auto result = getConfiguredScreenRulerEnabledValue();
172              Assert::IsTrue(IsValidGpoResult(result));
173          }
174  
175          TEST_METHOD(GetConfiguredCropAndLockEnabledValue_ReturnsValidState)
176          {
177              auto result = getConfiguredCropAndLockEnabledValue();
178              Assert::IsTrue(IsValidGpoResult(result));
179          }
180  
181          TEST_METHOD(GetConfiguredEnvironmentVariablesEnabledValue_ReturnsValidState)
182          {
183              auto result = getConfiguredEnvironmentVariablesEnabledValue();
184              Assert::IsTrue(IsValidGpoResult(result));
185          }
186  
187          // All GPO functions should not crash
188          TEST_METHOD(AllGpoFunctions_DoNotCrash)
189          {
190              getAllowExperimentationValue();
191              getConfiguredAlwaysOnTopEnabledValue();
192              getConfiguredAwakeEnabledValue();
193              getConfiguredColorPickerEnabledValue();
194              getConfiguredFancyZonesEnabledValue();
195              getConfiguredFileLocksmithEnabledValue();
196              getConfiguredImageResizerEnabledValue();
197              getConfiguredKeyboardManagerEnabledValue();
198              getConfiguredPowerRenameEnabledValue();
199              getConfiguredPowerLauncherEnabledValue();
200              getConfiguredShortcutGuideEnabledValue();
201              getConfiguredTextExtractorEnabledValue();
202              getConfiguredHostsFileEditorEnabledValue();
203              getConfiguredMousePointerCrosshairsEnabledValue();
204              getConfiguredMouseHighlighterEnabledValue();
205              getConfiguredMouseJumpEnabledValue();
206              getConfiguredFindMyMouseEnabledValue();
207              getConfiguredMouseWithoutBordersEnabledValue();
208              getConfiguredAdvancedPasteEnabledValue();
209              getConfiguredPeekEnabledValue();
210              getConfiguredRegistryPreviewEnabledValue();
211              getConfiguredScreenRulerEnabledValue();
212              getConfiguredCropAndLockEnabledValue();
213              getConfiguredEnvironmentVariablesEnabledValue();
214  
215              Assert::IsTrue(true);
216          }
217      };
218  }