]> granicus.if.org Git - taglib/commitdiff
Close temporary files regardless if the tests are successful or not.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 27 Nov 2015 06:20:16 +0000 (15:20 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 27 Nov 2015 06:20:16 +0000 (15:20 +0900)
delete statements are skipped when assertions fail.

tests/test_asf.cpp
tests/test_fileref.cpp
tests/test_flac.cpp
tests/test_mp4.cpp
tests/test_ogg.cpp
tests/test_oggflac.cpp
tests/test_opus.cpp
tests/test_riff.cpp
tests/test_wav.cpp

index 37614b0c8ffb26079bb055d1180104b83d03cc2c..2dfcb64d2ad9ef46a89fe9fe4c5c2b4cd5a133a6 100644 (file)
@@ -75,17 +75,18 @@ public:
     ScopedFileCopy copy("silence-1", ".wma");
     string newname = copy.fileName();
 
-    ASF::File *f = new ASF::File(newname.c_str());
-    ASF::AttributeList values;
-    values.append("Foo");
-    values.append("Bar");
-    f->tag()->setAttribute("WM/AlbumTitle", values);
-    f->save();
-    delete f;
-
-    f = new ASF::File(newname.c_str());
-    CPPUNIT_ASSERT_EQUAL(2, (int)f->tag()->attributeListMap()["WM/AlbumTitle"].size());
-    delete f;
+    {
+      ASF::File f(newname.c_str());
+      ASF::AttributeList values;
+      values.append("Foo");
+      values.append("Bar");
+      f.tag()->setAttribute("WM/AlbumTitle", values);
+      f.save();
+    }
+    {
+      ASF::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(2, (int)f.tag()->attributeListMap()["WM/AlbumTitle"].size());
+    }
   }
 
   void testDWordTrackNumber()
@@ -93,27 +94,28 @@ public:
     ScopedFileCopy copy("silence-1", ".wma");
     string newname = copy.fileName();
 
-    ASF::File *f = new ASF::File(newname.c_str());
-    CPPUNIT_ASSERT(!f->tag()->contains("WM/TrackNumber"));
-    f->tag()->setAttribute("WM/TrackNumber", (unsigned int)(123));
-    f->save();
-    delete f;
-
-    f = new ASF::File(newname.c_str());
-    CPPUNIT_ASSERT(f->tag()->contains("WM/TrackNumber"));
-    CPPUNIT_ASSERT_EQUAL(ASF::Attribute::DWordType,
-                         f->tag()->attribute("WM/TrackNumber").front().type());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(123), f->tag()->track());
-    f->tag()->setTrack(234);
-    f->save();
-    delete f;
-
-    f = new ASF::File(newname.c_str());
-    CPPUNIT_ASSERT(f->tag()->contains("WM/TrackNumber"));
-    CPPUNIT_ASSERT_EQUAL(ASF::Attribute::UnicodeType,
-                         f->tag()->attribute("WM/TrackNumber").front().type());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(234), f->tag()->track());
-    delete f;
+    {
+      ASF::File f(newname.c_str());
+      CPPUNIT_ASSERT(!f.tag()->contains("WM/TrackNumber"));
+      f.tag()->setAttribute("WM/TrackNumber", (unsigned int)(123));
+      f.save();
+    }
+    {
+      ASF::File f(newname.c_str());
+      CPPUNIT_ASSERT(f.tag()->contains("WM/TrackNumber"));
+      CPPUNIT_ASSERT_EQUAL(ASF::Attribute::DWordType,
+                           f.tag()->attribute("WM/TrackNumber").front().type());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(123), f.tag()->track());
+      f.tag()->setTrack(234);
+      f.save();
+    }
+    {
+      ASF::File f(newname.c_str());
+      CPPUNIT_ASSERT(f.tag()->contains("WM/TrackNumber"));
+      CPPUNIT_ASSERT_EQUAL(ASF::Attribute::UnicodeType,
+                           f.tag()->attribute("WM/TrackNumber").front().type());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(234), f.tag()->track());
+    }
   }
 
   void testSaveStream()
@@ -121,16 +123,18 @@ public:
     ScopedFileCopy copy("silence-1", ".wma");
     string newname = copy.fileName();
 
-    ASF::File *f = new ASF::File(newname.c_str());
-    ASF::Attribute attr("Foo");
-    attr.setStream(43);
-    f->tag()->setAttribute("WM/AlbumTitle", attr);
-    f->save();
-    delete f;
+    {
+      ASF::File f(newname.c_str());
+      ASF::Attribute attr("Foo");
+      attr.setStream(43);
+      f.tag()->setAttribute("WM/AlbumTitle", attr);
+      f.save();
+    }
 
-    f = new ASF::File(newname.c_str());
-    CPPUNIT_ASSERT_EQUAL(43, f->tag()->attribute("WM/AlbumTitle").front().stream());
-    delete f;
+    {
+      ASF::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(43, f.tag()->attribute("WM/AlbumTitle").front().stream());
+    }
   }
 
   void testSaveLanguage()
@@ -138,18 +142,19 @@ public:
     ScopedFileCopy copy("silence-1", ".wma");
     string newname = copy.fileName();
 
-    ASF::File *f = new ASF::File(newname.c_str());
-    ASF::Attribute attr("Foo");
-    attr.setStream(32);
-    attr.setLanguage(56);
-    f->tag()->setAttribute("WM/AlbumTitle", attr);
-    f->save();
-    delete f;
-
-    f = new ASF::File(newname.c_str());
-    CPPUNIT_ASSERT_EQUAL(32, f->tag()->attribute("WM/AlbumTitle").front().stream());
-    CPPUNIT_ASSERT_EQUAL(56, f->tag()->attribute("WM/AlbumTitle").front().language());
-    delete f;
+    {
+      ASF::File f(newname.c_str());
+      ASF::Attribute attr("Foo");
+      attr.setStream(32);
+      attr.setLanguage(56);
+      f.tag()->setAttribute("WM/AlbumTitle", attr);
+      f.save();
+    }
+    {
+      ASF::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(32, f.tag()->attribute("WM/AlbumTitle").front().stream());
+      CPPUNIT_ASSERT_EQUAL(56, f.tag()->attribute("WM/AlbumTitle").front().language());
+    }
   }
 
   void testSaveLargeValue()
@@ -157,16 +162,17 @@ public:
     ScopedFileCopy copy("silence-1", ".wma");
     string newname = copy.fileName();
 
-    ASF::File *f = new ASF::File(newname.c_str());
-    ASF::Attribute attr(ByteVector(70000, 'x'));
-    f->tag()->setAttribute("WM/Blob", attr);
-    f->save();
-    delete f;
-
-    f = new ASF::File(newname.c_str());
-    CPPUNIT_ASSERT_EQUAL(ByteVector(70000, 'x'),
-                         f->tag()->attribute("WM/Blob").front().toByteVector());
-    delete f;
+    {
+      ASF::File f(newname.c_str());
+      ASF::Attribute attr(ByteVector(70000, 'x'));
+      f.tag()->setAttribute("WM/Blob", attr);
+      f.save();
+    }
+    {
+      ASF::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(ByteVector(70000, 'x'),
+                           f.tag()->attribute("WM/Blob").front().toByteVector());
+    }
   }
 
   void testSavePicture()
@@ -174,27 +180,28 @@ public:
     ScopedFileCopy copy("silence-1", ".wma");
     string newname = copy.fileName();
 
