forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCommand.cpp
More file actions
134 lines (111 loc) · 4.14 KB
/
Copy pathTestCommand.cpp
File metadata and controls
134 lines (111 loc) · 4.14 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#ifndef AICLI_DISABLE_TEST_HOOKS
#include "TestCommand.h"
#include "AppInstallerRuntime.h"
namespace AppInstaller::CLI
{
namespace
{
void LogAndReport(Execution::Context& context, const std::string& message)
{
AICLI_LOG(CLI, Info, << message);
context.Reporter.Info() << message << std::endl;
}
HRESULT WaitForShutdown(Execution::Context& context)
{
LogAndReport(context, "Waiting for app shutdown event");
if (!Execution::WaitForAppShutdownEvent())
{
LogAndReport(context, "Failed getting app shutdown event");
return APPINSTALLER_CLI_ERROR_INTERNAL_ERROR;
}
LogAndReport(context, "Succeeded waiting for app shutdown event");
return S_OK;
}
HRESULT AppShutdownWindowMessage(Execution::Context& context)
{
auto windowHandle = Execution::GetWindowHandle();
if (windowHandle == NULL)
{
LogAndReport(context, "Window was not created");
return APPINSTALLER_CLI_ERROR_INTERNAL_ERROR;
}
if (context.Args.Contains(Execution::Args::Type::Force))
{
LogAndReport(context, "Sending WM_QUERYENDSESSION message");
THROW_LAST_ERROR_IF(!SendMessageTimeout(
windowHandle,
WM_QUERYENDSESSION,
NULL,
ENDSESSION_CLOSEAPP,
(SMTO_ABORTIFHUNG | SMTO_ERRORONEXIT),
5000,
NULL));
}
HRESULT hr = WaitForShutdown(context);
if (context.Args.Contains(Execution::Args::Type::Force))
{
LogAndReport(context, "Sending WM_ENDSESSION message");
THROW_LAST_ERROR_IF(!SendMessageTimeout(
windowHandle,
WM_ENDSESSION,
NULL,
ENDSESSION_CLOSEAPP,
(SMTO_ABORTIFHUNG | SMTO_ERRORONEXIT),
5000,
NULL));
}
return hr;
}
}
std::vector<std::unique_ptr<Command>> TestCommand::GetCommands() const
{
return InitializeFromMoveOnly<std::vector<std::unique_ptr<Command>>>({
std::make_unique<TestAppShutdownCommand>(FullName()),
});
}
void TestCommand::ExecuteInternal(Execution::Context& context) const
{
UNREFERENCED_PARAMETER(context);
Sleep(INFINITE);
}
Resource::LocString TestCommand::ShortDescription() const
{
return Utility::LocIndString("Waits infinitely"sv);
}
Resource::LocString TestCommand::LongDescription() const
{
return Utility::LocIndString("Waits infinitely. Use this if you want winget to wait forever while something is going on"sv);
}
std::vector<Argument> TestAppShutdownCommand::GetArguments() const
{
return {
Argument::ForType(Execution::Args::Type::Force)
};
}
void TestAppShutdownCommand::ExecuteInternal(Execution::Context& context) const
{
HRESULT hr = E_FAIL;
// Only package context and admin won't create the window message.
if (!Runtime::IsRunningInPackagedContext() || !Runtime::IsRunningAsAdmin())
{
hr = AppShutdownWindowMessage(context);
}
else
{
hr = WaitForShutdown(context);
}
AICLI_TERMINATE_CONTEXT(hr);
}
Resource::LocString TestAppShutdownCommand::ShortDescription() const
{
return Utility::LocIndString("Test command to verify appshutdown event."sv);
}
Resource::LocString TestAppShutdownCommand::LongDescription() const
{
return Utility::LocIndString("Test command for appshutdown. Verifies the window was created and waits for the app shutdown event"sv);
}
}
#endif