From 82315276db1fd4744e5d6c97debd1d50a5f9574f Mon Sep 17 00:00:00 2001 From: Scott Wheeler Date: Thu, 18 Sep 2014 16:23:28 +0200 Subject: [PATCH] Take ownership of embedded frames, as documented Previously embedded frames that were created automatically were never deleted. Fixes #440 --- taglib/mpeg/id3v2/frames/chapterframe.cpp | 5 ++++ .../id3v2/frames/tableofcontentsframe.cpp | 5 ++++ tests/test_id3v2.cpp | 30 +++++++++---------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/taglib/mpeg/id3v2/frames/chapterframe.cpp b/taglib/mpeg/id3v2/frames/chapterframe.cpp index 136a855a..c8650f9d 100644 --- a/taglib/mpeg/id3v2/frames/chapterframe.cpp +++ b/taglib/mpeg/id3v2/frames/chapterframe.cpp @@ -36,6 +36,11 @@ using namespace ID3v2; class ChapterFrame::ChapterFramePrivate { public: + ChapterFramePrivate() + { + embeddedFrameList.setAutoDelete(true); + } + ByteVector elementID; uint startTime; uint endTime; diff --git a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp index f70edd69..4698b7ec 100644 --- a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp +++ b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp @@ -35,6 +35,11 @@ using namespace ID3v2; class TableOfContentsFrame::TableOfContentsFramePrivate { public: + TableOfContentsFramePrivate() + { + embeddedFrameList.setAutoDelete(true); + } + ByteVector elementID; bool isTopLevel; bool isOrdered; diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index 1f080a1a..42bfaa38 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -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); -- 2.40.0