public void Test() { Environment.CurrentDirectory = Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "MagicISO", "Nero"); for (int i = 0; i < _testFiles.Length; i++) { var filter = new ZZZNoFilter(); filter.Open(_testFiles[i]); var image = new DiscImages.Nero(); bool opened = image.Open(filter); Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}"); using (new AssertionScope()) { Assert.Multiple(() => { Assert.AreEqual(_sectors[i], image.Info.Sectors, $"Sectors: {_testFiles[i]}"); Assert.AreEqual(_mediaTypes[i], image.Info.MediaType, $"Media type: {_testFiles[i]}"); Assert.AreEqual(_tracks[i], image.Tracks.Count, $"Tracks: {_testFiles[i]}"); image.Tracks.Select(t => t.TrackSession).Should(). BeEquivalentTo(_trackSessions[i], $"Track session: {_testFiles[i]}"); image.Tracks.Select(t => t.TrackStartSector).Should(). BeEquivalentTo(_trackStarts[i], $"Track start: {_testFiles[i]}"); image.Tracks.Select(t => t.TrackEndSector).Should(). BeEquivalentTo(_trackEnds[i], $"Track end: {_testFiles[i]}"); image.Tracks.Select(t => t.TrackPregap).Should(). BeEquivalentTo(_trackPregaps[i], $"Track pregap: {_testFiles[i]}"); int trackNo = 0; byte[] flags = new byte[image.Tracks.Count]; foreach (Track currentTrack in image.Tracks) { if (image.Info.ReadableSectorTags.Contains(SectorTagType.CdTrackFlags)) { flags[trackNo] = image.ReadSectorTag(currentTrack.TrackSequence, SectorTagType.CdTrackFlags)[0]; } trackNo++; } flags.Should().BeEquivalentTo(_trackFlags[i], $"Track flags: {_testFiles[i]}"); }); } } }
public void Hashes() { // How many sectors to read at once const uint sectorsToRead = 256; Environment.CurrentDirectory = Path.Combine(Consts.TEST_FILES_ROOT, "Media image formats", "MagicISO", "Nero"); Assert.Multiple(() => { for (int i = 0; i < _testFiles.Length; i++) { var filter = new ZZZNoFilter(); filter.Open(_testFiles[i]); var image = new DiscImages.Nero(); bool opened = image.Open(filter); Assert.AreEqual(true, opened, $"Open: {_testFiles[i]}"); Md5Context ctx; foreach (bool @long in new[] { false, true }) { ctx = new Md5Context(); foreach (Track currentTrack in image.Tracks) { ulong sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1; ulong doneSectors = 0; while (doneSectors < sectors) { byte[] sector; if (sectors - doneSectors >= sectorsToRead) { sector = @long ? image.ReadSectorsLong(doneSectors, sectorsToRead, currentTrack.TrackSequence) : image.ReadSectors(doneSectors, sectorsToRead, currentTrack.TrackSequence); doneSectors += sectorsToRead; } else { sector = @long ? image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors), currentTrack.TrackSequence) : image.ReadSectors(doneSectors, (uint)(sectors - doneSectors), currentTrack.TrackSequence); doneSectors += sectors - doneSectors; } ctx.Update(sector); } } Assert.AreEqual(@long ? _longMd5S[i] : _md5S[i], ctx.End(), $"{(@long ? "Long hash" : "Hash")}: {_testFiles[i]}"); } if (!image.Info.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel)) { continue; } ctx = new Md5Context(); foreach (Track currentTrack in image.Tracks) { ulong sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1; ulong doneSectors = 0; while (doneSectors < sectors) { byte[] sector; if (sectors - doneSectors >= sectorsToRead) { sector = image.ReadSectorsTag(doneSectors, sectorsToRead, currentTrack.TrackSequence, SectorTagType.CdSectorSubchannel); doneSectors += sectorsToRead; } else { sector = image.ReadSectorsTag(doneSectors, (uint)(sectors - doneSectors), currentTrack.TrackSequence, SectorTagType.CdSectorSubchannel); doneSectors += sectors - doneSectors; } ctx.Update(sector); } } Assert.AreEqual(_subchannelMd5S[i], ctx.End(), $"Subchannel hash: {_testFiles[i]}"); } }); }