Exemple #1
0
 private void TagTestWithSave(ref Ogg.XiphComment tag,
                              TagTestFunc testFunc)
 {
     testFunc(tag, "Before Save");
     tag = new Ogg.XiphComment(tag.Render(true));
     testFunc(tag, "After Save");
 }
Exemple #2
0
		public void TestAlbumArtists ()
		{
			Ogg.XiphComment tag = new Ogg.XiphComment ();
			
			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
				Assert.AreEqual (0, t.AlbumArtists.Length, "Initial (Zero): " + m);
			});
			
			tag.AlbumArtists = val_mult;
			
			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
				Assert.AreEqual (val_mult.Length, t.AlbumArtists.Length, "Value Set: " + m);
				for (int i = 0; i < val_mult.Length; i ++) {
					Assert.AreEqual (val_mult [i], t.AlbumArtists [i], "Value Set: " + m);
				}
			});
			
			tag.AlbumArtists = new string [0];
			
			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
				Assert.AreEqual (0, t.AlbumArtists.Length, "Value Cleared (Zero): " + m);
			});
		}
Exemple #3
0
        public void TestComposers()
        {
            Ogg.XiphComment tag = new Ogg.XiphComment();

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual(0, t.Composers.Length, "Initial (Zero): " + m);
            });

            tag.Composers = val_mult;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(val_mult.Length, t.Composers.Length, "Value Set: " + m);
                for (int i = 0; i < val_mult.Length; i++)
                {
                    Assert.AreEqual(val_mult [i], t.Composers [i], "Value Set: " + m);
                }
            });

            tag.Composers = new string [0];

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual(0, t.Composers.Length, "Value Cleared (Zero): " + m);
            });
        }
Exemple #4
0
        /// <summary>
        ///    Gets the first Xiph comment stored in the current
        ///    instance, optionally creating one if necessary.
        /// </summary>
        /// <param name="create">
        ///    A <see cref="bool" /> value indicating whether or not a
        ///    comment should be added if one cannot be found.
        /// </param>
        /// <param name="copy">
        ///    A <see cref="Tag" /> object containing the source tag to
        ///    copy the values from, or <see langword="null" /> to not
        ///    copy values.
        /// </param>
        /// <returns>
        ///    A <see cref="Ogg.XiphComment" /> object containing the
        ///    tag that was found in or added to the current instance.
        ///    If no matching tag was found and none was created, <see
        ///    langword="null" /> is returned.
        /// </returns>
        public Ogg.XiphComment GetComment(bool create, Tag copy)
        {
            foreach (Tag t in Tags)
            {
                if (t is Ogg.XiphComment)
                {
                    return(t as Ogg.XiphComment);
                }
            }

            if (!create)
            {
                return(null);
            }

            Ogg.XiphComment c = new Ogg.XiphComment();

            if (copy != null)
            {
                copy.CopyTo(c, true);
            }

            AddTag(c);

            return(c);
        }
Exemple #5
0
        public void TestClear()
        {
            Ogg.XiphComment tag = new Ogg.XiphComment();

            tag.Title          = "A";
            tag.Performers     = new string [] { "B" };
            tag.AlbumArtists   = new string [] { "C" };
            tag.Composers      = new string [] { "D" };
            tag.Album          = "E";
            tag.Comment        = "F";
            tag.Genres         = new string [] { "Blues" };
            tag.Year           = 123;
            tag.Track          = 234;
            tag.TrackCount     = 234;
            tag.Disc           = 234;
            tag.DiscCount      = 234;
            tag.Lyrics         = "G";
            tag.Grouping       = "H";
            tag.BeatsPerMinute = 234;
            tag.Conductor      = "I";
            tag.Copyright      = "J";
            tag.Pictures       = new Picture [] { new Picture(TestPath.Covers + "sample_a.png") };
            tag.InitialKey     = "K";
            tag.Publisher      = "L";
            tag.ISRC           = "M";
            tag.RemixedBy      = "N";

            Assert.IsFalse(tag.IsEmpty, "Should be full.");
            tag.Clear();

            Assert.IsNull(tag.Title, "Title");
            Assert.AreEqual(0, tag.Performers.Length, "Performers");
            Assert.AreEqual(0, tag.AlbumArtists.Length, "AlbumArtists");
            Assert.AreEqual(0, tag.Composers.Length, "Composers");
            Assert.IsNull(tag.Album, "Album");
            Assert.IsNull(tag.Comment, "Comment");
            Assert.AreEqual(0, tag.Genres.Length, "Genres");
            Assert.AreEqual(0, tag.Year, "Year");
            Assert.AreEqual(0, tag.Track, "Track");
            Assert.AreEqual(0, tag.TrackCount, "TrackCount");
            Assert.AreEqual(0, tag.Disc, "Disc");
            Assert.AreEqual(0, tag.DiscCount, "DiscCount");
            Assert.IsNull(tag.Lyrics, "Lyrics");
            Assert.IsNull(tag.Comment, "Comment");
            Assert.AreEqual(0, tag.BeatsPerMinute, "BeatsPerMinute");
            Assert.IsNull(tag.Conductor, "Conductor");
            Assert.IsNull(tag.Copyright, "Copyright");
            Assert.AreEqual(0, tag.Pictures.Length, "Pictures");
            Assert.IsTrue(tag.IsEmpty, "Should be empty.");
            Assert.IsNull(tag.InitialKey, "InitialKey");
            Assert.IsNull(tag.Publisher, "Publisher");
            Assert.IsNull(tag.ISRC, "ISRC");
            Assert.IsNull(tag.RemixedBy, "RemixedBy");
        }