-    ASF::File *f = new ASF::File(newname.c_str());
-    ASF::Picture picture;
-    picture.setMimeType("image/jpeg");
-    picture.setType(ASF::Picture::FrontCover);
-    picture.setDescription("description");
-    picture.setPicture("data");
-    f->tag()->setAttribute("WM/Picture", picture);
-    f->save();
-    delete f;
-
-    f = new ASF::File(newname.c_str());
-    ASF::AttributeList values2 = f->tag()->attribute("WM/Picture");
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), values2.size());
-    ASF::Attribute attr2 = values2.front();
-    ASF::Picture picture2 = attr2.toPicture();
-    CPPUNIT_ASSERT(picture2.isValid());
-    CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture2.mimeType());
-    CPPUNIT_ASSERT_EQUAL(ASF::Picture::FrontCover, picture2.type());
-    CPPUNIT_ASSERT_EQUAL(String("description"), picture2.description());
-    CPPUNIT_ASSERT_EQUAL(ByteVector("data"), picture2.picture());
-    delete f;
+    {
+      ASF::File f(newname.c_str());
+      ASF::Picture picture;
+      picture.setMimeType("image/jpeg");
+      picture.setType(ASF::Picture::FrontCover);
+      picture.setDescription("description");
+      picture.setPicture("data");
+      f.tag()->setAttribute("WM/Picture", picture);
+      f.save();
+    }
+    {
+      ASF::File f(newname.c_str());
+      ASF::AttributeList values2 = f.tag()->attribute("WM/Picture");
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), values2.size());
+      ASF::Attribute attr2 = values2.front();
+      ASF::Picture picture2 = attr2.toPicture();
+      CPPUNIT_ASSERT(picture2.isValid());
+      CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture2.mimeType());
+      CPPUNIT_ASSERT_EQUAL(ASF::Picture::FrontCover, picture2.type());
+      CPPUNIT_ASSERT_EQUAL(String("description"), picture2.description());
+      CPPUNIT_ASSERT_EQUAL(ByteVector("data"), picture2.picture());
+    }
   }
 
   void testSaveMultiplePictures()
@@ -202,40 +209,41 @@ public:
     ScopedFileCopy copy("silence-1", ".wma");
     string newname = copy.fileName();
 
-    ASF::File *f = new ASF::File(newname.c_str());
-    ASF::AttributeList values;
-    ASF::Picture picture;
-    picture.setMimeType("image/jpeg");
-    picture.setType(ASF::Picture::FrontCover);
-    picture.setDescription("description");
-    picture.setPicture("data");
-    values.append(ASF::Attribute(picture));
-    ASF::Picture picture2;
-    picture2.setMimeType("image/png");
-    picture2.setType(ASF::Picture::BackCover);
-    picture2.setDescription("back cover");
-    picture2.setPicture("PNG data");
-    values.append(ASF::Attribute(picture2));
-    f->tag()->setAttribute("WM/Picture", values);
-    f->save();
-    delete f;
-
-    f = new ASF::File(newname.c_str());
-    ASF::AttributeList values2 = f->tag()->attribute("WM/Picture");
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), values2.size());
-    ASF::Picture picture3 = values2[1].toPicture();
-    CPPUNIT_ASSERT(picture3.isValid());
-    CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture3.mimeType());
-    CPPUNIT_ASSERT_EQUAL(ASF::Picture::FrontCover, picture3.type());
-    CPPUNIT_ASSERT_EQUAL(String("description"), picture3.description());
-    CPPUNIT_ASSERT_EQUAL(ByteVector("data"), picture3.picture());
-    ASF::Picture picture4 = values2[0].toPicture();
-    CPPUNIT_ASSERT(picture4.isValid());
-    CPPUNIT_ASSERT_EQUAL(String("image/png"), picture4.mimeType());
-    CPPUNIT_ASSERT_EQUAL(ASF::Picture::BackCover, picture4.type());
-    CPPUNIT_ASSERT_EQUAL(String("back cover"), picture4.description());
-    CPPUNIT_ASSERT_EQUAL(ByteVector("PNG data"), picture4.picture());
-    delete f;
+    {
+      ASF::File f(newname.c_str());
+      ASF::AttributeList values;
+      ASF::Picture picture;
+      picture.setMimeType("image/jpeg");
+      picture.setType(ASF::Picture::FrontCover);
+      picture.setDescription("description");
+      picture.setPicture("data");
+      values.append(ASF::Attribute(picture));
+      ASF::Picture picture2;
+      picture2.setMimeType("image/png");
+      picture2.setType(ASF::Picture::BackCover);
+      picture2.setDescription("back cover");
+      picture2.setPicture("PNG data");
+      values.append(ASF::Attribute(picture2));
+      f.tag()->setAttribute("WM/Picture", values);
+      f.save();
+    }
+    {
+      ASF::File f(newname.c_str());
+      ASF::AttributeList values2 = f.tag()->attribute("WM/Picture");
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), values2.size());
+      ASF::Picture picture3 = values2[1].toPicture();
+      CPPUNIT_ASSERT(picture3.isValid());
+      CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture3.mimeType());
+      CPPUNIT_ASSERT_EQUAL(ASF::Picture::FrontCover, picture3.type());
+      CPPUNIT_ASSERT_EQUAL(String("description"), picture3.description());
+      CPPUNIT_ASSERT_EQUAL(ByteVector("data"), picture3.picture());
+      ASF::Picture picture4 = values2[0].toPicture();
+      CPPUNIT_ASSERT(picture4.isValid());
+      CPPUNIT_ASSERT_EQUAL(String("image/png"), picture4.mimeType());
+      CPPUNIT_ASSERT_EQUAL(ASF::Picture::BackCover, picture4.type());
+      CPPUNIT_ASSERT_EQUAL(String("back cover"), picture4.description());
+      CPPUNIT_ASSERT_EQUAL(ByteVector("PNG data"), picture4.picture());
+    }
   }
 
   void testProperties()
index a389cfd3363d392a812626e644f1ee007e53667b..f0122c83774a6729160fd6fda9e7e19bdf82f337 100644 (file)
@@ -52,54 +52,55 @@ public:
     ScopedFileCopy copy(filename, ext);
     string newname = copy.fileName();
 
