winget-cli

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

ArpHelper.cpp (2244B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "TestCommon.h"
      5 #include "TestHooks.h"
      6 #include "Microsoft/ARPHelper.h"
      7 #include "AppInstallerStrings.h"
      8 
      9 using namespace AppInstaller::Manifest;
     10 using namespace AppInstaller::Repository::Microsoft;
     11 using namespace AppInstaller::Utility;
     12 using namespace AppInstaller::Registry;
     13 
     14 
     15 TEST_CASE("ARPHelper_Watcher", "[ARPHelper]")
     16 {
     17     ARPHelper helper;
     18 
     19     wil::unique_event callbackEvent;
     20     callbackEvent.create();
     21 
     22     ScopeEnum scopeCallback = ScopeEnum::Unknown;
     23     Architecture architectureCallback = Architecture::Unknown;
     24 
     25     ScopeEnum scopeTarget = ScopeEnum::Machine;
     26     Architecture architectureTarget = Architecture::X86;
     27 
     28     auto fakeRoot = TestCommon::RegCreateVolatileTestRoot();
     29     TestHook::SetGetARPKey_Override arpOverride([&](ScopeEnum scope, Architecture arch)
     30         {
     31             if (scope == scopeTarget && arch == architectureTarget)
     32             {
     33                 return Key(fakeRoot.get(), L"");
     34             }
     35             else
     36             {
     37                 return Key{};
     38             }
     39         });
     40 
     41     auto watchers = helper.CreateRegistryWatchers(scopeTarget, [&](ScopeEnum scope, Architecture arch, wil::RegistryChangeKind)
     42         {
     43             scopeCallback = scope;
     44             architectureCallback = arch;
     45             callbackEvent.SetEvent();
     46         });
     47 
     48     auto arpKey = helper.GetARPKey(scopeTarget, architectureTarget);
     49     REQUIRE(!!arpKey);
     50 
     51     GUID guid;
     52     std::ignore = CoCreateGuid(&guid);
     53     std::ostringstream stream;
     54     stream << guid;
     55 
     56     auto testKey = TestCommon::RegCreateVolatileSubKey(arpKey, ConvertToUTF16(stream.str()));
     57 
     58     REQUIRE(callbackEvent.wait(1000));
     59     REQUIRE(scopeTarget == scopeCallback);
     60     REQUIRE(architectureTarget == architectureCallback);
     61 
     62     // Reset for changing a value
     63     scopeCallback = ScopeEnum::Unknown;
     64     architectureCallback = Architecture::Unknown;
     65 
     66     TestCommon::SetRegistryValue(testKey.get(), L"testValue", L"valueValue");
     67 
     68     REQUIRE(callbackEvent.wait(1000));
     69     REQUIRE(scopeTarget == scopeCallback);
     70     REQUIRE(architectureTarget == architectureCallback);
     71 }