2017-06-29 22:52:46 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Filename : XZ.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-06-29 22:52:46 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : DiscImageChef unit testing.
|
2017-06-29 22:52:46 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-06-29 22:52:46 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-06-29 22:52:46 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using DiscImageChef.Checksums;
|
|
|
|
|
|
using DiscImageChef.Filters;
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Tests.Filters
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestFixture]
|
2017-12-22 22:18:21 +00:00
|
|
|
|
public class Xz
|
2017-06-29 22:52:46 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
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};
|
2017-06-29 22:52:46 +01:00
|
|
|
|
readonly string location;
|
|
|
|
|
|
|
2017-12-22 22:18:21 +00:00
|
|
|
|
public Xz()
|
2017-06-29 22:52:46 +01:00
|
|
|
|
{
|
|
|
|
|
|
location = Path.Combine(Consts.TestFilesRoot, "filters", "xz.xz");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void CheckCorrectFile()
|
|
|
|
|
|
{
|
2018-02-03 19:11:41 +00:00
|
|
|
|
byte[] result = Md5Context.File(location);
|
2017-06-29 22:52:46 +01:00
|
|
|
|
Assert.AreEqual(ExpectedFile, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void CheckFilterId()
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
IFilter filter = new XZ();
|
2017-06-29 22:52:46 +01:00
|
|
|
|
Assert.AreEqual(true, filter.Identify(location));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Test()
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
IFilter filter = new XZ();
|
2017-06-29 22:52:46 +01:00
|
|
|
|
filter.Open(location);
|
2018-02-03 17:39:49 +00:00
|
|
|
|
Assert.AreEqual(true, filter.IsOpened());
|
2017-06-29 22:52:46 +01:00
|
|
|
|
Assert.AreEqual(1048576, filter.GetDataForkLength());
|
|
|
|
|
|
Assert.AreNotEqual(null, filter.GetDataForkStream());
|
2018-02-03 17:39:49 +00:00
|
|
|
|
Assert.AreEqual(0, filter.GetResourceForkLength());
|
|
|
|
|
|
Assert.AreEqual(null, filter.GetResourceForkStream());
|
2017-06-29 22:52:46 +01:00
|
|
|
|
Assert.AreEqual(false, filter.HasResourceFork());
|
|
|
|
|
|
filter.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void CheckContents()
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
IFilter filter = new XZ();
|
2017-06-29 22:52:46 +01:00
|
|
|
|
filter.Open(location);
|
2018-02-03 17:39:49 +00:00
|
|
|
|
Stream str = filter.GetDataForkStream();
|
2017-06-29 22:52:46 +01:00
|
|
|
|
byte[] data = new byte[1048576];
|
|
|
|
|
|
str.Read(data, 0, 1048576);
|
|
|
|
|
|
str.Close();
|
|
|
|
|
|
str.Dispose();
|
|
|
|
|
|
filter.Close();
|
2018-02-03 19:11:41 +00:00
|
|
|
|
Md5Context.Data(data, out byte[] result);
|
2017-06-29 22:52:46 +01:00
|
|
|
|
Assert.AreEqual(ExpectedContents, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|