Exemple #6
0
        public void TestPictures()
        {
            Ogg.XiphComment tag = new Ogg.XiphComment();

            Picture [] pictures = new Picture [] {
                new Picture("samples/covers/sample_a.png"),
                new Picture("samples/covers/sample_a.jpg"),
                new Picture("samples/covers/sample_b.png"),
                new Picture("samples/covers/sample_b.jpg"),
                new Picture("samples/covers/sample_c.png"),
                new Picture("samples/covers/sample_c.jpg")
            };

            for (int i = 0; i < 6; i++)
            {
                pictures [i].Type = (PictureType)(i * 2);
            }

            pictures [3].Description = val_sing;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual(0, t.Pictures.Length, "Initial (Zero): " + m);
            });

            tag.Pictures = pictures;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(!t.IsEmpty, "Value Set (IsEmpty): " + m);
            });

            tag.Pictures = new Picture [0];

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual(0, t.Pictures.Length, "Value Cleared (Zero): " + m);
            });
        }
Exemple #7
0
        public void TestAlbum()
        {
            Ogg.XiphComment tag = new Ogg.XiphComment ();

            TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
                Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.IsNull (t.Album, "Initial (Null): " + m);
            });

            tag.Album = val_sing;

            TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
                Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual (val_sing, t.Album, "Value Set (!Null): " + m);
            });

            tag.Album = string.Empty;

            TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
                Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.IsNull (t.Album, "Value Cleared (Null): " + m);
            });
        }
Exemple #8
0
        public void TestIsCompilation()
        {
            var tag = new Ogg.XiphComment();

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.IsFalse(t.IsCompilation, "Initial (False): " + m);
            });

            tag.IsCompilation = true;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.IsTrue(t.IsCompilation, "Value Set (True): " + m);
            });

            tag.IsCompilation = false;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.IsFalse(t.IsCompilation, "Value Cleared (False): " + m);
            });
        }
Exemple #9
0
        public void TestMusicBrainzReleaseCountry()
        {
            Ogg.XiphComment tag = new Ogg.XiphComment();

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.IsNull(t.MusicBrainzReleaseCountry, "Initial (Null): " + m);
            });

            tag.MusicBrainzReleaseCountry = val_sing;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(val_sing, t.MusicBrainzReleaseCountry, "Value Set (!Null): " + m);
            });

            tag.MusicBrainzReleaseCountry = string.Empty;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.IsNull(t.MusicBrainzReleaseCountry, "Value Cleared (Null): " + m);
            });
        }
Exemple #10
0
        public void TestAmazonID()
        {
            Ogg.XiphComment tag = new Ogg.XiphComment();

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.IsNull(t.AmazonId, "Initial (Null): " + m);
            });

            tag.AmazonId = val_sing;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(val_sing, t.AmazonId, "Value Set (!Null): " + m);
            });

            tag.AmazonId = string.Empty;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.IsNull(t.AmazonId, "Value Cleared (Null): " + m);
            });
        }
