mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
AR v2 & misc
This commit is contained in:
@@ -19,8 +19,6 @@ namespace CUETools.TestCodecs
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
private CDImageLayout toc;
|
||||
private CDImageLayout toc2;
|
||||
private AccurateRipVerify ar;
|
||||
private AccurateRipVerify ar2;
|
||||
|
||||
@@ -39,6 +37,26 @@ namespace CUETools.TestCodecs
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static AccurateRipVerify VerifyNoise(string trackoffsets, int seed, int offset)
|
||||
{
|
||||
return VerifyNoise(new CDImageLayout(trackoffsets), seed, offset);
|
||||
}
|
||||
|
||||
private static AccurateRipVerify VerifyNoise(CDImageLayout toc, int seed, int offset)
|
||||
{
|
||||
var src = new NoiseGenerator(AudioPCMConfig.RedBook, toc.AudioLength * 588, seed, offset);
|
||||
var buff = new AudioBuffer(src, 588 * 10);
|
||||
var ar = new AccurateRipVerify(toc, null);
|
||||
var rnd = new Random(seed);
|
||||
while (src.Remaining > 0)
|
||||
{
|
||||
src.Read(buff, rnd.Next(1, buff.Size));
|
||||
ar.Write(buff);
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
@@ -62,32 +80,8 @@ namespace CUETools.TestCodecs
|
||||
[TestInitialize()]
|
||||
public void MyTestInitialize()
|
||||
{
|
||||
toc = new CDImageLayout();
|
||||
toc.AddTrack(new CDTrack(1, 13, 55, true, false));
|
||||
toc.AddTrack(new CDTrack(2, 68, 31, true, false));
|
||||
toc.AddTrack(new CDTrack(3, 99, 37, true, false));
|
||||
toc[1][0].Start = 0;
|
||||
ar = new AccurateRipVerify(toc, null);
|
||||
|
||||
toc2 = new CDImageLayout();
|
||||
toc2.AddTrack(new CDTrack(1, 0, toc.AudioLength, true, false));
|
||||
toc2.AddTrack(new CDTrack(2, toc.AudioLength, 750, true, false));
|
||||
ar2 = new AccurateRipVerify(toc2, null);
|
||||
|
||||
Random rnd = new Random(2314);
|
||||
for (int sector = 0; sector < toc2.AudioLength; sector++)
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 588);
|
||||
buff.Length = 588;
|
||||
for (int i = 0; i < buff.Length; i++)
|
||||
{
|
||||
buff.Samples[i, 0] = rnd.Next(-32768, 32767);
|
||||
buff.Samples[i, 1] = rnd.Next(-32768, 32767);
|
||||
}
|
||||
if (sector < toc.AudioLength)
|
||||
ar.Write(buff);
|
||||
ar2.Write(buff);
|
||||
}
|
||||
ar = VerifyNoise("13 68 99 136", 2314, 0);
|
||||
ar2 = VerifyNoise("0 136 886", 2314, 0);
|
||||
}
|
||||
|
||||
//Use TestCleanup to run code after each test has run
|
||||
@@ -106,12 +100,12 @@ namespace CUETools.TestCodecs
|
||||
[TestMethod()]
|
||||
public void CRC32Test()
|
||||
{
|
||||
Assert.AreEqual<uint>(2884775698, ar.CRC32(0), "CRC32[0] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0474131972, ar.CRC32(1), "CRC32[1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1685633822, ar.CRC32(2), "CRC32[2] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2747309238, ar.CRC32(3), "CRC32[3] was not set correctly.");
|
||||
Assert.AreEqual<uint>(3791227907, ar.CRC32(0), "CRC32[0] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0321342250, ar.CRC32(1), "CRC32[1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0037001035, ar.CRC32(2), "CRC32[2] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0516255430, ar.CRC32(3), "CRC32[3] was not set correctly.");
|
||||
|
||||
Assert.AreEqual<uint>(2884775698, ar2.CRC32(1), "CRC32[1](2) was not set correctly.");
|
||||
Assert.AreEqual<uint>(3791227907, ar2.CRC32(1), "CRC32[1](2) was not set correctly.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,16 +114,16 @@ namespace CUETools.TestCodecs
|
||||
[TestMethod()]
|
||||
public void CRC32Test1()
|
||||
{
|
||||
Assert.AreEqual<uint>(2802501111, ar.CRC32(0, 13), "CRC32[0][13] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1987827634, ar.CRC32(0, -7), "CRC32[0][-7] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1624004597, ar.CRC32(1, 13), "CRC32[1][13] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2300462193, ar.CRC32(1, -7), "CRC32[1][-7] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0685357040, ar.CRC32(2, 15), "CRC32[2][15] was not set correctly.");
|
||||
Assert.AreEqual<uint>(4050516109, ar.CRC32(2, -1), "CRC32[2][-1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1860362251, ar.CRC32(3, 15), "CRC32[3][15] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0761448415, ar.CRC32(3, -1), "CRC32[3][-1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2953798997, ar.CRC32(0, 13), "CRC32[0][13] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0480843614, ar.CRC32(0, -7), "CRC32[0][-7] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1228729415, ar.CRC32(1, 13), "CRC32[1][13] was not set correctly.");
|
||||
Assert.AreEqual<uint>(3364131728, ar.CRC32(1, -7), "CRC32[1][-7] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1905873074, ar.CRC32(2, 15), "CRC32[2][15] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0611805314, ar.CRC32(2, -1), "CRC32[2][-1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(4242272536, ar.CRC32(3, 15), "CRC32[3][15] was not set correctly.");
|
||||
Assert.AreEqual<uint>(4236330757, ar.CRC32(3, -1), "CRC32[3][-1] was not set correctly.");
|
||||
|
||||
Assert.AreEqual<uint>(1987827634, ar2.CRC32(1, -7), "CRC32[1,13](2) was not set correctly.");
|
||||
Assert.AreEqual<uint>(0480843614, ar2.CRC32(1, -7), "CRC32[1,13](2) was not set correctly.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -138,12 +132,12 @@ namespace CUETools.TestCodecs
|
||||
[TestMethod()]
|
||||
public void CRCTest1()
|
||||
{
|
||||
Assert.AreEqual<uint>(0095215819, ar.CRC(0, -1), "CRC[0][-1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(4179900079, ar.CRC(0, 99), "CRC[0][99] was not set correctly.");
|
||||
Assert.AreEqual<uint>(3756565509, ar.CRC(1, -3), "CRC[1][-3] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1882341590, ar.CRC(1, 11), "CRC[1][11] was not set correctly.");
|
||||
Assert.AreEqual<uint>(4121006760, ar.CRC(2, -4), "CRC[2][-4] was not set correctly.");
|
||||
Assert.AreEqual<uint>(3648746406, ar.CRC(2, 55), "CRC[2][55] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0123722587, ar.CRC(0, -1), "CRC[0][-1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1975220196, ar.CRC(0, 99), "CRC[0][99] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1519928474, ar.CRC(1, -3), "CRC[1][-3] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2114385036, ar.CRC(1, 11), "CRC[1][11] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1521167728, ar.CRC(2, -4), "CRC[2][-4] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0301435197, ar.CRC(2, 55), "CRC[2][55] was not set correctly.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -152,9 +146,44 @@ namespace CUETools.TestCodecs
|
||||
[TestMethod()]
|
||||
public void CRCTest()
|
||||
{
|
||||
Assert.AreEqual<uint>(1190199900, ar.CRC(0), "CRC[0] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1914801336, ar.CRC(1), "CRC[1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1759975763, ar.CRC(2), "CRC[2] was not set correctly.");
|
||||
Assert.AreEqual<uint>(3727147246, ar.CRC(0), "CRC[0] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2202235240, ar.CRC(1), "CRC[1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(3752629998, ar.CRC(2), "CRC[2] was not set correctly.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///A test for CRCV2
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CRCV2Test()
|
||||
{
|
||||
Assert.AreEqual<uint>(3988391122, ar.CRCV2(0), "CRCV2[0] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2284845104, ar.CRCV2(1), "CRCV2[1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(3841231027, ar.CRCV2(2), "CRCV2[2] was not set correctly.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///A test for ARCRC offset
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CRCTestOffset()
|
||||
{
|
||||
var ar0 = VerifyNoise("13 68 99 136", 723722, 0);
|
||||
for (int offs = 1; offs < 588 * 5; offs += 17)
|
||||
{
|
||||
var ar1 = VerifyNoise("13 68 99 136", 723722, offs);
|
||||
for (int track = 0; track < 3; track++)
|
||||
{
|
||||
Assert.AreEqual<uint>(ar0.CRC(track, offs), ar1.CRC(track), "CRC with offset " + offs + " was not set correctly.");
|
||||
Assert.AreEqual<uint>(ar0.CRC(track), ar1.CRC(track, -offs), "CRC with offset " + (-offs) + " was not set correctly.");
|
||||
Assert.AreEqual<uint>(ar0.CRC450(track, offs), ar1.CRC450(track, 0), "CRC450 with offset " + offs + " was not set correctly.");
|
||||
Assert.AreEqual<uint>(ar0.CRC450(track, 0), ar1.CRC450(track, -offs), "CRC450 with offset " + (-offs) + " was not set correctly.");
|
||||
if (track != 2)
|
||||
Assert.AreEqual<uint>(ar0.CRC32(track + 1, offs), ar1.CRC32(track + 1), "CRC32 with offset " + (offs) + " was not set correctly.");
|
||||
if (track != 0)
|
||||
Assert.AreEqual<uint>(ar0.CRC32(track + 1), ar1.CRC32(track + 1, -offs), "CRC32 with offset " + (-offs) + " was not set correctly.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -163,8 +192,8 @@ namespace CUETools.TestCodecs
|
||||
[TestMethod()]
|
||||
public void CRCWONULLTest1()
|
||||
{
|
||||
Assert.AreEqual<uint>(3376349517, ar.CRCWONULL(2, 19), "CRC32WONULL[2][19] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0162318931, ar.CRCWONULL(2, -2), "CRC32WONULL[2][-2] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0812984565, ar.CRCWONULL(2, 19), "CRC32WONULL[2][19] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2390392664, ar.CRCWONULL(2, -2), "CRC32WONULL[2][-2] was not set correctly.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -173,11 +202,11 @@ namespace CUETools.TestCodecs
|
||||
[TestMethod()]
|
||||
public void CRCWONULLTest()
|
||||
{
|
||||
Assert.AreEqual<uint>(0509527097, ar.CRCWONULL(0), "CRC32WONULL[0] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0474131972, ar.CRCWONULL(1), "CRC32WONULL[1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1405611463, ar.CRCWONULL(2), "CRC32WONULL[2] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2747309238, ar.CRCWONULL(3), "CRC32WONULL[3] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0509527097, ar2.CRCWONULL(1), "CRC32WONULL[1](2) was not set correctly.");
|
||||
Assert.AreEqual<uint>(0404551290, ar.CRCWONULL(0), "CRC32WONULL[0] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0224527589, ar.CRCWONULL(1), "CRC32WONULL[1] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0557159190, ar.CRCWONULL(2), "CRC32WONULL[2] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0516255430, ar.CRCWONULL(3), "CRC32WONULL[3] was not set correctly.");
|
||||
Assert.AreEqual<uint>(0404551290, ar2.CRCWONULL(1), "CRC32WONULL[1](2) was not set correctly.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -186,9 +215,9 @@ namespace CUETools.TestCodecs
|
||||
[TestMethod()]
|
||||
public void CRC450Test()
|
||||
{
|
||||
Assert.AreEqual<uint>(1480802016, ar2.CRC450(1, 00), "CRC450[1,00] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2012115554, ar2.CRC450(1, 55), "CRC450[1,55] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1483829604, ar2.CRC450(1, -3), "CRC450[1,-3] was not set correctly.");
|
||||
Assert.AreEqual<uint>(2224430043, ar2.CRC450(1, 00), "CRC450[1,00] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1912726337, ar2.CRC450(1, 55), "CRC450[1,55] was not set correctly.");
|
||||
Assert.AreEqual<uint>(1251460151, ar2.CRC450(1, -3), "CRC450[1,-3] was not set correctly.");
|
||||
}
|
||||
|
||||
|
||||
@@ -198,39 +227,30 @@ namespace CUETools.TestCodecs
|
||||
[TestMethod()]
|
||||
public void OffsetSafeCRCRecordTest()
|
||||
{
|
||||
OffsetSafeCRCRecord[] records = new OffsetSafeCRCRecord[5000];
|
||||
for (int i = 0; i < records.Length; i++)
|
||||
{
|
||||
var arv = new AccurateRipVerify(toc, null);
|
||||
Random rnd = new Random(2314);
|
||||
Random rnd2 = new Random(2314);
|
||||
for (int k = 0; k < i; k++)
|
||||
{
|
||||
rnd.Next(-32768, 32767);
|
||||
rnd.Next(-32768, 32767);
|
||||
}
|
||||
int chunk;
|
||||
for (int k = 0; k < toc.AudioLength * 588; k += chunk)
|
||||
{
|
||||
chunk = Math.Min(512 + rnd2.Next(512), (int)toc.AudioLength * 588 - k);
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, chunk);
|
||||
buff.Length = chunk;
|
||||
for (int s = 0; s < chunk; s++)
|
||||
{
|
||||
buff.Samples[s, 0] = rnd.Next(-32768, 32767);
|
||||
buff.Samples[s, 1] = rnd.Next(-32768, 32767);
|
||||
}
|
||||
arv.Write(buff);
|
||||
}
|
||||
records[i] = arv.OffsetSafeCRC;
|
||||
arv.Close();
|
||||
}
|
||||
//OffsetSafeCRCRecord[] records = new OffsetSafeCRCRecord[5000];
|
||||
var record0 = VerifyNoise("13 68 99 136", 2314, 0).OffsetSafeCRC;
|
||||
|
||||
for (int i = 0; i < records.Length; i++)
|
||||
Assert.AreEqual(
|
||||
"8+lTDqEZidfayuC0LoxnL9Oluf4ywo1muFBu115XBgf254fKIdfVWZOcsQraS4eI\r\n" +
|
||||
"NoLn7W3t0a16i745nEvikfw27ZsMR7gWPrXgXdsI2OdtjWTRL2Vra2dLe3WOl/Ru\r\n" +
|
||||
"wFa1jqbB3+xHiB8XNi+5VKRh3fj1o5RSXS6tOZUvBUFFqoyuZK/DkeIyZ4gkotYO\r\n" +
|
||||
"MZSsx2JBr2tdBzHZMssUmfvWUrfJZAQD8wMv1epy7q0Mk3W/QetVz6cZZ+6rRctf\r\n" +
|
||||
"PGqvWBgNfS/+e7LBo/49KYd16kEofaX8LuuNB/7YJ85a3W71soQovwWLkjm32Xqo\r\n" +
|
||||
"KpaUagu9QED1WEx7frfu95vYsQLV+vq6zULP6QOznUpU6n6LuMPQa5WNA4+chigC\r\n" +
|
||||
"71GFeKTSO3bnS3xg8FMMqRtcTJleWF/7Bs3DkUZnxbkp4g8iZYZ3eMDc7A04AiYx\r\n" +
|
||||
"3tYvDi9WiEZMRWpvuHfoBzWU7HbfOk5+32yg8TyNyVlPq1cfFn/jwQrfNyztTyav\r\n" +
|
||||
"96ZJS2aBroYAw2We5RC2oekmi+N75L6+eQB/4iZOxB9aGP1sALd/UZaJqZP8FcmW\r\n" +
|
||||
"FJOXlBi/KW68TJvujz+2w/P7EaZ0L7llQAtoHwoJniuNN5WYXBlescGc+vyYr5df\r\n" +
|
||||
"jrul+QMmQ4xMi10mglq7CMLVfZZFFgBdvGBrn1tL9bg=\r\n",
|
||||
VerifyNoise("13 68 99 136", 2314, 13).OffsetSafeCRC.Base64);
|
||||
|
||||
for (int offset = 0; offset < 5000; offset += (offset < 256 ? 1 : 37))
|
||||
{
|
||||
int real_off = -i;
|
||||
var record = VerifyNoise("13 68 99 136", 2314, offset).OffsetSafeCRC;
|
||||
|
||||
int real_off = -offset;
|
||||
int off;
|
||||
bool found = records[0].FindOffset(records[i], out off);
|
||||
bool found = record0.FindOffset(record, out off);
|
||||
if (real_off > 4096 || real_off < -4096)
|
||||
{
|
||||
Assert.IsFalse(found, string.Format("FindOffset found offset where it shouldn't have, real offset {0}", real_off));
|
||||
@@ -240,8 +260,8 @@ namespace CUETools.TestCodecs
|
||||
Assert.IsTrue(found, string.Format("FindOffset failed to detect offset, real offset {0}", real_off));
|
||||
Assert.AreEqual(real_off, off, string.Format("FindOffset returned {0}, should be {1}", off, real_off));
|
||||
}
|
||||
real_off = i;
|
||||
found = records[i].FindOffset(records[0], out off);
|
||||
real_off = offset;
|
||||
found = record.FindOffset(record0, out off);
|
||||
if (real_off > 4096 || real_off < -4096)
|
||||
{
|
||||
Assert.IsFalse(found, string.Format("FindOffset found offset where it shouldn't have, real offset {0}", real_off));
|
||||
|
||||
Reference in New Issue
Block a user