Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net47</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AssemblyTitle>Benchmark</AssemblyTitle>
<Product>Benchmark</Product>
<Copyright>Copyright © 2020</Copyright>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SevenZipExtractor\SevenZipExtractor.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApplication86</RootNamespace>
<AssemblyName>ConsoleApplication86</AssemblyName>
<TargetFramework>net45</TargetFramework>
<TargetFrameworks>net6.0</TargetFrameworks>
<AssemblyTitle>ConsoleApplication86</AssemblyTitle>
<Product>ConsoleApplication86</Product>
<Copyright>Copyright © 2016</Copyright>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SevenZipExtractor\SevenZipExtractor.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Main(string[] args)
Console.WriteLine(entry.FileName);

// extract to file
entry.Extract(entry.FileName);
entry.Extract(entry.FileName ?? "NoFileName");

// extract to stream
MemoryStream memoryStream = new MemoryStream();
Expand Down
2 changes: 1 addition & 1 deletion SevenZipExtractor.Tests/Crc32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class Crc32 : HashAlgorithm
public const UInt32 DefaultPolynomial = 0xedb88320u;
public const UInt32 DefaultSeed = 0xffffffffu;

static UInt32[] defaultTable;
static UInt32[]? defaultTable;

readonly UInt32 seed;
readonly UInt32[] table;
Expand Down
Binary file added SevenZipExtractor.Tests/Resources/cab.cab
Binary file not shown.
Binary file added SevenZipExtractor.Tests/Resources/mslz.dl_
Binary file not shown.
13 changes: 6 additions & 7 deletions SevenZipExtractor.Tests/SevenZipExtractor.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFrameworks>net6.0</TargetFrameworks>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
Expand All @@ -11,15 +11,14 @@
<Copyright>Copyright © 2019</Copyright>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Platforms>AnyCPU;x64;x86</Platforms>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<Nullable>enable</Nullable>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
</ItemGroup>
<ItemGroup>
<Compile Update="TestFiles.Designer.cs">
Expand Down
13 changes: 9 additions & 4 deletions SevenZipExtractor.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ public abstract class TestBase
new TestFileEntry { Name = "testFolder\\image3.jpg", IsFolder = false, MD5 = "24ffd227340432596fe61ef6300098ad"},
};

protected void TestExtractToStream(byte[] archiveBytes, IList<TestFileEntry> expected, SevenZipFormat? sevenZipFormat = null)
protected IList<TestFileEntry> TestSingleFile = new List<TestFileEntry>()
{
new TestFileEntry { Name = "image1.jpg", IsFolder = false, MD5 = "b3144b66569ab0052b4019a2b4c07a31"},
};

protected void TestExtractToStream(byte[] archiveBytes, IList<TestFileEntry> expected, SevenZipFormat? sevenZipFormat = null, string? fileName = null)
{
MemoryStream memoryStream = new MemoryStream(archiveBytes);

using (ArchiveFile archiveFile = new ArchiveFile(memoryStream, sevenZipFormat))
using (ArchiveFile archiveFile = new ArchiveFile(memoryStream, sevenZipFormat, null, fileName))
{
foreach (TestFileEntry testEntry in expected)
{
Entry entry = archiveFile.Entries.FirstOrDefault(e => e.FileName == testEntry.Name && e.IsFolder == testEntry.IsFolder);
Entry? entry = archiveFile.Entries.FirstOrDefault(e => e.FileName == testEntry.Name && e.IsFolder == testEntry.IsFolder);

Assert.IsNotNull(entry, "Entry not found: " + testEntry.Name);

Expand All @@ -42,7 +47,7 @@ protected void TestExtractToStream(byte[] archiveBytes, IList<TestFileEntry> exp

using (MemoryStream entryMemoryStream = new MemoryStream())
{
entry.Extract(entryMemoryStream);
entry!.Extract(entryMemoryStream);

if (testEntry.MD5 != null)
{
Expand Down
17 changes: 17 additions & 0 deletions SevenZipExtractor.Tests/TestCab.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SevenZipExtractor;

namespace SevenZipExtractor.Tests {
[TestClass]
public class TestCab : TestBase {
[TestMethod]
public void TestGuessAndExtractToStream_OK() {
this.TestExtractToStream(Resources.TestFiles.cab, this.TestSingleFile);
}

[TestMethod]
public void TestKnownFormatAndExtractToStream_OK() {
this.TestExtractToStream(Resources.TestFiles.cab, this.TestSingleFile, SevenZipFormat.Cab);
}
}
}
22 changes: 21 additions & 1 deletion SevenZipExtractor.Tests/TestFiles.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions SevenZipExtractor.Tests/TestFiles.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,15 @@
<data name="ansimate_arj" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\ansimate-arj.arj;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="cab" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>resources\cab.cab;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="lzh" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\lzh.lzh;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="mslz" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>resources\mslz.dl_;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="rar" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\rar.rar;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
29 changes: 29 additions & 0 deletions SevenZipExtractor.Tests/TestMSCF.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SevenZipExtractor;
using SevenZipExtractor.Tests;
using System.Collections.Generic;
using System.Linq;

namespace SevenZipExtractor.Tests
{
[TestClass]
public class TestMSCF : TestBase {

protected IList<TestFileEntry> TestSingleDllFile = new List<TestFileEntry>()
{
new TestFileEntry { Name = "mslz.dll", IsFolder = false, MD5 = "b3144b66569ab0052b4019a2b4c07a31"},
};

[TestMethod]
public void TestGuessAndExtractToStream_OK()
{
this.TestExtractToStream(Resources.TestFiles.mslz, TestSingleDllFile, null, "mslz.dl_");
}

[TestMethod]
public void TestKnownFormatAndExtractToStream_OK()
{
this.TestExtractToStream(Resources.TestFiles.mslz, TestSingleDllFile, SevenZipFormat.Mslz, "mslz.dl_");
}
}
}
14 changes: 13 additions & 1 deletion SevenZipExtractor.Tests/TestZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SevenZipExtractor.Tests
{
[TestClass]
public class TestZip : TestBase
public class TestZip : TestBase
{
[TestMethod]
public void TestGuessAndExtractToStream_OK()
Expand All @@ -16,5 +16,17 @@ public void TestKnownFormatAndExtractToStream_OK()
{
this.TestExtractToStream(Resources.TestFiles.zip, this.TestEntriesWithFolder, SevenZipFormat.Zip);
}

[TestMethod]
public void TestGuessAndExtractToStreamWithFileName_OK()
{
this.TestExtractToStream(Resources.TestFiles.zip, this.TestEntriesWithFolder, null, "zip.zip");
}

[TestMethod]
public void TestKnownFormatAndExtractToStreamWithFileName_OK()
{
this.TestExtractToStream(Resources.TestFiles.zip, this.TestEntriesWithFolder, SevenZipFormat.Zip, "zip.zip");
}
}
}
Loading