-    FileRef *f = new FileRef(newname.c_str());
-    CPPUNIT_ASSERT(!f->isNull());
-    f->tag()->setArtist("test artist");
-    f->tag()->setTitle("test title");
-    f->tag()->setGenre("Test!");
-    f->tag()->setAlbum("albummmm");
-    f->tag()->setTrack(5);
-    f->tag()->setYear(2020);
-    f->save();
-    delete f;
-
-    f = new FileRef(newname.c_str());
-    CPPUNIT_ASSERT(!f->isNull());
-    CPPUNIT_ASSERT_EQUAL(f->tag()->artist(), String("test artist"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->title(), String("test title"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->genre(), String("Test!"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->album(), String("albummmm"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(5));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2020));
-    f->tag()->setArtist("ttest artist");
-    f->tag()->setTitle("ytest title");
-    f->tag()->setGenre("uTest!");
-    f->tag()->setAlbum("ialbummmm");
-    f->tag()->setTrack(7);
-    f->tag()->setYear(2080);
-    f->save();
-    delete f;
-
-    f = new FileRef(newname.c_str());
-    CPPUNIT_ASSERT(!f->isNull());
-    CPPUNIT_ASSERT_EQUAL(f->tag()->artist(), String("ttest artist"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->title(), String("ytest title"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->genre(), String("uTest!"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->album(), String("ialbummmm"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080));
-    delete f;
-
-    FileStream fs(newname.c_str());
-    f = new FileRef(&fs);
-    CPPUNIT_ASSERT(!f->isNull());
-    CPPUNIT_ASSERT_EQUAL(f->tag()->artist(), String("ttest artist"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->title(), String("ytest title"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->genre(), String("uTest!"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->album(), String("ialbummmm"));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7));
-    CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080));
-    delete f;
+    {
+      FileRef f(newname.c_str());
+      CPPUNIT_ASSERT(!f.isNull());
+      f.tag()->setArtist("test artist");
+      f.tag()->setTitle("test title");
+      f.tag()->setGenre("Test!");
+      f.tag()->setAlbum("albummmm");
+      f.tag()->setTrack(5);
+      f.tag()->setYear(2020);
+      f.save();
+    }
+    {
+      FileRef f(newname.c_str());
+      CPPUNIT_ASSERT(!f.isNull());
+      CPPUNIT_ASSERT_EQUAL(f.tag()->artist(), String("test artist"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->title(), String("test title"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->genre(), String("Test!"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->album(), String("albummmm"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->track(), TagLib::uint(5));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->year(), TagLib::uint(2020));
+      f.tag()->setArtist("ttest artist");
+      f.tag()->setTitle("ytest title");
+      f.tag()->setGenre("uTest!");
+      f.tag()->setAlbum("ialbummmm");
+      f.tag()->setTrack(7);
+      f.tag()->setYear(2080);
+      f.save();
+    }
+    {
+      FileRef f(newname.c_str());
+      CPPUNIT_ASSERT(!f.isNull());
+      CPPUNIT_ASSERT_EQUAL(f.tag()->artist(), String("ttest artist"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->title(), String("ytest title"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->genre(), String("uTest!"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->album(), String("ialbummmm"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->track(), TagLib::uint(7));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->year(), TagLib::uint(2080));
+    }
+    {
+      FileStream fs(newname.c_str());
+      FileRef f(&fs);
+      CPPUNIT_ASSERT(!f.isNull());
+      CPPUNIT_ASSERT_EQUAL(f.tag()->artist(), String("ttest artist"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->title(), String("ytest title"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->genre(), String("uTest!"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->album(), String("ialbummmm"));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->track(), TagLib::uint(7));
+      CPPUNIT_ASSERT_EQUAL(f.tag()->year(), TagLib::uint(2080));
+    }
   }
 
   void testMusepack()
@@ -159,18 +160,16 @@ public:
 
   void testOGA_FLAC()
   {
-      FileRef *f = new FileRef(TEST_FILE_PATH_C("empty_flac.oga"));
-      CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f->file()) == NULL);
-      CPPUNIT_ASSERT(dynamic_cast<Ogg::FLAC::File *>(f->file()) != NULL);
-      delete f;
+    FileRef f(TEST_FILE_PATH_C("empty_flac.oga"));
+    CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f.file()) == NULL);
+    CPPUNIT_ASSERT(dynamic_cast<Ogg::FLAC::File *>(f.file()) != NULL);
   }
 
   void testOGA_Vorbis()
   {
-      FileRef *f = new FileRef(TEST_FILE_PATH_C("empty_vorbis.oga"));
-      CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f->file()) != NULL);
-      CPPUNIT_ASSERT(dynamic_cast<Ogg::FLAC::File *>(f->file()) == NULL);
-      delete f;
+    FileRef f(TEST_FILE_PATH_C("empty_vorbis.oga"));
+    CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f.file()) != NULL);
+    CPPUNIT_ASSERT(dynamic_cast<Ogg::FLAC::File *>(f.file()) == NULL);
   }
 
   void testAPE()
@@ -189,16 +188,18 @@ public:
 
   void testFileResolver()
   {
-    FileRef *f = new FileRef(TEST_FILE_PATH_C("xing.mp3"));
-    CPPUNIT_ASSERT(dynamic_cast<MPEG::File *>(f->file()) != NULL);
-    delete f;
+    {
+      FileRef f(TEST_FILE_PATH_C("xing.mp3"));
+      CPPUNIT_ASSERT(dynamic_cast<MPEG::File *>(f.file()) != NULL);
+    }
 
     DummyResolver resolver;
     FileRef::addFileTypeResolver(&resolver);
 
-    f = new FileRef(TEST_FILE_PATH_C("xing.mp3"));
-    CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f->file()) != NULL);
-    delete f;
+    {
+      FileRef f(TEST_FILE_PATH_C("xing.mp3"));
+      CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f.file()) != NULL);
+    }
   }
 
 };
index 54104cc5d4e8aaf78e9a18c11d869bc1df40d097..9fdd51e159e84bc4b2c56ce19c1c9b92dc5ff363 100644 (file)
@@ -44,15 +44,16 @@ public:
     ScopedFileCopy copy("multiple-vc", ".flac");
     string newname = copy.fileName();
 
-    FLAC::File *f = new FLAC::File(newname.c_str());
-    CPPUNIT_ASSERT_EQUAL(String("Artist 1"), f->tag()->artist());
-    f->tag()->setArtist("The Artist");
-    f->save();
-    delete f;
-
-    f = new FLAC::File(newname.c_str());
-    CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
-    delete f;
+    {
+      FLAC::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(String("Artist 1"), f.tag()->artist());
+      f.tag()->setArtist("The Artist");
+      f.save();
+    }
+    {
+      FLAC::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist());
+    }
   }
 
   void testReadPicture()
@@ -60,8 +61,8 @@ public:
     ScopedFileCopy copy("silence-44-s", ".flac");
     string newname = copy.fileName();
 
-    FLAC::File *f = new FLAC::File(newname.c_str());
-    List<FLAC::Picture *> lst = f->pictureList();
+    FLAC::File f(newname.c_str());
+    List<FLAC::Picture *> lst = f.pictureList();
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
 
     FLAC::Picture *pic = lst.front();
@@ -73,8 +74,6 @@ public:
     CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType());
     CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description());
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size());
-
-    delete f;
   }
 
   void testAddPicture()
@@ -82,47 +81,48 @@ public:
     ScopedFileCopy copy("silence-44-s", ".flac");
     string newname = copy.fileName();
 
