Merge branch 'master' into merge-master-to-taglib2

# Conflicts:
#	CMakeLists.txt
#	examples/CMakeLists.txt
#	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_riff.cpp
This commit is contained in:
Tsuda Kageyu
2015-11-30 11:11:23 +09:00
20 changed files with 886 additions and 729 deletions

View 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(size_t(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(size_t(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(size_t(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(size_t(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()

View File

@ -54,57 +54,55 @@ public:
ScopedFileCopy copy(filename, ext);
string newname = copy.fileName();
FileRef *f = new FileRef(newname.c_str());
CPPUNIT_ASSERT(f->isValid());
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->isValid());
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->isValid());
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()
@ -174,18 +172,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()
@ -204,16 +200,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);
}
}
};

View 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(size_t(1), lst.size());
FLAC::Picture *pic = lst.front();
@ -73,7 +74,6 @@ public:
CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType());
CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description());
CPPUNIT_ASSERT_EQUAL(size_t(150), pic->data().size());
delete f;
}
void testAddPicture()
@ -81,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(size_t(1), lst.size());
{
FLAC::File f(newname.c_str());
List<FLAC::Picture *> lst = f.pictureList();
CPPUNIT_ASSERT_EQUAL(size_t(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;
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(size_t(2), lst.size());
f = new FLAC::File(newname.c_str());
lst = f->pictureList();
CPPUNIT_ASSERT_EQUAL(size_t(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(size_t(150), pic->data().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(size_t(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;
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()
@ -129,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(size_t(1), lst.size());
{
FLAC::File f(newname.c_str());
List<FLAC::Picture *> lst = f.pictureList();
CPPUNIT_ASSERT_EQUAL(size_t(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;
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(size_t(1), lst.size());
f = new FLAC::File(newname.c_str());
lst = f->pictureList();
CPPUNIT_ASSERT_EQUAL(size_t(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::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()
@ -168,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(size_t(1), lst.size());
{
FLAC::File f(newname.c_str());
List<FLAC::Picture *> lst = f.pictureList();
CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size());
f->removePictures();
f->save();
delete f;
f = new FLAC::File(newname.c_str());
lst = f->pictureList();
CPPUNIT_ASSERT_EQUAL(size_t(0), lst.size());
delete f;
f.removePictures();
f.save();
}
{
FLAC::File f(newname.c_str());
List<FLAC::Picture *> lst = f.pictureList();
CPPUNIT_ASSERT_EQUAL(size_t(0), lst.size());
}
}
void testRepeatedSave()
@ -187,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()
@ -209,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(size_t(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(size_t(2), m["ARTIST"].size());
CPPUNIT_ASSERT_EQUAL(String("artist 1"), m["ARTIST"][0]);
CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]);
}
}
void testDict()

View 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(static_cast<size_t>(stco->length - 12));
unsigned int count = data.toUInt32BE(0);
size_t pos = 4;
f.seek(stco->offset + 12);
ByteVector data = f.readBlock(static_cast<size_t>(stco->length - 12));
unsigned int count = data.mid(0, 4).toUInt32BE(0);
int pos = 4;
while (count--) {
unsigned int offset = data.toUInt32BE(pos);
f->seek(offset);
data1.append(f->readBlock(20));
unsigned int offset = data.mid(pos, 4).toUInt32BE(0);
f.seek(offset);
data1.append(f.readBlock(20));
pos += 4;
}
f.save();
}
f->save();
delete f;
f = new MP4::File(filename.c_str());
{
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(static_cast<size_t>(stco->length - 12));
unsigned int count = data.toUInt32BE(0);
size_t pos = 4, i = 0;
f.seek(stco->offset + 12);
ByteVector data = f.readBlock(static_cast<size_t>(stco->length - 12));
unsigned int count = data.mid(0, 4).toUInt32BE(0);
int pos = 4, i = 0;
while (count--) {
unsigned int offset = data.toUInt32BE(pos);
f->seek(offset);
CPPUNIT_ASSERT_EQUAL(data1[i], f->readBlock(20));
unsigned int offset = data.mid(pos, 4).toUInt32BE(0);
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::File f(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(offset_t(77), moov->length);
MP4::Atoms atoms(&f);
MP4::Atom *moov = atoms.atoms[0];
CPPUNIT_ASSERT_EQUAL(offset_t(77), moov->length);
f->tag()->setItem("pgap", true);
f->save();
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());
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());
atoms = new MP4::Atoms(f);
moov = atoms->atoms[0];
// original size + 'pgap' size + padding
CPPUNIT_ASSERT_EQUAL(offset_t(77 + 25 + 974), moov->length);
delete atoms;
delete f;
MP4::Atoms atoms(&f);
MP4::Atom *moov = atoms.atoms[0];
// original size + 'pgap' size + padding
CPPUNIT_ASSERT_EQUAL(offset_t(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(size_t(2), l.size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
CPPUNIT_ASSERT_EQUAL(size_t(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(size_t(3), l.size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format());
CPPUNIT_ASSERT_EQUAL(size_t(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(size_t(3), l.size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format());
CPPUNIT_ASSERT_EQUAL(size_t(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(size_t(2), l.size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size());
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size());
delete f;
}
void testProperties()

View File

@ -31,14 +31,15 @@ public:
ScopedFileCopy copy("empty", ".ogg");
string newname = copy.fileName();
Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str());
f->tag()->setArtist("The Artist");
f->save();
delete f;
f = new Ogg::Vorbis::File(newname.c_str());
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
delete f;
{
Ogg::Vorbis::File f(newname.c_str());
f.tag()->setArtist("The Artist");
f.save();
}
{
Ogg::Vorbis::File f(newname.c_str());
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist());
}
}
void testSplitPackets()
@ -50,24 +51,40 @@ public:
for (size_t i = 0; i < longText.length(); ++i)
longText[i] = static_cast<wchar>(L'A' + (i % 26));
Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str());
f->tag()->setTitle(longText);
f->save();
delete f;
{
Ogg::Vorbis::File f(newname.c_str());
f.tag()->setTitle(longText);
f.save();
}
{
Ogg::Vorbis::File f(newname.c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)136383, f.length());
CPPUNIT_ASSERT_EQUAL(19, f.lastPageHeader()->pageSequenceNumber());
CPPUNIT_ASSERT_EQUAL((size_t)30, f.packet(0).size());
CPPUNIT_ASSERT_EQUAL((size_t)131127, f.packet(1).size());
CPPUNIT_ASSERT_EQUAL((size_t)3832, f.packet(2).size());
CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title());
f = new Ogg::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;
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
f = new Ogg::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;
f.tag()->setTitle("ABCDE");
f.save();
}
{
Ogg::Vorbis::File f(newname.c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)4370, f.length());
CPPUNIT_ASSERT_EQUAL(3, f.lastPageHeader()->pageSequenceNumber());
CPPUNIT_ASSERT_EQUAL((size_t)30, f.packet(0).size());
CPPUNIT_ASSERT_EQUAL((size_t)60, f.packet(1).size());
CPPUNIT_ASSERT_EQUAL((size_t)3832, f.packet(2).size());
CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
}
}
void testDictInterface1()
@ -75,22 +92,20 @@ public:
ScopedFileCopy copy("empty", ".ogg");
string newname = copy.fileName();
Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str());
Ogg::Vorbis::File f(newname.c_str());
CPPUNIT_ASSERT_EQUAL(size_t(0), f->tag()->properties().size());
CPPUNIT_ASSERT_EQUAL(size_t(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(size_t(1), map.size());
CPPUNIT_ASSERT_EQUAL(size_t(2), map["ARTIST"].size());
CPPUNIT_ASSERT_EQUAL(String("value 1"), map["ARTIST"][0]);
delete f;
}
void testDictInterface2()
@ -98,8 +113,8 @@ public:
ScopedFileCopy copy("test", ".ogg");
string newname = copy.fileName();
Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str());
PropertyMap tags = f->tag()->properties();
Ogg::Vorbis::File f(newname.c_str());
PropertyMap tags = f.tag()->properties();
CPPUNIT_ASSERT_EQUAL(size_t(2), tags["UNUSUALTAG"].size());
CPPUNIT_ASSERT_EQUAL(String("usual value"), tags["UNUSUALTAG"][0]);
@ -111,13 +126,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()

View File

@ -5,6 +5,7 @@
#include <tbytevectorlist.h>
#include <oggfile.h>
#include <oggflacfile.h>
#include <oggpageheader.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -16,6 +17,7 @@ class TestOggFLAC : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(TestOggFLAC);
CPPUNIT_TEST(testFramingBit);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST(testSplitPackets);
CPPUNIT_TEST_SUITE_END();
public:
@ -25,19 +27,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;
{
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 = new Ogg::FLAC::File(newname.c_str());
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
f->seek(0, File::End);
offset_t size = f->tell();
CPPUNIT_ASSERT_EQUAL((offset_t)9134, size);
delete f;
f.seek(0, File::End);
CPPUNIT_ASSERT_EQUAL((offset_t)9134, f.tell());
}
}
void testFuzzedFile()
@ -46,6 +47,53 @@ public:
CPPUNIT_ASSERT(!f.isValid());
}
void testSplitPackets()
{
ScopedFileCopy copy("empty_flac", ".oga");
string newname = copy.fileName();
String longText(std::string(128 * 1024, ' ').c_str());
for(size_t i = 0; i < longText.length(); ++i)
longText[i] = static_cast<wchar>(L'A' + (i % 26));
{
Ogg::FLAC::File f(newname.c_str());
f.tag()->setTitle(longText);
f.save();
}
{
Ogg::FLAC::File f(newname.c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)141141, f.length());
CPPUNIT_ASSERT_EQUAL(21, f.lastPageHeader()->pageSequenceNumber());
CPPUNIT_ASSERT_EQUAL((size_t)51, f.packet(0).size());
CPPUNIT_ASSERT_EQUAL((size_t)131126, f.packet(1).size());
CPPUNIT_ASSERT_EQUAL((size_t)22, f.packet(2).size());
CPPUNIT_ASSERT_EQUAL((size_t)8196, f.packet(3).size());
CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds());
f.tag()->setTitle("ABCDE");
f.save();
}
{
Ogg::FLAC::File f(newname.c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)9128, f.length());
CPPUNIT_ASSERT_EQUAL(5, f.lastPageHeader()->pageSequenceNumber());
CPPUNIT_ASSERT_EQUAL((size_t)51, f.packet(0).size());
CPPUNIT_ASSERT_EQUAL((size_t)59, f.packet(1).size());
CPPUNIT_ASSERT_EQUAL((size_t)22, f.packet(2).size());
CPPUNIT_ASSERT_EQUAL((size_t)8196, f.packet(3).size());
CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestOggFLAC);

View File

@ -3,6 +3,7 @@
#include <tag.h>
#include <tbytevectorlist.h>
#include <opusfile.h>
#include <oggpageheader.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -15,6 +16,7 @@ class TestOpus : public CppUnit::TestFixture
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST(testReadComments);
CPPUNIT_TEST(testWriteComments);
CPPUNIT_TEST(testSplitPackets);
CPPUNIT_TEST_SUITE_END();
public:
@ -47,17 +49,65 @@ 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;
{
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());
}
}
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;
void testSplitPackets()
{
ScopedFileCopy copy("correctness_gain_silent_output", ".opus");
string newname = copy.fileName();
String longText(std::string(128 * 1024, ' ').c_str());
for(size_t i = 0; i < longText.length(); ++i)
longText[i] = static_cast<wchar>(L'A' + (i % 26));
{
Ogg::Opus::File f(newname.c_str());
f.tag()->setTitle(longText);
f.save();
}
{
Ogg::Opus::File f(newname.c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)167534, f.length());
CPPUNIT_ASSERT_EQUAL(27, f.lastPageHeader()->pageSequenceNumber());
CPPUNIT_ASSERT_EQUAL((size_t)19, f.packet(0).size());
CPPUNIT_ASSERT_EQUAL((size_t)131380, f.packet(1).size());
CPPUNIT_ASSERT_EQUAL((size_t)5, f.packet(2).size());
CPPUNIT_ASSERT_EQUAL((size_t)5, f.packet(3).size());
CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds());
f.tag()->setTitle("ABCDE");
f.save();
}
{
Ogg::Opus::File f(newname.c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)35521, f.length());
CPPUNIT_ASSERT_EQUAL(11, f.lastPageHeader()->pageSequenceNumber());
CPPUNIT_ASSERT_EQUAL((size_t)19, f.packet(0).size());
CPPUNIT_ASSERT_EQUAL((size_t)313, f.packet(1).size());
CPPUNIT_ASSERT_EQUAL((size_t)5, f.packet(2).size());
CPPUNIT_ASSERT_EQUAL((size_t)5, f.packet(3).size());
CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds());
}
}
};

