mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add unit test for issue 176.
This commit is contained in:
23
Aaru.Tests/Issues/176.cs
Normal file
23
Aaru.Tests/Issues/176.cs
Normal 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
59
Aaru.Tests/Issues/ImageReadIssueTest.cs
Normal file
59
Aaru.Tests/Issues/ImageReadIssueTest.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
81
Aaru.Tests/Issues/OpticalImageReadIssueTest.cs
Normal file
81
Aaru.Tests/Issues/OpticalImageReadIssueTest.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user