-    FLAC::File *f = new FLAC::File(newname.c_str());
-    List<FLAC::Picture *> lst = f->pictureList();
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
-
-    FLAC::Picture *newpic = new FLAC::Picture();
-    newpic->setType(FLAC::Picture::BackCover);
-    newpic->setWidth(5);
-    newpic->setHeight(6);
-    newpic->setColorDepth(16);
-    newpic->setNumColors(7);
-    newpic->setMimeType("image/jpeg");
-    newpic->setDescription("new image");
-    newpic->setData("JPEG data");
-    f->addPicture(newpic);
-    f->save();
-    delete f;
-
-    f = new FLAC::File(newname.c_str());
-    lst = f->pictureList();
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), lst.size());
-
-    FLAC::Picture *pic = lst[0];
-    CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pic->type());
-    CPPUNIT_ASSERT_EQUAL(1, pic->width());
-    CPPUNIT_ASSERT_EQUAL(1, pic->height());
-    CPPUNIT_ASSERT_EQUAL(24, pic->colorDepth());
-    CPPUNIT_ASSERT_EQUAL(0, pic->numColors());
-    CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType());
-    CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size());
-
-    pic = lst[1];
-    CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type());
-    CPPUNIT_ASSERT_EQUAL(5, pic->width());
-    CPPUNIT_ASSERT_EQUAL(6, pic->height());
-    CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth());
-    CPPUNIT_ASSERT_EQUAL(7, pic->numColors());
-    CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType());
-    CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description());
-    CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data());
-    delete f;
+    {
+      FLAC::File f(newname.c_str());
+      List<FLAC::Picture *> lst = f.pictureList();
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
+
+      FLAC::Picture *newpic = new FLAC::Picture();
+      newpic->setType(FLAC::Picture::BackCover);
+      newpic->setWidth(5);
+      newpic->setHeight(6);
+      newpic->setColorDepth(16);
+      newpic->setNumColors(7);
+      newpic->setMimeType("image/jpeg");
+      newpic->setDescription("new image");
+      newpic->setData("JPEG data");
+      f.addPicture(newpic);
+      f.save();
+    }
+    {
+      FLAC::File f(newname.c_str());
+      List<FLAC::Picture *> lst = f.pictureList();
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), lst.size());
+
+      FLAC::Picture *pic = lst[0];
+      CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pic->type());
+      CPPUNIT_ASSERT_EQUAL(1, pic->width());
+      CPPUNIT_ASSERT_EQUAL(1, pic->height());
+      CPPUNIT_ASSERT_EQUAL(24, pic->colorDepth());
+      CPPUNIT_ASSERT_EQUAL(0, pic->numColors());
+      CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType());
+      CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size());
+
+      pic = lst[1];
+      CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type());
+      CPPUNIT_ASSERT_EQUAL(5, pic->width());
+      CPPUNIT_ASSERT_EQUAL(6, pic->height());
+      CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth());
+      CPPUNIT_ASSERT_EQUAL(7, pic->numColors());
+      CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType());
+      CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description());
+      CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data());
+    }
   }
 
   void testReplacePicture()
@@ -130,38 +130,39 @@ public:
     ScopedFileCopy copy("silence-44-s", ".flac");
     string newname = copy.fileName();
 
-    FLAC::File *f = new FLAC::File(newname.c_str());
-    List<FLAC::Picture *> lst = f->pictureList();
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
-
-    FLAC::Picture *newpic = new FLAC::Picture();
-    newpic->setType(FLAC::Picture::BackCover);
-    newpic->setWidth(5);
-    newpic->setHeight(6);
-    newpic->setColorDepth(16);
-    newpic->setNumColors(7);
-    newpic->setMimeType("image/jpeg");
-    newpic->setDescription("new image");
-    newpic->setData("JPEG data");
-    f->removePictures();
-    f->addPicture(newpic);
-    f->save();
-    delete f;
-
-    f = new FLAC::File(newname.c_str());
-    lst = f->pictureList();
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
-
-    FLAC::Picture *pic = lst[0];
-    CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type());
-    CPPUNIT_ASSERT_EQUAL(5, pic->width());
-    CPPUNIT_ASSERT_EQUAL(6, pic->height());
-    CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth());
-    CPPUNIT_ASSERT_EQUAL(7, pic->numColors());
-    CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType());
-    CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description());
-    CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data());
-    delete f;
+    {
+      FLAC::File f(newname.c_str());
+      List<FLAC::Picture *> lst = f.pictureList();
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
+
+      FLAC::Picture *newpic = new FLAC::Picture();
+      newpic->setType(FLAC::Picture::BackCover);
+      newpic->setWidth(5);
+      newpic->setHeight(6);
+      newpic->setColorDepth(16);
+      newpic->setNumColors(7);
+      newpic->setMimeType("image/jpeg");
+      newpic->setDescription("new image");
+      newpic->setData("JPEG data");
+      f.removePictures();
+      f.addPicture(newpic);
+      f.save();
+    }
+    {
+      FLAC::File f(newname.c_str());
+      List<FLAC::Picture *> lst = f.pictureList();
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
+
+      FLAC::Picture *pic = lst[0];
+      CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type());
+      CPPUNIT_ASSERT_EQUAL(5, pic->width());
+      CPPUNIT_ASSERT_EQUAL(6, pic->height());
+      CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth());
+      CPPUNIT_ASSERT_EQUAL(7, pic->numColors());
+      CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType());
+      CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description());
+      CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data());
+    }
   }
 
   void testRemoveAllPictures()
@@ -169,18 +170,19 @@ public:
     ScopedFileCopy copy("silence-44-s", ".flac");
     string newname = copy.fileName();
 
-    FLAC::File *f = new FLAC::File(newname.c_str());
-    List<FLAC::Picture *> lst = f->pictureList();
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
-
-    f->removePictures();
-    f->save();
-    delete f;
+    {
+      FLAC::File f(newname.c_str());
+      List<FLAC::Picture *> lst = f.pictureList();
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
 
-    f = new FLAC::File(newname.c_str());
-    lst = f->pictureList();
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), lst.size());
-    delete f;
+      f.removePictures();
+      f.save();
+    }
+    {
+      FLAC::File f(newname.c_str());
+      List<FLAC::Picture *> lst = f.pictureList();
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), lst.size());
+    }
   }
 
   void testRepeatedSave()
@@ -188,21 +190,20 @@ public:
     ScopedFileCopy copy("silence-44-s", ".flac");
     string newname = copy.fileName();
 
-    FLAC::File *f = new FLAC::File(newname.c_str());
-    Tag *tag = f->tag();
-    CPPUNIT_ASSERT_EQUAL(String("Silence"), tag->title());
-    tag->setTitle("NEW TITLE");
-    f->save();
-    CPPUNIT_ASSERT_EQUAL(String("NEW TITLE"), tag->title());
-    tag->setTitle("NEW TITLE 2");
-    f->save();
-    CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), tag->title());
-    delete f;
-
-    f = new FLAC::File(newname.c_str());
-    tag = f->tag();
-    CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), tag->title());
-    delete f;
+    {
+      FLAC::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(String("Silence"), f.tag()->title());
+      f.tag()->setTitle("NEW TITLE");
+      f.save();
+      CPPUNIT_ASSERT_EQUAL(String("NEW TITLE"), f.tag()->title());
+      f.tag()->setTitle("NEW TITLE 2");
+      f.save();
+      CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), f.tag()->title());
+    }
+    {
+      FLAC::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), f.tag()->title());
+    }
   }
 
   void testSaveMultipleValues()
@@ -210,20 +211,19 @@ public:
     ScopedFileCopy copy("silence-44-s", ".flac");
     string newname = copy.fileName();
 
-    FLAC::File *f = new FLAC::File(newname.c_str());
-    Ogg::XiphComment* c = f->xiphComment(true);
-    c->addField("ARTIST", "artist 1", true);
-    c->addField("ARTIST", "artist 2", false);
-    f->save();
-    delete f;
-
-    f = new FLAC::File(newname.c_str());
-    c = f->xiphComment(true);
-    Ogg::FieldListMap m = c->fieldListMap();
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), m["ARTIST"].size());
-    CPPUNIT_ASSERT_EQUAL(String("artist 1"), m["ARTIST"][0]);
-    CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]);
-    delete f;
+    {
+      FLAC::File f(newname.c_str());
+      f.xiphComment(true)->addField("ARTIST", "artist 1", true);
+      f.xiphComment(true)->addField("ARTIST", "artist 2", false);
+      f.save();
+    }
+    {
+      FLAC::File f(newname.c_str());
+      Ogg::FieldListMap m = f.xiphComment()->fieldListMap();
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), m["ARTIST"].size());
+      CPPUNIT_ASSERT_EQUAL(String("artist 1"), m["ARTIST"][0]);
+      CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]);
+    }
   }
 
   void testDict()
