Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test for FastZip adding empty folders to archives #468

Merged
merged 1 commit into from
Jun 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/FastZipHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,45 @@ public void ExtractEmptyDirectories()
Assert.IsTrue(Directory.Exists(targetDir), "Empty directory should be created");
}

/// <summary>
/// Test that FastZip can create empty directory entries in archives.
/// </summary>
[TestCase(null)]
[TestCase("password")]
[Category("Zip")]
[Category("CreatesTempFile")]
public void CreateEmptyDirectories(string password)
{
using (var tempFilePath = new Utils.TempDir())
{
string name = Path.Combine(tempFilePath.Fullpath, "x.zip");

// Create empty test folders (The folder that we'll zip, and the test sub folder).
string archiveRootDir = Path.Combine(tempFilePath.Fullpath, ZipTempDir);
string targetDir = Path.Combine(archiveRootDir, "floyd");
Directory.CreateDirectory(targetDir);

// Create the archive with FastZip
var fastZip = new FastZip
{
CreateEmptyDirectories = true,
Password = password,
};
fastZip.CreateZip(name, archiveRootDir, true, null);

// Test that the archive contains the empty folder entry
using (var zipFile = new ZipFile(name))
{
Assert.That(zipFile.Count, Is.EqualTo(1), "Should only be one entry in the file");

var folderEntry = zipFile.GetEntry("floyd/");
Assert.That(folderEntry.IsDirectory, Is.True, "The entry must be a folder");

Assert.IsTrue(zipFile.TestArchive(true));
}
}
}

[Test]
[Category("Zip")]
[Category("CreatesTempFile")]
Expand Down