protected void test_RW_Existing(string fileName, int initialNbPictures, bool deleteTempFile = true, bool sameSizeAfterEdit = false, bool sameBitsAfterEdit = false) { ConsoleLogger log = new ConsoleLogger(); // Source : file with existing tag incl. unsupported picture (Conductor); unsupported field (MOOD) string location = TestUtils.GetResourceLocationRoot() + fileName; string testFileLocation = TestUtils.CopyAsTempTestFile(fileName); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Add a new supported field and a new supported picture Assert.IsTrue(theFile.ReadFromFile()); TagData theTag = new TagData(); char internationalChar = supportsInternationalChars ? '父' : '!'; TagData initialTestData = new TagData(testData); // These two cases cover all tag capabilities if (testData.Title != null) { theTag.Title = "Test !!" + internationalChar; } else if (testData.GeneralDescription != null) { theTag.GeneralDescription = "Description" + internationalChar; } if (testData.AdditionalFields != null && testData.AdditionalFields.Count > 0) { theTag.AdditionalFields = new List <MetaFieldInfo>(); foreach (MetaFieldInfo info in testData.AdditionalFields) { theTag.AdditionalFields.Add(info); break; // 1 is enough } } testData = new TagData(theTag); PictureInfo picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, PictureInfo.PIC_TYPE.CD); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"); theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, tagType)); readExistingTagsOnFile(theFile, initialNbPictures + 1); Assert.IsNotNull(theFile.getMeta(tagType)); IMetaDataIO meta = theFile.getMeta(tagType); Assert.IsTrue(meta.Exists); if (testData.Pictures != null && testData.Pictures.Count > 0) { int nbFound = 0; foreach (PictureInfo pic in meta.EmbeddedPictures) { if (pic.PicType.Equals(PictureInfo.PIC_TYPE.CD)) { if (tagType.Equals(MetaDataIOFactory.TAG_APE)) { Assert.AreEqual("Cover Art (Media)", pic.NativePicCodeStr); } else // ID3v2 convention { Assert.AreEqual(0x06, pic.NativePicCode); } using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData))) { Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg); Assert.AreEqual(600, picture.Height); Assert.AreEqual(900, picture.Width); } nbFound++; break; } } Assert.AreEqual(1, nbFound); } // Remove the additional supported field theTag = new TagData(initialTestData); testData = new TagData(initialTestData); // Remove additional picture picInfo = new PictureInfo(ImageFormat.Jpeg, PictureInfo.PIC_TYPE.CD); picInfo.MarkedForDeletion = true; theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, tagType)); readExistingTagsOnFile(theFile, initialNbPictures); // Additional removed field Assert.AreEqual("", theFile.getMeta(tagType).Conductor); // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added) if (sameSizeAfterEdit || sameBitsAfterEdit) { FileInfo originalFileInfo = new FileInfo(location); FileInfo testFileInfo = new FileInfo(testFileLocation); if (sameSizeAfterEdit) { Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); } if (sameBitsAfterEdit) { string originalMD5 = TestUtils.GetFileMD5Hash(location); string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation); Assert.AreEqual(originalMD5, testMD5); } } // Get rid of the working copy if (deleteTempFile) { File.Delete(testFileLocation); } }
public void TagIO_RW_VorbisOGG_Chapters() { ConsoleLogger log = new ConsoleLogger(); // Source : OGG with existing tag incl. chapters String testFileLocation = TestUtils.GetTempTestFile("OGG/chapters.ogg"); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetDataReader(testFileLocation)); // Check if the two fields are indeed accessible Assert.IsTrue(theFile.ReadFromFile(false, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(9, theFile.NativeTag.Chapters.Count); Dictionary <uint, ChapterInfo> expectedChaps = new Dictionary <uint, ChapterInfo>(); ChapterInfo ch = new ChapterInfo(); ch.StartTime = 0; ch.Title = "Intro"; ch.Url = "https://auphonic.com/"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 15000; ch.Title = "Creating a new production"; ch.Url = "https://auphonic.com/engine/upload/"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 22000; ch.Title = "Sound analysis"; ch.Url = ""; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 34000; ch.Title = "Adaptive leveler"; ch.Url = "https://auphonic.com/audio_examples#leveler"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 45000; ch.Title = "Global loudness normalization"; ch.Url = "https://auphonic.com/audio_examples#loudnorm"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 60000; ch.Title = "Audio restoration algorithms"; ch.Url = "https://auphonic.com/audio_examples#denoise"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 76000; ch.Title = "Output file formats"; ch.Url = "http://auphonic.com/blog/5/"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 94000; ch.Title = "External services"; ch.Url = "http://auphonic.com/blog/16/"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 111500; ch.Title = "Get a free account!"; ch.Url = "https://auphonic.com/accounts/register"; expectedChaps.Add(ch.StartTime, ch); int found = 0; foreach (ChapterInfo chap in theFile.NativeTag.Chapters) { if (expectedChaps.ContainsKey(chap.StartTime)) { found++; Assert.AreEqual(expectedChaps[chap.StartTime].StartTime, chap.StartTime); Assert.AreEqual(expectedChaps[chap.StartTime].Title, chap.Title); Assert.AreEqual(expectedChaps[chap.StartTime].Url, chap.Url); } else { System.Console.WriteLine(chap.StartTime); } } Assert.AreEqual(9, found); // Modify elements TagData theTag = new TagData(); theTag.Chapters = new List <ChapterInfo>(); expectedChaps.Clear(); ch = new ChapterInfo(); ch.StartTime = 123; ch.Title = "aaa"; ch.Url = "ddd"; theTag.Chapters.Add(ch); expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 1230; ch.Title = "aaa0"; ch.Url = "ddd0"; theTag.Chapters.Add(ch); expectedChaps.Add(ch.StartTime, ch); // Check if they are persisted properly Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile(false, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(2, theFile.NativeTag.Chapters.Count); // Check if values are the same found = 0; foreach (ChapterInfo chap in theFile.NativeTag.Chapters) { if (expectedChaps.ContainsKey(chap.StartTime)) { found++; Assert.AreEqual(chap.StartTime, expectedChaps[chap.StartTime].StartTime); Assert.AreEqual(chap.Title, expectedChaps[chap.StartTime].Title); Assert.AreEqual(chap.Url, expectedChaps[chap.StartTime].Url); } else { System.Console.WriteLine(chap.StartTime); } } Assert.AreEqual(2, found); // Get rid of the working copy File.Delete(testFileLocation); }
public void TagIO_RW_VorbisOGG_Empty() { ConsoleLogger log = new ConsoleLogger(); // Source : totally metadata-free OGG string location = TestUtils.GetResourceLocationRoot() + emptyFile; string testFileLocation = TestUtils.GetTempTestFile(emptyFile); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetDataReader(testFileLocation)); // Check that it is indeed metadata-free Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); Assert.IsFalse(theFile.NativeTag.Exists); // Construct a new tag TagData theTag = new TagData(); theTag.Title = "Test !!"; theTag.Album = "Album"; theTag.Artist = "Artist"; theTag.AlbumArtist = "Mike"; theTag.Comment = "This is a test"; theTag.RecordingYear = "2008"; theTag.RecordingDate = "2008/01/01"; theTag.Genre = "Merengue"; theTag.TrackNumber = "01/01"; theTag.DiscNumber = "2"; theTag.Composer = "Me"; theTag.Copyright = "父"; theTag.Conductor = "John Johnson Jr."; // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual("Test !!", theFile.NativeTag.Title); Assert.AreEqual("Album", theFile.NativeTag.Album); Assert.AreEqual("Artist", theFile.NativeTag.Artist); Assert.AreEqual("Mike", theFile.NativeTag.AlbumArtist); Assert.AreEqual("This is a test", theFile.NativeTag.Comment); Assert.AreEqual("2008", theFile.NativeTag.Year); Assert.AreEqual("Merengue", theFile.NativeTag.Genre); Assert.AreEqual(1, theFile.NativeTag.Track); Assert.AreEqual(2, theFile.NativeTag.Disc); Assert.AreEqual("Me", theFile.NativeTag.Composer); Assert.AreEqual("父", theFile.NativeTag.Copyright); Assert.AreEqual("John Johnson Jr.", theFile.NativeTag.Conductor); // Remove the tag and check that it has been indeed removed Assert.IsTrue(theFile.RemoveTagFromFile(MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); Assert.IsFalse(theFile.NativeTag.Exists); // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added) FileInfo originalFileInfo = new FileInfo(location); FileInfo testFileInfo = new FileInfo(testFileLocation); Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); string originalMD5 = TestUtils.GetFileMD5Hash(location); string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation); Assert.IsTrue(originalMD5.Equals(testMD5)); // Get rid of the working copy File.Delete(testFileLocation); }
private void tagIO_RW_VorbisOGG_Existing(string fileName, int initialNbPictures, bool deleteTempFile = true) { ConsoleLogger log = new ConsoleLogger(); // Source : OGG with existing tag incl. unsupported picture (Conductor); unsupported field (MOOD) string location = TestUtils.GetResourceLocationRoot() + fileName; string testFileLocation = TestUtils.GetTempTestFile(fileName); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetDataReader(testFileLocation)); // Add a new supported field and a new supported picture Assert.IsTrue(theFile.ReadFromFile()); TagData theTag = new TagData(); theTag.Conductor = "John Jackman"; PictureInfo picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, PictureInfo.PIC_TYPE.CD); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"); theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); readExistingTagsOnFile(ref theFile, initialNbPictures + 1); // Additional supported field Assert.AreEqual("John Jackman", theFile.NativeTag.Conductor); int nbFound = 0; foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures) { if (pic.PicType.Equals(PictureInfo.PIC_TYPE.CD)) { Assert.AreEqual(pic.NativePicCode, 0x06); Image picture = Image.FromStream(new MemoryStream(pic.PictureData)); Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg); Assert.AreEqual(picture.Height, 600); Assert.AreEqual(picture.Width, 900); nbFound++; break; } } Assert.AreEqual(1, nbFound); // Remove the additional supported field theTag = new TagData(); theTag.Conductor = ""; // Remove additional picture picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, PictureInfo.PIC_TYPE.CD); picInfo.MarkedForDeletion = true; theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); readExistingTagsOnFile(ref theFile, initialNbPictures); // Additional removed field Assert.AreEqual("", theFile.NativeTag.Conductor); // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added) FileInfo originalFileInfo = new FileInfo(location); FileInfo testFileInfo = new FileInfo(testFileLocation); Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); string originalMD5 = TestUtils.GetFileMD5Hash(location); string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation); Assert.IsTrue(originalMD5.Equals(testMD5)); // Get rid of the working copy if (deleteTempFile) { File.Delete(testFileLocation); } }
public void TagIO_RW_VorbisOGG_Unsupported_Empty() { // Source : tag-free OGG String testFileLocation = TestUtils.GetTempTestFile(emptyFile); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetDataReader(testFileLocation)); // Check that it is indeed tag-free Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); Assert.IsFalse(theFile.NativeTag.Exists); // Add new unsupported fields TagData theTag = new TagData(); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST", "This is a test 父")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST2", "This is another test 父")); // Add new unsupported pictures PictureInfo picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, MetaDataIOFactory.TAG_NATIVE, 0x0A); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"); theTag.Pictures.Add(picInfo); picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, MetaDataIOFactory.TAG_NATIVE, 0x0B); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic2.jpg"); theTag.Pictures.Add(picInfo); theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(3, theFile.NativeTag.AdditionalFields.Count); // 3 instead of 2 because of the VENDOR field... (specific to VorbisTag) Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST")); Assert.AreEqual("This is a test 父", theFile.NativeTag.AdditionalFields["TEST"]); Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST2")); Assert.AreEqual("This is another test 父", theFile.NativeTag.AdditionalFields["TEST2"]); Assert.AreEqual(2, theFile.NativeTag.EmbeddedPictures.Count); byte found = 0; foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures) { if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && pic.NativePicCode.Equals(0x0A)) { Image picture = Image.FromStream(new MemoryStream(pic.PictureData)); Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg); Assert.AreEqual(picture.Height, 600); Assert.AreEqual(picture.Width, 900); found++; } else if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && pic.NativePicCode.Equals(0x0B)) { Image picture = Image.FromStream(new MemoryStream(pic.PictureData)); Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg); Assert.AreEqual(picture.Height, 290); Assert.AreEqual(picture.Width, 900); found++; } } Assert.AreEqual(2, found); // Remove the additional unsupported field theTag = new TagData(); MetaFieldInfo fieldInfo = new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST"); fieldInfo.MarkedForDeletion = true; theTag.AdditionalFields.Add(fieldInfo); // Remove additional picture picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, MetaDataIOFactory.TAG_NATIVE, 0x0A); picInfo.MarkedForDeletion = true; theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); // Additional removed field Assert.AreEqual(2, theFile.NativeTag.AdditionalFields.Count); // 2 instead of 1 because of the VENDOR field... Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST2")); Assert.AreEqual("This is another test 父", theFile.NativeTag.AdditionalFields["TEST2"]); // Pictures Assert.AreEqual(1, theFile.NativeTag.EmbeddedPictures.Count); found = 0; foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures) { if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && pic.NativePicCode.Equals(0x0B)) { Image picture = Image.FromStream(new MemoryStream(pic.PictureData)); Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg); Assert.AreEqual(picture.Height, 290); Assert.AreEqual(picture.Width, 900); found++; } } Assert.AreEqual(1, found); // Get rid of the working copy File.Delete(testFileLocation); }
public void TagIO_RW_MP4_Chapters_QT() { ConsoleLogger log = new ConsoleLogger(); // Source : MP3 with existing tag incl. chapters String testFileLocation = TestUtils.CopyAsTempTestFile("AAC/chapters_QT.m4v"); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check if the two fields are indeed accessible Assert.IsTrue(theFile.ReadFromFile(false, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(4, theFile.NativeTag.Chapters.Count); Dictionary <uint, ChapterInfo> expectedChaps = new Dictionary <uint, ChapterInfo>(); ChapterInfo ch = new ChapterInfo(); ch.StartTime = 0; ch.Title = "Chapter One"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 1139; ch.Title = "Chapter 2"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 2728; ch.Title = "Chapter 003"; expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 3269; ch.Title = "Chapter 四"; expectedChaps.Add(ch.StartTime, ch); int found = 0; foreach (ChapterInfo chap in theFile.NativeTag.Chapters) { if (expectedChaps.ContainsKey(chap.StartTime)) { found++; Assert.AreEqual(chap.StartTime, expectedChaps[chap.StartTime].StartTime); Assert.AreEqual(chap.Title, expectedChaps[chap.StartTime].Title); } else { System.Console.WriteLine(chap.StartTime); } } Assert.AreEqual(4, found); /* * // Modify elements -- not supported yet * TagData theTag = new TagData(); * theTag.Chapters = new List<ChapterInfo>(); * expectedChaps.Clear(); * * ch = new ChapterInfo(); * ch.StartTime = 123; * ch.Title = "aaa"; * * theTag.Chapters.Add(ch); * expectedChaps.Add(ch.StartTime, ch); * * ch = new ChapterInfo(); * ch.StartTime = 1230; * ch.Title = "aaa0"; * * theTag.Chapters.Add(ch); * expectedChaps.Add(ch.StartTime, ch); * * // Check if they are persisted properly * Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); * * Assert.IsTrue(theFile.ReadFromFile(false, true)); * Assert.IsNotNull(theFile.NativeTag); * Assert.IsTrue(theFile.NativeTag.Exists); * * Assert.AreEqual(2, theFile.NativeTag.Chapters.Count); * * // Check if values are the same * found = 0; * foreach (ChapterInfo chap in theFile.NativeTag.Chapters) * { * if (expectedChaps.ContainsKey(chap.StartTime)) * { * found++; * Assert.AreEqual(chap.StartTime, expectedChaps[chap.StartTime].StartTime); * Assert.AreEqual(chap.Title, expectedChaps[chap.StartTime].Title); * } * else * { * System.Console.WriteLine(chap.StartTime); * } * } * Assert.AreEqual(2, found); */ // Get rid of the working copy File.Delete(testFileLocation); }
public void TagIO_RW_MP4_Chapters_QT_Create() { new ConsoleLogger(); ATL.Settings.MP4_createNeroChapters = false; try { // Source : file without 'chpl' atom String testFileLocation = TestUtils.CopyAsTempTestFile("MP4/empty.m4a"); AudioDataManager theFile = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.getMeta(tagType)); Assert.IsFalse(theFile.getMeta(tagType).Exists); // Modify elements TagData theTag = new TagData(); Dictionary <uint, ChapterInfo> expectedChaps = new Dictionary <uint, ChapterInfo>(); theTag.Chapters = new List <ChapterInfo>(); ChapterInfo ch = new ChapterInfo(); ch.StartTime = 0; ch.Title = "aaa"; theTag.Chapters.Add(ch); expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(); ch.StartTime = 1230; ch.Title = "aaa0"; theTag.Chapters.Add(ch); expectedChaps.Add(ch.StartTime, ch); // Check if they are persisted properly Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile(false, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(2, theFile.NativeTag.Chapters.Count); // Check if values are the same int found = 0; foreach (ChapterInfo chap in theFile.NativeTag.Chapters) { if (expectedChaps.ContainsKey(chap.StartTime)) { found++; Assert.AreEqual(expectedChaps[chap.StartTime].StartTime, chap.StartTime); Assert.AreEqual(expectedChaps[chap.StartTime].Title, chap.Title); } else { System.Console.WriteLine(chap.StartTime); } } Assert.AreEqual(2, found); // Get rid of the working copy if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } finally { ATL.Settings.MP4_createNeroChapters = true; } }
public void TagIO_RW_MP4_Existing() { new ConsoleLogger(); // Source : MP3 with existing tag incl. unsupported picture (Cover Art (Fronk)); unsupported field (MOOD) String testFileLocation = TestUtils.CopyAsTempTestFile(notEmptyFile); AudioDataManager theFile = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Add a new supported field and a new supported picture Assert.IsTrue(theFile.ReadFromFile()); TagData theTag = new TagData(); theTag.Conductor = "John Jackman"; byte[] data = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.png"); PictureInfo picInfo = PictureInfo.fromBinaryData(data, PictureInfo.PIC_TYPE.Generic, MetaDataIOFactory.TAG_ANY, 14); theTag.Pictures.Add(picInfo); theTag.Chapters = theFile.NativeTag.Chapters; theTag.Chapters.Add(new ChapterInfo(3000, "Chapter 2")); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); try { // Read Quicktime chapters specifically ATL.Settings.MP4_readChaptersExclusive = 1; Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.AreEqual(2, theFile.NativeTag.Chapters.Count); Assert.AreEqual((uint)0, theFile.NativeTag.Chapters[0].StartTime); // 1st Quicktime chapter can't start at position > 0 Assert.AreEqual("aa父bb", theFile.NativeTag.Chapters[0].Title); Assert.AreEqual((uint)2945, theFile.NativeTag.Chapters[1].StartTime); // Approximate due to the way timecodes are formatted in the MP4 format Assert.AreEqual("Chapter 2", theFile.NativeTag.Chapters[1].Title); // Read Nero chapters specifically ATL.Settings.MP4_readChaptersExclusive = 2; Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.AreEqual(2, theFile.NativeTag.Chapters.Count); Assert.AreEqual((uint)55, theFile.NativeTag.Chapters[0].StartTime); Assert.AreEqual("aa父bb", theFile.NativeTag.Chapters[0].Title); Assert.AreEqual((uint)3000, theFile.NativeTag.Chapters[1].StartTime); Assert.AreEqual("Chapter 2", theFile.NativeTag.Chapters[1].Title); } finally { ATL.Settings.MP4_readChaptersExclusive = 0; } // Read the rest supported fields readExistingTagsOnFile(theFile, 2); // Additional supported field Assert.AreEqual("John Jackman", theFile.NativeTag.Conductor); byte nbFound = 0; foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures) { if (pic.PicType.Equals(PIC_TYPE.Generic) && (1 == nbFound)) { using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData))) { Assert.AreEqual(ImageFormat.Png, picture.RawFormat); Assert.AreEqual(175, picture.Width); Assert.AreEqual(168, picture.Height); } } nbFound++; } Assert.AreEqual(2, nbFound); // Remove the additional supported field theTag = new TagData(); theTag.Conductor = ""; // Remove additional picture picInfo = new PictureInfo(PIC_TYPE.Back); picInfo.MarkedForDeletion = true; theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); readExistingTagsOnFile(theFile); // Additional removed field Assert.AreEqual("", theFile.NativeTag.Conductor); // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added) /* NOT POSSIBLE YET mainly due to tag order and tag naming (e.g. "gnre" becoming "©gen") differences * FileInfo originalFileInfo = new FileInfo(location); * FileInfo testFileInfo = new FileInfo(testFileLocation); * * Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); * * string originalMD5 = TestUtils.GetFileMD5Hash(location); * string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation); * * Assert.IsTrue(originalMD5.Equals(testMD5)); */ // Get rid of the working copy if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } }
public void TagIO_RW_MP4_Unsupported_Empty() { // Source : tag-free M4A String testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile); AudioDataManager theFile = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check that it is indeed tag-free Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); Assert.IsFalse(theFile.NativeTag.Exists); // Add new unsupported fields TagData theTag = new TagData(); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST", "This is a test 父")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TES2", "This is another test 父")); // Add new unsupported pictures PictureInfo picInfo = PictureInfo.fromBinaryData( File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"), PIC_TYPE.Unsupported, MetaDataIOFactory.TAG_NATIVE, "1234"); theTag.Pictures.Add(picInfo); picInfo = PictureInfo.fromBinaryData( File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic2.jpg"), PIC_TYPE.Unsupported, MetaDataIOFactory.TAG_NATIVE, "5678"); theTag.Pictures.Add(picInfo); theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(2, theFile.NativeTag.AdditionalFields.Count); Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST")); Assert.AreEqual("This is a test 父", theFile.NativeTag.AdditionalFields["TEST"]); Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TES2")); Assert.AreEqual("This is another test 父", theFile.NativeTag.AdditionalFields["TES2"]); Assert.AreEqual(2, theFile.NativeTag.EmbeddedPictures.Count); byte found = 0; foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures) { if (pic.PicType.Equals(PIC_TYPE.Generic) && (0 == found)) // No custom nor categorized picture type in MP4 { using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData))) { Assert.AreEqual(ImageFormat.Jpeg, picture.RawFormat); Assert.AreEqual(600, picture.Height); Assert.AreEqual(900, picture.Width); } found++; } else if (pic.PicType.Equals(PIC_TYPE.Generic) && (1 == found)) // No custom nor categorized picture type in MP4 { using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData))) { Assert.AreEqual(ImageFormat.Jpeg, picture.RawFormat); Assert.AreEqual(290, picture.Height); Assert.AreEqual(900, picture.Width); } found++; } } Assert.AreEqual(2, found); // Remove the additional unsupported field theTag = new TagData(); MetaFieldInfo fieldInfo = new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST"); fieldInfo.MarkedForDeletion = true; theTag.AdditionalFields.Add(fieldInfo); // Remove additional picture picInfo = new PictureInfo(PictureInfo.PIC_TYPE.Generic, 1); picInfo.MarkedForDeletion = true; theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); // Additional removed field Assert.AreEqual(1, theFile.NativeTag.AdditionalFields.Count); Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TES2")); Assert.AreEqual("This is another test 父", theFile.NativeTag.AdditionalFields["TES2"]); // Pictures Assert.AreEqual(1, theFile.NativeTag.EmbeddedPictures.Count); found = 0; foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures) { if (pic.PicType.Equals(PIC_TYPE.Generic) && (0 == found)) { using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData))) { Assert.AreEqual(ImageFormat.Jpeg, picture.RawFormat); Assert.AreEqual(290, picture.Height); Assert.AreEqual(900, picture.Width); } found++; } } Assert.AreEqual(1, found); // Get rid of the working copy if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } }
protected void test_RW_Cohabitation(int tagType1, int tagType2, bool canMeta1NotExist = true) { ConsoleLogger log = new ConsoleLogger(); // Source : empty file string location = TestUtils.GetResourceLocationRoot() + emptyFile; string testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check that it is indeed tag-free Assert.IsTrue(theFile.ReadFromFile()); IMetaDataIO meta1 = theFile.getMeta(tagType1); IMetaDataIO meta2 = theFile.getMeta(tagType2); Assert.IsNotNull(meta1); if (canMeta1NotExist) { Assert.IsFalse(meta1.Exists); } Assert.IsNotNull(meta2); Assert.IsFalse(meta2.Exists); // Construct a new tag with the most basic options (no un supported fields, no pictures) TagData theTag1 = new TagData(); theTag1.Title = "Test1"; theTag1.Album = "Album1"; TagData theTag2 = new TagData(); theTag2.Title = "Test2"; theTag2.Album = "Album2"; // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag1, tagType1)); Assert.IsTrue(theFile.UpdateTagInFile(theTag2, tagType2)); // This also tests if physical data can still be read (e.g. native tag has not been scrambled by the apparition of a non-native tag) Assert.IsTrue(theFile.ReadFromFile()); meta1 = theFile.getMeta(tagType1); meta2 = theFile.getMeta(tagType2); Assert.IsNotNull(meta1); Assert.IsTrue(meta1.Exists); Assert.IsNotNull(meta2); Assert.IsTrue(meta2.Exists); Assert.AreEqual("Test1", meta1.Title); Assert.AreEqual("Album1", meta1.Album); Assert.AreEqual("Test2", meta2.Title); Assert.AreEqual("Album2", meta2.Album); Assert.IsTrue(theFile.RemoveTagFromFile(tagType1)); Assert.IsTrue(theFile.ReadFromFile()); meta1 = theFile.getMeta(tagType1); meta2 = theFile.getMeta(tagType2); Assert.IsNotNull(meta1); if (canMeta1NotExist) { Assert.IsFalse(meta1.Exists); } Assert.IsNotNull(meta2); Assert.IsTrue(meta2.Exists); Assert.AreEqual("Test2", meta2.Title); Assert.AreEqual("Album2", meta2.Album); Assert.IsTrue(theFile.RemoveTagFromFile(tagType2)); Assert.IsTrue(theFile.ReadFromFile()); meta1 = theFile.getMeta(tagType1); meta2 = theFile.getMeta(tagType2); Assert.IsNotNull(meta1); if (canMeta1NotExist) { Assert.IsFalse(meta1.Exists); } Assert.IsNotNull(meta2); Assert.IsFalse(meta2.Exists); // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added) FileInfo originalFileInfo = new FileInfo(location); FileInfo testFileInfo = new FileInfo(testFileLocation); Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); string originalMD5 = TestUtils.GetFileMD5Hash(location); string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation); Assert.AreEqual(originalMD5, testMD5); // Get rid of the working copy File.Delete(testFileLocation); }
public void TagIO_RW_PSF_Unsupported_Empty() { // Source : tag-free file String testFileLocation = TestUtils.GetTempTestFile(emptyFile); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetDataReader(testFileLocation)); // Check that it is indeed tag-free Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); // Assert.IsFalse(theFile.NativeTag.Exists); Tag data contains information required for playback => can never be nonexistent // Add new unsupported fields TagData theTag = new TagData(); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST", "This is a test")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST2", "This is another test")); theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(5, theFile.NativeTag.AdditionalFields.Count); // 5 and not 2 because of "utf8", "length" and "fade" mandatory fields Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST")); Assert.AreEqual("This is a test", theFile.NativeTag.AdditionalFields["TEST"]); Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST2")); Assert.AreEqual("This is another test", theFile.NativeTag.AdditionalFields["TEST2"]); // Remove the additional unsupported field theTag = new TagData(); MetaFieldInfo fieldInfo = new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST"); fieldInfo.MarkedForDeletion = true; theTag.AdditionalFields.Add(fieldInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); // Additional removed field Assert.AreEqual(4, theFile.NativeTag.AdditionalFields.Count); // 4 and not 1 because of "utf8", "length" and "fade" mandatory fields Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST2")); Assert.AreEqual("This is another test", theFile.NativeTag.AdditionalFields["TEST2"]); // Get rid of the working copy File.Delete(testFileLocation); }
protected void readExistingTagsOnFile(AudioDataManager theFile, int nbPictures = 2) { Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.getMeta(tagType)); IMetaDataIO meta = theFile.getMeta(tagType); Assert.IsTrue(meta.Exists); // Supported fields if (testData.Title != null) { Assert.AreEqual(testData.Title, meta.Title); } if (testData.Album != null) { Assert.AreEqual(testData.Album, meta.Album); } if (testData.Artist != null) { Assert.AreEqual(testData.Artist, meta.Artist); } if (testData.AlbumArtist != null) { Assert.AreEqual(testData.AlbumArtist, meta.AlbumArtist); } if (testData.Comment != null) { Assert.AreEqual(testData.Comment, meta.Comment); } if (testData.RecordingYear != null) { Assert.AreEqual(testData.RecordingYear, meta.Year); } //if (testData.RecordingDate != null) Assert.AreEqual(testData.RecordingDate, meta.); if (testData.Genre != null) { Assert.AreEqual(testData.Genre, meta.Genre); } if (testData.Rating != null) { if (Utils.IsNumeric(testData.Rating)) { float f = float.Parse(testData.Rating); Assert.AreEqual((f / 5.0).ToString(), meta.Popularity.ToString()); } else if (0 == testData.Rating.Length) { Assert.AreEqual("0", meta.Popularity.ToString()); } else { Assert.AreEqual(testData.Rating, meta.Popularity.ToString()); } } if (testData.TrackNumber != null) { Assert.AreEqual(ushort.Parse(testData.TrackNumber), meta.Track); } if (testData.TrackTotal != null) { Assert.AreEqual(ushort.Parse(testData.TrackTotal), meta.TrackTotal); } if (testData.Composer != null) { Assert.AreEqual(testData.Composer, meta.Composer); } if (testData.DiscNumber != null) { Assert.AreEqual(ushort.Parse(testData.DiscNumber), meta.Disc); } if (testData.DiscTotal != null) { Assert.AreEqual(ushort.Parse(testData.DiscTotal), meta.DiscTotal); } if (testData.Conductor != null) { Assert.AreEqual(testData.Conductor, meta.Conductor); } if (testData.Publisher != null) { Assert.AreEqual(testData.Publisher, meta.Publisher); } if (testData.Copyright != null) { Assert.AreEqual(testData.Copyright, meta.Copyright); } if (testData.GeneralDescription != null) { Assert.AreEqual(testData.GeneralDescription, meta.GeneralDescription); } // Unsupported field if (testData.AdditionalFields != null && testData.AdditionalFields.Count > 0) { foreach (MetaFieldInfo field in testData.AdditionalFields) { Assert.IsTrue(meta.AdditionalFields.Keys.Contains(field.NativeFieldCode)); Assert.AreEqual(field.Value, meta.AdditionalFields[field.NativeFieldCode]); } } // Pictures if (testData.Pictures != null && testData.Pictures.Count > 0) { Assert.AreEqual(nbPictures, meta.EmbeddedPictures.Count); byte nbFound = 0; foreach (PictureInfo pic in meta.EmbeddedPictures) { foreach (PictureInfo testPicInfo in testData.Pictures) { if ((pic.NativePicCode > -1 && pic.NativePicCode.Equals(testPicInfo.NativePicCode)) || (pic.NativePicCodeStr != null && pic.NativePicCodeStr.Equals(testPicInfo.NativePicCodeStr, System.StringComparison.OrdinalIgnoreCase)) ) { nbFound++; pic.ComputePicHash(); Assert.AreEqual(testPicInfo.PictureHash, pic.PictureHash); break; } } } Assert.AreEqual(testData.Pictures.Count, nbFound); } }
public void TagIO_RW_VQF_Empty() { ConsoleLogger log = new ConsoleLogger(); // Source : totally metadata-free VQF string location = TestUtils.GetResourceLocationRoot() + emptyFile; string testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check that it is indeed metadata-free Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); // Assert.IsFalse(theFile.NativeTag.Exists); Tag data contains information required for playback => can never be nonexistent // Construct a new tag TagData theTag = new TagData(); theTag.Title = "Test !!"; theTag.Album = "Album"; theTag.Artist = "Artist"; theTag.Copyright = "父"; theTag.Comment = "This is a test"; theTag.RecordingDate = "2008"; theTag.Genre = "FPS"; theTag.TrackNumber = "22/23"; // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual("Test !!", theFile.NativeTag.Title); Assert.AreEqual("Album", theFile.NativeTag.Album); Assert.AreEqual("Artist", theFile.NativeTag.Artist); Assert.AreEqual("父", theFile.NativeTag.Copyright); Assert.AreEqual("This is a test", theFile.NativeTag.Comment); Assert.AreEqual("2008", theFile.NativeTag.Year); Assert.AreEqual("FPS", theFile.NativeTag.Genre); Assert.AreEqual(22, theFile.NativeTag.Track); // Remove the tag and check that it has been indeed removed Assert.IsTrue(theFile.RemoveTagFromFile(MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); // Assert.IsFalse(theFile.NativeTag.Exists); Tag data contains information required for playback => can never be nonexistent // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added) FileInfo originalFileInfo = new FileInfo(location); FileInfo testFileInfo = new FileInfo(testFileLocation); Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); string originalMD5 = TestUtils.GetFileMD5Hash(location); string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation); Assert.IsTrue(originalMD5.Equals(testMD5)); // Get rid of the working copy File.Delete(testFileLocation); }
public void TagIO_RW_VQF_Unsupported_Empty() { // Source : tag-free file String testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check that it is indeed tag-free Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.NativeTag); Assert.IsFalse(theFile.NativeTag.Exists); // Add new unsupported fields TagData theTag = new TagData(); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST", "This is a test")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TES2", "This is another test")); theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(2, theFile.NativeTag.AdditionalFields.Count); Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST")); Assert.AreEqual("This is a test", theFile.NativeTag.AdditionalFields["TEST"]); Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TES2")); Assert.AreEqual("This is another test", theFile.NativeTag.AdditionalFields["TES2"]); // Remove the additional unsupported field theTag = new TagData(); MetaFieldInfo fieldInfo = new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST"); fieldInfo.MarkedForDeletion = true; theTag.AdditionalFields.Add(fieldInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); // Additional removed field Assert.AreEqual(1, theFile.NativeTag.AdditionalFields.Count); Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TES2")); Assert.AreEqual("This is another test", theFile.NativeTag.AdditionalFields["TES2"]); // Get rid of the working copy File.Delete(testFileLocation); }
public void test_RW_Empty(string fileName, bool deleteTempFile = true, bool sameSizeAfterEdit = false, bool sameBitsAfterEdit = false) { ConsoleLogger log = new ConsoleLogger(); // Source : totally metadata-free file string location = TestUtils.GetResourceLocationRoot() + fileName; string testFileLocation = TestUtils.CopyAsTempTestFile(fileName); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check that it is indeed metadata-free Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.getMeta(tagType)); if (canMetaNotExist) { Assert.IsFalse(theFile.getMeta(tagType).Exists); } char internationalChar = supportsInternationalChars ? '父' : '!'; // Construct a new tag TagData theTag = new TagData(); if (testData.Title != null) { theTag.Title = "Test !!"; } if (testData.Album != null) { theTag.Album = "Album"; } if (testData.Artist != null) { theTag.Artist = "Artist"; } if (testData.AlbumArtist != null) { theTag.AlbumArtist = "Mike"; } if (testData.Comment != null) { theTag.Comment = "This is a test"; } if (testData.RecordingYear != null) { theTag.RecordingYear = "2008"; } if (testData.RecordingDate != null) { theTag.RecordingDate = "2008/01/01"; } if (testData.Genre != null) { theTag.Genre = "Merengue"; } if (testData.Rating != null) { theTag.Rating = 2.5.ToString(); } if (testData.TrackNumber != null) { theTag.TrackNumber = "01"; } if (testData.TrackTotal != null) { theTag.TrackTotal = "02"; } if (testData.DiscNumber != null) { theTag.DiscNumber = "03"; } if (testData.DiscTotal != null) { theTag.DiscTotal = "04"; } if (testData.Composer != null) { theTag.Composer = "Me"; } if (testData.Copyright != null) { theTag.Copyright = "a" + internationalChar + "a"; } if (testData.Conductor != null) { theTag.Conductor = "John Johnson Jr."; } if (testData.Publisher != null) { theTag.Publisher = "Z Corp."; } if (testData.GeneralDescription != null) { theTag.GeneralDescription = "Description"; } if (testData.AdditionalFields != null && testData.AdditionalFields.Count > 0) { theTag.AdditionalFields = new List <MetaFieldInfo>(); foreach (MetaFieldInfo info in testData.AdditionalFields) { theTag.AdditionalFields.Add(info); } } // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, tagType)); Assert.IsTrue(theFile.ReadFromFile(false, true)); Assert.IsNotNull(theFile.getMeta(tagType)); IMetaDataIO meta = theFile.getMeta(tagType); Assert.IsTrue(meta.Exists); if (testData.Title != null) { Assert.AreEqual("Test !!", meta.Title); } if (testData.Album != null) { Assert.AreEqual("Album", meta.Album); } if (testData.Artist != null) { Assert.AreEqual("Artist", meta.Artist); } if (testData.AlbumArtist != null) { Assert.AreEqual("Mike", meta.AlbumArtist); } if (testData.Comment != null) { Assert.AreEqual("This is a test", meta.Comment); } if (testData.RecordingDate != null) { DateTime date; Assert.IsTrue(DateTime.TryParse("2008/01/01", out date)); Assert.AreEqual(date, meta.Date); } if (testData.RecordingYear != null) { Assert.AreEqual("2008", meta.Year); } if (testData.Genre != null) { Assert.AreEqual("Merengue", meta.Genre); } if (testData.Rating != null) { Assert.AreEqual((float)(2.5 / 5), meta.Popularity); } if (testData.TrackNumber != null) { Assert.AreEqual(1, meta.Track); } if (testData.TrackTotal != null) { Assert.AreEqual(2, meta.TrackTotal); } if (testData.DiscNumber != null) { Assert.AreEqual(3, meta.Disc); } if (testData.DiscTotal != null) { Assert.AreEqual(4, meta.DiscTotal); } if (testData.Composer != null) { Assert.AreEqual("Me", meta.Composer); } if (testData.Copyright != null) { Assert.AreEqual("a" + internationalChar + "a", meta.Copyright); } if (testData.Conductor != null) { Assert.AreEqual("John Johnson Jr.", meta.Conductor); } if (testData.Publisher != null) { Assert.AreEqual("Z Corp.", meta.Publisher); } if (testData.GeneralDescription != null) { Assert.AreEqual("Description", meta.GeneralDescription); } if (testData.AdditionalFields != null && testData.AdditionalFields.Count > 0) { foreach (MetaFieldInfo info in testData.AdditionalFields) { Assert.IsTrue(meta.AdditionalFields.ContainsKey(info.NativeFieldCode)); Assert.AreEqual(info.Value, meta.AdditionalFields[info.NativeFieldCode]); } } // Remove the tag and check that it has been indeed removed Assert.IsTrue(theFile.RemoveTagFromFile(tagType)); Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.getMeta(tagType)); if (canMetaNotExist) { Assert.IsFalse(theFile.getMeta(tagType).Exists); } // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added) if (sameSizeAfterEdit || sameBitsAfterEdit) { FileInfo originalFileInfo = new FileInfo(location); FileInfo testFileInfo = new FileInfo(testFileLocation); if (sameSizeAfterEdit) { Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); } if (sameBitsAfterEdit) { string originalMD5 = TestUtils.GetFileMD5Hash(location); string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation); Assert.AreEqual(originalMD5, testMD5); } } // Get rid of the working copy if (deleteTempFile) { File.Delete(testFileLocation); } }
public void TagIO_RW_MP4_Chapters_QT_Edit() { new ConsoleLogger(); ATL.Settings.MP4_createNeroChapters = false; try { // Source : MP3 with existing tag incl. chapters String testFileLocation = TestUtils.CopyAsTempTestFile("MP4/chapters_QT.m4v"); AudioDataManager theFile = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check if the two fields are indeed accessible Assert.IsTrue(theFile.ReadFromFile(false, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(4, theFile.NativeTag.Chapters.Count); Dictionary <uint, ChapterInfo> expectedChaps = new Dictionary <uint, ChapterInfo>(); ChapterInfo ch = new ChapterInfo(0, "Chapter One"); expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(1139, "Chapter 2"); expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(2728, "Chapter 003"); expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(3269, "Chapter 四"); expectedChaps.Add(ch.StartTime, ch); int found = 0; foreach (ChapterInfo chap in theFile.NativeTag.Chapters) { if (expectedChaps.ContainsKey(chap.StartTime)) { found++; Assert.AreEqual(chap.StartTime, expectedChaps[chap.StartTime].StartTime); Assert.AreEqual(chap.Title, expectedChaps[chap.StartTime].Title); } else { System.Console.WriteLine(chap.StartTime); } } Assert.AreEqual(4, found); // Modify elements TagData theTag = new TagData(); theTag.Chapters = new List <ChapterInfo>(); expectedChaps.Clear(); ch = new ChapterInfo(0, "aaa"); theTag.Chapters.Add(ch); expectedChaps.Add(ch.StartTime, ch); ch = new ChapterInfo(1230, "aaa0四"); theTag.Chapters.Add(ch); expectedChaps.Add(ch.StartTime, ch); // Check if they are persisted properly Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); Assert.IsTrue(theFile.ReadFromFile(false, true)); Assert.IsNotNull(theFile.NativeTag); Assert.IsTrue(theFile.NativeTag.Exists); Assert.AreEqual(2, theFile.NativeTag.Chapters.Count); // Check if values are the same found = 0; foreach (ChapterInfo chap in theFile.NativeTag.Chapters) { if (expectedChaps.ContainsKey(chap.StartTime)) { found++; Assert.AreEqual(chap.StartTime, expectedChaps[chap.StartTime].StartTime); Assert.AreEqual(chap.Title, expectedChaps[chap.StartTime].Title); } else { System.Console.WriteLine(chap.StartTime); } } Assert.AreEqual(2, found); // Get rid of the working copy if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } finally { ATL.Settings.MP4_createNeroChapters = true; } }
public void test_RW_Unsupported_Empty(string fileName, bool deleteTempFile = true) { ConsoleLogger log = new ConsoleLogger(); // Source : totally metadata-free file string location = TestUtils.GetResourceLocationRoot() + fileName; string testFileLocation = TestUtils.CopyAsTempTestFile(fileName); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check that it is indeed tag-free Assert.IsTrue(theFile.ReadFromFile()); Assert.IsNotNull(theFile.getMeta(tagType)); IMetaDataIO meta = theFile.getMeta(tagType); if (canMetaNotExist) { Assert.IsFalse(meta.Exists); } bool handleUnsupportedFields = (testData.AdditionalFields != null && testData.AdditionalFields.Count > 0); bool handleUnsupportedPictures = (testData.Pictures != null && testData.Pictures.Count > 0); char internationalChar = supportsInternationalChars ? '父' : '!'; // Add new unsupported fields TagData theTag = new TagData(); if (handleUnsupportedFields) { theTag.AdditionalFields.Add(new MetaFieldInfo(tagType, "TEST", "This is a test " + internationalChar)); theTag.AdditionalFields.Add(new MetaFieldInfo(tagType, "TES2", "This is another test " + internationalChar)); } // Add new unsupported pictures PictureInfo picInfo = null; byte found = 0; object pictureCode1, pictureCode2; if (tagType.Equals(MetaDataIOFactory.TAG_APE)) { pictureCode1 = "pic1"; pictureCode2 = "pic2"; } else { pictureCode1 = 23; pictureCode2 = 24; } if (handleUnsupportedPictures) { picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, tagType, pictureCode1); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"); theTag.Pictures.Add(picInfo); picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, tagType, pictureCode2); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic2.jpg"); theTag.Pictures.Add(picInfo); } theFile.UpdateTagInFile(theTag, tagType); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.getMeta(tagType)); meta = theFile.getMeta(tagType); Assert.IsTrue(meta.Exists); if (handleUnsupportedFields) { Assert.AreEqual(2, meta.AdditionalFields.Count); Assert.IsTrue(meta.AdditionalFields.Keys.Contains("TEST")); Assert.AreEqual("This is a test " + internationalChar, meta.AdditionalFields["TEST"]); Assert.IsTrue(meta.AdditionalFields.Keys.Contains("TES2")); Assert.AreEqual("This is another test " + internationalChar, meta.AdditionalFields["TES2"]); } if (handleUnsupportedPictures) { Assert.AreEqual(2, meta.EmbeddedPictures.Count); found = 0; foreach (PictureInfo pic in meta.EmbeddedPictures) { if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && (pic.NativePicCode.Equals(pictureCode1) || (pic.NativePicCodeStr != null && pic.NativePicCodeStr.Equals(pictureCode1))) ) { using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData))) { Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg); Assert.AreEqual(600, picture.Height); Assert.AreEqual(900, picture.Width); } found++; } else if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && (pic.NativePicCode.Equals(pictureCode2) || (pic.NativePicCodeStr != null && pic.NativePicCodeStr.Equals(pictureCode2))) ) { using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData))) { Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg); Assert.AreEqual(290, picture.Height); Assert.AreEqual(900, picture.Width); } found++; } } Assert.AreEqual(2, found); } // Remove the additional unsupported field if (handleUnsupportedFields) { theTag = new TagData(); MetaFieldInfo fieldInfo = new MetaFieldInfo(tagType, "TEST"); fieldInfo.MarkedForDeletion = true; theTag.AdditionalFields.Add(fieldInfo); } // Remove additional picture if (handleUnsupportedPictures) { picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, tagType, pictureCode1); picInfo.MarkedForDeletion = true; theTag.Pictures.Add(picInfo); } // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, tagType)); Assert.IsTrue(theFile.ReadFromFile(true, true)); Assert.IsNotNull(theFile.getMeta(tagType)); meta = theFile.getMeta(tagType); Assert.IsTrue(meta.Exists); if (handleUnsupportedFields) { // Additional removed field Assert.AreEqual(1, meta.AdditionalFields.Count); Assert.IsTrue(meta.AdditionalFields.Keys.Contains("TES2")); Assert.AreEqual("This is another test " + internationalChar, meta.AdditionalFields["TES2"]); } // Pictures if (handleUnsupportedPictures) { Assert.AreEqual(1, meta.EmbeddedPictures.Count); found = 0; foreach (PictureInfo pic in meta.EmbeddedPictures) { if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && (pic.NativePicCode.Equals(pictureCode2) || (pic.NativePicCodeStr != null && pic.NativePicCodeStr.Equals(pictureCode2))) ) { using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData))) { Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg); Assert.AreEqual(290, picture.Height); Assert.AreEqual(900, picture.Width); } found++; } } Assert.AreEqual(1, found); } // Get rid of the working copy if (deleteTempFile) { File.Delete(testFileLocation); } }
public void TagIO_RW_MP4_Existing() { ConsoleLogger log = new ConsoleLogger(); // Source : MP3 with existing tag incl. unsupported picture (Cover Art (Fronk)); unsupported field (MOOD) String testFileLocation = TestUtils.CopyAsTempTestFile(notEmptyFile); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Add a new supported field and a new supported picture Assert.IsTrue(theFile.ReadFromFile()); TagData theTag = new TagData(); theTag.Conductor = "John Jackman"; PictureInfo picInfo = new PictureInfo(Commons.ImageFormat.Png, PictureInfo.PIC_TYPE.Generic, MetaDataIOFactory.TAG_ANY, 14); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.png"); theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); readExistingTagsOnFile(theFile, 2); // Additional supported field Assert.AreEqual("John Jackman", theFile.NativeTag.Conductor); byte nbFound = 0; foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures) { if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Generic) && (1 == nbFound)) { Image picture = Image.FromStream(new MemoryStream(pic.PictureData)); Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Png); Assert.AreEqual(picture.Width, 175); Assert.AreEqual(picture.Height, 168); } nbFound++; } Assert.AreEqual(2, nbFound); // Remove the additional supported field theTag = new TagData(); theTag.Conductor = ""; // Remove additional picture picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, PictureInfo.PIC_TYPE.Back); picInfo.MarkedForDeletion = true; theTag.Pictures.Add(picInfo); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE)); readExistingTagsOnFile(theFile); // Additional removed field Assert.AreEqual("", theFile.NativeTag.Conductor); // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added) /* NOT POSSIBLE YET mainly due to tag order and tag naming (e.g. "gnre" becoming "©gen") differences * FileInfo originalFileInfo = new FileInfo(location); * FileInfo testFileInfo = new FileInfo(testFileLocation); * * Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); * * string originalMD5 = TestUtils.GetFileMD5Hash(location); * string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation); * * Assert.IsTrue(originalMD5.Equals(testMD5)); */ // Get rid of the working copy File.Delete(testFileLocation); }