@@ -232,20 +232,21 @@ public:
     ScopedFileCopy copy("silence-44-s", ".flac");
     string newname = copy.fileName();
 
-    FLAC::File *f = new FLAC::File(newname.c_str());
-    PropertyMap dict;
-    dict["ARTIST"].append("artøst 1");
-    dict["ARTIST"].append("artöst 2");
-    f->setProperties(dict);
-    f->save();
-    delete f;
-
-    f = new FLAC::File(newname.c_str());
-    dict = f->properties();
-    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]);
-    delete f;
+    {
+      FLAC::File f(newname.c_str());
+      PropertyMap dict;
+      dict["ARTIST"].append("artøst 1");
+      dict["ARTIST"].append("artöst 2");
+      f.setProperties(dict);
+      f.save();
+    }
+    {
+      FLAC::File f(newname.c_str());
+      PropertyMap dict = f.properties();
+      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]);
+    }
   }
 
   void testInvalid()
index 58dbae42325225aceb8d0d670dc7b33477f5ac29..42d33b28ac8da4cf3416af5c629847d40986f0e6 100644 (file)
@@ -111,46 +111,45 @@ public:
     ScopedFileCopy copy("no-tags", ".3g2");
     string filename = copy.fileName();
 
-    MP4::File *f = new MP4::File(filename.c_str());
-    f->tag()->setArtist(ByteVector(3000, 'x'));
-
     ByteVectorList data1;
+
     {
-      MP4::Atoms a(f);
+      MP4::File f(filename.c_str());
+      f.tag()->setArtist(ByteVector(3000, 'x'));
+
+      MP4::Atoms a(&f);
       MP4::Atom *stco = a.find("moov")->findall("stco", true)[0];
-      f->seek(stco->offset + 12);
-      ByteVector data = f->readBlock(stco->length - 12);
+      f.seek(stco->offset + 12);
+      ByteVector data = f.readBlock(stco->length - 12);
       unsigned int count = data.mid(0, 4).toUInt();
       int pos = 4;
       while (count--) {
         unsigned int offset = data.mid(pos, 4).toUInt();
-        f->seek(offset);
-        data1.append(f->readBlock(20));
+        f.seek(offset);
+        data1.append(f.readBlock(20));
         pos += 4;
       }
-    }
 
-    f->save();
-    delete f;
-    f = new MP4::File(filename.c_str());
+      f.save();
+    }
 
     {
-      MP4::Atoms a(f);
+      MP4::File f(filename.c_str());
+
+      MP4::Atoms a(&f);
       MP4::Atom *stco = a.find("moov")->findall("stco", true)[0];
-      f->seek(stco->offset + 12);
-      ByteVector data = f->readBlock(stco->length - 12);
+      f.seek(stco->offset + 12);
+      ByteVector data = f.readBlock(stco->length - 12);
       unsigned int count = data.mid(0, 4).toUInt();
       int pos = 4, i = 0;
       while (count--) {
         unsigned int offset = data.mid(pos, 4).toUInt();
-        f->seek(offset);
-        CPPUNIT_ASSERT_EQUAL(data1[i], f->readBlock(20));
+        f.seek(offset);
+        CPPUNIT_ASSERT_EQUAL(data1[i], f.readBlock(20));
         pos += 4;
         i++;
       }
     }
-
-    delete f;
   }
 
   void testFreeForm()
@@ -158,18 +157,19 @@ public:
     ScopedFileCopy copy("has-tags", ".m4a");
     string filename = copy.fileName();
 
-    MP4::File *f = new MP4::File(filename.c_str());
-    CPPUNIT_ASSERT(f->tag()->contains("----:com.apple.iTunes:iTunNORM"));
-    f->tag()->setItem("----:org.kde.TagLib:Foo", StringList("Bar"));
-    f->save();
-    delete f;
-
-    f = new MP4::File(filename.c_str());
-    CPPUNIT_ASSERT(f->tag()->contains("----:org.kde.TagLib:Foo"));
-    CPPUNIT_ASSERT_EQUAL(String("Bar"),
-                         f->tag()->item("----:org.kde.TagLib:Foo").toStringList().front());
-    f->save();
-    delete f;
+    {
+      MP4::File f(filename.c_str());
+      CPPUNIT_ASSERT(f.tag()->contains("----:com.apple.iTunes:iTunNORM"));
+      f.tag()->setItem("----:org.kde.TagLib:Foo", StringList("Bar"));
+      f.save();
+    }
+    {
+      MP4::File f(filename.c_str());
+      CPPUNIT_ASSERT(f.tag()->contains("----:org.kde.TagLib:Foo"));
+      CPPUNIT_ASSERT_EQUAL(String("Bar"),
+                           f.tag()->item("----:org.kde.TagLib:Foo").toStringList().front());
+      f.save();
+    }
   }
 
   void testSaveExisingWhenIlstIsLast()
@@ -177,20 +177,21 @@ public:
     ScopedFileCopy copy("ilst-is-last", ".m4a");
     string filename = copy.fileName();
 
-    MP4::File *f = new MP4::File(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(String("82,164"),
-                         f->tag()->item("----:com.apple.iTunes:replaygain_track_minmax").toStringList().front());
-    CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f->tag()->artist());
-    f->tag()->setComment("foo");
-    f->save();
-    delete f;
-
-    f = new MP4::File(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(String("82,164"),
-                         f->tag()->item("----:com.apple.iTunes:replaygain_track_minmax").toStringList().front());
-    CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f->tag()->artist());
-    CPPUNIT_ASSERT_EQUAL(String("foo"), f->tag()->comment());
-    delete f;
+    {
+      MP4::File f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(String("82,164"),
+        f.tag()->item("----:com.apple.iTunes:replaygain_track_minmax").toStringList().front());
+      CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f.tag()->artist());
+      f.tag()->setComment("foo");
+      f.save();
+    }
+    {
+      MP4::File f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(String("82,164"),
+                           f.tag()->item("----:com.apple.iTunes:replaygain_track_minmax").toStringList().front());
+      CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f.tag()->artist());
+      CPPUNIT_ASSERT_EQUAL(String("foo"), f.tag()->comment());
+    }
   }
 
   void test64BitAtom()
@@ -198,48 +199,45 @@ public:
     ScopedFileCopy copy("64bit", ".mp4");
     string filename = copy.fileName();
 
