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
2 changes: 1 addition & 1 deletion Examples/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<configuration>
<startup>

<supportedRuntime version="v2.0.50727"/></startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To integrate unit test, targeted .Net Framework 4 Client Profile.
Multi targeting would be useful to keep compatibility with .Net Framework 2.0 ~ 3.5.

</configuration>
4 changes: 2 additions & 2 deletions Examples/Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Examples</RootNamespace>
<AssemblyName>Examples</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
20 changes: 20 additions & 0 deletions XZ.NET.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("XZ.Net.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XZ.Net.Tests")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("d5018c9d-9a97-4655-bd12-6efc92db0217")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file added XZ.NET.Tests/Samples/A.pdf
Binary file not shown.
Binary file added XZ.NET.Tests/Samples/A.xz
Binary file not shown.
Binary file added XZ.NET.Tests/Samples/B.txt
Binary file not shown.
Binary file added XZ.NET.Tests/Samples/B1.xz
Binary file not shown.
Binary file added XZ.NET.Tests/Samples/B9.xz
Binary file not shown.
Binary file added XZ.NET.Tests/Samples/C.bin
Binary file not shown.
Binary file added XZ.NET.Tests/Samples/C.xz
Binary file not shown.
Binary file added XZ.NET.Tests/Samples/xz.exe
Binary file not shown.
40 changes: 40 additions & 0 deletions XZ.NET.Tests/TestSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace XZ.NET.Tests
{
[TestClass]
public class TestSetup
{
public static string BaseDir;
public static string SampleDir;

[AssemblyInitialize]
public static void Init(TestContext context)
{
BaseDir = Path.GetFullPath(Path.Combine(TestHelper.GetProgramAbsolutePath(), "..", ".."));
SampleDir = Path.Combine(BaseDir, "Samples");
}

[AssemblyCleanup]
public static void Cleanup()
{
}
}

public class TestHelper
{
public static string GetProgramAbsolutePath()
{
string path = AppDomain.CurrentDomain.BaseDirectory;
if (Path.GetDirectoryName(path) != null)
path = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
return path;
}
}
}
75 changes: 75 additions & 0 deletions XZ.NET.Tests/XZ.NET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\XZ.NET\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\XZ.NET\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D5018C9D-9A97-4655-BD12-6EFC92DB0217}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XZ.NET.Tests</RootNamespace>
<AssemblyName>XZ.NET.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\XZ.NET\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\XZ.NET\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="TestSetup.cs" />
<Compile Include="XZInputStream.Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XZOutputStream.Tests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XZ.NET\XZ.NET.csproj">
<Project>{2A389B68-70DC-4853-81AE-56484F32E94D}</Project>
<Name>XZ.NET</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>이 프로젝트는 이 컴퓨터에 없는 NuGet 패키지를 참조합니다. 해당 패키지를 다운로드하려면 NuGet 패키지 복원을 사용하십시오. 자세한 내용은 http://go.microsoft.com/fwlink/?LinkID=322105를 참조하십시오. 누락된 파일은 {0}입니다.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\XZ.NET\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\XZ.NET\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\XZ.NET\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\XZ.NET\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\XZ.NET\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\XZ.NET\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets')" />
</Project>
52 changes: 52 additions & 0 deletions XZ.NET.Tests/XZInputStream.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using XZ.NET;

