2017-06-29 22:52:46 +01:00
|
|
|
|
// /***************************************************************************
|
2020-07-25 02:01:36 +01:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-06-29 22:52:46 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Filename : LZip.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-06-29 22:52:46 +01:00
|
|
|
|
//
|
2020-07-25 02:01:36 +01:00
|
|
|
|
// Component : Aaru 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-05-01 04:17:32 +01:00
|
|
|
|
// Copyright © 2011-2024 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;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.Checksums;
|
2021-09-16 04:42:14 +01:00
|
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2022-11-14 09:43:16 +00:00
|
|
|
|
using Aaru.Helpers;
|
2017-06-29 22:52:46 +01:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Tests.Filters;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[TestFixture]
|
|
|
|
|
|
public class LZip
|
2017-06-29 22:52:46 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
static readonly byte[] _expectedFile =
|
2024-05-01 04:39:38 +01:00
|
|
|
|
[
|
2022-03-06 13:29:38 +00:00
|
|
|
|
0x3f, 0x7b, 0x77, 0x3e, 0x52, 0x48, 0xd5, 0x26, 0xf4, 0xb1, 0xac, 0x15, 0xb2, 0xb3, 0x5f, 0x87
|
2024-05-01 04:39:38 +01:00
|
|
|
|
];
|
2022-03-06 13:29:38 +00:00
|
|
|
|
static readonly byte[] _expectedContents =
|
2024-05-01 04:39:38 +01:00
|
|
|
|
[
|
2022-03-06 13:29:38 +00:00
|
|
|
|
0x18, 0x90, 0x5a, 0xf9, 0x83, 0xd8, 0x2b, 0xdd, 0x1a, 0xcc, 0x69, 0x75, 0x4f, 0x0f, 0x81, 0x5e
|
2024-05-01 04:39:38 +01:00
|
|
|
|
];
|
2022-03-06 13:29:38 +00:00
|
|
|
|
readonly string _location;
|
2017-06-29 22:52:46 +01:00
|
|
|
|
|
2022-11-13 05:48:58 +00:00
|
|
|
|
public LZip() => _location = Path.Combine(Consts.TestFilesRoot, "Filters", "lzip.lz");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void CheckContents()
|
|
|
|
|
|
{
|
|
|
|
|
|
IFilter filter = new Aaru.Filters.LZip();
|
|
|
|
|
|
filter.Open(_location);
|
|
|
|
|
|
Stream str = filter.GetDataForkStream();
|
2023-10-03 23:44:33 +01:00
|
|
|
|
var data = new byte[1048576];
|
2022-11-14 09:43:16 +00:00
|
|
|
|
str.EnsureRead(data, 0, 1048576);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
str.Close();
|
|
|
|
|
|
str.Dispose();
|
|
|
|
|
|
filter.Close();
|
|
|
|
|
|
Md5Context.Data(data, out byte[] result);
|
2024-05-02 03:40:35 +01:00
|
|
|
|
Assert.That(result, Is.EqualTo(_expectedContents));
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2017-06-29 22:52:46 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void CheckCorrectFile()
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] result = Md5Context.File(_location);
|
2024-05-02 03:40:35 +01:00
|
|
|
|
Assert.That(result, Is.EqualTo(_expectedFile));
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2017-06-29 22:52:46 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void CheckFilterId()
|
|
|
|
|
|
{
|
|
|
|
|
|
IFilter filter = new Aaru.Filters.LZip();
|
2024-05-02 03:40:35 +01:00
|
|
|
|
Assert.That(filter.Identify(_location), Is.True);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2017-06-29 22:52:46 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Test()
|
|
|
|
|
|
{
|
|
|
|
|
|
IFilter filter = new Aaru.Filters.LZip();
|
2024-05-02 03:40:35 +01:00
|
|
|
|
Assert.That(filter.Open(_location), Is.EqualTo(ErrorNumber.NoError));
|
|
|
|
|
|
Assert.That(filter.DataForkLength, Is.EqualTo(1048576));
|
|
|
|
|
|
Assert.That(filter.GetDataForkStream(), Is.Not.Null);
|
|
|
|
|
|
Assert.That(filter.ResourceForkLength, Is.EqualTo(0));
|
|
|
|
|
|
Assert.That(filter.GetResourceForkStream(), Is.EqualTo(null));
|
|
|
|
|
|
Assert.That(filter.HasResourceFork, Is.EqualTo(false));
|
2022-03-06 13:29:38 +00:00
|
|
|
|
filter.Close();
|
2017-06-29 22:52:46 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|