mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
CD parity information database test
This commit is contained in:
196
CUETools/CUETools.TestParity/CDRepairDecodeTest.cs
Normal file
196
CUETools/CUETools.TestParity/CDRepairDecodeTest.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using CUETools.CDRepair;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using CUETools.Codecs;
|
||||
|
||||
namespace CUETools.TestParity
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for CDRepairDecodeTest and is intended
|
||||
///to contain all CDRepairDecodeTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class CDRepairDecodeTest
|
||||
{
|
||||
|
||||
const int finalSampleCount = 44100 * 60 * 10 + 20; // 10 minutes long
|
||||
//const int stride = finalSampleCount * 2 / 32768;
|
||||
const int stride = 10 * 588 * 2;
|
||||
const int npar = 8;
|
||||
static byte[] wav = new byte[finalSampleCount * 4];
|
||||
static byte[] wav2 = new byte[finalSampleCount * 4];
|
||||
static byte[] wav3 = new byte[finalSampleCount * 4];
|
||||
static byte[] parity;
|
||||
const int offset = 48;
|
||||
//const int offset = 5 * 588 - 5;
|
||||
//const int offset = 2000;
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
//Use ClassInitialize to run code before running the first test in the class
|
||||
[ClassInitialize()]
|
||||
public static void MyClassInitialize(TestContext testContext)
|
||||
{
|
||||
new Random(2423).NextBytes(wav);
|
||||
new Random(2423).NextBytes(wav2);
|
||||
Random rnd = new Random(987);
|
||||
for (int i = 0; i < stride / 4; i++)
|
||||
wav2[(int)(rnd.NextDouble() * (wav2.Length - 1))] = (byte)(rnd.NextDouble() * 255);
|
||||
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode encode = new CDRepairEncode(finalSampleCount, stride, npar, false);
|
||||
buff.Prepare(wav, finalSampleCount);
|
||||
encode.Write(buff);
|
||||
encode.Close();
|
||||
parity = encode.Parity;
|
||||
}
|
||||
//
|
||||
//Use ClassCleanup to run code after all tests in a class have run
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestInitialize to run code before running each test
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestCleanup to run code after each test has run
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
///Verifying rip that is accurate
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairDecodeOriginalTest()
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode decode = new CDRepairEncode(finalSampleCount, stride, npar, true);
|
||||
buff.Prepare(wav, finalSampleCount);
|
||||
decode.Write(buff);
|
||||
decode.Close();
|
||||
decode.VerifyParity(parity);
|
||||
Assert.IsFalse(decode.HasErrors);
|
||||
Assert.AreEqual(0, decode.ActualOffset, "wrong offset");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///Verifying rip that has errors
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairDecodeModifiedTest()
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode decode = new CDRepairEncode(finalSampleCount, stride, npar, true);
|
||||
buff.Prepare(wav2, finalSampleCount);
|
||||
decode.Write(buff);
|
||||
decode.Close();
|
||||
decode.VerifyParity(parity);
|
||||
Assert.IsTrue(decode.HasErrors, "doesn't have errors");
|
||||
Assert.IsTrue(decode.CanRecover, "cannot recover");
|
||||
Assert.AreEqual(0, decode.ActualOffset, "wrong offset");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///Verifying rip that has positive offset
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairDecodePositiveOffsetTest()
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode decode = new CDRepairEncode(finalSampleCount, stride, npar, true);
|
||||
Array.Copy(wav, offset * 4, wav3, 0, (finalSampleCount - offset) * 4);
|
||||
buff.Prepare(wav3, finalSampleCount);
|
||||
decode.Write(buff);
|
||||
decode.Close();
|
||||
decode.VerifyParity(parity);
|
||||
Assert.IsFalse(decode.HasErrors, "has errors");
|
||||
Assert.AreEqual(offset, decode.ActualOffset, "wrong offset");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///Verifying rip that has negative offset
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairDecodeNegativeOffsetTest()
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode decode = new CDRepairEncode(finalSampleCount, stride, npar, true);
|
||||
buff.Prepare(new byte[offset * 4], offset);
|
||||
decode.Write(buff);
|
||||
buff.Prepare(wav, finalSampleCount - offset);
|
||||
decode.Write(buff);
|
||||
decode.Close();
|
||||
decode.VerifyParity(parity);
|
||||
Assert.IsFalse(decode.HasErrors, "has errors");
|
||||
Assert.AreEqual(-offset, decode.ActualOffset, "wrong offset");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///Verifying rip that has errors and positive offset
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairDecodePositiveOffsetErrorsTest()
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode decode = new CDRepairEncode(finalSampleCount, stride, npar, true);
|
||||
Array.Copy(wav2, offset * 4, wav3, 0, (finalSampleCount - offset) * 4);
|
||||
buff.Prepare(wav3, finalSampleCount);
|
||||
decode.Write(buff);
|
||||
decode.Close();
|
||||
decode.VerifyParity(parity);
|
||||
Assert.IsTrue(decode.HasErrors, "doesn't have errors");
|
||||
Assert.IsTrue(decode.CanRecover, "cannot recover");
|
||||
Assert.AreEqual(offset, decode.ActualOffset, "wrong offset");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///Verifying rip that has errors and negative offset
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairDecodeNegativeOffsetErrorsTest()
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode decode = new CDRepairEncode(finalSampleCount, stride, npar, true);
|
||||
buff.Prepare(new byte[offset * 4], offset);
|
||||
decode.Write(buff);
|
||||
buff.Prepare(wav2, finalSampleCount - offset);
|
||||
decode.Write(buff);
|
||||
decode.Close();
|
||||
decode.VerifyParity(parity);
|
||||
Assert.IsTrue(decode.HasErrors, "doesn't have errors");
|
||||
Assert.IsTrue(decode.CanRecover, "cannot recover");
|
||||
Assert.AreEqual(-offset, decode.ActualOffset, "wrong offset");
|
||||
}
|
||||
}
|
||||
}
|
||||
101
CUETools/CUETools.TestParity/CDRepairEncodeTest.cs
Normal file
101
CUETools/CUETools.TestParity/CDRepairEncodeTest.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using CUETools.CDRepair;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using CUETools.Codecs;
|
||||
|
||||
namespace CUETools.TestParity
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for CDRepairEncodeTest and is intended
|
||||
///to contain all CDRepairEncodeTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class CDRepairEncodeTest
|
||||
{
|
||||
|
||||
const int finalSampleCount = 44100 * 60 * 10; // 10 minutes long
|
||||
//const int stride = finalSampleCount * 2 / 32768;
|
||||
const int stride = 10 * 588 * 2;
|
||||
// CD has maximum of 360.000 sectors;
|
||||
// If stride equals 10 sectors (10 sectors * 588 samples * 2 words),
|
||||
// then maximum sequence length is 36.000 sectors.
|
||||
// 36.000 is less than (65535 - npar), so we're ok here.
|
||||
// npar == 8 provides error correction for 4 samples out of every 36k,
|
||||
// i.e. at best one sample per 9k can be repaired.
|
||||
// Parity data per one CD requires 10 * 588 * 4 * npar bytes,
|
||||
// which equals 188.160b == 184kb
|
||||
// We might consider shorter strides to reduce parity data size,
|
||||
// but it probably should still be a multiple of 588 * 2;
|
||||
// (or the size of CD CIRC buffer?)
|
||||
|
||||
const int npar = 8;
|
||||
static byte[] wav = new byte[finalSampleCount * 4];
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
//Use ClassInitialize to run code before running the first test in the class
|
||||
[ClassInitialize()]
|
||||
public static void MyClassInitialize(TestContext testContext)
|
||||
{
|
||||
new Random(2423).NextBytes(wav);
|
||||
}
|
||||
|
||||
//Use ClassCleanup to run code after all tests in a class have run
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestInitialize to run code before running each test
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestCleanup to run code after each test has run
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
///A test for Write
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairEncodeWriteTest()
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode encode = new CDRepairEncode(finalSampleCount, stride, npar, false);
|
||||
buff.Prepare(wav, finalSampleCount);
|
||||
encode.Write(buff);
|
||||
encode.Close();
|
||||
Assert.AreEqual<byte>(8, encode.Parity[0]);
|
||||
Assert.AreEqual<uint>(2278257733, encode.CRC);
|
||||
}
|
||||
}
|
||||
}
|
||||
145
CUETools/CUETools.TestParity/CDRepairTest.cs
Normal file
145
CUETools/CUETools.TestParity/CDRepairTest.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using CUETools.Codecs;
|
||||
using CUETools.CDRepair;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace CUETools.TestParity
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for CDRepairTest and is intended
|
||||
///to contain all CDRepairTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class CDRepairTest
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
const int finalSampleCount = 44100 * 60 * 10; // 20 minutes long
|
||||
//const int stride = finalSampleCount * 2 / 32768;
|
||||
const int stride = 10 * 588 * 2;
|
||||
const int npar = 8;
|
||||
static byte[] wav = new byte[finalSampleCount * 4];
|
||||
static byte[] wav2 = new byte[finalSampleCount * 4];
|
||||
static byte[] parity;
|
||||
static uint crc;
|
||||
static CDRepairEncode decode;
|
||||
static CDRepairEncode decode2;
|
||||
const int offset = 48;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
//Use ClassInitialize to run code before running the first test in the class
|
||||
[ClassInitialize()]
|
||||
public static void MyClassInitialize(TestContext testContext)
|
||||
{
|
||||
new Random(2423).NextBytes(wav);
|
||||
new Random(2423).NextBytes(wav2);
|
||||
Random rnd = new Random(987);
|
||||
for (int i = 0; i < stride / 4; i++ )
|
||||
wav2[(int)(rnd.NextDouble() * (wav2.Length - 1))] = (byte)(rnd.NextDouble() * 255);
|
||||
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairEncode encode = new CDRepairEncode(finalSampleCount, stride, npar, false);
|
||||
buff.Prepare(wav, finalSampleCount);
|
||||
encode.Write(buff);
|
||||
encode.Close();
|
||||
parity = encode.Parity;
|
||||
crc = encode.CRC;
|
||||
|
||||
decode = new CDRepairEncode(finalSampleCount, stride, npar, true);
|
||||
buff.Prepare(wav2, finalSampleCount);
|
||||
decode.Write(buff);
|
||||
decode.Close();
|
||||
decode.VerifyParity(parity);
|
||||
|
||||
decode2 = new CDRepairEncode(finalSampleCount, stride, npar, true);
|
||||
buff.Prepare(new byte[offset * 4], offset);
|
||||
decode2.Write(buff);
|
||||
buff.Prepare(wav2, finalSampleCount - offset);
|
||||
decode2.Write(buff);
|
||||
decode2.Close();
|
||||
decode2.VerifyParity(parity);
|
||||
}
|
||||
|
||||
//Use ClassCleanup to run code after all tests in a class have run
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestInitialize to run code before running each test
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//Use TestCleanup to run code after each test has run
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
///A test for CDRepair Constructor
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairFixTest()
|
||||
{
|
||||
Assert.IsTrue(decode.HasErrors);
|
||||
Assert.IsTrue(decode.CanRecover);
|
||||
Assert.AreEqual(0, decode.ActualOffset, "wrong offset");
|
||||
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairFix fix = new CDRepairFix(decode);
|
||||
buff.Prepare(wav2, finalSampleCount);
|
||||
fix.Write(buff);
|
||||
fix.Close();
|
||||
|
||||
Assert.AreEqual<uint>(crc, fix.CRC);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///Repair with offset
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void CDRepairFixWithOffsetTest()
|
||||
{
|
||||
Assert.IsTrue(decode2.HasErrors);
|
||||
Assert.IsTrue(decode2.CanRecover);
|
||||
Assert.AreEqual(-offset, decode2.ActualOffset, "wrong offset");
|
||||
|
||||
AudioBuffer buff = new AudioBuffer(AudioPCMConfig.RedBook, 0);
|
||||
CDRepairFix fix = new CDRepairFix(decode2);
|
||||
buff.Prepare(new byte[offset * 4], offset);
|
||||
fix.Write(buff);
|
||||
buff.Prepare(wav2, finalSampleCount - offset);
|
||||
fix.Write(buff);
|
||||
fix.Close();
|
||||
|
||||
Assert.AreEqual<uint>(crc, fix.CRC);
|
||||
}
|
||||
}
|
||||
}
|
||||
77
CUETools/CUETools.TestParity/CUETools.TestParity.csproj
Normal file
77
CUETools/CUETools.TestParity/CUETools.TestParity.csproj
Normal file
@@ -0,0 +1,77 @@
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{6C74652F-1EF4-459E-84F4-99D93D3D17DA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CUETools.TestParity</RootNamespace>
|
||||
<AssemblyName>CUETools.TestParity</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CDRepairDecodeTest.cs" />
|
||||
<Compile Include="CDRepairEncodeTest.cs" />
|
||||
<Compile Include="CDRepairTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RsDecode16Test.cs" />
|
||||
<Compile Include="RsDecodeTest.cs" />
|
||||
<Compile Include="RsEncode16Test.cs" />
|
||||
<Compile Include="RsEncode8Test.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="AuthoringTests.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\CUETools.CDRepair\CUETools.CDRepair.csproj">
|
||||
<Project>{C4869B37-EBB1-47BB-9406-B1209BEAB84B}</Project>
|
||||
<Name>CUETools.CDRepair</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\CUETools.Codecs\CUETools.Codecs.csproj">
|
||||
<Project>{6458A13A-30EF-45A9-9D58-E5031B17BEE2}</Project>
|
||||
<Name>CUETools.Codecs</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\CUETools.Parity\CUETools.Parity.csproj">
|
||||
<Project>{ECEB839C-171B-4535-958F-9899310A0342}</Project>
|
||||
<Name>CUETools.Parity</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
35
CUETools/CUETools.TestParity/Properties/AssemblyInfo.cs
Normal file
35
CUETools/CUETools.TestParity/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("CUETools.TestParity")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("CUETools.TestParity")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM componenets. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("4efabde8-14de-4555-b326-a69be189dd45")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
105
CUETools/CUETools.TestParity/RsDecode16Test.cs
Normal file
105
CUETools/CUETools.TestParity/RsDecode16Test.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using CUETools.Parity;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace CUETools.TestParity
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for RsDecode16Test and is intended
|
||||
///to contain all RsDecode16Test Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class RsDecode16Test
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
//Use ClassInitialize to run code before running the first test in the class
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use ClassCleanup to run code after all tests in a class have run
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestInitialize to run code before running each test
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestCleanup to run code after each test has run
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
///A test for decode
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void decodeTest16()
|
||||
{
|
||||
RsDecode16 target = new RsDecode16(4);
|
||||
byte[] data = new byte[1024];
|
||||
byte[] parity = new byte[] { 193, 3, 222, 151, 9, 2, 128, 246 };
|
||||
byte[] dataplus = new byte[data.Length + parity.Length];
|
||||
Random rnd = new Random(2314);
|
||||
rnd.NextBytes(data);
|
||||
Array.Copy(data, 0, dataplus, 0, data.Length);
|
||||
Array.Copy(parity, 0, dataplus, data.Length, parity.Length);
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
int pos1 = (int)(rnd.NextDouble() * 1023);
|
||||
int pos2 = (int)(rnd.NextDouble() * 1023);
|
||||
if (Math.Abs(pos1 - pos2) < 4)
|
||||
pos2 = (pos1 + 4) % 1024;
|
||||
dataplus[pos1] = (byte)(rnd.NextDouble() * 255);
|
||||
dataplus[pos2] = (byte)(rnd.NextDouble() * 255);
|
||||
if (data[pos1] == dataplus[pos1]) dataplus[pos1] ^= 1;
|
||||
if (data[pos2] == dataplus[pos2]) dataplus[pos2] ^= 8;
|
||||
|
||||
//dataplus[(int)(rnd.NextDouble() * 1023)] = (byte)(rnd.NextDouble() * 255);
|
||||
|
||||
int errors;
|
||||
bool ok = target.decode(dataplus, 0, dataplus.Length, false, out errors);
|
||||
byte[] fixed_data = new byte[data.Length];
|
||||
Array.Copy(dataplus, fixed_data, data.Length);
|
||||
|
||||
Assert.AreEqual(true, ok, "Fail");
|
||||
Assert.AreEqual(2, errors, "Errors");
|
||||
CollectionAssert.AreEqual(data, fixed_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
86
CUETools/CUETools.TestParity/RsDecodeTest.cs
Normal file
86
CUETools/CUETools.TestParity/RsDecodeTest.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using CUETools.Parity;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace CUETools.TestParity
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for RsDecodeTest and is intended
|
||||
///to contain all RsDecodeTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class RsDecodeTest
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
//Use ClassInitialize to run code before running the first test in the class
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use ClassCleanup to run code after all tests in a class have run
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestInitialize to run code before running each test
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestCleanup to run code after each test has run
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
///A test for decode
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void decodeTest()
|
||||
{
|
||||
RsDecode8 target = new RsDecode8(4);
|
||||
byte[] data = Encoding.ASCII.GetBytes("my zest dada");
|
||||
byte[] parity = new byte[] { 255, 199, 140, 166 };
|
||||
byte[] dataplus = new byte[data.Length + 4];
|
||||
Array.Copy(data, 0, dataplus, 0, data.Length);
|
||||
Array.Copy(parity, 0, dataplus, data.Length, parity.Length);
|
||||
int errors;
|
||||
bool ok = target.decode(dataplus, dataplus.Length, false, out errors);
|
||||
Assert.AreEqual(true, ok, "Fail");
|
||||
Assert.AreEqual(2, errors, "Errors");
|
||||
Assert.AreEqual("my test data", Encoding.ASCII.GetString(dataplus, 0, data.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
82
CUETools/CUETools.TestParity/RsEncode16Test.cs
Normal file
82
CUETools/CUETools.TestParity/RsEncode16Test.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using CUETools.Parity;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace CUETools.TestParity
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for RsEncode16Test and is intended
|
||||
///to contain all RsEncode16Test Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class RsEncode16Test
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
//Use ClassInitialize to run code before running the first test in the class
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use ClassCleanup to run code after all tests in a class have run
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestInitialize to run code before running each test
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestCleanup to run code after each test has run
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
///A test for encode
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void encodeTest16()
|
||||
{
|
||||
RsEncode16 target = new RsEncode16(4);
|
||||
byte[] data = new byte[1024];
|
||||
byte[] expected = new byte[] { 193, 3, 222, 151, 9, 2, 128, 246 };
|
||||
byte[] parity = new byte[8];
|
||||
new Random(2314).NextBytes(data);
|
||||
target.encode(data, 0, data.Length, parity, 0);
|
||||
CollectionAssert.AreEqual(expected, parity, "oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
80
CUETools/CUETools.TestParity/RsEncode8Test.cs
Normal file
80
CUETools/CUETools.TestParity/RsEncode8Test.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Text;
|
||||
using CUETools.Parity;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
namespace CUETools.TestParity
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///This is a test class for RsEncode8Test and is intended
|
||||
///to contain all RsEncode8Test Unit Tests
|
||||
///</summary>
|
||||
[TestClass()]
|
||||
public class RsEncode8Test
|
||||
{
|
||||
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
//You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
//Use ClassInitialize to run code before running the first test in the class
|
||||
//[ClassInitialize()]
|
||||
//public static void MyClassInitialize(TestContext testContext)
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use ClassCleanup to run code after all tests in a class have run
|
||||
//[ClassCleanup()]
|
||||
//public static void MyClassCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestInitialize to run code before running each test
|
||||
//[TestInitialize()]
|
||||
//public void MyTestInitialize()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//Use TestCleanup to run code after each test has run
|
||||
//[TestCleanup()]
|
||||
//public void MyTestCleanup()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
///A test for encode
|
||||
///</summary>
|
||||
[TestMethod()]
|
||||
public void encodeTest()
|
||||
{
|
||||
RsEncode8 target = new RsEncode8(4);
|
||||
byte[] data = Encoding.ASCII.GetBytes("my test data");
|
||||
byte[] expected = new byte[] { 255, 199, 140, 166 };
|
||||
byte[] parity = new byte[4];
|
||||
target.encode(data, 0, data.Length, parity, 0);
|
||||
CollectionAssert.AreEqual(expected, parity, "oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user