]> granicus.if.org Git - taglib/commitdiff
Updated OWNE implementaion with minor changes after pull review
authorRupert Daniel <rupert.daniel@beatport.com>
Thu, 6 Sep 2012 11:11:20 +0000 (12:11 +0100)
committerRupert Daniel <rupert.daniel@beatport.com>
Thu, 6 Sep 2012 11:11:20 +0000 (12:11 +0100)
taglib/mpeg/id3v2/frames/ownershipframe.cpp
taglib/mpeg/id3v2/frames/ownershipframe.h
tests/test_id3v2.cpp

index da8410b50c3e2835f5abd2f812720e9540310d88..9451c4c459f75ec045c36731187fec913cb9bd22 100644 (file)
@@ -26,6 +26,7 @@
 #include <tdebug.h>
 
 #include "ownershipframe.h"
+#include <id3v2tag.h>
 
 using namespace TagLib;
 using namespace ID3v2;
@@ -33,7 +34,6 @@ using namespace ID3v2;
 class OwnershipFrame::OwnershipFramePrivate
 {
 public:
-  String currencyCode;
   String pricePaid;
   String datePurchased;
   String seller;
@@ -123,7 +123,7 @@ void OwnershipFrame::parseFields(const ByteVector &data)
   
   // If we don't have at least 8 bytes left then don't parse the rest of the
   // data
-  if (data.size() - pos < 8) {
+  if(data.size() - pos < 8) {
     return;
   }
   
@@ -132,7 +132,10 @@ void OwnershipFrame::parseFields(const ByteVector &data)
   pos += 8;
   
   // Read the seller
-  d->seller = String(data.mid(pos));
+  if(d->textEncoding == String::Latin1)
+    d->seller = Tag::latin1StringHandler()->parse(data.mid(pos));
+  else
+    d->seller = String(data.mid(pos), d->textEncoding);
 }
 
 ByteVector OwnershipFrame::renderFields() const
index b73832bab4c77e3e38894c67d793e4320b5d7698..34fc912961e1a91ed837e0fbc1e903422642ce19 100644 (file)
@@ -36,8 +36,8 @@ namespace TagLib {
     //! An implementation of ID3v2 "ownership"
 
     /*!
-     * This implements the ID3v2 ownership (OWNE frame).  It concists of
-     * an price paid, a date purchased (YYYYMMDD) and the name of the seller.
+     * This implements the ID3v2 ownership (OWNE frame).  It consists of
+     * a price paid, a date purchased (YYYYMMDD) and the name of the seller.
      */
 
     class TAGLIB_EXPORT OwnershipFrame : public Frame
@@ -81,7 +81,6 @@ namespace TagLib {
        */
       void setDatePurchased(const String &datePurchased);
 
-
       /*!
        * Returns the price paid.
        *
index 243f975331dcf1039d06f9e453c65dbad82324bb..d3fbfee956d05368af84a8740c21f7f59483b5d6 100644 (file)
@@ -72,8 +72,11 @@ 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(testW000);
   CPPUNIT_TEST(testPropertyInterface);
   CPPUNIT_TEST(testPropertyInterface2);
+  CPPUNIT_TEST(testDeleteFrame);
+  CPPUNIT_TEST(testSaveAndStripID3v1ShouldNotAddFrameFromID3v1ToId3v2);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -585,6 +588,16 @@ public:
     CPPUNIT_ASSERT_EQUAL(String(""), frame->description());
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(86414), frame->picture().size());
   }
+  
+  void testW000()
+  {
+    MPEG::File f(TEST_FILE_PATH_C("w000.mp3"), false);
+    CPPUNIT_ASSERT(f.ID3v2Tag()->frameListMap().contains("W000"));
+    ID3v2::UrlLinkFrame *frame =
+    dynamic_cast<TagLib::ID3v2::UrlLinkFrame*>(f.ID3v2Tag()->frameListMap()["W000"].front());
+    CPPUNIT_ASSERT(frame);
+    CPPUNIT_ASSERT_EQUAL(String("lukas.lalinsky@example.com____"), frame->url());
+  }
 
   void testPropertyInterface()
   {
@@ -663,6 +676,44 @@ public:
     CPPUNIT_ASSERT(tag.frameList("TIPL").isEmpty());
   }
 
+  void testDeleteFrame()
+  {
+    ScopedFileCopy copy("rare_frames", ".mp3");
+    string newname = copy.fileName();
+    MPEG::File f(newname.c_str());
+    ID3v2::Tag *t = f.ID3v2Tag();
+    ID3v2::Frame *frame = t->frameList("TCON")[0];
+    CPPUNIT_ASSERT_EQUAL(1u, t->frameList("TCON").size());
+    t->removeFrame(frame, true);
+    f.save(MPEG::File::ID3v2);
+    
+    MPEG::File f2(newname.c_str());
+    t = f2.ID3v2Tag();
+    CPPUNIT_ASSERT(t->frameList("TCON").isEmpty());
+  }
+  
+  void testSaveAndStripID3v1ShouldNotAddFrameFromID3v1ToId3v2()
+  {
+    ScopedFileCopy copy("xing", ".mp3");
+    string newname = copy.fileName();
+    
+    {
+      MPEG::File foo(newname.c_str());
+      foo.tag()->setArtist("Artist");
+      foo.save(MPEG::File::ID3v1 | MPEG::File::ID3v2);
+    }
+    
+    {
+      MPEG::File bar(newname.c_str());
+      bar.ID3v2Tag()->removeFrames("TPE1");
+      // Should strip ID3v1 here and not add old values to ID3v2 again
+      bar.save(MPEG::File::ID3v2, true);
+    }
+    
+    MPEG::File f(newname.c_str());
+    CPPUNIT_ASSERT(!f.ID3v2Tag()->frameListMap().contains("TPE1"));
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2);