public void ValidationOKTest()
        {
            /*
             *  T___
             *  TXXX
             *  WXXX
             *  APIC
             */

            var tagContainer = new TagContainerV3();
            tagContainer.Tag.SetExtendedHeader(0, false);
            tagContainer.Tag.SetHeaderOptions(false, false, false);

            var textFrame = new TextFrame("TALB", "My Albun", Encoding.Default);
            var userDefineTextFrame = new UserDefinedTextFrame("my comment", "so", Encoding.Default);
            var linkFrame = new UserDefinedUrlLinkFrame("Id3Tag", "Id3Tag.codeplex.com", Encoding.Default);
            var pictureFrame = new PictureFrame(
                Encoding.Default,
                "image/jpeg",
                "la",
                PictureType.Other,
                new byte[] {0x11, 0x12, 0x13, 0x14});

            tagContainer.Add(textFrame);
            tagContainer.Add(userDefineTextFrame);
            tagContainer.Add(linkFrame);
            tagContainer.Add(pictureFrame);

            WriteTagContainer(tagContainer);

            // OK... passed!
        }
        public void ExtendedHeaderEncoderTest()
        {
            var crc = new byte[] {0x20, 0x21, 0x22, 0x23};

            var tagContainer = new TagContainerV3();
            tagContainer.Tag.SetHeaderOptions(true, true, true);
            tagContainer.Tag.SetExtendedHeader(10, true);
            tagContainer.Tag.SetCrc32(crc);

            var titleFrame = new TextFrame();
            titleFrame.TextEncoding = Encoding.Unicode;
            titleFrame.Descriptor.Id = "TIT2";
            titleFrame.Content = "ABCD";

            tagContainer.Add(titleFrame);

            Id3TagInfo Id3Tag = m_TagController.Encode(tagContainer);

            Assert.AreEqual(Id3Tag.MajorVersion, 3);
            Assert.AreEqual(Id3Tag.Revision, 0);
            Assert.IsTrue(Id3Tag.Unsynchronised);
            Assert.IsTrue(Id3Tag.Unsynchronised);
            Assert.IsTrue(Id3Tag.ExtendedHeaderAvailable);

            ExtendedTagHeaderV3 extendedHeader = Id3Tag.ExtendedHeader.ConvertToV23();
            Assert.IsNotNull(extendedHeader);
            Assert.IsTrue(ComparePayload(extendedHeader.Crc32, crc));
            Assert.AreEqual(Id3Tag.Frames.Count, 1);
        }
        public void ConstructorTest()
        {
            var textFrame = new TextFrame("TALB", "ABCD", Encoding.Unicode);

            Assert.AreEqual(textFrame.Descriptor.Id, "TALB");
            Assert.AreEqual(textFrame.Content, "ABCD");
            Assert.AreEqual(textFrame.TextEncoding, Encoding.Unicode);
        }
        public void ConverterISO88591_Test()
        {
            var textFrame = new TextFrame
                                {
                                    TextEncoding = Encoding.Default,
                                    Content = "ABCD",
                                    Descriptor = {Id = "TALB"}
                                };

            RawFrame rawFrame = textFrame.Convert(TagVersion.Id3V23);

            Assert.AreEqual(rawFrame.Id, "TALB");
            Assert.AreEqual(rawFrame.Payload[0], 0); // ISO_8859 coding
            Assert.AreEqual(rawFrame.Payload.Count, 5);
        }
        public void ConverterUTF16_Test()
        {
            var textFrame = new TextFrame
                                {
                                    TextEncoding = Encoding.Unicode,
                                    Content = "ABCD",
                                    Descriptor = {Id = "TALB"}
                                };

            RawFrame rawFrame = textFrame.Convert(TagVersion.Id3V23);

            Assert.AreEqual(rawFrame.Id, "TALB");
            Assert.AreEqual(rawFrame.Payload[0], 1); // UTF 16
            Assert.AreEqual(rawFrame.Payload[1], 0xFF); // BOM 1
            Assert.AreEqual(rawFrame.Payload[2], 0xFE); // BOM 2
            Assert.AreEqual(rawFrame.Payload.Count, 11);
        }
        public void ConverterUTF16BE_Test()
        {
            var textFrame = new TextFrame
                                {
                                    TextEncoding = new UnicodeEncoding(true, false),
                                    Content = "ABCD",
                                    Descriptor = {Id = "TALB"}
                                };

            RawFrame rawFrame = textFrame.Convert(TagVersion.Id3V23);

            Assert.AreEqual(rawFrame.Id, "TALB");

            var refBytes = new byte[]
                               {
                                   0x02, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, 0x44
                               };

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
        private byte[] GetContent()
        {
            // Creating valid tag frame first.
            TagContainer tagContainer = Id3TagFactory.CreateId3Tag(TagVersion.Id3V23);
            var textFrame = new TextFrame("TIT2", "My Title", Encoding.ASCII);
            tagContainer.Add(textFrame);

            // OK... Create a valid output stream
            Stream output = null;
            Stream audio = null;
            byte[] content = null;
            try
            {
                output = new MemoryStream(new byte[64000], true);
                audio = new MemoryStream(m_AudioData);

                m_Controller.Write(tagContainer, audio, output);

                output.Position = 0;
                using (var reader = new BinaryReader(output))
                {
                    long size = output.Length;
                    content = reader.ReadBytes(Convert.ToInt32(size));
                }
            }
            finally
            {
                if (audio != null)
                {
                    audio.Close();
                }

                if (output != null)
                {
                    output.Close();
                }
            }

            return content;
        }
        public void SimpleEncoderTest()
        {
            var tagContainer = new TagContainerV3();
            tagContainer.Tag.SetHeaderOptions(false, false, false);

            var titleFrame = new TextFrame();
            titleFrame.TextEncoding = Encoding.Unicode;
            titleFrame.Descriptor.Id = "TIT2";
            titleFrame.Content = "ABCD";

            tagContainer.Add(titleFrame);

            Id3TagInfo Id3Tag = m_TagController.Encode(tagContainer);

            Assert.AreEqual(Id3Tag.MajorVersion, 3);
            Assert.AreEqual(Id3Tag.Revision, 0);
            Assert.IsFalse(Id3Tag.Unsynchronised);
            Assert.IsFalse(Id3Tag.Unsynchronised);
            Assert.IsFalse(Id3Tag.ExtendedHeaderAvailable);
            Assert.IsNull(Id3Tag.ExtendedHeader);
            Assert.AreEqual(Id3Tag.Frames.Count, 1);
        }
        public TagContainer BuildTag(ID3V2TagData data)
        {
            TagContainer container = Id3TagFactory.CreateId3Tag(data.Version);
            if (data.Version == TagVersion.Id3V23)
            {
                //
                //  Configure the ID3v2.3 header
                //
                TagDescriptorV3 extendedHeaderV23 = container.GetId3V23Descriptor();
                // Configure the tag header.
                extendedHeaderV23.SetHeaderOptions(data.Unsynchronisation, data.ExtendedHeader,
                                                   data.ExperimentalIndicator);

                if (data.ExtendedHeader)
                {
                    extendedHeaderV23.SetExtendedHeader(data.PaddingSize, data.CrCPresent);
                    extendedHeaderV23.SetCrc32(data.Crc);
                }
            }
            else
            {
                //
                //  Configure the ID3v2.4 header
                //
                TagDescriptorV4 extendedHeaderV24 = container.GetId3V24Descriptor();
                extendedHeaderV24.SetHeaderOptions(false, false, false, true);
            }

            // OK. Build the frames.
            var albumFrame = new TextFrame("TALB", data.Album, data.TextEncoding);
            var artistFrame = new TextFrame("TPE2", data.Artist, data.TextEncoding);
            var yearFrame = new TextFrame("TYER", data.Year, data.TextEncoding);
            var titleFrame = new TextFrame("TIT2", data.Title, data.TextEncoding);
            var textComment = new UserDefinedTextFrame("Your comment", data.Comment, data.TextEncoding);
            var comment = new CommentFrame("ENG", "Your Comment", data.Comment, data.TextEncoding);
            var encoder = new TextFrame("TENC", data.Encoder, data.TextEncoding);

            container.Add(albumFrame);
            container.Add(artistFrame);
            container.Add(yearFrame);
            container.Add(titleFrame);
            container.Add(textComment);
            container.Add(comment);
            container.Add(encoder);

            if (data.PictureFrameEnabled)
            {
                if (File.Exists(data.PictureFile))
                {
                    WritePictureFrame(data, container);
                }
                else
                {
                    MessageBox.Show("Picture file not found.");
                }
            }

            if (data.WriteLyricsFlag)
            {
                WriteUnsychronisedLyrics(data.LyricsDescriptor, data.Lyrics, container);
            }

            return container;
        }
Exemple #10
0
        public void EncodeWithExtendedHeaderTest2()
        {
            //
            // Configure the tag
            //
            var tagContainer1 = new TagContainerV3();
            tagContainer1.Tag.SetHeaderOptions(true, true, true);
            tagContainer1.Tag.SetExtendedHeader(10, true);
            tagContainer1.Tag.SetCrc32(new byte[] {0x10, 0x20, 0x30, 0x40});

            var titleFrame = new TextFrame
                                 {
                                     Descriptor = {Id = "TIT2"},
                                     TextEncoding = Encoding.Unicode,
                                     Content = "Title1"
                                 };

            tagContainer1.Add(titleFrame);

            //
            // Write and read the tag again. 
            //
            TagContainer tagContainer2 = WriteAndRead(tagContainer1);

            //
            // Compare both container!
            //
            CompareContainer(tagContainer1, tagContainer2);
        }
Exemple #11
0
        public void EncodeWithoutExtendedHeaderTest()
        {
            //
            // Configure the tag
            //
            var tagContainer1 = new TagContainerV3();
            tagContainer1.Tag.SetHeaderOptions(false, false, false);

            var titleFrame = new TextFrame
                                 {
                                     Descriptor = {Id = "TIT2"},
                                     TextEncoding = Encoding.Unicode,
                                     Content = "Title1"
                                 };

            tagContainer1.Add(titleFrame);

            //
            // Write and read the tag again. 
            //
            TagContainer tagContainer2 = WriteAndRead(tagContainer1);

            //
            // Compare both container!
            //
            CompareContainer(tagContainer1, tagContainer2);
        }