Skip to content

Commit

Permalink
Merge pull request squid-box#16 from squid-box/dev
Browse files Browse the repository at this point in the history
Release with SFX bugfix
  • Loading branch information
squid-box authored Jul 31, 2018
2 parents 8243838 + 2ae033c commit 3600e15
Show file tree
Hide file tree
Showing 39 changed files with 488 additions and 743 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ Backup/
.vs/**
/packages/**
/[Ss]tage/**
/TestResult.xml
/coverage.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SevenZipTests
namespace SevenZip.Tests
{
using System.Collections.Generic;
using System.IO;
Expand Down
27 changes: 27 additions & 0 deletions SevenZip.Tests/LibraryManagerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace SevenZip.Tests
{
using NUnit.Framework;

[TestFixture]
public class LibraryManagerTests : TestBase
{
[Test]
public void SetNonExistant7zDllLocationTest()
{
Assert.Throws<SevenZipLibraryException>(() => SevenZipLibraryManager.SetLibraryPath("null"));
}

[Test]
public void CurrentLibraryFeaturesTest()
{
var features = SevenZipBase.CurrentLibraryFeatures;

// Exercising more code paths...
features = SevenZipLibraryManager.CurrentLibraryFeatures;

Assert.IsTrue(features.HasFlag(LibraryFeature.ExtractAll));
Assert.IsTrue(features.HasFlag(LibraryFeature.CompressAll));
Assert.IsTrue(features.HasFlag(LibraryFeature.Modify));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace SevenZipTests
namespace SevenZip.Tests
{
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;

using NUnit.Framework;
Expand All @@ -14,71 +13,37 @@
public class MiscellaneousTests : TestBase
{
[Test]
public void CurrentLibraryFeaturesTest()
{
Assert.Ignore("Not sure CurrentLibraryFeatures actually work as intended.");

var features = SevenZip.SevenZipExtractor.CurrentLibraryFeatures;
Console.WriteLine(features);
Assert.AreEqual(LibraryFeature.ExtractAll, features);
Assert.AreEqual(LibraryFeature.CompressAll, features);
}

[Test]
public void ToughnessTest()
public void SerializationTest()
{
Assert.Ignore("Not translated yet.");
var ex = new ArgumentException("blahblah");
var bf = new BinaryFormatter();

Console.ReadKey();
string exeAssembly = Assembly.GetAssembly(typeof(SevenZipExtractor)).FullName;
AppDomain dom = AppDomain.CreateDomain("Extract");
for (int i = 0; i < 1000; i++)
using (var ms = new MemoryStream())
{
using (SevenZipExtractor tmp =
(SevenZipExtractor)dom.CreateInstance(
exeAssembly, typeof(SevenZipExtractor).FullName,
false, BindingFlags.CreateInstance, null,
new object[] { @"D:\Temp\7z465_extra.7z" },
System.Globalization.CultureInfo.CurrentCulture, null, null).Unwrap())
using (var fileStream = File.Create(TemporaryFile))
{
tmp.ExtractArchive(@"D:\Temp\!Пусто");
bf.Serialize(ms, ex);
SevenZipCompressor cmpr = new SevenZipCompressor();
cmpr.CompressStream(ms, fileStream);
}
Console.Clear();
Console.WriteLine(i);
}
AppDomain.Unload(dom);
}

[Test]
public void SerializationTest()
public void CreateSfxArchiveTest([Values]SfxModule sfxModule)
{
Assert.Ignore("Not translated yet.");

ArgumentException ex = new ArgumentException("blahblah");
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
if (sfxModule.HasFlag(SfxModule.Custom))
{
bf.Serialize(ms, ex);
SevenZipCompressor cmpr = new SevenZipCompressor();
cmpr.CompressStream(ms, File.Create(@"d:\Temp\test.7z"));
Assert.Ignore("No idea how to use SfxModule \"Custom\".");
}
}

[Test]
public void CreateSfxArchiveTest()
{
Assert.Ignore("Legacy bug, needs investigation.");

var sfxFile = Path.Combine(OutputDirectory, "sfx.exe");
var sfx = new SevenZipSfx(sfxModule);
var compressor = new SevenZipCompressor {DirectoryStructure = false};

var sfx = new SevenZipSfx();
var compressor = new SevenZipCompressor();
compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip");

using (var ms = new MemoryStream())
{
compressor.CompressFiles(ms, @"TestData\zip.zip");
sfx.MakeSfx(ms, sfxFile);
}
sfx.MakeSfx(TemporaryFile, sfxFile);

Assert.IsTrue(File.Exists(sfxFile));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SevenZipTest")]
[assembly: AssemblyTitle("SevenZip.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MIPT")]
[assembly: AssemblyProduct("SevenZipTest")]
[assembly: AssemblyCopyright("Copyright © MIPT 2009")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SevenZipzTests")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("cc5e7de8-0fe2-43c4-a217-1f215bbcd798")]
[assembly: Guid("67192e62-c7fe-485f-bec4-05734a943faa")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<ProjectGuid>{67192E62-C7FE-485F-BEC4-05734A943FAA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SevenZipTests</RootNamespace>
<AssemblyName>SevenZipTests</AssemblyName>
<RootNamespace>SevenZip.Tests</RootNamespace>
<AssemblyName>SevenZip.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
Expand Down Expand Up @@ -55,6 +55,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="LibraryManagerTests.cs" />
<Compile Include="SevenZipCompressorAsynchronousTests.cs" />
<Compile Include="SevenZipExtractorAsynchronousTests.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="FileCheckerTests.cs" />
<Compile Include="MiscellaneousTests.cs" />
Expand Down
189 changes: 189 additions & 0 deletions SevenZip.Tests/SevenZipCompressorAsynchronousTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
namespace SevenZip.Tests
{
using System.Collections.Generic;
using System.IO;
using System.Threading;

using NUnit.Framework;

[TestFixture]
public class SevenZipCompressorAsynchronousTests : TestBase
{
[Test]
public void AsynchronousCompressDirecoryAndEventsTest()
{
var filesFoundInvoked = 0;
var fileCompressionStartedInvoked = 0;
var fileCompressionFinishedInvoked = 0;
var compressingInvoked = 0;
var compressionFinishedInvoked = 0;

var compressor = new SevenZipCompressor();

compressor.FilesFound += (o, e) => filesFoundInvoked++;
compressor.FileCompressionStarted += (o, e) => fileCompressionStartedInvoked++;
compressor.FileCompressionFinished += (o, e) => fileCompressionFinishedInvoked++;
compressor.Compressing += (o, e) => compressingInvoked++;
compressor.CompressionFinished += (o, e) => compressionFinishedInvoked++;

compressor.BeginCompressDirectory(@"TestData", TemporaryFile);

var timeToWait = 1000;
while (compressionFinishedInvoked == 0)
{
if (timeToWait <= 0)
{
break;
}

Thread.Sleep(25);
timeToWait -= 25;
}

var numberOfTestDataFiles = Directory.GetFiles("TestData").Length;

Assert.AreEqual(1, filesFoundInvoked);
Assert.AreEqual(numberOfTestDataFiles, fileCompressionStartedInvoked);
Assert.AreEqual(numberOfTestDataFiles, fileCompressionFinishedInvoked);
Assert.AreEqual(numberOfTestDataFiles, compressingInvoked);
Assert.AreEqual(1, compressionFinishedInvoked);

Assert.IsTrue(File.Exists(TemporaryFile));
}

[Test]
public void AsynchronousCompressFilesTest()
{
var compressionFinishedInvoked = false;

var compressor = new SevenZipCompressor {DirectoryStructure = false};
compressor.CompressionFinished += (o, e) => compressionFinishedInvoked = true;

compressor.BeginCompressFiles(TemporaryFile, @"TestData\zip.zip", @"TestData\tar.tar");

var timeToWait = 1000;
while (!compressionFinishedInvoked)
{
if (timeToWait <= 0)
{
break;
}

Thread.Sleep(25);
timeToWait -= 25;
}

Assert.IsTrue(File.Exists(TemporaryFile));

using (var extractor = new SevenZipExtractor(TemporaryFile))
{
Assert.AreEqual(2, extractor.FilesCount);
Assert.IsTrue(extractor.ArchiveFileNames.Contains("zip.zip"));
Assert.IsTrue(extractor.ArchiveFileNames.Contains("tar.tar"));
}
}

[Test]
public void AsynchronousCompressStreamTest()
{
var compressionFinishedInvoked = false;

var compressor = new SevenZipCompressor { DirectoryStructure = false };
compressor.CompressionFinished += (o, e) => compressionFinishedInvoked = true;

using (var inputStream = File.OpenRead(@"TestData\zip.zip"))
{
using (var outputStream = new FileStream(TemporaryFile, FileMode.Create))
{
compressor.BeginCompressStream(inputStream, outputStream);

var timeToWait = 1000;
while (!compressionFinishedInvoked)
{
if (timeToWait <= 0)
{
break;
}

Thread.Sleep(25);
timeToWait -= 25;
}
}
}

Assert.IsTrue(File.Exists(TemporaryFile));

using (var extractor = new SevenZipExtractor(TemporaryFile))
{
Assert.AreEqual(1, extractor.FilesCount);
}
}

[Test]
public void AsynchronousModifyArchiveTest()
{
var compressor = new SevenZipCompressor { DirectoryStructure = false };

compressor.CompressFiles(TemporaryFile, @"TestData\tar.tar");

var compressionFinishedInvoked = false;
compressor.CompressionFinished += (o, e) => compressionFinishedInvoked = true;

compressor.BeginModifyArchive(TemporaryFile, new Dictionary<int, string>{{0, @"tartar"}});

var timeToWait = 1000;
while (!compressionFinishedInvoked)
{
if (timeToWait <= 0)
{
break;
}

Thread.Sleep(25);
timeToWait -= 25;
}

Assert.IsTrue(File.Exists(TemporaryFile));

using (var extractor = new SevenZipExtractor(TemporaryFile))
{
Assert.AreEqual(1, extractor.FilesCount);
Assert.AreEqual("tartar", extractor.ArchiveFileNames[0]);
}
}

[Test]
public void AsynchronousCompressFilesEncryptedTest()
{
var compressionFinishedInvoked = false;

var compressor = new SevenZipCompressor { DirectoryStructure = false };
compressor.CompressionFinished += (o, e) => compressionFinishedInvoked = true;

compressor.BeginCompressFilesEncrypted(TemporaryFile, "secure", @"TestData\zip.zip", @"TestData\tar.tar");

var timeToWait = 1000;
while (!compressionFinishedInvoked)
{
if (timeToWait <= 0)
{
break;
}

Thread.Sleep(25);
timeToWait -= 25;
}

Assert.IsTrue(File.Exists(TemporaryFile));

using (var extractor = new SevenZipExtractor(TemporaryFile))
{
Assert.AreEqual(2, extractor.FilesCount);
Assert.IsTrue(extractor.ArchiveFileNames.Contains("zip.zip"));
Assert.IsTrue(extractor.ArchiveFileNames.Contains("tar.tar"));

Assert.Throws<ExtractionFailedException>(() => extractor.ExtractArchive(OutputDirectory));
}
}
}
}
Loading

0 comments on commit 3600e15

Please sign in to comment.