]> granicus.if.org Git - taglib/commitdiff
Added another test for ID3v2 PropertyMap interface; fixed various bugs
authorMichael Helmling <helmling@mathematik.uni-kl.de>
Sat, 25 Feb 2012 17:22:17 +0000 (18:22 +0100)
committerMichael Helmling <helmling@mathematik.uni-kl.de>
Sat, 25 Feb 2012 17:22:17 +0000 (18:22 +0100)
taglib/mpeg/id3v2/frames/textidentificationframe.cpp
taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp
taglib/mpeg/id3v2/id3v2tag.cpp
taglib/toolkit/tpropertymap.cpp
tests/test_id3v2.cpp

index 3c3d43763c50873534fbc49275e654ac998f29cc..0ab1c84c1df0f344ec4526f38c4fe9b9c1fce1cd 100644 (file)
@@ -260,7 +260,8 @@ PropertyMap TextIdentificationFrame::makeTIPLProperties() const
     map.unsupportedData().append(frameID());
     return map;
   }
-  for(StringList::ConstIterator it = fieldList().begin(); it != fieldList().end(); ++it) {
+  StringList l = fieldList();
+  for(StringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
     bool found = false;
     for(uint i = 0; i < involvedPeopleSize; ++i)
       if(*it == involvedPeople[i][0]) {
@@ -286,7 +287,8 @@ PropertyMap TextIdentificationFrame::makeTMCLProperties() const
     map.unsupportedData().append(frameID());
     return map;
   }
-  for(StringList::ConstIterator it = fieldList().begin(); it != fieldList().end(); ++it) {
+  StringList l = fieldList();
+  for(StringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
     String instrument = PropertyMap::prepareKey(*it);
     if(instrument.isNull()) {
       // instrument is not a valid key -> frame unsupported
index ae013ec97abd2a44f6a96faa57a65db9e5d70a79..6719a9b3e04907d82926a0d4094aab6ee34fe47c 100644 (file)
@@ -114,11 +114,11 @@ void UnsynchronizedLyricsFrame::setTextEncoding(String::Type encoding)
 
 PropertyMap UnsynchronizedLyricsFrame::asProperties() const
 {
-  String key = PropertyMap::prepareKey(description());
   PropertyMap map;
-  if(key.isEmpty())
-    key = "LYRICS";
-  if(key.isNull())
+  String key = PropertyMap::prepareKey(description());
+  if(key.isEmpty() || key.upper() == "LYRICS")
+    map.insert("LYRICS", text());
+  else if(key.isNull())
     map.unsupportedData().append(L"USLT/" + description());
   else
     map.insert("LYRICS:" + key, text());
index 4085daae349eded1e73b54dff091dd2b78446f34..cdfa4353f398977536228a6497accf1b2deaf904 100644 (file)
@@ -339,6 +339,7 @@ PropertyMap ID3v2::Tag::properties() const
   PropertyMap properties;
   for(FrameList::ConstIterator it = frameList().begin(); it != frameList().end(); ++it) {
     PropertyMap props = (*it)->asProperties();
+    debug("read properties:\n" + props.toString());
     properties.merge(props);
   }
   return properties;
index 40bcaba7754c0446a98b1474fa174ada9074e4a8..1743a0b239910e1b467f01b5ddd6a816b83a4b66 100644 (file)
@@ -166,6 +166,8 @@ String PropertyMap::toString() const
   String ret = "";
   for(ConstIterator it = begin(); it != end(); ++it)
     ret += it->first+"="+it->second.toString(", ") + "\n";
+  if(!unsupported.isEmpty())
+    ret += "Unsupported Data: " + unsupported.toString(", ") + "\n";
   return ret;
 }
 
index ef92b44ddb9949018de3835e8aa20e55815f74d6..530b3f3d9ba485955af643ce617c7482a7bddc21 100644 (file)
@@ -10,6 +10,7 @@
 #include <uniquefileidentifierframe.h>
 #include <textidentificationframe.h>
 #include <attachedpictureframe.h>
+#include <unsynchronizedlyricsframe.h>
 #include <generalencapsulatedobjectframe.h>
 #include <relativevolumeframe.h>
 #include <popularimeterframe.h>
@@ -68,7 +69,8 @@ class TestID3v2 : public CppUnit::TestFixture
   CPPUNIT_TEST(testDowngradeTo23);
   // CPPUNIT_TEST(testUpdateFullDate22); TODO TYE+TDA should be upgraded to TDRC together
   CPPUNIT_TEST(testCompressedFrameWithBrokenLength);
-  CPPUNIT_TEST(testDictInterface);
+  CPPUNIT_TEST(testPropertyInterface);
+  CPPUNIT_TEST(testPropertyInterface2);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -549,7 +551,7 @@ public:
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(86414), frame->picture().size());
   }
 
-  void testDictInterface()
+  void testPropertyInterface()
   {
     ScopedFileCopy copy("rare_frames", ".mp3");
     string newname = copy.fileName();
@@ -572,6 +574,55 @@ public:
     CPPUNIT_ASSERT_EQUAL(String("UFID"), dict.unsupportedData().front());
   }
 
+  void testPropertyInterface2()
+  {
+    ID3v2::Tag tag;
+    ID3v2::UnsynchronizedLyricsFrame *frame1 = new ID3v2::UnsynchronizedLyricsFrame();
+    frame1->setDescription("test");
+    frame1->setText("la-la-la test");
+    tag.addFrame(frame1);
+
+    ID3v2::UnsynchronizedLyricsFrame *frame2 = new ID3v2::UnsynchronizedLyricsFrame();
+    frame2->setDescription("");
+    frame2->setText("la-la-la nodescription");
+    tag.addFrame(frame2);
+
+    ID3v2::AttachedPictureFrame *frame3 = new ID3v2::AttachedPictureFrame();
+    frame3->setDescription("test picture");
+    tag.addFrame(frame3);
+
+    ID3v2::TextIdentificationFrame *frame4 = new ID3v2::TextIdentificationFrame("TIPL");
+    frame4->setText("single value is invalid for TIPL");
+    tag.addFrame(frame4);
+
+    ID3v2::TextIdentificationFrame *frame5 = new ID3v2::TextIdentificationFrame("TMCL");
+    StringList tmclData;
+    tmclData.append("VIOLIN");
+    tmclData.append("a violinist");
+    tmclData.append("PIANO");
+    tmclData.append("a pianist");
+    frame5->setText(tmclData);
+    tag.addFrame(frame5);
+
+    PropertyMap properties = tag.properties();
+
+    CPPUNIT_ASSERT_EQUAL(2u, properties.unsupportedData().size());
+    CPPUNIT_ASSERT(properties.unsupportedData().contains("TIPL"));
+    CPPUNIT_ASSERT(properties.unsupportedData().contains("APIC"));
+
+    CPPUNIT_ASSERT(properties.contains("PERFORMER:VIOLIN"));
+    CPPUNIT_ASSERT(properties.contains("PERFORMER:PIANO"));
+    CPPUNIT_ASSERT_EQUAL(String("a violinist"), properties["PERFORMER:VIOLIN"].front());
+    CPPUNIT_ASSERT_EQUAL(String("a pianist"), properties["PERFORMER:PIANO"].front());
+
+    CPPUNIT_ASSERT(properties.contains("LYRICS"));
+    CPPUNIT_ASSERT(properties.contains("LYRICS:TEST"));
+
+    tag.removeUnsupportedProperties(properties.unsupportedData());
+    CPPUNIT_ASSERT(tag.frameList("APIC").isEmpty());
+    CPPUNIT_ASSERT(tag.frameList("TIPL").isEmpty());
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2);