mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Added tests for compression filters.
This commit is contained in:
@@ -46,18 +46,27 @@
|
|||||||
<Compile Include="Checksums\SpamSum.cs" />
|
<Compile Include="Checksums\SpamSum.cs" />
|
||||||
<Compile Include="Checksums\SHA512.cs" />
|
<Compile Include="Checksums\SHA512.cs" />
|
||||||
<Compile Include="Checksums\Adler32.cs" />
|
<Compile Include="Checksums\Adler32.cs" />
|
||||||
|
<Compile Include="Filters\GZip.cs" />
|
||||||
|
<Compile Include="Filters\XZ.cs" />
|
||||||
|
<Compile Include="Filters\LZip.cs" />
|
||||||
|
<Compile Include="Filters\BZip2.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Checksums\" />
|
<Folder Include="Checksums\" />
|
||||||
|
<Folder Include="Filters\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DiscImageChef.Checksums\DiscImageChef.Checksums.csproj">
|
<ProjectReference Include="..\DiscImageChef.Checksums\DiscImageChef.Checksums.csproj">
|
||||||
<Project>{CC48B324-A532-4A45-87A6-6F91F7141E8D}</Project>
|
<Project>{CC48B324-A532-4A45-87A6-6F91F7141E8D}</Project>
|
||||||
<Name>DiscImageChef.Checksums</Name>
|
<Name>DiscImageChef.Checksums</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\DiscImageChef.Filters\DiscImageChef.Filters.csproj">
|
||||||
|
<Project>{D571B8EF-903D-4353-BDD5-B834F9F029EF}</Project>
|
||||||
|
<Name>DiscImageChef.Filters</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
|
|||||||
104
DiscImageChef.Tests/Filters/BZip2.cs
Normal file
104
DiscImageChef.Tests/Filters/BZip2.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : GZip.cs
|
||||||
|
// Version : 1.0
|
||||||
|
// Author(s) : Natalia Portillo
|
||||||
|
//
|
||||||
|
// Component : Component
|
||||||
|
//
|
||||||
|
// Revision : $Revision$
|
||||||
|
// Last change by : $Author$
|
||||||
|
// Date : $Date$
|
||||||
|
//
|
||||||
|
// --[ Description ] ----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Description
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 2011-2015 Claunia.com
|
||||||
|
// ****************************************************************************/
|
||||||
|
// //$Id$
|
||||||
|
using System.IO;
|
||||||
|
using DiscImageChef.Checksums;
|
||||||
|
using DiscImageChef.Filters;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Tests.Filters
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class BZip2
|
||||||
|
{
|
||||||
|
static readonly byte[] ExpectedFile = { 0xf8, 0xb6, 0xbc, 0x62, 0x33, 0xcf, 0x1d, 0x28, 0x02, 0xef, 0x80, 0xf1, 0xe4, 0xfc, 0x1b, 0xdf };
|
||||||
|
static readonly byte[] ExpectedContents = { 0x18, 0x90, 0x5a, 0xf9, 0x83, 0xd8, 0x2b, 0xdd, 0x1a, 0xcc, 0x69, 0x75, 0x4f, 0x0f, 0x81, 0x5e };
|
||||||
|
readonly string location;
|
||||||
|
|
||||||
|
public BZip2()
|
||||||
|
{
|
||||||
|
location = Path.Combine(Consts.TestFilesRoot, "filters", "bzip2.bz2");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckCorrectFile()
|
||||||
|
{
|
||||||
|
MD5Context ctx = new MD5Context();
|
||||||
|
ctx.Init();
|
||||||
|
byte[] result = ctx.File(location);
|
||||||
|
Assert.AreEqual(ExpectedFile, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckFilterId()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.BZip2();
|
||||||
|
Assert.AreEqual(true, filter.Identify(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.BZip2();
|
||||||
|
filter.Open(location);
|
||||||
|
Assert.AreEqual(true, filter.IsOpened());
|
||||||
|
Assert.AreEqual(1048576, filter.GetDataForkLength());
|
||||||
|
Assert.AreNotEqual(null, filter.GetDataForkStream());
|
||||||
|
Assert.AreEqual(0, filter.GetResourceForkLength());
|
||||||
|
Assert.AreEqual(null, filter.GetResourceForkStream());
|
||||||
|
Assert.AreEqual(false, filter.HasResourceFork());
|
||||||
|
filter.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckContents()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.BZip2();
|
||||||
|
filter.Open(location);
|
||||||
|
Stream str = filter.GetDataForkStream();
|
||||||
|
byte[] data = new byte[1048576];
|
||||||
|
str.Read(data, 0, 1048576);
|
||||||
|
str.Close();
|
||||||
|
str.Dispose();
|
||||||
|
filter.Close();
|
||||||
|
MD5Context ctx = new MD5Context();
|
||||||
|
ctx.Init();
|
||||||
|
ctx.Data(data, out byte[] result);
|
||||||
|
Assert.AreEqual(ExpectedContents, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
104
DiscImageChef.Tests/Filters/GZip.cs
Normal file
104
DiscImageChef.Tests/Filters/GZip.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : GZip.cs
|
||||||
|
// Version : 1.0
|
||||||
|
// Author(s) : Natalia Portillo
|
||||||
|
//
|
||||||
|
// Component : Component
|
||||||
|
//
|
||||||
|
// Revision : $Revision$
|
||||||
|
// Last change by : $Author$
|
||||||
|
// Date : $Date$
|
||||||
|
//
|
||||||
|
// --[ Description ] ----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Description
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 2011-2015 Claunia.com
|
||||||
|
// ****************************************************************************/
|
||||||
|
// //$Id$
|
||||||
|
using System.IO;
|
||||||
|
using DiscImageChef.Checksums;
|
||||||
|
using DiscImageChef.Filters;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Tests.Filters
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class GZip
|
||||||
|
{
|
||||||
|
static readonly byte[] ExpectedFile = { 0x35, 0xe2, 0x9c, 0x9d, 0x05, 0x1b, 0x6d, 0xa6, 0x6c, 0x24, 0xeb, 0x30, 0xe8, 0xd2, 0xa6, 0x6b };
|
||||||
|
static readonly byte[] ExpectedContents = { 0x18, 0x90, 0x5a, 0xf9, 0x83, 0xd8, 0x2b, 0xdd, 0x1a, 0xcc, 0x69, 0x75, 0x4f, 0x0f, 0x81, 0x5e };
|
||||||
|
readonly string location;
|
||||||
|
|
||||||
|
public GZip()
|
||||||
|
{
|
||||||
|
location = Path.Combine(Consts.TestFilesRoot, "filters", "gzip.gz");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckCorrectFile()
|
||||||
|
{
|
||||||
|
MD5Context ctx = new MD5Context();
|
||||||
|
ctx.Init();
|
||||||
|
byte[] result = ctx.File(location);
|
||||||
|
Assert.AreEqual(ExpectedFile, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckFilterId()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.GZip();
|
||||||
|
Assert.AreEqual(true, filter.Identify(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.GZip();
|
||||||
|
filter.Open(location);
|
||||||
|
Assert.AreEqual(true, filter.IsOpened());
|
||||||
|
Assert.AreEqual(1048576, filter.GetDataForkLength());
|
||||||
|
Assert.AreNotEqual(null, filter.GetDataForkStream());
|
||||||
|
Assert.AreEqual(0, filter.GetResourceForkLength());
|
||||||
|
Assert.AreEqual(null, filter.GetResourceForkStream());
|
||||||
|
Assert.AreEqual(false, filter.HasResourceFork());
|
||||||
|
filter.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckContents()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.GZip();
|
||||||
|
filter.Open(location);
|
||||||
|
Stream str = filter.GetDataForkStream();
|
||||||
|
byte[] data = new byte[1048576];
|
||||||
|
str.Read(data, 0, 1048576);
|
||||||
|
str.Close();
|
||||||
|
str.Dispose();
|
||||||
|
filter.Close();
|
||||||
|
MD5Context ctx = new MD5Context();
|
||||||
|
ctx.Init();
|
||||||
|
ctx.Data(data, out byte[] result);
|
||||||
|
Assert.AreEqual(ExpectedContents, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
104
DiscImageChef.Tests/Filters/LZip.cs
Normal file
104
DiscImageChef.Tests/Filters/LZip.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : GZip.cs
|
||||||
|
// Version : 1.0
|
||||||
|
// Author(s) : Natalia Portillo
|
||||||
|
//
|
||||||
|
// Component : Component
|
||||||
|
//
|
||||||
|
// Revision : $Revision$
|
||||||
|
// Last change by : $Author$
|
||||||
|
// Date : $Date$
|
||||||
|
//
|
||||||
|
// --[ Description ] ----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Description
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 2011-2015 Claunia.com
|
||||||
|
// ****************************************************************************/
|
||||||
|
// //$Id$
|
||||||
|
using System.IO;
|
||||||
|
using DiscImageChef.Checksums;
|
||||||
|
using DiscImageChef.Filters;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Tests.Filters
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class LZip
|
||||||
|
{
|
||||||
|
static readonly byte[] ExpectedFile = { 0x3f, 0x7b, 0x77, 0x3e, 0x52, 0x48, 0xd5, 0x26, 0xf4, 0xb1, 0xac, 0x15, 0xb2, 0xb3, 0x5f, 0x87 };
|
||||||
|
static readonly byte[] ExpectedContents = { 0x18, 0x90, 0x5a, 0xf9, 0x83, 0xd8, 0x2b, 0xdd, 0x1a, 0xcc, 0x69, 0x75, 0x4f, 0x0f, 0x81, 0x5e };
|
||||||
|
readonly string location;
|
||||||
|
|
||||||
|
public LZip()
|
||||||
|
{
|
||||||
|
location = Path.Combine(Consts.TestFilesRoot, "filters", "lzip.lz");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckCorrectFile()
|
||||||
|
{
|
||||||
|
MD5Context ctx = new MD5Context();
|
||||||
|
ctx.Init();
|
||||||
|
byte[] result = ctx.File(location);
|
||||||
|
Assert.AreEqual(ExpectedFile, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckFilterId()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.LZip();
|
||||||
|
Assert.AreEqual(true, filter.Identify(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.LZip();
|
||||||
|
filter.Open(location);
|
||||||
|
Assert.AreEqual(true, filter.IsOpened());
|
||||||
|
Assert.AreEqual(1048576, filter.GetDataForkLength());
|
||||||
|
Assert.AreNotEqual(null, filter.GetDataForkStream());
|
||||||
|
Assert.AreEqual(0, filter.GetResourceForkLength());
|
||||||
|
Assert.AreEqual(null, filter.GetResourceForkStream());
|
||||||
|
Assert.AreEqual(false, filter.HasResourceFork());
|
||||||
|
filter.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckContents()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.LZip();
|
||||||
|
filter.Open(location);
|
||||||
|
Stream str = filter.GetDataForkStream();
|
||||||
|
byte[] data = new byte[1048576];
|
||||||
|
str.Read(data, 0, 1048576);
|
||||||
|
str.Close();
|
||||||
|
str.Dispose();
|
||||||
|
filter.Close();
|
||||||
|
MD5Context ctx = new MD5Context();
|
||||||
|
ctx.Init();
|
||||||
|
ctx.Data(data, out byte[] result);
|
||||||
|
Assert.AreEqual(ExpectedContents, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
104
DiscImageChef.Tests/Filters/XZ.cs
Normal file
104
DiscImageChef.Tests/Filters/XZ.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : GZip.cs
|
||||||
|
// Version : 1.0
|
||||||
|
// Author(s) : Natalia Portillo
|
||||||
|
//
|
||||||
|
// Component : Component
|
||||||
|
//
|
||||||
|
// Revision : $Revision$
|
||||||
|
// Last change by : $Author$
|
||||||
|
// Date : $Date$
|
||||||
|
//
|
||||||
|
// --[ Description ] ----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Description
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 2011-2015 Claunia.com
|
||||||
|
// ****************************************************************************/
|
||||||
|
// //$Id$
|
||||||
|
using System.IO;
|
||||||
|
using DiscImageChef.Checksums;
|
||||||
|
using DiscImageChef.Filters;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Tests.Filters
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class XZ
|
||||||
|
{
|
||||||
|
static readonly byte[] ExpectedFile = { 0x6c, 0x88, 0xa5, 0x9a, 0x1b, 0x7a, 0xec, 0x59, 0x2b, 0xef, 0x8a, 0x28, 0xdb, 0x11, 0x01, 0xc8 };
|
||||||
|
static readonly byte[] ExpectedContents = { 0x18, 0x90, 0x5a, 0xf9, 0x83, 0xd8, 0x2b, 0xdd, 0x1a, 0xcc, 0x69, 0x75, 0x4f, 0x0f, 0x81, 0x5e };
|
||||||
|
readonly string location;
|
||||||
|
|
||||||
|
public XZ()
|
||||||
|
{
|
||||||
|
location = Path.Combine(Consts.TestFilesRoot, "filters", "xz.xz");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckCorrectFile()
|
||||||
|
{
|
||||||
|
MD5Context ctx = new MD5Context();
|
||||||
|
ctx.Init();
|
||||||
|
byte[] result = ctx.File(location);
|
||||||
|
Assert.AreEqual(ExpectedFile, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckFilterId()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.XZ();
|
||||||
|
Assert.AreEqual(true, filter.Identify(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.XZ();
|
||||||
|
filter.Open(location);
|
||||||
|
Assert.AreEqual(true, filter.IsOpened());
|
||||||
|
Assert.AreEqual(1048576, filter.GetDataForkLength());
|
||||||
|
Assert.AreNotEqual(null, filter.GetDataForkStream());
|
||||||
|
Assert.AreEqual(0, filter.GetResourceForkLength());
|
||||||
|
Assert.AreEqual(null, filter.GetResourceForkStream());
|
||||||
|
Assert.AreEqual(false, filter.HasResourceFork());
|
||||||
|
filter.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckContents()
|
||||||
|
{
|
||||||
|
Filter filter = new DiscImageChef.Filters.XZ();
|
||||||
|
filter.Open(location);
|
||||||
|
Stream str = filter.GetDataForkStream();
|
||||||
|
byte[] data = new byte[1048576];
|
||||||
|
str.Read(data, 0, 1048576);
|
||||||
|
str.Close();
|
||||||
|
str.Dispose();
|
||||||
|
filter.Close();
|
||||||
|
MD5Context ctx = new MD5Context();
|
||||||
|
ctx.Init();
|
||||||
|
ctx.Data(data, out byte[] result);
|
||||||
|
Assert.AreEqual(ExpectedContents, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user