View 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(offset_t(0x1728 + 8), f->chunkOffset(2));
{
PublicRIFF f(filename.c_str());
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2));
CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f.chunkOffset(2));
f->setChunkData("TEST", "foo");
delete f;
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(offset_t(0x1728 + 8), f.chunkOffset(2));
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(offset_t(0x1728 + 8), f->chunkOffset(2));
f.setChunkData("SSND", "abcd");
f->setChunkData("SSND", "abcd");
CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1));
CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f.chunkData(1));
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));
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));
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));
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;
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(offset_t(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(offset_t(4400), f->length());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize());
f->setChunkData("TEST", "abcd");
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(4412), f->length());
delete f;
{
PublicRIFF f(filename.c_str());
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(4400), f.length());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize());
f.setChunkData("TEST", "abcd");
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(4399), f->length());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize());
f->setChunkData("TEST", "abcd");
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(4412), f->length());
delete f;
{
PublicRIFF f(filename.c_str());
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(4399), f.length());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize());
f.setChunkData("TEST", "abcd");
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(4399), f->length());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize());
f->setChunkData("TEST", "abc");
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(4412), f->length());
delete f;
{
PublicRIFF f(filename.c_str());
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(4399), f.length());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize());
f.setChunkData("TEST", "abc");
CPPUNIT_ASSERT_EQUAL(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(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(offset_t(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1));
CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f->chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f->chunkOffset(2));
CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.chunkName(0));
CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1));
CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f.chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2));
CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f.chunkOffset(2));
const ByteVector data(0x400, ' ');
f->setChunkData("SSND", data);
CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f->chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(offset_t(0x042E + 8), f->chunkOffset(2));
f.setChunkData("SSND", data);
CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f.chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(offset_t(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.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(offset_t(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(offset_t(0x0414 + 8), f->chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(offset_t(0x081C + 8), f->chunkOffset(2));
f.setChunkData(0, data);
CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(offset_t(0x0414 + 8), f.chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(offset_t(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.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(offset_t(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(offset_t(0x0414 + 8), f->chunkOffset(1));
f.removeChunk("SSND");
CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(offset_t(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.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(offset_t(0x000C + 8), f->chunkOffset(0));
f.removeChunk(0);
CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0));
f->seek(f->chunkOffset(0) - 8);
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4));
delete f;
f.seek(f.chunkOffset(0) - 8);
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4));
}
};

View File

@ -1,4 +1,5 @@
#include <speexfile.h>
#include <oggpageheader.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -9,6 +10,7 @@ class TestSpeex : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestSpeex);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST(testSplitPackets);
CPPUNIT_TEST_SUITE_END();
public:
@ -26,6 +28,53 @@ public:
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
}
void testSplitPackets()
{
ScopedFileCopy copy("empty", ".spx");
string newname = copy.fileName();
String longText(std::string(128 * 1024, ' ').c_str());
for (size_t i = 0; i < longText.length(); ++i)
longText[i] = static_cast<wchar>(L'A' + (i % 26));
{
Ogg::Speex::File f(newname.c_str());
f.tag()->setTitle(longText);
f.save();
}
{
Ogg::Speex::File f(newname.c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)156330, f.length());
CPPUNIT_ASSERT_EQUAL(23, f.lastPageHeader()->pageSequenceNumber());
CPPUNIT_ASSERT_EQUAL((size_t)80, f.packet(0).size());
CPPUNIT_ASSERT_EQUAL((size_t)131116, f.packet(1).size());
CPPUNIT_ASSERT_EQUAL((size_t)93, f.packet(2).size());
CPPUNIT_ASSERT_EQUAL((size_t)93, f.packet(3).size());
CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
f.tag()->setTitle("ABCDE");
f.save();
}
{
Ogg::Speex::File f(newname.c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)24317, f.length());
CPPUNIT_ASSERT_EQUAL(7, f.lastPageHeader()->pageSequenceNumber());
CPPUNIT_ASSERT_EQUAL((size_t)80, f.packet(0).size());
CPPUNIT_ASSERT_EQUAL((size_t)49, f.packet(1).size());
CPPUNIT_ASSERT_EQUAL((size_t)93, f.packet(2).size());
CPPUNIT_ASSERT_EQUAL((size_t)93, f.packet(3).size());
CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestSpeex);

View 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()

View File

@ -30,17 +30,11 @@ inline string copyFile(const string &filename, const string &ext)
char testFileName[1024];
#ifdef _WIN32
GetTempPathA(sizeof(testFileName), testFileName);
GetTempFileNameA(testFileName, "tag", 0, testFileName);
DeleteFileA(testFileName);
# if defined(_MSC_VER) && _MSC_VER > 1500
strcat_s(testFileName, ext.c_str());
# else
strcat(testFileName, ext.c_str());
# endif
char tempDir[MAX_PATH + 1];
GetTempPathA(sizeof(tempDir), tempDir);
wsprintfA(testFileName, "%s\\taglib-test%s", tempDir, ext.c_str());
#else
snprintf(testFileName, sizeof(testFileName), "/%s/taglib-test-XXXXXX%s", P_tmpdir, ext.c_str());
static_cast<void>(mkstemps(testFileName, 6));
snprintf(testFileName, sizeof(testFileName), "/%s/taglib-test%s", P_tmpdir, ext.c_str());
#endif
string sourceFileName = testFilePath(filename) + ext;