forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFontHelper.cpp
More file actions
60 lines (49 loc) · 1.73 KB
/
Copy pathFontHelper.cpp
File metadata and controls
60 lines (49 loc) · 1.73 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "TestCommon.h"
#include "TestHooks.h"
#include "AppInstallerStrings.h"
#include "Microsoft/FontHelper.h"
using namespace AppInstaller::Manifest;
using namespace AppInstaller::Repository::Microsoft;
using namespace AppInstaller::Utility;
using namespace AppInstaller::Registry;
TEST_CASE("FontHelper_Watcher", "[FontHelper]")
{
FontHelper helper;
wil::unique_event callbackEvent;
callbackEvent.create();
ScopeEnum scopeCallback = ScopeEnum::Unknown;
ScopeEnum scopeTarget = ScopeEnum::Machine;
auto fakeRoot = TestCommon::RegCreateVolatileTestRoot();
TestHook::SetGetFontRegistryRoot_Override fontRootOverride([&](ScopeEnum scope)
{
if (scope == scopeTarget)
{
return Key(fakeRoot.get(), L"");
}
else
{
return Key{};
}
});
auto watchers = std::vector<wil::unique_registry_watcher>();
helper.AddRegistryWatchers(scopeTarget, [&](ScopeEnum scope, wil::RegistryChangeKind)
{
scopeCallback = scope;
callbackEvent.SetEvent();
}, watchers);
GUID guid;
std::ignore = CoCreateGuid(&guid);
std::ostringstream stream;
stream << guid;
auto testKey = TestCommon::RegCreateVolatileSubKey(fakeRoot.get(), ConvertToUTF16(stream.str()));
REQUIRE(callbackEvent.wait(1000));
REQUIRE(scopeTarget == scopeCallback);
// Reset for changing a value
scopeCallback = ScopeEnum::Unknown;
TestCommon::SetRegistryValue(testKey.get(), L"testValue", L"valueValue");
REQUIRE(callbackEvent.wait(1000));
REQUIRE(scopeTarget == scopeCallback);
}