]> granicus.if.org Git - taglib/commitdiff
Added tests and information about ignored id3 frames.
authorMichael Helmling <helmling@mathematik.uni-kl.de>
Sun, 1 Jan 2012 13:42:48 +0000 (14:42 +0100)
committerMichael Helmling <helmling@mathematik.uni-kl.de>
Sun, 1 Jan 2012 13:42:48 +0000 (14:42 +0100)
The ID3v2::toDict() function now has an optional
StringList* argument which will contain information
about frames that could not be converted to the dict
interface.
There are some dict tests for APE and FLAC now, and the
ID3v2 test was enlarged.

taglib/ape/apetag.cpp
taglib/mpeg/id3v2/id3v2tag.cpp
taglib/mpeg/id3v2/id3v2tag.h
tests/test_apetag.cpp
tests/test_flac.cpp
tests/test_id3v2.cpp

index 1f3f84a26a57b40979c0e1d2e9f1c955d827a97a..92d106c44dd2ab0192e31ad043f687981925a62a 100644 (file)
@@ -197,6 +197,7 @@ void APE::Tag::fromDict(const TagDict &orig_dict)
 {
   TagDict dict(orig_dict); // make a local copy that can be modified
 
+  // see comment in toDict() about TRACKNUMBER and YEAR
   if (dict.contains("TRACKNUMBER")) {
     dict.insert("TRACK", dict["TRACKNUMBER"]);
     dict.erase("TRACKNUMBER");
index 9c5e50f41b9fa643e5d50061c5d1b236cb94ace8..dd3e97a7737a9236367732386d63d0b6b646d356 100644 (file)
@@ -334,18 +334,22 @@ void ID3v2::Tag::removeFrames(const ByteVector &id)
     removeFrame(*it, true);
 }
 
-TagDict ID3v2::Tag::toDict() const
+TagDict ID3v2::Tag::toDict(StringList *ignoreInfo) const
 {
   TagDict dict;
   FrameList::ConstIterator frameIt = frameList().begin();
   for (; frameIt != frameList().end(); ++frameIt) {
     ByteVector id = (*frameIt)->frameID();
 
-    if (ignored(id))
+    if (ignored(id)) {
       debug("toDict() found ignored id3 frame: " + id);
-    else if (deprecated(id))
+      if (ignoreInfo)
+       ignoreInfo->append(String(id) + " frame is not supported");
+    } else if (deprecated(id)) {
       debug("toDict() found deprecated id3 frame: " + id);
-    else {
+      if (ignoreInfo)
+        ignoreInfo->append(String(id) + " frame is deprecated");
+    } else {
         // in the future, something like dict[frame->tagName()].append(frame->values())
         // might replace the following lines.
         KeyValuePair kvp = parseFrame(*frameIt);
index 3f731282a7a6a0ee83ee8df13d159ddc138258ef..33d9a33cc1780880d952c28e21dc0724682a8b63 100644 (file)
@@ -264,8 +264,13 @@ namespace TagLib {
        * Implements the unified tag dictionary interface -- export function.
        * This function does some work to translate the hard-specified ID3v2
        * frame types into a free-form string-to-stringlist dictionary.
+       *
+       * If the optional pointer to a StringList is given, that list will
+       * be filled with a descriptive text for each ID3v2 frame that could
+       * not be incorporated into the dict interface (binary data, unsupported
+       * frames, ...).
        */
-      TagDict toDict() const;
+      TagDict toDict(StringList *ignoredInfo = 0) const;
 
       /*!
        * Implements the unified tag dictionary interface -- import function.
index 901a2aafae09b8bfe7c674d9195c83f17dd7fdfd..fc38907f8b4e001e5d27cf201b455f925f7cffb5 100644 (file)
@@ -15,6 +15,7 @@ class TestAPETag : public CppUnit::TestFixture
   CPPUNIT_TEST_SUITE(TestAPETag);
   CPPUNIT_TEST(testIsEmpty);
   CPPUNIT_TEST(testIsEmpty2);
+  CPPUNIT_TEST(testDict);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -35,6 +36,21 @@ public:
     CPPUNIT_ASSERT(!tag.isEmpty());
   }
 
+  void testDict()
+  {
+         APE::Tag tag;
+         TagDict dict = tag.toDict();
+         CPPUNIT_ASSERT(dict.isEmpty());
+         dict["ARTIST"] = String("artist 1");
+         dict["ARTIST"].append("artist 2");
+         dict["TRACKNUMBER"].append("17");
+         tag.fromDict(dict);
+         CPPUNIT_ASSERT_EQUAL(String("17"), tag.itemListMap()["TRACK"].values()[0]);
+         CPPUNIT_ASSERT_EQUAL(2u, tag.itemListMap()["ARTIST"].values().size());
+         CPPUNIT_ASSERT_EQUAL(String("artist 1"), tag.artist());
+         CPPUNIT_ASSERT_EQUAL(17u, tag.track());
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestAPETag);
index 90baa844989527a2f1d761032ff804e202e918d2..f9a0afa479998491c8de3595c1f9ca3d03970f9c 100644 (file)
@@ -22,6 +22,7 @@ class TestFLAC : public CppUnit::TestFixture
   CPPUNIT_TEST(testRemoveAllPictures);
   CPPUNIT_TEST(testRepeatedSave);
   CPPUNIT_TEST(testSaveMultipleValues);
+  CPPUNIT_TEST(testDict);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -208,6 +209,27 @@ public:
     CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]);
   }
 
+  void testDict()
+  {
+       // test unicode & multiple values with dict interface
+    ScopedFileCopy copy("silence-44-s", ".flac");
+    string newname = copy.fileName();
+
+    FLAC::File *f = new FLAC::File(newname.c_str());
+    TagDict dict;
+    dict["ARTIST"].append("artøst 1");
+    dict["ARTIST"].append("artöst 2");
+    f->fromDict(dict);
+    f->save();
+    delete f;
+
+    f = new FLAC::File(newname.c_str());
+    dict = f->toDict();
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), dict["ARTIST"].size());
+    CPPUNIT_ASSERT_EQUAL(String("artøst 1"), dict["ARTIST"][0]);
+    CPPUNIT_ASSERT_EQUAL(String("artöst 2"), dict["ARTIST"][1]);
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);
index 067bcd221df4371017b93746e8d4647d7ad94f49..1823a5c34e380e54f3161d7fd33f3605c4321a2f 100644 (file)
@@ -553,20 +553,22 @@ public:
     ScopedFileCopy copy("rare_frames", ".mp3");
     string newname = copy.fileName();
     MPEG::File f(newname.c_str());
-    TagDict dict = f.ID3v2Tag(false)->toDict();
+    StringList ignored;
+    TagDict dict = f.ID3v2Tag(false)->toDict(&ignored);
     CPPUNIT_ASSERT_EQUAL(uint(6), dict.size());
     CPPUNIT_ASSERT_EQUAL(String("userTextData1"), dict["USERTEXTDESCRIPTION1"][0]);
     CPPUNIT_ASSERT_EQUAL(String("userTextData2"), dict["USERTEXTDESCRIPTION1"][1]);
     CPPUNIT_ASSERT_EQUAL(String("userTextData1"), dict["USERTEXTDESCRIPTION2"][0]);
     CPPUNIT_ASSERT_EQUAL(String("userTextData2"), dict["USERTEXTDESCRIPTION2"][1]);
 
-    CPPUNIT_ASSERT_EQUAL(String("Pop"), dict["GENRE"][0]);
     CPPUNIT_ASSERT_EQUAL(String("Pop"), dict["GENRE"][0]);
 
     CPPUNIT_ASSERT_EQUAL(String("http://a.user.url"), dict["USERURL"][0]);
     CPPUNIT_ASSERT_EQUAL(String("http://a.user.url/with/empty/description"), dict["URL"][0]);
 
     CPPUNIT_ASSERT_EQUAL(String("A COMMENT"), dict["COMMENT"][0]);
+    CPPUNIT_ASSERT_EQUAL(String("UFID frame is not supported"), ignored[0]);
+    CPPUNIT_ASSERT_EQUAL(1u, ignored.size());
   }
 
 };