From 0936d4fbad5c18e33db5c4e6b81202e0d78e8fbb Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 7 Mar 2021 17:23:23 +0000 Subject: [PATCH] Add unit test for issue 176. --- Aaru.Tests/Issues/176.cs | 23 ++++++ Aaru.Tests/Issues/ImageReadIssueTest.cs | 59 ++++++++++++++ .../Issues/OpticalImageReadIssueTest.cs | 81 +++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 Aaru.Tests/Issues/176.cs create mode 100644 Aaru.Tests/Issues/ImageReadIssueTest.cs create mode 100644 Aaru.Tests/Issues/OpticalImageReadIssueTest.cs diff --git a/Aaru.Tests/Issues/176.cs b/Aaru.Tests/Issues/176.cs new file mode 100644 index 000000000..ecb910bc1 --- /dev/null +++ b/Aaru.Tests/Issues/176.cs @@ -0,0 +1,23 @@ +using System.IO; +using NUnit.Framework; + +namespace Aaru.Tests.Issues +{ + /* + * SilasLaspada commented on May 13, 2018 + * Trying to convert an MDF/MDS file pair that is CD-ROM XA that has 2 tracks results in the program crashing + * with the command window having been spammed with "Converting sectors x to x in track 2 (xx.xx% done)Error + * Can't found track containing x writing sector x, continuing..." before the crash. A very similar crash occurs + * when dumping the disc to MDF/MDS. The image is dumped correctly when using the BIN/CUE format. I have had the + * same issue with similar CD-ROM XA discs, but seemingly only if they had multiple tracks. I attached all the logs + * and I'll try to get a link to the image file up ASAP, let me know if you need anything else! + */ + + // CLAUNIA: Fixed in bdaece414e5f1329610dcbc4a490ebe7ab1ad43e + [TestFixture] + public class _176 : OpticalImageReadIssueTest + { + public override string DataFolder => Path.Combine(Consts.TEST_FILES_ROOT, "Issues", "Fixed", "issue176"); + public override string TestFile => "WEBBEARS.mds"; + } +} \ No newline at end of file diff --git a/Aaru.Tests/Issues/ImageReadIssueTest.cs b/Aaru.Tests/Issues/ImageReadIssueTest.cs new file mode 100644 index 000000000..881962685 --- /dev/null +++ b/Aaru.Tests/Issues/ImageReadIssueTest.cs @@ -0,0 +1,59 @@ +using System; +using System.IO; +using Aaru.Checksums; +using Aaru.CommonTypes; +using Aaru.CommonTypes.Interfaces; +using Aaru.Core; +using NUnit.Framework; + +namespace Aaru.Tests.Issues +{ + /// This class will test an issue that happens when reading an image completely, from start to end, crashes. + public abstract class ImageReadIssueTest + { + const uint SECTORS_TO_READ = 256; + public abstract string DataFolder { get; } + public abstract string TestFile { get; } + + [Test] + public void Test() + { + Environment.CurrentDirectory = DataFolder; + + bool exists = File.Exists(TestFile); + Assert.True(exists, "Test file not found"); + + var filtersList = new FiltersList(); + IFilter inputFilter = filtersList.GetFilter(TestFile); + + Assert.IsNotNull(inputFilter, "Filter for test file is not detected"); + + IMediaImage image = ImageFormat.Detect(inputFilter); + + Assert.IsNotNull(image, "Image format for test file is not detected"); + + Assert.AreEqual(true, image.Open(inputFilter), "Cannot open image for test file"); + + ulong doneSectors = 0; + var ctx = new Crc32Context(); + + while(doneSectors < image.Info.Sectors) + { + byte[] sector; + + if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ) + { + sector = image.ReadSectors(doneSectors, SECTORS_TO_READ); + doneSectors += SECTORS_TO_READ; + } + else + { + sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors)); + doneSectors += image.Info.Sectors - doneSectors; + } + + ctx.Update(sector); + } + } + } +} \ No newline at end of file diff --git a/Aaru.Tests/Issues/OpticalImageReadIssueTest.cs b/Aaru.Tests/Issues/OpticalImageReadIssueTest.cs new file mode 100644 index 000000000..5dfb6f532 --- /dev/null +++ b/Aaru.Tests/Issues/OpticalImageReadIssueTest.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Aaru.Checksums; +using Aaru.CommonTypes; +using Aaru.CommonTypes.Interfaces; +using Aaru.CommonTypes.Structs; +using Aaru.Core; +using NUnit.Framework; + +namespace Aaru.Tests.Issues +{ + /// This class will test an issue that happens when reading an image completely, from start to end, crashes. + public abstract class OpticalImageReadIssueTest + { + const uint SECTORS_TO_READ = 256; + public abstract string DataFolder { get; } + public abstract string TestFile { get; } + + [Test] + public void Test() + { + Environment.CurrentDirectory = DataFolder; + + bool exists = File.Exists(TestFile); + Assert.True(exists, "Test file not found"); + + var filtersList = new FiltersList(); + IFilter inputFilter = filtersList.GetFilter(TestFile); + + Assert.IsNotNull(inputFilter, "Filter for test file is not detected"); + + IMediaImage image = ImageFormat.Detect(inputFilter); + + Assert.IsNotNull(image, "Image format for test file is not detected"); + + Assert.AreEqual(true, image.Open(inputFilter), "Cannot open image for test file"); + + var opticalInput = image as IOpticalMediaImage; + + Assert.IsNotNull(opticalInput, "Image format for test file is not for an optical disc"); + + var ctx = new Crc32Context(); + + Checksum trackChecksum = null; + + ulong previousTrackEnd = 0; + + List inputTracks = opticalInput.Tracks; + + foreach(Track currentTrack in inputTracks) + { + ulong sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1; + ulong doneSectors = 0; + + while(doneSectors < sectors) + { + byte[] sector; + + if(sectors - doneSectors >= SECTORS_TO_READ) + { + sector = opticalInput.ReadSectors(doneSectors, SECTORS_TO_READ, currentTrack.TrackSequence); + + doneSectors += SECTORS_TO_READ; + } + else + { + sector = opticalInput.ReadSectors(doneSectors, (uint)(sectors - doneSectors), + currentTrack.TrackSequence); + + doneSectors += sectors - doneSectors; + } + + ctx.Update(sector); + } + + previousTrackEnd = currentTrack.TrackEndSector; + } + } + } +} \ No newline at end of file