-    MP4::File *f = new MP4::File(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(true, f->tag()->itemMap()["cpil"].toBool());
-
-    MP4::Atoms *atoms = new MP4::Atoms(f);
-    MP4::Atom *moov = atoms->atoms[0];
-    CPPUNIT_ASSERT_EQUAL(long(77), moov->length);
-
-    f->tag()->setItem("pgap", true);
-    f->save();
-    delete atoms;
-    delete f;
+    {
+      MP4::File f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(true, f.tag()->itemMap()["cpil"].toBool());
 
-    f = new MP4::File(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(true, f->tag()->item("cpil").toBool());
-    CPPUNIT_ASSERT_EQUAL(true, f->tag()->item("pgap").toBool());
+      MP4::Atoms atoms(&f);
+      MP4::Atom *moov = atoms.atoms[0];
+      CPPUNIT_ASSERT_EQUAL(long(77), moov->length);
 
-    atoms = new MP4::Atoms(f);
-    moov = atoms->atoms[0];
-    // original size + 'pgap' size + padding
-    CPPUNIT_ASSERT_EQUAL(long(77 + 25 + 974), moov->length);
-    delete atoms;
-    delete f;
+      f.tag()->setItem("pgap", true);
+      f.save();
+    }
+    {
+      MP4::File f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(true, f.tag()->item("cpil").toBool());
+      CPPUNIT_ASSERT_EQUAL(true, f.tag()->item("pgap").toBool());
+
+      MP4::Atoms atoms(&f);
+      MP4::Atom *moov = atoms.atoms[0];
+      // original size + 'pgap' size + padding
+      CPPUNIT_ASSERT_EQUAL(long(77 + 25 + 974), moov->length);
+    }
   }
 
   void testGnre()
   {
-    MP4::File *f = new MP4::File(TEST_FILE_PATH_C("gnre.m4a"));
-    CPPUNIT_ASSERT_EQUAL(TagLib::String("Ska"), f->tag()->genre());
-    delete f;
+    MP4::File f(TEST_FILE_PATH_C("gnre.m4a"));
+    CPPUNIT_ASSERT_EQUAL(TagLib::String("Ska"), f.tag()->genre());
   }
 
   void testCovrRead()
   {
-    MP4::File *f = new MP4::File(TEST_FILE_PATH_C("has-tags.m4a"));
-    CPPUNIT_ASSERT(f->tag()->contains("covr"));
-    MP4::CoverArtList l = f->tag()->item("covr").toCoverArtList();
+    MP4::File f(TEST_FILE_PATH_C("has-tags.m4a"));
+    CPPUNIT_ASSERT(f.tag()->contains("covr"));
+    MP4::CoverArtList l = f.tag()->item("covr").toCoverArtList();
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size());
     CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size());
     CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size());
-    delete f;
   }
 
   void testCovrWrite()
@@ -247,38 +245,38 @@ public:
     ScopedFileCopy copy("has-tags", ".m4a");
     string filename = copy.fileName();
 
-    MP4::File *f = new MP4::File(filename.c_str());
-    CPPUNIT_ASSERT(f->tag()->contains("covr"));
-    MP4::CoverArtList l = f->tag()->item("covr").toCoverArtList();
-    l.append(MP4::CoverArt(MP4::CoverArt::PNG, "foo"));
-    f->tag()->setItem("covr", l);
-    f->save();
-    delete f;
-
-    f = new MP4::File(filename.c_str());
-    CPPUNIT_ASSERT(f->tag()->contains("covr"));
-    l = f->tag()->item("covr").toCoverArtList();
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), l.size());
-    CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size());
-    CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size());
-    CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), l[2].data().size());
-    delete f;
+    {
+      MP4::File f(filename.c_str());
+      CPPUNIT_ASSERT(f.tag()->contains("covr"));
+      MP4::CoverArtList l = f.tag()->item("covr").toCoverArtList();
+      l.append(MP4::CoverArt(MP4::CoverArt::PNG, "foo"));
+      f.tag()->setItem("covr", l);
+      f.save();
+    }
+    {
+      MP4::File f(filename.c_str());
+      CPPUNIT_ASSERT(f.tag()->contains("covr"));
+      MP4::CoverArtList l = f.tag()->item("covr").toCoverArtList();
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), l.size());
+      CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size());
+      CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size());
+      CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), l[2].data().size());
+    }
   }
 
   void testCovrRead2()
   {
-    MP4::File *f = new MP4::File(TEST_FILE_PATH_C("covr-junk.m4a"));
-    CPPUNIT_ASSERT(f->tag()->contains("covr"));
-    MP4::CoverArtList l = f->tag()->item("covr").toCoverArtList();
+    MP4::File f(TEST_FILE_PATH_C("covr-junk.m4a"));
+    CPPUNIT_ASSERT(f.tag()->contains("covr"));
+    MP4::CoverArtList l = f.tag()->item("covr").toCoverArtList();
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size());
     CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size());
     CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size());
-    delete f;
   }
 
   void testProperties()
index 90ae162d54ee8a7a09eb17a751422ccf557371e4..0fc7cfef72b5598003239670854f2613febc027b 100644 (file)
@@ -31,14 +31,15 @@ public:
     ScopedFileCopy copy("empty", ".ogg");
     string newname = copy.fileName();
 
-    Vorbis::File *f = new Vorbis::File(newname.c_str());
-    f->tag()->setArtist("The Artist");
-    f->save();
-    delete f;
-
-    f = new Vorbis::File(newname.c_str());
-    CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
-    delete f;
+    {
+      Vorbis::File f(newname.c_str());
+      f.tag()->setArtist("The Artist");
+      f.save();
+    }
+    {
+      Vorbis::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist());
+    }
   }
 
   void testSplitPackets()
@@ -50,24 +51,25 @@ public:
     for (size_t i = 0; i < longText.length(); ++i)
       longText[i] = static_cast<wchar>(L'A' + (i % 26));
 
-    Vorbis::File *f = new Vorbis::File(newname.c_str());
-    f->tag()->setTitle(longText);
-    f->save();
-    delete f;
-
-    f = new Vorbis::File(newname.c_str());
-    CPPUNIT_ASSERT(f->isValid());
-    CPPUNIT_ASSERT_EQUAL(19, f->lastPageHeader()->pageSequenceNumber());
-    CPPUNIT_ASSERT_EQUAL(longText, f->tag()->title());
-    f->tag()->setTitle("ABCDE");
-    f->save();
-    delete f;
-
-    f = new Vorbis::File(newname.c_str());
-    CPPUNIT_ASSERT(f->isValid());
-    CPPUNIT_ASSERT_EQUAL(3, f->lastPageHeader()->pageSequenceNumber());
-    CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f->tag()->title());
-    delete f;
+    {
+      Vorbis::File f(newname.c_str());
+      f.tag()->setTitle(longText);
+      f.save();
+    }
+    {
+      Vorbis::File f(newname.c_str());
+      CPPUNIT_ASSERT(f.isValid());
+      CPPUNIT_ASSERT_EQUAL(19, f.lastPageHeader()->pageSequenceNumber());
+      CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title());
+      f.tag()->setTitle("ABCDE");
+      f.save();
+    }
+    {
+      Vorbis::File f(newname.c_str());
+      CPPUNIT_ASSERT(f.isValid());
+      CPPUNIT_ASSERT_EQUAL(3, f.lastPageHeader()->pageSequenceNumber());
+      CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
+    }
   }
 
   void testDictInterface1()
@@ -75,22 +77,20 @@ public:
     ScopedFileCopy copy("empty", ".ogg");
     string newname = copy.fileName();
 
-    Vorbis::File *f = new Vorbis::File(newname.c_str());
+    Vorbis::File f(newname.c_str());
 
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->tag()->properties().size());
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.tag()->properties().size());
 
     PropertyMap newTags;
     StringList values("value 1");
     values.append("value 2");
     newTags["ARTIST"] = values;
-    f->tag()->setProperties(newTags);
+    f.tag()->setProperties(newTags);
 
