delete statements are skipped when assertions fail.
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()
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()
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()
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()
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()
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()
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()
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()
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()
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);
+ }
}
};
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()
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();
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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]);
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()
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()
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());
+ }
}
};
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()
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()
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()
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()
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));
}
};
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()