]> granicus.if.org Git - taglib/commitdiff
Merge branch 'xiph-picture' of https://github.com/gogglesmm/taglib into gogglesmm...
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Wed, 2 Dec 2015 05:59:50 +0000 (14:59 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Wed, 2 Dec 2015 05:59:50 +0000 (14:59 +0900)
# Conflicts:
# tests/test_bytevector.cpp
# tests/test_ogg.cpp

1  2 
taglib/ogg/xiphcomment.cpp
taglib/ogg/xiphcomment.h
taglib/toolkit/tbytevector.cpp
taglib/toolkit/tbytevector.h
tests/test_bytevector.cpp
tests/test_ogg.cpp

index 9de817888d957f40227fbbf3cddda14ac6539db8,8ec108dd978fc3d02e08d00a0767cea9f622ebfb..d825333e516c25b1377aac9ae035f461a6306824
@@@ -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<FLAC::Picture *> Ogg::XiphComment::pictureList()
+ {
+   return d->pictureList;
+ }
  ByteVector Ogg::XiphComment::render() const
  {
    return render(true);
Simple merge
Simple merge
Simple merge
index b9e31f873954b35e9c4f41536dfadb1fcb0f2a18,8d23b82b84da037d16bb75eae730968c10d7d306..2848c6ce9359598cd69452ba1c711fd6177e0f78
@@@ -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:
      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);
index 45620d61315ed9deccdcd7105b31ec450e663569,3afeb196d6599db59feb046a107bdb8cbbe75303..4adf0c50ef0008cda9d2f232566173caa56cbf81
@@@ -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:
      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);