Exemple #11
0
        public void TestBeatsPerMinute()
        {
            Ogg.XiphComment tag = new Ogg.XiphComment();

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual(0, tag.BeatsPerMinute, "Initial (Zero): " + m);
            });

            tag.BeatsPerMinute = 199;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(199, tag.BeatsPerMinute, "Value Set: " + m);
            });

            tag.BeatsPerMinute = 0;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual(0, t.BeatsPerMinute, "Value Cleared (Zero): " + m);
            });
        }
Exemple #12
0
        /// <summary>
        ///    Gets the first Xiph comment stored in the current
        ///    instance, optionally creating one if necessary.
        /// </summary>
        /// <param name="create">
        ///    A <see cref="bool" /> value indicating whether or not a
        ///    comment should be added if one cannot be found.
        /// </param>
        /// <param name="copy">
        ///    A <see cref="Tag" /> object containing the source tag to
        ///    copy the values from, or <see langword="null" /> to not
        ///    copy values.
        /// </param>
        /// <returns>
        ///    A <see cref="Ogg.XiphComment" /> object containing the
        ///    tag that was found in or added to the current instance.
        ///    If no matching tag was found and none was created, <see
        ///    langword="null" /> is returned.
        /// </returns>
        public Ogg.XiphComment GetComment(bool create, Tag copy)
        {
            foreach (Tag t in Tags)
                if (t is Ogg.XiphComment)
                    return t as Ogg.XiphComment;

            if (!create)
                return null;

            Ogg.XiphComment c = new Ogg.XiphComment ();

            if (copy != null)
                copy.CopyTo (c, true);

            AddTag (c);

            return c;
        }
Exemple #13
0
		public void TestBeatsPerMinute ()
		{
			Ogg.XiphComment tag = new Ogg.XiphComment ();
		
			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
				Assert.AreEqual (0, tag.BeatsPerMinute, "Initial (Zero): " + m);
			});
			
			tag.BeatsPerMinute = 199;
			
			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
				Assert.AreEqual (199, tag.BeatsPerMinute, "Value Set: " + m);
			});
			
			tag.BeatsPerMinute = 0;

			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
				Assert.AreEqual (0, t.BeatsPerMinute, "Value Cleared (Zero): " + m);
			});
		}
Exemple #14
0
        public void TestPictures()
        {
            Ogg.XiphComment tag = new Ogg.XiphComment();

            Picture [] pictures = new Picture [] {
                new Picture(TestPath.Covers + "sample_a.png"),
                new Picture(TestPath.Covers + "sample_a.jpg"),
                new Picture(TestPath.Covers + "sample_b.png"),
                new Picture(TestPath.Covers + "sample_b.jpg"),
                new Picture(TestPath.Covers + "sample_c.png"),
                new Picture(TestPath.Covers + "sample_c.jpg")
            };

            for (int i = 0; i < 6; i++)
            {
                pictures [i].Type = (PictureType)(i * 2);
            }

            pictures [3].Description = val_sing;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual(0, t.Pictures.Length, "Initial (Zero): " + m);
            });

            tag.Pictures = pictures;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(!t.IsEmpty, "Value Set (IsEmpty): " + m);
            });

            tag.Pictures = new Picture [0];

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual(0, t.Pictures.Length, "Value Cleared (Zero): " + m);
            });

            // Test that COVERART fields are parsed in Pictures property
            string[] pictureStrings = new string[pictures.Length];
            for (int i = 0; i < 6; ++i)
            {
                pictureStrings[i] = Convert.ToBase64String(pictures[i].Data.Data);
            }
            tag.SetField("COVERART", pictureStrings);

            var parsedPictures = tag.Pictures;

            Assert.IsTrue(!tag.IsEmpty, "Legacy Value Set (IsEmpty)");
            Assert.AreEqual(6, parsedPictures.Length, "Legacy Value Set (Length)");

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                // COVERART should be preserved
                Assert.AreEqual(6, t.GetField("COVERART").Length, "Legacy Field Set (Length): " + m);
            });

            // Setting the pictures array should replace COVERART with METADATA_BLOCK_PICTURE
            tag.Pictures = pictures;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.AreEqual(0, t.GetField("COVERART").Length, "Legacy Field Set (Length): " + m);
                Assert.AreEqual(6, t.GetField("METADATA_BLOCK_PICTURE").Length, "Current Field Set (Length): " + m);
            });

            // The user should be able to clear the pictures array
            tag.Pictures = null;

            TagTestWithSave(ref tag, delegate(Ogg.XiphComment t, string m) {
                Assert.AreEqual(0, t.Pictures.Length, "Pictures Length (null): " + m);
            });
        }
