Files
Aaru/Aaru.Tests/Filters/GZip.cs

95 lines
3.4 KiB
C#
Raw Normal View History

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
// ----------------------------------------------------------------------------
//
// Filename : GZip.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/>.
//
// ----------------------------------------------------------------------------
2022-02-18 10:02:53 +00:00
// Copyright © 2011-2022 Natalia Portillo
2017-06-29 22:52:46 +01: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;
2021-09-15 13:03:42 +01:00
using Aaru.CommonTypes.Structs;
2017-06-29 22:52:46 +01:00
using NUnit.Framework;
2020-02-27 00:33:26 +00:00
namespace Aaru.Tests.Filters
2017-06-29 22:52:46 +01:00
{
[TestFixture]
public class GZip
{
2020-07-20 21:11:32 +01:00
static readonly byte[] _expectedFile =
2018-12-31 13:17:27 +00:00
{
0x35, 0xe2, 0x9c, 0x9d, 0x05, 0x1b, 0x6d, 0xa6, 0x6c, 0x24, 0xeb, 0x30, 0xe8, 0xd2, 0xa6, 0x6b
};
2020-07-20 21:11:32 +01:00
static readonly byte[] _expectedContents =
2018-12-31 13:17:27 +00:00
{
0x18, 0x90, 0x5a, 0xf9, 0x83, 0xd8, 0x2b, 0xdd, 0x1a, 0xcc, 0x69, 0x75, 0x4f, 0x0f, 0x81, 0x5e
};
2020-07-20 21:11:32 +01:00
readonly string _location;
2017-06-29 22:52:46 +01:00
2020-07-20 21:11:32 +01:00
public GZip() => _location = Path.Combine(Consts.TEST_FILES_ROOT, "Filters", "gzip.gz");
2020-02-29 18:03:35 +00:00
[Test]
public void CheckContents()
2017-06-29 22:52:46 +01:00
{
2020-02-29 18:03:35 +00:00
IFilter filter = new Aaru.Filters.GZip();
2020-07-20 21:11:32 +01:00
filter.Open(_location);
2020-02-29 18:03:35 +00:00
Stream str = filter.GetDataForkStream();
byte[] data = new byte[1048576];
str.Read(data, 0, 1048576);
str.Close();
str.Dispose();
filter.Close();
Md5Context.Data(data, out byte[] result);
2020-07-20 21:11:32 +01:00
Assert.AreEqual(_expectedContents, result);
2017-06-29 22:52:46 +01:00
}
[Test]
public void CheckCorrectFile()
{
2020-07-20 21:11:32 +01:00
byte[] result = Md5Context.File(_location);
Assert.AreEqual(_expectedFile, result);
2017-06-29 22:52:46 +01:00
}
[Test]
public void CheckFilterId()
{
2020-02-27 00:33:26 +00:00
IFilter filter = new Aaru.Filters.GZip();
2020-07-20 21:11:32 +01:00
Assert.AreEqual(true, filter.Identify(_location));
2017-06-29 22:52:46 +01:00
}
[Test]
public void Test()
{
2020-02-27 00:33:26 +00:00
IFilter filter = new Aaru.Filters.GZip();
2021-09-16 04:42:14 +01:00
Assert.AreEqual(ErrorNumber.NoError, filter.Open(_location));
Assert.AreEqual(1048576, filter.DataForkLength);
2017-06-29 22:52:46 +01:00
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.ResourceForkLength);
2020-02-29 18:03:35 +00:00
Assert.AreEqual(null, filter.GetResourceForkStream());
Assert.AreEqual(false, filter.HasResourceFork);
2017-06-29 22:52:46 +01:00
filter.Close();
}
}
2017-12-19 20:33:03 +00:00
}