Skip to content

Commit

Permalink
Expose IsRebootRequired property
Browse files Browse the repository at this point in the history
  • Loading branch information
heaths committed Jan 23, 2019
1 parent c021cdb commit 0d92cf1
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 12 deletions.
9 changes: 9 additions & 0 deletions docker/Tests/vswhere.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ Describe 'vswhere' {
$instances = [xml](C:\bin\vswhere.exe -all -format xml)
$instances.instances.instance.Count | Should Be 3
}

It 'returns 1 instance where IsRebootRequired' {
# Make sure PowerShell converts to a collection of PSCustomObjects before filtering.
$instances = C:\bin\vswhere.exe -all -format json | ConvertFrom-Json

$instances = @($instances | Where-Object { $_.IsRebootRequired })
$instances.Count | Should Be 1
$instances[0].instanceId | Should Be 3
}
}

Context '-products' {
Expand Down
24 changes: 24 additions & 0 deletions src/vswhere.lib/Formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Formatter::Formatter()
{ L"isComplete", bind(&Formatter::GetIsComplete, this, _1, _2) },
{ L"isLaunchable", bind(&Formatter::GetIsLaunchable, this, _1, _2) },
{ L"isPrerelease", bind(&Formatter::GetIsPrerelease, this, _1, _2) },
{ L"isRebootRequired", bind(&Formatter::GetIsRebootRequired, this, _1, _2) },
{ L"displayName", bind(&Formatter::GetDisplayName, this, _1, _2) },
{ L"description", bind(&Formatter::GetDescription, this, _1, _2) },
};
Expand Down Expand Up @@ -532,6 +533,29 @@ HRESULT Formatter::GetIsPrerelease(_In_ ISetupInstance* pInstance, _Out_ VARIANT
return hr;
}

HRESULT Formatter::GetIsRebootRequired(_In_ ISetupInstance* pInstance, _Out_ VARIANT* pvtIsRebootRequired)
{
ISetupInstance2Ptr instance;
variant_t vt;

auto hr = pInstance->QueryInterface(&instance);
if (SUCCEEDED(hr))
{
auto state = InstanceState::eNone;

hr = instance->GetState(&state);
if (SUCCEEDED(hr))
{
vt.vt = VT_BOOL;
vt.boolVal = (state & InstanceState::eNoRebootRequired) == 0 ? VARIANT_TRUE : VARIANT_FALSE;

*pvtIsRebootRequired = vt.Detach();
}
}

return hr;
}

