From 8730ad1a8b8923005835548c4b2d0facf6f5868d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 26 Feb 2021 20:11:03 +0000 Subject: [PATCH] Add unit tests for DiskCopy 4.2 images created by pce. --- Aaru.Tests/Images/pce/DiskCopy42.cs | 180 ++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 Aaru.Tests/Images/pce/DiskCopy42.cs diff --git a/Aaru.Tests/Images/pce/DiskCopy42.cs b/Aaru.Tests/Images/pce/DiskCopy42.cs new file mode 100644 index 000000000..e30d8381c --- /dev/null +++ b/Aaru.Tests/Images/pce/DiskCopy42.cs @@ -0,0 +1,180 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : DiskCopy42.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.Filters; +using FluentAssertions.Execution; +using NUnit.Framework; + +namespace Aaru.Tests.Images.pce +{ + [TestFixture] + public class DiskCopy42 + { + readonly string[] _testFiles = + { + "mf1dd_gcr.dc42.lz", "mf2dd.dc42.lz", "mf2dd_gcr.dc42.lz" + }; + + readonly ulong[] _sectors = + { + // mf1dd_gcr.dc42.lz + 800, + + // mf2dd.dc42.lz + 1440, + + // mf2dd_gcr.dc42.lz + 1600 + }; + + readonly uint[] _sectorSize = + { + // mf1dd_gcr.dc42.lz + 512, + + // mf2dd.dc42.lz + 512, + + // mf2dd_gcr.dc42.lz + 512 + }; + + readonly MediaType[] _mediaTypes = + { + // mf1dd_gcr.dc42.lz + MediaType.AppleSonySS, + + // mf2dd.dc42.lz + MediaType.DOS_35_DS_DD_9, + + // mf2dd_gcr.dc42.lz + MediaType.AppleSonyDS + }; + + readonly string[] _md5S = + { + // mf1dd_gcr.dc42.lz + "c5d92544c3e78b7f0a9b4baaa9a64eec", + + // mf2dd.dc42.lz + "de3f85896f771b7e5bc4c9e3926d64e4", + + // mf2dd_gcr.dc42.lz + "93e71b9ecdb39d3ec9245b4f451856d4" + }; + + readonly string _dataFolder = + Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "pce", "DiskCopy 4.2"); + + [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 DiscImages.DiskCopy42(); + 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 DiscImages.DiskCopy42(); + 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