From dea2849ed65214d9f770f1bcfe37c03dd45577f3 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 23 Feb 2021 04:37:06 +0000 Subject: [PATCH] Add unit tests for raw images created by Disk-Utilities. --- Aaru.Tests/Images/DiskUtilities/Raw.cs | 226 +++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 Aaru.Tests/Images/DiskUtilities/Raw.cs diff --git a/Aaru.Tests/Images/DiskUtilities/Raw.cs b/Aaru.Tests/Images/DiskUtilities/Raw.cs new file mode 100644 index 000000000..43c24c71f --- /dev/null +++ b/Aaru.Tests/Images/DiskUtilities/Raw.cs @@ -0,0 +1,226 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : Raw.cs +// Author(s) : Natalia Portillo +// +// 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2021 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.IO; +using Aaru.Checksums; +using Aaru.CommonTypes; +using Aaru.DiscImages; +using Aaru.Filters; +using FluentAssertions.Execution; +using NUnit.Framework; + +namespace Aaru.Tests.Images.DiskUtilities +{ + [TestFixture] + public class Raw + { + readonly string[] _testFiles = + { + "mf2dd_acorn.img.lz", "mf2dd_amiga.adf.lz", "mf2dd_fdformat_820.img.lz", "mf2hd_2m.img.lz", + "mf2hd_2m_max.img.lz", "mf2hd_fdformat_172.img.lz", "mf2hd_xdf.img.lz" + }; + readonly ulong[] _sectors = + { + // mf2dd_acorn.img.lz + 1600, + + // mf2dd_amiga.adf.lz + 1760, + + // mf2dd_fdformat_820.img.lz + 1640, + + // mf2hd_2m.img.lz + 3605, + + // mf2hd_2m_max.img.lz + 3768, + + // mf2hd_fdformat_172.img.lz + 3444, + + // mf2hd_xdf.img.lz + 670 + }; + readonly uint[] _sectorSize = + { + // mf2dd_acorn.img.lz + 512, + + // mf2dd_amiga.adf.lz + 512, + + // mf2dd_fdformat_820.img.lz + 512, + + // mf2hd_2m.img.lz + 512, + + // mf2hd_2m_max.img.lz + 512, + + // mf2hd_fdformat_172.img.lz + 512, + + // mf2hd_xdf.img.lz + 8192 + }; + readonly MediaType[] _mediaTypes = + { + // mf2dd_acorn.img.lz + MediaType.AppleSonyDS, + + // mf2dd_amiga.adf.lz + MediaType.CBM_AMIGA_35_DD, + + // mf2dd_fdformat_820.img.lz + MediaType.FDFORMAT_35_DD, + + // mf2hd_2m.img.lz + MediaType.GENERIC_HDD, + + // mf2hd_2m_max.img.lz + MediaType.GENERIC_HDD, + + // mf2hd_fdformat_172.img.lz + MediaType.FDFORMAT_35_HD, + + // mf2hd_xdf.img.lz + MediaType.XDF_35 + }; + readonly string[] _md5S = + { + // mf2dd_acorn.img.lz + "2626f65b49ec085253c41fa2e2a9e788", + + // mf2dd_amiga.adf.lz + "7db6730656efb22695cdf0a49e2674c9", + + // mf2dd_fdformat_820.img.lz + "9d978dff1196b456b8372d78e6b17970", + + // mf2hd_2m.img.lz + "7ee82cecd23b30cc9aa6f0ec59877851", + + // mf2hd_2m_max.img.lz + "c96c0be31797a0e6c9f23aad8ae38555", + + // mf2hd_fdformat_172.img.lz + "9dea1e119a73a21a38d134f36b2e5564", + + // mf2hd_xdf.img.lz + "UNKNOWN" + }; + + readonly string _dataFolder = + Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "disk-analyse", "raw"); + + [Test] + public void Info() + { + Environment.CurrentDirectory = _dataFolder; + + Assert.Multiple(() => + { + for(int i = 0; i < _testFiles.Length; i++) + { + var filter = new LZip(); + filter.Open(_testFiles[i]); + + var image = new ZZZRawImage(); + bool opened = image.Open(filter); + + Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}"); + + if(!opened) + continue; + + using(new AssertionScope()) + { + Assert.Multiple(() => + { + Assert.AreEqual(_sectors[i], image.Info.Sectors, $"Sectors: {_testFiles[i]}"); + Assert.AreEqual(_sectorSize[i], image.Info.SectorSize, $"Sector size: {_testFiles[i]}"); + Assert.AreEqual(_mediaTypes[i], image.Info.MediaType, $"Media type: {_testFiles[i]}"); + }); + } + } + }); + } + + // How many sectors to read at once + const uint _sectorsToRead = 256; + + [Test] + public void Hashes() + { + Environment.CurrentDirectory = _dataFolder; + + Assert.Multiple(() => + { + for(int i = 0; i < _testFiles.Length; i++) + { + var filter = new LZip(); + filter.Open(_testFiles[i]); + + var image = new ZZZRawImage(); + bool opened = image.Open(filter); + ulong doneSectors = 0; + + Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}"); + + if(!opened) + continue; + + var ctx = new Md5Context(); + + while(doneSectors < image.Info.Sectors) + { + byte[] sector; + + if(image.Info.Sectors - doneSectors >= _sectorsToRead) + { + sector = image.ReadSectors(doneSectors, _sectorsToRead); + doneSectors += _sectorsToRead; + } + else + { + sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors)); + doneSectors += image.Info.Sectors - doneSectors; + } + + ctx.Update(sector); + } + + Assert.AreEqual(_md5S[i], ctx.End(), $"Hash: {_testFiles[i]}"); + } + }); + } + } +} \ No newline at end of file