]> granicus.if.org Git - taglib/commitdiff
Take ownership of embedded frames, as documented
authorScott Wheeler <scott@directededge.com>
Thu, 18 Sep 2014 14:23:28 +0000 (16:23 +0200)
committerScott Wheeler <scott@directededge.com>
Thu, 18 Sep 2014 14:23:28 +0000 (16:23 +0200)
Previously embedded frames that were created automatically were
never deleted.

Fixes #440

taglib/mpeg/id3v2/frames/chapterframe.cpp
taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp
tests/test_id3v2.cpp

index 136a855aea6b9946fcde0c3a7f65daf01c0f63e6..c8650f9df10b063ef75e09c5a3ec5849fba6130c 100644 (file)
@@ -36,6 +36,11 @@ using namespace ID3v2;
 class ChapterFrame::ChapterFramePrivate
 {
 public:
+  ChapterFramePrivate()
+  {
+    embeddedFrameList.setAutoDelete(true);
+  }
+
   ByteVector elementID;
   uint startTime;
   uint endTime;
index f70edd6959c16575f6784f1e032eba493945a287..4698b7ec2fb94d89c74f67ae6d6e11492b955166 100644 (file)
@@ -35,6 +35,11 @@ using namespace ID3v2;
 class TableOfContentsFrame::TableOfContentsFramePrivate
 {
 public:
+  TableOfContentsFramePrivate()
+  {
+    embeddedFrameList.setAutoDelete(true);
+  }
+
   ByteVector elementID;
   bool isTopLevel;
   bool isOrdered;
index 1f080a1a0724ba2a90f321ee9426a3f38995d1aa..42bfaa382198fbc19d18ee38b253f795af4487a0 100644 (file)
@@ -885,7 +885,7 @@ public:
     MPEG::File f(newname.c_str());
     CPPUNIT_ASSERT(!f.ID3v2Tag()->frameListMap().contains("TPE1"));
   }
-  
+
   void testParseChapterFrame()
   {
     ID3v2::ChapterFrame f(
@@ -901,7 +901,7 @@ public:
                  "\x00\x00\x00\x04"         // Embedded frame size
                  "\x00\x00"                 // Embedded frame flags
                  "\x00"                     // TIT2 frame text encoding
-                 "CH1", 42));               // Chapter title 
+                 "CH1", 42));               // Chapter title
     CPPUNIT_ASSERT_EQUAL(ByteVector("\x43\x00", 2),
                          f.elementID());
     CPPUNIT_ASSERT((uint)0x03 == f.startTime());
@@ -912,7 +912,7 @@ public:
     CPPUNIT_ASSERT(f.embeddedFrameList("TIT2").size() == 1);
     CPPUNIT_ASSERT(f.embeddedFrameList("TIT2")[0]->toString() == "CH1");
   }
-  
+
   void testRenderChapterFrame()
   {
     ID3v2::ChapterFrame f("CHAP");
@@ -921,9 +921,9 @@ public:
     f.setEndTime(5);
     f.setStartOffset(2);
     f.setEndOffset(3);
-    ID3v2::TextIdentificationFrame eF("TIT2");
-    eF.setText("CH1");
-    f.addEmbeddedFrame(&eF);
+    ID3v2::TextIdentificationFrame *eF = new ID3v2::TextIdentificationFrame("TIT2");
+    eF->setText("CH1");
+    f.addEmbeddedFrame(eF);
     CPPUNIT_ASSERT_EQUAL(
       ByteVector("CHAP"                     // Frame ID
                  "\x00\x00\x00\x20"         // Frame size
@@ -937,10 +937,10 @@ public:
                  "\x00\x00\x00\x04"         // Embedded frame size
                  "\x00\x00"                 // Embedded frame flags
                  "\x00"                     // TIT2 frame text encoding
-                 "CH1", 42),                // Chapter title 
+                 "CH1", 42),                // Chapter title
       f.render());
   }
-  
+
   void testParseTableOfContentsFrame()
   {
     ID3v2::TableOfContentsFrame f(
@@ -956,7 +956,7 @@ public:
                  "\x00\x00\x00\x04"         // Embedded frame size
                  "\x00\x00"                 // Embedded frame flags
                  "\x00"                     // TIT2 frame text encoding
-                 "TC1", 32));               // Table of contents title 
+                 "TC1", 32));               // Table of contents title
     CPPUNIT_ASSERT_EQUAL(ByteVector("\x54\x00", 2),
                          f.elementID());
     CPPUNIT_ASSERT(!f.isTopLevel());
@@ -970,7 +970,7 @@ public:
     CPPUNIT_ASSERT(f.embeddedFrameList("TIT2").size() == 1);
     CPPUNIT_ASSERT(f.embeddedFrameList("TIT2")[0]->toString() == "TC1");
   }
-  
+
   void testRenderTableOfContentsFrame()
   {
     ID3v2::TableOfContentsFrame f("CTOC");
@@ -979,9 +979,9 @@ public:
     f.setIsOrdered(true);
     f.addChildElement(ByteVector("\x43\x00", 2));
     f.addChildElement(ByteVector("\x44\x00", 2));
-    ID3v2::TextIdentificationFrame eF("TIT2");
-    eF.setText("TC1");
-    f.addEmbeddedFrame(&eF);
+    ID3v2::TextIdentificationFrame *eF = new ID3v2::TextIdentificationFrame("TIT2");
+    eF->setText("TC1");
+    f.addEmbeddedFrame(eF);
     CPPUNIT_ASSERT_EQUAL(
       ByteVector("CTOC"                     // Frame ID
                  "\x00\x00\x00\x16"         // Frame size
@@ -995,10 +995,10 @@ public:
                  "\x00\x00\x00\x04"         // Embedded frame size
                  "\x00\x00"                 // Embedded frame flags
                  "\x00"                     // TIT2 frame text encoding
-                 "TC1", 32),                // Table of contents title 
+                 "TC1", 32),                // Table of contents title
       f.render());
   }
-  
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2);