mirror of
https://github.com/taglib/taglib.git
synced 2025-07-18 21:14:23 -04:00
Full read/write support for FLAC pictures
NEEDS MORE TESTING BUG:218696 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1212863 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
@ -41,7 +41,6 @@ SET(test_runner_SRCS
|
||||
test_oggflac.cpp
|
||||
test_flac.cpp
|
||||
test_flacpicture.cpp
|
||||
test_flacmetadatablocks.cpp
|
||||
test_flacunknownmetadatablock.cpp
|
||||
test_ape.cpp
|
||||
test_apetag.cpp
|
||||
|
@ -15,7 +15,11 @@ class TestFLAC : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST_SUITE(TestFLAC);
|
||||
CPPUNIT_TEST(testSignature);
|
||||
CPPUNIT_TEST(testMultipleCommentBlocks);
|
||||
CPPUNIT_TEST(testPicture);
|
||||
CPPUNIT_TEST(testReadPicture);
|
||||
CPPUNIT_TEST(testAddPicture);
|
||||
CPPUNIT_TEST(testReplacePicture);
|
||||
CPPUNIT_TEST(testRemoveAllPictures);
|
||||
CPPUNIT_TEST(testRepeatedSave);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -42,7 +46,7 @@ public:
|
||||
delete f;
|
||||
}
|
||||
|
||||
void testPicture()
|
||||
void testReadPicture()
|
||||
{
|
||||
ScopedFileCopy copy("silence-44-s", ".flac");
|
||||
string newname = copy.fileName();
|
||||
@ -52,7 +56,7 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
|
||||
|
||||
FLAC::Picture *pic = lst.front();
|
||||
CPPUNIT_ASSERT_EQUAL(3, int(pic->type()));
|
||||
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());
|
||||
@ -62,6 +66,136 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size());
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
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();
|
||||
|
||||
f = new FLAC::File(newname.c_str());
|
||||
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());
|
||||
|
||||
f = new FLAC::File(newname.c_str());
|
||||
tag = f->tag();
|
||||
CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), tag->title());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);
|
||||
|
@ -1,41 +0,0 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <tag.h>
|
||||
#include <tstringlist.h>
|
||||
#include <tbytevectorlist.h>
|
||||
#include <flacfile.h>
|
||||
#include <flacmetadatablock.h>
|
||||
#include <flacmetadatablocks.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestFLACMetadataBlocks : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestFLACMetadataBlocks);
|
||||
CPPUNIT_TEST(testRead);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testRead()
|
||||
{
|
||||
FLAC::File f("data/silence-44-s.flac");
|
||||
FLAC::MetadataBlocks b;
|
||||
f.seek(4);
|
||||
b.read(&f);
|
||||
List<FLAC::MetadataBlock *> blocks = b.metadataBlockList();
|
||||
CPPUNIT_ASSERT_EQUAL(TagLib::uint(5), blocks.size());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::StreamInfo, blocks[0]->code());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::SeekTable, blocks[1]->code());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::VorbisComment, blocks[2]->code());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::CueSheet, blocks[3]->code());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::Picture, blocks[4]->code());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLACMetadataBlocks);
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <tbytevectorlist.h>
|
||||
#include <flacfile.h>
|
||||
#include <flacmetadatablock.h>
|
||||
#include <flacmetadatablocks.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
Reference in New Issue
Block a user