Exemple #15
0
		private void TagTestWithSave (ref Ogg.XiphComment tag,
		                              TagTestFunc testFunc)
		{
			testFunc (tag, "Before Save");
			tag = new Ogg.XiphComment (tag.Render (true));
			testFunc (tag, "After Save");
		}
Exemple #16
0
		public void TestClear ()
		{
			Ogg.XiphComment tag = new Ogg.XiphComment ();
			
			tag.Title = "A";
			tag.Performers = new string [] {"B"};
			tag.AlbumArtists = new string [] {"C"};
			tag.Composers = new string [] {"D"};
			tag.Album = "E";
			tag.Comment = "F";
			tag.Genres = new string [] {"Blues"};
			tag.Year = 123;
			tag.Track = 234;
			tag.TrackCount = 234;
			tag.Disc = 234;
			tag.DiscCount = 234;
			tag.Lyrics = "G";
			tag.Grouping = "H";
			tag.BeatsPerMinute = 234;
			tag.Conductor = "I";
			tag.Copyright = "J";
			tag.Pictures = new Picture [] {new Picture ("../examples/covers/sample_a.png")};
			
			Assert.IsFalse (tag.IsEmpty, "Should be full.");
			tag.Clear ();
			
			Assert.IsNull (tag.Title, "Title");
			Assert.AreEqual (0, tag.Performers.Length, "Performers");
			Assert.AreEqual (0, tag.AlbumArtists.Length, "AlbumArtists");
			Assert.AreEqual (0, tag.Composers.Length, "Composers");
			Assert.IsNull (tag.Album, "Album");
			Assert.IsNull (tag.Comment, "Comment");
			Assert.AreEqual (0, tag.Genres.Length, "Genres");
			Assert.AreEqual (0, tag.Year, "Year");
			Assert.AreEqual (0, tag.Track, "Track");
			Assert.AreEqual (0, tag.TrackCount, "TrackCount");
			Assert.AreEqual (0, tag.Disc, "Disc");
			Assert.AreEqual (0, tag.DiscCount, "DiscCount");
			Assert.IsNull (tag.Lyrics, "Lyrics");
			Assert.IsNull (tag.Comment, "Comment");
			Assert.AreEqual (0, tag.BeatsPerMinute, "BeatsPerMinute");
			Assert.IsNull (tag.Conductor, "Conductor");
			Assert.IsNull (tag.Copyright, "Copyright");
			Assert.AreEqual (0, tag.Pictures.Length, "Pictures");
			Assert.IsTrue (tag.IsEmpty, "Should be empty.");
		}
Exemple #17
0
		public void TestIsCompilation ()
		{
			var tag = new Ogg.XiphComment ();

			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
				Assert.IsFalse (t.IsCompilation, "Initial (False): " + m);
			});

			tag.IsCompilation = true;

			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
				Assert.IsTrue (t.IsCompilation, "Value Set (True): " + m);
			});

			tag.IsCompilation = false;

			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
				Assert.IsFalse (t.IsCompilation, "Value Cleared (False): " + m);
			});
		}
Exemple #18
0
		public void TestPictures ()
		{
			Ogg.XiphComment tag = new Ogg.XiphComment ();
			
			Picture [] pictures = new Picture [] {
				new Picture ("../examples/covers/sample_a.png"),
				new Picture ("../examples/covers/sample_a.jpg"),
				new Picture ("../examples/covers/sample_b.png"),
				new Picture ("../examples/covers/sample_b.jpg"),
				new Picture ("../examples/covers/sample_c.png"),
				new Picture ("../examples/covers/sample_c.jpg")
			};
			
			for (int i = 0; i < 6; i ++)
				pictures [i].Type = (PictureType) (i * 2);
			
			pictures [3].Description = val_sing;
			
			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
				Assert.AreEqual (0, t.Pictures.Length, "Initial (Zero): " + m);
			});
			
			tag.Pictures = pictures;
			
			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (!t.IsEmpty, "Value Set (IsEmpty): " + m);
			});
			
			tag.Pictures = new Picture [0];
			
			TagTestWithSave (ref tag, delegate (Ogg.XiphComment t, string m) {
				Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
				Assert.AreEqual (0, t.Pictures.Length, "Value Cleared (Zero): " + m);
			});
		}