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