-    PropertyMap map = f->tag()->properties();
+    PropertyMap map = f.tag()->properties();
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), map.size());
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), map["ARTIST"].size());
     CPPUNIT_ASSERT_EQUAL(String("value 1"), map["ARTIST"][0]);
-    delete f;
-
   }
 
   void testDictInterface2()
@@ -98,8 +98,8 @@ public:
     ScopedFileCopy copy("test", ".ogg");
     string newname = copy.fileName();
 
-    Vorbis::File *f = new Vorbis::File(newname.c_str());
-    PropertyMap tags = f->tag()->properties();
+    Vorbis::File f(newname.c_str());
+    PropertyMap tags = f.tag()->properties();
 
     CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), tags["UNUSUALTAG"].size());
     CPPUNIT_ASSERT_EQUAL(String("usual value"), tags["UNUSUALTAG"][0]);
@@ -111,13 +111,11 @@ public:
     tags["UNICODETAG"][0] = String(
       "\xCE\xBD\xCE\xB5\xCF\x89\x20\xCE\xBD\xCE\xB1\xCE\xBB\xCF\x85\xCE\xB5", String::UTF8);
     tags.erase("UNUSUALTAG");
-    f->tag()->setProperties(tags);
+    f.tag()->setProperties(tags);
     CPPUNIT_ASSERT_EQUAL(
       String("\xCE\xBD\xCE\xB5\xCF\x89\x20\xCE\xBD\xCE\xB1\xCE\xBB\xCF\x85\xCE\xB5", String::UTF8),
-      f->tag()->properties()["UNICODETAG"][0]);
-    CPPUNIT_ASSERT_EQUAL(false, f->tag()->properties().contains("UNUSUALTAG"));
-
-    delete f;
+      f.tag()->properties()["UNICODETAG"][0]);
+    CPPUNIT_ASSERT_EQUAL(false, f.tag()->properties().contains("UNUSUALTAG"));
   }
 
   void testAudioProperties()
index 975af44ed5f4c7f2fa2c8edc909c681cc250513c..e0f5bb164c46aa2bc8a57c061e606f519dd717a5 100644 (file)
@@ -25,19 +25,18 @@ public:
     ScopedFileCopy copy("empty_flac", ".oga");
     string newname = copy.fileName();
 
-    Ogg::FLAC::File *f = new Ogg::FLAC::File(newname.c_str());
-    f->tag()->setArtist("The Artist");
-    f->save();
-    delete f;
-
-    f = new Ogg::FLAC::File(newname.c_str());
-    CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
-
-    f->seek(0, File::End);
-    int size = f->tell();
-    CPPUNIT_ASSERT_EQUAL(9134, size);
-
-    delete f;
+    {
+      Ogg::FLAC::File f(newname.c_str());
+      f.tag()->setArtist("The Artist");
+      f.save();
+    }
+    {
+      Ogg::FLAC::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist());
+
+      f.seek(0, File::End);
+      CPPUNIT_ASSERT_EQUAL(9134L, f.tell());
+    }
   }
 
   void testFuzzedFile()
index 73863bf8314ec067fd3290522a826c7f78aeec58..398e7e91877a9a38fbe61f0bed7c53582fde5b14 100644 (file)
@@ -47,17 +47,18 @@ public:
     ScopedFileCopy copy("correctness_gain_silent_output", ".opus");
     string filename = copy.fileName();
 
-    Ogg::Opus::File *f = new Ogg::Opus::File(filename.c_str());
-    f->tag()->setArtist("Your Tester");
-    f->save();
-    delete f;
-
-    f = new Ogg::Opus::File(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(StringList("Xiph.Org Opus testvectormaker"), f->tag()->fieldListMap()["ENCODER"]);
-    CPPUNIT_ASSERT(f->tag()->fieldListMap().contains("TESTDESCRIPTION"));
-    CPPUNIT_ASSERT_EQUAL(StringList("Your Tester"), f->tag()->fieldListMap()["ARTIST"]);
-    CPPUNIT_ASSERT_EQUAL(String("libopus 0.9.11-66-g64c2dd7"), f->tag()->vendorID());
-    delete f;
+    {
+      Ogg::Opus::File f(filename.c_str());
+      f.tag()->setArtist("Your Tester");
+      f.save();
+    }
+    {
+      Ogg::Opus::File f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(StringList("Xiph.Org Opus testvectormaker"), f.tag()->fieldListMap()["ENCODER"]);
+      CPPUNIT_ASSERT(f.tag()->fieldListMap().contains("TESTDESCRIPTION"));
+      CPPUNIT_ASSERT_EQUAL(StringList("Your Tester"), f.tag()->fieldListMap()["ARTIST"]);
+      CPPUNIT_ASSERT_EQUAL(String("libopus 0.9.11-66-g64c2dd7"), f.tag()->vendorID());
+    }
   }
 
 };
index e07687f13d701fdd6ee10c8f4b136915a8a11dbf..4ee8d080bbcd2ece1d095345f95e35f0bfb955a1 100644 (file)
@@ -50,44 +50,42 @@ public:
     ScopedFileCopy copy("empty", ".aiff");
     string filename = copy.fileName();
 
-    PublicRIFF *f = new PublicRIFF(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f->chunkOffset(2));
-
-    f->setChunkData("TEST", "foo");
-    delete f;
-
-    f = new PublicRIFF(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f->chunkOffset(2));
-
-    f->setChunkData("SSND", "abcd");
-
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f->chunkData(1));
-
-    f->seek(f->chunkOffset(1));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f->readBlock(4));
-
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2));
-
-    f->seek(f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->readBlock(3));
-
-    delete f;
-
-    f = new PublicRIFF(filename.c_str());
-
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f->chunkData(1));
-
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2));
-
-    delete f;
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f.chunkOffset(2));
+
+      f.setChunkData("TEST", "foo");
+    }
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f.chunkData(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f.chunkOffset(2));
+
+      f.setChunkData("SSND", "abcd");
+
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f.chunkData(1));
+
+      f.seek(f.chunkOffset(1));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f.readBlock(4));
+
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f.chunkData(2));
+
+      f.seek(f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f.readBlock(3));
+    }
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f.chunkData(1));
+
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f.chunkData(2));
+    }
   }
 
   void testLastChunkAtEvenPosition()
@@ -95,36 +93,37 @@ public:
     ScopedFileCopy copy("noise", ".aif");
     string filename = copy.fileName();
 
-    PublicRIFF *f = new PublicRIFF(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(long(4400), f->length());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize());
-    f->setChunkData("TEST", "abcd");
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f->chunkOffset(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4412 - 8), f->riffSize());
-    delete f;
-
-    f = new PublicRIFF(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f->chunkOffset(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3));
-    CPPUNIT_ASSERT_EQUAL(long(4412), f->length());
-    delete f;
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(long(4400), f.length());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize());
+      f.setChunkData("TEST", "abcd");
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f.chunkOffset(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f.chunkDataSize(3));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4412 - 8), f.riffSize());
+    }
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f.chunkOffset(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f.chunkDataSize(3));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(3));
+      CPPUNIT_ASSERT_EQUAL(long(4412), f.length());
+    }
   }
 
   void testLastChunkAtEvenPosition2()
@@ -132,36 +131,37 @@ public:
     ScopedFileCopy copy("noise_odd", ".aif");
     string filename = copy.fileName();
 
