-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathArchive.cpp
More file actions
82 lines (64 loc) · 2.49 KB
/
Archive.cpp
File metadata and controls
82 lines (64 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "TestCommon.h"
#include "WorkflowCommon.h"
#include <winget/Archive.h>
#include <Workflows/ShellExecuteInstallerHandler.h>
using namespace AppInstaller::Archive;
using namespace AppInstaller::CLI::Workflow;
using namespace AppInstaller::Settings;
using namespace TestCommon;
constexpr std::string_view s_ZipFile = "TestZip.zip";
constexpr std::string_view s_TarGzFile = "TestTarGz.tar.gz";
constexpr std::string_view s_Large7zFile = "TestLarge7z.7z";
TEST_CASE("Extract_ZipArchive", "[archive]")
{
TestCommon::TempDirectory tempDirectory("TempDirectory");
TestDataFile testZip(s_ZipFile);
const auto& testZipPath = testZip.GetPath();
const auto& tempDirectoryPath = tempDirectory.GetPath();
HRESULT hr = TryExtractArchive(testZipPath, tempDirectoryPath);
std::filesystem::path expectedPath = tempDirectoryPath / "test.txt";
REQUIRE(SUCCEEDED(hr));
REQUIRE(std::filesystem::exists(expectedPath));
}
TEST_CASE("Scan_ZipArchive", "[archive]")
{
TestDataFile testZip(s_ZipFile);
const auto& testZipPath = testZip.GetPath();
bool result = ScanZipFile(testZipPath);
REQUIRE(result);
}
TEST_CASE("Extract_TarGzArchive", "[archive]")
{
TestCommon::TempDirectory tempDirectory("TempDirectory");
TestDataFile testTarGz(s_TarGzFile);
TestCommon::TestUserSettings testSettings;
testSettings.Set<Setting::ArchiveExtractionMethod>(AppInstaller::Archive::ExtractionMethod::Tar);
const auto& testTarGzPath = testTarGz.GetPath();
const auto& tempDirectoryPath = tempDirectory.GetPath();
ShellExecuteExtractArchive(testTarGzPath, tempDirectoryPath);
std::ostringstream extractOutput;
TestContext context{ extractOutput, std::cin };
context << ShellExecuteExtractArchive(testTarGzPath, tempDirectoryPath);
std::filesystem::path expectedPath = tempDirectoryPath / "test.txt";
REQUIRE(SUCCEEDED(context.GetTerminationHR()));
REQUIRE(std::filesystem::exists(expectedPath));
INFO(extractOutput.str());
}
TEST_CASE("Scan_TarGzArchive", "[archive]")
{
TestDataFile testTarGz(s_TarGzFile);
const auto& testTarGzPath = testTarGz.GetPath();
bool result = ScanZipFile(testTarGzPath);
REQUIRE(result);
}
//TEST_CASE("Scan_Large7zArchive", "[archive]")
//{
// TestDataFile testLarge7z(s_Large7zFile);
//
// const auto& testTarGzPath = testLarge7z.GetPath();
// bool result = ScanZipFile(testTarGzPath);
// REQUIRE(result);
//}