Skip to content

Commit 37c3a9e

Browse files
authored
Merge PR #468: Add test for adding empty folders to archives using FastZip
1 parent 861a313 commit 37c3a9e

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

test/ICSharpCode.SharpZipLib.Tests/Zip/FastZipHandling.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,45 @@ public void ExtractEmptyDirectories()
9393
Assert.IsTrue(Directory.Exists(targetDir), "Empty directory should be created");
9494
}
9595

96+
/// <summary>
97+
/// Test that FastZip can create empty directory entries in archives.
98+
/// </summary>
99+
[TestCase(null)]
100+
[TestCase("password")]
101+
[Category("Zip")]
102+
[Category("CreatesTempFile")]
103+
public void CreateEmptyDirectories(string password)
104+
{
105+
using (var tempFilePath = new Utils.TempDir())
106+
{
107+
string name = Path.Combine(tempFilePath.Fullpath, "x.zip");
108+
109+
// Create empty test folders (The folder that we'll zip, and the test sub folder).
110+
string archiveRootDir = Path.Combine(tempFilePath.Fullpath, ZipTempDir);
111+
string targetDir = Path.Combine(archiveRootDir, "floyd");
112+
Directory.CreateDirectory(targetDir);
113+
114+
// Create the archive with FastZip
115+
var fastZip = new FastZip
116+
{
117+
CreateEmptyDirectories = true,
118+
Password = password,
119+
};
120+
fastZip.CreateZip(name, archiveRootDir, true, null);
121+
122+
// Test that the archive contains the empty folder entry
123+
using (var zipFile = new ZipFile(name))
124+
{
125+
Assert.That(zipFile.Count, Is.EqualTo(1), "Should only be one entry in the file");
126+
127+
var folderEntry = zipFile.GetEntry("floyd/");
128+
Assert.That(folderEntry.IsDirectory, Is.True, "The entry must be a folder");
129+
130+
Assert.IsTrue(zipFile.TestArchive(true));
131+
}
132+
}
133+
}
134+
96135
[Test]
97136
[Category("Zip")]
98137
[Category("CreatesTempFile")]

0 commit comments

Comments
 (0)