From 451d23ca37510ba9dc174a8738806d07747fd690 Mon Sep 17 00:00:00 2001 From: Scott Wheeler Date: Mon, 18 May 2015 20:30:19 +0200 Subject: [PATCH] Add isEmpty() to MP4 Closes #457 --- taglib/mp4/mp4tag.cpp | 5 +++++ taglib/mp4/mp4tag.h | 2 ++ tests/test_mp4.cpp | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 1a2fec7c..08e5f411 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -760,6 +760,11 @@ MP4::Tag::setTrack(uint value) d->items["trkn"] = MP4::Item(value, 0); } +bool MP4::Tag::isEmpty() const +{ + return d->items.isEmpty(); +} + MP4::ItemListMap & MP4::Tag::itemListMap() { diff --git a/taglib/mp4/mp4tag.h b/taglib/mp4/mp4tag.h index 48d71fcb..cde68964 100644 --- a/taglib/mp4/mp4tag.h +++ b/taglib/mp4/mp4tag.h @@ -65,6 +65,8 @@ namespace TagLib { void setYear(uint value); void setTrack(uint value); + virtual bool isEmpty() const; + ItemListMap &itemListMap(); PropertyMap properties() const; diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index ac4d4907..9bd2deb7 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -19,6 +19,7 @@ class TestMP4 : public CppUnit::TestFixture CPPUNIT_TEST(testPropertiesALAC); CPPUNIT_TEST(testFreeForm); CPPUNIT_TEST(testCheckValid); + CPPUNIT_TEST(testIsEmpty); CPPUNIT_TEST(testUpdateStco); CPPUNIT_TEST(testSaveExisingWhenIlstIsLast); CPPUNIT_TEST(test64BitAtom); @@ -62,6 +63,18 @@ public: CPPUNIT_ASSERT(f2.isValid()); } + void testIsEmpty() + { + MP4::Tag t1; + CPPUNIT_ASSERT(t1.isEmpty()); + t1.setArtist("Foo"); + CPPUNIT_ASSERT(!t1.isEmpty()); + + MP4::Tag t2; + t2.itemListMap()["foo"] = "bar"; + CPPUNIT_ASSERT(!t2.isEmpty()); + } + void testUpdateStco() { ScopedFileCopy copy("no-tags", ".3g2");