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<FLAC::Picture *> Ogg::XiphComment::pictureList()
+ {
+ return d->pictureList;
+ }
+
ByteVector Ogg::XiphComment::render() const
{
return render(true);
CPPUNIT_TEST(testReplace);
CPPUNIT_TEST(testIterator);
CPPUNIT_TEST(testResize);
+ CPPUNIT_TEST(testAppend);
+ CPPUNIT_TEST(testBase64);
CPPUNIT_TEST_SUITE_END();
public:
CPPUNIT_ASSERT_EQUAL(-1, c.find('C'));
}
- all[i]=0xff;
+ 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]=(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);
CPPUNIT_TEST(testDictInterface1);
CPPUNIT_TEST(testDictInterface2);
CPPUNIT_TEST(testAudioProperties);
+ CPPUNIT_TEST(testPageChecksum);
+ CPPUNIT_TEST(testPicture);
CPPUNIT_TEST_SUITE_END();
public:
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<FLAC::Picture *> 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);