From: Tsuda Kageyu Date: Wed, 2 Dec 2015 05:59:50 +0000 (+0900) Subject: Merge branch 'xiph-picture' of https://github.com/gogglesmm/taglib into gogglesmm... X-Git-Tag: v1.11beta~64 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1529af7a12c8bf1181cd20c027f80f621803fd5d;p=taglib Merge branch 'xiph-picture' of https://github.com/gogglesmm/taglib into gogglesmm-xiph-picture # Conflicts: # tests/test_bytevector.cpp # tests/test_ogg.cpp --- 1529af7a12c8bf1181cd20c027f80f621803fd5d diff --cc taglib/ogg/xiphcomment.cpp index 9de81788,8ec108dd..d825333e --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@@ -293,9 -280,39 +301,39 @@@ void Ogg::XiphComment::removeAllFields( bool Ogg::XiphComment::contains(const String &key) const { - return d->fieldListMap.contains(key) && !d->fieldListMap[key].isEmpty(); + return !d->fieldListMap[key.upper()].isEmpty(); } + void Ogg::XiphComment::removePicture(FLAC::Picture *picture, bool del) + { + PictureList::Iterator it = d->pictureList.find(picture); + if(it != d->pictureList.end()) + d->pictureList.erase(it); + + if(del) + delete picture; + } + + void Ogg::XiphComment::removePictures() + { + PictureList newList; + for(uint i = 0; i < d->pictureList.size(); i++) { + delete d->pictureList[i]; + } + d->pictureList = newList; + } + + void Ogg::XiphComment::addPicture(FLAC::Picture * picture) + { + d->pictureList.append(picture); + } + + + List Ogg::XiphComment::pictureList() + { + return d->pictureList; + } + ByteVector Ogg::XiphComment::render() const { return render(true); diff --cc tests/test_bytevector.cpp index b9e31f87,8d23b82b..2848c6ce --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@@ -43,7 -43,7 +43,8 @@@ class TestByteVector : public CppUnit:: CPPUNIT_TEST(testReplace); CPPUNIT_TEST(testIterator); CPPUNIT_TEST(testResize); + CPPUNIT_TEST(testAppend); + CPPUNIT_TEST(testBase64); CPPUNIT_TEST_SUITE_END(); public: @@@ -388,20 -380,112 +389,125 @@@ CPPUNIT_ASSERT_EQUAL(-1, c.find('C')); } + void testAppend() + { + ByteVector v1("taglib"); + ByteVector v2 = v1; + + v1.append("ABC"); + CPPUNIT_ASSERT_EQUAL(ByteVector("taglibABC"), v1); + v1.append('1'); + v1.append('2'); + v1.append('3'); + CPPUNIT_ASSERT_EQUAL(ByteVector("taglibABC123"), v1); + CPPUNIT_ASSERT_EQUAL(ByteVector("taglib"), v2); + } + + void testBase64() + { + ByteVector sempty; + ByteVector t0("a"); // test 1 byte + ByteVector t1("any carnal pleasure."); + ByteVector t2("any carnal pleasure"); + ByteVector t3("any carnal pleasur"); + ByteVector s0("a"); // test 1 byte + ByteVector s1("any carnal pleasure."); + ByteVector s2("any carnal pleasure"); + ByteVector s3("any carnal pleasur"); + ByteVector eempty; + ByteVector e0("YQ=="); + ByteVector e1("YW55IGNhcm5hbCBwbGVhc3VyZS4="); + ByteVector e2("YW55IGNhcm5hbCBwbGVhc3VyZQ=="); + ByteVector e3("YW55IGNhcm5hbCBwbGVhc3Vy"); + + // Encode + CPPUNIT_ASSERT_EQUAL(eempty, sempty.toBase64()); + CPPUNIT_ASSERT_EQUAL(e0, s0.toBase64()); + CPPUNIT_ASSERT_EQUAL(e1, s1.toBase64()); + CPPUNIT_ASSERT_EQUAL(e2, s2.toBase64()); + CPPUNIT_ASSERT_EQUAL(e3, s3.toBase64()); + + // Decode + CPPUNIT_ASSERT_EQUAL(sempty, eempty.toBase64()); + CPPUNIT_ASSERT_EQUAL(s0, ByteVector::fromBase64(e0)); + CPPUNIT_ASSERT_EQUAL(s1, ByteVector::fromBase64(e1)); + CPPUNIT_ASSERT_EQUAL(s2, ByteVector::fromBase64(e2)); + CPPUNIT_ASSERT_EQUAL(s3, ByteVector::fromBase64(e3)); + + CPPUNIT_ASSERT_EQUAL(t0, ByteVector::fromBase64(s0.toBase64())); + CPPUNIT_ASSERT_EQUAL(t1, ByteVector::fromBase64(s1.toBase64())); + CPPUNIT_ASSERT_EQUAL(t2, ByteVector::fromBase64(s2.toBase64())); + CPPUNIT_ASSERT_EQUAL(t3, ByteVector::fromBase64(s3.toBase64())); + + ByteVector all((uint)256); + + // in order + { + for(int i = 0; i < 256; i++){ + all[i]=(unsigned char)i; + } + ByteVector b64 = all.toBase64(); + ByteVector original = ByteVector::fromBase64(b64); + CPPUNIT_ASSERT_EQUAL(all,original); + } + + // reverse + { + for(int i = 0; i < 256; i++){ + all[i]=(unsigned char)255-i; + } + ByteVector b64 = all.toBase64(); + ByteVector original = ByteVector::fromBase64(b64); + CPPUNIT_ASSERT_EQUAL(all,original); + } + + // all zeroes + { + for(int i = 0; i < 256; i++){ + all[i]=0; + } + ByteVector b64 = all.toBase64(); + ByteVector original = ByteVector::fromBase64(b64); + CPPUNIT_ASSERT_EQUAL(all,original); + } + + // all ones + { + for(int i = 0; i < 256; i++){ - all[i]=0xff; ++ all[i]=(unsigned char)0xff; + } + ByteVector b64 = all.toBase64(); + ByteVector original = ByteVector::fromBase64(b64); + CPPUNIT_ASSERT_EQUAL(all,original); + } + + // Missing end bytes + { + // No missing bytes + ByteVector m0("YW55IGNhcm5hbCBwbGVhc3VyZQ=="); + CPPUNIT_ASSERT_EQUAL(s2,ByteVector::fromBase64(m0)); + + // 1 missing byte + ByteVector m1("YW55IGNhcm5hbCBwbGVhc3VyZQ="); + CPPUNIT_ASSERT_EQUAL(sempty,ByteVector::fromBase64(m1)); + + // 2 missing bytes + ByteVector m2("YW55IGNhcm5hbCBwbGVhc3VyZQ"); + CPPUNIT_ASSERT_EQUAL(sempty,ByteVector::fromBase64(m2)); + + // 3 missing bytes + ByteVector m3("YW55IGNhcm5hbCBwbGVhc3VyZ"); + CPPUNIT_ASSERT_EQUAL(sempty,ByteVector::fromBase64(m3)); + } + + // Grok invalid characters + { + ByteVector invalid("abd\x00\x01\x02\x03\x04"); + CPPUNIT_ASSERT_EQUAL(sempty,ByteVector::fromBase64(invalid)); + } + + } + - }; CPPUNIT_TEST_SUITE_REGISTRATION(TestByteVector); diff --cc tests/test_ogg.cpp index 45620d61,3afeb196..4adf0c50 --- a/tests/test_ogg.cpp +++ b/tests/test_ogg.cpp @@@ -21,7 -21,7 +21,8 @@@ class TestOGG : public CppUnit::TestFix CPPUNIT_TEST(testDictInterface1); CPPUNIT_TEST(testDictInterface2); CPPUNIT_TEST(testAudioProperties); + CPPUNIT_TEST(testPageChecksum); + CPPUNIT_TEST(testPicture); CPPUNIT_TEST_SUITE_END(); public: @@@ -149,29 -136,40 +150,62 @@@ CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrateMinimum()); } + void testPageChecksum() + { + ScopedFileCopy copy("empty", ".ogg"); + + { + Vorbis::File f(copy.fileName().c_str()); + f.tag()->setArtist("The Artist"); + f.save(); + + f.seek(0x50); + CPPUNIT_ASSERT_EQUAL((TagLib::uint)0x3d3bd92d, f.readBlock(4).toUInt(0, true)); + } + { + Vorbis::File f(copy.fileName().c_str()); + f.tag()->setArtist("The Artist 2"); + f.save(); + + f.seek(0x50); + CPPUNIT_ASSERT_EQUAL((TagLib::uint)0xd985291c, f.readBlock(4).toUInt(0, true)); + } + + } + + void testPicture() + { + ScopedFileCopy copy("empty", ".ogg"); + string newname = copy.fileName(); + + Vorbis::File *f = new Vorbis::File(newname.c_str()); + 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->tag()->addPicture(newpic); + f->save(); + delete f; + + f = new Vorbis::File(newname.c_str()); + List lst = f->tag()->pictureList(); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size()); + CPPUNIT_ASSERT_EQUAL(int(5), lst[0]->width()); + CPPUNIT_ASSERT_EQUAL(int(6), lst[0]->height()); + CPPUNIT_ASSERT_EQUAL(int(16), lst[0]->colorDepth()); + CPPUNIT_ASSERT_EQUAL(int(7), lst[0]->numColors()); + CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), lst[0]->mimeType()); + CPPUNIT_ASSERT_EQUAL(String("new image"), lst[0]->description()); + CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), lst[0]->data()); - ++ + delete f; + } + - }; CPPUNIT_TEST_SUITE_REGISTRATION(TestOGG);