HRESULT Formatter::GetDisplayName(_In_ ISetupInstance* pInstance, _Out_ VARIANT* pvtDisplayName)
{
auto lcid = ::GetUserDefaultLCID();
Expand Down
1 change: 1 addition & 0 deletions src/vswhere.lib/Formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Formatter
HRESULT GetIsComplete(_In_ ISetupInstance* pInstance, _Out_ VARIANT* pvtIsComplete);
HRESULT GetIsLaunchable(_In_ ISetupInstance* pInstance, _Out_ VARIANT* pvtIsLaunchable);
HRESULT GetIsPrerelease(_In_ ISetupInstance* pInstance, _Out_ VARIANT* pvtIsPrerelease);
HRESULT GetIsRebootRequired(_In_ ISetupInstance* pInstance, _Out_ VARIANT* pvtIsRebootRequired);
HRESULT GetDisplayName(_In_ ISetupInstance* pInstance, _Out_ VARIANT* pvtDisplayName);
HRESULT GetDescription(_In_ ISetupInstance* pInstance, _Out_ VARIANT* pvtDescription);

Expand Down
6 changes: 4 additions & 2 deletions test/vswhere.test/JsonFormatterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ TEST_CLASS(JsonFormatterTests)
L" \"instanceId\": \"a1b2c3\",\n"
L" \"state\": 11,\n"
L" \"isComplete\": true,\n"
L" \"isLaunchable\": false\n"
L" \"isLaunchable\": false,\n"
L" \"isRebootRequired\": true\n"
L" }\n"
L"]\n";

Expand Down Expand Up @@ -474,7 +475,8 @@ TEST_CLASS(JsonFormatterTests)
L" \"instanceId\": \"a1b2c3\",\n"
L" \"state\": 4294967295,\n"
L" \"isComplete\": true,\n"
L" \"isLaunchable\": true\n"
L" \"isLaunchable\": true,\n"
L" \"isRebootRequired\": false\n"
L" }\n"
L"]\n";

Expand Down
20 changes: 14 additions & 6 deletions test/vswhere.test/TestInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TestInstance :
m_properties(list.begin(), list.end()),
m_ulRef(1)
{
m_locale = ::_wcreate_locale(LC_ALL, L"en-US");
}

TestInstance(
Expand All @@ -27,6 +28,8 @@ class TestInstance :
m_properties(properties),
m_ulRef(1)
{
m_locale = ::_wcreate_locale(LC_ALL, L"en-US");

for (const auto package : packages)
{
m_packages.push_back(package);
Expand All @@ -35,6 +38,10 @@ class TestInstance :

~TestInstance()
{
if (m_locale)
{
::_free_locale(m_locale);
}
}

// IUnknown
Expand Down Expand Up @@ -191,7 +198,7 @@ class TestInstance :
_Out_ InstanceState* pState
)
{
return TryGetLONGLONG(L"State", reinterpret_cast<PLONGLONG>(pState));
return TryGetULONG(L"State", reinterpret_cast<PULONG>(pState));
}

STDMETHODIMP GetPackages(
Expand Down Expand Up @@ -414,9 +421,9 @@ class TestInstance :
return hr;
}

STDMETHODIMP TryGetLONGLONG(_In_ LPCWSTR wszName, _Out_ PLONGLONG pll)
STDMETHODIMP TryGetULONG(_In_ LPCWSTR wszName, _Out_ PULONG pul)
{
if (!pll)
if (!pul)
{
return E_POINTER;
}
Expand All @@ -426,10 +433,10 @@ class TestInstance :
auto hr = TryGet(wszName, value);
if (SUCCEEDED(hr))
{
*pll = _wtoi64(value.c_str());
if (*pll == 0)
*pul = _wcstoul_l(value.c_str(), NULL, 10, m_locale);
if (*pul == 0 || *pul == ULONG_MAX)
{
if (errno == ERANGE || errno == EINVAL)
if (errno == ERANGE)
{
hr = E_INVALIDARG;
}
Expand All @@ -444,5 +451,6 @@ class TestInstance :
MapType m_properties;
TestPropertyStore m_catalogProperties;
TestPropertyStore m_additionalProperties;
_locale_t m_locale;
ULONG m_ulRef;
};
6 changes: 4 additions & 2 deletions test/vswhere.test/TextFormatterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ TEST_CLASS(TextFormatterTests)
L"instanceId: a1b2c3\n"
L"state: 11\n"
L"isComplete: 1\n"
L"isLaunchable: 0\n";
L"isLaunchable: 0\n"
L"isRebootRequired: 1\n";

Assert::AreEqual(expected, console);
}
Expand All @@ -449,7 +450,8 @@ TEST_CLASS(TextFormatterTests)
L"instanceId: a1b2c3\n"
L"state: 4294967295\n"
L"isComplete: 1\n"
L"isLaunchable: 1\n";
L"isLaunchable: 1\n"
L"isRebootRequired: 0\n";

Assert::AreEqual(expected, console);
}
Expand Down
6 changes: 4 additions & 2 deletions test/vswhere.test/ValueFormatterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ TEST_CLASS(ValueFormatterTests)
L"a1b2c3\n"
L"11\n"
L"1\n"
L"0\n";
L"0\n"
L"1\n";

Assert::AreEqual(expected, console);
}
Expand All @@ -422,7 +423,8 @@ TEST_CLASS(ValueFormatterTests)
L"a1b2c3\n"
L"4294967295\n"
L"1\n"
L"1\n";
L"1\n"
L"0\n";

Assert::AreEqual(expected, console);
}
Expand Down
2 changes: 2 additions & 0 deletions test/vswhere.test/XmlFormatterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ TEST_CLASS(XmlFormatterTests)
L" <state>11</state>\n"
L" <isComplete>1</isComplete>\n"
L" <isLaunchable>0</isLaunchable>\n"
L" <isRebootRequired>1</isRebootRequired>\n"
L" </instance>\n"
L"</instances>\n";

Expand Down Expand Up @@ -488,6 +489,7 @@ TEST_CLASS(XmlFormatterTests)
L" <state>4294967295</state>\n"
L" <isComplete>1</isComplete>\n"
L" <isLaunchable>1</isLaunchable>\n"
L" <isRebootRequired>0</isRebootRequired>\n"
L" </instance>\n"
L"</instances>\n";

Expand Down

0 comments on commit 0d92cf1

Please sign in to comment.