private void audio_X_AAC_MP4_Atom(string atom, string atomCaption = null) { if (null == atomCaption) { atomCaption = atom; } ArrayLogger log = new ArrayLogger(); string resource = "AAC/mp4.m4a"; string location = TestUtils.GetResourceLocationRoot() + resource; string testFileLocation = TestUtils.CopyAsTempTestFile(resource); using (FileStream fs = new FileStream(testFileLocation, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)) { StreamUtils.FindSequence(fs, Utils.Latin1Encoding.GetBytes(atom)); fs.Seek(-1, SeekOrigin.Current); fs.WriteByte(0); Track theTrack = new Track(fs, ".mp4"); IList <LogItem> logItems = log.GetAllItems(Log.LV_ERROR); Assert.AreEqual(1, logItems.Count); Assert.AreEqual(atomCaption + " atom could not be found; aborting read", logItems[0].Message); } // Get rid of the working copy File.Delete(testFileLocation); }
public void Audio_X_APE_invalid() { // Source : APE with invalid header ArrayLogger log = new ArrayLogger(); string location = TestUtils.GetResourceLocationRoot() + "MP3/invalidApeHeader.mp3"; new Track(location); IList <LogItem> logItems = log.GetAllItems(LV_ERROR); Assert.AreEqual(1, logItems.Count); Assert.AreEqual("Invalid value found while reading APEtag frame", logItems[0].Message); }
public void PL_Common() { IPlaylistReader theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u"); Assert.AreEqual(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u", theReader.Path); ArrayLogger log = new ArrayLogger(); try { theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(TestUtils.GetResourceLocationRoot() + "_Playlists/efiufhziuefizeub.m3u"); theReader.GetFiles(); Assert.Fail(); } catch { IList <LogItem> logItems = log.GetAllItems(Log.LV_ERROR); Assert.AreEqual(1, logItems.Count); Assert.IsTrue(logItems[0].Message.Contains("efiufhziuefizeub.m3u")); // Can't do much more than than because the exception message is localized } }
private void audio_X_MP4_Atom(string resourceName, string atom, int logLevel = Log.LV_ERROR, string atomCaption = null) { if (null == atomCaption) { atomCaption = atom; } ArrayLogger log = new ArrayLogger(); string resource = "MP4/" + resourceName; string testFileLocation = TestUtils.CopyAsTempTestFile(resource); using (FileStream fs = new FileStream(testFileLocation, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)) { StreamUtils.FindSequence(fs, Utils.Latin1Encoding.GetBytes(atom)); fs.Seek(-1, SeekOrigin.Current); fs.WriteByte(0); if (StreamUtils.FindSequence(fs, Utils.Latin1Encoding.GetBytes(atom))) { fs.Seek(-1, SeekOrigin.Current); fs.WriteByte(0); } new Track(fs, ".mp4"); IList <LogItem> logItems = log.GetAllItems(logLevel); Assert.IsTrue(logItems.Count > 0); bool found = false; foreach (LogItem l in logItems) { if (l.Message.Contains(atomCaption + " atom could not be found")) { found = true; } } Assert.IsTrue(found); } // Get rid of the working copy if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } }
public void TagIO_RW_ID3v24_Extended() { ArrayLogger logger = new ArrayLogger(); // Source : MP3 with extended tag properties (tag restrictions) string testFileLocation = TestUtils.GetTempTestFile("MP3/id3v2.4_UTF8_extendedTag.mp3"); AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation)); // Check that the presence of an extended tag does not disrupt field reading readExistingTagsOnFile(theFile); Settings.ID3v2_useExtendedHeaderRestrictions = true; try { // Insert a very long field while tag restrictions specify that string shouldn't be longer than 30 characters TagData theTag = new TagData(); theTag.Conductor = "Veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery long field"; // Insert a large picture while tag restrictions specify that pictures shouldn't be larger than 64x64pixels AND tag size shouldn't be larger than 4 KB PictureInfo picInfo = new PictureInfo(Commons.ImageFormat.Jpeg, PictureInfo.PIC_TYPE.Back); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"); theTag.Pictures.Add(picInfo); // Insert a gif picture while tag restrictions specify that pictures should be either jpeg or png picInfo = new PictureInfo(Commons.ImageFormat.Gif, PictureInfo.PIC_TYPE.Back); picInfo.PictureData = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.gif"); theTag.Pictures.Add(picInfo); // Insert 20 garbage fields to raise the number of field above maximum required fields (30) theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA01", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA02", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA03", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA04", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA05", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA06", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA07", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA08", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA09", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA10", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA11", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA12", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA13", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA14", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA15", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA16", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA17", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA18", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA19", "aaa")); theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA20", "aaa")); // Add the new tag and check that it has been indeed added with all the correct information Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_ID3V2)); // Get rid of the working copy File.Delete(testFileLocation); } finally { Settings.ID3v2_useExtendedHeaderRestrictions = false; } bool isAlertFieldLength = false; bool isAlertTagSize = false; bool isAlertNbFrames = false; bool isAlertPicDimension = false; bool isAlertPicType = false; foreach (Logging.Log.LogItem logItem in logger.Items) { if (logItem.Message.Contains("is longer than authorized")) { isAlertFieldLength = true; } if (logItem.Message.StartsWith("Tag is too large")) { isAlertTagSize = true; } if (logItem.Message.StartsWith("Tag has too many frames")) { isAlertNbFrames = true; } if (logItem.Message.EndsWith("does not respect ID3v2 restrictions (exactly 64x64)")) { isAlertPicDimension = true; } if (logItem.Message.EndsWith("does not respect ID3v2 restrictions (jpeg or png required)")) { isAlertPicType = true; } } Assert.IsTrue(isAlertFieldLength); Assert.IsTrue(isAlertTagSize); Assert.IsTrue(isAlertNbFrames); Assert.IsTrue(isAlertPicDimension); Assert.IsTrue(isAlertPicType); }
private void tagIO_RW_UpdatePadding(string resource, int paddingSize = 2048) { ATL.Settings.PaddingSize = paddingSize; try { ArrayLogger log = new ArrayLogger(); string location = TestUtils.GetResourceLocationRoot() + resource; string testFileLocation = TestUtils.CopyAsTempTestFile(resource); Track theTrack = new Track(testFileLocation); string originalTitle = theTrack.Title; // Test the use of padding without padding option on // A1- Check that the resulting file (working copy that has been processed) keeps the same quantity of bytes when adding data theTrack.Title = originalTitle + "1234567890"; theTrack.Save(); // A11- File length should be the same FileInfo originalFileInfo = new FileInfo(location); FileInfo testFileInfo = new FileInfo(testFileLocation); Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); // A12- No stream manipulation should have occurred IList <LogItem> logItems = log.GetAllItems(LV_DEBUG); foreach (LogItem item in logItems) { if (item.Message.StartsWith("Disk stream operation : ")) { Assert.Fail(item.Message); } } // A2- Check that the resulting file (working copy that has been processed) keeps the same quantity of bytes when removing data theTrack.Title = originalTitle; theTrack.Save(); // A21- File length should be the same originalFileInfo = new FileInfo(location); testFileInfo = new FileInfo(testFileLocation); Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length); // A22- No stream manipulation should have occurred logItems = log.GetAllItems(LV_DEBUG); foreach (LogItem item in logItems) { if (item.Message.StartsWith("Disk stream operation : ")) { Assert.Fail(item.Message); } } // Get rid of the working copy if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } finally { ATL.Settings.PaddingSize = 2048; } }