winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

MsixManifest.cpp (4204B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "TestCommon.h"
      5 #include <AppInstallerMsixInfo.h>
      6 #include <AppInstallerDownloader.h>
      7 #include <AppInstallerRuntime.h>
      8 #include <winget/MsixManifest.h>
      9 
     10 using namespace TestCommon;
     11 using namespace AppInstaller;
     12 using namespace AppInstaller::Msix;
     13 using namespace Microsoft::WRL;
     14 
     15 namespace
     16 {
     17     // Input values
     18     constexpr std::string_view installerGoodMsix = "Installer-Good.msix";
     19     constexpr std::string_view installerGoodMsixBundle = "Installer-Good.msixbundle";
     20 
     21     // Expected
     22     constexpr std::string_view expectedFamilyName = "FakeInstallerForTesting_125rzkzqaqjwj";
     23     PackageVersion expectedPackageVersion { 0xAAAABBBBCCCCDDDD };
     24     constexpr std::string_view expectedWindowsDesktopName = "Windows.Desktop";
     25     OSVersion expectedWindowsDesktopMinVersion { "10.0.16299.0" };
     26     OSVersion expectedWindowsUniversalMinVersion { "10.0.0.0" };
     27 }
     28 
     29 TEST_CASE("MsixManifest_ValidateFieldsParsedFromManifestReader", "[MsixManifest]")
     30 {
     31     ComPtr<IAppxManifestReader> manifestReader;
     32     REQUIRE(GetMsixPackageManifestReader(installerGoodMsix, &manifestReader));
     33 
     34     Msix::MsixPackageManifest msixManifest(manifestReader);
     35     REQUIRE(expectedFamilyName == msixManifest.GetIdentity().GetPackageFamilyName());
     36     REQUIRE(expectedPackageVersion == msixManifest.GetIdentity().GetVersion());
     37     REQUIRE(2 == msixManifest.GetTargetDeviceFamilies().size());
     38     REQUIRE(expectedWindowsUniversalMinVersion == msixManifest.GetMinimumOSVersionForSupportedPlatforms().value());
     39 
     40     auto targets = msixManifest.GetTargetDeviceFamilies();
     41     auto windowsDesktop = std::find_if(targets.begin(), targets.end(), [](auto& t) { return t.GetMinVersion() == expectedWindowsDesktopMinVersion; });
     42     REQUIRE(windowsDesktop != targets.end());
     43 
     44     auto windowsUniversal = std::find_if(targets.begin(), targets.end(), [](auto& t) { return t.GetMinVersion() == expectedWindowsUniversalMinVersion; });
     45     REQUIRE(windowsUniversal != targets.end());
     46 }
     47 
     48 TEST_CASE("MsixManifest_ValidateFieldsParsedFromMsix", "[MsixManifest]")
     49 {
     50     TestDataFile testFile(installerGoodMsix);
     51     MsixInfo msixInfo(testFile.GetPath());
     52 
     53     auto appPackageManifests = msixInfo.GetAppPackageManifests();
     54     REQUIRE(1 == appPackageManifests.size());
     55 
     56     auto &appPackageManifest = appPackageManifests[0];
     57     REQUIRE(expectedFamilyName == appPackageManifest.GetIdentity().GetPackageFamilyName());
     58     REQUIRE(expectedPackageVersion == appPackageManifest.GetIdentity().GetVersion());
     59     REQUIRE(2 == appPackageManifest.GetTargetDeviceFamilies().size());
     60     REQUIRE(expectedWindowsUniversalMinVersion == appPackageManifest.GetMinimumOSVersionForSupportedPlatforms().value());
     61 
     62     auto targets = appPackageManifest.GetTargetDeviceFamilies();
     63     auto windowsDesktop = std::find_if(targets.begin(), targets.end(), [](auto& t) { return t.GetMinVersion() == expectedWindowsDesktopMinVersion; });
     64     REQUIRE(windowsDesktop != targets.end());
     65 
     66     auto windowsUniversal = std::find_if(targets.begin(), targets.end(), [](auto& t) { return t.GetMinVersion() == expectedWindowsUniversalMinVersion; });
     67     REQUIRE(windowsUniversal != targets.end());
     68 }
     69 
     70 TEST_CASE("MsixManifest_ValidateFieldsParsedFromMsixBundle", "[MsixManifest]")
     71 {
     72     TestDataFile testFile(installerGoodMsixBundle);
     73     MsixInfo msixInfo(testFile.GetPath());
     74     
     75     auto appPackageManifests = msixInfo.GetAppPackageManifests();
     76     REQUIRE(2 == appPackageManifests.size());
     77 
     78     for (auto& appPackageManifest : appPackageManifests)
     79     {
     80         REQUIRE(expectedFamilyName == appPackageManifest.GetIdentity().GetPackageFamilyName());
     81         REQUIRE(expectedPackageVersion == appPackageManifest.GetIdentity().GetVersion());
     82         REQUIRE(1 == appPackageManifest.GetTargetDeviceFamilies().size());
     83         REQUIRE(expectedWindowsDesktopName == appPackageManifest.GetTargetDeviceFamilies().front().GetName());
     84         REQUIRE(expectedWindowsDesktopMinVersion == appPackageManifest.GetTargetDeviceFamilies().front().GetMinVersion());
     85         REQUIRE(expectedWindowsDesktopMinVersion == appPackageManifest.GetMinimumOSVersionForSupportedPlatforms().value());
     86     }
     87 }