-    PublicRIFF *f = new PublicRIFF(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(long(4399), f->length());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize());
-    f->setChunkData("TEST", "abcd");
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f->chunkOffset(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4412 - 8), f->riffSize());
-    delete f;
-
-    f = new PublicRIFF(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f->chunkOffset(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3));
-    CPPUNIT_ASSERT_EQUAL(long(4412), f->length());
-    delete f;
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(long(4399), f.length());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize());
+      f.setChunkData("TEST", "abcd");
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f.chunkOffset(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f.chunkDataSize(3));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4412 - 8), f.riffSize());
+    }
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f.chunkOffset(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f.chunkDataSize(3));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(3));
+      CPPUNIT_ASSERT_EQUAL(long(4412), f.length());
+    }
   }
 
   void testLastChunkAtEvenPosition3()
@@ -169,36 +169,37 @@ public:
     ScopedFileCopy copy("noise_odd", ".aif");
     string filename = copy.fileName();
 
-    PublicRIFF *f = new PublicRIFF(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(long(4399), f->length());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize());
-    f->setChunkData("TEST", "abc");
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f->chunkOffset(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f->chunkDataSize(3));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4411 - 8), f->riffSize());
-    delete f;
-
-    f = new PublicRIFF(filename.c_str());
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f->chunkOffset(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f->chunkDataSize(3));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(3));
-    CPPUNIT_ASSERT_EQUAL(long(4412), f->length());
-    delete f;
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(long(4399), f.length());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize());
+      f.setChunkData("TEST", "abc");
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f.chunkOffset(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f.chunkDataSize(3));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4411 - 8), f.riffSize());
+    }
+    {
+      PublicRIFF f(filename.c_str());
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f.chunkOffset(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(4408), f.chunkOffset(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f.chunkDataSize(3));
+      CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3));
+      CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(3));
+      CPPUNIT_ASSERT_EQUAL(long(4412), f.length());
+    }
   }
 
   void testChunkOffset()
@@ -206,56 +207,54 @@ public:
     ScopedFileCopy copy("empty", ".aiff");
     string filename = copy.fileName();
 
-    PublicRIFF *f = new PublicRIFF(filename.c_str());
+    PublicRIFF f(filename.c_str());
 
-    CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->chunkName(0));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f->chunkOffset(1));
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f->chunkOffset(2));
+    CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.chunkName(0));
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0));
+    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1));
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f.chunkOffset(1));
+    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2));
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f.chunkOffset(2));
 
     const ByteVector data(0x400, ' ');
-    f->setChunkData("SSND", data);
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f->chunkOffset(1));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x042E + 8), f->chunkOffset(2));
-
-    f->seek(f->chunkOffset(0) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4));
-    f->seek(f->chunkOffset(1) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->readBlock(4));
-    f->seek(f->chunkOffset(2) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4));
-
-    f->setChunkData(0, data);
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f->chunkOffset(1));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x081C + 8), f->chunkOffset(2));
-
-    f->seek(f->chunkOffset(0) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4));
-    f->seek(f->chunkOffset(1) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->readBlock(4));
-    f->seek(f->chunkOffset(2) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4));
-
-    f->removeChunk("SSND");
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f->chunkOffset(1));
-
-    f->seek(f->chunkOffset(0) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4));
-    f->seek(f->chunkOffset(1) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4));
-
-    f->removeChunk(0);
-    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
-
-    f->seek(f->chunkOffset(0) - 8);
-    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4));
-
-    delete f;
+    f.setChunkData("SSND", data);
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0));
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f.chunkOffset(1));
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x042E + 8), f.chunkOffset(2));
+
+    f.seek(f.chunkOffset(0) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.readBlock(4));
+    f.seek(f.chunkOffset(1) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.readBlock(4));
+    f.seek(f.chunkOffset(2) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4));
+
+    f.setChunkData(0, data);
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0));
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f.chunkOffset(1));
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x081C + 8), f.chunkOffset(2));
+
+    f.seek(f.chunkOffset(0) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.readBlock(4));
+    f.seek(f.chunkOffset(1) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.readBlock(4));
+    f.seek(f.chunkOffset(2) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4));
+
+    f.removeChunk("SSND");
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0));
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f.chunkOffset(1));
+
+    f.seek(f.chunkOffset(0) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.readBlock(4));
+    f.seek(f.chunkOffset(1) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4));
+
+    f.removeChunk(0);
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0));
+
+    f.seek(f.chunkOffset(0) - 8);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4));
   }
 
 };
index 24bb02c5d39cafe14a27c101b0b4137eee87efba..d7bc48816028a8fa468b40d504b53990e820f52f 100644 (file)
@@ -154,36 +154,37 @@ public:
     ScopedFileCopy copy("empty", ".wav");
     string filename = copy.fileName();
 
-    RIFF::WAV::File *f = new RIFF::WAV::File(filename.c_str());
-    f->ID3v2Tag()->setTitle("test title");
-    f->InfoTag()->setTitle("test title");
-    f->save();
-    delete f;
-
-    f = new RIFF::WAV::File(filename.c_str());
-    CPPUNIT_ASSERT(f->hasID3v2Tag());
-    CPPUNIT_ASSERT(f->hasInfoTag());
-    f->save(RIFF::WAV::File::ID3v2, true);
-    delete f;
-
-    f = new RIFF::WAV::File(filename.c_str());
-    CPPUNIT_ASSERT(f->hasID3v2Tag());
-    CPPUNIT_ASSERT(!f->hasInfoTag());
-    f->ID3v2Tag()->setTitle("test title");
-    f->InfoTag()->setTitle("test title");
-    f->save();
-    delete f;
-
-    f = new RIFF::WAV::File(filename.c_str());
-    CPPUNIT_ASSERT(f->hasID3v2Tag());
-    CPPUNIT_ASSERT(f->hasInfoTag());
-    f->save(RIFF::WAV::File::Info, true);
-    delete f;
-
-    f = new RIFF::WAV::File(filename.c_str());
-    CPPUNIT_ASSERT(!f->hasID3v2Tag());
-    CPPUNIT_ASSERT(f->hasInfoTag());
-    delete f;
+    {
+      RIFF::WAV::File f(filename.c_str());
+      f.ID3v2Tag()->setTitle("test title");
+      f.InfoTag()->setTitle("test title");
+      f.save();
+    }
+    {
+      RIFF::WAV::File f(filename.c_str());
+      CPPUNIT_ASSERT(f.hasID3v2Tag());
+      CPPUNIT_ASSERT(f.hasInfoTag());
+      f.save(RIFF::WAV::File::ID3v2, true);
+    }
+    {
+      RIFF::WAV::File f(filename.c_str());
+      CPPUNIT_ASSERT(f.hasID3v2Tag());
+      CPPUNIT_ASSERT(!f.hasInfoTag());
+      f.ID3v2Tag()->setTitle("test title");
+      f.InfoTag()->setTitle("test title");
+      f.save();
+    }
+    {
+      RIFF::WAV::File f(filename.c_str());
+      CPPUNIT_ASSERT(f.hasID3v2Tag());
+      CPPUNIT_ASSERT(f.hasInfoTag());
+      f.save(RIFF::WAV::File::Info, true);
+    }
+    {
+      RIFF::WAV::File f(filename.c_str());
+      CPPUNIT_ASSERT(!f.hasID3v2Tag());
+      CPPUNIT_ASSERT(f.hasInfoTag());
+    }
   }
 
   void testDuplicateTags()