Add unit test for issue 176.

This commit is contained in:
2021-03-07 17:23:23 +00:00
parent 0a526abf24
commit 0936d4fbad
3 changed files with 163 additions and 0 deletions

23
Aaru.Tests/Issues/176.cs Normal file
View File

@@ -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";
}
}

View File

@@ -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
{
/// <summary>This class will test an issue that happens when reading an image completely, from start to end, crashes.</summary>
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);
}
}
}
}

View File

@@ -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
{
/// <summary>This class will test an issue that happens when reading an image completely, from start to end, crashes.</summary>
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<Track> 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;
}
}
}
}