winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

TestSettings.cpp (1998B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "TestCommon.h"
      5 #include "TestSettings.h"
      6 #include <winget/Settings.h>
      7 
      8 using namespace AppInstaller::Settings;
      9 
     10 namespace TestCommon
     11 {
     12     namespace
     13     {
     14         void DeleteUserSettingsFilesInternal()
     15         {
     16             auto settingsPath = UserSettings::SettingsFilePath();
     17             if (std::filesystem::exists(settingsPath))
     18             {
     19                 std::filesystem::remove(settingsPath);
     20             }
     21 
     22             auto settingsBackupPath = GetPathTo(Stream::BackupUserSettings);
     23             if (std::filesystem::exists(settingsBackupPath))
     24             {
     25                 std::filesystem::remove(settingsBackupPath);
     26             }
     27         }
     28     }
     29 
     30     void SetSetting(const AppInstaller::Settings::StreamDefinition& stream, std::string_view value)
     31     {
     32         REQUIRE(Stream{ stream }.Set(value));
     33     }
     34 
     35     void RemoveSetting(const AppInstaller::Settings::StreamDefinition& stream)
     36     {
     37         Stream{ stream }.Remove();
     38     }
     39 
     40     std::filesystem::path GetPathTo(const AppInstaller::Settings::StreamDefinition& stream)
     41     {
     42         return Stream{ stream }.GetPath();
     43     }
     44 
     45     UserSettingsFileGuard::UserSettingsFileGuard()
     46     {
     47         DeleteUserSettingsFilesInternal();
     48     }
     49 
     50     UserSettingsFileGuard::~UserSettingsFileGuard()
     51     {
     52         DeleteUserSettingsFilesInternal();
     53     }
     54 
     55     [[nodiscard]] UserSettingsFileGuard DeleteUserSettingsFiles()
     56     {
     57         return {};
     58     }
     59 
     60     GroupPolicyTestOverride::GroupPolicyTestOverride(const AppInstaller::Registry::Key& key) : GroupPolicy(key)
     61     {
     62         GroupPolicy::OverrideInstance(this);
     63     }
     64 
     65     GroupPolicyTestOverride::~GroupPolicyTestOverride()
     66     {
     67         GroupPolicy::ResetInstance();
     68     }
     69 
     70     void GroupPolicyTestOverride::SetState(TogglePolicy::Policy policy, PolicyState state)
     71     {
     72         m_toggles[policy] = state;
     73     }
     74 }