// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename       : AppleDoubleUnix.cs
// Author(s)      : Natalia Portillo <claunia@claunia.com>
//
// Component      : Aaru unit testing.
//
// --[ 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 © 2011-2026 Natalia Portillo
// ****************************************************************************/

using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Filters;
using Aaru.Helpers;
using FluentAssertions;
using NUnit.Framework;

namespace Aaru.Tests.Filters;

[TestFixture]
public class AppleDoubleUnix
{
    const    string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4";
    const    string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250";
    const    string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
    const    string EXPECTED_RESOURCE = "c689c58945169065483d94e39583d416";
    readonly string _location = Path.Combine(Consts.TestFilesRoot, "Filters", "AppleDouble", "unix", "DOS_720.dmg");
    readonly string _sidecar = Path.Combine(Consts.TestFilesRoot, "Filters", "AppleDouble", "unix", "%DOS_720.dmg");

    [Test]
    public void CheckContents()
    {
        IFilter filter = new AppleDouble();
        filter.Open(_location);
        Stream str  = filter.GetDataForkStream();
        var    data = new byte[737280];
        str.EnsureRead(data, 0, 737280);
        str.Close();
        str.Dispose();
        filter.Close();
        string result = Md5Context.Data(data, out _);
        result.Should().Be(EXPECTED_CONTENTS);
    }

    [Test]
    public void CheckCorrectFile()
    {
        string result = Md5Context.File(_location, out _);
        result.Should().Be(EXPECTED_FILE);

        result = Md5Context.File(_sidecar, out _);
        result.Should().Be(EXPECTED_SIDECAR);
    }

    [Test]
    public void CheckFilterId()
    {
        IFilter filter = new AppleDouble();
        filter.Identify(_location).Should().BeTrue();
    }

    [Test]
    public void CheckResource()
    {
        IFilter filter = new AppleDouble();
        filter.Open(_location);
        Stream str  = filter.GetResourceForkStream();
        var    data = new byte[286];
        str.EnsureRead(data, 0, 286);
        str.Close();
        str.Dispose();
        filter.Close();
        string result = Md5Context.Data(data, out _);
        result.Should().Be(EXPECTED_RESOURCE);
    }

    [Test]
    public void Test()
    {
        IFilter filter = new AppleDouble();
        filter.Open(_location).Should().Be(ErrorNumber.NoError);
        filter.DataForkLength.Should().Be(737280);
        filter.GetDataForkStream().Should().NotBeNull();
        filter.ResourceForkLength.Should().Be(286);
        filter.GetResourceForkStream().Should().NotBeNull();
        filter.HasResourceFork.Should().BeTrue();
        filter.Close();
    }
}