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

# Conflicts:
#	CMakeLists.txt
#	ConfigureChecks.cmake
#	taglib/flac/flacfile.cpp
#	taglib/mp4/mp4file.cpp
#	taglib/mpeg/mpegheader.cpp
#	taglib/mpeg/mpegproperties.cpp
#	taglib/riff/rifffile.cpp
#	taglib/toolkit/trefcounter.h
This commit is contained in:
Tsuda Kageyu
2015-12-16 13:33:04 +09:00
18 changed files with 343 additions and 166 deletions

Binary file not shown.

View File

@ -7,6 +7,7 @@
#include <flacfile.h>
#include <xiphcomment.h>
#include <id3v1tag.h>
#include <id3v2tag.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -22,13 +23,19 @@ class TestFLAC : public CppUnit::TestFixture
CPPUNIT_TEST(testAddPicture);
CPPUNIT_TEST(testReplacePicture);
CPPUNIT_TEST(testRemoveAllPictures);
CPPUNIT_TEST(testRepeatedSave);
CPPUNIT_TEST(testRepeatedSave1);
CPPUNIT_TEST(testRepeatedSave2);
CPPUNIT_TEST(testRepeatedSave3);
CPPUNIT_TEST(testSaveMultipleValues);
CPPUNIT_TEST(testDict);
CPPUNIT_TEST(testInvalid);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST(testZeroSizedPadding);
CPPUNIT_TEST(testZeroSizedPadding1);
CPPUNIT_TEST(testZeroSizedPadding2);
CPPUNIT_TEST(testShrinkPadding);
CPPUNIT_TEST(testSaveID3v1);
CPPUNIT_TEST(testUpdateID3v2);
CPPUNIT_TEST(testEmptyID3v2);
CPPUNIT_TEST_SUITE_END();
public:
@ -185,7 +192,7 @@ public:
}
}
void testRepeatedSave()
void testRepeatedSave1()
{
ScopedFileCopy copy("silence-44-s", ".flac");
string newname = copy.fileName();
@ -206,6 +213,31 @@ public:
}
}
void testRepeatedSave2()
{
ScopedFileCopy copy("no-tags", ".flac");
FLAC::File f(copy.fileName().c_str());
f.ID3v2Tag(true)->setTitle("0123456789");
f.save();
CPPUNIT_ASSERT_EQUAL(5735LL, f.length());
f.save();
CPPUNIT_ASSERT_EQUAL(5735LL, f.length());
CPPUNIT_ASSERT(f.find("fLaC") >= 0);
}
void testRepeatedSave3()
{
ScopedFileCopy copy("no-tags", ".flac");
FLAC::File f(copy.fileName().c_str());
f.xiphComment()->setTitle(std::string(8 * 1024, 'X').c_str());
f.save();
CPPUNIT_ASSERT_EQUAL(12862LL, f.length());
f.save();
CPPUNIT_ASSERT_EQUAL(12862LL, f.length());
}
void testSaveMultipleValues()
{
ScopedFileCopy copy("silence-44-s", ".flac");
@ -278,7 +310,7 @@ public:
f.audioProperties()->signature());
}
void testZeroSizedPadding()
void testZeroSizedPadding1()
{
ScopedFileCopy copy("zero-sized-padding", ".flac");
@ -286,6 +318,44 @@ public:
CPPUNIT_ASSERT(f.isValid());
}
void testZeroSizedPadding2()
{
ScopedFileCopy copy("silence-44-s", ".flac");
{
FLAC::File f(copy.fileName().c_str());
f.xiphComment()->setTitle("ABC");
f.save();
}
{
FLAC::File f(copy.fileName().c_str());
f.xiphComment()->setTitle(std::string(3067, 'X').c_str());
f.save();
}
{
FLAC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(f.isValid());
}
}
void testShrinkPadding()
{
ScopedFileCopy copy("no-tags", ".flac");
{
FLAC::File f(copy.fileName().c_str());
f.xiphComment()->setTitle(std::wstring(128 * 1024, L'X').c_str());
f.save();
CPPUNIT_ASSERT(f.length() > 128 * 1024);
}
{
FLAC::File f(copy.fileName().c_str());
f.xiphComment()->setTitle("0123456789");
f.save();
CPPUNIT_ASSERT(f.length() < 8 * 1024);
}
}
void testSaveID3v1()
{
ScopedFileCopy copy("no-tags", ".flac");
@ -309,6 +379,41 @@ public:
}
}
void testUpdateID3v2()
{
ScopedFileCopy copy("no-tags", ".flac");
{
FLAC::File f(copy.fileName().c_str());
f.ID3v2Tag(true)->setTitle("0123456789");
f.save();
}
{
FLAC::File f(copy.fileName().c_str());
f.ID3v2Tag()->setTitle("ABCDEFGHIJ");
f.save();
}
{
FLAC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT_EQUAL(String("ABCDEFGHIJ"), f.ID3v2Tag()->title());
}
}
void testEmptyID3v2()
{
ScopedFileCopy copy("no-tags", ".flac");
{
FLAC::File f(copy.fileName().c_str());
f.ID3v2Tag(true);
f.save();
}
{
FLAC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(!f.hasID3v2Tag());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);

View File

@ -31,6 +31,7 @@ class TestMP4 : public CppUnit::TestFixture
CPPUNIT_TEST(testCovrRead2);
CPPUNIT_TEST(testProperties);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST(testRepeatedSave);
CPPUNIT_TEST_SUITE_END();
public:
@ -358,6 +359,17 @@ public:
CPPUNIT_ASSERT(f.isValid());
}
void testRepeatedSave()
{
ScopedFileCopy copy("no-tags", ".m4a");
MP4::File f(copy.fileName().c_str());
f.tag()->setTitle("0123456789");
f.save();
f.save();
CPPUNIT_ASSERT_EQUAL(2862LL, f.find("0123456789"));
CPPUNIT_ASSERT_EQUAL(-1LL, f.find("0123456789", 2863));
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4);

View File

@ -22,6 +22,7 @@ class TestMPEG : public CppUnit::TestFixture
CPPUNIT_TEST(testAudioPropertiesXingHeaderVBR);
CPPUNIT_TEST(testAudioPropertiesVBRIHeader);
CPPUNIT_TEST(testAudioPropertiesNoVBRHeaders);
CPPUNIT_TEST(testSkipInvalidFrames);
CPPUNIT_TEST(testVersion2DurationWithXingHeader);
CPPUNIT_TEST(testSaveID3v24);
CPPUNIT_TEST(testSaveID3v24WrongParam);
@ -102,6 +103,19 @@ public:
CPPUNIT_ASSERT_EQUAL(209, lastHeader.frameLength());
}
void testSkipInvalidFrames()
{
MPEG::File f(TEST_FILE_PATH_C("invalid-frames.mp3"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(393, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(160, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT(!f.audioProperties()->xingHeader());
}
void testVersion2DurationWithXingHeader()
{
MPEG::File f(TEST_FILE_PATH_C("mpeg2.mp3"));