diff --git a/WindowsAppRuntime.sln b/WindowsAppRuntime.sln index 9dbfdd6b0..1ebd8089b 100644 --- a/WindowsAppRuntime.sln +++ b/WindowsAppRuntime.sln @@ -461,9 +461,13 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PackageManagerTests", "test\PackageManager\API\PackageManagerTests.vcxproj", "{4A38CB80-3580-4960-9B31-3301058B7AFE}" ProjectSection(ProjectDependencies) = postProject {09DDAE21-397F-4263-8561-7F2FF28127CF} = {09DDAE21-397F-4263-8561-7F2FF28127CF} + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF} = {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF} + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA} = {39277B4C-4FB5-45F6-B0AA-EE8086590CDA} {4626E11F-A7A4-41A2-B22D-5A108BC369AC} = {4626E11F-A7A4-41A2-B22D-5A108BC369AC} {58E95711-A12F-4C0E-A978-C6B4A0842AC8} = {58E95711-A12F-4C0E-A978-C6B4A0842AC8} {66D0D8B1-FAF4-4C6A-8303-07F3BA356FE3} = {66D0D8B1-FAF4-4C6A-8303-07F3BA356FE3} + {AC79B8FF-4C27-4326-AD20-BBC70059FF51} = {AC79B8FF-4C27-4326-AD20-BBC70059FF51} + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D} = {AD7D0A19-44B9-41D6-A68A-9FECAC28078D} {B73AD907-6164-4294-88FB-F3C9C10DA1F1} = {B73AD907-6164-4294-88FB-F3C9C10DA1F1} {D0A1DFB8-8CEE-4CFC-B57B-B7C574B411C2} = {D0A1DFB8-8CEE-4CFC-B57B-B7C574B411C2} {F2946790-DAF7-4DFF-A754-BA471A12E494} = {F2946790-DAF7-4DFF-A754-BA471A12E494} @@ -493,6 +497,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Windows.Managemen {B73AD907-6164-4294-88FB-F3C9C10DA1F1} = {B73AD907-6164-4294-88FB-F3C9C10DA1F1} EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PackageManager.Test.M.Black.msix", "PackageManager.Test.M.Black.msix", "{1AC589D7-FA54-470E-8640-AB2477CA844C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PackageManager.Test.M.Blacker.msix", "PackageManager.Test.M.Blacker.msix", "{4567CD12-A0A7-4E65-8075-B17C09261767}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PackageManager.Test.M.Black.msix", "test\PackageManager\data\PackageManager.Test.M.Black.msix\PackageManager.Test.M.Black.msix.vcxproj", "{39277B4C-4FB5-45F6-B0AA-EE8086590CDA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PackageManager.Test.M.Blacker.msix", "test\PackageManager\data\PackageManager.Test.M.Blacker.msix\PackageManager.Test.M.Blacker.msix.vcxproj", "{AD7D0A19-44B9-41D6-A68A-9FECAC28078D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PackageManager.Test.M.White.msix", "PackageManager.Test.M.White.msix", "{6759ECC6-9381-4172-89E6-853F81A03D28}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PackageManager.Test.M.Whiter.msix", "PackageManager.Test.M.Whiter.msix", "{7C240089-0F22-4247-9C91-51255C8DC18B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PackageManager.Test.M.Whiter.msix", "test\PackageManager\data\PackageManager.Test.M.Whiter.msix\PackageManager.Test.M.Whiter.msix.vcxproj", "{AC79B8FF-4C27-4326-AD20-BBC70059FF51}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PackageManager.Test.M.White.msix", "test\PackageManager\data\PackageManager.Test.M.White.msix\PackageManager.Test.M.White.msix.vcxproj", "{28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1739,6 +1759,70 @@ Global {57E6CCBE-EDEB-4300-8334-98A591D11B3F}.Release|x64.Build.0 = Release|x64 {57E6CCBE-EDEB-4300-8334-98A591D11B3F}.Release|x86.ActiveCfg = Release|x86 {57E6CCBE-EDEB-4300-8334-98A591D11B3F}.Release|x86.Build.0 = Release|x86 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Debug|Any CPU.ActiveCfg = Debug|x64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Debug|Any CPU.Build.0 = Debug|x64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Debug|ARM64.Build.0 = Debug|ARM64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Debug|x64.ActiveCfg = Debug|x64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Debug|x64.Build.0 = Debug|x64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Debug|x86.ActiveCfg = Debug|Win32 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Debug|x86.Build.0 = Debug|Win32 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Release|Any CPU.ActiveCfg = Release|x64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Release|Any CPU.Build.0 = Release|x64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Release|ARM64.ActiveCfg = Release|ARM64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Release|ARM64.Build.0 = Release|ARM64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Release|x64.ActiveCfg = Release|x64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Release|x64.Build.0 = Release|x64 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Release|x86.ActiveCfg = Release|Win32 + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA}.Release|x86.Build.0 = Release|Win32 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Debug|Any CPU.ActiveCfg = Debug|x64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Debug|Any CPU.Build.0 = Debug|x64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Debug|ARM64.Build.0 = Debug|ARM64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Debug|x64.ActiveCfg = Debug|x64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Debug|x64.Build.0 = Debug|x64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Debug|x86.ActiveCfg = Debug|Win32 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Debug|x86.Build.0 = Debug|Win32 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Release|Any CPU.ActiveCfg = Release|x64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Release|Any CPU.Build.0 = Release|x64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Release|ARM64.ActiveCfg = Release|ARM64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Release|ARM64.Build.0 = Release|ARM64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Release|x64.ActiveCfg = Release|x64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Release|x64.Build.0 = Release|x64 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Release|x86.ActiveCfg = Release|Win32 + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D}.Release|x86.Build.0 = Release|Win32 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Debug|Any CPU.ActiveCfg = Debug|x64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Debug|Any CPU.Build.0 = Debug|x64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Debug|ARM64.Build.0 = Debug|ARM64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Debug|x64.ActiveCfg = Debug|x64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Debug|x64.Build.0 = Debug|x64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Debug|x86.ActiveCfg = Debug|Win32 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Debug|x86.Build.0 = Debug|Win32 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Release|Any CPU.ActiveCfg = Release|x64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Release|Any CPU.Build.0 = Release|x64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Release|ARM64.ActiveCfg = Release|ARM64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Release|ARM64.Build.0 = Release|ARM64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Release|x64.ActiveCfg = Release|x64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Release|x64.Build.0 = Release|x64 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Release|x86.ActiveCfg = Release|Win32 + {AC79B8FF-4C27-4326-AD20-BBC70059FF51}.Release|x86.Build.0 = Release|Win32 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Debug|Any CPU.ActiveCfg = Debug|x64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Debug|Any CPU.Build.0 = Debug|x64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Debug|ARM64.Build.0 = Debug|ARM64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Debug|x64.ActiveCfg = Debug|x64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Debug|x64.Build.0 = Debug|x64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Debug|x86.ActiveCfg = Debug|Win32 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Debug|x86.Build.0 = Debug|Win32 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|Any CPU.ActiveCfg = Release|x64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|Any CPU.Build.0 = Release|x64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|ARM64.ActiveCfg = Release|ARM64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|ARM64.Build.0 = Release|ARM64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|x64.ActiveCfg = Release|x64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|x64.Build.0 = Release|x64 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|x86.ActiveCfg = Release|Win32 + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1885,9 +1969,17 @@ Global {4626E11F-A7A4-41A2-B22D-5A108BC369AC} = {266AE21F-0D59-4422-A95C-4B3D2BA32A4C} {39A17DBB-F1DB-4D0C-B90E-D5F9BEC2283A} = {6213B1A3-E854-498F-AAFA-4CFC1E71023E} {FBAE1876-C50A-4EFC-A686-3008B6438731} = {39A17DBB-F1DB-4D0C-B90E-D5F9BEC2283A} - {B6B68924-6A0B-457E-AD53-018696EC8889} = {B03C7C69-0A52-4553-B465-04C995161E42} + {B6B68924-6A0B-457E-AD53-018696EC8889} = {6213B1A3-E854-498F-AAFA-4CFC1E71023E} {D0A1DFB8-8CEE-4CFC-B57B-B7C574B411C2} = {B6B68924-6A0B-457E-AD53-018696EC8889} {57E6CCBE-EDEB-4300-8334-98A591D11B3F} = {716C26A0-E6B0-4981-8412-D14A4D410531} + {1AC589D7-FA54-470E-8640-AB2477CA844C} = {6213B1A3-E854-498F-AAFA-4CFC1E71023E} + {4567CD12-A0A7-4E65-8075-B17C09261767} = {6213B1A3-E854-498F-AAFA-4CFC1E71023E} + {39277B4C-4FB5-45F6-B0AA-EE8086590CDA} = {1AC589D7-FA54-470E-8640-AB2477CA844C} + {AD7D0A19-44B9-41D6-A68A-9FECAC28078D} = {4567CD12-A0A7-4E65-8075-B17C09261767} + {6759ECC6-9381-4172-89E6-853F81A03D28} = {6213B1A3-E854-498F-AAFA-4CFC1E71023E} + {7C240089-0F22-4247-9C91-51255C8DC18B} = {6213B1A3-E854-498F-AAFA-4CFC1E71023E} + {AC79B8FF-4C27-4326-AD20-BBC70059FF51} = {7C240089-0F22-4247-9C91-51255C8DC18B} + {28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF} = {6759ECC6-9381-4172-89E6-853F81A03D28} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4B3D7591-CFEC-4762-9A07-ABE99938FB77} diff --git a/dev/Common/AppModel.Identity.h b/dev/Common/AppModel.Identity.h index 649099df3..c1ef91ce6 100644 --- a/dev/Common/AppModel.Identity.h +++ b/dev/Common/AppModel.Identity.h @@ -372,6 +372,14 @@ public: return m_packageId->publisherId; } + std::wstring PackageFamilyName() const + { + WCHAR packageFamilyName[PACKAGE_FAMILY_NAME_MAX_LENGTH + 1]{}; + UINT32 packageFamilyNameLength{ ARRAYSIZE(packageFamilyName) }; + THROW_IF_WIN32_ERROR_MSG(::PackageFamilyNameFromId(m_packageId, &packageFamilyNameLength, packageFamilyName), "%ls", m_packageFullName.c_str()); + return packageFamilyName; + } + explicit operator bool() const { return m_packageId != nullptr; @@ -384,6 +392,15 @@ private: PACKAGE_RESOURCEID_MAX_LENGTH + 1 + PACKAGE_PUBLISHERID_MAX_LENGTH + 1) * sizeof(WCHAR)]{}; }; + +template +T ToPackageFamilyName(PCWSTR packageFullName) +{ + WCHAR packageFamilyName[PACKAGE_FAMILY_NAME_MAX_LENGTH + 1]{}; + UINT32 packageFamilyNameLength{ ARRAYSIZE(packageFamilyName) }; + THROW_IF_WIN32_ERROR_MSG(::PackageFamilyNameFromFullName(packageFullName, &packageFamilyNameLength, packageFamilyName), "%ls", packageFullName); + return T{ packageFamilyName }; +} } #endif // __APPMODEL_IDENTITY_H diff --git a/dev/Common/IsWindowsVersion.h b/dev/Common/IsWindowsVersion.h index 88ca80191..96b17a568 100644 --- a/dev/Common/IsWindowsVersion.h +++ b/dev/Common/IsWindowsVersion.h @@ -55,7 +55,7 @@ inline bool IsWindows11_22H2OrGreater() inline bool IsWindows11_23H1OrGreater() { // TryCreatePackageDependency2() added to in NTDDI_WIN10_GE (aka Windows 11 23H1) - return IsExportPresent(L"api-ms-win-appmodel-runtime-l1-1-7.dll", "TryCreatePackageDependency2"); + return IsExportPresent(L"kernelbase.dll", "TryCreatePackageDependency2"); } } diff --git a/dev/Common/Security.User.h b/dev/Common/Security.User.h index 87e7d0d8c..c37fdafca 100644 --- a/dev/Common/Security.User.h +++ b/dev/Common/Security.User.h @@ -18,6 +18,32 @@ inline bool IsLocalSystem(HANDLE token = nullptr) return !!EqualSid(userSid, localSystemSid); } + +/// @return sid. Allocated via LocalAlloc; use LocalFree to deallocate +inline PSID StringToSid(PCWSTR sidString) +{ + if (!sidString || (sidString[0] == L'\0')) + { + return nullptr; + } + + PSID sid{}; + THROW_IF_WIN32_BOOL_FALSE(::ConvertStringSidToSidW(sidString, &sid)); + return sid; +} + +/// @return sid as a string. Allocated via LocalAlloc; use LocalFree to deallocate +inline PWSTR SidToString(PSID sid) +{ + if (!sid) + { + return nullptr; + } + + PWSTR sidString{}; + THROW_IF_WIN32_BOOL_FALSE(::ConvertSidToStringSidW(sid, &sidString)); + return sidString; +} } #endif // __SECURITY_USER_H diff --git a/dev/Deployment/DeploymentManager.cpp b/dev/Deployment/DeploymentManager.cpp index fd8fee2b6..a744277b9 100644 --- a/dev/Deployment/DeploymentManager.cpp +++ b/dev/Deployment/DeploymentManager.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation and Contributors. +// Copyright (c) Microsoft Corporation and Contributors. // Licensed under the MIT License. #include @@ -403,7 +403,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem HRESULT deploymentOperationHResult{}; HRESULT deploymentOperationExtendedHResult{}; - if (deploymentOperation.Status() != AsyncStatus::Completed) + if (deploymentOperation.Status() != winrt::Windows::Foundation::AsyncStatus::Completed) { deploymentOperationHResult = static_cast(deploymentOperation.ErrorCode()); deploymentOperationExtendedHResult = deploymentResult.ExtendedErrorCode(); diff --git a/dev/MRTCore/mrt/Core/unittests/packages.config b/dev/MRTCore/mrt/Core/unittests/packages.config index 1861ca894..9749bd814 100644 --- a/dev/MRTCore/mrt/Core/unittests/packages.config +++ b/dev/MRTCore/mrt/Core/unittests/packages.config @@ -1,4 +1,4 @@  - + diff --git a/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/UnpackagedTests/packages.config b/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/UnpackagedTests/packages.config index 11a9dacfc..be237de8a 100644 --- a/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/UnpackagedTests/packages.config +++ b/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/UnpackagedTests/packages.config @@ -1,4 +1,4 @@  - + diff --git a/dev/MRTCore/mrt/mrm/UnitTests/packages.config b/dev/MRTCore/mrt/mrm/UnitTests/packages.config index 3a3c1cd7e..c49326759 100644 --- a/dev/MRTCore/mrt/mrm/UnitTests/packages.config +++ b/dev/MRTCore/mrt/mrm/UnitTests/packages.config @@ -1,5 +1,5 @@  - + diff --git a/dev/PackageManager/API/M.W.M.D.EnsureReadyOptions.cpp b/dev/PackageManager/API/M.W.M.D.EnsureReadyOptions.cpp index c0a3075a4..8c6a3ba5a 100644 --- a/dev/PackageManager/API/M.W.M.D.EnsureReadyOptions.cpp +++ b/dev/PackageManager/API/M.W.M.D.EnsureReadyOptions.cpp @@ -14,4 +14,12 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation { return m_addPackageOptions; } + bool EnsureReadyOptions::RegisterNewerIfAvailable() + { + return m_registerNewerIfAvailable; + } + void EnsureReadyOptions::RegisterNewerIfAvailable(bool value) + { + m_registerNewerIfAvailable = value; + } } diff --git a/dev/PackageManager/API/M.W.M.D.EnsureReadyOptions.h b/dev/PackageManager/API/M.W.M.D.EnsureReadyOptions.h index 85d288fcb..d68d126e7 100644 --- a/dev/PackageManager/API/M.W.M.D.EnsureReadyOptions.h +++ b/dev/PackageManager/API/M.W.M.D.EnsureReadyOptions.h @@ -12,8 +12,11 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation EnsureReadyOptions() = default; winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions AddPackageOptions(); + bool RegisterNewerIfAvailable(); + void RegisterNewerIfAvailable(bool value); private: winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions m_addPackageOptions{}; + bool m_registerNewerIfAvailable{}; }; } namespace winrt::Microsoft::Windows::Management::Deployment::factory_implementation diff --git a/dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.cpp b/dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.cpp index 149e09b81..9615c0165 100644 --- a/dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.cpp +++ b/dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.cpp @@ -11,6 +11,29 @@ #include "PackageManagerTelemetry.h" +#include +#include +#include +#if defined(NTDDI_WIN11_GE) +# define TODO_UpdatedWindowsSDK_with_Windows_Management_Deployment_IRemovePackageOptions +#endif +#if !defined(TODO_UpdatedWindowsSDK_with_Windows_Management_Deployment_IRemovePackageOptions) +// Until we have access to the updated Windows SDK we can't use RemovePackageOptions +// but we need *something* to satisfy PackageManagement_RemovePackageByUriAsync() in the FrameworkUDK +// so we'll make a placeholder definition to satisfy the compiler enough to let us call +// PackageManagement_RemovePackageByUriAsync2(uri, nullptr). Remove this once the updated +// Windows SDK makes this unnecessary. +namespace ABI::Windows::Management::Deployment +{ + typedef void * IRemovePackageOptions; +} +#endif +// +#include +#include + +#include + static_assert(static_cast(winrt::Microsoft::Windows::Management::Deployment::StubPackageOption::Default) == static_cast(winrt::Windows::Management::Deployment::StubPackageOption::Default), "winrt::Microsoft::Windows::Management::Deployment::StubPackageOption::Default != winrt::Windows::Management::Deployment::StubPackageOption::Default"); static_assert(static_cast(winrt::Microsoft::Windows::Management::Deployment::StubPackageOption::InstallFull) == static_cast(winrt::Windows::Management::Deployment::StubPackageOption::InstallFull), @@ -20,12 +43,125 @@ static_assert(static_cast(winrt::Microsoft::Windows::Management::Deployment static_assert(static_cast(winrt::Microsoft::Windows::Management::Deployment::StubPackageOption::UsePreference) == static_cast(winrt::Windows::Management::Deployment::StubPackageOption::UsePreference), "winrt::Microsoft::Windows::Management::Deployment::StubPackageOption::UsePreference != winrt::Windows::Management::Deployment::StubPackageOption::UsePreference"); +static PackageManagement_ArchitectureType ToArchitectureType(const winrt::Windows::System::ProcessorArchitecture architecture) +{ + switch (architecture) + { + case winrt::Windows::System::ProcessorArchitecture::X86: return PackageManagement_ArchitectureType_X86; + case winrt::Windows::System::ProcessorArchitecture::Arm: return PackageManagement_ArchitectureType_Arm; + case winrt::Windows::System::ProcessorArchitecture::X64: return PackageManagement_ArchitectureType_X64; + case winrt::Windows::System::ProcessorArchitecture::Neutral: return PackageManagement_ArchitectureType_Neutral; + case winrt::Windows::System::ProcessorArchitecture::Arm64: return PackageManagement_ArchitectureType_Arm64; + case winrt::Windows::System::ProcessorArchitecture::X86OnArm64: return PackageManagement_ArchitectureType_X86A64; + case winrt::Windows::System::ProcessorArchitecture::Unknown: return PackageManagement_ArchitectureType_Unknown; + default: THROW_HR_MSG(E_UNEXPECTED, "%d", static_cast(architecture)); + } +} + +namespace winrt::Microsoft::Windows::ApplicationModel::DynamicDependency +{ + DEFINE_ENUM_FLAG_OPERATORS(PackageDependencyProcessorArchitectures) +} +static PackageManagement_ArchitectureType ToArchitectureType(const winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures processorArchitectureFilter) +{ + auto architectureType{ PackageManagement_ArchitectureType_None }; + if (WI_IsFlagSet(processorArchitectureFilter, winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::Neutral)) + { + architectureType |= PackageManagement_ArchitectureType_Neutral; + } + if (WI_IsFlagSet(processorArchitectureFilter, winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::X86)) + { + architectureType |= PackageManagement_ArchitectureType_X86; + } + if (WI_IsFlagSet(processorArchitectureFilter, winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::X64)) + { + architectureType |= PackageManagement_ArchitectureType_X64; + } + if (WI_IsFlagSet(processorArchitectureFilter, winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::Arm)) + { + architectureType |= PackageManagement_ArchitectureType_Arm; + } + if (WI_IsFlagSet(processorArchitectureFilter, winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::Arm64)) + { + architectureType |= PackageManagement_ArchitectureType_Arm64; + } + if (WI_IsFlagSet(processorArchitectureFilter, winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::X86OnArm64)) + { + architectureType |= PackageManagement_ArchitectureType_X86A64; + } + return architectureType; +} + +static winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures ToPackageDependencyProcessorArchitectures(const winrt::Windows::System::ProcessorArchitecture architecture) +{ + switch (architecture) + { + case winrt::Windows::System::ProcessorArchitecture::X86: return winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::X86; + case winrt::Windows::System::ProcessorArchitecture::X64: return winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::X64; + case winrt::Windows::System::ProcessorArchitecture::Arm: return winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::Arm; + case winrt::Windows::System::ProcessorArchitecture::Arm64: return winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::Arm64; + case winrt::Windows::System::ProcessorArchitecture::X86OnArm64: return winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::X86OnArm64; + case winrt::Windows::System::ProcessorArchitecture::Neutral: return winrt::Microsoft::Windows::ApplicationModel::DynamicDependency::PackageDependencyProcessorArchitectures::Neutral; + case winrt::Windows::System::ProcessorArchitecture::Unknown: THROW_HR_MSG(E_UNEXPECTED, "Unsupported architecture 0x%X", architecture); + default: THROW_HR_MSG(E_UNEXPECTED, "Unknown architecture 0x%X", architecture); + } +} + namespace winrt::Microsoft::Windows::Management::Deployment::implementation { winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager PackageDeploymentManager::GetDefault() { return winrt::make(); } + bool PackageDeploymentManager::IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature feature) + { + switch (feature) + { + case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup: + { + //TODO Feature lookup + // Relies on PackageManagement_IsFeatureSupported(L"PackageUriScheme.ms-uup") exist in Microsoft.FrameworkUdk and enabled + return ::WindowsVersion::IsExportPresent(L"appxdeploymentclient.dll", "MsixRemovePackageByUriAsync"); + } + case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::IsPackageReadyOrNewerAvailable: + { + //TODO Feature lookup + // Relies on PackageManagement_IsFeatureSupported(L"IsPackageReadyOrNewerAvailable") exist in Microsoft.FrameworkUdk and enabled + return false; + } + case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::RemovePackageByUri: + { + //TODO Awaiting Platform SDK defining RemovePackageOptions + //return ::WindowsVersion::IsExportPresent(L"appxdeploymentclient.dll", "MsixRemovePackageByUriAsync"); + return false; + } + case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ResetPackage: + { + return ::WindowsVersion::IsExportPresent(L"appxdeploymentclient.dll", "MsixResetPackageAsync"); + } + case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::RepairPackage: + { + return ::WindowsVersion::IsExportPresent(L"appxdeploymentclient.dll", "MsixRepairPackageAsync"); + } + case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ProvisionPackage_Framework: + { + //TODO Awaiting ProvisionPackageForAllUsersAsync() support for Framework packages + //return IsPackageDeploymentFeatureSupported(L"ProvisionPackage.Framework"); + return false; + } + default: + { + (void)LOG_HR_MSG(E_UNEXPECTED, "Feature:%d", static_cast(feature)); + return false; + } + } + } + bool PackageDeploymentManager::IsPackageDeploymentFeatureSupported(PCWSTR feature) + { + BOOL isSupported{}; + THROW_IF_FAILED_MSG(PackageManagement_IsFeatureSupported(feature, &isSupported), "%s", feature); + return !!isSupported; + } bool PackageDeploymentManager::IsPackageReady(hstring const& package) { if (VerifyPackageFullName(package.c_str()) == ERROR_SUCCESS) @@ -43,12 +179,32 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation } bool PackageDeploymentManager::IsPackageReadyByUri(winrt::Windows::Foundation::Uri const& packageUri) { - //TODO Awaiting FrameworkUdk update with Uup_SRFindPackageFullNamesByUupProductId() - throw hresult_not_implemented(); + // Currently supported URI schemes: ms-uup + const auto packageFullNames{ GetPackageFullNamesFromUupProductUriIfMsUup(packageUri) }; + if (!packageFullNames) + { + // Currently supported URI schemes: ms-uup + if (!IsUriScheme_MsUup(packageUri)) + { + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup)); + } + + // Ready UUP Products always have 1+ package so no packages found means not ready + return false; + } + + for (PCWSTR packageFullName : packageFullNames) + { + if (!IsReadyByPackageFullName(packageFullName)) + { + return false; + } + } + return true; } bool PackageDeploymentManager::IsPackageSetReady(winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) { - Validate(packageSet); + Validate_PackageUriIsOptional(packageSet); for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSet.Items()) { @@ -69,6 +225,118 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation } return true; } + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus PackageDeploymentManager::IsPackageReadyOrNewerAvailable(hstring const& package) + { + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::IsPackageReadyOrNewerAvailable)); + + if (VerifyPackageFullName(package.c_str()) == ERROR_SUCCESS) + { + return IsReadyOrNewerAvailableByPackageFullName(package.c_str()); + } + + const winrt::Windows::Foundation::Uri packageUri{ package }; + const auto packageAbsoluteUri{ packageUri.AbsoluteUri() }; + if (!packageAbsoluteUri.empty()) + { + return IsPackageReadyOrNewerAvailableByUri(packageUri); + } + THROW_HR_MSG(E_INVALIDARG, "%ls", package.c_str()); + } + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus PackageDeploymentManager::IsPackageReadyOrNewerAvailableByUri(winrt::Windows::Foundation::Uri const& packageUri) + { + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::IsPackageReadyOrNewerAvailable)); + + // Currently supported URI schemes: ms-uup + const auto schemeName{ packageUri.SchemeName() }; + const auto uupProductId{ GetUupProductIdIfMsUup(packageUri) }; + if (uupProductId.empty()) + { + // Currently supported URI schemes: ms-uup + if (!IsUriScheme_MsUup(packageUri)) + { + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup)); + } + + // Ready UUP Products always have 1+ package so no packages found means not ready + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady; + } + + wil::unique_cotaskmem_array_ptr packageFullNames; + THROW_IF_FAILED_MSG(Uup_SRFindPackageFullNamesByUupProductId(uupProductId.c_str(), packageFullNames.size_address(), packageFullNames.addressof()), "%s", uupProductId.c_str()); + + bool anyNewerAvailable{}; + const auto packageUriAsString{ packageUri.ToString() }; + for (PCWSTR packageFullName : packageFullNames) + { + const auto packageIdentity{ ::AppModel::Identity::PackageIdentity::FromPackageFullName(packageFullName) }; + const auto packageFamilyName{ packageIdentity.PackageFamilyName() }; + const auto minVersion{ packageIdentity.Version().Version }; + const auto architectureType{ ToArchitectureType(packageIdentity.Architecture()) }; + BOOL isRegistered{}; + BOOL isNewerAvailable{}; + THROW_IF_FAILED_MSG(PackageManagement_IsRegisteredOrNewerAvailable(nullptr, packageFamilyName.c_str(), minVersion, architectureType, &isRegistered, &isNewerAvailable), "%s", packageUriAsString.c_str()); + if (!isRegistered) + { + // At least one package isn't ready so we have our answer + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady; + } + if (!anyNewerAvailable & !!isNewerAvailable) + { + anyNewerAvailable = true; + } + } + if (anyNewerAvailable) + { + // All packages are registered but at least 1 has a newer version available + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable; + } + + // All packages are registered and none have anything newer avaiable + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready; + } + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus PackageDeploymentManager::IsPackageSetReadyOrNewerAvailable(winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) + { + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::IsPackageReadyOrNewerAvailable)); + + Validate_PackageUriIsOptional(packageSet); + + bool newerAvailable{}; + for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSet.Items()) + { + const auto status{ IsReadyOrNewerAvailable(packageSetItem) }; + if (status == winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady) + { + const ::AppModel::Identity::PackageVersion minVersion{ packageSetItem.MinVersion() }; + TraceLoggingWrite( + PackageManagementTelemetryProvider::Provider(), + "PackageDeployment.Resolver.NotFound", + TraceLoggingWideString(packageSetItem.Id().c_str(), "Criteria.Id"), + TraceLoggingWideString(packageSetItem.PackageFamilyName().c_str(), "Criteria.PackageFamilyName"), + TraceLoggingHexUInt64(minVersion.Version, "Criteria.MinVersion"), + TraceLoggingHexInt32(static_cast(packageSetItem.ProcessorArchitectureFilter()), "Criteria.ArchitectureFilter"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance)); + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady; + } + if (!newerAvailable && (status == winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable)) + { + const ::AppModel::Identity::PackageVersion minVersion{ packageSetItem.MinVersion() }; + TraceLoggingWrite( + PackageManagementTelemetryProvider::Provider(), + "PackageDeployment.Resolver.NewerAvailable", + TraceLoggingWideString(packageSetItem.Id().c_str(), "Criteria.Id"), + TraceLoggingWideString(packageSetItem.PackageFamilyName().c_str(), "Criteria.PackageFamilyName"), + TraceLoggingHexUInt64(minVersion.Version, "Criteria.MinVersion"), + TraceLoggingHexInt32(static_cast(packageSetItem.ProcessorArchitectureFilter()), "Criteria.ArchitectureFilter"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance)); + newerAvailable = true; + } + } + return newerAvailable ? + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable : + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready; + } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::EnsurePackageReadyAsync(hstring package, winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options) { @@ -83,8 +351,45 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::EnsurePackageReadyByUriAsync(winrt::Windows::Foundation::Uri packageUri, winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options) { - //TODO Awaiting FrameworkUdk update with Uup_SRFindPackageFullNamesByUupProductId() - throw hresult_not_implemented(); + // Currently supported URI schemes: ms-uup + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup)); + + // Create a PackageSet for the URI + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + const auto packageFullNames{ GetPackageFullNamesFromUupProductUriIfMsUup(packageUri) }; + if (packageFullNames) + { + packageSet.Id(packageUri.ToString()); + packageSet.PackageUri(packageUri); + auto packageSetItems{ packageSet.Items() }; + for (PCWSTR packageFullName : packageFullNames) + { + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + packageSetItem.Id(packageFullName); + const auto packageIdentity{ ::AppModel::Identity::PackageIdentity::FromPackageFullName(packageFullName) }; + packageSetItem.PackageFamilyName(packageIdentity.PackageFamilyName().c_str()); + const ::AppModel::Identity::PackageVersion minVersion{ packageIdentity.Version() }; + packageSetItem.MinVersion(minVersion.ToWinrtPackageVersion()); + const auto processorArchitectureFilter{ ToPackageDependencyProcessorArchitectures(packageIdentity.Architecture()) }; + packageSetItem.ProcessorArchitectureFilter(processorArchitectureFilter); + packageSetItems.Append(packageSetItem); + } + } + + auto logTelemetry{ PackageManagementTelemetry::EnsurePackageReadyByUriAsync::Start(packageUri.ToString()) }; + + if (packageSet.Id().empty()) + { + // Package URI isn't known to the system so it's an add or bust + co_return co_await AddPackageByUriAsync(packageUri, options.AddPackageOptions()); + } + else + { + // Package URI is known so process the PackageSet + co_return co_await EnsurePackageSetReadyAsync(packageSet, options); + } + + logTelemetry.Stop(packageUri.ToString()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::EnsurePackageSetReadyAsync(winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet, winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options) @@ -108,7 +413,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation progress(packageDeploymentProgress); // Check parameter(s) - Validate(packageSet); + Validate_PackageUriIsRequired(packageSet); // Is there any work to do? packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; @@ -132,10 +437,10 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) { const auto packageFamilyName{ packageSetItem.PackageFamilyName() }; - const auto packageUri{ packageSetItem.PackageUri() }; + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; try { - error = LOG_IF_FAILED_MSG(EnsureReadyAsync(packageSetItem, options, packageDeploymentProgress, progress, extendedError, errorText, activityId), + error = LOG_IF_FAILED_MSG(EnsureReadyAsync(packageUri, packageSetItem, options, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), "Error:0x%08X (0x%08X) PackageFamilyName:%ls PackageUri:%ls : %ls", error, extendedError, packageFamilyName.c_str(), packageUri.ToString().c_str(), errorText.c_str()); } @@ -196,17 +501,15 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation PackageDeploymentProgressStatus::Queued, 0} }; progress(packageDeploymentProgress); - // Check parameter(s) - //TODO Validate(packageSet); - winrt::Windows::Management::Deployment::AddPackageOptions addOptions{ ToOptions(options) }; + const double progressMaxPerPackage{ 1.0 }; HRESULT error{}; HRESULT extendedError{}; winrt::hstring errorText; winrt::guid activityId{}; try { - error = LOG_IF_FAILED_MSG(AddPackage(packageUri, addOptions, packageDeploymentProgress, progress, extendedError, errorText, activityId), + error = LOG_IF_FAILED_MSG(AddPackage(packageUri, addOptions, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageUri.ToString().c_str()); } @@ -247,7 +550,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation progress(packageDeploymentProgress); // Check parameter(s) - Validate(packageSet); + Validate_PackageUriIsRequired(packageSet); packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; const double c_progressPercentageStartOfInstalls{ 0.10 }; @@ -261,18 +564,24 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::guid activityId{}; for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) { + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; try { - error = LOG_IF_FAILED_MSG(AddPackage(packageSetItem, options, packageDeploymentProgress, progress, extendedError, errorText, activityId), + const auto progressBeforePackage{ packageDeploymentProgress.Progress }; + error = LOG_IF_FAILED_MSG(AddPackage(packageUri, options, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", - extendedError, packageSetItem.PackageFamilyName().c_str(), packageSetItem.PackageUri().ToString().c_str()); - packageDeploymentProgress.Progress = packageDeploymentProgress.Progress + progressIncrementPerPackageSetItem; - progress(packageDeploymentProgress); + extendedError, packageSetItem.PackageFamilyName().c_str(), packageUri.ToString().c_str()); + const auto progressAfterPackage{ progressBeforePackage + progressIncrementPerPackageSetItem }; + if (packageDeploymentProgress.Progress < progressAfterPackage) + { + packageDeploymentProgress.Progress = progressAfterPackage; + progress(packageDeploymentProgress); + } } catch (...) { const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; - error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageSetItem.PackageFamilyName().c_str(), packageSetItem.PackageUri().ToString().c_str()); + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageSetItem.PackageFamilyName().c_str(), packageUri.ToString().c_str()); } if (FAILED(error)) { @@ -317,17 +626,15 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation PackageDeploymentProgressStatus::Queued, 0} }; progress(packageDeploymentProgress); - // Check parameter(s) - //TODO Validate(packageSet); - winrt::Windows::Management::Deployment::StagePackageOptions stageOptions{ ToOptions(options) }; + const double progressMaxPerPackage{ 1.0 }; HRESULT error{}; HRESULT extendedError{}; winrt::hstring errorText; winrt::guid activityId{}; try { - error = LOG_IF_FAILED_MSG(StagePackage(packageUri, stageOptions, packageDeploymentProgress, progress, extendedError, errorText, activityId), + error = LOG_IF_FAILED_MSG(StagePackage(packageUri, stageOptions, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageUri.ToString().c_str()); } @@ -368,7 +675,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation progress(packageDeploymentProgress); // Check parameter(s) - Validate(packageSet); + Validate_PackageUriIsRequired(packageSet); packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; const double c_progressPercentageStartOfInstalls{ 0.10 }; @@ -382,18 +689,24 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::guid activityId{}; for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) { + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; try { - error = LOG_IF_FAILED_MSG(StagePackage(packageSetItem, options, packageDeploymentProgress, progress, extendedError, errorText, activityId), + const auto progressBeforePackage{ packageDeploymentProgress.Progress }; + error = LOG_IF_FAILED_MSG(StagePackage(packageUri, options, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", - extendedError, packageSetItem.PackageFamilyName().c_str(), packageSetItem.PackageUri().ToString().c_str()); - packageDeploymentProgress.Progress = packageDeploymentProgress.Progress + progressIncrementPerPackageSetItem; - progress(packageDeploymentProgress); + extendedError, packageSetItem.PackageFamilyName().c_str(), packageUri.ToString().c_str()); + const auto progressAfterPackage{ progressBeforePackage + progressIncrementPerPackageSetItem }; + if (packageDeploymentProgress.Progress < progressAfterPackage) + { + packageDeploymentProgress.Progress = progressAfterPackage; + progress(packageDeploymentProgress); + } } catch (...) { const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; - error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageSetItem.PackageFamilyName().c_str(), packageSetItem.PackageUri().ToString().c_str()); + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageSetItem.PackageFamilyName().c_str(), packageUri.ToString().c_str()); } if (FAILED(error)) { @@ -411,11 +724,11 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation { if (VerifyPackageFamilyName(package.c_str()) == ERROR_SUCCESS) { - return RegisterPackageByPackageFullNameAsync(package, options); + return RegisterPackageByPackageFamilyNameAsync(package, options); } else if (VerifyPackageFullName(package.c_str()) == ERROR_SUCCESS) { - return RegisterPackageByPackageFamilyNameAsync(package, options); + return RegisterPackageByPackageFullNameAsync(package, options); } const winrt::Windows::Foundation::Uri packageUri{ package }; @@ -448,17 +761,15 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation PackageDeploymentProgressStatus::Queued, 0} }; progress(packageDeploymentProgress); - // Check parameter(s) - //TODO Validate(packageSet); - winrt::Windows::Management::Deployment::RegisterPackageOptions registerOptions{ ToOptions(options) }; + const double progressMaxPerPackage{ 1.0 }; HRESULT error{}; HRESULT extendedError{}; winrt::hstring errorText; winrt::guid activityId{}; try { - error = LOG_IF_FAILED_MSG(RegisterPackage(packageUri, registerOptions, packageDeploymentProgress, progress, extendedError, errorText, activityId), + error = LOG_IF_FAILED_MSG(RegisterPackage(packageUri, registerOptions, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageUri.ToString().c_str()); } @@ -499,7 +810,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation progress(packageDeploymentProgress); // Check parameter(s) - Validate(packageSet); + Validate_PackageUriIsRequired(packageSet); packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; const double c_progressPercentageStartOfInstalls{ 0.10 }; @@ -513,18 +824,24 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::guid activityId{}; for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) { + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; try { - error = LOG_IF_FAILED_MSG(RegisterPackage(packageSetItem, options, packageDeploymentProgress, progress, extendedError, errorText, activityId), + const auto progressBeforePackage{ packageDeploymentProgress.Progress }; + error = LOG_IF_FAILED_MSG(RegisterPackage(packageUri, options, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", - extendedError, packageSetItem.PackageFamilyName().c_str(), packageSetItem.PackageUri().ToString().c_str()); - packageDeploymentProgress.Progress = packageDeploymentProgress.Progress + progressIncrementPerPackageSetItem; - progress(packageDeploymentProgress); + extendedError, packageSetItem.PackageFamilyName().c_str(), packageUri.ToString().c_str()); + const auto progressAfterPackage{ progressBeforePackage + progressIncrementPerPackageSetItem }; + if (packageDeploymentProgress.Progress < progressAfterPackage) + { + packageDeploymentProgress.Progress = progressAfterPackage; + progress(packageDeploymentProgress); + } } catch (...) { const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; - error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageSetItem.PackageFamilyName().c_str(), packageSetItem.PackageUri().ToString().c_str()); + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageSetItem.PackageFamilyName().c_str(), packageUri.ToString().c_str()); } if (FAILED(error)) { @@ -560,68 +877,656 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::RemovePackageByFullNameAsync(hstring packageFullName, winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options) { - //TODO Awaiting FrameworkUdk update with PackageManagement_RemovePackageByUriAsync() - throw hresult_not_implemented(); + auto logTelemetry{ PackageManagementTelemetry::RemovePackageAsync::Start(packageFullName) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + winrt::Windows::Management::Deployment::RemovalOptions removeOptions{ ToOptions(options) }; + const double progressMaxPerPackage{ 1.0 }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(RemovePackageByFullName(packageFullName, options, removeOptions, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageUri:%ls", + extendedError, packageFullName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageFullName.c_str()); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageFullName); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::RemovePackageByFamilyNameAsync(hstring packageFamilyName, winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options) { - //TODO Awaiting FrameworkUdk update with PackageManagement_RemovePackageByUriAsync() - throw hresult_not_implemented(); + auto logTelemetry{ PackageManagementTelemetry::RemovePackageAsync::Start(packageFamilyName) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + winrt::hstring packageFullName{ packageFamilyName }; + const double progressMaxPerPackageFamily{ 1.0 }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(RemovePackageByFamilyName(packageFamilyName, options, packageDeploymentProgress, progress, progressMaxPerPackageFamily, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFamilyName:%ls", + extendedError, packageFamilyName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls", extendedError, packageFamilyName.c_str()); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageFamilyName); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::RemovePackageByUriAsync(winrt::Windows::Foundation::Uri packageUri, winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options) { - //TODO Awaiting FrameworkUdk update with PackageManagement_RemovePackageByUriAsync() - throw hresult_not_implemented(); + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::RemovePackageByUri)); + + const winrt::hstring packageUriAsString{ packageUri.ToString() }; + auto logTelemetry{ PackageManagementTelemetry::RemovePackageByUriAsync::Start(packageUriAsString) }; + + // Check parameter(s) + if (IsUriScheme_MsUup(packageUri)) + { + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup)); + } + else + { + // Other URI schemes not supported + THROW_HR_MSG(E_INVALIDARG, "%ls", packageUri.ToString().c_str()); + } + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + // Check parameter(s) + if (IsUriScheme_MsUup(packageUri)) + { + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup)); + } + else + { + // Other URI schemes not supported + THROW_HR_MSG(E_INVALIDARG, "%ls", packageUri.ToString().c_str()); + } + + winrt::Windows::Management::Deployment::RemovalOptions removeOptions{ ToOptions(options) }; + const double progressMaxPerPackage{ 1.0 }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(RemovePackage(packageUri, removeOptions, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageUri:%ls", + extendedError, packageUri.ToString().c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageUri.ToString().c_str()); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageUriAsString); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::RemovePackageSetAsync(winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet, winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options) { - //TODO Awaiting FrameworkUdk update with PackageManagement_RemovePackageByUriAsync() - throw hresult_not_implemented(); + auto logTelemetry{ PackageManagementTelemetry::RemovePackageSetAsync::Start(packageSet.Id()) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + // Allow to register the progress and complete handler + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + // Check parameter(s) + Validate_PackageUriOrFamilyName(packageSet); + + packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; + const double c_progressPercentageStartOfInstalls{ 0.10 }; + packageDeploymentProgress.Progress = c_progressPercentageStartOfInstalls; + progress(packageDeploymentProgress); + auto packageSetItems{ packageSet.Items() }; + const double progressIncrementPerPackageSetItem{ (1.0 - c_progressPercentageStartOfInstalls) / packageSetItems.Size() }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) + { + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; + const auto packageFamilyName{ packageSetItem.PackageFamilyName() }; + try + { + const auto progressBeforePackage{ packageDeploymentProgress.Progress }; + if (packageUri) + { + error = LOG_IF_FAILED_MSG(RemovePackage(packageUri, options, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", + extendedError, packageFamilyName.c_str(), packageUri ? packageUri.ToString().c_str() : L""); + } + else + { + error = LOG_IF_FAILED_MSG(RemovePackageByFamilyName(packageFamilyName, options, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:", + extendedError, packageFamilyName.c_str()); + } + const auto progressAfterPackage{ progressBeforePackage + progressIncrementPerPackageSetItem }; + if (packageDeploymentProgress.Progress < progressAfterPackage) + { + packageDeploymentProgress.Progress = progressAfterPackage; + progress(packageDeploymentProgress); + } + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageFamilyName.c_str(), packageUri ? packageUri.ToString().c_str() : L""); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageSet.Id()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::ResetPackageAsync(hstring package) { - //TODO Awaiting FrameworkUdk update with Uup_SRFindPackageFullNamesByUupProductId() - throw hresult_not_implemented(); + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ResetPackage)); + + if (VerifyPackageFamilyName(package.c_str()) == ERROR_SUCCESS) + { + return ResetPackageByFamilyNameAsync(package); + } + else if (VerifyPackageFullName(package.c_str()) == ERROR_SUCCESS) + { + return ResetPackageByFullNameAsync(package); + } + + const winrt::Windows::Foundation::Uri packageUri{ package }; + const auto packageAbsoluteUri{ packageUri.AbsoluteUri() }; + if (!packageAbsoluteUri.empty()) + { + return ResetPackageByUriAsync(packageUri); + } + THROW_HR_MSG(E_INVALIDARG, "%ls", package.c_str()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::ResetPackageByUriAsync(winrt::Windows::Foundation::Uri packageUri) { - //TODO Awaiting FrameworkUdk update with PackageManagement_ResetPackageAsync() - throw hresult_not_implemented(); + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ResetPackage)); + + // Currently supported URI schemes: ms-uup + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup)); + + auto logTelemetry{ PackageManagementTelemetry::ResetPackageByUriAsync::Start(packageUri.ToString()) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + // Allow to register the progress and complete handler + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + // Create a PackageSet of (just) package family names for the URI + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + packageSet.Id(packageUri.ToString()); + const auto packageFullNames{ GetPackageFullNamesFromUupProductUriIfMsUup(packageUri) }; + if (packageFullNames.empty()) + { + const auto hr{ HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND) }; + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, GUID{}, hr, HRESULT_FROM_WIN32(ERROR_NOT_FOUND), winrt::impl::message_from_hresult(hr)); + } + + packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; + const double c_progressPercentageStartOfInstalls{ 0.10 }; + packageDeploymentProgress.Progress = c_progressPercentageStartOfInstalls; + progress(packageDeploymentProgress); + const double progressIncrementPerPackageSetItem{ (1.0 - c_progressPercentageStartOfInstalls) / packageFullNames.size() }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + const auto packageUriAsString{ packageUri.ToString() }; + for (PCWSTR packageFullName : packageFullNames) + { + try + { + const auto progressBeforePackage{ packageDeploymentProgress.Progress }; + error = LOG_IF_FAILED_MSG(ResetPackageByFullName(packageFullName, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFullName:%ls PackageUri:%ls", + extendedError, packageFullName, packageUriAsString.c_str()); + const auto progressAfterPackage{ progressBeforePackage + progressIncrementPerPackageSetItem }; + if (packageDeploymentProgress.Progress < progressAfterPackage) + { + packageDeploymentProgress.Progress = progressAfterPackage; + progress(packageDeploymentProgress); + } + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls PackageFamilyName:%ls PackageUri:%ls", + extendedError, packageFullName, packageUriAsString.c_str()); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageSet.Id()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::ResetPackageSetAsync(winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet) { - //TODO Awaiting FrameworkUdk update with PackageManagement_ResetPackageAsync() - throw hresult_not_implemented(); + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ResetPackage)); + + auto logTelemetry{ PackageManagementTelemetry::ResetPackageSetAsync::Start(packageSet.Id()) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + // Allow to register the progress and complete handler + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + // Check parameter(s) + Validate_PackageUriIsOptional(packageSet); + + packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; + const double c_progressPercentageStartOfInstalls{ 0.10 }; + packageDeploymentProgress.Progress = c_progressPercentageStartOfInstalls; + progress(packageDeploymentProgress); + auto packageSetItems{ packageSet.Items() }; + const double progressIncrementPerPackageSetItem{ (1.0 - c_progressPercentageStartOfInstalls) / packageSetItems.Size() }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) + { + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; + const auto packageFamilyName{ packageSetItem.PackageFamilyName() }; + try + { + const auto progressBeforePackage{ packageDeploymentProgress.Progress }; + error = LOG_IF_FAILED_MSG(ResetPackageByFamilyName(packageFamilyName, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:", + extendedError, packageFamilyName.c_str()); + const auto progressAfterPackage{ progressBeforePackage + progressIncrementPerPackageSetItem }; + if (packageDeploymentProgress.Progress < progressAfterPackage) + { + packageDeploymentProgress.Progress = progressAfterPackage; + progress(packageDeploymentProgress); + } + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageFamilyName.c_str(), packageUri ? packageUri.ToString().c_str() : L""); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageSet.Id()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::RepairPackageAsync(hstring package) { - //TODO Awaiting FrameworkUdk update with Uup_SRFindPackageFullNamesByUupProductId() - throw hresult_not_implemented(); + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::RepairPackage)); + + if (VerifyPackageFamilyName(package.c_str()) == ERROR_SUCCESS) + { + return RepairPackageByFamilyNameAsync(package); + } + else if (VerifyPackageFullName(package.c_str()) == ERROR_SUCCESS) + { + return RepairPackageByFullNameAsync(package); + } + + const winrt::Windows::Foundation::Uri packageUri{ package }; + const auto packageAbsoluteUri{ packageUri.AbsoluteUri() }; + if (!packageAbsoluteUri.empty()) + { + return RepairPackageByUriAsync(packageUri); + } + THROW_HR_MSG(E_INVALIDARG, "%ls", package.c_str()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::RepairPackageByUriAsync(winrt::Windows::Foundation::Uri packageUri) { - //TODO Awaiting FrameworkUdk update with PackageManagement_RepairPackageAsync() - throw hresult_not_implemented(); + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::RepairPackage)); + + // Currently supported URI schemes: ms-uup + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup)); + + auto logTelemetry{ PackageManagementTelemetry::RepairPackageByUriAsync::Start(packageUri.ToString()) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + // Allow to register the progress and complete handler + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + // Create a PackageSet of (just) package family names for the URI + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + packageSet.Id(packageUri.ToString()); + const auto packageFullNames{ GetPackageFullNamesFromUupProductUriIfMsUup(packageUri) }; + if (packageFullNames.empty()) + { + const auto hr{ HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND) }; + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, GUID{}, hr, HRESULT_FROM_WIN32(ERROR_NOT_FOUND), winrt::impl::message_from_hresult(hr)); + } + + packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; + const double c_progressPercentageStartOfInstalls{ 0.10 }; + packageDeploymentProgress.Progress = c_progressPercentageStartOfInstalls; + progress(packageDeploymentProgress); + const double progressIncrementPerPackageSetItem{ (1.0 - c_progressPercentageStartOfInstalls) / packageFullNames.size() }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + const auto packageUriAsString{ packageUri.ToString() }; + for (PCWSTR packageFullName : packageFullNames) + { + try + { + const auto progressBeforePackage{ packageDeploymentProgress.Progress }; + error = LOG_IF_FAILED_MSG(RepairPackageByFullName(packageFullName, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFullName:%ls PackageUri:%ls", + extendedError, packageFullName, packageUriAsString.c_str()); + const auto progressAfterPackage{ progressBeforePackage + progressIncrementPerPackageSetItem }; + if (packageDeploymentProgress.Progress < progressAfterPackage) + { + packageDeploymentProgress.Progress = progressAfterPackage; + progress(packageDeploymentProgress); + } + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls PackageFamilyName:%ls PackageUri:%ls", + extendedError, packageFullName, packageUriAsString.c_str()); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageSet.Id()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::RepairPackageSetAsync(winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet) { - //TODO Awaiting FrameworkUdk update with PackageManagement_RepairPackageAsync() - throw hresult_not_implemented(); + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::RepairPackage)); + + auto logTelemetry{ PackageManagementTelemetry::RepairPackageSetAsync::Start(packageSet.Id()) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + // Allow to register the progress and complete handler + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + // Check parameter(s) + Validate_PackageUriIsOptional(packageSet); + + packageDeploymentProgress.Status = PackageDeploymentProgressStatus::InProgress; + const double c_progressPercentageStartOfInstalls{ 0.10 }; + packageDeploymentProgress.Progress = c_progressPercentageStartOfInstalls; + progress(packageDeploymentProgress); + auto packageSetItems{ packageSet.Items() }; + const double progressIncrementPerPackageSetItem{ (1.0 - c_progressPercentageStartOfInstalls) / packageSetItems.Size() }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) + { + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; + const auto packageFamilyName{ packageSetItem.PackageFamilyName() }; + try + { + const auto progressBeforePackage{ packageDeploymentProgress.Progress }; + error = LOG_IF_FAILED_MSG(RepairPackageByFamilyName(packageFamilyName, packageDeploymentProgress, progress, progressIncrementPerPackageSetItem, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:", + extendedError, packageFamilyName.c_str()); + const auto progressAfterPackage{ progressBeforePackage + progressIncrementPerPackageSetItem }; + if (packageDeploymentProgress.Progress < progressAfterPackage) + { + packageDeploymentProgress.Progress = progressAfterPackage; + progress(packageDeploymentProgress); + } + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls", extendedError, packageFamilyName.c_str(), packageUri ? packageUri.ToString().c_str() : L""); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageSet.Id()); + } + bool PackageDeploymentManager::IsPackageProvisioned(hstring const& package) + { + if (VerifyPackageFamilyName(package.c_str()) == ERROR_SUCCESS) + { + return IsProvisionedByPackageFamilyName(package); + } + + const winrt::Windows::Foundation::Uri packageUri{ package }; + const auto packageAbsoluteUri{ packageUri.AbsoluteUri() }; + if (!packageAbsoluteUri.empty()) + { + return IsPackageProvisionedByUri(packageUri); + } + THROW_HR_MSG(E_INVALIDARG, "%ls", package.c_str()); + } + bool PackageDeploymentManager::IsPackageProvisionedByUri(winrt::Windows::Foundation::Uri const& packageUri) + { + const auto packageFullNames{ GetPackageFullNamesFromUupProductUriIfMsUup(packageUri) }; + if (!packageFullNames) + { + // Currently supported URI schemes: ms-uup + if (!IsUriScheme_MsUup(packageUri)) + { + THROW_HR_IF(E_NOTIMPL, !IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup)); + } + + // Provisioned UUP Products always have 1+ package so no packages found means not provisioned + return false; + } + + for (PCWSTR packageFullName : packageFullNames) + { + // Provisioning is based on package family but we only know package full names for the URI + // Use the package's family name for the actual provisioning check + const auto packageFamilyName{ ::AppModel::Identity::ToPackageFamilyName(packageFullName) }; + if (!IsProvisionedByPackageFamilyName(packageFamilyName)) + { + return false; + } + } + return true; + } + bool PackageDeploymentManager::IsPackageSetProvisioned(winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) + { + Validate_PackageUriIsOptional(packageSet); + + const auto provisionedPackages{ m_packageManager.FindProvisionedPackages() }; + for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSet.Items()) + { + if (!IsProvisioned(provisionedPackages, packageSetItem)) + { + return false; + } + } + return true; } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::ProvisionPackageAsync(hstring package, winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options) { - //TODO Awaiting FrameworkUdk update with Uup_SRFindPackageFullNamesByUupProductId() - throw hresult_not_implemented(); + if (VerifyPackageFamilyName(package.c_str()) == ERROR_SUCCESS) + { + return ProvisionPackageByFamilyNameAsync(package, options); + } + + const winrt::Windows::Foundation::Uri packageUri{ package }; + const auto packageAbsoluteUri{ packageUri.AbsoluteUri() }; + if (!packageAbsoluteUri.empty()) + { + return ProvisionPackageByUriAsync(packageUri, options); + } + THROW_HR_MSG(E_INVALIDARG, "%ls", package.c_str()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::ProvisionPackageByUriAsync(winrt::Windows::Foundation::Uri packageUri, winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options) @@ -638,8 +1543,18 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::DeprovisionPackageAsync(hstring package) { - //TODO Awaiting FrameworkUdk update with Uup_SRFindPackageFullNamesByUupProductId() - throw hresult_not_implemented(); + if (VerifyPackageFamilyName(package.c_str()) == ERROR_SUCCESS) + { + return DeprovisionPackageByFamilyNameAsync(package); + } + + const winrt::Windows::Foundation::Uri packageUri{ package }; + const auto packageAbsoluteUri{ packageUri.AbsoluteUri() }; + if (!packageAbsoluteUri.empty()) + { + return DeprovisionPackageByUriAsync(packageUri); + } + THROW_HR_MSG(E_INVALIDARG, "%ls", package.c_str()); } winrt::Windows::Foundation::IAsyncOperationWithProgress PackageDeploymentManager::DeprovisionPackageByUriAsync(winrt::Windows::Foundation::Uri packageUri) @@ -653,14 +1568,21 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation //TODO Awaiting FrameworkUdk update with Uup_SRFindPackageFullNamesByUupProductId() throw hresult_not_implemented(); } - bool PackageDeploymentManager::IsPackageRegistrationPending(hstring const& packageFamilyName) + bool PackageDeploymentManager::IsPackageRegistrationPending(hstring const& packageFullName) { - return IsPackageRegistrationPendingForUser(hstring{}, packageFamilyName); + return IsPackageRegistrationPendingForUser(nullptr, packageFullName.c_str()); } - bool PackageDeploymentManager::IsPackageRegistrationPendingForUser(hstring const& userSecurityId, hstring const& packageFamilyName) + bool PackageDeploymentManager::IsPackageRegistrationPendingForUser(hstring const& userSecurityId, hstring const& packageFullName) { - //TODO Awaiting FrameworkUdk update with PackageManagement_IsPackageRegistrationPending() - throw hresult_not_implemented(); + wil::unique_any_psid userSid{ ::Security::User::StringToSid(userSecurityId.c_str()) }; + return IsPackageRegistrationPendingForUser(userSid.get(), packageFullName.c_str()); + } + + bool PackageDeploymentManager::IsPackageRegistrationPendingForUser(PSID userSid, PCWSTR packageFullName) + { + BOOL isPending{}; + THROW_IF_FAILED(::PackageManagement_IsPackageRegistrationPending(userSid, packageFullName, &isPending)); + return !!isPending; } winrt::Windows::Foundation::IAsyncOperationWithProgress @@ -691,9 +1613,6 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation PackageDeploymentProgressStatus::Queued, 0} }; progress(packageDeploymentProgress); - // Check parameter(s) - //TODO Validate(packageSet); - HRESULT error{}; HRESULT extendedError{}; winrt::hstring errorText; @@ -741,9 +1660,6 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation PackageDeploymentProgressStatus::Queued, 0} }; progress(packageDeploymentProgress); - // Check parameter(s) - //TODO Validate(packageSet); - winrt::Windows::Management::Deployment::RegisterPackageOptions registerOptions{ ToOptions(options) }; HRESULT error{}; HRESULT extendedError{}; @@ -771,9 +1687,56 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation logTelemetry.Stop(packageFullName); } + winrt::hstring PackageDeploymentManager::GetUupProductIdIfMsUup(winrt::Windows::Foundation::Uri const& uri) const + { + if (IsUriScheme_MsUup(uri)) + { + // Support legacy behavior (for now) + // + // ms-uup://Product/id + const auto uriAsString{ uri.ToString() }; + const std::wstring_view legacyPrefix{ L"ms-uup://Product/" }; + if ((uriAsString.size() > legacyPrefix.length()) && + StringEqualsNoCase(uriAsString.c_str(), legacyPrefix.length(), legacyPrefix.data(), legacyPrefix.length())) + { + return uriAsString.begin() + legacyPrefix.length(); + } + + // ms-uup:///Product/id + if (uri.Host().empty()) + { + const auto path{ uri.Path() }; + const std::wstring_view c_product{ L"/Product/" }; + if ((path.size() > c_product.length()) && + StringEqualsNoCase(path.c_str(), c_product.length(), c_product.data(), c_product.length())) + { + return path.begin() + c_product.length(); + } + } + } + return winrt::hstring{}; + } + + wil::unique_cotaskmem_array_ptr PackageDeploymentManager::GetPackageFullNamesFromUupProductUriIfMsUup(winrt::Windows::Foundation::Uri const& uri) const + { + wil::unique_cotaskmem_array_ptr packageFullNames; + + const auto schemeName{ uri.SchemeName() }; + const auto uupProductId{ GetUupProductIdIfMsUup(uri) }; + if (!uupProductId.empty()) + { + THROW_IF_FAILED_MSG(Uup_SRFindPackageFullNamesByUupProductId(uupProductId.c_str(), packageFullNames.size_address(), packageFullNames.addressof()), "%s", uupProductId.c_str()); + } + return packageFullNames; + } + bool PackageDeploymentManager::IsReadyByPackageFullName(hstring const& packageFullName) { - return ::Microsoft::Windows::ApplicationModel::PackageDeploymentResolver::FindAny(m_packageManager, packageFullName); + const auto packageIdentity{ ::AppModel::Identity::PackageIdentity::FromPackageFullName(packageFullName.c_str()) }; + const winrt::hstring packageFamilyName{ packageIdentity.PackageFamilyName().c_str()}; + const AppModel::Identity::PackageVersion minVersion{ packageIdentity.Version() }; + const auto processorArchitectureFilter{ ToPackageDependencyProcessorArchitectures(packageIdentity.Architecture()) }; + return ::Microsoft::Windows::ApplicationModel::PackageDeploymentResolver::FindAny(m_packageManager, packageFamilyName, minVersion, processorArchitectureFilter); } bool PackageDeploymentManager::IsReady(winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem) @@ -783,31 +1746,124 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation return ::Microsoft::Windows::ApplicationModel::PackageDeploymentResolver::FindAny(m_packageManager, packageSetItem.PackageFamilyName(), minVersion, processorArchitectureFilter); } - void PackageDeploymentManager::Validate(winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) const + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus PackageDeploymentManager::IsReadyOrNewerAvailableByPackageFullName(hstring const& packageFullName) + { + const auto packageIdentity{ ::AppModel::Identity::PackageIdentity::FromPackageFullName(packageFullName.c_str()) }; + const auto packageFamilyName{ packageIdentity.PackageFamilyName() }; + const auto minVersion{ packageIdentity.Version().Version }; + const auto architectureType{ ToArchitectureType(packageIdentity.Architecture()) }; + BOOL isRegistered{}; + BOOL isNewerAvailable{}; + THROW_IF_FAILED_MSG(PackageManagement_IsRegisteredOrNewerAvailable(nullptr, packageFamilyName.c_str(), minVersion, architectureType, &isRegistered, &isNewerAvailable), "%s", packageFullName.c_str()); + if (!isRegistered) + { + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady; + } + else if (!isNewerAvailable) + { + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready; + } + else + { + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable; + } + } + + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus PackageDeploymentManager::IsReadyOrNewerAvailable(winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem) + { + const auto packageFamilyName{ packageSetItem.PackageFamilyName().c_str() }; + const AppModel::Identity::PackageVersion minVersion{ packageSetItem.MinVersion() }; + const auto architectureType{ ToArchitectureType(packageSetItem.ProcessorArchitectureFilter()) }; + BOOL isRegistered{}; + BOOL isNewerAvailable{}; + THROW_IF_FAILED_MSG(PackageManagement_IsRegisteredOrNewerAvailable(nullptr, packageFamilyName, minVersion.Version, architectureType, &isRegistered, &isNewerAvailable), "%ls", packageFamilyName); + if (!isRegistered) + { + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady; + } + else if (!isNewerAvailable) + { + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready; + } + else + { + return winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable; + } + } + + void PackageDeploymentManager::Validate_PackageUriIsRequired( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) const + { + return _Validate(packageSet, true); + } + + void PackageDeploymentManager::Validate_PackageUriIsOptional( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) const + { + return _Validate(packageSet, false); + } + + void PackageDeploymentManager::_Validate( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet, + const bool packageUriIsRequired) const { THROW_HR_IF(E_INVALIDARG, packageSet.Id().empty()); const auto& packageSetItems{ packageSet.Items() }; THROW_HR_IF(E_INVALIDARG, packageSetItems.Size() == 0); for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) { - Validate(packageSetItem); + _Validate(packageSet, packageSetItem, packageUriIsRequired); } } - void PackageDeploymentManager::Validate(winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem) const + void PackageDeploymentManager::_Validate( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet, + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, + const bool packageUriIsRequired) const { const auto packageFamilyName{ packageSetItem.PackageFamilyName() }; THROW_IF_WIN32_ERROR_MSG(VerifyPackageFamilyName(packageFamilyName.c_str()), "PackageFamilyName:%ls", packageFamilyName.c_str()); - const auto packageUri{ packageSetItem.PackageUri() }; - THROW_HR_IF_NULL_MSG(E_INVALIDARG, packageUri, "PackageUri:"); + if (packageUriIsRequired) + { + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; + THROW_HR_IF_NULL_MSG(E_INVALIDARG, packageUri, "PackageUri:"); + } + } + + void PackageDeploymentManager::Validate_PackageUriOrFamilyName( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) const + { + THROW_HR_IF(E_INVALIDARG, packageSet.Id().empty()); + const auto& packageSetItems{ packageSet.Items() }; + THROW_HR_IF(E_INVALIDARG, packageSetItems.Size() == 0); + for (const winrt::Microsoft::Windows::Management::Deployment::PackageSetItem& packageSetItem : packageSetItems) + { + Validate_PackageUriOrFamilyName(packageSet, packageSetItem); + } + } + + void PackageDeploymentManager::Validate_PackageUriOrFamilyName( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet, + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem) const + { + const auto packageUri{ GetEffectivePackageUri(packageSet, packageSetItem) }; + if (packageUri) + { + return; + } + + const auto packageFamilyName{ packageSetItem.PackageFamilyName() }; + THROW_IF_WIN32_ERROR_MSG(VerifyPackageFamilyName(packageFamilyName.c_str()), "PackageUri: PackageFamilyName:%ls", packageFamilyName.c_str()); } HRESULT PackageDeploymentManager::EnsureReadyAsync( + winrt::Windows::Foundation::Uri const& packageUri, winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions const& options, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackageSetItem, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId) @@ -821,16 +1877,20 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation return S_OK; } - auto packageUri{ packageSetItem.PackageUri() }; winrt::Windows::Management::Deployment::AddPackageOptions addOptions{ ToOptions(options) }; + const auto progressBefore{ packageDeploymentProgress.Progress }; auto deploymentOperation{ m_packageManager.AddPackageByUriAsync(packageUri, addOptions) }; deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< winrt::Windows::Management::Deployment::DeploymentResult, winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) { - packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage); - progress(packageDeploymentProgress); + const auto progressAfter{ progressBefore + PercentageToProgress(progressInfo.percentage, progressMaxPerPackageSetItem) }; + if (packageDeploymentProgress.Progress < progressAfter) + { + packageDeploymentProgress.Progress = progressAfter; + progress(packageDeploymentProgress); + } }); deploymentOperation.get(); try @@ -845,7 +1905,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation { RETURN_IF_FAILED_MSG(error, "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls : %ls", - extendedError, packageSetItem.PackageFamilyName().c_str(), packageSetItem.PackageUri().ToString().c_str(), errorText.c_str()); + extendedError, packageSetItem.PackageFamilyName().c_str(), packageUri.ToString().c_str(), errorText.c_str()); // Status=Error but SUCCEEDED(error) == This.Should.Never.Happen. FAIL_FAST_HR_MSG(E_UNEXPECTED, @@ -864,16 +1924,17 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; THROW_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageUri:%ls : %ls", - extendedError, packageSetItem.PackageFamilyName().c_str(), packageSetItem.PackageUri().ToString().c_str(), errorText.c_str()); + extendedError, packageSetItem.PackageFamilyName().c_str(), packageUri.ToString().c_str(), errorText.c_str()); } return S_OK; } HRESULT PackageDeploymentManager::AddPackage( - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, + winrt::Windows::Foundation::Uri const& packageUri, winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions const& options, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackageSetItem, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId) @@ -882,9 +1943,8 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation errorText.clear(); activityId = winrt::guid{}; - auto packageUri{ packageSetItem.PackageUri() }; winrt::Windows::Management::Deployment::AddPackageOptions addOptions{ ToOptions(options) }; - RETURN_IF_FAILED(AddPackage(packageUri, addOptions, packageDeploymentProgress, progress, extendedError, errorText, activityId)); + RETURN_IF_FAILED(AddPackage(packageUri, addOptions, packageDeploymentProgress, progress, progressMaxPerPackageSetItem, extendedError, errorText, activityId)); return S_OK; } @@ -893,6 +1953,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::AddPackageOptions const& addOptions, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackage, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId) @@ -901,14 +1962,19 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation errorText.clear(); activityId = winrt::guid{}; + const auto progressBefore{ packageDeploymentProgress.Progress }; auto deploymentOperation{ m_packageManager.AddPackageByUriAsync(packageUri, addOptions) }; deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< winrt::Windows::Management::Deployment::DeploymentResult, winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) { - packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage); - progress(packageDeploymentProgress); + const auto progressAfter{ progressBefore + PercentageToProgress(progressInfo.percentage, progressMaxPerPackage) }; + if (packageDeploymentProgress.Progress < progressAfter) + { + packageDeploymentProgress.Progress = progressAfter; + progress(packageDeploymentProgress); + } }); deploymentOperation.get(); try @@ -957,10 +2023,12 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation return S_OK; } - HRESULT PackageDeploymentManager::StagePackage(winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, + HRESULT PackageDeploymentManager::StagePackage( + winrt::Windows::Foundation::Uri const& packageUri, winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions const& options, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackageSetItem, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId) @@ -969,9 +2037,8 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation errorText.clear(); activityId = winrt::guid{}; - auto packageUri{ packageSetItem.PackageUri() }; winrt::Windows::Management::Deployment::StagePackageOptions stageOptions{ ToOptions(options) }; - RETURN_IF_FAILED(StagePackage(packageUri, stageOptions, packageDeploymentProgress, progress, extendedError, errorText, activityId)); + RETURN_IF_FAILED(StagePackage(packageUri, stageOptions, packageDeploymentProgress, progress, progressMaxPerPackageSetItem, extendedError, errorText, activityId)); return S_OK; } @@ -980,6 +2047,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::StagePackageOptions const& stageOptions, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackage, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId) @@ -988,14 +2056,19 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation errorText.clear(); activityId = winrt::guid{}; + const auto progressBefore{ packageDeploymentProgress.Progress }; auto deploymentOperation{ m_packageManager.StagePackageByUriAsync(packageUri, stageOptions) }; deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< winrt::Windows::Management::Deployment::DeploymentResult, winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) { - packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage); - progress(packageDeploymentProgress); + const auto progressAfter{ progressBefore + PercentageToProgress(progressInfo.percentage, progressMaxPerPackage) }; + if (packageDeploymentProgress.Progress < progressAfter) + { + packageDeploymentProgress.Progress = progressAfter; + progress(packageDeploymentProgress); + } }); deploymentOperation.get(); try @@ -1045,10 +2118,11 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation } HRESULT PackageDeploymentManager::RegisterPackage( - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, + winrt::Windows::Foundation::Uri const& packageUri, winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions const& options, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackageSetItem, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId) @@ -1057,9 +2131,8 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation errorText.clear(); activityId = winrt::guid{}; - auto packageUri{ packageSetItem.PackageUri() }; winrt::Windows::Management::Deployment::RegisterPackageOptions registerOptions{ ToOptions(options) }; - RETURN_IF_FAILED(RegisterPackage(packageUri, registerOptions, packageDeploymentProgress, progress, extendedError, errorText, activityId)); + RETURN_IF_FAILED(RegisterPackage(packageUri, registerOptions, packageDeploymentProgress, progress, progressMaxPerPackageSetItem, extendedError, errorText, activityId)); return S_OK; } @@ -1068,6 +2141,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::RegisterPackageOptions const& registerOptions, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackage, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId) @@ -1076,14 +2150,19 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation errorText.clear(); activityId = winrt::guid{}; + const auto progressBefore{ packageDeploymentProgress.Progress }; auto deploymentOperation{ m_packageManager.RegisterPackageByUriAsync(packageUri, registerOptions) }; deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< winrt::Windows::Management::Deployment::DeploymentResult, winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) { - packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage); - progress(packageDeploymentProgress); + const auto progressAfter{ progressBefore + PercentageToProgress(progressInfo.percentage, progressMaxPerPackage) }; + if (packageDeploymentProgress.Progress < progressAfter) + { + packageDeploymentProgress.Progress = progressAfter; + progress(packageDeploymentProgress); + } }); deploymentOperation.get(); try @@ -1154,7 +2233,8 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) { - packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage); + const double progressMaxPerPackageFamily{ 1.0 }; + packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage, progressMaxPerPackageFamily); progress(packageDeploymentProgress); }); deploymentOperation.get(); @@ -1225,7 +2305,8 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) { - packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage); + const double progressMaxPerPackage{ 1.0 }; + packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage, progressMaxPerPackage); progress(packageDeploymentProgress); }); deploymentOperation.get(); @@ -1275,6 +2356,907 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation return S_OK; } + HRESULT PackageDeploymentManager::RemovePackage( + winrt::Windows::Foundation::Uri const& packageUri, + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageSetItem, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + winrt::Windows::Management::Deployment::RemovalOptions removeOptions{ ToOptions(options) }; + RETURN_IF_FAILED(RemovePackage(packageUri, removeOptions, packageDeploymentProgress, progress, progressMaxPerPackageSetItem, extendedError, errorText, activityId)); + return S_OK; + } + + HRESULT PackageDeploymentManager::RemovePackage( + winrt::Windows::Foundation::Uri const& /*packageUri*/, + winrt::Windows::Management::Deployment::RemovalOptions const& /*removeOptions*/, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& /*packageDeploymentProgress*/, + wistd::function /*progress*/, + const double /*progressMaxPerPackage*/, + HRESULT& /*extendedError*/, + winrt::hstring& /*errorText*/, + winrt::guid& /*activityId*/) + { + //TODO Awaiting Platform SDK defining RemovePackageOptions + RETURN_HR(E_NOTIMPL); + } + + HRESULT PackageDeploymentManager::RemovePackageByFullName( + winrt::hstring const& packageFullName, + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options, + winrt::Windows::Management::Deployment::RemovalOptions const& removeOptions, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackage, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + auto deploymentOperation{ m_packageManager.RemovePackageAsync(packageFullName, removeOptions) }; + deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< + winrt::Windows::Management::Deployment::DeploymentResult, + winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, + winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) + { + packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage, progressMaxPerPackage); + progress(packageDeploymentProgress); + }); + deploymentOperation.get(); + try + { + const auto deploymentResult{ deploymentOperation.GetResults() }; + const HRESULT error{ static_cast(deploymentOperation.ErrorCode()) }; + extendedError = deploymentResult.ExtendedErrorCode(); + errorText = deploymentResult.ErrorText(); + activityId = deploymentResult.ActivityId(); + const auto status{ deploymentOperation.Status() }; + if (status == winrt::Windows::Foundation::AsyncStatus::Error) + { + if (error == HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)) + { + if (!options.FailIfNotFound()) + { + // Package not installed. Success! + (void)LOG_HR_MSG(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + extendedError = error; + errorText.clear(); + return S_OK; + } + } + RETURN_IF_FAILED_MSG(error, + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + + // Status=Error but SUCCEEDED(error) == This.Should.Never.Happen. + FAIL_FAST_HR_MSG(E_UNEXPECTED, + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + } + else if (status == winrt::Windows::Foundation::AsyncStatus::Canceled) + { + RETURN_WIN32_MSG(ERROR_CANCELLED, "%ls", packageFullName.c_str()); + } + FAIL_FAST_HR_IF_MSG(E_UNEXPECTED, status != winrt::Windows::Foundation::AsyncStatus::Completed, + "Status:%d PackageFullName:%ls : %ls", static_cast(status), packageFullName.c_str(), errorText.c_str()); + } + catch (...) + { + auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + THROW_HR_MSG(exception.code(), + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + } + return S_OK; + } + + HRESULT PackageDeploymentManager::RemovePackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageFamily, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + winrt::Windows::Management::Deployment::RemovalOptions removeOptions{ ToOptions(options) }; + RETURN_IF_FAILED(RemovePackageByFamilyName(packageFamilyName, options, removeOptions, packageDeploymentProgress, progress, progressMaxPerPackageFamily, extendedError, errorText, activityId)); + return S_OK; + } + + HRESULT PackageDeploymentManager::RemovePackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options, + winrt::Windows::Management::Deployment::RemovalOptions const& removeOptions, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageFamily, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + // Resource packages are automagically removed when their associated Main|Optional package is removed + // Bundle packages are automagically removed when their associated Main|Optional package is removed + const auto packageTypes{ winrt::Windows::Management::Deployment::PackageTypes::Framework | + winrt::Windows::Management::Deployment::PackageTypes::Main | + winrt::Windows::Management::Deployment::PackageTypes::Optional }; + auto packages{ + ::Security::IntegrityLevel::IsElevated() ? + m_packageManager.FindPackagesWithPackageTypes(packageFamilyName, packageTypes) : + m_packageManager.FindPackagesForUserWithPackageTypes(winrt::hstring(), packageFamilyName, packageTypes) }; + const size_t packagesCount{ packages ? Count(packages) : 0 }; + if (packagesCount > 0) + { + const auto progressMaxPerPackage{ progressMaxPerPackageFamily / packagesCount }; + for (const winrt::Windows::ApplicationModel::Package& package : packages) + { + const auto packageFullName{ package.Id().FullName() }; + try + { + RETURN_IF_FAILED_MSG(RemovePackageByFullName(packageFullName, options, removeOptions, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFamilyName:%ls PackageFullName:%ls", + extendedError, packageFamilyName.c_str(), packageFullName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + RETURN_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageFullName:%ls", extendedError, packageFamilyName.c_str(), packageFullName.c_str()); + } + } + } + else if (options.FailIfNotFound()) + { + extendedError = HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND); + errorText = winrt::impl::message_from_hresult(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + RETURN_HR_MSG(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), "PackageFamilyName:%ls", packageFamilyName.c_str()); + } + return S_OK; + } + + winrt::Windows::Foundation::IAsyncOperationWithProgress + PackageDeploymentManager::ResetPackageByFamilyNameAsync(hstring packageFamilyName) + { + auto logTelemetry{ PackageManagementTelemetry::ResetPackageAsync::Start(packageFamilyName) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + const double progressMaxPerPackageFamily{ 1.0 }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(ResetPackageByFamilyName(packageFamilyName, packageDeploymentProgress, progress, progressMaxPerPackageFamily, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageUri:%ls", + extendedError, packageFamilyName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageFamilyName.c_str()); + } + if (FAILED(error)) + { + if (error == HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED) && (extendedError == HRESULT_FROM_WIN32(ERROR_NOT_FOUND))) + { + error = HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND); + } + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageFamilyName); + } + + HRESULT PackageDeploymentManager::ResetPackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageFamily, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + // Resource packages are automagically reseted when their associated Main|Optional package is reseted + // Bundle packages are automagically reseted when their associated Main|Optional package is reseted + const auto packageTypes{ winrt::Windows::Management::Deployment::PackageTypes::Framework | + winrt::Windows::Management::Deployment::PackageTypes::Main | + winrt::Windows::Management::Deployment::PackageTypes::Optional }; +#if defined(TODO_Reset_DoesElevatedMatter) + auto packages{ + ::Security::IntegrityLevel::IsElevated() ? + m_packageManager.FindPackagesWithPackageTypes(packageFamilyName, packageTypes) : + m_packageManager.FindPackagesForUserWithPackageTypes(winrt::hstring(), packageFamilyName, packageTypes) }; +#else + auto packages{ m_packageManager.FindPackagesForUserWithPackageTypes(winrt::hstring(), packageFamilyName, packageTypes) }; +#endif + const size_t packagesCount{ packages ? Count(packages) : 0 }; + if (packagesCount == 0) + { + extendedError = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); + errorText = winrt::impl::message_from_hresult(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + } + const auto progressMaxPerPackage{ progressMaxPerPackageFamily / packagesCount }; + for (const winrt::Windows::ApplicationModel::Package& package : packages) + { + const auto packageFullName{ package.Id().FullName() }; + HRESULT error{}; + try + { + error = LOG_IF_FAILED_MSG(ResetPackageByFullName(packageFullName, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFamilyName:%ls PackageFullName:%ls", + extendedError, packageFamilyName.c_str(), packageFullName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageFullName:%ls", extendedError, packageFamilyName.c_str(), packageFullName.c_str()); + } + if (FAILED(error)) + { + if (error == HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED) && (extendedError == HRESULT_FROM_WIN32(ERROR_NOT_FOUND))) + { + error = HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND); + } + RETURN_HR(error); + } + } + return S_OK; + } + + winrt::Windows::Foundation::IAsyncOperationWithProgress + PackageDeploymentManager::ResetPackageByFullNameAsync(hstring packageFullName) + { + auto logTelemetry{ PackageManagementTelemetry::ResetPackageAsync::Start(packageFullName) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + const double progressMaxPerPackage{ 1.0 }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(ResetPackageByFullName(packageFullName, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageUri:%ls", + extendedError, packageFullName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageFullName.c_str()); + } + if (FAILED(error)) + { + if (error == HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED) && (extendedError == HRESULT_FROM_WIN32(ERROR_NOT_FOUND))) + { + error = HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND); + } + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageFullName); + } + + HRESULT PackageDeploymentManager::ResetPackageByFullName( + winrt::hstring const& packageFullName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackage, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + // Reset only works on packages if they're registered to the caller. + // But PackageManagement_ResetPackageAsync2() = Remove + StageUserData + Register + // which succeeds if the package isn't initially registered for the caller. + // Ensure we're only working on packages if they're registered to the caller + if (!::Microsoft::Windows::ApplicationModel::PackageDeploymentResolver::IsRegistered(m_packageManager, packageFullName)) + { + extendedError = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); + errorText = winrt::impl::message_from_hresult(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + } + + ::ABI::Windows::Foundation::IAsyncOperationWithProgress<::ABI::Windows::Management::Deployment::DeploymentResult*, ::ABI::Windows::Management::Deployment::DeploymentProgress>* abiDeploymentOperation{}; + RETURN_IF_FAILED(PackageManagement_ResetPackageAsync2(packageFullName.c_str(), &abiDeploymentOperation)); + winrt::Windows::Foundation::IAsyncOperationWithProgress deploymentOperation; + winrt::copy_from_abi(deploymentOperation, abiDeploymentOperation); + deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< + winrt::Windows::Management::Deployment::DeploymentResult, + winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, + winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) + { + packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage, progressMaxPerPackage); + progress(packageDeploymentProgress); + }); + deploymentOperation.get(); + try + { + const auto deploymentResult{ deploymentOperation.GetResults() }; + const HRESULT error{ static_cast(deploymentOperation.ErrorCode()) }; + extendedError = deploymentResult.ExtendedErrorCode(); + errorText = deploymentResult.ErrorText(); + activityId = deploymentResult.ActivityId(); + const auto status{ deploymentOperation.Status() }; + if (status == winrt::Windows::Foundation::AsyncStatus::Error) + { + RETURN_IF_FAILED_MSG(error, + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + + // Status=Error but SUCCEEDED(error) == This.Should.Never.Happen. + FAIL_FAST_HR_MSG(E_UNEXPECTED, + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + } + else if (status == winrt::Windows::Foundation::AsyncStatus::Canceled) + { + RETURN_WIN32_MSG(ERROR_CANCELLED, "%ls", packageFullName.c_str()); + } + FAIL_FAST_HR_IF_MSG(E_UNEXPECTED, status != winrt::Windows::Foundation::AsyncStatus::Completed, + "Status:%d PackageFullName:%ls : %ls", static_cast(status), packageFullName.c_str(), errorText.c_str()); + } + catch (...) + { + auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + THROW_HR_MSG(exception.code(), + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + } + return S_OK; + } + + winrt::Windows::Foundation::IAsyncOperationWithProgress + PackageDeploymentManager::RepairPackageByFamilyNameAsync(hstring packageFamilyName) + { + auto logTelemetry{ PackageManagementTelemetry::RepairPackageAsync::Start(packageFamilyName) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + const double progressMaxPerPackageFamily{ 1.0 }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(RepairPackageByFamilyName(packageFamilyName, packageDeploymentProgress, progress, progressMaxPerPackageFamily, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageUri:%ls", + extendedError, packageFamilyName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageFamilyName.c_str()); + } + if (FAILED(error)) + { + if (error == HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED) && (extendedError == HRESULT_FROM_WIN32(ERROR_NOT_FOUND))) + { + error = HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND); + } + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageFamilyName); + } + + HRESULT PackageDeploymentManager::RepairPackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageFamily, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + // Resource packages are automagically repaired when their associated Main|Optional package is repaired + // Bundle packages are automagically repaired when their associated Main|Optional package is repaired + const auto packageTypes{ winrt::Windows::Management::Deployment::PackageTypes::Framework | + winrt::Windows::Management::Deployment::PackageTypes::Main | + winrt::Windows::Management::Deployment::PackageTypes::Optional }; +#if defined(TODO_Reset_DoesElevatedMatter) + auto packages{ + ::Security::IntegrityLevel::IsElevated() ? + m_packageManager.FindPackagesWithPackageTypes(packageFamilyName, packageTypes) : + m_packageManager.FindPackagesForUserWithPackageTypes(winrt::hstring(), packageFamilyName, packageTypes) }; +#else + auto packages{ m_packageManager.FindPackagesForUserWithPackageTypes(winrt::hstring(), packageFamilyName, packageTypes) }; +#endif + const size_t packagesCount{ packages ? Count(packages) : 0 }; + if (packagesCount == 0) + { + extendedError = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); + errorText = winrt::impl::message_from_hresult(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + } + const auto progressMaxPerPackage{ progressMaxPerPackageFamily / packagesCount }; + for (const winrt::Windows::ApplicationModel::Package& package : packages) + { + const auto packageFullName{ package.Id().FullName() }; + HRESULT error{}; + try + { + error = LOG_IF_FAILED_MSG(RepairPackageByFullName(packageFullName, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageFamilyName:%ls PackageFullName:%ls", + extendedError, packageFamilyName.c_str(), packageFullName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageFamilyName:%ls PackageFullName:%ls", extendedError, packageFamilyName.c_str(), packageFullName.c_str()); + } + if (FAILED(error)) + { + if (error == HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED) && (extendedError == HRESULT_FROM_WIN32(ERROR_NOT_FOUND))) + { + error = HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND); + } + RETURN_HR(error); + } + } + return S_OK; + } + + winrt::Windows::Foundation::IAsyncOperationWithProgress + PackageDeploymentManager::RepairPackageByFullNameAsync(hstring packageFullName) + { + auto logTelemetry{ PackageManagementTelemetry::RepairPackageAsync::Start(packageFullName) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + const double progressMaxPerPackage{ 1.0 }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(RepairPackageByFullName(packageFullName, packageDeploymentProgress, progress, progressMaxPerPackage, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageUri:%ls", + extendedError, packageFullName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageFullName.c_str()); + } + if (FAILED(error)) + { + if (error == HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED) && (extendedError == HRESULT_FROM_WIN32(ERROR_NOT_FOUND))) + { + error = HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND); + } + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageFullName); + } + + HRESULT PackageDeploymentManager::RepairPackageByFullName( + winrt::hstring const& packageFullName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackage, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + // Repair only works on packages if they're registered to the caller. + // But PackageManagement_RepairPackageAsync2() = Register + // which succeeds if the package isn't initially registered for the caller. + // Ensure we're only working on packages if they're registered to the caller + if (!::Microsoft::Windows::ApplicationModel::PackageDeploymentResolver::IsRegistered(m_packageManager, packageFullName)) + { + extendedError = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); + errorText = winrt::impl::message_from_hresult(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND)); + } + + ::ABI::Windows::Foundation::IAsyncOperationWithProgress<::ABI::Windows::Management::Deployment::DeploymentResult*, ::ABI::Windows::Management::Deployment::DeploymentProgress>* abiDeploymentOperation{}; + RETURN_IF_FAILED(PackageManagement_RepairPackageAsync2(packageFullName.c_str(), &abiDeploymentOperation)); + winrt::Windows::Foundation::IAsyncOperationWithProgress deploymentOperation; + winrt::copy_from_abi(deploymentOperation, abiDeploymentOperation); + deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< + winrt::Windows::Management::Deployment::DeploymentResult, + winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, + winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) + { + packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage, progressMaxPerPackage); + progress(packageDeploymentProgress); + }); + deploymentOperation.get(); + try + { + const auto deploymentResult{ deploymentOperation.GetResults() }; + const HRESULT error{ static_cast(deploymentOperation.ErrorCode()) }; + extendedError = deploymentResult.ExtendedErrorCode(); + errorText = deploymentResult.ErrorText(); + activityId = deploymentResult.ActivityId(); + const auto status{ deploymentOperation.Status() }; + if (status == winrt::Windows::Foundation::AsyncStatus::Error) + { + RETURN_IF_FAILED_MSG(error, + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + + // Status=Error but SUCCEEDED(error) == This.Should.Never.Happen. + FAIL_FAST_HR_MSG(E_UNEXPECTED, + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + } + else if (status == winrt::Windows::Foundation::AsyncStatus::Canceled) + { + RETURN_WIN32_MSG(ERROR_CANCELLED, "%ls", packageFullName.c_str()); + } + FAIL_FAST_HR_IF_MSG(E_UNEXPECTED, status != winrt::Windows::Foundation::AsyncStatus::Completed, + "Status:%d PackageFullName:%ls : %ls", static_cast(status), packageFullName.c_str(), errorText.c_str()); + } + catch (...) + { + auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + THROW_HR_MSG(exception.code(), + "ExtendedError:0x%08X PackageFullName:%ls : %ls", + extendedError, packageFullName.c_str(), errorText.c_str()); + } + return S_OK; + } + + bool PackageDeploymentManager::IsProvisionedByPackageFamilyName(hstring const& packageFamilyName) + { + const auto provisionedPackages{ m_packageManager.FindProvisionedPackages() }; + return IsProvisionedByPackageFamilyName(provisionedPackages, packageFamilyName); + } + + bool PackageDeploymentManager::IsProvisionedByPackageFamilyName( + winrt::Windows::Foundation::Collections::IVector const& provisionedPackages, + hstring const& packageFamilyName) + { + for (const winrt::Windows::ApplicationModel::Package& provisionedPackage: provisionedPackages) + { + if (StringEqualsNoCase(packageFamilyName, provisionedPackage.Id().FamilyName())) + { + return true; + } + } + return false; + } + + bool PackageDeploymentManager::IsProvisioned( + winrt::Windows::Foundation::Collections::IVector const& provisionedPackages, + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem) + { + return IsProvisionedByPackageFamilyName(provisionedPackages, packageSetItem.PackageFamilyName()); + } + + winrt::Windows::Foundation::IAsyncOperationWithProgress + PackageDeploymentManager::ProvisionPackageByFamilyNameAsync( + hstring packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions const& options) + { + auto logTelemetry{ PackageManagementTelemetry::ProvisionPackageAsync::Start(packageFamilyName) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + winrt::Windows::Management::Deployment::PackageAllUserProvisioningOptions provisionOptions{ ToOptions(options) }; + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(ProvisionPackageByFamilyName(packageFamilyName, provisionOptions, packageDeploymentProgress, progress, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageUri:%ls", + extendedError, packageFamilyName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageFamilyName.c_str()); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageFamilyName); + } + + HRESULT PackageDeploymentManager::ProvisionPackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Windows::Management::Deployment::PackageAllUserProvisioningOptions const& options, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + // PackageManager.ProvisionPackageForAllUsersAsync(String, PackageAllUserProvisioningOptions) requires Windows >= 10.0.22000.0 (aka Win11 21H2) + winrt::Windows::Foundation::IAsyncOperationWithProgress deploymentOperation; + if (WindowsVersion::IsWindows11_21H2OrGreater()) + { + deploymentOperation = m_packageManager.ProvisionPackageForAllUsersAsync(packageFamilyName, options); + } + else + { + deploymentOperation = m_packageManager.ProvisionPackageForAllUsersAsync(packageFamilyName); + } + deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< + winrt::Windows::Management::Deployment::DeploymentResult, + winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, + winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) + { + const double progressMaxPerPackage{ 1.0 }; + packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage, progressMaxPerPackage); + progress(packageDeploymentProgress); + }); + deploymentOperation.get(); + try + { + const auto deploymentResult{ deploymentOperation.GetResults() }; + const HRESULT error{ static_cast(deploymentOperation.ErrorCode()) }; + extendedError = deploymentResult.ExtendedErrorCode(); + errorText = deploymentResult.ErrorText(); + activityId = deploymentResult.ActivityId(); + const auto status{ deploymentOperation.Status() }; + if (status == winrt::Windows::Foundation::AsyncStatus::Error) + { + RETURN_IF_FAILED_MSG(error, + "ExtendedError:0x%08X PackageFamilyName:%ls : %ls", + extendedError, packageFamilyName.c_str(), errorText.c_str()); + + // Status=Error but SUCCEEDED(error) == This.Should.Never.Happen. + FAIL_FAST_HR_MSG(E_UNEXPECTED, + "ExtendedError:0x%08X PackageFamilyName:%ls : %ls", + extendedError, packageFamilyName.c_str(), errorText.c_str()); + } + else if (status == winrt::Windows::Foundation::AsyncStatus::Canceled) + { + RETURN_WIN32_MSG(ERROR_CANCELLED, "%ls", packageFamilyName.c_str()); + } + FAIL_FAST_HR_IF_MSG(E_UNEXPECTED, status != winrt::Windows::Foundation::AsyncStatus::Completed, + "Status:%d PackageFamilyName:%ls : %ls", static_cast(status), packageFamilyName.c_str(), errorText.c_str()); + } + catch (...) + { + auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + THROW_HR_MSG(exception.code(), + "ExtendedError:0x%08X PackageFamilyName:%ls : %ls", + extendedError, packageFamilyName.c_str(), errorText.c_str()); + } + return S_OK; + } + + winrt::Windows::Foundation::IAsyncOperationWithProgress + PackageDeploymentManager::DeprovisionPackageByFamilyNameAsync(hstring packageFamilyName) + { + auto logTelemetry{ PackageManagementTelemetry::DeprovisionPackageAsync::Start(packageFamilyName) }; + + auto strong{ get_strong() }; + + auto cancellation{ co_await winrt::get_cancellation_token() }; + cancellation.enable_propagation(true); + + logTelemetry.IgnoreCurrentThread(); + co_await resume_background(); // Allow to register the progress and complete handler + auto logTelemetryContinuation{ logTelemetry.ContinueOnCurrentThread() }; + + auto progress{ co_await winrt::get_progress_token() }; + auto packageDeploymentProgress{ + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress{ + PackageDeploymentProgressStatus::Queued, 0} }; + progress(packageDeploymentProgress); + + HRESULT error{}; + HRESULT extendedError{}; + winrt::hstring errorText; + winrt::guid activityId{}; + try + { + error = LOG_IF_FAILED_MSG(DeprovisionPackageByFamilyName(packageFamilyName, packageDeploymentProgress, progress, extendedError, errorText, activityId), + "ExtendedError:0x%08X PackageUri:%ls", + extendedError, packageFamilyName.c_str()); + } + catch (...) + { + const auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + error = LOG_HR_MSG(exception.code(), "ExtendedError:0x%08X PackageUri:%ls", extendedError, packageFamilyName.c_str()); + } + if (FAILED(error)) + { + co_return winrt::make( + PackageDeploymentStatus::CompletedFailure, activityId, error, extendedError, errorText); + } + + co_return winrt::make(PackageDeploymentStatus::CompletedSuccess, activityId); + + logTelemetry.Stop(packageFamilyName); + } + + HRESULT PackageDeploymentManager::DeprovisionPackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId) + { + extendedError = S_OK; + errorText.clear(); + activityId = winrt::guid{}; + + auto deploymentOperation{ m_packageManager.DeprovisionPackageForAllUsersAsync(packageFamilyName) }; + deploymentOperation.Progress([&](winrt::Windows::Foundation::IAsyncOperationWithProgress< + winrt::Windows::Management::Deployment::DeploymentResult, + winrt::Windows::Management::Deployment::DeploymentProgress> const& /*sender*/, + winrt::Windows::Management::Deployment::DeploymentProgress const& progressInfo) + { + const double progressMaxPerPackage{ 1.0 }; + packageDeploymentProgress.Progress = PercentageToProgress(progressInfo.percentage, progressMaxPerPackage); + progress(packageDeploymentProgress); + }); + deploymentOperation.get(); + try + { + const auto deploymentResult{ deploymentOperation.GetResults() }; + const HRESULT error{ static_cast(deploymentOperation.ErrorCode()) }; + extendedError = deploymentResult.ExtendedErrorCode(); + errorText = deploymentResult.ErrorText(); + activityId = deploymentResult.ActivityId(); + const auto status{ deploymentOperation.Status() }; + if (status == winrt::Windows::Foundation::AsyncStatus::Error) + { + RETURN_IF_FAILED_MSG(error, + "ExtendedError:0x%08X PackageFamilyName:%ls : %ls", + extendedError, packageFamilyName.c_str(), errorText.c_str()); + + // Status=Error but SUCCEEDED(error) == This.Should.Never.Happen. + FAIL_FAST_HR_MSG(E_UNEXPECTED, + "ExtendedError:0x%08X PackageFamilyName:%ls : %ls", + extendedError, packageFamilyName.c_str(), errorText.c_str()); + } + else if (status == winrt::Windows::Foundation::AsyncStatus::Canceled) + { + RETURN_WIN32_MSG(ERROR_CANCELLED, "%ls", packageFamilyName.c_str()); + } + FAIL_FAST_HR_IF_MSG(E_UNEXPECTED, status != winrt::Windows::Foundation::AsyncStatus::Completed, + "Status:%d PackageFamilyName:%ls : %ls", static_cast(status), packageFamilyName.c_str(), errorText.c_str()); + } + catch (...) + { + auto exception{ hresult_error(to_hresult(), take_ownership_from_abi) }; + THROW_HR_MSG(exception.code(), + "ExtendedError:0x%08X PackageFamilyName:%ls : %ls", + extendedError, packageFamilyName.c_str(), errorText.c_str()); + } + return S_OK; + } + winrt::Windows::Management::Deployment::PackageVolume PackageDeploymentManager::ToPackageVolume(winrt::Microsoft::Windows::Management::Deployment::PackageVolume const& packageVolume) const { if (packageVolume) @@ -1501,9 +3483,29 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation return deploymentOptions; } - double PackageDeploymentManager::PercentageToProgress(uint32_t percentage) + winrt::Windows::Management::Deployment::PackageAllUserProvisioningOptions PackageDeploymentManager::ToOptions(winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions const& options) const { - return static_cast(percentage) / 100.0; + auto optionalPackageFamilyNames{ options.OptionalPackageFamilyNames() }; + THROW_HR_IF(E_NOTIMPL, (optionalPackageFamilyNames.Size() >0) && !options.IsOptionalPackageFamilyNamesSupported()); + + auto projectionOrderPackageFamilyNames{ options.ProjectionOrderPackageFamilyNames() }; + THROW_HR_IF(E_NOTIMPL, (projectionOrderPackageFamilyNames.Size() >0) && !options.IsProjectionOrderPackageFamilyNamesSupported()); + + winrt::Windows::Management::Deployment::PackageAllUserProvisioningOptions toOptions; + for (const auto optionalPackageFamilyName : optionalPackageFamilyNames) + { + toOptions.OptionalPackageFamilyNames().Append(optionalPackageFamilyName); + } + for (const auto projectionOrderPackageFamilyName : projectionOrderPackageFamilyNames) + { + toOptions.ProjectionOrderPackageFamilyNames().Append(projectionOrderPackageFamilyName); + } + return toOptions; + } + + double PackageDeploymentManager::PercentageToProgress(uint32_t percentage, const double progressMaxPerItem) + { + return (static_cast(percentage) / 100.0) * progressMaxPerItem; } bool PackageDeploymentManager::IsUriEndsWith(winrt::Windows::Foundation::Uri const& packageUri, PCWSTR target) @@ -1524,4 +3526,25 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation PCWSTR pathToCompare{ path.c_str() + (path.size() - targetLength) }; return CompareStringOrdinal(pathToCompare, -1, target, -1, TRUE) == CSTR_EQUAL; } + + winrt::Windows::Foundation::Uri PackageDeploymentManager::GetEffectivePackageUri( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet, + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem) + { + auto packageUri{ packageSetItem.PackageUri() }; + if (packageUri) + { + return packageUri; + } + else + { + return packageSet.PackageUri(); + } + } + + bool PackageDeploymentManager::IsUriScheme_MsUup(winrt::Windows::Foundation::Uri const& packageUri) + { + const auto schemeName{ packageUri.SchemeName() }; + return CompareStringOrdinal(schemeName.c_str(), -1, L"ms-uup", -1, TRUE) == CSTR_EQUAL; + } } diff --git a/dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.h b/dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.h index 9c1e75340..d31f46f8e 100644 --- a/dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.h +++ b/dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.h @@ -10,9 +10,16 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation struct PackageDeploymentManager : PackageDeploymentManagerT { static winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager GetDefault(); + static bool IsPackageDeploymentFeatureSupported(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature feature); + private: + static bool IsPackageDeploymentFeatureSupported(PCWSTR feature); + public: bool IsPackageReady(hstring const& package); bool IsPackageReadyByUri(winrt::Windows::Foundation::Uri const& packageUri); bool IsPackageSetReady(winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet); + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus IsPackageReadyOrNewerAvailable(hstring const& package); + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus IsPackageReadyOrNewerAvailableByUri(winrt::Windows::Foundation::Uri const& packageUri); + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus IsPackageSetReadyOrNewerAvailable(winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet); winrt::Windows::Foundation::IAsyncOperationWithProgress EnsurePackageReadyAsync(hstring package, winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options); winrt::Windows::Foundation::IAsyncOperationWithProgress EnsurePackageReadyByUriAsync(winrt::Windows::Foundation::Uri packageUri, winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options); winrt::Windows::Foundation::IAsyncOperationWithProgress EnsurePackageSetReadyAsync(winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet, winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options); @@ -36,14 +43,20 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Foundation::IAsyncOperationWithProgress RepairPackageAsync(hstring package); winrt::Windows::Foundation::IAsyncOperationWithProgress RepairPackageByUriAsync(winrt::Windows::Foundation::Uri packageUri); winrt::Windows::Foundation::IAsyncOperationWithProgress RepairPackageSetAsync(winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet); + bool IsPackageProvisioned(hstring const& package); + bool IsPackageProvisionedByUri(winrt::Windows::Foundation::Uri const& packageUri); + bool IsPackageSetProvisioned(winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet); winrt::Windows::Foundation::IAsyncOperationWithProgress ProvisionPackageAsync(hstring package, winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options); winrt::Windows::Foundation::IAsyncOperationWithProgress ProvisionPackageByUriAsync(winrt::Windows::Foundation::Uri packageUri, winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options); winrt::Windows::Foundation::IAsyncOperationWithProgress ProvisionPackageSetAsync(winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet, winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options); winrt::Windows::Foundation::IAsyncOperationWithProgress DeprovisionPackageAsync(hstring package); winrt::Windows::Foundation::IAsyncOperationWithProgress DeprovisionPackageByUriAsync(winrt::Windows::Foundation::Uri packageUri); winrt::Windows::Foundation::IAsyncOperationWithProgress DeprovisionPackageSetAsync(winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet); - bool IsPackageRegistrationPending(hstring const& packageFamilyName); - bool IsPackageRegistrationPendingForUser(hstring const& userSecurityId, hstring const& packageFamilyName); + bool IsPackageRegistrationPending(hstring const& packageFullName); + bool IsPackageRegistrationPendingForUser(hstring const& userSecurityId, hstring const& packageFullName); + + private: + bool IsPackageRegistrationPendingForUser(PSID userSid, PCWSTR packageFullName); private: winrt::Windows::Foundation::IAsyncOperationWithProgress AddPackageByAppInstallerFileAsync(winrt::Windows::Foundation::Uri packageUri, winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options); @@ -51,23 +64,44 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Foundation::IAsyncOperationWithProgress RegisterPackageByPackageFullNameAsync(winrt::hstring const& packageFullName, winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options); private: + winrt::hstring GetUupProductIdIfMsUup(winrt::Windows::Foundation::Uri const& uri) const; + wil::unique_cotaskmem_array_ptr GetPackageFullNamesFromUupProductUriIfMsUup(winrt::Windows::Foundation::Uri const& uri) const; bool IsReadyByPackageFullName(hstring const& packageFullName); - bool IsReady(winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSet); - void Validate(winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) const; - void Validate(winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem) const; + bool IsReady(winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem); + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus IsReadyOrNewerAvailableByPackageFullName(hstring const& packageFullName); + winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus IsReadyOrNewerAvailable(winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem); + void Validate_PackageUriIsRequired( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) const; + void Validate_PackageUriIsOptional( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) const; + void _Validate( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet, + const bool packageUriIsRequired) const; + void _Validate( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet, + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, + const bool packageUriIsRequired) const; + void Validate_PackageUriOrFamilyName( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet) const; + void Validate_PackageUriOrFamilyName( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet, + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem) const; HRESULT EnsureReadyAsync( + winrt::Windows::Foundation::Uri const& packageUri, winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions const& options, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackageSetItem, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId); HRESULT AddPackage( - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, + winrt::Windows::Foundation::Uri const& packageUri, winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions const& options, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackageSetItem, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId); @@ -76,14 +110,16 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::AddPackageOptions const& addOptions, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackage, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId); HRESULT StagePackage( - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, + winrt::Windows::Foundation::Uri const& packageUri, winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions const& options, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackageSetItem, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId); @@ -92,14 +128,16 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::StagePackageOptions const& stageOptions, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackage, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId); HRESULT RegisterPackage( - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem, + winrt::Windows::Foundation::Uri const& packageUri, winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions const& options, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackageSetItem, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId); @@ -108,6 +146,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::RegisterPackageOptions const& registerOptions, winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, wistd::function progress, + const double progressMaxPerPackage, HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId); @@ -127,6 +166,121 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation HRESULT& extendedError, winrt::hstring& errorText, winrt::guid& activityId); + HRESULT RemovePackage( + winrt::Windows::Foundation::Uri const& packageUri, + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageSetItem, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + HRESULT RemovePackage( + winrt::Windows::Foundation::Uri const& packageUri, + winrt::Windows::Management::Deployment::RemovalOptions const& removeOptions, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackage, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + HRESULT RemovePackageByFullName( + winrt::hstring const& packageFullName, + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options, + winrt::Windows::Management::Deployment::RemovalOptions const& removeOptions, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackage, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + HRESULT RemovePackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageFamily, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + HRESULT RemovePackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options, + winrt::Windows::Management::Deployment::RemovalOptions const& removeOptions, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageFamily, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + winrt::Windows::Foundation::IAsyncOperationWithProgress ResetPackageByFamilyNameAsync( + hstring packageFamilyName); + HRESULT ResetPackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageFamily, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + winrt::Windows::Foundation::IAsyncOperationWithProgress ResetPackageByFullNameAsync( + hstring packageFullName); + HRESULT ResetPackageByFullName( + winrt::hstring const& packageFullName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackage, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + winrt::Windows::Foundation::IAsyncOperationWithProgress RepairPackageByFamilyNameAsync( + hstring packageFamilyName); + HRESULT RepairPackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackageFamily, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + winrt::Windows::Foundation::IAsyncOperationWithProgress RepairPackageByFullNameAsync( + hstring packageFullName); + HRESULT RepairPackageByFullName( + winrt::hstring const& packageFullName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + const double progressMaxPerPackage, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + bool IsProvisionedByPackageFamilyName( + hstring const& packageFamilyName); + bool IsProvisionedByPackageFamilyName( + winrt::Windows::Foundation::Collections::IVector const& provisionedPackages, + hstring const& packageFamilyName); + bool IsProvisioned( + winrt::Windows::Foundation::Collections::IVector const& provisionedPackages, + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem); + winrt::Windows::Foundation::IAsyncOperationWithProgress ProvisionPackageByFamilyNameAsync( + hstring packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions const& options); + HRESULT ProvisionPackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Windows::Management::Deployment::PackageAllUserProvisioningOptions const& options, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); + winrt::Windows::Foundation::IAsyncOperationWithProgress DeprovisionPackageByFamilyNameAsync( + hstring packageFamilyName); + HRESULT DeprovisionPackageByFamilyName( + winrt::hstring const& packageFamilyName, + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentProgress& packageDeploymentProgress, + wistd::function progress, + HRESULT& extendedError, + winrt::hstring& errorText, + winrt::guid& activityId); winrt::Windows::Management::Deployment::PackageVolume ToPackageVolume(winrt::Microsoft::Windows::Management::Deployment::PackageVolume const& packageVolume) const; winrt::Windows::Management::Deployment::AddPackageOptions ToOptions(winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions const& options) const; winrt::Windows::Management::Deployment::StagePackageOptions ToOptions(winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions const& options) const; @@ -134,8 +288,64 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation winrt::Windows::Management::Deployment::RemovalOptions ToOptions(winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions const& options) const; winrt::Windows::Management::Deployment::AddPackageOptions ToOptions(winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions const& options) const; winrt::Windows::Management::Deployment::DeploymentOptions ToDeploymentOptions(winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions const& options) const; - static double PercentageToProgress(uint32_t percentage); + winrt::Windows::Management::Deployment::PackageAllUserProvisioningOptions ToOptions(winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions const& options) const; + static double PercentageToProgress(uint32_t percentage, const double progressMaxPerItem); static bool IsUriEndsWith(winrt::Windows::Foundation::Uri const& packageUri, PCWSTR target); + static winrt::Windows::Foundation::Uri GetEffectivePackageUri( + winrt::Microsoft::Windows::Management::Deployment::PackageSet const& packageSet, + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem const& packageSetItem); + static bool IsUriScheme_MsUup(winrt::Windows::Foundation::Uri const& packageUri); + + private: + static size_t Count(winrt::Windows::Foundation::Collections::IIterable packages) + { + size_t count{}; + if (packages) + { + const auto iterator{ packages.First() }; + if (iterator.HasCurrent()) + { + ++count; + while (iterator.MoveNext()) + { + ++count; + } + } + } + return count; + } + private: + static bool Any(winrt::Windows::Foundation::Collections::IIterable packages) + { + return packages ? packages.First().HasCurrent() : false; + } + + private: + static int StringCompareNoCase(PCWSTR left, PCWSTR right) + { + return CompareStringOrdinal(left, -1, right, -1, TRUE) - CSTR_EQUAL; + } + static bool StringEqualsNoCase(PCWSTR left, PCWSTR right) + { + return StringCompareNoCase(left, right) == 0; + } + static int StringCompareNoCase(PCWSTR left, const size_t leftLength, PCWSTR right, const size_t rightLength) + { + return CompareStringOrdinal(left, static_cast(leftLength), right, static_cast(rightLength), TRUE) - CSTR_EQUAL; + } + static int StringEqualsNoCase(PCWSTR left, const size_t leftLength, PCWSTR right, const size_t rightLength) + { + return StringCompareNoCase(left, leftLength, right, rightLength) == 0; + } + private: + static int StringCompareNoCase(const winrt::hstring& left, const winrt::hstring& right) + { + return StringCompareNoCase(left.c_str(), right.c_str()); + } + static bool StringEqualsNoCase(const winrt::hstring& left, const winrt::hstring& right) + { + return StringEqualsNoCase(left.c_str(), right.c_str()); + } private: winrt::Windows::Management::Deployment::PackageManager m_packageManager; diff --git a/dev/PackageManager/API/M.W.M.D.RemovePackageOptions.h b/dev/PackageManager/API/M.W.M.D.RemovePackageOptions.h index 1faf7871a..ce0bdfd00 100644 --- a/dev/PackageManager/API/M.W.M.D.RemovePackageOptions.h +++ b/dev/PackageManager/API/M.W.M.D.RemovePackageOptions.h @@ -21,7 +21,7 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation void RemoveForAllUsers(bool value); private: - bool m_failIfNotFound{ true }; + bool m_failIfNotFound{}; bool m_preserveApplicationData{}; bool m_preserveRoamableApplicationData{}; bool m_removeForAllUsers{}; diff --git a/dev/PackageManager/API/PackageDeploymentResolver.cpp b/dev/PackageManager/API/PackageDeploymentResolver.cpp index 143ac694b..63d7cd12f 100644 --- a/dev/PackageManager/API/PackageDeploymentResolver.cpp +++ b/dev/PackageManager/API/PackageDeploymentResolver.cpp @@ -330,3 +330,12 @@ winrt::hstring Microsoft::Windows::ApplicationModel::PackageDeploymentResolver:: } return bestFitPackageFullName; } + +bool Microsoft::Windows::ApplicationModel::PackageDeploymentResolver::IsRegistered( + const winrt::Windows::Management::Deployment::PackageManager& packageManager, + const winrt::hstring& packageFullName) +{ + // Find the match + auto package{ packageManager.FindPackageForUser(winrt::hstring(), packageFullName) }; + return !!package; +} diff --git a/dev/PackageManager/API/PackageDeploymentResolver.h b/dev/PackageManager/API/PackageDeploymentResolver.h index 5188585f6..11dc1c65d 100644 --- a/dev/PackageManager/API/PackageDeploymentResolver.h +++ b/dev/PackageManager/API/PackageDeploymentResolver.h @@ -24,6 +24,10 @@ namespace Microsoft::Windows::ApplicationModel::PackageDeploymentResolver bool FindAny( const winrt::Windows::Management::Deployment::PackageManager& packageManager, const winrt::hstring& packageFullName); + + bool IsRegistered( + const winrt::Windows::Management::Deployment::PackageManager& packageManager, + const winrt::hstring& packageFullName); } #endif // PACKAGERESOLVER_H diff --git a/dev/PackageManager/API/PackageManager.idl b/dev/PackageManager/API/PackageManager.idl index 0f2eece2d..a5b88396a 100644 --- a/dev/PackageManager/API/PackageManager.idl +++ b/dev/PackageManager/API/PackageManager.idl @@ -7,9 +7,22 @@ import "M.AM.DynamicDependency.idl"; namespace Microsoft.Windows.Management.Deployment { - [contractversion(1)] + [contractversion(2)] apicontract PackageDeploymentContract{}; + /// Features can be queried if currently available/enabled. + /// @see PackageDeploymentManager.IsPackageDeploymentFeatureSupported() + [contract(PackageDeploymentContract, 2)] + enum PackageDeploymentFeature + { + PackageUriScheme_ms_uup = 1, + IsPackageReadyOrNewerAvailable = 2, + RemovePackageByUri = 3, + ResetPackage = 4, + RepairPackage = 5, + ProvisionPackage_Framework = 6, + }; + /// Represents a package storage volume. /// @note A volume 'name' is the volume's media ID (you can treat 'Volume Name' == 'Volume Media ID'). /// @see https://learn.microsoft.com/uwp/api/windows.management.deployment.packagevolume @@ -71,6 +84,15 @@ namespace Microsoft.Windows.Management.Deployment UsePreference, }; + /// Defines the stub behavior for an app package that is being added or staged. + [contract(PackageDeploymentContract, 2)] + enum PackageReadyOrNewerAvailableStatus + { + NotReady = 0, + Ready = 1, + NewerAvailable = 2, + }; + /// The progress status of the deployment request. /// @see https://learn.microsoft.com/uwp/api/windows.management.deployment.deploymentprogress.state [contract(PackageDeploymentContract, 1)] @@ -258,6 +280,9 @@ namespace Microsoft.Windows.Management.Deployment EnsureReadyOptions(); AddPackageOptions AddPackageOptions { get; }; + + [contract(PackageDeploymentContract, 2)] + Boolean RegisterNewerIfAvailable; } [contract(PackageDeploymentContract, 1)] @@ -266,6 +291,11 @@ namespace Microsoft.Windows.Management.Deployment // Get an instance of the manager static PackageDeploymentManager GetDefault(); + //------------------------------------------------------------- + // IsPackageDeploymentFeatureSupported + + static Boolean IsPackageDeploymentFeatureSupported(PackageDeploymentFeature feature); + //------------------------------------------------------------- // IsReady @@ -275,8 +305,24 @@ namespace Microsoft.Windows.Management.Deployment Boolean IsPackageReadyByUri(Windows.Foundation.Uri packageUri); + /// @note packageSet[Item].PackageUri is optional Boolean IsPackageSetReady(PackageSet packageSet); + //------------------------------------------------------------- + // IsReadyOrNewerAvailable + + // Return true if the package(s) are present and available for use + + [contract(PackageDeploymentContract, 2)] + PackageReadyOrNewerAvailableStatus IsPackageReadyOrNewerAvailable(String package); + + [contract(PackageDeploymentContract, 2)] + PackageReadyOrNewerAvailableStatus IsPackageReadyOrNewerAvailableByUri(Windows.Foundation.Uri packageUri); + + /// @note packageSet[Item].PackageUri is optional + [contract(PackageDeploymentContract, 2)] + PackageReadyOrNewerAvailableStatus IsPackageSetReadyOrNewerAvailable(PackageSet packageSet); + //------------------------------------------------------------- // EnsureReady @@ -292,6 +338,7 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress EnsurePackageReadyByUriAsync(Windows.Foundation.Uri packageUri, EnsureReadyOptions options); + /// @note packageSet[Item].PackageUri is required Windows.Foundation.IAsyncOperationWithProgress EnsurePackageSetReadyAsync(PackageSet packageSet, EnsureReadyOptions options); @@ -304,6 +351,7 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress AddPackageByUriAsync(Windows.Foundation.Uri packageUri, AddPackageOptions options); + /// @note packageSet[Item].PackageUri is required Windows.Foundation.IAsyncOperationWithProgress AddPackageSetAsync(PackageSet packageSet, AddPackageOptions options); @@ -316,6 +364,7 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress StagePackageByUriAsync(Windows.Foundation.Uri packageUri, StagePackageOptions options); + /// @note packageSet[Item].PackageUri is required Windows.Foundation.IAsyncOperationWithProgress StagePackageSetAsync(PackageSet packageSet, StagePackageOptions options); @@ -328,6 +377,7 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress RegisterPackageByUriAsync(Windows.Foundation.Uri packageUri, RegisterPackageOptions options); + /// @note packageSet[Item].PackageUri is optional Windows.Foundation.IAsyncOperationWithProgress RegisterPackageSetAsync(PackageSet packageSet, RegisterPackageOptions options); @@ -346,6 +396,7 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress RemovePackageByUriAsync(Windows.Foundation.Uri packageUri, RemovePackageOptions options); + /// @note packageSet[Item].PackageUri is optional Windows.Foundation.IAsyncOperationWithProgress RemovePackageSetAsync(PackageSet packageSet, RemovePackageOptions options); @@ -358,6 +409,7 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress ResetPackageByUriAsync(Windows.Foundation.Uri packageUri); + /// @note packageSet[Item].PackageUri is optional Windows.Foundation.IAsyncOperationWithProgress ResetPackageSetAsync(PackageSet packageSet); @@ -370,9 +422,25 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress RepairPackageByUriAsync(Windows.Foundation.Uri packageUri); + /// @note packageSet[Item].PackageUri is optional Windows.Foundation.IAsyncOperationWithProgress RepairPackageSetAsync(PackageSet packageSet); + //------------------------------------------------------------- + // IsProvisioned + + // Return true if the package(s) are provisioned + + [contract(PackageDeploymentContract, 2)] + Boolean IsPackageProvisioned(String package); + + [contract(PackageDeploymentContract, 2)] + Boolean IsPackageProvisionedByUri(Windows.Foundation.Uri packageUri); + + /// @note packageSet[Item].PackageUri is optional + [contract(PackageDeploymentContract, 2)] + Boolean IsPackageSetProvisioned(PackageSet packageSet); + //------------------------------------------------------------- // Provision packages @@ -382,6 +450,7 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress ProvisionPackageByUriAsync(Windows.Foundation.Uri packageUri, ProvisionPackageOptions options); + /// @note packageSet[Item].PackageUri is optional Windows.Foundation.IAsyncOperationWithProgress ProvisionPackageSetAsync(PackageSet packageSet, ProvisionPackageOptions options); @@ -394,15 +463,16 @@ namespace Microsoft.Windows.Management.Deployment Windows.Foundation.IAsyncOperationWithProgress DeprovisionPackageByUriAsync(Windows.Foundation.Uri packageUri); + /// @note packageSet[Item].PackageUri is optional Windows.Foundation.IAsyncOperationWithProgress DeprovisionPackageSetAsync(PackageSet packageSet); //------------------------------------------------------------- // IsRegistrationPending - Boolean IsPackageRegistrationPending(String packageFamilyName); + Boolean IsPackageRegistrationPending(String packageFullName); - Boolean IsPackageRegistrationPendingForUser(String userSecurityId, String packageFamilyName); + Boolean IsPackageRegistrationPendingForUser(String userSecurityId, String packageFullName); } [contract(PackageDeploymentContract, 1)] diff --git a/dev/PackageManager/API/PackageManagerTelemetry.h b/dev/PackageManager/API/PackageManagerTelemetry.h index 013747307..3f9a71b7f 100644 --- a/dev/PackageManager/API/PackageManagerTelemetry.h +++ b/dev/PackageManager/API/PackageManagerTelemetry.h @@ -126,11 +126,11 @@ public: CATCH_LOG() END_ACTIVITY_CLASS(); - BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(EnsurePackageAsync, PDT_ProductAndServicePerformance); + BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(EnsurePackageReadyAsync, PDT_ProductAndServicePerformance); DEFINE_ACTIVITY_START(winrt::hstring const& package) noexcept try { TraceLoggingClassWriteStart( - EnsurePackageAsync, + EnsurePackageReadyAsync, _GENERIC_PARTB_FIELDS_ENABLED, TraceLoggingWideString(package.c_str(), "Package")); } @@ -138,17 +138,17 @@ public: DEFINE_ACTIVITY_STOP(winrt::hstring const& package) noexcept try { TraceLoggingClassWriteStop( - EnsurePackageAsync, + EnsurePackageReadyAsync, _GENERIC_PARTB_FIELDS_ENABLED, TraceLoggingWideString(package.c_str(), "Package")); } CATCH_LOG() END_ACTIVITY_CLASS(); - BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(EnsurePackageByUriAsync, PDT_ProductAndServicePerformance); + BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(EnsurePackageReadyByUriAsync, PDT_ProductAndServicePerformance); DEFINE_ACTIVITY_START(winrt::hstring const& packageUri) noexcept try { TraceLoggingClassWriteStart( - EnsurePackageByUriAsync, + EnsurePackageReadyByUriAsync, _GENERIC_PARTB_FIELDS_ENABLED, TraceLoggingWideString(packageUri.c_str(), "PackageUri")); } @@ -156,7 +156,7 @@ public: DEFINE_ACTIVITY_STOP(winrt::hstring const& packageUri) noexcept try { TraceLoggingClassWriteStop( - EnsurePackageByUriAsync, + EnsurePackageReadyByUriAsync, _GENERIC_PARTB_FIELDS_ENABLED, TraceLoggingWideString(packageUri.c_str(), "PackageUri")); } diff --git a/dev/PackageManager/API/pch.h b/dev/PackageManager/API/pch.h index 3dcd1b1b1..22be15110 100644 --- a/dev/PackageManager/API/pch.h +++ b/dev/PackageManager/API/pch.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include @@ -28,5 +30,9 @@ #include #include +#include #include "MsixPackageManager.h" + +#include +#include diff --git a/dev/WindowsAppRuntime_DLL/packages.config b/dev/WindowsAppRuntime_DLL/packages.config index cd05427e9..647f7eaa0 100644 --- a/dev/WindowsAppRuntime_DLL/packages.config +++ b/dev/WindowsAppRuntime_DLL/packages.config @@ -5,4 +5,5 @@ + diff --git a/dev/WindowsAppRuntime_DLL/pch.h b/dev/WindowsAppRuntime_DLL/pch.h index ec070ce0f..37ab34eed 100644 --- a/dev/WindowsAppRuntime_DLL/pch.h +++ b/dev/WindowsAppRuntime_DLL/pch.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include @@ -53,6 +55,7 @@ #include #include #include +#include #include #include diff --git a/docs/Coding-Guidelines/GettingStarted.md b/docs/Coding-Guidelines/GettingStarted.md index db39f9480..b5b5aa15c 100644 --- a/docs/Coding-Guidelines/GettingStarted.md +++ b/docs/Coding-Guidelines/GettingStarted.md @@ -18,7 +18,14 @@ or via the browser: **NOTE:** Visual Studio 2022 doesn't include this SDK but will use it if installed on the machine. -2. Visual Studio 2022 with... +2. Windows 11 SDK 10.0.26100.0 (24H2) + a. Browse to https://go.microsoft.com/fwlink/?linkid=2272610 + b. Save the offered download `winsdksetup.exe` + c. Run winsdksetup.exe + +**NOTE:** Visual Studio 2022 doesn't include this SDK but will use it if installed on the machine. + +3. Visual Studio 2022 with... * Workloads * .NET desktop development * Desktop development with C++ @@ -51,7 +58,7 @@ or via the browser: **NOTE:** You can tell the Visual Studio Installer to do the heavy lifting for you via `More` / `Import configuration` and select `docs\Coding-Guidelines\VisualStudio2022.vsconfig`. -3. Run NuGet Restore +4. Run NuGet Restore * Download nuget.exe version >= 6.2.1 from https://www.nuget.org/downloads e.g. https://dist.nuget.org/win-x86-commandline/v6.2.1/nuget.exe * Open a command prompt @@ -88,7 +95,7 @@ Some tips: ## MSBuild Tips -Build everything from the command line via msbuild e.g. +### Build everything from the command line via msbuild e.g. | Goal | Command Line | |---|---| @@ -103,6 +110,17 @@ See MSBuild documentation for more details. Troubleshoot build problems by enabling binary logging (e.g. `msbuild...-bl`) and use [MSBuild Binary and Structured Log Viewer](https://msbuildlog.com/) to review the log. +### Common Build Errors + +PROBLEM 001: Expired Test Certificate +SYMPTOMS: + VS ErrorList: + MSB3073 The command "signtool.exe sign ..." exited with code 1...\MakeMsix.targets... + Build Output: + Build Output: EXEC : SignTool error : No certificates were found that met all the given criteria. + ...\MakeMsix.targets...error MSB3073: The command "signtool.exe sign ..." exited with code 1. +SOLUTION: Run DevCheck.cmd (from an admin prompt). This detects the expired certificate and prompts to create a new one. + ## Testing Tips * Use Test Explorer to view and run tests via the View menu's `Test Explorer` diff --git a/eng/Version.Dependencies.xml b/eng/Version.Dependencies.xml index fba4803c9..28fe3c043 100644 --- a/eng/Version.Dependencies.xml +++ b/eng/Version.Dependencies.xml @@ -29,7 +29,7 @@ - + diff --git a/eng/common/DevCheck.ps1 b/eng/common/DevCheck.ps1 index 7aebb317c..ff1eb8c1c 100644 --- a/eng/common/DevCheck.ps1 +++ b/eng/common/DevCheck.ps1 @@ -43,6 +43,9 @@ .PARAMETER NoInteractive Run in non-interactive mode (fail if any need for user input) +.PARAMETER InstallWindowsSDK + Download and install Windows Platform SDKs (if necessary). + .PARAMETER Offline Do not access the network @@ -100,6 +103,8 @@ Param( [Switch]$Clean=$false, + [Switch]$InstallWindowsSDK=$false, + [Switch]$NoInteractive=$false, [Switch]$Offline=$false, @@ -307,7 +312,6 @@ function Get-VSWhereOnline Write-Host "Downloading $global:vswhere from $global:vswhere_url..." Write-Verbose "Executing: curl.exe --output $path -L -# $global:vswhere_url" $null = Start-Process curl.exe -ArgumentList "--output $path -L -# $global:vswhere_url" -Wait -NoNewWindow -PassThru - } if (-not(Test-Path -Path $path -PathType Leaf)) { @@ -456,17 +460,61 @@ function Test-VisualStudio2022Install return $ok } +function Install-WindowsSDK +{ + param( + [String]$version, + [uri]$url + ) + + $path = Join-Path $env:TEMP "winsdksetup-$($version).exe" + if ($Clean -eq $true -And (Test-Path -Path $path -PathType Leaf)) + { + Write-Verbose "Found $path. Deleting per -Clean..." + Remove-Item -Path $path -Force + } + + $log = Join-Path $env:TEMP "winsdksetup-$($version).log" + if ($Clean -eq $true -And (Test-Path -Path $log -PathType Leaf)) + { + Write-Verbose "Found $log. Deleting per -Clean..." + Remove-Item -Path $log -Force + } + + if (-not(Test-Path -Path $path -PathType Leaf)) + { + Write-Host "Downloading Windows SDK $version from $url..." + Write-Verbose "Executing: curl.exe --output $path -L -# $url" + $null = Start-Process curl.exe -ArgumentList "--output $path -L -# $url" -Wait -NoNewWindow -PassThru + } + $p = Start-Process $path -ArgumentList "/features + /q /log $log" -Wait -NoNewWindow -PassThru + if ($p.ExitCode -ne 0) + { + Write-Host "...ERROR: Windows SDK $($version) install failed. See $log" -ForegroundColor Red -BackgroundColor Black + $global:issues++ + return $false + } + Write-Host "Install Windows SDK $($version)...OK" + return $true +} + function Test-WindowsSDKInstall { param( - [String]$version + [String]$version, + [uri]$url ) $regkey = "HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots\$version" $found = Test-Path $regkey -PathType Container if ($found) { - Write-Verbose "Windows SDK $($version) = OK" + Write-Host "Windows SDK $($version) = OK" + } + elseif ($InstallWindowsSDK -eq $true) + { + Write-Warning "WARNING: Windows SDK $($version) not found. Installing..." + $null = Install-WindowsSDK $version $url } else { @@ -1279,8 +1327,8 @@ function Get-DeveloperMode $regkey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock' if (Test-Path -Path $regkey -PathType Container) { - $value = Get-ItemProperty -Path $regkey -Name AllowDevelopmentWithoutDevLicense - return $value.AllowDevelopmentWithoutDevLicense -eq 1 + $value = $(Get-Item -Path $regkey).GetValue('AllowDevelopmentWithoutDevLicense') + return $value -eq 1 } return $false @@ -1297,7 +1345,6 @@ function Test-DeveloperMode { Write-Host "ERROR: Developer mode is not enabled. Enable it via Settings" -ForegroundColor Red -BackgroundColor Black $global:issues++ - $fatal_errors++ } } @@ -1354,7 +1401,8 @@ if (($CheckAll -ne $false) -Or ($CheckVisualStudio -ne $false)) { $null = Test-VisualStudioComponents } - $null = Test-WindowsSDKInstall '10.0.17763.0' + $null = Test-WindowsSDKInstall '10.0.17763.0' [uri]'https://go.microsoft.com/fwlink/p/?LinkID=2033908' + #TODO Uncomment to require new SDK: $null = Test-WindowsSDKInstall '10.0.26100.0' [uri]'https://go.microsoft.com/fwlink/?linkid=2272610' } if (($CheckAll -ne $false) -Or ($CheckTestPfx -ne $false)) diff --git a/installer/test/InstallerFunctionalTests/packages.config b/installer/test/InstallerFunctionalTests/packages.config index 1117ac430..dc444ff57 100644 --- a/installer/test/InstallerFunctionalTests/packages.config +++ b/installer/test/InstallerFunctionalTests/packages.config @@ -1,6 +1,6 @@  - + diff --git a/specs/packagemanager/PackageManagement.md b/specs/packagemanager/PackageManagement.md index e84b679b4..aa2c5355b 100644 --- a/specs/packagemanager/PackageManagement.md +++ b/specs/packagemanager/PackageManagement.md @@ -17,10 +17,12 @@ but with additional functionality, improved developer experience and performance - [3.6. Reset](#36-reset) - [3.7. IsPackageRegistrationPending](#37-ispackageregistrationpending) - [3.8. PackageSet](#38-packageset) + - [3.8.1. PackageSet Properties](#381-packageset-properties) + - [3.8.2. PackageSetItem Properties](#382-packagesetitem-properties) - [3.9. PackageRuntimeManager](#39-packageruntimemanager) - [3.10. PackageVolume Repair](#310-packagevolume-repair) - [3.11. Usability](#311-usability) - - [3.12 Is\*Provisioned()](#312-isprovisioned) + - [3.12. Is\*Provisioned()](#312-312-isprovisioned) - [4. Examples](#4-examples) - [4.1. AddPackageAsync()](#41-addpackageasync) - [4.2. AddPackageByUriAsync()](#42-addpackagebyuriasync) @@ -133,10 +135,10 @@ The following table shows the supported permutations of verbs and targets: Legend: -* OS = Supported by Windows (OS) APIs in the Windows.Management.Deployment.PackageManager namespace. -* WAS = Supported by Windows App SDK APIs in the +* **OS** = Supported by Windows (OS) APIs in the Windows.Management.Deployment.PackageManager namespace. +* **WAS** = Supported by Windows App SDK APIs in the Microsoft.Windows.Management.Deployment.PackageDeploymentManager namespace. -* X = Not supported +* **X** = Not supported ## 3.2. Is\*Ready() @@ -286,6 +288,50 @@ foreach (PackageSetItem psi in ps.Items) return new PackageDeploymentResult(PackageDeploymentStatus.CompletedSuccess); ``` +### 3.8.1. PackageSet Properties + +`Id` is optional. This is used primarily for logging and troubleshooting. + +`Items` is required to contain 1+ item. + +`PackageUri` is optional. This is used if a `PackageUri` is needed for a `PackageSetItem` but the +`PackageSetItem.PackageUri` is not specified. + +### 3.8.2. PackageSetItem Properties + +`Id` is required and used primarily for logging and troubleshooting. + +`MinVersion` is optional. If not set the default value is 0.0.0.0. Some verbs use this property (see below). + +`PackageFamilyName` is optional. Some verbs require this property (see below). + +`PackageUri` is optional. If a `PackageUri` is needed and this is not set the `PackageSet`'s `PackageUri` property is used. Some verbs require this property (see below). + +`ProcessorArchitectureFilter` is optional. If not set the default value is `Microsoft.Windows.ApplicationModel.DynamicDependency.PackageDependencyProcessorArchitectures.None`. Only some verbs use this property (see below). + +|Verb | MinVersion | PackageFamilyName | PackageUri | ProcessorArchitectureFilter | +|------------------------|:----------:|:-------------------------:|:----------:|:---------------------------:| +|IsReady | Used | Required | N/A | Optional | +|IsReadyOrNewerAvailable | Used | Required | N/A | Optional | +|EnsureReady | Used | Required | Used | Optional | +|Add | N/A | N/A | Used | N/A | +|Stage | N/A | N/A | USed | N/A | +|Register | N/A | N/A | Used | N/A | +|Remove | N/A | Used-if-no-PackageUri | Optional | N/A | +|Repair | N/A | Used-if-no-PackageUri | Optional | N/A | +|Reset | N/A | Used-if-no-PackageUri | Optional | N/A | +|IsProvisioned | N/A | Used | Optional | N/A | +|Provision | N/A | Used-if-no-PackageUri | Optional | N/A | +|Deprovision | N/A | Used-if-no-PackageUri | Optional | N/A | + +**Legend:** + +* **N/A** = Not applicable. This property is not used. +* **Optional** = This property is used, if specified. +* **Required** = This property is required. +* **Used** = This property is used; if not specified, the default value is used. + + ## 3.9. PackageRuntimeManager The `PackageRuntimeManager` API provides Dynamic Dependency support for PackageSet operations, @@ -347,7 +393,7 @@ package management APIs in Windows (e.g. Windows.Management.Deployment.PackageMa not PackageFamilyName. `PackageDeploymentManager` provides a richer API accepting additional identifiers. -## 3.12 Is*Provisioned() +## 3.12. Is*Provisioned() Is\*Provisioned\*() methods determine if the target is provisioned. @@ -1173,9 +1219,9 @@ namespace Microsoft.Windows.Management.Deployment //------------------------------------------------------------- // IsRegistrationPending - Boolean IsPackageRegistrationPending(String packageFamilyName); + Boolean IsPackageRegistrationPending(String packageFullName); - Boolean IsPackageRegistrationPendingForUser(String userSecurityId, String packageFamilyName); + Boolean IsPackageRegistrationPendingForUser(String userSecurityId, String packageFullName); } [contract(PackageDeploymentContract, 1)] diff --git a/test/AccessControlTests/packages.config b/test/AccessControlTests/packages.config index 3313efc9e..e0f09cb39 100644 --- a/test/AccessControlTests/packages.config +++ b/test/AccessControlTests/packages.config @@ -1,5 +1,5 @@  - + diff --git a/test/AppLifecycle/packages.config b/test/AppLifecycle/packages.config index 1117ac430..dc444ff57 100644 --- a/test/AppLifecycle/packages.config +++ b/test/AppLifecycle/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/AppNotificationBuilderTests/packages.config b/test/AppNotificationBuilderTests/packages.config index 1117ac430..dc444ff57 100644 --- a/test/AppNotificationBuilderTests/packages.config +++ b/test/AppNotificationBuilderTests/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/AppNotificationTests/packages.config b/test/AppNotificationTests/packages.config index 1117ac430..dc444ff57 100644 --- a/test/AppNotificationTests/packages.config +++ b/test/AppNotificationTests/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/Common/packages.config b/test/Common/packages.config index 1117ac430..dc444ff57 100644 --- a/test/Common/packages.config +++ b/test/Common/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/Common/pch.h b/test/Common/pch.h index 332b96ac0..1991ea648 100644 --- a/test/Common/pch.h +++ b/test/Common/pch.h @@ -11,6 +11,7 @@ #define PCH_H #include +#include #include #include diff --git a/test/Deployment/API/packages.config b/test/Deployment/API/packages.config index 1117ac430..dc444ff57 100644 --- a/test/Deployment/API/packages.config +++ b/test/Deployment/API/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/DynamicDependency/Test_Win32/packages.config b/test/DynamicDependency/Test_Win32/packages.config index 1861ca894..9749bd814 100644 --- a/test/DynamicDependency/Test_Win32/packages.config +++ b/test/DynamicDependency/Test_Win32/packages.config @@ -1,4 +1,4 @@  - + diff --git a/test/DynamicDependency/Test_WinRT/packages.config b/test/DynamicDependency/Test_WinRT/packages.config index 1861ca894..9749bd814 100644 --- a/test/DynamicDependency/Test_WinRT/packages.config +++ b/test/DynamicDependency/Test_WinRT/packages.config @@ -1,4 +1,4 @@  - + diff --git a/test/EnvironmentManagerTests/packages.config b/test/EnvironmentManagerTests/packages.config index 1117ac430..dc444ff57 100644 --- a/test/EnvironmentManagerTests/packages.config +++ b/test/EnvironmentManagerTests/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/LRPTests/packages.config b/test/LRPTests/packages.config index 1117ac430..dc444ff57 100644 --- a/test/LRPTests/packages.config +++ b/test/LRPTests/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/PackageManager/API/PackageDeploymentManagerTests.cpp b/test/PackageManager/API/PackageDeploymentManagerTests.cpp index b4ed6f593..62b6ebf49 100644 --- a/test/PackageManager/API/PackageDeploymentManagerTests.cpp +++ b/test/PackageManager/API/PackageDeploymentManagerTests.cpp @@ -3,48 +3,19 @@ #include "pch.h" +#include "PackageDeploymentManagerTests.h" + #include namespace TD = ::Test::Diagnostics; namespace TB = ::Test::Bootstrap; namespace TP = ::Test::Packages; namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; namespace TPMT = ::Test::PackageManager::Tests; namespace Test::PackageManager::Tests { - class PackageDeploymentManagerTests_Base - { - protected: - winrt::Windows::ApplicationModel::PackageStatus GetPackageStatus(PCWSTR packageFullName) - { - return TPMT::GetPackageStatus(m_packageManager, packageFullName); - } - - void SetPackageStatus(PCWSTR packageFullName, winrt::Windows::Management::Deployment::PackageStatus status) - { - TPMT::SetPackageStatus(m_packageManager, packageFullName, status); - } - - void SetPackageStatusByPackageFamilyName(PCWSTR packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus status) - { - TPMT::SetPackageStatusByPackageFamilyName(m_packageManager, packageFamilyName, status); - } - - void ClearPackageStatus(PCWSTR packageFullName, winrt::Windows::Management::Deployment::PackageStatus status) - { - TPMT::ClearPackageStatus(m_packageManager, packageFullName, status); - } - - void ClearPackageStatusByPackageFamilyName(PCWSTR packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus status) - { - TPMT::ClearPackageStatusByPackageFamilyName(m_packageManager, packageFamilyName, status); - } - - protected: - winrt::Windows::Management::Deployment::PackageManager m_packageManager; - }; - class PackageDeploymentManagerTests : PackageDeploymentManagerTests_Base { public: @@ -59,2340 +30,42 @@ namespace Test::PackageManager::Tests WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); return true; } - RemovePackage_Blue(); - RemovePackage_Green(); - RemovePackage_Redder(); - RemovePackage_Red(); + ::TB::Setup(); return true; } TEST_CLASS_CLEANUP(ClassCleanup) { - RemovePackage_Blue(); - RemovePackage_Green(); - RemovePackage_Redder(); - RemovePackage_Red(); ::TB::Cleanup(); return true; } - TEST_METHOD(IsPackageSetReady_InvalidParameter) + TEST_METHOD(IsPackageDeploymentFeatureSupported_InvalidParameter) { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - packageDeploymentManager.IsPackageSetReady(packageSet); - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - - packageDeploymentManager.IsPackageSetReady(packageSet); - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - packageSet.Items().Append(packageSetItem); - - packageDeploymentManager.IsPackageSetReady(packageSet); - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Not a valid Package Family Name" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - packageSet.Items().Append(packageSetItem); - - packageDeploymentManager.IsPackageSetReady(packageSet); - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - packageSet.Items().Append(packageSetItem); - - packageDeploymentManager.IsPackageSetReady(packageSet); - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageUriAsString{ L"https://doesnotexist.com/assemble.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - packageSetItem.PackageUri(packageUri); - packageSet.Items().Append(packageSetItem); - - packageDeploymentManager.IsPackageSetReady(packageSet); - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - } - - TEST_METHOD(IsPackageSetReady_1_NoSuchPackage_No) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - packageSetItem.PackageUri(packageUri); - packageSet.Items().Append(packageSetItem); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(IsPackageSetReady_1_NotInstalled_No) - { - RemovePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(IsPackageSetReady_1_Registered_Yes) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(IsPackageSetReady_1_OlderRegistered_No) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; - packageSet.Items().Append(redder); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(IsPackageSetReady_1_NewerRegistered_Yes) - { - AddPackage_Redder(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(IsPackageSetReady_N_NotInstalled_No) - { - RemovePackage_Red(); - RemovePackage_Green(); - RemovePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(IsPackageSetReady_N_Registered_Yes) - { - AddPackage_Red(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(IsPackageSetReady_N_OlderRegistered_No) - { - AddPackage_Red(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; - packageSet.Items().Append(redder); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(IsPackageSetReady_N_NewerRegistered_Yes) - { - AddPackage_Redder(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(IsPackageSetReady_N_RegisteredAndNotInstalled_No) - { - AddPackage_Red(); - RemovePackage_Green(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(IsPackageSetReady_N_No_NotAllPackageStatusOK) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - AddPackage_Red(); - AddPackage_Green(); - SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); - - ClearPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_InvalidParameter) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - packageSet.Items().Append(packageSetItem); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Not a valid Package Family Name" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - packageSet.Items().Append(packageSetItem); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - packageSet.Items().Append(packageSetItem); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - - try - { - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageUriAsString{ L"file://c:/assemble.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - packageSetItem.PackageUri(packageUri); - packageSet.Items().Append(packageSetItem); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_FAIL(L"Success is not expected"); - } - catch (winrt::hresult_error& e) - { - VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); - } - } - - TEST_METHOD(EnsurePackageSetReadyAsync_1_NoSuchPackage_Fail) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - packageSetItem.PackageUri(packageUri); - packageSet.Items().Append(packageSetItem); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_1_NotInstalled_Success) - { - RemovePackageFamily_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_1_Staged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_1_Registered_Success) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_1_OlderRegistered_Success) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; - packageSet.Items().Append(redder); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_1_NewerRegistered_Success) - { - AddPackage_Redder(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_N_NotInstalled_Success) - { - RemovePackageFamily_Red(); - RemovePackage_Green(); - RemovePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_N_Registered_Success) - { - AddPackage_Red(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_N_NewerRegistered_Success) - { - AddPackage_Redder(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_N_OlderRegistered_Success) - { - AddPackage_Red(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; - packageSet.Items().Append(redder); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_N_RegisteredAndNotInstalled_Success) - { - AddPackage_Red(); - RemovePackage_Green(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_N_RegisteredAndNotInstalledAndStaged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - AddPackage_Red(); - RemovePackage_Green(); - StagePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageAsync_NoSuchPackage_Fail) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - PCWSTR package{ L"c:\\does\\not\\exist.msix" }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - } - - TEST_METHOD(AddPackageAsync_NotInstalled_Success) - { - RemovePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - } - - TEST_METHOD(AddPackageAsync_Staged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - } - - TEST_METHOD(AddPackageAsync_Registered_Success) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - } - - TEST_METHOD(AddPackageAsync_OlderRegistered_Success) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - - RemovePackage_Redder(); - } - - TEST_METHOD(AddPackageAsync_NewerRegistered_Success) - { - AddPackage_Redder(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Redder()); - - RemovePackage_Redder(); - } - - TEST_METHOD(AddPackageByUriAsync_NoSuchPackage_Fail) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - } - - TEST_METHOD(AddPackageByUriAsync_NotInstalled_Success) - { - RemovePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - } - - TEST_METHOD(AddPackageByUriAsync_Staged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - } - - TEST_METHOD(AddPackageByUriAsync_Registered_Success) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - } - - TEST_METHOD(AddPackageByUriAsync_OlderRegistered_Success) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - - RemovePackage_Redder(); - } - - TEST_METHOD(AddPackageByUriAsync_NewerRegistered_Success) - { - AddPackage_Redder(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Redder()); - - RemovePackage_Redder(); - } - - TEST_METHOD(AddPackageSetAsync_1_NoSuchPackage_Fail) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - packageSetItem.PackageUri(packageUri); - packageSet.Items().Append(packageSetItem); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageSetAsync_1_NotInstalled_Success) - { - RemovePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageSetAsync_1_Staged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageSetAsync_1_Registered_Success) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageSetAsync_1_OlderRegistered_Success) - { - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; - packageSet.Items().Append(redder); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(AddPackageSetAsync_1_NewerRegistered_Success) - { - AddPackage_Redder(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(AddPackageSetAsync_N_NotInstalled_Success) - { - RemovePackage_Red(); - RemovePackage_Green(); - RemovePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageSetAsync_N_Registered_Success) - { - AddPackage_Red(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageSetAsync_N_NewerRegistered_Success) - { - AddPackage_Redder(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(AddPackageSetAsync_N_OlderRegistered_Success) - { - AddPackage_Red(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; - packageSet.Items().Append(redder); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackage_Redder(); - } - - TEST_METHOD(AddPackageSetAsync_N_RegisteredAndNotInstalled_Success) - { - AddPackage_Red(); - RemovePackage_Green(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageSetAsync_N_RegisteredAndNotInstalledAndStaged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - AddPackage_Red(); - RemovePackage_Green(); - StagePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageAsync_NoSuchPackage_Fail) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - PCWSTR package{ L"c:\\does\\not\\exist.msix" }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - // - // NOTE: ExtendedError() should be HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) but on some platforms may be S_OK (and also ErrorText() may be empty) - VERIFY_IS_TRUE((deploymentResult.ExtendedError() == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) || (deploymentResult.ExtendedError() == S_OK), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - if (FAILED(deploymentResult.ExtendedError())) - { - VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - } - } - - TEST_METHOD(StagePackageAsync_NotInstalled_Success) - { - RemovePackageFamily_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - VERIFY_IS_TRUE(IsPackageStaged_Red()); - } - - TEST_METHOD(StagePackageAsync_Staged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - RemovePackageFamily_Red(); - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - } - - TEST_METHOD(StagePackageAsync_Registered_Success) - { - RemovePackageFamily_Red(); - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - } - - TEST_METHOD(StagePackageAsync_OlderStaged_Success) - { - RemovePackageFamily_Red(); - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_FALSE(IsPackageStaged_Redder()); - - RemovePackage_Redder(); - } - - TEST_METHOD(StagePackageAsync_NewerStaged_Success) - { - RemovePackageFamily_Redder(); - StagePackage_Redder(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Redder()); - - RemovePackageFamily_Redder(); - } - - TEST_METHOD(StagePackageByUriAsync_NoSuchPackage_Fail) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - // - // NOTE: ExtendedError() should be HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) but on some platforms may be S_OK (and also ErrorText() may be empty) - VERIFY_IS_TRUE((deploymentResult.ExtendedError() == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) || (deploymentResult.ExtendedError() == S_OK), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - if (FAILED(deploymentResult.ExtendedError())) - { - VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - } - } - - TEST_METHOD(StagePackageByUriAsync_NotInstalled_Success) - { - RemovePackageFamily_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - } - - TEST_METHOD(StagePackageByUriAsync_Staged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - RemovePackageFamily_Red(); - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - } - - TEST_METHOD(StagePackageByUriAsync_Registered_Success) - { - RemovePackageFamily_Red(); - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - } - - TEST_METHOD(StagePackageByUriAsync_OlderStaged_Success) - { - RemovePackageFamily_Red(); - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_FALSE(IsPackageStaged_Redder()); - - RemovePackageFamily_Redder(); - } - - TEST_METHOD(StagePackageByUriAsync_NewerStaged_Success) - { - RemovePackageFamily_Redder(); - StagePackage_Redder(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Redder()); - - RemovePackageFamily_Redder(); - } - - TEST_METHOD(StagePackageSetAsync_1_NoSuchPackage_Fail) - { - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - packageSetItem.PackageUri(packageUri); - packageSet.Items().Append(packageSetItem); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - // - // NOTE: ExtendedError() should be HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) but on some platforms may be S_OK (and also ErrorText() may be empty) - VERIFY_IS_TRUE((deploymentResult.ExtendedError() == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) || (deploymentResult.ExtendedError() == S_OK), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - if (FAILED(deploymentResult.ExtendedError())) - { - VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - } - - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_1_NotInstalled_Success) - { - RemovePackageFamily_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_1_Staged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - RemovePackageFamily_Red(); - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_1_Registered_Success) - { - RemovePackageFamily_Red(); - AddPackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_1_OlderStaged_Success) - { - RemovePackageFamily_Red(); - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; - packageSet.Items().Append(redder); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_FALSE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Redder()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - RemovePackageFamily_Red(); - } - - TEST_METHOD(StagePackageSetAsync_1_NewerStaged_Success) - { - RemovePackageFamily_Red(); - StagePackage_Redder(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_FALSE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Redder()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_NoSuchPackage_Fail) - { - RemovePackageFamily_Red(); - RemovePackage_Blue(); - StagePackage_Red(); - StagePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"Does.Not.Exist" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; - PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; - packageSetItem.PackageFamilyName(c_packageFamilyName); - PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; - winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; - packageSetItem.PackageUri(packageUri); - packageSet.Items().Append(packageSetItem); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); - VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - // - // NOTE: ExtendedError() should be HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) but on some platforms may be S_OK (and also ErrorText() may be empty) - VERIFY_IS_TRUE((deploymentResult.ExtendedError() == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) || (deploymentResult.ExtendedError() == S_OK), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - if (FAILED(deploymentResult.ExtendedError())) - { - VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - } - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Blue()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_NotInstalled_Success) - { - RemovePackageFamily_Red(); - RemovePackage_Green(); - RemovePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Green()); - VERIFY_IS_TRUE(IsPackageStaged_Blue()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_Staged_Success) - { - RemovePackageFamily_Red(); - RemovePackage_Green(); - RemovePackage_Blue(); - StagePackage_Red(); - StagePackage_Green(); - StagePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Green()); - VERIFY_IS_TRUE(IsPackageStaged_Blue()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_Registered_Success) - { - RemovePackageFamily_Red(); - RemovePackage_Green(); - RemovePackage_Blue(); - AddPackage_Red(); - AddPackage_Green(); - AddPackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Green()); - VERIFY_IS_TRUE(IsPackageStaged_Blue()); - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_OlderStaged_Success) - { - RemovePackageFamily_Red(); - RemovePackage_Green(); - RemovePackage_Blue(); - StagePackage_Red(); - StagePackage_Green(); - StagePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; - packageSet.Items().Append(redder); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Redder()); - VERIFY_IS_TRUE(IsPackageStaged_Green()); - VERIFY_IS_TRUE(IsPackageStaged_Blue()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_NewerStaged_Success) - { - RemovePackageFamily_Redder(); - RemovePackage_Green(); - RemovePackage_Blue(); - StagePackage_Redder(); - StagePackage_Green(); - StagePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Redder()); - VERIFY_IS_TRUE(IsPackageStaged_Green()); - VERIFY_IS_TRUE(IsPackageStaged_Blue()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_StagedAndNotInstalled_Success) - { - RemovePackageFamily_Red(); - RemovePackage_Green(); - StagePackage_Red(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Green()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_StagedAndNotInstalledAndStaged_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - RemovePackageFamily_Red(); - RemovePackage_Green(); - RemovePackage_Blue(); - StagePackage_Red(); - StagePackage_Blue(); - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(blue); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Green()); - VERIFY_IS_TRUE(IsPackageStaged_Blue()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - }; - - class PackageDeploymentManagerTests_Elevated : PackageDeploymentManagerTests_Base - { - public: - BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Elevated) - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassSetup) - { - if (!::WindowsVersion::IsWindows10_20H1OrGreater()) - { - WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); - return true; - } - - TD::DumpExecutionContext(); - - RemovePackage_Blue(); - RemovePackage_Green(); - RemovePackage_Redder(); - RemovePackage_Red(); - AddPackage_Red(); - ::TB::Setup(); - return true; - } - - TEST_CLASS_CLEANUP(ClassCleanup) - { - TD::DumpExecutionContext(); - - RemovePackage_Blue(); - RemovePackage_Green(); - RemovePackage_Redder(); - RemovePackage_Red(); - ::TB::Cleanup(); - return true; - } - - TEST_METHOD(IsPackageSetReady_1_RegisteredPackageStatusBad_No) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - AddPackage_Red(); - SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - - ClearPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_1_RegisteredPackageStatusBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - AddPackage_Red(); - SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(EnsurePackageSetReadyAsync_N_RegisteredPackageStatusOkAndBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - AddPackage_Red(); - AddPackage_Green(); - SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - - winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; - auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(AddPackageAsync_RegisteredPackageStatusBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - AddPackage_Red(); - SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - } - - TEST_METHOD(AddPackageByUriAsync_RegisteredPackageStatusBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - AddPackage_Red(); - SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageRegistered_Red()); - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - } - - TEST_METHOD(AddPackageSetAsync_1_RegisteredPackageStatusBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - AddPackage_Red(); - SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - } - - TEST_METHOD(AddPackageSetAsync_N_RegisteredPackageStatusOkAndBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - AddPackage_Red(); - AddPackage_Green(); - SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - - winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; - auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); - VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); - } - - TEST_METHOD(StagePackageAsync_StagedPackageStatusBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - RemovePackageFamily_Red(); - StagePackage_Red(); - SetPackageStatus(::TPF::Red::GetPackageFullName(), winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(IsPackageRegistered_Red()); - - const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; - const winrt::hstring package{ packagePath.c_str() }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageAsync(package, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - } - - TEST_METHOD(StagePackageByUriAsync_StagedPackageStatusBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - RemovePackageFamily_Red(); - StagePackage_Red(); - SetPackageStatusByPackageFamilyName(::TPF::Red::GetPackageFullName(), winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - - winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - } - - TEST_METHOD(StagePackageSetAsync_1_StagedPackageStatusBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - RemovePackageFamily_Red(); - StagePackage_Red(); - SetPackageStatusByPackageFamilyName(::TPF::Red::GetPackageFullName(), winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); - } - - TEST_METHOD(StagePackageSetAsync_N_StagedPackageStatusOkAndBad_Success) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") - END_TEST_METHOD_PROPERTIES() - - auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; - - RemovePackageFamily_Red(); - RemovePackage_Green(); - StagePackage_Red(); - StagePackage_Green(); - SetPackageStatusByPackageFamilyName(::TPF::Green::GetPackageFullName(), winrt::Windows::Management::Deployment::PackageStatus::Modified); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); - - winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; - PCWSTR c_packageSetId{ L"RGB" }; - packageSet.Id(c_packageSetId); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; - packageSet.Items().Append(red); - winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; - packageSet.Items().Append(green); - - winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; - auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; - VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess, deploymentResult.Status()); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); - VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); - - VERIFY_IS_TRUE(IsPackageStaged_Red()); - VERIFY_IS_TRUE(IsPackageStaged_Green()); - VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + const auto feature{ static_cast(0) }; + VERIFY_IS_FALSE(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::IsPackageDeploymentFeatureSupported(feature)); } }; } + +void Test::PackageManager::Tests::VerifyDeploymentSucceeded( + const winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentResult& deploymentResult, + PCSTR filename, + int line, + PCSTR function) +{ + WEX::Common::String source; + source.Format(L"File: %hs, Function: %hs, Line: %d", filename, function, line); + PCWSTR message{ static_cast(source) }; + + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"VERIFY Deployment Suceeded: %ls", message)); + + const bool ok{ (deploymentResult.Status() == winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedSuccess) && + (deploymentResult.Error() == S_OK) && + (deploymentResult.ExtendedError() == S_OK) && + deploymentResult.ErrorText().empty() }; + VERIFY_IS_TRUE(ok, WEX::Common::String().Format(L"Status:%d Error:0x%X ExtendedError:0x%X ErrorText:%ls %ls", + deploymentResult.Status(), deploymentResult.Error(), deploymentResult.ExtendedError(), + deploymentResult.ErrorText().c_str(), message)); +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests.h b/test/PackageManager/API/PackageDeploymentManagerTests.h new file mode 100644 index 000000000..738a4b4c4 --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests.h @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + inline bool SkipIfFeatureNotSupported( + const winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature feature, + PCWSTR message) + { + const bool isSupported{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::IsPackageDeploymentFeatureSupported(feature) }; + if (!isSupported) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, message); + } + return !isSupported; + } + + inline bool SkipIfFeatureNotSupported_PackageUriScheme_ms_uup() + { + const auto feature{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup }; + PCWSTR message{ L"ms-uup: not supported on this system. Skipping test" }; + return TPMT::SkipIfFeatureNotSupported(feature, message); + } + + inline bool SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable() + { + const auto feature{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::IsPackageReadyOrNewerAvailable }; + PCWSTR message{ L"IsPackageReadyOrNewerAvailable not supported on this system. Skipping test" }; + return TPMT::SkipIfFeatureNotSupported(feature, message); + } + + inline bool SkipIfFeatureNotSupported_RemovePackageByUri() + { + const auto feature{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::RemovePackageByUri }; + PCWSTR message{ L"RemovePackageByUri not supported on this system. Skipping test" }; + return TPMT::SkipIfFeatureNotSupported(feature, message); + } + + inline bool SkipIfFeatureNotSupported_ResetPackage() + { + const auto feature{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ResetPackage }; + PCWSTR message{ L"ResetPackage not supported on this system. Skipping test" }; + return TPMT::SkipIfFeatureNotSupported(feature, message); + } + + inline bool SkipIfFeatureNotSupported_RepairPackage() + { + const auto feature{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::RepairPackage }; + PCWSTR message{ L"RepairPackage not supported on this system. Skipping test" }; + return TPMT::SkipIfFeatureNotSupported(feature, message); + } + + inline bool SkipIfFeatureNotSupported_ProvisionPackage_Framework() + { + const auto feature{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ProvisionPackage_Framework }; + PCWSTR message{ L"ProvisionPackage.Framework not supported on this system. Skipping test" }; + return TPMT::SkipIfFeatureNotSupported(feature, message); + } + + inline bool PreBootstrap_SkipIfFeatureNotSupported( + const winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature feature, + PCWSTR message) + { + // NOTE: Some tests can't use winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature + // due to chicken/egg dependencies (can't use it before Bootstrapper's initialized but need access + // before Bootstrapper's initialized...). So we'll handle them by directly calling the FrameworkUdk + // + // NOTE: Only support necessary features here. + switch (feature) + { + case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ProvisionPackage_Framework: + { + //TODO Awaiting ProvisionPackageForAllUsersAsync() support for Framework packages + //return IsPackageDeploymentFeatureSupported(L"ProvisionPackage.Framework"); + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, message); + return true; + } + default: + { + // Unsupported pre-Bootstrap feature check + WEX::Logging::Log::Result(WEX::Logging::TestResults::Blocked, message); + VERIFY_FAIL(WEX::Common::String().Format(L"Feature:%d", static_cast(feature))); + return true; + } + } + } + + inline bool PreBootstrap_SkipIfFeatureNotSupported_ProvisionPackage_Framework() + { + const auto feature{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::ProvisionPackage_Framework }; + PCWSTR message{ L"ProvisionPackage.Framework not supported on this system. Skipping test" }; + return TPMT::PreBootstrap_SkipIfFeatureNotSupported(feature, message); + } + + void VerifyDeploymentSucceeded( + const winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentResult& deploymentResult, + PCSTR filename, + int line, + PCSTR function); + + class PackageDeploymentManagerTests_Base + { + protected: + inline bool DoNotExecuteTestMethod() const + { + return m_doNotExecuteTestMethod; + } + inline void DoNotExecuteTestMethod(const bool doNotExecuteTestMethod) + { + m_doNotExecuteTestMethod = doNotExecuteTestMethod; + } + private: + bool m_doNotExecuteTestMethod{}; + + protected: + winrt::Windows::ApplicationModel::PackageStatus GetPackageStatus(PCWSTR packageFullName) + { + return TPMT::GetPackageStatus(m_packageManager, packageFullName); + } + + void SetPackageStatus(PCWSTR packageFullName, winrt::Windows::Management::Deployment::PackageStatus status) + { + TPMT::SetPackageStatus(m_packageManager, packageFullName, status); + } + + void SetPackageStatusByPackageFamilyName(PCWSTR packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus status) + { + TPMT::SetPackageStatusByPackageFamilyName(m_packageManager, packageFamilyName, status); + } + + void ClearPackageStatus(PCWSTR packageFullName, winrt::Windows::Management::Deployment::PackageStatus status) + { + TPMT::ClearPackageStatus(m_packageManager, packageFullName, status); + } + + void ClearPackageStatusByPackageFamilyName(PCWSTR packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus status) + { + TPMT::ClearPackageStatusByPackageFamilyName(m_packageManager, packageFamilyName, status); + } + + winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentResult WaitForDeploymentOperation( + winrt::Windows::Foundation::IAsyncOperationWithProgress& deploymentOperation) + { + using namespace winrt::Windows::Foundation; + using namespace winrt::Microsoft::Windows::Management::Deployment; + AsyncOperationProgressHandler progressCallback( + [&](const IAsyncOperationWithProgress&, PackageDeploymentProgress progress) + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"...State:%d Percentage:%lf", static_cast(progress.Status), progress.Progress)); + } + ); + deploymentOperation.Progress(progressCallback); + auto deploymentResult{ deploymentOperation.get() }; + return deploymentResult; + } + + protected: + winrt::Windows::Management::Deployment::PackageManager m_packageManager; + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Add.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Add.cpp new file mode 100644 index 000000000..d0a342240 --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Add.cpp @@ -0,0 +1,700 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Add : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Add) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(AddPackageAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR package{ L"c:\\does\\not\\exist.msix" }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentResult{ packageDeploymentManager.AddPackageAsync(package, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(AddPackageAsync_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(AddPackageAsync_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(AddPackageAsync_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(AddPackageAsync_OlderRegistered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + + RemovePackage_Redder(); + } + + TEST_METHOD(AddPackageAsync_NewerRegistered_Success) + { + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Redder()); + + RemovePackage_Redder(); + } + + TEST_METHOD(AddPackageByUriAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentResult{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(AddPackageByUriAsync_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(AddPackageByUriAsync_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(AddPackageByUriAsync_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(AddPackageByUriAsync_OlderRegistered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + + RemovePackage_Redder(); + } + + TEST_METHOD(AddPackageByUriAsync_NewerRegistered_Success) + { + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Redder()); + + RemovePackage_Redder(); + } + + TEST_METHOD(AddPackageSetAsync_1_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentResult{ packageDeploymentManager.AddPackageSetAsync(packageSet, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(AddPackageSetAsync_1_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(AddPackageSetAsync_1_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(AddPackageSetAsync_1_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(AddPackageSetAsync_1_OlderRegistered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(AddPackageSetAsync_1_NewerRegistered_Success) + { + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(AddPackageSetAsync_N_NotInstalled_Success) + { + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(AddPackageSetAsync_N_Registered_Success) + { + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(AddPackageSetAsync_N_NewerRegistered_Success) + { + AddPackage_Redder(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(AddPackageSetAsync_N_OlderRegistered_Success) + { + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(AddPackageSetAsync_N_RegisteredAndNotInstalled_Success) + { + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(AddPackageSetAsync_N_RegisteredAndNotInstalledAndStaged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + AddPackage_Red(); + RemovePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + }; + + class PackageDeploymentManagerTests_Add_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Add_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + AddPackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(AddPackageAsync_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(AddPackageByUriAsync_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(AddPackageSetAsync_1_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(AddPackageSetAsync_N_RegisteredPackageStatusOkAndBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + AddPackage_Green(); + SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::AddPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.AddPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + } + + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Deprovision_Framework.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Deprovision_Framework.cpp new file mode 100644 index 000000000..68840170d --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Deprovision_Framework.cpp @@ -0,0 +1,637 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Deprovision_Framework : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Deprovision_Framework) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunFixtureAs", L"ElevatedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + if (TPMT::PreBootstrap_SkipIfFeatureNotSupported_ProvisionPackage_Framework()) + { + return true; + } + + RemovePackage_Red(); + AddPackage_Red(); + ProvisionPackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + DeprovisionPackage_Red(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(DeprovisionPackageAsync_Registered_AccessDenied) + { + AddPackage_Red(); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_ACCESSDENIED, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + }; + + class PackageDeploymentManagerTests_Deprovision_Framework_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Deprovision_Framework_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + TEST_CLASS_PROPERTY(L"RunFixtureAs", L"ElevatedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + if (TPMT::PreBootstrap_SkipIfFeatureNotSupported_ProvisionPackage_Framework()) + { + return true; + } + + TD::DumpExecutionContext(); + + DeprovisionPackage_Blue(); + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + DeprovisionPackage_Blue(); + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(DeprovisionPackageAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + + auto deploymentResult{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(DeprovisionPackageAsync_Staged_Success) + { + DeprovisionPackage_Red(); + StagePackage_Red(); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(DeprovisionPackageAsync_Registered_Success) + { + DeprovisionPackage_Red(); + AddPackage_Red(); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(DeprovisionPackageAsync_StagedProvisioned_Success) + { + DeprovisionPackage_Red(); + StagePackage_Red(); + ProvisionPackage_Red(); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(DeprovisionPackageAsync_RegisteredProvisioned_Success) + { + AddPackage_Red(); + ProvisionPackage_Red(); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(DeprovisionPackageAsync_RegisteredPackageStatusBad_Success) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + DeprovisionPackage_Red(); + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_Staged_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_StagedProvisioned_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_RegisteredProvisioned_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_RegisteredPackageStatusBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + packageSet.Items().Append(packageSetItem); + + auto deploymentResult{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_Staged_Success) + { + DeprovisionPackage_Red(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_Registered_Success) + { + DeprovisionPackage_Red(); + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_StagedProvisioned_Success) + { + DeprovisionPackage_Red(); + StagePackage_Red(); + ProvisionPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_RegisteredProvisioned_Success) + { + DeprovisionPackage_Red(); + AddPackage_Red(); + ProvisionPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_Staged_Success) + { + DeprovisionPackage_Red(); + DeprovisionPackage_Green(); + DeprovisionPackage_Blue(); + StagePackage_Red(); + StagePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_Registered_Success) + { + DeprovisionPackage_Red(); + DeprovisionPackage_Green(); + DeprovisionPackage_Blue(); + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_StagedProvisioned_Success) + { + DeprovisionPackage_Red(); + DeprovisionPackage_Green(); + DeprovisionPackage_Blue(); + StagePackage_Red(); + StagePackage_Green(); + StagePackage_Blue(); + ProvisionPackage_Red(); + ProvisionPackage_Green(); + ProvisionPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_RegisteredProvisioned_Success) + { + DeprovisionPackage_Red(); + DeprovisionPackage_Green(); + DeprovisionPackage_Blue(); + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + ProvisionPackage_Red(); + ProvisionPackage_Green(); + ProvisionPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_RegisteredAndNoSuchPackage_Fail) + { + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_RegisteredAndNoSuchPackageAndStaged_Fail) + { + DeprovisionPackage_Blue(); + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + AddPackage_Red(); + RemovePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(IsPackageRegistered_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(IsPackageRegistered_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Deprovision_Main.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Deprovision_Main.cpp new file mode 100644 index 000000000..dc0796016 --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Deprovision_Main.cpp @@ -0,0 +1,702 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Deprovision_Main : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Deprovision_Main) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunFixtureAs", L"ElevatedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + DoNotExecuteTestMethod(true); + return true; + } + + if (TPMT::PreBootstrap_SkipIfFeatureNotSupported_ProvisionPackage_Framework()) + { + DoNotExecuteTestMethod(true); + return true; + } + + RemovePackage_Black(); + AddPackage_Black(); + ProvisionPackage_Black(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + DeprovisionPackage_Black(); + RemovePackage_Black(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(DeprovisionPackageAsync_Registered_AccessDenied) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + AddPackage_Black(); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPM::Black::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_ACCESSDENIED, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + }; + + class PackageDeploymentManagerTests_Deprovision_Main_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Deprovision_Main_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + TEST_CLASS_PROPERTY(L"RunFixtureAs", L"ElevatedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + DoNotExecuteTestMethod(true); + return true; + } + + if (TPMT::PreBootstrap_SkipIfFeatureNotSupported_ProvisionPackage_Framework()) + { + DoNotExecuteTestMethod(true); + return true; + } + + TD::DumpExecutionContext(); + + DeprovisionPackage_White(); + DeprovisionPackage_Black(); + RemovePackage_White(); + RemovePackage_Blacker(); + RemovePackage_Black(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + DeprovisionPackage_White(); + DeprovisionPackage_Black(); + RemovePackage_White(); + RemovePackage_Blacker(); + RemovePackage_Black(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(DeprovisionPackageAsync_NoSuchPackage_Fail) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + + auto deploymentResult{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(DeprovisionPackageAsync_Staged_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + StagePackage_Black(); + + VERIFY_IS_TRUE(IsPackageStaged_Black()); + VERIFY_IS_FALSE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageProvisioned_Black()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPM::Black::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Black()); + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_TRUE(IsPackageProvisioned_Black()); + } + + TEST_METHOD(DeprovisionPackageAsync_Registered_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + AddPackage_Black(); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageProvisioned_Black()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPM::Black::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageProvisioned_Black()); + } + + TEST_METHOD(DeprovisionPackageAsync_StagedProvisioned_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + StagePackage_Black(); + ProvisionPackage_Black(); + + VERIFY_IS_TRUE(IsPackageStaged_Black()); + VERIFY_IS_FALSE(IsPackageRegistered_Black()); + VERIFY_IS_TRUE(IsPackageProvisioned_Black()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPM::Black::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Black()); + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageProvisioned_Black()); + } + + TEST_METHOD(DeprovisionPackageAsync_RegisteredProvisioned_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + AddPackage_Black(); + ProvisionPackage_Black(); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_TRUE(IsPackageProvisioned_Black()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPM::Black::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageProvisioned_Black()); + } + + TEST_METHOD(DeprovisionPackageAsync_RegisteredPackageStatusBad_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + DeprovisionPackage_Black(); + AddPackage_Black(); + SetPackageStatusByPackageFamilyName(::TPM::Black::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPM::Black::GetPackageFullName())); + VERIFY_IS_FALSE(IsPackageProvisioned_Black()); + + const auto packageFamilyName{ ::TPM::Black::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPM::Black::GetPackageFullName())); + VERIFY_IS_TRUE(IsPackageProvisioned_Black()); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_Staged_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_StagedProvisioned_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_RegisteredProvisioned_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageByUriAsync_RegisteredPackageStatusBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_NoSuchPackage_Fail) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + packageSet.Items().Append(packageSetItem); + + auto deploymentResult{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_Staged_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + StagePackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + black.PackageUri(packageUri); + packageSet.Items().Append(black); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_Registered_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + AddPackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + black.PackageUri(packageUri); + packageSet.Items().Append(black); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_StagedProvisioned_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + StagePackage_Black(); + ProvisionPackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + black.PackageUri(packageUri); + packageSet.Items().Append(black); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_1_RegisteredProvisioned_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + AddPackage_Black(); + ProvisionPackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + black.PackageUri(packageUri); + packageSet.Items().Append(black); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_Staged_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + DeprovisionPackage_White(); + StagePackage_Black(); + StagePackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + packageSet.Items().Append(black); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem(::TPM::White::GetPackageFullName(), ::TPM::White::c_packageDirName) }; + packageSet.Items().Append(white); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_Registered_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + DeprovisionPackage_White(); + AddPackage_Black(); + AddPackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + packageSet.Items().Append(black); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem(::TPM::White::GetPackageFullName(), ::TPM::White::c_packageDirName) }; + packageSet.Items().Append(white); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_StagedProvisioned_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + DeprovisionPackage_White(); + StagePackage_Black(); + StagePackage_White(); + ProvisionPackage_Black(); + ProvisionPackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + packageSet.Items().Append(black); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem(::TPM::White::GetPackageFullName(), ::TPM::White::c_packageDirName) }; + packageSet.Items().Append(white); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_RegisteredProvisioned_Success) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_Black(); + DeprovisionPackage_White(); + AddPackage_Black(); + AddPackage_White(); + ProvisionPackage_Black(); + ProvisionPackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + packageSet.Items().Append(black); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem(::TPM::White::GetPackageFullName(), ::TPM::White::c_packageDirName) }; + packageSet.Items().Append(white); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_RegisteredAndNoSuchPackage_Fail) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_White(); + DeprovisionPackage_Black(); + AddPackage_Black(); + RemovePackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + packageSet.Items().Append(black); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem(::TPM::White::GetPackageFullName(), ::TPM::White::c_packageDirName) }; + packageSet.Items().Append(white); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageRegistered_White()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageRegistered_White()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(DeprovisionPackageSetAsync_N_RegisteredAndNoSuchPackageAndStaged_Fail) + { + if (DoNotExecuteTestMethod()) + { + return; + } + + DeprovisionPackage_White(); + DeprovisionPackage_Black(); + AddPackage_Black(); + RemovePackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + packageSet.Items().Append(black); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem(::TPM::White::GetPackageFullName(), ::TPM::White::c_packageDirName) }; + packageSet.Items().Append(white); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageRegistered_White()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + auto deploymentOperation{ packageDeploymentManager.DeprovisionPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + VERIFY_IS_FALSE(IsPackageRegistered_White()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_EnsureReady.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_EnsureReady.cpp new file mode 100644 index 000000000..04d22ab0a --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_EnsureReady.cpp @@ -0,0 +1,551 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_EnsureReady : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_EnsureReady) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(EnsurePackageSetReadyAsync_InvalidParameter) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Not a valid Package Family Name" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageUriAsString{ L"file://c:/assemble.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentResult{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options).get() }; + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + } + + TEST_METHOD(EnsurePackageSetReadyAsync_1_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_1_NotInstalled_Success) + { + RemovePackageFamily_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_1_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_1_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_1_OlderRegistered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_1_NewerRegistered_Success) + { + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_N_NotInstalled_Success) + { + RemovePackageFamily_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_N_Registered_Success) + { + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_N_NewerRegistered_Success) + { + AddPackage_Redder(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_N_OlderRegistered_Success) + { + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_N_RegisteredAndNotInstalled_Success) + { + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_N_RegisteredAndNotInstalledAndStaged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + AddPackage_Red(); + RemovePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + }; + + class PackageDeploymentManagerTests_EnsureReady_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_EnsureReady_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + AddPackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(EnsurePackageSetReadyAsync_1_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(EnsurePackageSetReadyAsync_N_RegisteredPackageStatusOkAndBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + AddPackage_Green(); + SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::EnsureReadyOptions options; + auto deploymentOperation{ packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_IsPackageRegistrationPending.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_IsPackageRegistrationPending.cpp new file mode 100644 index 000000000..17155ce4e --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_IsPackageRegistrationPending.cpp @@ -0,0 +1,163 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_IsPackageRegistrationPending : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_IsPackageRegistrationPending) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blacker(); + RemovePackage_Black(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blacker(); + RemovePackage_Black(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(IsPackageRegistrationPending_NoSuchPackage) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ L"Does.Not.Exist_0.0.0.0_neutral__1234567890abc" }; + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageRegistrationPending(packageFullName)); + } + + TEST_METHOD(IsPackageRegistrationPending_NotInstalled) + { + RemovePackage_Blacker(); + RemovePackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFullName{ ::TPM::Black::GetPackageFullName() }; + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageRegistrationPending(packageFullName)); + } + + TEST_METHOD(IsPackageRegistrationPending_Registered) + { + RemovePackage_Blacker(); + AddPackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPM::Black::GetPackageFullName() }; + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageRegistrationPending(packageFullName)); + } + + TEST_METHOD(IsPackageRegistrationPending_Pending) + { + RemovePackage_Blacker(); + AddPackage_Black(); + + PCWSTR eventName{ L"PackageManagerTests.IsPackageRegistrationPending_Pending.EndOfTheLine" }; + wil::unique_event_nothrow endOfTheLine{ ::CreateEventW(nullptr, TRUE, FALSE, eventName) }; + if (!endOfTheLine) + { + const auto rc{ GetLastError() }; + VERIFY_FAIL(WEX::Common::String().Format(L"CreateEventW() LastError:%u (0x%08X)", rc, rc)); + } + wil::com_ptr AAM{ wil::CoCreateInstance(CLSID_ApplicationActivationManager, CLSCTX_LOCAL_SERVER) }; + PCWSTR appUserModelId{ ::TPM::Black::c_appUserModelId }; + DWORD processId{}; + VERIFY_SUCCEEDED(AAM->ActivateApplication(appUserModelId, eventName, AO_NONE, &processId)); + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"AppUserModleId:%s Arguments:%s ProcessId:%u", appUserModelId, eventName, processId)); + + AddPackageDefer_Blacker(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPM::Black::GetPackageFullName() }; + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageRegistrationPending(packageFullName)); + + VERIFY_SUCCEEDED(LOG_IF_WIN32_BOOL_FALSE(::SetEvent(endOfTheLine.get()))); + } + + TEST_METHOD(IsPackageRegistrationPendingForUser_NoSuchPackage) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ L"Does.Not.Exist_0.0.0.0_neutral__1234567890abc" }; + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageRegistrationPendingForUser(winrt::hstring{}, packageFullName)); + } + + TEST_METHOD(IsPackageRegistrationPendingForUser_NotInstalled) + { + RemovePackage_Blacker(); + RemovePackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPM::Black::GetPackageFullName() }; + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageRegistrationPendingForUser(winrt::hstring{}, packageFullName)); + } + + TEST_METHOD(IsPackageRegistrationPendingForUser_Registered) + { + RemovePackage_Blacker(); + AddPackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPM::Black::GetPackageFullName() }; + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageRegistrationPendingForUser(winrt::hstring{}, packageFullName)); + } + + TEST_METHOD(IsPackageRegistrationPendingForUser_Pending) + { + RemovePackage_Blacker(); + AddPackage_Black(); + + PCWSTR eventName{ L"PackageManagerTests.IsPackageRegistrationPendingForUser_Pending.EndOfTheLine" }; + wil::unique_event_nothrow endOfTheLine{ ::CreateEventW(nullptr, TRUE, FALSE, eventName) }; + if (!endOfTheLine) + { + const auto rc{ GetLastError() }; + VERIFY_FAIL(WEX::Common::String().Format(L"CreateEventW() LastError:%u (0x%08X)", rc, rc)); + } + wil::com_ptr AAM{ wil::CoCreateInstance(CLSID_ApplicationActivationManager, CLSCTX_LOCAL_SERVER) }; + PCWSTR appUserModelId{ ::TPM::Black::c_appUserModelId }; + DWORD processId{}; + VERIFY_SUCCEEDED(AAM->ActivateApplication(appUserModelId, eventName, AO_NONE, &processId)); + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"AppUserModleId:%s Arguments:%s ProcessId:%u", appUserModelId, eventName, processId)); + + AddPackageDefer_Blacker(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPM::Black::GetPackageFullName() }; + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageRegistrationPendingForUser(winrt::hstring{}, packageFullName)); + + VERIFY_SUCCEEDED(LOG_IF_WIN32_BOOL_FALSE(::SetEvent(endOfTheLine.get()))); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_IsReady.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_IsReady.cpp new file mode 100644 index 000000000..7faf3387b --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_IsReady.cpp @@ -0,0 +1,416 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_IsReady : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_IsReady) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(IsPackageReady_InvalidParameter) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + try + { + PCWSTR packageFullName{ L"Not a valid Package Full Name" }; + packageDeploymentManager.IsPackageReady(packageFullName); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + } + + TEST_METHOD(IsPackageReady_NoSuchPackage_No) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageFullName{ L"Does.Not.Exist_1.2.3.4_neutral__1234567890abc" }; + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(c_packageFullName)); + } + + TEST_METHOD(IsPackageReady_NotInstalled_No) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPF::Red::GetPackageFullName() }; + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(packageFullName)); + } + + TEST_METHOD(IsPackageReady_Registered_Yes) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPF::Red::GetPackageFullName() }; + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(packageFullName)); + } + + TEST_METHOD(IsPackageReady_OlderRegistered_No) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPF::Redder::GetPackageFullName() }; + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(packageFullName)); + } + + TEST_METHOD(IsPackageReady_NewerRegistered_Yes) + { + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPF::Red::GetPackageFullName() }; + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(packageFullName)); + + RemovePackage_Redder(); + } + + TEST_METHOD(IsPackageSetReady_InvalidParameter) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + packageDeploymentManager.IsPackageSetReady(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + + packageDeploymentManager.IsPackageSetReady(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + packageSet.Items().Append(packageSetItem); + + packageDeploymentManager.IsPackageSetReady(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Not a valid Package Family Name" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + packageSet.Items().Append(packageSetItem); + + packageDeploymentManager.IsPackageSetReady(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageUriAsString{ L"https://doesnotexist.com/assemble.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + packageDeploymentManager.IsPackageSetReady(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + } + + TEST_METHOD(IsPackageSetReady_1_NoSuchPackage_No) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(IsPackageSetReady_1_NotInstalled_No) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(IsPackageSetReady_1_Registered_Yes) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(IsPackageSetReady_1_OlderRegistered_No) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(IsPackageSetReady_1_NewerRegistered_Yes) + { + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(IsPackageSetReady_N_NotInstalled_No) + { + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(IsPackageSetReady_N_Registered_Yes) + { + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(IsPackageSetReady_N_OlderRegistered_No) + { + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(IsPackageSetReady_N_NewerRegistered_Yes) + { + AddPackage_Redder(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(IsPackageSetReady_N_RegisteredAndNotInstalled_No) + { + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(IsPackageSetReady_N_No_NotAllPackageStatusOK) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + AddPackage_Green(); + SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + + ClearPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_IsReadyOrNewerAvailable.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_IsReadyOrNewerAvailable.cpp new file mode 100644 index 000000000..9a2b56a97 --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_IsReadyOrNewerAvailable.cpp @@ -0,0 +1,834 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_IsReadyOrNewerAvailable : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_IsReadyOrNewerAvailable) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFullName_InvalidParameter) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + try + { + PCWSTR packageFullName{ L"Not a valid Package Full Name" }; + packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFullName); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFullName_NoSuchPackage_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageFullName{ L"Does.Not.Exist_1.2.3.4_neutral__1234567890abc" }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageReadyOrNewerAvailable(c_packageFullName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFullName_NotInstalled_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPF::Red::GetPackageFullName() }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFullName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFullName_Registered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPF::Red::GetPackageFullName() }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFullName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFullName_OlderRegistered_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPF::Redder::GetPackageFullName() }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFullName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFullName_NewerRegistered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPF::Red::GetPackageFullName() }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFullName)); + + RemovePackage_Redder(); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFullName_NewerAvailable) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + RemovePackage_Blacker(); + AddPackage_Black(); + StagePackage_Blacker(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ ::TPM::Black::GetPackageFullName() }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFullName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFamilyName_InvalidParameter) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + try + { + PCWSTR packageFamilyName{ L"Not a valid Package Family Name" }; + packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFamilyName); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFamilyName_NoSuchPackage_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageReadyOrNewerAvailable(c_packageFamilyName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFamilyName_NotInstalled_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFamilyName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFamilyName_Registered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFamilyName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFamilyName_OlderRegistered_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ ::TPF::Redder::c_packageFamilyName }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFamilyName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFamilyName_NewerRegistered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFamilyName)); + + RemovePackage_Redder(); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailable_PackageFamilyName_NewerAvailable) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + RemovePackage_Blacker(); + AddPackage_Black(); + StagePackage_Blacker(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ ::TPM::Black::c_packageFamilyName }; + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable, packageDeploymentManager.IsPackageReadyOrNewerAvailable(packageFamilyName)); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailableByUri_InvalidParameter) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailableByUri_NoSuchPackage_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailableByUri_NotInstalled_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailableByUri_Registered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailableByUri_OlderRegistered_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(IsPackageReadyOrNewerAvailableByUri_NewerRegistered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_InvalidParameter) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + + packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + packageSet.Items().Append(packageSetItem); + + packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Not a valid Package Family Name" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + packageSet.Items().Append(packageSetItem); + + packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + packageSet.Items().Append(packageSetItem); + + packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + + try + { + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageUriAsString{ L"https://doesnotexist.com/assemble.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet); + VERIFY_FAIL(L"Success is not expected"); + } + catch (winrt::hresult_error& e) + { + VERIFY_ARE_EQUAL(E_INVALIDARG, e.code(), WEX::Common::String().Format(L"0x%X %s", e.code(), e.message().c_str())); + } + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_1_NoSuchPackage_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_1_NotInstalled_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_1_Registered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_1_OlderRegistered_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_1_NewerRegistered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_1_NewerAvailable) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + RemovePackage_Blacker(); + AddPackage_Black(); + StagePackage_Blacker(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"B" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + packageSet.Items().Append(black); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_N_NotInstalled_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_N_Registered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_N_OlderRegistered_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_N_NewerRegistered_Ready) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Redder(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::Ready, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + + RemovePackage_Redder(); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_N_RegisteredAndNotInstalled_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_N_RegisteredAndNewerAvailable_NotReady) + { + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + AddPackage_Black(); + RemovePackage_Whiter(); + AddPackage_White(); + StagePackage_Whiter(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"BW" }; + packageSet.Id(c_packageSetId); + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem(::TPM::Black::GetPackageFullName(), ::TPM::Black::c_packageDirName) }; + packageSet.Items().Append(black); + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem(::TPM::White::GetPackageFullName(), ::TPM::White::c_packageDirName) }; + packageSet.Items().Append(white); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NewerAvailable, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + } + + TEST_METHOD(IsPackageSetReadyOrNewerAvailable_N_No_NotAllPackageStatusOK) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_IsPackageReadyOrNewerAvailable()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + AddPackage_Green(); + SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageReadyOrNewerAvailable(::TPF::Green::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageSetReadyOrNewerAvailable(packageSet)); + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageReadyOrNewerAvailableStatus::NotReady, packageDeploymentManager.IsPackageReadyOrNewerAvailable(::TPF::Green::GetPackageFullName())); + + ClearPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + } + }; + + class PackageDeploymentManagerTests_IsReadyOrNewerAvailable_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_IsReadyOrNewerAvailable_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + AddPackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(IsPackageSetReady_1_RegisteredPackageStatusBad_No) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + ClearPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Provision.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Provision.cpp new file mode 100644 index 000000000..fd11abd05 --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Provision.cpp @@ -0,0 +1,722 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Provision : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Provision) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { +#if !defined(TODO_Not_Latest_Platform_SDK) + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Provision* requires latest platform SDK. Skipping tests"); + return true; +#else + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Red(); + ::TB::Setup(); + return true; +#endif + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { +#if !defined(TODO_Not_Latest_Platform_SDK) + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Provision* requires latest platform SDK. Skipping tests"); + return true; +#else + RemovePackage_Red(); + ::TB::Cleanup(); + return true; +#endif + } + + TEST_METHOD(ProvisionPackageAsync_Registered_AccessDenied) + { + AddPackage_Red(); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_ACCESSDENIED, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + }; + + class PackageDeploymentManagerTests_Provision_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Provision_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + TEST_CLASS_PROPERTY(L"RunFixtureAs", L"ElevatedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { +#if !defined(TODO_Not_Latest_Platform_SDK) + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Provision* requires latest platform SDK. Skipping tests"); + return true; +#else + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + TD::DumpExecutionContext(); + + DeprovisionPackage_Blue(); + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; +#endif + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { +#if !defined(TODO_Not_Latest_Platform_SDK) + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Provision* requires latest platform SDK. Skipping tests"); + return true; +#else + TD::DumpExecutionContext(); + + DeprovisionPackage_Blue(); + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; +#endif + } + + TEST_METHOD(ProvisionPackageAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentResult{ packageDeploymentManager.ProvisionPackageAsync(packageFamilyName, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(ProvisionPackageAsync_Staged_Success) + { + DeprovisionPackage_Red(); + StagePackage_Red(); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(ProvisionPackageAsync_Registered_Success) + { + DeprovisionPackage_Red(); + AddPackage_Red(); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(ProvisionPackageAsync_StagedProvisioned_Success) + { + DeprovisionPackage_Red(); + StagePackage_Red(); + ProvisionPackage_Red(); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(ProvisionPackageAsync_RegisteredProvisioned_Success) + { + AddPackage_Red(); + ProvisionPackage_Red(); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(ProvisionPackageAsync_RegisteredPackageStatusBad_Success) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + DeprovisionPackage_Red(); + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + VERIFY_IS_FALSE(IsPackageProvisioned_Red()); + + const auto packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + VERIFY_IS_TRUE(IsPackageProvisioned_Red()); + } + + TEST_METHOD(ProvisionPackageByUriAsync_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ProvisionPackageByUriAsync_Staged_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ProvisionPackageByUriAsync_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ProvisionPackageByUriAsync_StagedProvisioned_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ProvisionPackageByUriAsync_RegisteredProvisioned_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ProvisionPackageByUriAsync_RegisteredPackageStatusBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ProvisionPackageSetAsync_1_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentResult{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(ProvisionPackageSetAsync_1_Staged_Success) + { + DeprovisionPackage_Red(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_1_Registered_Success) + { + DeprovisionPackage_Red(); + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_1_StagedProvisioned_Success) + { + DeprovisionPackage_Red(); + StagePackage_Red(); + ProvisionPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_1_RegisteredProvisioned_Success) + { + DeprovisionPackage_Red(); + AddPackage_Red(); + ProvisionPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_1_RegisteredPackageStatusBad_Success) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + DeprovisionPackage_Red(); + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_N_Staged_Success) + { + DeprovisionPackage_Red(); + DeprovisionPackage_Green(); + DeprovisionPackage_Blue(); + StagePackage_Red(); + StagePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_N_Registered_Success) + { + DeprovisionPackage_Red(); + DeprovisionPackage_Green(); + DeprovisionPackage_Blue(); + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_N_StagedProvisioned_Success) + { + DeprovisionPackage_Red(); + DeprovisionPackage_Green(); + DeprovisionPackage_Blue(); + StagePackage_Red(); + StagePackage_Green(); + StagePackage_Blue(); + ProvisionPackage_Red(); + ProvisionPackage_Green(); + ProvisionPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_N_RegisteredProvisioned_Success) + { + DeprovisionPackage_Red(); + DeprovisionPackage_Green(); + DeprovisionPackage_Blue(); + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + ProvisionPackage_Red(); + ProvisionPackage_Green(); + ProvisionPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_N_RegisteredAndNoSuchPackage_Fail) + { + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_N_RegisteredAndNoSuchPackageAndStaged_Fail) + { + DeprovisionPackage_Blue(); + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + AddPackage_Red(); + RemovePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(IsPackageRegistered_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(IsPackageRegistered_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + } + + TEST_METHOD(ProvisionPackageSetAsync_N_RegisteredPackageStatusOkAndBad_Success) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + DeprovisionPackage_Green(); + DeprovisionPackage_Red(); + AddPackage_Red(); + AddPackage_Green(); + SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Green()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetProvisioned(packageSet)); + + winrt::Microsoft::Windows::Management::Deployment::ProvisionPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.ProvisionPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Green()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + } + + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Register.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Register.cpp new file mode 100644 index 000000000..ec2cb9a6c --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Register.cpp @@ -0,0 +1,712 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +#if !defined(TODO_Register_error_0x80073D2B_ERROR_UNSIGNED_PACKAGE_INVALID_CONTENT_on_20h_vb) +#define RETURN_TRUE_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST() \ + if (!::WindowsVersion::IsWindows11_21H2OrGreater()) \ + { \ + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager.Register*() tests require >= 21H2 (SV1). Skipping tests"); \ + return true; \ + } +#define RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST() \ + if (!::WindowsVersion::IsWindows11_21H2OrGreater()) \ + { \ + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager.Register*() tests require >= 21H2 (SV1). Skipping tests"); \ + return; \ + } +#endif + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Register : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Register) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RETURN_TRUE_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + RemovePackage_White(); + RemovePackage_Blacker(); + RemovePackage_Black(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + RemovePackage_White(); + RemovePackage_Blacker(); + RemovePackage_Black(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(RegisterPackageAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR package{ L"c:\\does\\not\\exist\\appxmanifest.xml" }; + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(RegisterPackageAsync_Framework_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPF::Red::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RegisterPackageAsync_Main_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + StagePackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPM::Black::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + } + + TEST_METHOD(RegisterPackageAsync_Framework_Registered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPF::Red::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RegisterPackageAsync_Main_Registered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPM::Black::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + } + + TEST_METHOD(RegisterPackageAsync_Framework_OlderRegistered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + StagePackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPF::Redder::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Redder()); + + RemovePackage_Redder(); + } + + TEST_METHOD(RegisterPackageAsync_Main_OlderRegistered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Black(); + StagePackage_Blacker(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPM::Blacker::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Black()); + VERIFY_IS_TRUE(IsPackageRegistered_Blacker()); + + RemovePackage_Blacker(); + } + + TEST_METHOD(RegisterPackageByUriAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist/appxmanifest.xml" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_OPEN_PACKAGE_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(RegisterPackageByUriAsync_Framework_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPF::Red::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + winrt::Windows::Foundation::Uri packageUri{ package }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"packageUri: %ls", packageUri.ToString().c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RegisterPackageByUriAsync_Main_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + StagePackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPM::Black::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + winrt::Windows::Foundation::Uri packageUri{ package }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"packageUri: %ls", packageUri.ToString().c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + } + + TEST_METHOD(RegisterPackageByUriAsync_Framework_Registered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPF::Red::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + winrt::Windows::Foundation::Uri packageUri{ package }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"packageUri: %ls", packageUri.ToString().c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RegisterPackageByUriAsync_Main_Registered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPM::Black::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + winrt::Windows::Foundation::Uri packageUri{ package }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"packageUri: %ls", packageUri.ToString().c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Black()); + } + + TEST_METHOD(RegisterPackageByUriAsync_Framework_OlderRegistered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + StagePackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPF::Redder::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + winrt::Windows::Foundation::Uri packageUri{ package }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"packageUri: %ls", packageUri.ToString().c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Redder()); + + RemovePackage_Redder(); + } + + TEST_METHOD(RegisterPackageByUriAsync_Main_OlderRegistered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Black(); + StagePackage_Blacker(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto appxManifestPath{ TP::GetAppxManifestPackagePath(::TPM::Blacker::GetPackageFullName()) }; + const winrt::hstring package{ appxManifestPath.c_str() }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"package: %ls", package.c_str())); + winrt::Windows::Foundation::Uri packageUri{ package }; + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"packageUri: %ls", packageUri.ToString().c_str())); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Black()); + VERIFY_IS_TRUE(IsPackageRegistered_Blacker()); + + RemovePackage_Blacker(); + } + + TEST_METHOD(RegisterPackageSetAsync_Framework_1_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem_ForRegister(::TPF::Red::GetPackageFullName()) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RegisterPackageSetAsync_Main_1_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + StagePackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem_ForRegister(::TPM::Black::GetPackageFullName()) }; + packageSet.Items().Append(black); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RegisterPackageSetAsync_Framework_1_Registered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem_ForRegister(::TPF::Red::GetPackageFullName()) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RegisterPackageSetAsync_Main_1_Registered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Black(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"BW" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem_ForRegister(::TPM::Black::GetPackageFullName()) }; + packageSet.Items().Append(black); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RegisterPackageSetAsync_Framework_1_OlderRegistered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + StagePackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem_ForRegister(::TPF::Redder::GetPackageFullName()) }; + packageSet.Items().Append(redder); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Redder()); + + RemovePackage_Redder(); + } + + TEST_METHOD(RegisterPackageSetAsync_Main_1_OlderRegistered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Black(); + StagePackage_Blacker(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem_ForRegister(::TPM::Blacker::GetPackageFullName()) }; + packageSet.Items().Append(redder); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + VERIFY_IS_FALSE(IsPackageRegistered_Black()); + VERIFY_IS_TRUE(IsPackageRegistered_Blacker()); + + RemovePackage_Blacker(); + } + + TEST_METHOD(RegisterPackageSetAsync_Framework_N_Registered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem_ForRegister(::TPF::Red::GetPackageFullName()) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem_ForRegister(::TPF::Green::GetPackageFullName()) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem_ForRegister(::TPF::Blue::GetPackageFullName()) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RegisterPackageSetAsync_Main_N_Registered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Black(); + AddPackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"BW" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem_ForRegister(::TPM::Black::GetPackageFullName()) }; + packageSet.Items().Append(black); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem_ForRegister(::TPM::White::GetPackageFullName()) }; + packageSet.Items().Append(white); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RegisterPackageSetAsync_Framework_N_OlderRegistered_Success) + { + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + StagePackage_Redder(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem_ForRegister(::TPF::Redder::GetPackageFullName()) }; + packageSet.Items().Append(redder); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem_ForRegister(::TPF::Green::GetPackageFullName()) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem_ForRegister(::TPF::Blue::GetPackageFullName()) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(IsPackageRegistered_Redder()); + RemovePackage_Redder(); + } + + TEST_METHOD(RegisterPackageSetAsync_Main_N_OlderRegistered_Success) + { + AddPackage_Black(); + StagePackage_Blacker(); + AddPackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blacker{ Make_PackageSetItem_ForRegister(::TPM::Blacker::GetPackageFullName()) }; + packageSet.Items().Append(blacker); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem_ForRegister(::TPM::White::GetPackageFullName()) }; + packageSet.Items().Append(white); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + VERIFY_IS_FALSE(IsPackageRegistered_Black()); + VERIFY_IS_TRUE(IsPackageRegistered_Blacker()); + RemovePackage_Blacker(); + } + + TEST_METHOD(RegisterPackageSetAsync_Framework_N_RegisteredAndStaged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Red(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem_ForRegister(::TPF::Red::GetPackageFullName()) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem_ForRegister(::TPF::Blue::GetPackageFullName()) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RegisterPackageSetAsync_Main_N_RegisteredAndStaged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RETURN_IF_SKIP_ON_WIN10_DUE_TO_0x80073D2B_IN_TEST(); + + AddPackage_Black(); + StagePackage_White(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"BW" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem black{ Make_PackageSetItem_ForRegister(::TPM::Black::GetPackageFullName()) }; + packageSet.Items().Append(black); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem white{ Make_PackageSetItem_ForRegister(::TPM::White::GetPackageFullName()) }; + packageSet.Items().Append(white); + + winrt::Microsoft::Windows::Management::Deployment::RegisterPackageOptions options; + auto deploymentOperation{ packageDeploymentManager.RegisterPackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Remove.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Remove.cpp new file mode 100644 index 000000000..4db273f14 --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Remove.cpp @@ -0,0 +1,1336 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Remove : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Remove) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(RemovePackageAsync_PackageFullName_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ L"Does.Not.Exist_0.0.0.0_neutral__1234567890abc" }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentResult{ packageDeploymentManager.RemovePackageAsync(packageFullName, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(RemovePackageAsync_PackageFullName_NotInstalled_Fail) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageAsync_PackageFullName_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageAsync_PackageFullName_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageAsync_PackageFullName_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageAsync_PackageFamilyName_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentResult{ packageDeploymentManager.RemovePackageAsync(packageFamilyName, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageAsync_PackageFamilyName_NoSuchPackage_Success) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentResult{ packageDeploymentManager.RemovePackageAsync(packageFamilyName, options).get() }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageAsync_PackageFamilyName_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageAsync_PackageFamilyName_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageAsync_PackageFamilyName_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageByFullNameAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ L"Does.Not.Exist_0.0.0.0_neutral__1234567890abc" }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentResult{ packageDeploymentManager.RemovePackageByFullNameAsync(packageFullName, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(RemovePackageByFullNameAsync_NotInstalled_Fail) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageByFullNameAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageByFullNameAsync_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageByFullNameAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageByFullNameAsync_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageByFullNameAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageByFullNameAsync_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageByFullNameAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageByFamilyNameAsync_NoSuchPackage_Success) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentResult{ packageDeploymentManager.RemovePackageByFamilyNameAsync(packageFamilyName, options).get() }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + } + + TEST_METHOD(RemovePackageByFamilyNameAsync_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageByFamilyNameAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageByFamilyNameAsync_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageByFamilyNameAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageByFamilyNameAsync_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageByFamilyNameAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageByUriAsync_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RemovePackageByUri() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageUriAsString{ L"ms-uup://Product/does.not.exist" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentResult{ packageDeploymentManager.RemovePackageByUriAsync(packageUri, options).get() }; +//TODO WTH +WEX::Logging::Log::Comment(WEX::Common::String().Format(L"Status: %d", deploymentResult.Status())); +WEX::Logging::Log::Comment(WEX::Common::String().Format(L"Error: 0x%08X", deploymentResult.Error())); +WEX::Logging::Log::Comment(WEX::Common::String().Format(L"ExtendedError: 0x%08X", deploymentResult.ExtendedError())); +WEX::Logging::Log::Comment(WEX::Common::String().Format(L"ErrorText: %s", deploymentResult.ErrorText().c_str())); + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(RemovePackageByUriAsync_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RemovePackageByUri() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RemovePackageByUriAsync_NotInstalled_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RemovePackageByUri() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RemovePackageByUriAsync_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_RemovePackageByUri() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RemovePackageByUriAsync_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RemovePackageByUri() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_1_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentResult{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#else + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_1_NotInstalled_Fail) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#else + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_1_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_1_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_1_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); +#endif + } + + TEST_METHOD(RemovePackageSetAsync_Uri_N_NotInstalled_Fail) + { + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#else + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_N_NotInstalled_Success) + { + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); +#endif + } + + TEST_METHOD(RemovePackageSetAsync_Uri_N_Registered_Success) + { + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); +#endif + } + + TEST_METHOD(RemovePackageSetAsync_Uri_N_RegisteredAndNotInstalled_Success) + { + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_N_RegisteredAndNotInstalledAndStaged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + AddPackage_Red(); + RemovePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_1_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentResult{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_1_NotInstalled_Fail) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_1_NotInstalled_Success) + { + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_1_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_1_Registered_Success) + { + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_N_NotInstalled_Fail) + { + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + green.PackageUri(nullptr); + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + blue.PackageUri(nullptr); + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_N_NotInstalled_Success) + { + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + green.PackageUri(nullptr); + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + blue.PackageUri(nullptr); + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_N_Registered_Success) + { + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + green.PackageUri(nullptr); + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + blue.PackageUri(nullptr); + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_N_RegisteredAndNotInstalled_Success) + { + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + green.PackageUri(nullptr); + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_N_RegisteredAndNotInstalledAndStaged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + AddPackage_Red(); + RemovePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + red.PackageUri(nullptr); + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + green.PackageUri(nullptr); + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + blue.PackageUri(nullptr); + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + VERIFY_IS_FALSE(options.FailIfNotFound()); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + }; + + class PackageDeploymentManagerTests_Remove_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Remove_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + AddPackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(RemovePackageAsync_PackageFullName_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(RemovePackageAsync_PackageFamilyName_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(RemovePackageByFullNameAsync_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFullName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(RemovePackageByFamilyNameAsync_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageAsync(packageFamilyName, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(RemovePackageByUriAsync_RegisteredPackageStatusBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RemovePackageByUri() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_1_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(RemovePackageSetAsync_Uri_N_RegisteredPackageStatusOkAndBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + AddPackage_Green(); + SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; +#if defined(TODO_use_Platform_SDK_defining_RemovePackageOptions) + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); +#else + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(E_NOTIMPL, deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(S_OK, deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_TRUE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); +#endif + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_1_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(RemovePackageSetAsync_NoUri_N_RegisteredPackageStatusOkAndBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + AddPackage_Green(); + SetPackageStatusByPackageFamilyName(::TPF::Green::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + winrt::Windows::Foundation::Uri packageUri{ nullptr }; + red.PackageUri(packageUri); + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + green.PackageUri(packageUri); + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::RemovePackageOptions options; + options.FailIfNotFound(true); + auto deploymentOperation{ packageDeploymentManager.RemovePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Repair.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Repair.cpp new file mode 100644 index 000000000..d34310674 --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Repair.cpp @@ -0,0 +1,625 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Repair : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Repair) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(RepairPackageAsync_PackageFullName_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ L"Does.Not.Exist_0.0.0.0_neutral__1234567890abc" }; + + auto deploymentResult{ packageDeploymentManager.RepairPackageAsync(packageFullName).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(RepairPackageAsync_PackageFullName_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + auto deploymentOperation{ packageDeploymentManager.RepairPackageAsync(packageFullName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RepairPackageAsync_PackageFullName_Staged_Fail) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + auto deploymentOperation{ packageDeploymentManager.RepairPackageAsync(packageFullName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RepairPackageAsync_PackageFullName_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + auto deploymentOperation{ packageDeploymentManager.RepairPackageAsync(packageFullName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RepairPackageAsync_PackageFamilyName_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.RepairPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RepairPackageAsync_PackageFamilyName_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.RepairPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RepairPackageAsync_PackageFamilyName_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.RepairPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RepairPackageByUriAsync_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageUriAsString{ L"ms-uup://Product/does.not.exist" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + + auto deploymentResult{ packageDeploymentManager.RepairPackageByUriAsync(packageUri).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(RepairPackageByUriAsync_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RepairPackageByUriAsync_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_RepairPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RepairPackageByUriAsync_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RepairPackageSetAsync_1_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"ms-uup://Product/does.not.exist" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + auto deploymentResult{ packageDeploymentManager.RepairPackageSetAsync(packageSet).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(RepairPackageSetAsync_1_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + auto deploymentOperation{ packageDeploymentManager.RepairPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RepairPackageSetAsync_1_Staged_Fail) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + auto deploymentOperation{ packageDeploymentManager.RepairPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RepairPackageSetAsync_1_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + auto deploymentOperation{ packageDeploymentManager.RepairPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RepairPackageSetAsync_N_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + auto deploymentOperation{ packageDeploymentManager.RepairPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(RepairPackageSetAsync_N_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + auto deploymentOperation{ packageDeploymentManager.RepairPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RepairPackageSetAsync_N_RegisteredAndNotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + auto deploymentOperation{ packageDeploymentManager.RepairPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(RepairPackageSetAsync_N_RegisteredAndNotInstalledAndStaged_Fail) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + AddPackage_Red(); + RemovePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + auto deploymentOperation{ packageDeploymentManager.RepairPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + }; + + class PackageDeploymentManagerTests_Repair_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Repair_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + AddPackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(RepairPackageAsync_PackageFullName_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + auto deploymentOperation{ packageDeploymentManager.RepairPackageAsync(packageFullName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(RepairPackageAsync_PackageFamilyName_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_RepairPackage()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.RepairPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(RepairPackageByUriAsync_RegisteredPackageStatusBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RepairPackageSetAsync_1_RegisteredPackageStatusBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(RepairPackageSetAsync_N_RegisteredPackageStatusOkAndBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_RepairPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Reset.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Reset.cpp new file mode 100644 index 000000000..0c2dcc7fe --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Reset.cpp @@ -0,0 +1,641 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Reset : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Reset) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(ResetPackageAsync_PackageFullName_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR packageFullName{ L"Does.Not.Exist_0.0.0.0_neutral__1234567890abc" }; + + auto deploymentResult{ packageDeploymentManager.ResetPackageAsync(packageFullName).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(ResetPackageAsync_PackageFullName_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + auto deploymentOperation{ packageDeploymentManager.ResetPackageAsync(packageFullName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(ResetPackageAsync_PackageFullName_Staged_Fail) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + auto deploymentOperation{ packageDeploymentManager.ResetPackageAsync(packageFullName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(ResetPackageAsync_PackageFullName_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + auto deploymentOperation{ packageDeploymentManager.ResetPackageAsync(packageFullName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + +#if defined(TODO_Reset_succeed_but_IsRegistered_is_false_on_rs_prerelease_x64fre) + VERIFY_IS_TRUE(IsPackageRegistered_Red()); +#else + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"TODO: Reset succeeds but package not registered on rs_prerelease_x64fre; see error 0x80070002 in Microsoft-Windows-AppxDeploymentServer/Operational"); +#endif + } + + TEST_METHOD(ResetPackageAsync_PackageFamilyName_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.ResetPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(ResetPackageAsync_PackageFamilyName_Staged_Fail) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.ResetPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(ResetPackageAsync_PackageFamilyName_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.ResetPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + +#if defined(TODO_Reset_succeed_but_IsRegistered_is_false_on_rs_prerelease_x64fre) + VERIFY_IS_TRUE(IsPackageRegistered_Red()); +#else + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"TODO: Reset succeeds but package not registered on rs_prerelease_x64fre; see error 0x80070002 in Microsoft-Windows-AppxDeploymentServer/Operational"); +#endif + } + + TEST_METHOD(ResetPackageByUriAsync_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageUriAsString{ L"ms-uup://Product/does.not.exist" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + + auto deploymentResult{ packageDeploymentManager.ResetPackageByUriAsync(packageUri).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(ResetPackageByUriAsync_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ResetPackageByUriAsync_Staged_Fail) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_ResetPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ResetPackageByUriAsync_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ResetPackageSetAsync_1_NoSuchPackage_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + auto deploymentResult{ packageDeploymentManager.ResetPackageSetAsync(packageSet).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + TEST_METHOD(ResetPackageSetAsync_1_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + RemovePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + auto deploymentOperation{ packageDeploymentManager.ResetPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(ResetPackageSetAsync_1_Staged_Fail) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + auto deploymentOperation{ packageDeploymentManager.ResetPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(ResetPackageSetAsync_1_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + auto deploymentOperation{ packageDeploymentManager.ResetPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(ResetPackageSetAsync_N_NotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + RemovePackage_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + auto deploymentOperation{ packageDeploymentManager.ResetPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + } + + TEST_METHOD(ResetPackageSetAsync_N_Registered_Success) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + auto deploymentOperation{ packageDeploymentManager.ResetPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(ResetPackageSetAsync_N_RegisteredAndNotInstalled_Fail) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + AddPackage_Red(); + RemovePackage_Green(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + auto deploymentOperation{ packageDeploymentManager.ResetPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(ResetPackageSetAsync_N_RegisteredAndNotInstalledAndStaged_Fail) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + AddPackage_Red(); + RemovePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + auto deploymentOperation{ packageDeploymentManager.ResetPackageSetAsync(packageSet) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_PACKAGE_NOT_FOUND), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_FOUND), deploymentResult.ExtendedError(), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + }; + + class PackageDeploymentManagerTests_Reset_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Reset_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + AddPackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(ResetPackageAsync_PackageFullName_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const winrt::hstring packageFullName{ ::TPF::Red::GetPackageFullName() }; + + auto deploymentOperation{ packageDeploymentManager.ResetPackageAsync(packageFullName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + +#if defined(TODO_Reset_succeed_but_IsRegistered_is_false_on_rs_prerelease_x64fre) + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); +#else + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"TODO: Reset succeeds but package not registered on rs_prerelease_x64fre; see error 0x80070002 in Microsoft-Windows-AppxDeploymentServer/Operational"); +#endif + } + + TEST_METHOD(ResetPackageAsync_PackageFamilyName_RegisteredPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + if (TPMT::SkipIfFeatureNotSupported_ResetPackage()) + { + return; + } + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + AddPackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::c_packageFamilyName, winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + const winrt::hstring packageFamilyName{ ::TPF::Red::c_packageFamilyName }; + + auto deploymentOperation{ packageDeploymentManager.ResetPackageAsync(packageFamilyName) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + +#if defined(TODO_Reset_succeed_but_IsRegistered_is_false_on_rs_prerelease_x64fre) + VERIFY_IS_TRUE(IsPackageRegistered_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); +#else + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"TODO: Reset succeeds but package not registered on rs_prerelease_x64fre; see error 0x80070002 in Microsoft-Windows-AppxDeploymentServer/Operational"); +#endif + } + + TEST_METHOD(ResetPackageByUriAsync_RegisteredPackageStatusBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ResetPackageSetAsync_1_RegisteredPackageStatusBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + + TEST_METHOD(ResetPackageSetAsync_N_RegisteredPackageStatusOkAndBad_Success) + { + if (TPMT::SkipIfFeatureNotSupported_ResetPackage() || TPMT::SkipIfFeatureNotSupported_PackageUriScheme_ms_uup()) + { + return; + } + + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"Cannot test ms-uup: URIs here. Skipping test"); + } + }; +} diff --git a/test/PackageManager/API/PackageDeploymentManagerTests_Stage.cpp b/test/PackageManager/API/PackageDeploymentManagerTests_Stage.cpp new file mode 100644 index 000000000..5f302b58a --- /dev/null +++ b/test/PackageManager/API/PackageDeploymentManagerTests_Stage.cpp @@ -0,0 +1,839 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +#include "PackageDeploymentManagerTests.h" + +#include + +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + +namespace Test::PackageManager::Tests +{ + class PackageDeploymentManagerTests_Stage : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Stage) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(StagePackageAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR package{ L"c:\\does\\not\\exist.msix" }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentResult{ packageDeploymentManager.StagePackageAsync(package, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + // + // NOTE: ExtendedError() should be HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) but on some platforms may be S_OK (and also ErrorText() may be empty) + VERIFY_IS_TRUE((deploymentResult.ExtendedError() == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) || (deploymentResult.ExtendedError() == S_OK), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + if (FAILED(deploymentResult.ExtendedError())) + { + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + } + + TEST_METHOD(StagePackageAsync_NotInstalled_Success) + { + RemovePackageFamily_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + VERIFY_IS_TRUE(IsPackageStaged_Red()); + } + + TEST_METHOD(StagePackageAsync_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RemovePackageFamily_Red(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + } + + TEST_METHOD(StagePackageAsync_Registered_Success) + { + RemovePackageFamily_Red(); + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + } + + TEST_METHOD(StagePackageAsync_OlderStaged_Success) + { + RemovePackageFamily_Red(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(IsPackageStaged_Redder()); + + RemovePackage_Redder(); + } + + TEST_METHOD(StagePackageAsync_NewerStaged_Success) + { + RemovePackageFamily_Redder(); + StagePackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Redder()); + + RemovePackageFamily_Redder(); + } + + TEST_METHOD(StagePackageByUriAsync_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentResult{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + // + // NOTE: ExtendedError() should be HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) but on some platforms may be S_OK (and also ErrorText() may be empty) + VERIFY_IS_TRUE((deploymentResult.ExtendedError() == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) || (deploymentResult.ExtendedError() == S_OK), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + if (FAILED(deploymentResult.ExtendedError())) + { + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + } + + TEST_METHOD(StagePackageByUriAsync_NotInstalled_Success) + { + RemovePackageFamily_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + } + + TEST_METHOD(StagePackageByUriAsync_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RemovePackageFamily_Red(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + } + + TEST_METHOD(StagePackageByUriAsync_Registered_Success) + { + RemovePackageFamily_Red(); + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + } + + TEST_METHOD(StagePackageByUriAsync_OlderStaged_Success) + { + RemovePackageFamily_Red(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(IsPackageStaged_Redder()); + + RemovePackageFamily_Redder(); + } + + TEST_METHOD(StagePackageByUriAsync_NewerStaged_Success) + { + RemovePackageFamily_Redder(); + StagePackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Redder()); + + RemovePackageFamily_Redder(); + } + + TEST_METHOD(StagePackageSetAsync_1_NoSuchPackage_Fail) + { + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + // + // NOTE: ExtendedError() should be HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) but on some platforms may be S_OK (and also ErrorText() may be empty) + VERIFY_IS_TRUE((deploymentResult.ExtendedError() == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) || (deploymentResult.ExtendedError() == S_OK), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + if (FAILED(deploymentResult.ExtendedError())) + { + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_1_NotInstalled_Success) + { + RemovePackageFamily_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_1_Staged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RemovePackageFamily_Red(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_1_Registered_Success) + { + RemovePackageFamily_Red(); + AddPackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_1_OlderStaged_Success) + { + RemovePackageFamily_Red(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Redder()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + + RemovePackageFamily_Red(); + } + + TEST_METHOD(StagePackageSetAsync_1_NewerStaged_Success) + { + RemovePackageFamily_Red(); + StagePackage_Redder(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_FALSE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Redder()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_NoSuchPackage_Fail) + { + RemovePackageFamily_Red(); + RemovePackage_Blue(); + StagePackage_Red(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"Does.Not.Exist" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem packageSetItem; + PCWSTR c_packageFamilyName{ L"Does.Not.Exist_1234567890abc" }; + packageSetItem.PackageFamilyName(c_packageFamilyName); + PCWSTR c_packageUriAsString{ L"file://c:/does/not/exist.msix" }; + winrt::Windows::Foundation::Uri packageUri{ c_packageUriAsString }; + packageSetItem.PackageUri(packageUri); + packageSet.Items().Append(packageSetItem); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentResult{ packageDeploymentManager.StagePackageSetAsync(packageSet, options).get() }; + VERIFY_ARE_EQUAL(winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentStatus::CompletedFailure, deploymentResult.Status()); + VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_INSTALL_FAILED), deploymentResult.Error(), WEX::Common::String().Format(L"0x%X", deploymentResult.Error())); + // + // NOTE: ExtendedError() should be HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) but on some platforms may be S_OK (and also ErrorText() may be empty) + VERIFY_IS_TRUE((deploymentResult.ExtendedError() == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) || (deploymentResult.ExtendedError() == S_OK), WEX::Common::String().Format(L"0x%X", deploymentResult.ExtendedError())); + if (FAILED(deploymentResult.ExtendedError())) + { + VERIFY_IS_FALSE(deploymentResult.ErrorText().empty(), WEX::Common::String().Format(L"%s", deploymentResult.ErrorText().c_str())); + } + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_NotInstalled_Success) + { + RemovePackageFamily_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Green()); + VERIFY_IS_TRUE(IsPackageStaged_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_Staged_Success) + { + RemovePackageFamily_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + StagePackage_Red(); + StagePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Green()); + VERIFY_IS_TRUE(IsPackageStaged_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_Registered_Success) + { + RemovePackageFamily_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + AddPackage_Red(); + AddPackage_Green(); + AddPackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Green()); + VERIFY_IS_TRUE(IsPackageStaged_Blue()); + VERIFY_IS_TRUE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_OlderStaged_Success) + { + RemovePackageFamily_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + StagePackage_Red(); + StagePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem redder{ Make_PackageSetItem(::TPF::Redder::GetPackageFullName(), ::TPF::Redder::c_packageDirName) }; + packageSet.Items().Append(redder); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Redder()); + VERIFY_IS_TRUE(IsPackageStaged_Green()); + VERIFY_IS_TRUE(IsPackageStaged_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_NewerStaged_Success) + { + RemovePackageFamily_Redder(); + RemovePackage_Green(); + RemovePackage_Blue(); + StagePackage_Redder(); + StagePackage_Green(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Redder()); + VERIFY_IS_TRUE(IsPackageStaged_Green()); + VERIFY_IS_TRUE(IsPackageStaged_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_StagedAndNotInstalled_Success) + { + RemovePackageFamily_Red(); + RemovePackage_Green(); + StagePackage_Red(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Green()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_StagedAndNotInstalledAndStaged_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + RemovePackageFamily_Red(); + RemovePackage_Green(); + RemovePackage_Blue(); + StagePackage_Red(); + StagePackage_Blue(); + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem blue{ Make_PackageSetItem(::TPF::Blue::GetPackageFullName(), ::TPF::Blue::c_packageDirName) }; + packageSet.Items().Append(blue); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Green()); + VERIFY_IS_TRUE(IsPackageStaged_Blue()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + }; + + class PackageDeploymentManagerTests_Stage_Elevated : PackageDeploymentManagerTests_Base + { + public: + BEGIN_TEST_CLASS(PackageDeploymentManagerTests_Stage_Elevated) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassSetup) + { + if (!::WindowsVersion::IsWindows10_20H1OrGreater()) + { + WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"PackageDeploymentManager requires >= 20H1 (Vibranium). Skipping tests"); + return true; + } + + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + AddPackage_Red(); + ::TB::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassCleanup) + { + TD::DumpExecutionContext(); + + RemovePackage_Blue(); + RemovePackage_Green(); + RemovePackage_Redder(); + RemovePackage_Red(); + ::TB::Cleanup(); + return true; + } + + TEST_METHOD(StagePackageAsync_StagedPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + RemovePackageFamily_Red(); + StagePackage_Red(); + SetPackageStatus(::TPF::Red::GetPackageFullName(), winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(IsPackageRegistered_Red()); + + const auto packagePath{ TP::GetMsixPackagePath(::TPF::Red::c_packageDirName) }; + const winrt::hstring package{ packagePath.c_str() }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageAsync(package, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(StagePackageByUriAsync_StagedPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + RemovePackageFamily_Red(); + StagePackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::GetPackageFullName(), winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + winrt::Windows::Foundation::Uri packageUri{ TP::GetMsixPackageUri(::TPF::Red::c_packageDirName) }; + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageByUriAsync(packageUri, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + } + + TEST_METHOD(StagePackageSetAsync_1_StagedPackageStatusBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + RemovePackageFamily_Red(); + StagePackage_Red(); + SetPackageStatusByPackageFamilyName(::TPF::Red::GetPackageFullName(), winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Red::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageSetReady(packageSet)); + } + + TEST_METHOD(StagePackageSetAsync_N_StagedPackageStatusOkAndBad_Success) + { + BEGIN_TEST_METHOD_PROPERTIES() + TEST_CLASS_PROPERTY(L"RunAs", L"ElevatedUser") + END_TEST_METHOD_PROPERTIES() + + auto packageDeploymentManager{ winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentManager::GetDefault() }; + + RemovePackageFamily_Red(); + RemovePackage_Green(); + StagePackage_Red(); + StagePackage_Green(); + SetPackageStatusByPackageFamilyName(::TPF::Green::GetPackageFullName(), winrt::Windows::Management::Deployment::PackageStatus::Modified); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + + winrt::Microsoft::Windows::Management::Deployment::PackageSet packageSet; + PCWSTR c_packageSetId{ L"RGB" }; + packageSet.Id(c_packageSetId); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem red{ Make_PackageSetItem(::TPF::Red::GetPackageFullName(), ::TPF::Red::c_packageDirName) }; + packageSet.Items().Append(red); + winrt::Microsoft::Windows::Management::Deployment::PackageSetItem green{ Make_PackageSetItem(::TPF::Green::GetPackageFullName(), ::TPF::Green::c_packageDirName) }; + packageSet.Items().Append(green); + + winrt::Microsoft::Windows::Management::Deployment::StagePackageOptions options; + auto deploymentOperation{ packageDeploymentManager.StagePackageSetAsync(packageSet, options) }; + auto deploymentResult{ WaitForDeploymentOperation(deploymentOperation) }; + TPMT::VerifyDeploymentSucceeded(deploymentResult, __FILE__, __LINE__, __FUNCTION__); + + VERIFY_IS_TRUE(IsPackageStaged_Red()); + VERIFY_IS_TRUE(IsPackageStaged_Green()); + VERIFY_IS_FALSE(packageDeploymentManager.IsPackageReady(::TPF::Green::GetPackageFullName())); + } + }; +} diff --git a/test/PackageManager/API/PackageManagerTests.Packages.h b/test/PackageManager/API/PackageManagerTests.Packages.h index a30a62d7e..300e7c6c1 100644 --- a/test/PackageManager/API/PackageManagerTests.Packages.h +++ b/test/PackageManager/API/PackageManagerTests.Packages.h @@ -4,7 +4,21 @@ #ifndef __PACKAGEMANAGERTESTS_PACKAGES_H #define __PACKAGEMANAGERTESTS_PACKAGES_H -namespace Test::Packages::Framework +namespace Test::Packages::Framework{} +namespace Test::Packages::Main{} +namespace Test::PackageManager::Tests{} +// +namespace TD = ::Test::Diagnostics; +namespace TB = ::Test::Bootstrap; +namespace TP = ::Test::Packages; +namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; +namespace TPMT = ::Test::PackageManager::Tests; + + +namespace Test::Packages +{ +namespace Framework { namespace Red { @@ -87,6 +101,94 @@ namespace Blue } } } +namespace Main +{ +namespace Black +{ + constexpr PCWSTR c_packageDirName = L"PackageManager.Test.M.Black.msix"; + constexpr PCWSTR c_packageFamilyName = L"Test.PackageManager.M.Black_8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_x86 = L"Test.PackageManager.M.Black_1.2.3.4_x86__8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_x64 = L"Test.PackageManager.M.Black_1.2.3.4_x64__8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_arm64 = L"Test.PackageManager.M.Black_1.2.3.4_arm64__8wekyb3d8bbwe"; + constexpr inline PCWSTR GetPackageFullName() + { +#if defined(_M_ARM64) + return c_packageFullName_arm64; +#elif defined(_M_IX86) + return c_packageFullName_x86; +#elif defined(_M_X64) + return c_packageFullName_x64; +#else +# error "Unknown processor architecture" +#endif + } + constexpr PCWSTR c_appUserModelId = L"Test.PackageManager.M.Black_8wekyb3d8bbwe!App"; +} +namespace Blacker +{ + constexpr PCWSTR c_packageDirName = L"PackageManager.Test.M.Blacker.msix"; + constexpr PCWSTR c_packageFamilyName = L"Test.PackageManager.M.Black_8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_x86 = L"Test.PackageManager.M.Black_2.4.6.8_x86__8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_x64 = L"Test.PackageManager.M.Black_2.4.6.8_x64__8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_arm64 = L"Test.PackageManager.M.Black_2.4.6.8_arm64__8wekyb3d8bbwe"; + constexpr inline PCWSTR GetPackageFullName() + { +#if defined(_M_ARM64) + return c_packageFullName_arm64; +#elif defined(_M_IX86) + return c_packageFullName_x86; +#elif defined(_M_X64) + return c_packageFullName_x64; +#else +# error "Unknown processor architecture" +#endif + } + constexpr PCWSTR c_appUserModelId = L"Test.PackageManager.M.Black_8wekyb3d8bbwe!App"; +} +namespace White +{ + constexpr PCWSTR c_packageDirName = L"PackageManager.Test.M.White.msix"; + constexpr PCWSTR c_packageFamilyName = L"Test.PackageManager.M.White_8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_x86 = L"Test.PackageManager.M.White_1.2.3.4_x86__8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_x64 = L"Test.PackageManager.M.White_1.2.3.4_x64__8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_arm64 = L"Test.PackageManager.M.White_1.2.3.4_arm64__8wekyb3d8bbwe"; + constexpr inline PCWSTR GetPackageFullName() + { +#if defined(_M_ARM64) + return c_packageFullName_arm64; +#elif defined(_M_IX86) + return c_packageFullName_x86; +#elif defined(_M_X64) + return c_packageFullName_x64; +#else +# error "Unknown processor architecture" +#endif + } + constexpr PCWSTR c_appUserModelId = L"Test.PackageManager.M.White_8wekyb3d8bbwe!App"; +} +namespace Whiter +{ + constexpr PCWSTR c_packageDirName = L"PackageManager.Test.M.Whiter.msix"; + constexpr PCWSTR c_packageFamilyName = L"Test.PackageManager.M.White_8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_x86 = L"Test.PackageManager.M.White_2.4.6.8_x86__8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_x64 = L"Test.PackageManager.M.White_2.4.6.8_x64__8wekyb3d8bbwe"; + constexpr PCWSTR c_packageFullName_arm64 = L"Test.PackageManager.M.White_2.4.6.8_arm64__8wekyb3d8bbwe"; + constexpr inline PCWSTR GetPackageFullName() + { +#if defined(_M_ARM64) + return c_packageFullName_arm64; +#elif defined(_M_IX86) + return c_packageFullName_x86; +#elif defined(_M_X64) + return c_packageFullName_x64; +#else +# error "Unknown processor architecture" +#endif + } + constexpr PCWSTR c_appUserModelId = L"Test.PackageManager.M.White_8wekyb3d8bbwe!App"; +} +} +} namespace Test::PackageManager::Tests { @@ -96,21 +198,36 @@ namespace Test::PackageManager::Tests // Forward declarations void RemovePackageFamily_Redder(); - inline winrt::Microsoft::Windows::Management::Deployment::PackageSetItem Make_PackageSetItem( + inline winrt::Microsoft::Windows::Management::Deployment::PackageSetItem _Make_PackageSetItem( PCWSTR packageFullName, - PCWSTR packageDirName) + winrt::Windows::Foundation::Uri const& packageUri) { - WEX::Logging::Log::Comment(WEX::Common::String().Format(L"PackageSetItem: PackageFullName:%s Path:%s", packageFullName, packageDirName)); + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"PackageSetItem: PackageFullName:%s Path:%s", packageFullName, packageUri.ToString().c_str())); const auto [packageName, packageVersion, packageArchitecture, packageResourceId, packagePublisherId, packageFamilyName]{ ::AppModel::Package::ParsePackageFullName(packageFullName) }; winrt::Microsoft::Windows::Management::Deployment::PackageSetItem psi; psi.PackageFamilyName(packageFamilyName); - psi.PackageUri(TP::GetMsixPackageUri(packageDirName)); + psi.PackageUri(packageUri); const ::AppModel::Identity::PackageVersion version{ packageVersion }; psi.MinVersion(version.ToWinrtPackageVersion()); return psi; } + inline winrt::Microsoft::Windows::Management::Deployment::PackageSetItem Make_PackageSetItem( + PCWSTR packageFullName, + PCWSTR packageDirName) + { + const auto packageUri{ TP::GetMsixPackageUri(packageDirName) }; + return _Make_PackageSetItem(packageFullName, packageUri); + } + + inline winrt::Microsoft::Windows::Management::Deployment::PackageSetItem Make_PackageSetItem_ForRegister( + PCWSTR packageFullName) + { + const auto appxManifestUri{ TP::GetAppxManifestPackageUri(packageFullName) }; + return _Make_PackageSetItem(packageFullName, appxManifestUri); + } + inline bool IsPackageRegistered_Red() { return TP::IsPackageRegistered(TPF::Red::GetPackageFullName()); @@ -121,11 +238,15 @@ namespace Test::PackageManager::Tests } inline void AddPackage_Red() { - TP::AddPackageIfNecessary(Test::Packages::Framework::Red::c_packageDirName, TPF::Red::GetPackageFullName()); + TP::AddPackageIfNecessary(TPF::Red::c_packageDirName, TPF::Red::GetPackageFullName()); } inline void StagePackage_Red() { - TP::StagePackageIfNecessary(Test::Packages::Framework::Red::c_packageDirName, TPF::Red::GetPackageFullName()); + TP::StagePackageIfNecessary(TPF::Red::c_packageDirName, TPF::Red::GetPackageFullName()); + } + inline void RegisterPackage_Red() + { + TP::RegisterPackageIfNecessary(TPF::Red::GetPackageFullName()); } inline void RemovePackage_Red() { @@ -145,16 +266,18 @@ namespace Test::PackageManager::Tests { // Same as RemovePackageFamily_Redder RemovePackageFamily_Redder(); -#if 0 - // The package could be staged and not registered so checking - // checking for registered packages in the family is insufficient, - // and checking for staged packages not registered for the current user - // requires admin privilege (which we may not have). So we'll rely on - // remove for each package in the family handling it whether the packages - // are staged or registered. - TP::RemovePackageIfNecessary(TPF::Red::GetPackageFullName()); - TP::RemovePackageIfNecessary(TPF::Redder::GetPackageFullName()); -#endif + } + inline bool IsPackageProvisioned_Red() + { + return TP::IsPackageProvisioned(TPF::Red::c_packageFamilyName); + } + inline void ProvisionPackage_Red() + { + TP::ProvisionPackage(TPF::Red::c_packageFamilyName); + } + inline void DeprovisionPackage_Red() + { + TP::DeprovisionPackageIfNecessary(TPF::Red::c_packageFamilyName); } inline bool IsPackageRegistered_Redder() @@ -167,11 +290,15 @@ namespace Test::PackageManager::Tests } inline void AddPackage_Redder() { - TP::AddPackageIfNecessary(Test::Packages::Framework::Redder::c_packageDirName, TPF::Redder::GetPackageFullName()); + TP::AddPackageIfNecessary(TPF::Redder::c_packageDirName, TPF::Redder::GetPackageFullName()); } inline void StagePackage_Redder() { - TP::StagePackageIfNecessary(Test::Packages::Framework::Redder::c_packageDirName, TPF::Redder::GetPackageFullName()); + TP::StagePackageIfNecessary(TPF::Redder::c_packageDirName, TPF::Redder::GetPackageFullName()); + } + inline void RegisterPackage_Redder() + { + TP::RegisterPackageIfNecessary(TPF::Redder::GetPackageFullName()); } inline void RemovePackage_Redder() { @@ -191,16 +318,18 @@ namespace Test::PackageManager::Tests { RemovePackage_Redder(); RemovePackage_Red(); -#if 0 - // The package could be staged and not registered so checking - // checking for registered packages in the family is insufficient, - // and checking for staged packages not registered for the current user - // requires admin privilege (which we may not have). So we'll rely on - // remove for each package in the family handling it whether the packages - // are staged or registered. - TP::RemovePackageIfNecessary(TPF::Red::GetPackageFullName()); - TP::RemovePackageIfNecessary(TPF::Redder::GetPackageFullName()); -#endif + } + inline bool IsPackageProvisioned_Redder() + { + return TP::IsPackageProvisioned(TPF::Redder::c_packageFamilyName); + } + inline void ProvisionPackage_Redder() + { + TP::ProvisionPackage(TPF::Redder::c_packageFamilyName); + } + inline void DeprovisionPackage_Redder() + { + TP::DeprovisionPackageIfNecessary(TPF::Redder::c_packageFamilyName); } inline bool IsPackageRegistered_Green() @@ -213,11 +342,15 @@ namespace Test::PackageManager::Tests } inline void AddPackage_Green() { - TP::AddPackageIfNecessary(Test::Packages::Framework::Green::c_packageDirName, TPF::Green::GetPackageFullName()); + TP::AddPackageIfNecessary(TPF::Green::c_packageDirName, TPF::Green::GetPackageFullName()); } inline void StagePackage_Green() { - TP::StagePackageIfNecessary(Test::Packages::Framework::Green::c_packageDirName, TPF::Green::GetPackageFullName()); + TP::StagePackageIfNecessary(TPF::Green::c_packageDirName, TPF::Green::GetPackageFullName()); + } + inline void RegisterPackage_Green() + { + TP::RegisterPackageIfNecessary(TPF::Green::GetPackageFullName()); } inline void RemovePackage_Green() { @@ -236,15 +369,18 @@ namespace Test::PackageManager::Tests inline void RemovePackageFamily_Green() { RemovePackage_Green(); -#if 0 - // The package could be staged and not registered so checking - // checking for registered packages in the family is insufficient, - // and checking for staged packages not registered for the current user - // requires admin privilege (which we may not have). So we'll rely on - // remove for each package in the family handling it whether the packages - // are staged or registered. - TP::RemovePackageIfNecessary(TPF::Green::GetPackageFullName()); -#endif + } + inline bool IsPackageProvisioned_Green() + { + return TP::IsPackageProvisioned(TPF::Green::c_packageFamilyName); + } + inline void ProvisionPackage_Green() + { + TP::ProvisionPackage(TPF::Green::c_packageFamilyName); + } + inline void DeprovisionPackage_Green() + { + TP::DeprovisionPackageIfNecessary(TPF::Green::c_packageFamilyName); } inline bool IsPackageRegistered_Blue() @@ -257,11 +393,15 @@ namespace Test::PackageManager::Tests } inline void AddPackage_Blue() { - TP::AddPackageIfNecessary(Test::Packages::Framework::Blue::c_packageDirName, TPF::Blue::GetPackageFullName()); + TP::AddPackageIfNecessary(TPF::Blue::c_packageDirName, TPF::Blue::GetPackageFullName()); } inline void StagePackage_Blue() { - TP::StagePackageIfNecessary(Test::Packages::Framework::Blue::c_packageDirName, TPF::Blue::GetPackageFullName()); + TP::StagePackageIfNecessary(TPF::Blue::c_packageDirName, TPF::Blue::GetPackageFullName()); + } + inline void RegisterPackage_Blue() + { + TP::RegisterPackageIfNecessary(TPF::Blue::GetPackageFullName()); } inline void RemovePackage_Blue() { @@ -280,15 +420,238 @@ namespace Test::PackageManager::Tests inline void RemovePackageFamily_Blue() { RemovePackage_Blue(); -#if 0 - // The package could be staged and not registered so checking - // checking for registered packages in the family is insufficient, - // and checking for staged packages not registered for the current user - // requires admin privilege (which we may not have). So we'll rely on - // remove for each package in the family handling it whether the packages - // are staged or registered. - TP::RemovePackageIfNecessary(TPF::Green::GetPackageFullName()); -#endif + } + inline bool IsPackageProvisioned_Blue() + { + return TP::IsPackageProvisioned(TPF::Blue::c_packageFamilyName); + } + inline void ProvisionPackage_Blue() + { + TP::ProvisionPackage(TPF::Blue::c_packageFamilyName); + } + inline void DeprovisionPackage_Blue() + { + TP::DeprovisionPackageIfNecessary(TPF::Blue::c_packageFamilyName); + } + + inline bool IsPackageRegistered_Black() + { + return TP::IsPackageRegistered(TPM::Black::GetPackageFullName()); + } + inline bool IsPackageStaged_Black() + { + return TP::IsPackageStaged(TPM::Black::GetPackageFullName()); + } + inline void AddPackage_Black() + { + TP::AddPackageIfNecessary(TPM::Black::c_packageDirName, TPM::Black::GetPackageFullName()); + } + inline void AddPackageDefer_Black() + { + TP::AddPackageDeferIfNecessary(TPM::Black::c_packageDirName, TPM::Black::GetPackageFullName()); + } + inline void StagePackage_Black() + { + TP::StagePackageIfNecessary(TPM::Black::c_packageDirName, TPM::Black::GetPackageFullName()); + } + inline void RegisterPackage_Black() + { + TP::RegisterPackageIfNecessary(TPM::Black::GetPackageFullName()); + } + inline void RemovePackage_Black() + { + if (IsPackageRegistered_Black()) + { + TP::RemovePackage(TPM::Black::GetPackageFullName()); + } + else if (IsPackageStaged_Black()) + { + // We can't directly remove a Stage package not registered for current user + // w/o admin privilege but we can add it to make it registered and then remove it. + AddPackage_Black(); + TP::RemovePackage(TPM::Black::GetPackageFullName()); + } + } + inline void RemovePackageFamily_Black() + { + RemovePackage_Black(); + } + inline bool IsPackageProvisioned_Black() + { + return TP::IsPackageProvisioned(TPM::Black::c_packageFamilyName); + } + inline void ProvisionPackage_Black() + { + TP::ProvisionPackage(TPM::Black::c_packageFamilyName); + } + inline void DeprovisionPackage_Black() + { + TP::DeprovisionPackageIfNecessary(TPM::Black::c_packageFamilyName); + } + + inline bool IsPackageRegistered_Blacker() + { + return TP::IsPackageRegistered(TPM::Blacker::GetPackageFullName()); + } + inline bool IsPackageStaged_Blacker() + { + return TP::IsPackageStaged(TPM::Blacker::GetPackageFullName()); + } + inline void AddPackage_Blacker() + { + TP::AddPackageIfNecessary(TPM::Blacker::c_packageDirName, TPM::Blacker::GetPackageFullName()); + } + inline void AddPackageDefer_Blacker() + { + TP::AddPackageDeferIfNecessary(TPM::Blacker::c_packageDirName, TPM::Blacker::GetPackageFullName()); + } + inline void StagePackage_Blacker() + { + TP::StagePackageIfNecessary(TPM::Blacker::c_packageDirName, TPM::Blacker::GetPackageFullName()); + } + inline void RegisterPackage_Blacker() + { + TP::RegisterPackageIfNecessary(TPM::Blacker::GetPackageFullName()); + } + inline void RemovePackage_Blacker() + { + if (IsPackageRegistered_Blacker()) + { + TP::RemovePackage(TPM::Blacker::GetPackageFullName()); + } + else if (IsPackageStaged_Blacker()) + { + // We can't directly remove a Stage package not registered for current user + // w/o admin privilege but we can add it to make it registered and then remove it. + AddPackage_Blacker(); + TP::RemovePackage(TPM::Blacker::GetPackageFullName()); + } + } + inline void RemovePackageFamily_Blacker() + { + RemovePackage_Blacker(); + } + inline bool IsPackageProvisioned_Blacker() + { + return TP::IsPackageProvisioned(TPM::Blacker::c_packageFamilyName); + } + inline void ProvisionPackage_Blacker() + { + TP::ProvisionPackage(TPM::Blacker::c_packageFamilyName); + } + inline void DeprovisionPackage_Blacker() + { + TP::DeprovisionPackageIfNecessary(TPM::Blacker::c_packageFamilyName); + } + + inline bool IsPackageRegistered_White() + { + return TP::IsPackageRegistered(TPM::White::GetPackageFullName()); + } + inline bool IsPackageStaged_White() + { + return TP::IsPackageStaged(TPM::White::GetPackageFullName()); + } + inline void AddPackage_White() + { + TP::AddPackageIfNecessary(TPM::White::c_packageDirName, TPM::White::GetPackageFullName()); + } + inline void AddPackageDefer_White() + { + TP::AddPackageDeferIfNecessary(TPM::White::c_packageDirName, TPM::White::GetPackageFullName()); + } + inline void StagePackage_White() + { + TP::StagePackageIfNecessary(TPM::White::c_packageDirName, TPM::White::GetPackageFullName()); + } + inline void RegisterPackage_White() + { + TP::RegisterPackageIfNecessary(TPM::White::GetPackageFullName()); + } + inline void RemovePackage_White() + { + if (IsPackageRegistered_White()) + { + TP::RemovePackage(TPM::White::GetPackageFullName()); + } + else if (IsPackageStaged_White()) + { + // We can't directly remove a Stage package not registered for current user + // w/o admin privilege but we can add it to make it registered and then remove it. + AddPackage_White(); + TP::RemovePackage(TPM::White::GetPackageFullName()); + } + } + inline void RemovePackageFamily_White() + { + RemovePackage_White(); + } + inline bool IsPackageProvisioned_White() + { + return TP::IsPackageProvisioned(TPM::White::c_packageFamilyName); + } + inline void ProvisionPackage_White() + { + TP::ProvisionPackage(TPM::White::c_packageFamilyName); + } + inline void DeprovisionPackage_White() + { + TP::DeprovisionPackageIfNecessary(TPM::White::c_packageFamilyName); + } + + inline bool IsPackageRegistered_Whiter() + { + return TP::IsPackageRegistered(TPM::Whiter::GetPackageFullName()); + } + inline bool IsPackageStaged_Whiter() + { + return TP::IsPackageStaged(TPM::Whiter::GetPackageFullName()); + } + inline void AddPackage_Whiter() + { + TP::AddPackageIfNecessary(TPM::Whiter::c_packageDirName, TPM::Whiter::GetPackageFullName()); + } + inline void AddPackageDefer_Whiter() + { + TP::AddPackageDeferIfNecessary(TPM::Whiter::c_packageDirName, TPM::Whiter::GetPackageFullName()); + } + inline void StagePackage_Whiter() + { + TP::StagePackageIfNecessary(TPM::Whiter::c_packageDirName, TPM::Whiter::GetPackageFullName()); + } + inline void RegisterPackage_Whiter() + { + TP::RegisterPackageIfNecessary(TPM::Whiter::GetPackageFullName()); + } + inline void RemovePackage_Whiter() + { + if (IsPackageRegistered_Whiter()) + { + TP::RemovePackage(TPM::Whiter::GetPackageFullName()); + } + else if (IsPackageStaged_Whiter()) + { + // We can't directly remove a Stage package not registered for current user + // w/o admin privilege but we can add it to make it registered and then remove it. + AddPackage_Whiter(); + TP::RemovePackage(TPM::Whiter::GetPackageFullName()); + } + } + inline void RemovePackageFamily_Whiter() + { + RemovePackage_Whiter(); + } + inline bool IsPackageProvisioned_Whiter() + { + return TP::IsPackageProvisioned(TPM::Whiter::c_packageFamilyName); + } + inline void ProvisionPackage_Whiter() + { + TP::ProvisionPackage(TPM::Whiter::c_packageFamilyName); + } + inline void DeprovisionPackage_Whiter() + { + TP::DeprovisionPackageIfNecessary(TPM::Whiter::c_packageFamilyName); } inline winrt::Windows::ApplicationModel::PackageStatus GetPackageStatus(winrt::Windows::Management::Deployment::PackageManager packageManager, PCWSTR packageFullName) diff --git a/test/PackageManager/API/PackageManagerTests.vcxproj b/test/PackageManager/API/PackageManagerTests.vcxproj index a874267c5..c60298ae3 100644 --- a/test/PackageManager/API/PackageManagerTests.vcxproj +++ b/test/PackageManager/API/PackageManagerTests.vcxproj @@ -88,6 +88,7 @@ onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) + Microsoft.Internal.FrameworkUdk.dll;%(DelayLoadDLLs) @@ -110,10 +111,24 @@ Create + + + + + + + + + + + + + + @@ -153,6 +168,7 @@ + @@ -168,5 +184,6 @@ + diff --git a/test/PackageManager/API/PackageManagerTests.vcxproj.filters b/test/PackageManager/API/PackageManagerTests.vcxproj.filters index 50298e2af..2f54e9455 100644 --- a/test/PackageManager/API/PackageManagerTests.vcxproj.filters +++ b/test/PackageManager/API/PackageManagerTests.vcxproj.filters @@ -21,6 +21,45 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + Source Files @@ -29,6 +68,9 @@ Header Files + + Header Files + Header Files @@ -36,4 +78,7 @@ + + + diff --git a/test/PackageManager/API/PackageRuntimeManagerTests.cpp b/test/PackageManager/API/PackageRuntimeManagerTests.cpp index 6a055a189..8e7e4f017 100644 --- a/test/PackageManager/API/PackageRuntimeManagerTests.cpp +++ b/test/PackageManager/API/PackageRuntimeManagerTests.cpp @@ -5,9 +5,11 @@ #include +namespace TD = ::Test::Diagnostics; namespace TB = ::Test::Bootstrap; namespace TP = ::Test::Packages; namespace TPF = ::Test::Packages::Framework; +namespace TPM = ::Test::Packages::Main; namespace TPMT = ::Test::PackageManager::Tests; namespace Test::PackageManager::Tests diff --git a/test/PackageManager/API/packages.config b/test/PackageManager/API/packages.config index ecebfdd18..3a4280472 100644 --- a/test/PackageManager/API/packages.config +++ b/test/PackageManager/API/packages.config @@ -3,7 +3,8 @@ - + + diff --git a/test/PackageManager/API/pch.h b/test/PackageManager/API/pch.h index 9ae9d75ea..900c25a3d 100644 --- a/test/PackageManager/API/pch.h +++ b/test/PackageManager/API/pch.h @@ -6,6 +6,9 @@ #include +#include + +#include #include #include @@ -28,4 +31,24 @@ #include "PackageManagerTests.Packages.h" +#include +#include +#include +#if defined(NTDDI_WIN11_GE) +# define TODO_UpdatedWindowsSDK_with_Windows_Management_Deployment_IRemovePackageOptions +#endif +#if !defined(TODO_UpdatedWindowsSDK_with_Windows_Management_Deployment_IRemovePackageOptions) +// Until we have access to the updated Windows SDK we can't use RemovePackageOptions +// but we need *something* to satisfy PackageManagement_RemovePackageByUriAsync() in the FrameworkUDK +// so we'll make a placeholder definition to satisfy the compiler enough to let us call +// PackageManagement_RemovePackageByUriAsync2(uri, nullptr). Remove this once the updated +// Windows SDK makes this unnecessary. +namespace ABI::Windows::Management::Deployment +{ + typedef void * IRemovePackageOptions; +} +#endif +// +#include + #endif //PCH_H diff --git a/test/PackageManager/data/PackageManager.Test.F.Red.msix/pch.cpp b/test/PackageManager/data/PackageManager.Test.F.Red.msix/pch.cpp new file mode 100644 index 000000000..a77728ba0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.F.Red.msix/pch.cpp @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/test/PackageManager/data/PackageManager.Test.F.Red.msix/pch.h b/test/PackageManager/data/PackageManager.Test.F.Red.msix/pch.h new file mode 100644 index 000000000..c32e747e3 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.F.Red.msix/pch.h @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef PCH_H +#define PCH_H + +#include + +#include +#include +#include + +#include +#include +#include + +#endif //PCH_H diff --git a/test/PackageManager/data/PackageManager.Test.F.Red.msix/winmain.cpp b/test/PackageManager/data/PackageManager.Test.F.Red.msix/winmain.cpp new file mode 100644 index 000000000..43db21717 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.F.Red.msix/winmain.cpp @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, PSTR /*lpCmdLine*/, int /*nCmdShow*/) +{ + // Usage: This.Exe + // where + // eventname = event name signaling we should quit. + + // Parse the command line + const auto eventName{ GetCommandLineW() }; + if (eventName) + { + wil::unique_event_nothrow endOfTheLine{ ::OpenEventW(SYNCHRONIZE, FALSE, eventName) }; + RETURN_LAST_ERROR_IF_NULL(endOfTheLine); + + auto rc{ WaitForSingleObject(endOfTheLine.get(), INFINITE) }; + if (rc != WAIT_OBJECT_0) + { + if (rc == WAIT_FAILED) + { + LOG_LAST_ERROR(); + } + else + { + LOG_HR_MSG(E_UNEXPECTED, "%u", rc); + } + return rc; + } + } + return 0; +} diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/SplashScreen.png b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/SplashScreen.png new file mode 100644 index 000000000..184821318 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/SplashScreen.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Square150x150Logo.png b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Square150x150Logo.png new file mode 100644 index 000000000..a50c70379 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Square150x150Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Square44x44Logo.png b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Square44x44Logo.png new file mode 100644 index 000000000..844b60c20 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Square44x44Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Wide310x150Logo.png b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Wide310x150Logo.png new file mode 100644 index 000000000..b5d5f2c42 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/Wide310x150Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/logo.png b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/logo.png new file mode 100644 index 000000000..fd2293e7b Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Black.msix/Assets/logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.msix.vcxproj b/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.msix.vcxproj new file mode 100644 index 000000000..3e6133957 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.msix.vcxproj @@ -0,0 +1,185 @@ + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + {39277b4c-4fb5-45f6-b0aa-ee8086590cda} + Win32Proj + PackageManager.Test.M.Black.Msix + en-US + 16.0 + 10.0.22621.0 + 10.0.17763.0 + 10.0 + + + Application + v143 + Unicode + + + true + + + false + + + PackageManager.Test.M.Black + + + PackageManager.Test.M.Black + + + PackageManager.Test.M.Black + + + PackageManager.Test.M.Black + + + PackageManager.Test.M.Black + + + PackageManager.Test.M.Black + + + + + + + + + + + + + + + + + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + _WINDOWS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories); + + + Windows + false + %(AdditionalLibraryDirectories) + onecore.lib;onecoreuap.lib;%(AdditionalDependencies) + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + WIN32;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + + + + + + + + Create + + + + + + + + + + PackageManager.Test.M.Black.msix + PackageManager.Test.M.Black + $(TargetBasename) + $(OutDir)$(ProjectName) + $(TargetExeDir)\$(TargetExe).exe + + + + appxmanifest.xml + + + appxmanifest.xml + + + appxmanifest.xml + + + + + + $(RepoTestCertificatePFX) + $(RepoTestCertificatePassword) + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.msix.vcxproj.filters b/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.msix.vcxproj.filters new file mode 100644 index 000000000..008c8045a --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.msix.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.vcxproj.filters b/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.vcxproj.filters new file mode 100644 index 000000000..2df21c891 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/PackageManager.Test.M.Black.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-arm64.xml b/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-arm64.xml new file mode 100644 index 000000000..5905f6985 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-arm64.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Black + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-x64.xml b/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-x64.xml new file mode 100644 index 000000000..e7a465393 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-x64.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Black + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-x86.xml b/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-x86.xml new file mode 100644 index 000000000..ee06c33ee --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/appxmanifest-x86.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Black + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/logo.png b/test/PackageManager/data/PackageManager.Test.M.Black.msix/logo.png new file mode 100644 index 000000000..5bd7c0ce4 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Black.msix/logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/packages.config b/test/PackageManager/data/PackageManager.Test.M.Black.msix/packages.config new file mode 100644 index 000000000..e9fecf8c0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/packages.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/pch.cpp b/test/PackageManager/data/PackageManager.Test.M.Black.msix/pch.cpp new file mode 100644 index 000000000..a77728ba0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/pch.cpp @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/pch.h b/test/PackageManager/data/PackageManager.Test.M.Black.msix/pch.h new file mode 100644 index 000000000..c32e747e3 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/pch.h @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef PCH_H +#define PCH_H + +#include + +#include +#include +#include + +#include +#include +#include + +#endif //PCH_H diff --git a/test/PackageManager/data/PackageManager.Test.M.Black.msix/winmain.cpp b/test/PackageManager/data/PackageManager.Test.M.Black.msix/winmain.cpp new file mode 100644 index 000000000..6203782ae --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Black.msix/winmain.cpp @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, PSTR /*lpCmdLine*/, int /*nCmdShow*/) +{ + // Usage: This.Exe + // where + // eventname = event name signaling we should quit. + + // Parse the command line + const auto commandLine{ GetCommandLineW() }; + int argc{}; + PWSTR* argv{ CommandLineToArgvW(commandLine, &argc) }; + RETURN_HR_IF_NULL(E_INVALIDARG, argv); + if (argc >= 2) + { + PCWSTR eventName{ argv[1] }; + wil::unique_event_nothrow endOfTheLine{ ::OpenEventW(SYNCHRONIZE, FALSE, eventName) }; + RETURN_LAST_ERROR_IF_NULL(endOfTheLine); + + auto rc{ WaitForSingleObject(endOfTheLine.get(), INFINITE) }; + if (rc != WAIT_OBJECT_0) + { + if (rc == WAIT_FAILED) + { + LOG_LAST_ERROR(); + } + else + { + LOG_HR_MSG(E_UNEXPECTED, "%u", rc); + } + return rc; + } + } + return 0; +} diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/SplashScreen.png b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/SplashScreen.png new file mode 100644 index 000000000..184821318 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/SplashScreen.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Square150x150Logo.png b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Square150x150Logo.png new file mode 100644 index 000000000..a50c70379 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Square150x150Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Square44x44Logo.png b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Square44x44Logo.png new file mode 100644 index 000000000..844b60c20 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Square44x44Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Wide310x150Logo.png b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Wide310x150Logo.png new file mode 100644 index 000000000..b5d5f2c42 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/Wide310x150Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/logo.png b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/logo.png new file mode 100644 index 000000000..fd2293e7b Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/Assets/logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.msix.vcxproj b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.msix.vcxproj new file mode 100644 index 000000000..d7edb152f --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.msix.vcxproj @@ -0,0 +1,185 @@ + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + {ad7d0a19-44b9-41d6-a68a-9fecac28078d} + Win32Proj + PackageManager.Test.M.Blacker.Msix + en-US + 16.0 + 10.0.22621.0 + 10.0.17763.0 + 10.0 + + + Application + v143 + Unicode + + + true + + + false + + + PackageManager.Test.M.Blacker + + + PackageManager.Test.M.Blacker + + + PackageManager.Test.M.Blacker + + + PackageManager.Test.M.Blacker + + + PackageManager.Test.M.Blacker + + + PackageManager.Test.M.Blacker + + + + + + + + + + + + + + + + + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + _WINDOWS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories); + + + Windows + false + %(AdditionalLibraryDirectories) + onecore.lib;onecoreuap.lib;%(AdditionalDependencies) + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + WIN32;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + + + + + + + + Create + + + + + + + + + + PackageManager.Test.M.Blacker.msix + PackageManager.Test.M.Blacker + $(TargetBasename) + $(OutDir)$(ProjectName) + $(TargetExeDir)\$(TargetExe).exe + + + + appxmanifest.xml + + + appxmanifest.xml + + + appxmanifest.xml + + + + + + $(RepoTestCertificatePFX) + $(RepoTestCertificatePassword) + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.msix.vcxproj.filters b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.msix.vcxproj.filters new file mode 100644 index 000000000..008c8045a --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.msix.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.vcxproj.filters b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.vcxproj.filters new file mode 100644 index 000000000..2df21c891 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/PackageManager.Test.M.Blacker.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-arm64.xml b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-arm64.xml new file mode 100644 index 000000000..aef1532b9 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-arm64.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Blacker + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-x64.xml b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-x64.xml new file mode 100644 index 000000000..f228880da --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-x64.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Blacker + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-x86.xml b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-x86.xml new file mode 100644 index 000000000..1311717bf --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/appxmanifest-x86.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Blacker + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/logo.png b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/logo.png new file mode 100644 index 000000000..5bd7c0ce4 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/packages.config b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/packages.config new file mode 100644 index 000000000..e9fecf8c0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/packages.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/pch.cpp b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/pch.cpp new file mode 100644 index 000000000..a77728ba0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/pch.cpp @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/pch.h b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/pch.h new file mode 100644 index 000000000..c32e747e3 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/pch.h @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef PCH_H +#define PCH_H + +#include + +#include +#include +#include + +#include +#include +#include + +#endif //PCH_H diff --git a/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/winmain.cpp b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/winmain.cpp new file mode 100644 index 000000000..6203782ae --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Blacker.msix/winmain.cpp @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, PSTR /*lpCmdLine*/, int /*nCmdShow*/) +{ + // Usage: This.Exe + // where + // eventname = event name signaling we should quit. + + // Parse the command line + const auto commandLine{ GetCommandLineW() }; + int argc{}; + PWSTR* argv{ CommandLineToArgvW(commandLine, &argc) }; + RETURN_HR_IF_NULL(E_INVALIDARG, argv); + if (argc >= 2) + { + PCWSTR eventName{ argv[1] }; + wil::unique_event_nothrow endOfTheLine{ ::OpenEventW(SYNCHRONIZE, FALSE, eventName) }; + RETURN_LAST_ERROR_IF_NULL(endOfTheLine); + + auto rc{ WaitForSingleObject(endOfTheLine.get(), INFINITE) }; + if (rc != WAIT_OBJECT_0) + { + if (rc == WAIT_FAILED) + { + LOG_LAST_ERROR(); + } + else + { + LOG_HR_MSG(E_UNEXPECTED, "%u", rc); + } + return rc; + } + } + return 0; +} diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/SplashScreen.png b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/SplashScreen.png new file mode 100644 index 000000000..184821318 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/SplashScreen.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Square150x150Logo.png b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Square150x150Logo.png new file mode 100644 index 000000000..a50c70379 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Square150x150Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Square44x44Logo.png b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Square44x44Logo.png new file mode 100644 index 000000000..844b60c20 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Square44x44Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Wide310x150Logo.png b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Wide310x150Logo.png new file mode 100644 index 000000000..b5d5f2c42 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/Wide310x150Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/logo.png b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/logo.png new file mode 100644 index 000000000..fd2293e7b Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.White.msix/Assets/logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.msix.vcxproj b/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.msix.vcxproj new file mode 100644 index 000000000..496e8cfeb --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.msix.vcxproj @@ -0,0 +1,185 @@ + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + {28dcf9ce-d9f4-4a7d-8ad1-f2efc0d3b4df} + Win32Proj + PackageManager.Test.M.White.Msix + en-US + 16.0 + 10.0.22621.0 + 10.0.17763.0 + 10.0 + + + Application + v143 + Unicode + + + true + + + false + + + PackageManager.Test.M.White + + + PackageManager.Test.M.White + + + PackageManager.Test.M.White + + + PackageManager.Test.M.White + + + PackageManager.Test.M.White + + + PackageManager.Test.M.White + + + + + + + + + + + + + + + + + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + _WINDOWS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories); + + + Windows + false + %(AdditionalLibraryDirectories) + onecore.lib;onecoreuap.lib;%(AdditionalDependencies) + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + WIN32;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + + + + + + + + Create + + + + + + + + + + PackageManager.Test.M.White.msix + PackageManager.Test.M.White + $(TargetBasename) + $(OutDir)$(ProjectName) + $(TargetExeDir)\$(TargetExe).exe + + + + appxmanifest.xml + + + appxmanifest.xml + + + appxmanifest.xml + + + + + + $(RepoTestCertificatePFX) + $(RepoTestCertificatePassword) + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.msix.vcxproj.filters b/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.msix.vcxproj.filters new file mode 100644 index 000000000..008c8045a --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.msix.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.vcxproj.filters b/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.vcxproj.filters new file mode 100644 index 000000000..2df21c891 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/PackageManager.Test.M.White.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-arm64.xml b/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-arm64.xml new file mode 100644 index 000000000..37eb2f297 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-arm64.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.White + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-x64.xml b/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-x64.xml new file mode 100644 index 000000000..39f2b8fe9 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-x64.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.White + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-x86.xml b/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-x86.xml new file mode 100644 index 000000000..50a82c629 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/appxmanifest-x86.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.White + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/logo.png b/test/PackageManager/data/PackageManager.Test.M.White.msix/logo.png new file mode 100644 index 000000000..5bd7c0ce4 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.White.msix/logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/packages.config b/test/PackageManager/data/PackageManager.Test.M.White.msix/packages.config new file mode 100644 index 000000000..e9fecf8c0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/packages.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/pch.cpp b/test/PackageManager/data/PackageManager.Test.M.White.msix/pch.cpp new file mode 100644 index 000000000..a77728ba0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/pch.cpp @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/pch.h b/test/PackageManager/data/PackageManager.Test.M.White.msix/pch.h new file mode 100644 index 000000000..c32e747e3 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/pch.h @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef PCH_H +#define PCH_H + +#include + +#include +#include +#include + +#include +#include +#include + +#endif //PCH_H diff --git a/test/PackageManager/data/PackageManager.Test.M.White.msix/winmain.cpp b/test/PackageManager/data/PackageManager.Test.M.White.msix/winmain.cpp new file mode 100644 index 000000000..6203782ae --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.White.msix/winmain.cpp @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, PSTR /*lpCmdLine*/, int /*nCmdShow*/) +{ + // Usage: This.Exe + // where + // eventname = event name signaling we should quit. + + // Parse the command line + const auto commandLine{ GetCommandLineW() }; + int argc{}; + PWSTR* argv{ CommandLineToArgvW(commandLine, &argc) }; + RETURN_HR_IF_NULL(E_INVALIDARG, argv); + if (argc >= 2) + { + PCWSTR eventName{ argv[1] }; + wil::unique_event_nothrow endOfTheLine{ ::OpenEventW(SYNCHRONIZE, FALSE, eventName) }; + RETURN_LAST_ERROR_IF_NULL(endOfTheLine); + + auto rc{ WaitForSingleObject(endOfTheLine.get(), INFINITE) }; + if (rc != WAIT_OBJECT_0) + { + if (rc == WAIT_FAILED) + { + LOG_LAST_ERROR(); + } + else + { + LOG_HR_MSG(E_UNEXPECTED, "%u", rc); + } + return rc; + } + } + return 0; +} diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/SplashScreen.png b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/SplashScreen.png new file mode 100644 index 000000000..184821318 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/SplashScreen.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Square150x150Logo.png b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Square150x150Logo.png new file mode 100644 index 000000000..a50c70379 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Square150x150Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Square44x44Logo.png b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Square44x44Logo.png new file mode 100644 index 000000000..844b60c20 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Square44x44Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Wide310x150Logo.png b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Wide310x150Logo.png new file mode 100644 index 000000000..b5d5f2c42 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/Wide310x150Logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/logo.png b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/logo.png new file mode 100644 index 000000000..fd2293e7b Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/Assets/logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.msix.vcxproj b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.msix.vcxproj new file mode 100644 index 000000000..437620337 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.msix.vcxproj @@ -0,0 +1,185 @@ + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + {ac79b8ff-4c27-4326-ad20-bbc70059ff51} + Win32Proj + PackageManager.Test.M.Whiter.Msix + en-US + 16.0 + 10.0.22621.0 + 10.0.17763.0 + 10.0 + + + Application + v143 + Unicode + + + true + + + false + + + PackageManager.Test.M.Whiter + + + PackageManager.Test.M.Whiter + + + PackageManager.Test.M.Whiter + + + PackageManager.Test.M.Whiter + + + PackageManager.Test.M.Whiter + + + PackageManager.Test.M.Whiter + + + + + + + + + + + + + + + + + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + _WINDOWS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories); + + + Windows + false + %(AdditionalLibraryDirectories) + onecore.lib;onecoreuap.lib;%(AdditionalDependencies) + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + WIN32;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + + + + + + + + Create + + + + + + + + + + PackageManager.Test.M.Whiter.msix + PackageManager.Test.M.Whiter + $(TargetBasename) + $(OutDir)$(ProjectName) + $(TargetExeDir)\$(TargetExe).exe + + + + appxmanifest.xml + + + appxmanifest.xml + + + appxmanifest.xml + + + + + + $(RepoTestCertificatePFX) + $(RepoTestCertificatePassword) + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.msix.vcxproj.filters b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.msix.vcxproj.filters new file mode 100644 index 000000000..008c8045a --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.msix.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.vcxproj.filters b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.vcxproj.filters new file mode 100644 index 000000000..2df21c891 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/PackageManager.Test.M.Whiter.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-arm64.xml b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-arm64.xml new file mode 100644 index 000000000..7649cf2a9 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-arm64.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Whiter + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-x64.xml b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-x64.xml new file mode 100644 index 000000000..95d68f9f8 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-x64.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Whiter + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-x86.xml b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-x86.xml new file mode 100644 index 000000000..f2de7b3f5 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/appxmanifest-x86.xml @@ -0,0 +1,49 @@ + + + + + + + + Test.PackageManager.M.Whiter + Microsoft Corporation + Assets\logo.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/logo.png b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/logo.png new file mode 100644 index 000000000..5bd7c0ce4 Binary files /dev/null and b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/logo.png differ diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/packages.config b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/packages.config new file mode 100644 index 000000000..e9fecf8c0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/packages.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/pch.cpp b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/pch.cpp new file mode 100644 index 000000000..a77728ba0 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/pch.cpp @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/pch.h b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/pch.h new file mode 100644 index 000000000..c32e747e3 --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/pch.h @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +// pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef PCH_H +#define PCH_H + +#include + +#include +#include +#include + +#include +#include +#include + +#endif //PCH_H diff --git a/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/winmain.cpp b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/winmain.cpp new file mode 100644 index 000000000..6203782ae --- /dev/null +++ b/test/PackageManager/data/PackageManager.Test.M.Whiter.msix/winmain.cpp @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" + +int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, PSTR /*lpCmdLine*/, int /*nCmdShow*/) +{ + // Usage: This.Exe + // where + // eventname = event name signaling we should quit. + + // Parse the command line + const auto commandLine{ GetCommandLineW() }; + int argc{}; + PWSTR* argv{ CommandLineToArgvW(commandLine, &argc) }; + RETURN_HR_IF_NULL(E_INVALIDARG, argv); + if (argc >= 2) + { + PCWSTR eventName{ argv[1] }; + wil::unique_event_nothrow endOfTheLine{ ::OpenEventW(SYNCHRONIZE, FALSE, eventName) }; + RETURN_LAST_ERROR_IF_NULL(endOfTheLine); + + auto rc{ WaitForSingleObject(endOfTheLine.get(), INFINITE) }; + if (rc != WAIT_OBJECT_0) + { + if (rc == WAIT_FAILED) + { + LOG_LAST_ERROR(); + } + else + { + LOG_HR_MSG(E_UNEXPECTED, "%u", rc); + } + return rc; + } + } + return 0; +} diff --git a/test/PowerNotifications/packages.config b/test/PowerNotifications/packages.config index 1117ac430..dc444ff57 100644 --- a/test/PowerNotifications/packages.config +++ b/test/PowerNotifications/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/PushNotificationTests/packages.config b/test/PushNotificationTests/packages.config index 1117ac430..dc444ff57 100644 --- a/test/PushNotificationTests/packages.config +++ b/test/PushNotificationTests/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/TestApps/AccessControlTestApp/packages.config b/test/TestApps/AccessControlTestApp/packages.config index 1117ac430..dc444ff57 100644 --- a/test/TestApps/AccessControlTestApp/packages.config +++ b/test/TestApps/AccessControlTestApp/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/TestApps/AppLifecycleTestApp/packages.config b/test/TestApps/AppLifecycleTestApp/packages.config index 1117ac430..dc444ff57 100644 --- a/test/TestApps/AppLifecycleTestApp/packages.config +++ b/test/TestApps/AppLifecycleTestApp/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/TestApps/ManualTestApp/packages.config b/test/TestApps/ManualTestApp/packages.config index 1117ac430..dc444ff57 100644 --- a/test/TestApps/ManualTestApp/packages.config +++ b/test/TestApps/ManualTestApp/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/TestApps/PushNotificationsDemoApp/packages.config b/test/TestApps/PushNotificationsDemoApp/packages.config index 1117ac430..dc444ff57 100644 --- a/test/TestApps/PushNotificationsDemoApp/packages.config +++ b/test/TestApps/PushNotificationsDemoApp/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/TestApps/PushNotificationsTestApp/packages.config b/test/TestApps/PushNotificationsTestApp/packages.config index 1117ac430..dc444ff57 100644 --- a/test/TestApps/PushNotificationsTestApp/packages.config +++ b/test/TestApps/PushNotificationsTestApp/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/TestApps/ToastNotificationsDemoApp/packages.config b/test/TestApps/ToastNotificationsDemoApp/packages.config index 1117ac430..dc444ff57 100644 --- a/test/TestApps/ToastNotificationsDemoApp/packages.config +++ b/test/TestApps/ToastNotificationsDemoApp/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/TestApps/ToastNotificationsTestApp/packages.config b/test/TestApps/ToastNotificationsTestApp/packages.config index 1117ac430..dc444ff57 100644 --- a/test/TestApps/ToastNotificationsTestApp/packages.config +++ b/test/TestApps/ToastNotificationsTestApp/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/VersionInfo/packages.config b/test/VersionInfo/packages.config index 1117ac430..dc444ff57 100644 --- a/test/VersionInfo/packages.config +++ b/test/VersionInfo/packages.config @@ -1,6 +1,6 @@  - + diff --git a/test/inc/WindowsAppRuntime.Test.Package.h b/test/inc/WindowsAppRuntime.Test.Package.h index cebfd74e4..5ce92a839 100644 --- a/test/inc/WindowsAppRuntime.Test.Package.h +++ b/test/inc/WindowsAppRuntime.Test.Package.h @@ -8,6 +8,7 @@ #include #include +#include #include #define WINDOWSAPPRUNTIME_TEST_METADATA_VERSION 0x0004000107AF014DLLu @@ -126,19 +127,36 @@ namespace DeploymentWindowsAppRuntimeSingleton constexpr PCWSTR c_PackageFullName = WINDOWSAPPRUNTIME_TEST_MSIX_DEPLOYMENT_SINGLETON_PACKAGE_NAME L"_" WINDOWSAPPRUNTIME_TEST_METADATA_VERSION_STRING L"_neutral__" WINDOWSAPPRUNTIME_TEST_MSIX_PUBLISHERID; } -inline std::wstring GetPackagePath(PCWSTR packageFullName) +template +inline T GetPackagePath(PCWSTR packageFullName) { UINT32 pathLength{}; - const auto rc{ GetPackagePathByFullName(packageFullName, &pathLength, nullptr) }; + const auto rc{ ::GetPackagePathByFullName(packageFullName, &pathLength, nullptr) }; if (rc == ERROR_NOT_FOUND) { - return std::wstring(); + return T{}; } VERIFY_ARE_EQUAL(ERROR_INSUFFICIENT_BUFFER, rc); - auto path = wil::make_process_heap_string(nullptr, pathLength); + auto path{ wil::make_process_heap_string(nullptr, pathLength) }; VERIFY_ARE_EQUAL(ERROR_SUCCESS, GetPackagePathByFullName(packageFullName, &pathLength, path.get())); - return std::wstring(path.get()); + return T{ path.get() }; +} + +template +inline T GetStagedPackagePath(PCWSTR packageFullName) +{ + UINT32 pathLength{}; + const auto rc{ ::GetStagedPackagePathByFullName(packageFullName, &pathLength, nullptr) }; + if (rc == ERROR_NOT_FOUND) + { + return T{}; + } + + VERIFY_ARE_EQUAL(ERROR_INSUFFICIENT_BUFFER, rc); + auto path{ wil::make_process_heap_string(nullptr, pathLength) }; + VERIFY_ARE_EQUAL(ERROR_SUCCESS, ::GetStagedPackagePathByFullName(packageFullName, &pathLength, path.get())); + return T{ path.get() }; } #if defined(__APPMODEL_IDENTITY_H) @@ -188,19 +206,6 @@ inline bool IsPackageRegistered(PCWSTR packageFullName) inline bool IsPackageStaged(PCWSTR packageFullName) { -#if 0 - UINT32 pathLength{}; - const auto rc{ ::GetStagedPackagePathByFullName(packageFullName, &pathLength, nullptr) }; - if (rc == ERROR_INSUFFICIENT_BUFFER) - { - return true; - } - else if (rc == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) - { - return false; - } - THROW_WIN32(rc); -#else // Check if the package is staged PackageOrigin packageOrigin{}; const auto rc{ GetStagedPackageOrigin(packageFullName, &packageOrigin) }; @@ -213,7 +218,6 @@ inline bool IsPackageStaged(PCWSTR packageFullName) return false; } THROW_WIN32(rc); -#endif } inline bool IsPackageAvailable(PCWSTR packageFullName) @@ -229,21 +233,26 @@ inline std::filesystem::path GetMsixPackagePath(PCWSTR packageDirName) { // Build the target package's .msix filename. It's under the Solution's $(OutDir) // NOTE: It could live in ...\Something.msix\... or ...\Something\... - auto solutionOutDirPath = ::Test::FileSystem::GetSolutionOutDirPath(); - // + auto solutionOutDirPath{ ::Test::FileSystem::GetSolutionOutDirPath() }; + + // Filename is packagedirName plus .msix (if not already present) + std::filesystem::path filename{ packageDirName }; + if (CompareStringOrdinal(filename.extension().c_str(), -1, L".msix", -1, TRUE) != CSTR_EQUAL) + { + filename += L".msix"; + } + // Look in ...\Something.msix\... auto msix(solutionOutDirPath); msix /= packageDirName; msix += L".msix"; - msix /= packageDirName; - msix += L".msix"; + msix /= filename; if (!std::filesystem::is_regular_file(msix)) { // Look in ...\Something\... msix = solutionOutDirPath; msix /= packageDirName; - msix /= packageDirName; - msix += L".msix"; + msix /= filename; WIN32_FILE_ATTRIBUTE_DATA data{}; const auto ok{ GetFileAttributesExW(msix.c_str(), GetFileExInfoStandard, &data) }; const auto lastError{ ::GetLastError() }; @@ -264,17 +273,39 @@ inline winrt::Windows::Foundation::Uri GetMsixPackageUri(PCWSTR packageDirName) return winrt::Windows::Foundation::Uri{ path.c_str() }; } +inline std::filesystem::path GetAppxManifestPackagePath(PCWSTR packageFullName) +{ + auto path{ GetStagedPackagePath(packageFullName) }; + return path / L"AppxManifest.xml"; +} + +inline winrt::Windows::Foundation::Uri GetAppxManifestPackageUri(PCWSTR packageFullName) +{ + auto path{ GetAppxManifestPackagePath(packageFullName) }; + return winrt::Windows::Foundation::Uri{ path.c_str() }; +} + inline void AddPackage(PCWSTR packageDirName, PCWSTR packageFullName) { auto msixUri{ GetMsixPackageUri(packageDirName) }; - // Install the package winrt::Windows::Management::Deployment::PackageManager packageManager; auto options{ winrt::Windows::Management::Deployment::DeploymentOptions::None }; auto deploymentResult{ packageManager.AddPackageAsync(msixUri, nullptr, options).get() }; VERIFY_SUCCEEDED(deploymentResult.ExtendedErrorCode(), WEX::Common::String().Format(L"AddPackageAsync('%s') = 0x%0X %s", packageFullName, deploymentResult.ExtendedErrorCode(), deploymentResult.ErrorText().c_str())); } +inline void AddPackageDefer(PCWSTR packageDirName, PCWSTR packageFullName) +{ + auto msixUri{ GetMsixPackageUri(packageDirName) }; + + winrt::Windows::Management::Deployment::PackageManager packageManager; + winrt::Windows::Management::Deployment::AddPackageOptions options; + options.DeferRegistrationWhenPackagesAreInUse(true); + auto deploymentResult{ packageManager.AddPackageByUriAsync(msixUri, options).get() }; + VERIFY_SUCCEEDED(deploymentResult.ExtendedErrorCode(), WEX::Common::String().Format(L"AddPackageByUriAsync('%s') = 0x%0X %s", packageFullName, deploymentResult.ExtendedErrorCode(), deploymentResult.ErrorText().c_str())); +} + inline void AddPackageIfNecessary(PCWSTR packageDirName, PCWSTR packageFullName) { if (IsPackageRegistered(packageFullName)) @@ -288,11 +319,23 @@ inline void AddPackageIfNecessary(PCWSTR packageDirName, PCWSTR packageFullName) } } +inline void AddPackageDeferIfNecessary(PCWSTR packageDirName, PCWSTR packageFullName) +{ + if (IsPackageRegistered(packageFullName)) + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"AddPackageDeferIfNecessary: %s already registered", packageFullName)); + } + else + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"AddPackageDeferIfNecessary: %s not registered, adding...", packageFullName)); + AddPackageDefer(packageDirName, packageFullName); + } +} + inline void StagePackage(PCWSTR packageDirName, PCWSTR packageFullName) { auto msixUri{ GetMsixPackageUri(packageDirName) }; - // Install the package winrt::Windows::Management::Deployment::PackageManager packageManager; auto options{ winrt::Windows::Management::Deployment::DeploymentOptions::None }; auto deploymentResult{ packageManager.StagePackageAsync(msixUri, nullptr, options).get() }; @@ -312,6 +355,29 @@ inline void StagePackageIfNecessary(PCWSTR packageDirName, PCWSTR packageFullNam } } +inline void RegisterPackage(PCWSTR packageFullName) +{ + winrt::hstring mainPackageFullName{ packageFullName }; + + winrt::Windows::Management::Deployment::PackageManager packageManager; + auto options{ winrt::Windows::Management::Deployment::DeploymentOptions::None }; + auto deploymentResult{ packageManager.RegisterPackageByFullNameAsync(mainPackageFullName, nullptr, options).get() }; + VERIFY_SUCCEEDED(deploymentResult.ExtendedErrorCode(), WEX::Common::String().Format(L"RegisterPackageByFullNameAsync('%s') = 0x%0X %s", packageFullName, deploymentResult.ExtendedErrorCode(), deploymentResult.ErrorText().c_str())); +} + +inline void RegisterPackageIfNecessary(PCWSTR packageFullName) +{ + if (IsPackageRegistered(packageFullName)) + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"RegisterPackageIfNecessary: %s already registered", packageFullName)); + } + else + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"RegisterPackageIfNecessary: %s not registered, adding...", packageFullName)); + RegisterPackage(packageFullName); + } +} + inline void RemovePackage(PCWSTR packageFullName) { winrt::Windows::Management::Deployment::PackageManager packageManager; @@ -330,6 +396,63 @@ inline void RemovePackageIfNecessary(PCWSTR packageFullName) } } +inline bool IsPackageProvisioned(PCWSTR packageFamilyName) +{ + // We have no random access check for a specific package family + // so we'll have to brute force it by scanning the list of all + // provisioned packages for the one we're interested in + winrt::Windows::Management::Deployment::PackageManager packageManager; + const auto provisionedPackages{ packageManager.FindProvisionedPackages() }; + for (const winrt::Windows::ApplicationModel::Package& provisionedPackage: provisionedPackages) + { + if (CompareStringOrdinal(packageFamilyName, -1, provisionedPackage.Id().FamilyName().c_str(), -1, TRUE) == CSTR_EQUAL) + { + return true; + } + } + return false; +} + +inline void ProvisionPackage(PCWSTR packageFamilyName) +{ + winrt::Windows::Management::Deployment::PackageManager packageManager; + auto deploymentResult{ packageManager.ProvisionPackageForAllUsersAsync(packageFamilyName).get() }; + VERIFY_SUCCEEDED(deploymentResult.ExtendedErrorCode(), WEX::Common::String().Format(L"ProvisionPackageForAllUsersAsync('%s') = 0x%0X %s", packageFamilyName, deploymentResult.ExtendedErrorCode(), deploymentResult.ErrorText().c_str())); +} + +inline void ProvisionPackageIfNecessary(PCWSTR packageFamilyName) +{ + if (IsPackageProvisioned(packageFamilyName)) + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"ProvisionPackageIfNecessary: %s already provisioned", packageFamilyName)); + } + else + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"ProvisionPackageIfNecessary: %s not provisioned, provisioning...", packageFamilyName)); + ProvisionPackage(packageFamilyName); + } +} + +inline void DeprovisionPackage(PCWSTR packageFamilyName) +{ + winrt::Windows::Management::Deployment::PackageManager packageManager; + auto deploymentResult{ packageManager.DeprovisionPackageForAllUsersAsync(packageFamilyName).get() }; + VERIFY_SUCCEEDED(deploymentResult.ExtendedErrorCode(), WEX::Common::String().Format(L"DeprovisionPackageForAllUsersAsync('%s') = 0x%0X %s", packageFamilyName, deploymentResult.ExtendedErrorCode(), deploymentResult.ErrorText().c_str())); +} + +inline void DeprovisionPackageIfNecessary(PCWSTR packageFamilyName) +{ + if (IsPackageProvisioned(packageFamilyName)) + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"DeprovisionPackageIfNecessary: %s is provisioned, deprovisioning...", packageFamilyName)); + DeprovisionPackage(packageFamilyName); + } + else + { + WEX::Logging::Log::Comment(WEX::Common::String().Format(L"DeprovisionPackageIfNecessary: %s not provisioned", packageFamilyName)); + } +} + inline void AddPackage_DynamicDependencyLifetimeManager() { AddPackage(Test::Packages::DynamicDependencyLifetimeManager::c_PackageDirName, Test::Packages::DynamicDependencyLifetimeManager::c_PackageFullName); diff --git a/tools/ProjectTemplates/test.cpp.dll.taef/packages.config b/tools/ProjectTemplates/test.cpp.dll.taef/packages.config index ecebfdd18..3a041cbe6 100644 --- a/tools/ProjectTemplates/test.cpp.dll.taef/packages.config +++ b/tools/ProjectTemplates/test.cpp.dll.taef/packages.config @@ -3,7 +3,7 @@ - +