diff --git a/test/ICSharpCode.SharpZipLib.Tests/TestSupport/SevenZip.cs b/test/ICSharpCode.SharpZipLib.Tests/TestSupport/SevenZip.cs
new file mode 100644
index 000000000..c312ec401
--- /dev/null
+++ b/test/ICSharpCode.SharpZipLib.Tests/TestSupport/SevenZip.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using NUnit.Framework;
+
+namespace ICSharpCode.SharpZipLib.Tests.TestSupport
+{
+ // Helper class for verifying zips with 7-zip
+ internal static class SevenZipHelper
+ {
+ private static readonly string[] possible7zPaths = new[] {
+ // Check in PATH
+ "7z", "7za",
+
+ // Check in default install location
+ Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "7-Zip", "7z.exe"),
+ Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "7-Zip", "7z.exe"),
+ };
+
+ public static bool TryGet7zBinPath(out string path7z)
+ {
+ var runTimeLimit = TimeSpan.FromSeconds(3);
+
+ foreach (var testPath in possible7zPaths)
+ {
+ try
+ {
+ var p = Process.Start(new ProcessStartInfo(testPath, "i")
+ {
+ RedirectStandardOutput = true,
+ UseShellExecute = false
+ });
+ while (!p.StandardOutput.EndOfStream && (DateTime.Now - p.StartTime) < runTimeLimit)
+ {
+ p.StandardOutput.DiscardBufferedData();
+ }
+ if (!p.HasExited)
+ {
+ p.Close();
+ Assert.Warn($"Timed out checking for 7z binary in \"{testPath}\"!");
+ continue;
+ }
+
+ if (p.ExitCode == 0)
+ {
+ path7z = testPath;
+ return true;
+ }
+ }
+ catch (Exception)
+ {
+ continue;
+ }
+ }
+ path7z = null;
+ return false;
+ }
+
+ ///
+ /// Helper function to verify the provided zip stream with 7Zip.
+ ///
+ /// A stream containing the zip archive to test.
+ /// The password for the archive.
+ internal static void VerifyZipWith7Zip(Stream zipStream, string password)
+ {
+ if (TryGet7zBinPath(out string path7z))
+ {
+ Console.WriteLine($"Using 7z path: \"{path7z}\"");
+
+ var fileName = Path.GetTempFileName();
+
+ try
+ {
+ using (var fs = File.OpenWrite(fileName))
+ {
+ zipStream.Seek(0, SeekOrigin.Begin);
+ zipStream.CopyTo(fs);
+ }
+
+ var p = Process.Start(path7z, $"t -p{password} \"{fileName}\"");
+ if (!p.WaitForExit(2000))
+ {
+ Assert.Warn("Timed out verifying zip file!");
+ }
+
+ Assert.AreEqual(0, p.ExitCode, "Archive verification failed");
+ }
+ finally
+ {
+ File.Delete(fileName);
+ }
+ }
+ else
+ {
+ Assert.Warn("Skipping file verification since 7za is not in path");
+ }
+ }
+ }
+}
diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEncryptionHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEncryptionHandling.cs
index 49317207c..34dde202b 100644
--- a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEncryptionHandling.cs
+++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEncryptionHandling.cs
@@ -1,8 +1,6 @@
-using ICSharpCode.SharpZipLib.Core;
-using ICSharpCode.SharpZipLib.Zip;
+using ICSharpCode.SharpZipLib.Zip;
using NUnit.Framework;
using System;
-using System.Diagnostics;
using System.IO;
using System.Text;
using ICSharpCode.SharpZipLib.Tests.TestSupport;
@@ -74,7 +72,7 @@ public void ZipOutputStreamEncryptEmptyEntries(
zipOutputStream.CloseEntry();
}
- VerifyZipWith7Zip(ms, "password");
+ SevenZipHelper.VerifyZipWith7Zip(ms, "password");
}
}
@@ -315,7 +313,7 @@ public void ZipFileAesAdd()
}
// As an extra test, verify the file with 7-zip
- VerifyZipWith7Zip(memoryStream, password);
+ SevenZipHelper.VerifyZipWith7Zip(memoryStream, password);
}
}
@@ -399,7 +397,7 @@ public void ZipFileAesDelete()
}
// As an extra test, verify the file with 7-zip
- VerifyZipWith7Zip(memoryStream, password);
+ SevenZipHelper.VerifyZipWith7Zip(memoryStream, password);
}
}
@@ -471,54 +469,6 @@ public void ZipinputStreamShouldGracefullyFailWithAESStreams()
}
}
- private static readonly string[] possible7zPaths = new[] {
- // Check in PATH
- "7z", "7za",
-
- // Check in default install location
- Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "7-Zip", "7z.exe"),
- Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "7-Zip", "7z.exe"),
- };
-
- public static bool TryGet7zBinPath(out string path7z)
- {
- var runTimeLimit = TimeSpan.FromSeconds(3);
-
- foreach (var testPath in possible7zPaths)
- {
- try
- {
- var p = Process.Start(new ProcessStartInfo(testPath, "i")
- {
- RedirectStandardOutput = true,
- UseShellExecute = false
- });
- while (!p.StandardOutput.EndOfStream && (DateTime.Now - p.StartTime) < runTimeLimit)
- {
- p.StandardOutput.DiscardBufferedData();
- }
- if (!p.HasExited)
- {
- p.Close();
- Assert.Warn($"Timed out checking for 7z binary in \"{testPath}\"!");
- continue;
- }
-
- if (p.ExitCode == 0)
- {
- path7z = testPath;
- return true;
- }
- }
- catch (Exception)
- {
- continue;
- }
- }
- path7z = null;
- return false;
- }
-
public void WriteEncryptedZipToStream(Stream stream, string password, int keySize, CompressionMethod compressionMethod = CompressionMethod.Deflated)
{
using (var zs = new ZipOutputStream(stream))
@@ -572,51 +522,10 @@ public void CreateZipWithEncryptedEntries(string password, int keySize, Compress
using (var ms = new MemoryStream())
{
WriteEncryptedZipToStream(ms, password, keySize, compressionMethod);
- VerifyZipWith7Zip(ms, password);
- }
- }
-
- ///
- /// Helper function to verify the provided zip stream with 7Zip.
- ///
- /// A stream containing the zip archive to test.
- /// The password for the archive.
- private void VerifyZipWith7Zip(Stream zipStream, string password)
- {
- if (TryGet7zBinPath(out string path7z))
- {
- Console.WriteLine($"Using 7z path: \"{path7z}\"");
-
- var fileName = Path.GetTempFileName();
-
- try
- {
- using (var fs = File.OpenWrite(fileName))
- {
- zipStream.Seek(0, SeekOrigin.Begin);
- zipStream.CopyTo(fs);
- }
-
- var p = Process.Start(path7z, $"t -p{password} \"{fileName}\"");
- if (!p.WaitForExit(2000))
- {
- Assert.Warn("Timed out verifying zip file!");
- }
-
- Assert.AreEqual(0, p.ExitCode, "Archive verification failed");
- }
- finally
- {
- File.Delete(fileName);
- }
- }
- else
- {
- Assert.Warn("Skipping file verification since 7za is not in path");
+ SevenZipHelper.VerifyZipWith7Zip(ms, password);
}
}
-
private const string DummyDataString = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Fusce bibendum diam ac nunc rutrum ornare. Maecenas blandit elit ligula, eget suscipit lectus rutrum eu.
Maecenas aliquam, purus mattis pulvinar pharetra, nunc orci maximus justo, sed facilisis massa dui sed lorem.