private static void TestTagUtilsTestCloneUsingRaw() { ID3.Tag tag = TestTags.CreateDemoTag(Version.v2_3); byte[] b0 = TagUtils.TagToRaw(tag); byte[] b1 = TagUtils.TagToRaw(tag.Clone()); UnitTest.Test(ArrayUtils.IsEqual(b0, b1)); }
private static void TestTagUtilsWriteRawSmallerQuantizeAbove() { string fileName = VirtualDrive.VirtualFileName("TestTagUtilsWriteRawSmallerQuantizeAbove\\t1.mp3"); TestTags.WriteDemoMp3(fileName, TestTags.demoTag2_4); FileInfo fileInfo = new FileInfo(fileName); TagUtils.WriteTagV2(TestTags.demoTag2_3, fileInfo, Rewriter.Strategy.Quantize); UnitTest.Test(TagUtils.TagSizeV2(new FileInfo(fileName)) % Rewriter.BlockSize == 0); TagUtils.StripTagV2(new FileInfo(fileName), 0); UnitTest.Test(ArrayUtils.IsEqual(VirtualDrive.Load(fileName), TestTags.mpegDummy)); }
private static void TestTagUtilsWriteRawSmallerNeverShrink() { string fileName = VirtualDrive.VirtualFileName("TestTagUtilsWriteRawSmallerNeverShrink\\t1.mp3"); TestTags.WriteDemoMp3(fileName, TestTags.demoTag2_4); FileInfo fileInfo = new FileInfo(fileName); TagUtils.WriteTagV2(TestTags.demoTag2_3, fileInfo, Rewriter.Strategy.NeverShrink); UnitTest.Test(TagUtils.TagSizeV2(fileInfo) == TestTags.demoTag2_4.Length); TagUtils.StripTagV2(fileInfo, 0); UnitTest.Test(ArrayUtils.IsEqual(VirtualDrive.Load(fileName), TestTags.mpegDummy)); }
private static void TestTagUtilsWriteRawBiggerExact() { string fileName = VirtualDrive.VirtualFileName("TestTagUtilsWriteRawBiggerExact\\t1.mp3"); TestTags.WriteDemoMp3(fileName, TestTags.demoTag2_3); FileInfo fileInfo = new FileInfo(fileName); TagUtils.WriteTagV2(TestTags.demoTag2_4, fileInfo, Rewriter.Strategy.Exact); UnitTest.Test(VirtualDrive.FileLength(fileName) == TestTags.demoTag2_4.Length + TestTags.mpegDummy.Length); TagUtils.StripTagV2(fileInfo, 0); UnitTest.Test(ArrayUtils.IsEqual(VirtualDrive.Load(fileName), TestTags.mpegDummy)); }
public static void CreateDemoTags(string path, int count, Action <TagEditor> action) { for (int i = 0; i < count; ++i) { Tag tag = TestTags.CreateDemoTag(ID3.Version.v2_3); TagEditor editor = new TagEditor(tag); editor.Title = "Song No. " + (i + 1); editor.TrackNumber = (i + 1).ToString(); editor.ReleaseYear = "1993"; action(editor); TagUtils.WriteTag(tag, new FileInfo(Path.Combine(path, "Test" + i + ".mp3"))); } }
private static void TestTagUtilsWriteTagBiggerQuantize() { string fileName = VirtualDrive.VirtualFileName("TestTagUtilsWriteTagBiggerQuantize\\t1.mp3"); TestTags.WriteDemoMp3(fileName, TestTags.demoTag2_3); FileInfo fileInfo = new FileInfo(fileName); Tag tag = TagUtils.ReadTag(fileInfo); Frame f = new Frame(tag.DescriptionMap, "MCDI"); (f.Content as FrameContentBinary).Content = new byte[1024]; tag.Add(f); TagUtils.WriteTagV2(tag, fileInfo, Rewriter.Strategy.Quantize); UnitTest.Test(VirtualDrive.FileLength(fileName) == 2048 + TestTags.mpegDummy.Length); TagUtils.StripTagV2(fileInfo, 0); UnitTest.Test(ArrayUtils.IsEqual(VirtualDrive.Load(fileName), TestTags.mpegDummy)); }
private static void TestTagUtilsBuildByCodeAndSerializeInVirtualStore() { foreach (ID3.Version version in ID3.Version.Versions) { string filename = VirtualDrive.VirtualFileName( "TestID3TagBuildByCodeAndSerializeInVirtualStore\\" + version.ToString() + ".tag"); Tag tag0 = TestTags.CreateDemoTag(version); TagUtils.WriteTag(tag0, new FileInfo(filename)); Tag tag1 = TagUtils.ReadTag(new FileInfo(filename)); TagEditor editor0 = new TagEditor(tag0); TagEditor editor1 = new TagEditor(tag1); UnitTest.Test(editor1.Equals(editor0)); } }
private static void TestTagUtilsWriteTagSmallerExact() { Tag tag = TagUtils.RawToTag(TestTags.demoTag2_3); Frame f = new Frame(tag.DescriptionMap, "MCDI"); (f.Content as FrameContentBinary).Content = new byte[1024]; tag.Add(f); string fileName = VirtualDrive.VirtualFileName("TestTagUtilsWriteTagSmallerExact\\t1.mp3"); TestTags.WriteDemoMp3(fileName, TagUtils.TagToRaw(tag)); tag.Remove(f); FileInfo fileInfo = new FileInfo(fileName); TagUtils.WriteTagV2(tag, fileInfo, Rewriter.Strategy.Exact); UnitTest.Test(VirtualDrive.FileLength(fileName) == TagUtils.TagToRaw(tag).Length + TestTags.mpegDummy.Length); TagUtils.StripTagV2(fileInfo, 0); UnitTest.Test(ArrayUtils.IsEqual(VirtualDrive.Load(fileName), TestTags.mpegDummy)); }
private static void TestTagUtilsReadWrite() { int counter = 0; foreach (var demoTag in TestTags.Demotags) { FileInfo fileInfo = VirtualDrive.CreateVirtualFileInfo( "TestTagUtilsReadWrite\\" + counter + ".tag"); TagUtils.WriteTag(demoTag, fileInfo); Tag tag0 = TagUtils.ReadTag(fileInfo); UnitTest.Test(TestTags.IsDemoTag(new TagEditor(tag0))); TagUtils.WriteTag(tag0, fileInfo); UnitTest.Test(ArrayUtils.IsEqual(TagUtils.ReadTagRaw(fileInfo), demoTag)); counter++; } }
private static void TestTagUtilsRewriteMP3() { byte[] tag20 = TagUtils.TagToRaw(TestTags.CreateDemoTag(Version.v2_3)); byte[] tag10 = TestTags.demoTag1_0; string fileName = VirtualDrive.VirtualFileName("TestID3TagUtilsRewrite\\t1.mp3"); using (Stream s = VirtualDrive.OpenOutStream(fileName)) { s.Write(tag20, 0, tag20.Length); s.WriteByte(0); s.WriteByte(0); s.Write(TestTags.mpegDummy, 0, TestTags.mpegDummy.Length); s.Write(tag10, 0, tag10.Length); } long offset = TagUtils.OffsetTagToMpegHeader(new FileInfo(fileName)); UnitTest.Test(offset == 2); TagUtils.StripTags(new FileInfo(fileName), 0, 0); UnitTest.Test(ArrayUtils.IsEqual(VirtualDrive.Load(fileName), TestTags.mpegDummy)); }