namespace XZ.NET.Tests
{
[TestClass]
public class XZInputStreamTests
{
[TestMethod]
[TestCategory("XZ.NET")]
public void Decompress()
{
Decompress_Template("A.xz", "A.pdf");
Decompress_Template("B9.xz", "B.txt");
Decompress_Template("B1.xz", "B.txt");
Decompress_Template("C.xz", "C.bin");
}

public void Decompress_Template(string xzFileName, string originFileName)
{
byte[] decompDigest;
byte[] originDigest;

string xzFile = Path.Combine(TestSetup.SampleDir, xzFileName);
string originFile = Path.Combine(TestSetup.SampleDir, originFileName);
using (MemoryStream decompMs = new MemoryStream())
{
using (FileStream compFs = new FileStream(xzFile, FileMode.Open, FileAccess.Read, FileShare.Read))
using (XZInputStream xz = new XZInputStream(compFs))
{
xz.CopyTo(decompMs);
}
decompMs.Position = 0;

HashAlgorithm hash = SHA256.Create();
decompDigest = hash.ComputeHash(decompMs);
}

using (FileStream originFs = new FileStream(originFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
HashAlgorithm hash = SHA256.Create();
originDigest = hash.ComputeHash(originFs);
}

Assert.IsTrue(decompDigest.SequenceEqual(originDigest));
}
}
}
86 changes: 86 additions & 0 deletions XZ.NET.Tests/XZOutputStream.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using XZ.NET;

namespace XZ.NET.Tests
{
[TestClass]
public class XZOutputStreamTests
{
[TestMethod]
[TestCategory("XZ.NET")]
public void Compress()
{
Compress_Template("A.pdf", 1, 9);
Compress_Template("B.txt", 1, XZOutputStream.DefaultPreset);
Compress_Template("C.bin", 1, 1);
}

[TestMethod]
[TestCategory("XZ.NET")]
public void CompressMultithread()
{
Compress_Template("A.pdf", 2, 6);
Compress_Template("B.txt", 2, 4);
Compress_Template("C.bin", Environment.ProcessorCount, 1);
}

public void Compress_Template(string sampleFileName, int threads, uint preset)
{
string tempDecompFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string tempXzFile = tempDecompFile + ".xz";
try
{
string sampleFile = Path.Combine(TestSetup.SampleDir, sampleFileName);
using (FileStream xzCompFs = new FileStream(tempXzFile, FileMode.Create, FileAccess.Write, FileShare.None))
using (FileStream sampleFs = new FileStream(sampleFile, FileMode.Open, FileAccess.Read, FileShare.Read))
using (XZOutputStream xz = new XZOutputStream(xzCompFs, threads, preset, true))
{
sampleFs.CopyTo(xz);
}

Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
UseShellExecute = false,
CreateNoWindow = true,
FileName = Path.Combine(TestSetup.SampleDir, "xz.exe"),
Arguments = $"-k -d {tempXzFile}",
}
};
proc.Start();
proc.WaitForExit();
Assert.IsTrue(proc.ExitCode == 0);

byte[] decompDigest;
byte[] originDigest;
using (FileStream fs = new FileStream(sampleFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
HashAlgorithm hash = SHA256.Create();
originDigest = hash.ComputeHash(fs);
}

using (FileStream fs = new FileStream(tempDecompFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
HashAlgorithm hash = SHA256.Create();
decompDigest = hash.ComputeHash(fs);
}

Assert.IsTrue(originDigest.SequenceEqual(decompDigest));

}
finally
{
if (File.Exists(tempXzFile))
File.Delete(tempXzFile);
if (File.Exists(tempDecompFile))
File.Delete(tempDecompFile);
}
}
}
}
5 changes: 5 additions & 0 deletions XZ.NET.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.2.0" targetFramework="net45" />
<package id="MSTest.TestFramework" version="1.2.0" targetFramework="net45" />
</packages>
6 changes: 4 additions & 2 deletions XZ.NET/XZ.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XZ.NET</RootNamespace>
<AssemblyName>XZ.NET</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -30,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
9 changes: 9 additions & 0 deletions XZ.NET/XZ.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XZ.NET", "XZ.NET.csproj", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "..\Examples\Examples.csproj", "{EBEC5795-82AB-455E-806B-64099BA50A0A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XZ.NET.Tests", "..\XZ.NET.Tests\XZ.NET.Tests.csproj", "{D5018C9D-9A97-4655-BD12-6EFC92DB0217}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,8 +23,15 @@ Global
{EBEC5795-82AB-455E-806B-64099BA50A0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBEC5795-82AB-455E-806B-64099BA50A0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBEC5795-82AB-455E-806B-64099BA50A0A}.Release|Any CPU.Build.0 = Release|Any CPU
{D5018C9D-9A97-4655-BD12-6EFC92DB0217}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5018C9D-9A97-4655-BD12-6EFC92DB0217}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5018C9D-9A97-4655-BD12-6EFC92DB0217}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5018C9D-9A97-4655-BD12-6EFC92DB0217}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E8D4071D-94BA-43BD-A629-E87AEFBDA58A}
EndGlobalSection
EndGlobal
Loading