Skip to content

Commit edc8cf4

Browse files
authored
Merge branch 'dev' into master
2 parents 0f7db45 + 2ae033c commit edc8cf4

File tree

172 files changed

+2600
-13722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+2600
-13722
lines changed

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
*.suo
22
Backup/
33
*.user
4-
bin/
5-
obj/
4+
/*/bin/**
5+
/*/obj/**
66
/SevenZip/UpgradeLog.htm
7+
/SevenZip/.vs/**
8+
.vs/**
9+
/packages/**
10+
/[Ss]tage/**
11+
/TestResult.xml
12+
/coverage.xml

SevenZip.Tests/FileCheckerTests.cs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
namespace SevenZip.Tests
2+
{
3+
using System.Collections.Generic;
4+
using System.IO;
5+
6+
using SevenZip;
7+
8+
using NUnit.Framework;
9+
10+
/// <summary>
11+
/// Test data to use for CheckFileSignatureTest.
12+
/// </summary>
13+
public struct FileCheckerTestData
14+
{
15+
public FileCheckerTestData(string testDataFilePath, InArchiveFormat expectedFormat)
16+
{
17+
TestDataFilePath = testDataFilePath;
18+
ExpectedFormat = expectedFormat;
19+
}
20+
21+
/// <summary>
22+
/// Format this test expects to find.
23+
/// </summary>
24+
public InArchiveFormat ExpectedFormat { get; }
25+
26+
/// <summary>
27+
/// Path to archive file to test against.
28+
/// </summary>
29+
public string TestDataFilePath { get; }
30+
31+
public override string ToString()
32+
{
33+
// Used to get useful test results.
34+
return ExpectedFormat.ToString();
35+
}
36+
}
37+
38+
[TestFixture]
39+
public class FileCheckerTests
40+
{
41+
/// <summary>
42+
/// Test data for CheckFileSignature test.
43+
/// </summary>
44+
public static List<FileCheckerTestData> TestData = new List<FileCheckerTestData>
45+
{
46+
new FileCheckerTestData(@"TestData\arj.arj", InArchiveFormat.Arj),
47+
new FileCheckerTestData(@"TestData\bzip2.bz2", InArchiveFormat.BZip2),
48+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Cab),
49+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Chm),
50+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Compound),
51+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Cpio),
52+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Deb),
53+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Dmg),
54+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Elf),
55+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Flv),
56+
new FileCheckerTestData(@"TestData\gzip.gz", InArchiveFormat.GZip),
57+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Hfs),
58+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Iso),
59+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Lzh),
60+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Lzma),
61+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Lzw),
62+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Msi),
63+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Mslz),
64+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Mub),
65+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Nsis),
66+
new FileCheckerTestData(@"TestData\", InArchiveFormat.PE),
67+
new FileCheckerTestData(@"TestData\rar5.rar", InArchiveFormat.Rar),
68+
new FileCheckerTestData(@"TestData\rar4.rar", InArchiveFormat.Rar4),
69+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Rpm),
70+
new FileCheckerTestData(@"TestData\7z_LZMA2.7z", InArchiveFormat.SevenZip),
71+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Split),
72+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Swf),
73+
new FileCheckerTestData(@"TestData\tar.tar", InArchiveFormat.Tar),
74+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Udf),
75+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Vhd),
76+
new FileCheckerTestData(@"TestData\wim.wim", InArchiveFormat.Wim),
77+
new FileCheckerTestData(@"TestData\xz.xz", InArchiveFormat.XZ),
78+
new FileCheckerTestData(@"TestData\", InArchiveFormat.Xar),
79+
new FileCheckerTestData(@"TestData\zip.zip", InArchiveFormat.Zip)
80+
};
81+
82+
[SetUp]
83+
public void SetUp()
84+
{
85+
// Ensures we're in the correct working directory (for test data files).
86+
Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
87+
}
88+
89+
[TestCaseSource(nameof(TestData))]
90+
public void CheckFileSignatureTest(FileCheckerTestData data)
91+
{
92+
if (!File.Exists(data.TestDataFilePath))
93+
{
94+
Assert.Ignore("No test data found for this format.");
95+
}
96+
else
97+
{
98+
int ignored;
99+
bool ignored2;
100+
Assert.AreEqual(data.ExpectedFormat, FileChecker.CheckSignature(data.TestDataFilePath, out ignored, out ignored2));
101+
}
102+
}
103+
}
104+
}

SevenZip.Tests/LibraryManagerTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace SevenZip.Tests
2+
{
3+
using NUnit.Framework;
4+
5+
[TestFixture]
6+
public class LibraryManagerTests : TestBase
7+
{
8+
[Test]
9+
public void SetNonExistant7zDllLocationTest()
10+
{
11+
Assert.Throws<SevenZipLibraryException>(() => SevenZipLibraryManager.SetLibraryPath("null"));
12+
}
13+
14+
[Test]
15+
public void CurrentLibraryFeaturesTest()
16+
{
17+
var features = SevenZipBase.CurrentLibraryFeatures;
18+
19+
// Exercising more code paths...
20+
features = SevenZipLibraryManager.CurrentLibraryFeatures;
21+
22+
Assert.IsTrue(features.HasFlag(LibraryFeature.ExtractAll));
23+
Assert.IsTrue(features.HasFlag(LibraryFeature.CompressAll));
24+
Assert.IsTrue(features.HasFlag(LibraryFeature.Modify));
25+
}
26+
}
27+
}

SevenZip.Tests/MiscellaneousTests.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
namespace SevenZip.Tests
2+
{
3+
using System;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Runtime.Serialization.Formatters.Binary;
7+
8+
using NUnit.Framework;
9+
10+
using SevenZip;
11+
12+
[TestFixture]
13+
public class MiscellaneousTests : TestBase
14+
{
15+
[Test]
16+
public void SerializationTest()
17+
{
18+
var ex = new ArgumentException("blahblah");
19+
var bf = new BinaryFormatter();
20+
21+
using (var ms = new MemoryStream())
22+
{
23+
using (var fileStream = File.Create(TemporaryFile))
24+
{
25+
bf.Serialize(ms, ex);
26+
SevenZipCompressor cmpr = new SevenZipCompressor();
27+
cmpr.CompressStream(ms, fileStream);
28+
}
29+
}
30+
}
31+
32+
[Test]
33+
public void CreateSfxArchiveTest([Values]SfxModule sfxModule)
34+
{
35+
if (sfxModule.HasFlag(SfxModule.Custom))
36+
{
37+
Assert.Ignore("No idea how to use SfxModule \"Custom\".");
38+
}
39+
40+
var sfxFile = Path.Combine(OutputDirectory, "sfx.exe");
41+
var sfx = new SevenZipSfx(sfxModule);
42+
var compressor = new SevenZipCompressor {DirectoryStructure = false};
43+
44+
compressor.CompressFiles(TemporaryFile, @"TestData\zip.zip");
45+
46+
sfx.MakeSfx(TemporaryFile, sfxFile);
47+
48+
Assert.IsTrue(File.Exists(sfxFile));
49+
50+
using (var extractor = new SevenZipExtractor(sfxFile))
51+
{
52+
Assert.AreEqual(1, extractor.FilesCount);
53+
Assert.AreEqual("zip.zip", extractor.ArchiveFileNames[0]);
54+
}
55+
56+
Assert.DoesNotThrow(() =>
57+
{
58+
var process = Process.Start(sfxFile);
59+
process?.Kill();
60+
});
61+
}
62+
63+
[Test]
64+
public void LzmaEncodeDecodeTest()
65+
{
66+
using (var output = new FileStream(TemporaryFile, FileMode.Create))
67+
{
68+
var encoder = new LzmaEncodeStream(output);
69+
using (var inputSample = new FileStream(@"TestData\zip.zip", FileMode.Open))
70+
{
71+
int bufSize = 24576, count;
72+
var buf = new byte[bufSize];
73+
74+
while ((count = inputSample.Read(buf, 0, bufSize)) > 0)
75+
{
76+
encoder.Write(buf, 0, count);
77+
}
78+
}
79+
80+
encoder.Close();
81+
}
82+
83+
var newZip = Path.Combine(OutputDirectory, "new.zip");
84+
85+
using (var input = new FileStream(TemporaryFile, FileMode.Open))
86+
{
87+
var decoder = new LzmaDecodeStream(input);
88+
using (var output = new FileStream(newZip, FileMode.Create))
89+
{
90+
int bufSize = 24576, count;
91+
var buf = new byte[bufSize];
92+
93+
while ((count = decoder.Read(buf, 0, bufSize)) > 0)
94+
{
95+
output.Write(buf, 0, count);
96+
}
97+
}
98+
}
99+
100+
Assert.IsTrue(File.Exists(newZip));
101+
102+
using (var extractor = new SevenZipExtractor(newZip))
103+
{
104+
Assert.AreEqual(1, extractor.FilesCount);
105+
Assert.AreEqual("zip.txt", extractor.ArchiveFileNames[0]);
106+
}
107+
}
108+
}
109+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following
65
// set of attributes. Change these attribute values to modify the information
76
// associated with an assembly.
8-
[assembly: AssemblyTitle("SevenZipSharpMobileTest")]
7+
[assembly: AssemblyTitle("SevenZip.Tests")]
98
[assembly: AssemblyDescription("")]
109
[assembly: AssemblyConfiguration("")]
1110
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("SevenZipSharpMobileTest")]
13-
[assembly: AssemblyCopyright("Copyright © 2010")]
11+
[assembly: AssemblyProduct("SevenZipzTests")]
12+
[assembly: AssemblyCopyright("Copyright © 2018")]
1413
[assembly: AssemblyTrademark("")]
1514
[assembly: AssemblyCulture("")]
1615

@@ -20,7 +19,7 @@
2019
[assembly: ComVisible(false)]
2120

2221
// The following GUID is for the ID of the typelib if this project is exposed to COM
23-
[assembly: Guid("faa27044-4cde-43d9-950f-9b87d815d4dd")]
22+
[assembly: Guid("67192e62-c7fe-485f-bec4-05734a943faa")]
2423

2524
// Version information for an assembly consists of the following four values:
2625
//
@@ -29,8 +28,8 @@
2928
// Build Number
3029
// Revision
3130
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
3234
[assembly: AssemblyVersion("1.0.0.0")]
33-
34-
// Below attribute is to suppress FxCop warning "CA2232 : Microsoft.Usage : Add STAThreadAttribute to assembly"
35-
// as Device app does not support STA thread.
36-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2232:MarkWindowsFormsEntryPointsWithStaThread")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)