Merge branch 'master' into taglib2

Conflicts:
	CMakeLists.txt
	ConfigureChecks.cmake
	config.h.cmake
	taglib/CMakeLists.txt
	taglib/ape/apefile.cpp
	taglib/ape/apefile.h
	taglib/ape/apeproperties.cpp
	taglib/ape/apeproperties.h
	taglib/ape/apetag.cpp
	taglib/asf/asfattribute.cpp
	taglib/asf/asffile.cpp
	taglib/asf/asffile.h
	taglib/asf/asfpicture.cpp
	taglib/asf/asfpicture.h
	taglib/asf/asfproperties.cpp
	taglib/asf/asfproperties.h
	taglib/audioproperties.cpp
	taglib/flac/flacfile.cpp
	taglib/flac/flacfile.h
	taglib/flac/flacproperties.cpp
	taglib/flac/flacproperties.h
	taglib/it/itproperties.cpp
	taglib/mod/modproperties.cpp
	taglib/mp4/mp4atom.cpp
	taglib/mp4/mp4file.cpp
	taglib/mp4/mp4file.h
	taglib/mp4/mp4properties.cpp
	taglib/mp4/mp4tag.cpp
	taglib/mp4/mp4tag.h
	taglib/mpc/mpcfile.cpp
	taglib/mpc/mpcfile.h
	taglib/mpc/mpcproperties.cpp
	taglib/mpc/mpcproperties.h
	taglib/mpeg/id3v2/frames/chapterframe.cpp
	taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp
	taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp
	taglib/mpeg/mpegfile.cpp
	taglib/mpeg/mpegfile.h
	taglib/mpeg/mpegheader.cpp
	taglib/mpeg/mpegproperties.cpp
	taglib/mpeg/mpegproperties.h
	taglib/mpeg/xingheader.cpp
	taglib/mpeg/xingheader.h
	taglib/ogg/opus/opusfile.cpp
	taglib/ogg/opus/opusfile.h
	taglib/ogg/opus/opusproperties.cpp
	taglib/ogg/opus/opusproperties.h
	taglib/ogg/speex/speexfile.cpp
	taglib/ogg/speex/speexfile.h
	taglib/ogg/speex/speexproperties.cpp
	taglib/ogg/speex/speexproperties.h
	taglib/ogg/vorbis/vorbisfile.cpp
	taglib/ogg/vorbis/vorbisfile.h
	taglib/ogg/vorbis/vorbisproperties.cpp
	taglib/ogg/vorbis/vorbisproperties.h
	taglib/riff/aiff/aifffile.cpp
	taglib/riff/aiff/aifffile.h
	taglib/riff/aiff/aiffproperties.cpp
	taglib/riff/aiff/aiffproperties.h
	taglib/riff/wav/infotag.h
	taglib/riff/wav/wavfile.cpp
	taglib/riff/wav/wavfile.h
	taglib/riff/wav/wavproperties.cpp
	taglib/riff/wav/wavproperties.h
	taglib/s3m/s3mproperties.cpp
	taglib/taglib_config.h.cmake
	taglib/toolkit/tbytevector.cpp
	taglib/toolkit/tfile.cpp
	taglib/toolkit/tfile.h
	taglib/toolkit/tfilestream.cpp
	taglib/toolkit/trefcounter.cpp
	taglib/toolkit/tstring.cpp
	taglib/toolkit/tstring.h
	taglib/toolkit/tutils.h
	taglib/trueaudio/trueaudiofile.cpp
	taglib/trueaudio/trueaudiofile.h
	taglib/trueaudio/trueaudioproperties.cpp
	taglib/trueaudio/trueaudioproperties.h
	taglib/wavpack/wavpackfile.cpp
	taglib/wavpack/wavpackfile.h
	taglib/wavpack/wavpackproperties.cpp
	taglib/wavpack/wavpackproperties.h
	taglib/xm/xmproperties.cpp
	taglib/xm/xmproperties.h
	tests/CMakeLists.txt
	tests/data/alaw.wav
	tests/test_asf.cpp
	tests/test_mp4.cpp
	tests/test_ogg.cpp
	tests/test_opus.cpp
	tests/test_string.cpp
	tests/test_wav.cpp
	tests/test_wavpack.cpp
This commit is contained in:
Tsuda Kageyu
2015-08-10 00:24:20 +09:00
178 changed files with 4703 additions and 2281 deletions

View File

@ -42,6 +42,7 @@ SET(test_runner_SRCS
test_bytevectorstream.cpp
test_string.cpp
test_propertymap.cpp
test_file.cpp
test_fileref.cpp
test_id3v1.cpp
test_id3v2.cpp
@ -68,6 +69,7 @@ SET(test_runner_SRCS
test_xm.cpp
test_mpc.cpp
test_opus.cpp
test_speex.cpp
test_dsf.cpp
test_matroska.cpp
)

Binary file not shown.

BIN
tests/data/ape-id3v1.mp3 Normal file

Binary file not shown.

BIN
tests/data/ape-id3v2.mp3 Normal file

Binary file not shown.

BIN
tests/data/ape.mp3 Normal file

Binary file not shown.

BIN
tests/data/bladeenc.mp3 Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tests/data/float64.wav Normal file

Binary file not shown.

BIN
tests/data/four_channels.wv Normal file

Binary file not shown.

BIN
tests/data/infloop.m4a Normal file

Binary file not shown.

BIN
tests/data/infloop.wv Normal file

Binary file not shown.

BIN
tests/data/lame_cbr.mp3 Normal file

Binary file not shown.

BIN
tests/data/lame_vbr.mp3 Normal file

Binary file not shown.

BIN
tests/data/lossless.wma Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tests/data/sinewave.flac Normal file

Binary file not shown.

BIN
tests/data/tagged.tta Normal file

Binary file not shown.

BIN
tests/data/tagged.wv Normal file

Binary file not shown.

BIN
tests/data/vbri.mp3 Normal file

Binary file not shown.

Binary file not shown.

View File

@ -17,7 +17,7 @@ int main(int argc, char* argv[])
// Create the event manager and test controller
CppUnit::TestResult controller;
// Add a listener that colllects test result
// Add a listener that collects test result
CppUnit::TestResultCollector result;
controller.addListener(&result);
@ -39,12 +39,20 @@ int main(int argc, char* argv[])
CppUnit::CompilerOutputter outputter(&result, std::cerr);
outputter.write();
#if defined(_MSC_VER) && _MSC_VER > 1500
char *xml = NULL;
::_dupenv_s(&xml, NULL, "CPPUNIT_XML");
#else
char *xml = ::getenv("CPPUNIT_XML");
#endif
if(xml && !::strcmp(xml, "1")) {
std::ofstream xmlfileout("cpptestresults.xml");
CppUnit::XmlOutputter xmlout(&result, xmlfileout);
xmlout.write();
}
#if defined(_MSC_VER) && _MSC_VER > 1500
::free(xml);
#endif
}
catch(std::invalid_argument &e){
std::cerr << std::endl

View File

@ -12,19 +12,48 @@ using namespace TagLib;
class TestAIFF : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestAIFF);
CPPUNIT_TEST(testReading);
CPPUNIT_TEST(testSaveID3v2);
CPPUNIT_TEST(testAiffProperties);
CPPUNIT_TEST(testAiffCProperties);
CPPUNIT_TEST(testSaveID3v2);
CPPUNIT_TEST(testDuplicateID3v2);
CPPUNIT_TEST(testFuzzedFile1);
CPPUNIT_TEST(testFuzzedFile2);
CPPUNIT_TEST_SUITE_END();
public:
void testReading()
void testAiffProperties()
{
RIFF::AIFF::File f(TEST_FILE_PATH_C("empty.aiff"));
CPPUNIT_ASSERT_EQUAL(705, f.audioProperties()->bitrate());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(67, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(706, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->sampleWidth());
CPPUNIT_ASSERT_EQUAL(2941U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isAiffC());
}
void testAiffCProperties()
{
RIFF::AIFF::File f(TEST_FILE_PATH_C("alaw.aifc"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(37, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(355, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->sampleWidth());
CPPUNIT_ASSERT_EQUAL(1622U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(true, f.audioProperties()->isAiffC());
CPPUNIT_ASSERT_EQUAL(ByteVector("ALAW"), f.audioProperties()->compressionType());
CPPUNIT_ASSERT_EQUAL(String("SGI CCITT G.711 A-law"), f.audioProperties()->compressionName());
}
void testSaveID3v2()
@ -46,12 +75,15 @@ public:
}
}
void testAiffCProperties()
void testDuplicateID3v2()
{
RIFF::AIFF::File f(TEST_FILE_PATH_C("alaw.aifc"));
CPPUNIT_ASSERT(f.audioProperties()->isAiffC());
CPPUNIT_ASSERT(f.audioProperties()->compressionType() == "ALAW");
CPPUNIT_ASSERT(f.audioProperties()->compressionName() == "SGI CCITT G.711 A-law");
RIFF::AIFF::File f(TEST_FILE_PATH_C("duplicate_id3v2.aiff"));
// duplicate_id3v2.aiff has duplicate ID3v2 tags.
// title() returns "Title2" if can't skip the second tag.
CPPUNIT_ASSERT(f.hasID3v2Tag());
CPPUNIT_ASSERT_EQUAL(String("Title1"), f.tag()->title());
}
void testFuzzedFile1()

View File

@ -14,6 +14,8 @@ class TestAPE : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestAPE);
CPPUNIT_TEST(testProperties399);
CPPUNIT_TEST(testProperties399Tagged);
CPPUNIT_TEST(testProperties399Id3v2);
CPPUNIT_TEST(testProperties396);
CPPUNIT_TEST(testProperties390);
CPPUNIT_TEST(testFuzzedFile1);
@ -25,28 +27,76 @@ public:
void testProperties399()
{
APE::File f(TEST_FILE_PATH_C("mac-399.ape"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(192, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(3990, f.audioProperties()->version());
}
void testProperties399Tagged()
{
APE::File f(TEST_FILE_PATH_C("mac-399-tagged.ape"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(192, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(3990, f.audioProperties()->version());
}
void testProperties399Id3v2()
{
APE::File f(TEST_FILE_PATH_C("mac-399-id3v2.ape"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(192, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(3990, f.audioProperties()->version());
}
void testProperties396()
{
APE::File f(TEST_FILE_PATH_C("mac-396.ape"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(162496U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(3960, f.audioProperties()->version());
}
void testProperties390()
{
APE::File f(TEST_FILE_PATH_C("mac-390-hdr.ape"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(15, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(15, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(15630, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(689262U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(3900, f.audioProperties()->version());
}
void testFuzzedFile1()

View File

@ -15,6 +15,7 @@ class TestASF : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestASF);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST(testLosslessProperties);
CPPUNIT_TEST(testRead);
CPPUNIT_TEST(testSaveMultipleValues);
CPPUNIT_TEST(testSaveStream);
@ -31,10 +32,35 @@ public:
void testAudioProperties()
{
ASF::File f(TEST_FILE_PATH_C("silence-1.wma"));
CPPUNIT_ASSERT_EQUAL(4, f.audioProperties()->length());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3712, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(ASF::AudioProperties::WMA2, f.audioProperties()->codec());
CPPUNIT_ASSERT_EQUAL(String("Windows Media Audio 9.1"), f.audioProperties()->codecName());
CPPUNIT_ASSERT_EQUAL(String("64 kbps, 48 kHz, stereo 2-pass CBR"), f.audioProperties()->codecDescription());
CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isEncrypted());
}
void testLosslessProperties()
{
ASF::File f(TEST_FILE_PATH_C("lossless.wma"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3549, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(1152, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(ASF::AudioProperties::WMA9Lossless, f.audioProperties()->codec());
CPPUNIT_ASSERT_EQUAL(String("Windows Media Audio 9.2 Lossless"), f.audioProperties()->codecName());
CPPUNIT_ASSERT_EQUAL(String("VBR Quality 100, 44 kHz, 2 channel 16 bit 1-pass VBR"), f.audioProperties()->codecDescription());
CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isEncrypted());
}
void testRead()
@ -52,7 +78,7 @@ public:
ASF::AttributeList values;
values.append("Foo");
values.append("Bar");
f->tag()->attributeListMap()["WM/AlbumTitle"] = values;
f->tag()->setAttribute("WM/AlbumTitle", values);
f->save();
delete f;
@ -67,22 +93,24 @@ public:
string newname = copy.fileName();
ASF::File *f = new ASF::File(newname.c_str());
CPPUNIT_ASSERT(!f->tag()->attributeListMap().contains("WM/TrackNumber"));
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()->attributeListMap().contains("WM/TrackNumber"));
CPPUNIT_ASSERT_EQUAL(ASF::Attribute::DWordType, f->tag()->attributeListMap()["WM/TrackNumber"].front().type());
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()->attributeListMap().contains("WM/TrackNumber"));
CPPUNIT_ASSERT_EQUAL(ASF::Attribute::UnicodeType, f->tag()->attributeListMap()["WM/TrackNumber"].front().type());
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;
}
@ -93,16 +121,14 @@ public:
string newname = copy.fileName();
ASF::File *f = new ASF::File(newname.c_str());
ASF::AttributeList values;
ASF::Attribute attr("Foo");
attr.setStream(43);
values.append(attr);
f->tag()->attributeListMap()["WM/AlbumTitle"] = values;
f->tag()->setAttribute("WM/AlbumTitle", attr);
f->save();
delete f;
f = new ASF::File(newname.c_str());
CPPUNIT_ASSERT_EQUAL(43, f->tag()->attributeListMap()["WM/AlbumTitle"][0].stream());
CPPUNIT_ASSERT_EQUAL(43, f->tag()->attribute("WM/AlbumTitle").front().stream());
delete f;
}
@ -112,18 +138,16 @@ public:
string newname = copy.fileName();
ASF::File *f = new ASF::File(newname.c_str());
ASF::AttributeList values;
ASF::Attribute attr("Foo");
attr.setStream(32);
attr.setLanguage(56);
values.append(attr);
f->tag()->attributeListMap()["WM/AlbumTitle"] = values;
f->tag()->setAttribute("WM/AlbumTitle", attr);
f->save();
delete f;
f = new ASF::File(newname.c_str());
CPPUNIT_ASSERT_EQUAL(32, f->tag()->attributeListMap()["WM/AlbumTitle"][0].stream());
CPPUNIT_ASSERT_EQUAL(56, f->tag()->attributeListMap()["WM/AlbumTitle"][0].language());
CPPUNIT_ASSERT_EQUAL(32, f->tag()->attribute("WM/AlbumTitle").front().stream());
CPPUNIT_ASSERT_EQUAL(56, f->tag()->attribute("WM/AlbumTitle").front().language());
delete f;
}
@ -133,15 +157,14 @@ public:
string newname = copy.fileName();
ASF::File *f = new ASF::File(newname.c_str());
ASF::AttributeList values;
ASF::Attribute attr(ByteVector(70000, 'x'));
values.append(attr);
f->tag()->attributeListMap()["WM/Blob"] = values;
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()->attributeListMap()["WM/Blob"][0].toByteVector());
CPPUNIT_ASSERT_EQUAL(ByteVector(70000, 'x'),
f->tag()->attribute("WM/Blob").front().toByteVector());
delete f;
}
@ -151,20 +174,17 @@ public:
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");
ASF::Attribute attr(picture);
values.append(attr);
f->tag()->attributeListMap()["WM/Picture"] = values;
f->tag()->setAttribute("WM/Picture", picture);
f->save();
delete f;
f = new ASF::File(newname.c_str());
ASF::AttributeList values2 = f->tag()->attributeListMap()["WM/Picture"];
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();
@ -195,12 +215,12 @@ public:
picture2.setDescription("back cover");
picture2.setPicture("PNG data");
values.append(ASF::Attribute(picture2));
f->tag()->attributeListMap()["WM/Picture"] = values;
f->tag()->setAttribute("WM/Picture", values);
f->save();
delete f;
f = new ASF::File(newname.c_str());
ASF::AttributeList values2 = f->tag()->attributeListMap()["WM/Picture"];
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());
@ -220,7 +240,7 @@ public:
void testProperties()
{
ASF::File f(TEST_FILE_PATH_C("silence-1.wma"));
PropertyMap tags = f.properties();
tags["TRACKNUMBER"] = StringList("2");
@ -234,19 +254,19 @@ public:
CPPUNIT_ASSERT_EQUAL(String("Foo Bar"), f.tag()->artist());
CPPUNIT_ASSERT_EQUAL(StringList("Foo Bar"), tags["ARTIST"]);
CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/BeatsPerMinute"));
CPPUNIT_ASSERT_EQUAL((size_t)1u, f.tag()->attributeListMap()["WM/BeatsPerMinute"].size());
CPPUNIT_ASSERT_EQUAL(String("123"), f.tag()->attributeListMap()["WM/BeatsPerMinute"].front().toString());
CPPUNIT_ASSERT(f.tag()->contains("WM/BeatsPerMinute"));
CPPUNIT_ASSERT_EQUAL((size_t)1, f.tag()->attributeListMap()["WM/BeatsPerMinute"].size());
CPPUNIT_ASSERT_EQUAL(String("123"), f.tag()->attribute("WM/BeatsPerMinute").front().toString());
CPPUNIT_ASSERT_EQUAL(StringList("123"), tags["BPM"]);
CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/TrackNumber"));
CPPUNIT_ASSERT_EQUAL((size_t)1u, f.tag()->attributeListMap()["WM/TrackNumber"].size());
CPPUNIT_ASSERT_EQUAL(String("2"), f.tag()->attributeListMap()["WM/TrackNumber"].front().toString());
CPPUNIT_ASSERT(f.tag()->contains("WM/TrackNumber"));
CPPUNIT_ASSERT_EQUAL((size_t)1, f.tag()->attributeListMap()["WM/TrackNumber"].size());
CPPUNIT_ASSERT_EQUAL(String("2"), f.tag()->attribute("WM/TrackNumber").front().toString());
CPPUNIT_ASSERT_EQUAL(StringList("2"), tags["TRACKNUMBER"]);
CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/PartOfSet"));
CPPUNIT_ASSERT_EQUAL((size_t)1u, f.tag()->attributeListMap()["WM/PartOfSet"].size());
CPPUNIT_ASSERT_EQUAL(String("3"), f.tag()->attributeListMap()["WM/PartOfSet"].front().toString());
CPPUNIT_ASSERT(f.tag()->contains("WM/PartOfSet"));
CPPUNIT_ASSERT_EQUAL((size_t)1, f.tag()->attributeListMap()["WM/PartOfSet"].size());
CPPUNIT_ASSERT_EQUAL(String("3"), f.tag()->attribute("WM/PartOfSet").front().toString());
CPPUNIT_ASSERT_EQUAL(StringList("3"), tags["DISCNUMBER"]);
}

View File

@ -42,6 +42,7 @@ class TestByteVector : public CppUnit::TestFixture
CPPUNIT_TEST(testNumericCoversion);
CPPUNIT_TEST(testReplace);
CPPUNIT_TEST(testIterator);
CPPUNIT_TEST(testResize);
CPPUNIT_TEST_SUITE_END();
public:
@ -303,8 +304,66 @@ public:
*it4 = 'A';
CPPUNIT_ASSERT_EQUAL('a', *it3);
CPPUNIT_ASSERT_EQUAL('A', *it4);
ByteVector v3;
v3 = ByteVector("0123456789").mid(3, 4);
it1 = v3.begin();
it2 = v3.end() - 1;
CPPUNIT_ASSERT_EQUAL('3', *it1);
CPPUNIT_ASSERT_EQUAL('6', *it2);
it3 = v3.rbegin();
it4 = v3.rend() - 1;
CPPUNIT_ASSERT_EQUAL('6', *it3);
CPPUNIT_ASSERT_EQUAL('3', *it4);
}
void testResize()
{
ByteVector a = ByteVector("0123456789");
ByteVector b = a.mid(3, 4);
b.resize(6, 'A');
CPPUNIT_ASSERT_EQUAL(size_t(6), b.size());
CPPUNIT_ASSERT_EQUAL('6', b[3]);
CPPUNIT_ASSERT_EQUAL('A', b[4]);
CPPUNIT_ASSERT_EQUAL('A', b[5]);
b.resize(10, 'B');
CPPUNIT_ASSERT_EQUAL(size_t(10), b.size());
CPPUNIT_ASSERT_EQUAL('6', b[3]);
CPPUNIT_ASSERT_EQUAL('B', b[6]);
CPPUNIT_ASSERT_EQUAL('B', b[9]);
b.resize(3, 'C');
CPPUNIT_ASSERT_EQUAL(size_t(3), b.size());
CPPUNIT_ASSERT_EQUAL(ByteVector::npos, b.find('C'));
b.resize(3);
CPPUNIT_ASSERT_EQUAL(size_t(3), b.size());
// Check if a and b were properly detached.
CPPUNIT_ASSERT_EQUAL(size_t(10), a.size());
CPPUNIT_ASSERT_EQUAL('3', a[3]);
CPPUNIT_ASSERT_EQUAL('5', a[5]);
// Special case that refCount == 1 and d->offset != 0.
ByteVector c = ByteVector("0123456789").mid(3, 4);
c.resize(6, 'A');
CPPUNIT_ASSERT_EQUAL(size_t(6), c.size());
CPPUNIT_ASSERT_EQUAL('6', c[3]);
CPPUNIT_ASSERT_EQUAL('A', c[4]);
CPPUNIT_ASSERT_EQUAL('A', c[5]);
c.resize(10, 'B');
CPPUNIT_ASSERT_EQUAL(size_t(10), c.size());
CPPUNIT_ASSERT_EQUAL('6', c[3]);
CPPUNIT_ASSERT_EQUAL('B', c[6]);
CPPUNIT_ASSERT_EQUAL('B', c[9]);
c.resize(3, 'C');
CPPUNIT_ASSERT_EQUAL(size_t(3), c.size());
CPPUNIT_ASSERT_EQUAL(ByteVector::npos, c.find('C'));
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestByteVector);

131
tests/test_file.cpp Normal file
View File

@ -0,0 +1,131 @@
/***************************************************************************
copyright : (C) 2014 by Lukas Lalinsky
email : lukas@oxygene.sk
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301 USA *
***************************************************************************/
#include <tfile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
using namespace TagLib;
// File subclass that gives tests access to filesystem operations
class PlainFile : public File {
public:
PlainFile(FileName name) : File(name) { }
Tag *tag() const { return NULL; }
AudioProperties *audioProperties() const { return NULL; }
bool save(){ return false; }
void truncate(long length) { File::truncate(length); }
};
class TestFile : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestFile);
CPPUNIT_TEST(testFindInSmallFile);
CPPUNIT_TEST(testRFindInSmallFile);
CPPUNIT_TEST(testSeek);
CPPUNIT_TEST_SUITE_END();
public:
void testFindInSmallFile()
{
ScopedFileCopy copy("empty", ".ogg");
std::string name = copy.fileName();
{
PlainFile file(name.c_str());
file.seek(0);
file.writeBlock(ByteVector("0123456239", 10));
file.truncate(10);
}
{
PlainFile file(name.c_str());
CPPUNIT_ASSERT_EQUAL((offset_t)10, file.length());
CPPUNIT_ASSERT_EQUAL((offset_t)2, file.find(ByteVector("23", 2)));
CPPUNIT_ASSERT_EQUAL((offset_t)2, file.find(ByteVector("23", 2), 2));
CPPUNIT_ASSERT_EQUAL((offset_t)7, file.find(ByteVector("23", 2), 3));
file.seek(0);
const ByteVector v = file.readBlock(static_cast<size_t>(file.length()));
CPPUNIT_ASSERT_EQUAL((size_t)10, v.size());
CPPUNIT_ASSERT_EQUAL((offset_t)v.find("23"), file.find("23"));
CPPUNIT_ASSERT_EQUAL((offset_t)v.find("23", 2), file.find("23", 2));
CPPUNIT_ASSERT_EQUAL((offset_t)v.find("23", 3), file.find("23", 3));
}
}
void testRFindInSmallFile()
{
ScopedFileCopy copy("empty", ".ogg");
std::string name = copy.fileName();
{
PlainFile file(name.c_str());
file.seek(0);
file.writeBlock(ByteVector("0123456239", 10));
file.truncate(10);
}
{
PlainFile file(name.c_str());
CPPUNIT_ASSERT_EQUAL((offset_t)10, file.length());
CPPUNIT_ASSERT_EQUAL((offset_t)7, file.rfind(ByteVector("23", 2)));
CPPUNIT_ASSERT_EQUAL((offset_t)7, file.rfind(ByteVector("23", 2), 7));
CPPUNIT_ASSERT_EQUAL((offset_t)2, file.rfind(ByteVector("23", 2), 6));
file.seek(0);
const ByteVector v = file.readBlock(file.length());
CPPUNIT_ASSERT_EQUAL((size_t)10, v.size());
CPPUNIT_ASSERT_EQUAL((offset_t)v.rfind("23"), file.rfind("23"));
CPPUNIT_ASSERT_EQUAL((offset_t)v.rfind("23", 7), file.rfind("23", 7));
CPPUNIT_ASSERT_EQUAL((offset_t)v.rfind("23", 6), file.rfind("23", 6));
}
}
void testSeek()
{
ScopedFileCopy copy("empty", ".ogg");
std::string name = copy.fileName();
PlainFile f(name.c_str());
CPPUNIT_ASSERT_EQUAL((offset_t)0, f.tell());
CPPUNIT_ASSERT_EQUAL((offset_t)4328, f.length());
f.seek(100, File::Beginning);
CPPUNIT_ASSERT_EQUAL((offset_t)100, f.tell());
f.seek(100, File::Current);
CPPUNIT_ASSERT_EQUAL((offset_t)200, f.tell());
f.seek(-300, File::Current);
CPPUNIT_ASSERT_EQUAL((offset_t)200, f.tell());
f.seek(-100, File::End);
CPPUNIT_ASSERT_EQUAL((offset_t)4228, f.tell());
f.seek(-100, File::Current);
CPPUNIT_ASSERT_EQUAL((offset_t)4128, f.tell());
f.seek(300, File::Current);
CPPUNIT_ASSERT_EQUAL((offset_t)4428, f.tell());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestFile);

View File

@ -6,6 +6,7 @@
#include <tpropertymap.h>
#include <flacfile.h>
#include <xiphcomment.h>
#include <id3v1tag.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -25,6 +26,9 @@ class TestFLAC : public CppUnit::TestFixture
CPPUNIT_TEST(testSaveMultipleValues);
CPPUNIT_TEST(testDict);
CPPUNIT_TEST(testInvalid);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST(testZeroSizedPadding);
CPPUNIT_TEST(testSaveID3v1);
CPPUNIT_TEST_SUITE_END();
public:
@ -254,6 +258,55 @@ public:
CPPUNIT_ASSERT_EQUAL(size_t(0), f.properties().size());
}
void testAudioProperties()
{
FLAC::File f(TEST_FILE_PATH_C("sinewave.flac"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(145, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->sampleWidth());
CPPUNIT_ASSERT_EQUAL(156556ULL, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(
ByteVector("\xcf\xe3\xd9\xda\xba\xde\xab\x2c\xbf\x2c\xa2\x35\x27\x4b\x7f\x76"),
f.audioProperties()->signature());
}
void testZeroSizedPadding()
{
ScopedFileCopy copy("zero-sized-padding", ".flac");
FLAC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(f.isValid());
}
void testSaveID3v1()
{
ScopedFileCopy copy("no-tags", ".flac");
ByteVector audioStream;
{
FLAC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(!f.hasID3v1Tag());
CPPUNIT_ASSERT_EQUAL((offset_t)4692, f.length());
f.seek(0x0100);
audioStream = f.readBlock(4436);
f.ID3v1Tag(true)->setTitle("01234 56789 ABCDE FGHIJ");
f.save();
CPPUNIT_ASSERT(f.hasID3v1Tag());
CPPUNIT_ASSERT_EQUAL((offset_t)4820, f.length());
f.seek(0x0100);
CPPUNIT_ASSERT_EQUAL(audioStream, f.readBlock(4436));
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);

View File

@ -94,6 +94,7 @@ class TestID3v2 : public CppUnit::TestFixture
CPPUNIT_TEST(testParseTableOfContentsFrame);
CPPUNIT_TEST(testRenderTableOfContentsFrame);
CPPUNIT_TEST(testShrinkPadding);
CPPUNIT_TEST(testEmptyFrame);
CPPUNIT_TEST_SUITE_END();
public:
@ -901,45 +902,58 @@ public:
void testParseChapterFrame()
{
ID3v2::Header header;
ID3v2::ChapterFrame f(
&header,
ByteVector chapterData =
ByteVector("CHAP" // Frame ID
"\x00\x00\x00\x20" // Frame size
"\x00\x00" // Frame flags
"\x43\x00" // Element ID
"\x43\x00" // Element ID ("C")
"\x00\x00\x00\x03" // Start time
"\x00\x00\x00\x05" // End time
"\x00\x00\x00\x02" // Start offset
"\x00\x00\x00\x03" // End offset
"TIT2" // Embedded frame ID
"\x00\x00\x00\x03", 28); // End offset
ByteVector embeddedFrameData =
ByteVector("TIT2" // Embedded frame ID
"\x00\x00\x00\x04" // Embedded frame size
"\x00\x00" // Embedded frame flags
"\x00" // TIT2 frame text encoding
"CH1", 42)); // Chapter title
CPPUNIT_ASSERT_EQUAL(ByteVector("\x43\x00", 2),
f.elementID());
CPPUNIT_ASSERT((uint)0x03 == f.startTime());
CPPUNIT_ASSERT((uint)0x05 == f.endTime());
CPPUNIT_ASSERT((uint)0x02 == f.startOffset());
CPPUNIT_ASSERT((uint)0x03 == f.endOffset());
CPPUNIT_ASSERT((uint)0x01 == f.embeddedFrameList().size());
CPPUNIT_ASSERT(f.embeddedFrameList("TIT2").size() == 1);
CPPUNIT_ASSERT(f.embeddedFrameList("TIT2")[0]->toString() == "CH1");
"CH1", 14); // Chapter title
ID3v2::ChapterFrame f1(&header, chapterData);
CPPUNIT_ASSERT_EQUAL(ByteVector("C"), f1.elementID());
CPPUNIT_ASSERT((TagLib::uint)0x03 == f1.startTime());
CPPUNIT_ASSERT((TagLib::uint)0x05 == f1.endTime());
CPPUNIT_ASSERT((TagLib::uint)0x02 == f1.startOffset());
CPPUNIT_ASSERT((TagLib::uint)0x03 == f1.endOffset());
CPPUNIT_ASSERT((TagLib::uint)0x00 == f1.embeddedFrameList().size());
ID3v2::ChapterFrame f2(&header, chapterData + embeddedFrameData);
CPPUNIT_ASSERT_EQUAL(ByteVector("C"), f2.elementID());
CPPUNIT_ASSERT((TagLib::uint)0x03 == f2.startTime());
CPPUNIT_ASSERT((TagLib::uint)0x05 == f2.endTime());
CPPUNIT_ASSERT((TagLib::uint)0x02 == f2.startOffset());
CPPUNIT_ASSERT((TagLib::uint)0x03 == f2.endOffset());
CPPUNIT_ASSERT((TagLib::uint)0x01 == f2.embeddedFrameList().size());
CPPUNIT_ASSERT(f2.embeddedFrameList("TIT2").size() == 1);
CPPUNIT_ASSERT(f2.embeddedFrameList("TIT2")[0]->toString() == "CH1");
}
void testRenderChapterFrame()
{
ID3v2::Header header;
ID3v2::ChapterFrame f(&header, "CHAP");
f.setElementID(ByteVector("\x43\x00", 2));
f.setStartTime(3);
f.setEndTime(5);
f.setStartOffset(2);
f.setEndOffset(3);
ID3v2::ChapterFrame f1(&header, "CHAP");
f1.setElementID(ByteVector("\x43\x00", 2));
f1.setStartTime(3);
f1.setEndTime(5);
f1.setStartOffset(2);
f1.setEndOffset(3);
ID3v2::TextIdentificationFrame *eF = new ID3v2::TextIdentificationFrame("TIT2");
eF->setText("CH1");
f.addEmbeddedFrame(eF);
CPPUNIT_ASSERT_EQUAL(
f1.addEmbeddedFrame(eF);
ByteVector expected =
ByteVector("CHAP" // Frame ID
"\x00\x00\x00\x20" // Frame size
"\x00\x00" // Frame flags
@ -952,8 +966,45 @@ public:
"\x00\x00\x00\x04" // Embedded frame size
"\x00\x00" // Embedded frame flags
"\x00" // TIT2 frame text encoding
"CH1", 42), // Chapter title
f.render());
"CH1", 42); // Chapter title
CPPUNIT_ASSERT_EQUAL(expected, f1.render());
f1.setElementID("C");
CPPUNIT_ASSERT_EQUAL(expected, f1.render());
ID3v2::FrameList frames;
eF = new ID3v2::TextIdentificationFrame("TIT2");
eF->setText("CH1");
frames.append(eF);
ID3v2::ChapterFrame f2(ByteVector("\x43\x00", 2), 3, 5, 2, 3, frames);
CPPUNIT_ASSERT_EQUAL(expected, f2.render());
frames.clear();
eF = new ID3v2::TextIdentificationFrame("TIT2");
eF->setText("CH1");
frames.append(eF);
ID3v2::ChapterFrame f3(ByteVector("C\x00", 2), 3, 5, 2, 3, frames);
CPPUNIT_ASSERT_EQUAL(expected, f3.render());
frames.clear();
eF = new ID3v2::TextIdentificationFrame("TIT2");
eF->setText("CH1");
frames.append(eF);
ID3v2::ChapterFrame f4("C", 3, 5, 2, 3, frames);
CPPUNIT_ASSERT_EQUAL(expected, f4.render());
CPPUNIT_ASSERT(!f4.toString().isEmpty());
ID3v2::ChapterFrame f5("C", 3, 5, 2, 3);
eF = new ID3v2::TextIdentificationFrame("TIT2");
eF->setText("CH1");
f5.addEmbeddedFrame(eF);
CPPUNIT_ASSERT_EQUAL(expected, f5.render());
}
void testParseTableOfContentsFrame()
@ -964,26 +1015,23 @@ public:
ByteVector("CTOC" // Frame ID
"\x00\x00\x00\x16" // Frame size
"\x00\x00" // Frame flags
"\x54\x00" // Element ID
"\x54\x00" // Element ID ("T")
"\x01" // CTOC flags
"\x02" // Entry count
"\x43\x00" // First entry
"\x44\x00" // Second entry
"\x43\x00" // First entry ("C")
"\x44\x00" // Second entry ("D")
"TIT2" // Embedded frame ID
"\x00\x00\x00\x04" // Embedded frame size
"\x00\x00" // Embedded frame flags
"\x00" // TIT2 frame text encoding
"TC1", 32)); // Table of contents title
CPPUNIT_ASSERT_EQUAL(ByteVector("\x54\x00", 2),
f.elementID());
CPPUNIT_ASSERT_EQUAL(ByteVector("T"), f.elementID());
CPPUNIT_ASSERT(!f.isTopLevel());
CPPUNIT_ASSERT(f.isOrdered());
CPPUNIT_ASSERT((uint)0x02 == f.entryCount());
CPPUNIT_ASSERT_EQUAL(ByteVector("\x43\x00", 2),
f.childElements()[0]);
CPPUNIT_ASSERT_EQUAL(ByteVector("\x44\x00", 2),
f.childElements()[1]);
CPPUNIT_ASSERT((uint)0x01 == f.embeddedFrameList().size());
CPPUNIT_ASSERT((TagLib::uint)0x02 == f.entryCount());
CPPUNIT_ASSERT_EQUAL(ByteVector("C"), f.childElements()[0]);
CPPUNIT_ASSERT_EQUAL(ByteVector("D"), f.childElements()[1]);
CPPUNIT_ASSERT((TagLib::uint)0x01 == f.embeddedFrameList().size());
CPPUNIT_ASSERT(f.embeddedFrameList("TIT2").size() == 1);
CPPUNIT_ASSERT(f.embeddedFrameList("TIT2")[0]->toString() == "TC1");
}
@ -1050,6 +1098,37 @@ public:
}
}
void testEmptyFrame()
{
ScopedFileCopy copy("xing", ".mp3");
string newname = copy.fileName();
{
MPEG::File f(newname.c_str());
ID3v2::Tag *tag = f.ID3v2Tag(true);
ID3v2::UrlLinkFrame *frame1 = new ID3v2::UrlLinkFrame(
ByteVector("WOAF\x00\x00\x00\x01\x00\x00\x00", 11));
tag->addFrame(frame1);
ID3v2::TextIdentificationFrame *frame2 = new ID3v2::TextIdentificationFrame("TIT2");
frame2->setText("Title");
tag->addFrame(frame2);
f.save();
}
{
MPEG::File f(newname.c_str());
CPPUNIT_ASSERT_EQUAL(true, f.hasID3v2Tag());
ID3v2::Tag *tag = f.ID3v2Tag();
CPPUNIT_ASSERT_EQUAL(String("Title"), tag->title());
CPPUNIT_ASSERT_EQUAL(true, tag->frameListMap()["WOAF"].isEmpty());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2);

View File

@ -34,16 +34,17 @@ public:
{
RIFF::Info::Tag tag;
CPPUNIT_ASSERT_EQUAL((uint)0, tag.track());
CPPUNIT_ASSERT_EQUAL((TagLib::uint)0, tag.track());
tag.setTrack(1234);
CPPUNIT_ASSERT_EQUAL((uint)1234, tag.track());
CPPUNIT_ASSERT_EQUAL((TagLib::uint)1234, tag.track());
CPPUNIT_ASSERT_EQUAL(String("1234"), tag.fieldText("IPRT"));
CPPUNIT_ASSERT_EQUAL((uint)0, tag.year());
CPPUNIT_ASSERT_EQUAL((TagLib::uint)0, tag.year());
tag.setYear(1234);
CPPUNIT_ASSERT_EQUAL((uint)1234, tag.year());
CPPUNIT_ASSERT_EQUAL((TagLib::uint)1234, tag.year());
CPPUNIT_ASSERT_EQUAL(String("1234"), tag.fieldText("ICRD"));
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestInfoTag);

View File

@ -22,8 +22,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <tlist.h>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
using namespace TagLib;
@ -51,7 +51,7 @@ public:
l3.append(3);
l3.append(4);
CPPUNIT_ASSERT(l1 == l3);
List<int> l4 = l1;
List<int>::Iterator it = l4.find(3);
*it = 33;

View File

@ -1,6 +1,6 @@
#include <cppunit/extensions/HelperMacros.h>
#include <tstring.h>
#include <tmap.h>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
using namespace TagLib;

View File

@ -19,6 +19,7 @@ class TestMP4 : public CppUnit::TestFixture
CPPUNIT_TEST(testPropertiesALAC);
CPPUNIT_TEST(testFreeForm);
CPPUNIT_TEST(testCheckValid);
CPPUNIT_TEST(testIsEmpty);
CPPUNIT_TEST(testUpdateStco);
CPPUNIT_TEST(testSaveExisingWhenIlstIsLast);
CPPUNIT_TEST(test64BitAtom);
@ -27,6 +28,7 @@ class TestMP4 : public CppUnit::TestFixture
CPPUNIT_TEST(testCovrWrite);
CPPUNIT_TEST(testCovrRead2);
CPPUNIT_TEST(testProperties);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST_SUITE_END();
public:
@ -34,23 +36,31 @@ public:
void testPropertiesAAC()
{
MP4::File f(TEST_FILE_PATH_C("has-tags.m4a"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3707, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, ((MP4::AudioProperties *)f.audioProperties())->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(MP4::AudioProperties::AAC, ((MP4::AudioProperties *)f.audioProperties())->codec());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isEncrypted());
CPPUNIT_ASSERT_EQUAL(MP4::AudioProperties::AAC, f.audioProperties()->codec());
}
void testPropertiesALAC()
{
MP4::File f(TEST_FILE_PATH_C("empty_alac.m4a"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, ((MP4::AudioProperties *)f.audioProperties())->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(MP4::AudioProperties::ALAC, ((MP4::AudioProperties *)f.audioProperties())->codec());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isEncrypted());
CPPUNIT_ASSERT_EQUAL(MP4::AudioProperties::ALAC, f.audioProperties()->codec());
}
void testCheckValid()
@ -61,6 +71,18 @@ public:
CPPUNIT_ASSERT(f2.isValid());
}
void testIsEmpty()
{
MP4::Tag t1;
CPPUNIT_ASSERT(t1.isEmpty());
t1.setArtist("Foo");
CPPUNIT_ASSERT(!t1.isEmpty());
MP4::Tag t2;
t2.setItem("foo", "bar");
CPPUNIT_ASSERT(!t2.isEmpty());
}
void testUpdateStco()
{
ScopedFileCopy copy("no-tags", ".3g2");
@ -74,7 +96,7 @@ public:
MP4::Atoms a(f);
MP4::Atom *stco = a.find("moov")->findall("stco", true)[0];
f->seek(stco->offset + 12);
ByteVector data = f->readBlock(stco->length - 12);
ByteVector data = f->readBlock(static_cast<size_t>(stco->length - 12));
unsigned int count = data.toUInt32BE(0);
size_t pos = 4;
while (count--) {
@ -93,7 +115,7 @@ public:
MP4::Atoms a(f);
MP4::Atom *stco = a.find("moov")->findall("stco", true)[0];
f->seek(stco->offset + 12);
ByteVector data = f->readBlock(stco->length - 12);
ByteVector data = f->readBlock(static_cast<size_t>(stco->length - 12));
unsigned int count = data.toUInt32BE(0);
size_t pos = 4, i = 0;
while (count--) {
@ -114,14 +136,15 @@ public:
string filename = copy.fileName();
MP4::File *f = new MP4::File(filename.c_str());
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("----:com.apple.iTunes:iTunNORM"));
f->tag()->itemListMap()["----:org.kde.TagLib:Foo"] = StringList("Bar");
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()->itemListMap().contains("----:org.kde.TagLib:Foo"));
CPPUNIT_ASSERT_EQUAL(String("Bar"), f->tag()->itemListMap()["----:org.kde.TagLib:Foo"].toStringList()[0]);
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;
}
@ -132,14 +155,16 @@ public:
string filename = copy.fileName();
MP4::File *f = new MP4::File(filename.c_str());
CPPUNIT_ASSERT_EQUAL(String("82,164"), f->tag()->itemListMap()["----:com.apple.iTunes:replaygain_track_minmax"].toStringList()[0]);
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()->itemListMap()["----:com.apple.iTunes:replaygain_track_minmax"].toStringList()[0]);
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;
@ -151,20 +176,20 @@ public:
string filename = copy.fileName();
MP4::File *f = new MP4::File(filename.c_str());
CPPUNIT_ASSERT_EQUAL(true, f->tag()->itemListMap()["cpil"].toBool());
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);
f->tag()->itemListMap()["pgap"] = true;
f->tag()->setItem("pgap", true);
f->save();
delete atoms;
delete f;
f = new MP4::File(filename.c_str());
CPPUNIT_ASSERT_EQUAL(true, f->tag()->itemListMap()["cpil"].toBool());
CPPUNIT_ASSERT_EQUAL(true, f->tag()->itemListMap()["pgap"].toBool());
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];
@ -184,8 +209,8 @@ public:
void testCovrRead()
{
MP4::File *f = new MP4::File(TEST_FILE_PATH_C("has-tags.m4a"));
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr"));
MP4::CoverArtList l = f->tag()->itemListMap()["covr"].toCoverArtList();
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());
@ -200,16 +225,16 @@ public:
string filename = copy.fileName();
MP4::File *f = new MP4::File(filename.c_str());
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr"));
MP4::CoverArtList l = f->tag()->itemListMap()["covr"].toCoverArtList();
CPPUNIT_ASSERT(f->tag()->contains("covr"));
MP4::CoverArtList l = f->tag()->item("covr").toCoverArtList();
l.append(MP4::CoverArt(MP4::CoverArt::PNG, "foo"));
f->tag()->itemListMap()["covr"] = l;
f->tag()->setItem("covr", l);
f->save();
delete f;
f = new MP4::File(filename.c_str());
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr"));
l = f->tag()->itemListMap()["covr"].toCoverArtList();
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());
@ -223,8 +248,8 @@ public:
void testCovrRead2()
{
MP4::File *f = new MP4::File(TEST_FILE_PATH_C("covr-junk.m4a"));
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr"));
MP4::CoverArtList l = f->tag()->itemListMap()["covr"].toCoverArtList();
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());
@ -250,26 +275,26 @@ public:
tags = f.properties();
CPPUNIT_ASSERT(f.tag()->itemListMap().contains("trkn"));
CPPUNIT_ASSERT_EQUAL(2, f.tag()->itemListMap()["trkn"].toIntPair().first);
CPPUNIT_ASSERT_EQUAL(4, f.tag()->itemListMap()["trkn"].toIntPair().second);
CPPUNIT_ASSERT(f.tag()->contains("trkn"));
CPPUNIT_ASSERT_EQUAL(2, f.tag()->item("trkn").toIntPair().first);
CPPUNIT_ASSERT_EQUAL(4, f.tag()->item("trkn").toIntPair().second);
CPPUNIT_ASSERT_EQUAL(StringList("2/4"), tags["TRACKNUMBER"]);
CPPUNIT_ASSERT(f.tag()->itemListMap().contains("disk"));
CPPUNIT_ASSERT_EQUAL(3, f.tag()->itemListMap()["disk"].toIntPair().first);
CPPUNIT_ASSERT_EQUAL(5, f.tag()->itemListMap()["disk"].toIntPair().second);
CPPUNIT_ASSERT(f.tag()->contains("disk"));
CPPUNIT_ASSERT_EQUAL(3, f.tag()->item("disk").toIntPair().first);
CPPUNIT_ASSERT_EQUAL(5, f.tag()->item("disk").toIntPair().second);
CPPUNIT_ASSERT_EQUAL(StringList("3/5"), tags["DISCNUMBER"]);
CPPUNIT_ASSERT(f.tag()->itemListMap().contains("tmpo"));
CPPUNIT_ASSERT_EQUAL(123, f.tag()->itemListMap()["tmpo"].toInt());
CPPUNIT_ASSERT(f.tag()->contains("tmpo"));
CPPUNIT_ASSERT_EQUAL(123, f.tag()->item("tmpo").toInt());
CPPUNIT_ASSERT_EQUAL(StringList("123"), tags["BPM"]);
CPPUNIT_ASSERT(f.tag()->itemListMap().contains("\251ART"));
CPPUNIT_ASSERT_EQUAL(StringList("Foo Bar"), f.tag()->itemListMap()["\251ART"].toStringList());
CPPUNIT_ASSERT(f.tag()->contains("\251ART"));
CPPUNIT_ASSERT_EQUAL(StringList("Foo Bar"), f.tag()->item("\251ART").toStringList());
CPPUNIT_ASSERT_EQUAL(StringList("Foo Bar"), tags["ARTIST"]);
CPPUNIT_ASSERT(f.tag()->itemListMap().contains("cpil"));
CPPUNIT_ASSERT_EQUAL(true, f.tag()->itemListMap()["cpil"].toBool());
CPPUNIT_ASSERT(f.tag()->contains("cpil"));
CPPUNIT_ASSERT_EQUAL(true, f.tag()->item("cpil").toBool());
CPPUNIT_ASSERT_EQUAL(StringList("1"), tags["COMPILATION"]);
tags["COMPILATION"] = StringList("0");
@ -277,11 +302,17 @@ public:
tags = f.properties();
CPPUNIT_ASSERT(f.tag()->itemListMap().contains("cpil"));
CPPUNIT_ASSERT_EQUAL(false, f.tag()->itemListMap()["cpil"].toBool());
CPPUNIT_ASSERT(f.tag()->contains("cpil"));
CPPUNIT_ASSERT_EQUAL(false, f.tag()->item("cpil").toBool());
CPPUNIT_ASSERT_EQUAL(StringList("0"), tags["COMPILATION"]);
}
void testFuzzedFile()
{
MP4::File f(TEST_FILE_PATH_C("infloop.m4a"));
CPPUNIT_ASSERT(f.isValid());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4);

View File

@ -28,41 +28,61 @@ public:
void testPropertiesSV8()
{
MPC::File f(TEST_FILE_PATH_C("sv8_header.mpc"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->mpcVersion());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(1497, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(66014U, f.audioProperties()->sampleFrames());
}
void testPropertiesSV7()
{
MPC::File f(TEST_FILE_PATH_C("click.mpc"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->mpcVersion());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(40, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(318, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(1760U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(14221, f.audioProperties()->trackGain());
CPPUNIT_ASSERT_EQUAL(19848, f.audioProperties()->trackPeak());
CPPUNIT_ASSERT_EQUAL(14221, f.audioProperties()->albumGain());
CPPUNIT_ASSERT_EQUAL(19848, f.audioProperties()->albumPeak());
}
void testPropertiesSV5()
{
MPC::File f(TEST_FILE_PATH_C("sv5_header.mpc"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(5, f.audioProperties()->mpcVersion());
CPPUNIT_ASSERT_EQUAL(26, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(26, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(26371, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(1162944U, f.audioProperties()->sampleFrames());
}
void testPropertiesSV4()
{
MPC::File f(TEST_FILE_PATH_C("sv4_header.mpc"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(4, f.audioProperties()->mpcVersion());
CPPUNIT_ASSERT_EQUAL(26, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(26, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(26371, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(1162944U, f.audioProperties()->sampleFrames());
}
void testFuzzedFile1()

View File

@ -3,6 +3,9 @@
#include <tstring.h>
#include <mpegfile.h>
#include <id3v2tag.h>
#include <mpegproperties.h>
#include <xingheader.h>
#include <mpegheader.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -12,20 +15,96 @@ using namespace TagLib;
class TestMPEG : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestMPEG);
CPPUNIT_TEST(testAudioPropertiesXingHeaderCBR);
CPPUNIT_TEST(testAudioPropertiesXingHeaderVBR);
CPPUNIT_TEST(testAudioPropertiesVBRIHeader);
CPPUNIT_TEST(testAudioPropertiesNoVBRHeaders);
CPPUNIT_TEST(testVersion2DurationWithXingHeader);
CPPUNIT_TEST(testSaveID3v24);
CPPUNIT_TEST(testSaveID3v24WrongParam);
CPPUNIT_TEST(testSaveID3v23);
CPPUNIT_TEST(testDuplicateID3v2);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST(testFrameOffset);
CPPUNIT_TEST_SUITE_END();
public:
void testAudioPropertiesXingHeaderCBR()
{
MPEG::File f(TEST_FILE_PATH_C("lame_cbr.mp3"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(1887, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(1887, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(1887164, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(MPEG::XingHeader::Xing, f.audioProperties()->xingHeader()->type());
}
void testAudioPropertiesXingHeaderVBR()
{
MPEG::File f(TEST_FILE_PATH_C("lame_vbr.mp3"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(1887, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(1887, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(1887164, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(70, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(MPEG::XingHeader::Xing, f.audioProperties()->xingHeader()->type());
}
void testAudioPropertiesVBRIHeader()
{
MPEG::File f(TEST_FILE_PATH_C("vbri.mp3"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(222, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(222, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(222198, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(233, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(MPEG::XingHeader::VBRI, f.audioProperties()->xingHeader()->type());
}
void testAudioPropertiesNoVBRHeaders()
{
MPEG::File f(TEST_FILE_PATH_C("bladeenc.mp3"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3553, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT(!f.audioProperties()->xingHeader());
offset_t last = f.lastFrameOffset();
f.seek(last);
MPEG::Header lastHeader(f.readBlock(4));
while (!lastHeader.isValid()) {
last = f.previousFrameOffset(last);
f.seek(last);
lastHeader = MPEG::Header(f.readBlock(4));
}
CPPUNIT_ASSERT_EQUAL((offset_t)28213, last);
CPPUNIT_ASSERT_EQUAL(209, lastHeader.frameLength());
}
void testVersion2DurationWithXingHeader()
{
MPEG::File f(TEST_FILE_PATH_C("mpeg2.mp3"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(5387, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(5387, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(5387285, f.audioProperties()->lengthInMilliseconds());
}
void testSaveID3v24()
@ -96,14 +175,12 @@ public:
void testDuplicateID3v2()
{
ScopedFileCopy copy("duplicate_id3v2", ".mp3");
string newname = copy.fileName();
MPEG::File f(newname.c_str());
MPEG::File f(TEST_FILE_PATH_C("duplicate_id3v2.mp3"));
// duplicate_id3v2.mp3 has duplicate ID3v2 tags.
// Sample rate will be 32000 if can't skip the second tag.
CPPUNIT_ASSERT(f.hasID3v2Tag());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
}
@ -113,6 +190,28 @@ public:
CPPUNIT_ASSERT(f.isValid());
}
void testFrameOffset()
{
{
MPEG::File f(TEST_FILE_PATH_C("ape.mp3"));
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)0x0000, f.firstFrameOffset());
CPPUNIT_ASSERT_EQUAL((offset_t)0x1FD6, f.lastFrameOffset());
}
{
MPEG::File f(TEST_FILE_PATH_C("ape-id3v1.mp3"));
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)0x0000, f.firstFrameOffset());
CPPUNIT_ASSERT_EQUAL((offset_t)0x1FD6, f.lastFrameOffset());
}
{
MPEG::File f(TEST_FILE_PATH_C("ape-id3v2.mp3"));
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT_EQUAL((offset_t)0x041A, f.firstFrameOffset());
CPPUNIT_ASSERT_EQUAL((offset_t)0x23F0, f.lastFrameOffset());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestMPEG);

View File

@ -20,6 +20,7 @@ class TestOGG : public CppUnit::TestFixture
CPPUNIT_TEST(testSplitPackets);
CPPUNIT_TEST(testDictInterface1);
CPPUNIT_TEST(testDictInterface2);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST_SUITE_END();
public:
@ -44,13 +45,27 @@ public:
ScopedFileCopy copy("empty", ".ogg");
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::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str());
f->tag()->addField("test", ByteVector(128 * 1024, 'x') + ByteVector(1, '\0'));
f->tag()->setTitle(longText);
f->save();
delete f;
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;
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;
}
@ -104,6 +119,21 @@ public:
delete f;
}
void testAudioProperties()
{
Ogg::Vorbis::File f(TEST_FILE_PATH_C("empty.ogg"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(9, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->vorbisVersion());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrateMaximum());
CPPUNIT_ASSERT_EQUAL(112000, f.audioProperties()->bitrateNominal());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrateMinimum());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestOGG);

View File

@ -34,8 +34,8 @@ public:
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
f->seek(0, File::End);
int size = f->tell();
CPPUNIT_ASSERT_EQUAL(9134, size);
offset_t size = f->tell();
CPPUNIT_ASSERT_EQUAL((offset_t)9134, size);
delete f;
}

View File

@ -12,21 +12,25 @@ using namespace TagLib;
class TestOpus : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestOpus);
CPPUNIT_TEST(testProperties);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST(testReadComments);
CPPUNIT_TEST(testWriteComments);
CPPUNIT_TEST_SUITE_END();
public:
void testProperties()
void testAudioProperties()
{
Ogg::Opus::File f(TEST_FILE_PATH_C("correctness_gain_silent_output.opus"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(41, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(37, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(48000, ((Ogg::Opus::AudioProperties *)f.audioProperties())->inputSampleRate());
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->inputSampleRate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->opusVersion());
}
void testReadComments()

View File

@ -1,25 +1,32 @@
#include <cppunit/extensions/HelperMacros.h>
#include <tpropertymap.h>
#include <tag.h>
#include <id3v1tag.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
using namespace TagLib;
class TestPropertyMap : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestPropertyMap);
CPPUNIT_TEST(testInvalidKeys);
CPPUNIT_TEST(testGetSet);
CPPUNIT_TEST_SUITE_END();
public:
void testInvalidKeys()
{
TagLib::PropertyMap map1;
PropertyMap map1;
CPPUNIT_ASSERT(map1.isEmpty());
map1[L"\x00c4\x00d6\x00dc"].append("test");
CPPUNIT_ASSERT_EQUAL(map1.size(), (size_t)1);
TagLib::PropertyMap map2;
PropertyMap map2;
map2[L"\x00c4\x00d6\x00dc"].append("test");
CPPUNIT_ASSERT(map1 == map2);
CPPUNIT_ASSERT(map1.contains(map2));
map2["ARTIST"] = TagLib::String("Test Artist");
map2["ARTIST"] = String("Test Artist");
CPPUNIT_ASSERT(map1 != map2);
CPPUNIT_ASSERT(map2.contains(map1));
@ -28,6 +35,43 @@ public:
CPPUNIT_ASSERT(!map2.contains(map1));
}
void testGetSet()
{
ID3v1::Tag tag;
tag.setTitle("Test Title");
tag.setArtist("Test Artist");
tag.setAlbum("Test Album");
tag.setYear(2015);
tag.setTrack(10);
{
PropertyMap prop = tag.properties();
CPPUNIT_ASSERT_EQUAL(String("Test Title"), prop["TITLE" ].front());
CPPUNIT_ASSERT_EQUAL(String("Test Artist"), prop["ARTIST" ].front());
CPPUNIT_ASSERT_EQUAL(String("Test Album"), prop["ALBUM" ].front());
CPPUNIT_ASSERT_EQUAL(String("2015"), prop["DATE" ].front());
CPPUNIT_ASSERT_EQUAL(String("10"), prop["TRACKNUMBER"].front());
prop["TITLE" ].front() = "Test Title 2";
prop["ARTIST" ].front() = "Test Artist 2";
prop["TRACKNUMBER"].front() = "5";
tag.setProperties(prop);
}
CPPUNIT_ASSERT_EQUAL(String("Test Title 2"), tag.title());
CPPUNIT_ASSERT_EQUAL(String("Test Artist 2"), tag.artist());
CPPUNIT_ASSERT_EQUAL(5U, tag.track());
tag.setProperties(PropertyMap());
CPPUNIT_ASSERT_EQUAL(String(""), tag.title());
CPPUNIT_ASSERT_EQUAL(String(""), tag.artist());
CPPUNIT_ASSERT_EQUAL(0U, tag.track());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestPropertyMap);

View File

@ -15,12 +15,12 @@ public:
PublicRIFF(FileName file) : RIFF::File(file, BigEndian) {};
TagLib::uint riffSize() { return RIFF::File::riffSize(); };
TagLib::uint chunkCount() { return RIFF::File::chunkCount(); };
TagLib::uint chunkOffset(TagLib::uint i) { return RIFF::File::chunkOffset(i); };
offset_t chunkOffset(TagLib::uint i) { return RIFF::File::chunkOffset(i); };
TagLib::uint chunkPadding(TagLib::uint i) { return RIFF::File::chunkPadding(i); };
TagLib::uint chunkDataSize(TagLib::uint i) { return RIFF::File::chunkDataSize(i); };
ByteVector chunkName(TagLib::uint i) { return RIFF::File::chunkName(i); };
ByteVector chunkData(TagLib::uint i) { return RIFF::File::chunkData(i); };
void setChunkData(uint i, const ByteVector &data) {
void setChunkData(TagLib::uint i, const ByteVector &data) {
RIFF::File::setChunkData(i, data);
}
void setChunkData(const ByteVector &name, const ByteVector &data) {
@ -29,7 +29,7 @@ public:
virtual TagLib::Tag* tag() const { return 0; };
virtual TagLib::AudioProperties* audioProperties() const { return 0;};
virtual bool save() { return false; };
void removeChunk(uint i) { RIFF::File::removeChunk(i); }
void removeChunk(TagLib::uint i) { RIFF::File::removeChunk(i); }
void removeChunk(const ByteVector &name) { RIFF::File::removeChunk(name); }
};
@ -52,7 +52,7 @@ public:
PublicRIFF *f = new PublicRIFF(filename.c_str());
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f->chunkOffset(2));
CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f->chunkOffset(2));
f->setChunkData("TEST", "foo");
delete f;
@ -61,7 +61,7 @@ public:
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(TagLib::uint(0x1728 + 8), f->chunkOffset(2));
CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f->chunkOffset(2));
f->setChunkData("SSND", "abcd");
@ -96,18 +96,18 @@ public:
string filename = copy.fileName();
PublicRIFF *f = new PublicRIFF(filename.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f->chunkOffset(2));
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(TagLib::uint(4088), f->chunkOffset(2));
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(TagLib::uint(4408), f->chunkOffset(3));
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));
@ -115,11 +115,11 @@ public:
delete f;
f = new PublicRIFF(filename.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
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(TagLib::uint(4408), f->chunkOffset(3));
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));
@ -133,18 +133,18 @@ public:
string filename = copy.fileName();
PublicRIFF *f = new PublicRIFF(filename.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f->chunkOffset(2));
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(TagLib::uint(4088), f->chunkOffset(2));
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(TagLib::uint(4408), f->chunkOffset(3));
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));
@ -152,11 +152,11 @@ public:
delete f;
f = new PublicRIFF(filename.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
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(TagLib::uint(4408), f->chunkOffset(3));
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));
@ -170,18 +170,18 @@ public:
string filename = copy.fileName();
PublicRIFF *f = new PublicRIFF(filename.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0xff0 + 8), f->chunkOffset(2));
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(TagLib::uint(4088), f->chunkOffset(2));
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(TagLib::uint(4408), f->chunkOffset(3));
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));
@ -189,11 +189,11 @@ public:
delete f;
f = new PublicRIFF(filename.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2));
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(TagLib::uint(4408), f->chunkOffset(3));
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));
@ -209,17 +209,17 @@ public:
PublicRIFF *f = new PublicRIFF(filename.c_str());
CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->chunkName(0));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f->chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f->chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f->chunkOffset(2));
CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f->chunkOffset(2));
const ByteVector data(0x400, ' ');
f->setChunkData("SSND", data);
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f->chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x042E + 8), f->chunkOffset(2));
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));
@ -229,9 +229,9 @@ public:
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4));
f->setChunkData(0, data);
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f->chunkOffset(1));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x081C + 8), f->chunkOffset(2));
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));
@ -241,8 +241,8 @@ public:
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4));
f->removeChunk("SSND");
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0));
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f->chunkOffset(1));
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));
@ -250,7 +250,7 @@ public:
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4));
f->removeChunk(0);
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(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));
@ -261,3 +261,4 @@ public:
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestRIFF);

31
tests/test_speex.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <speexfile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
using namespace std;
using namespace TagLib;
class TestSpeex : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestSpeex);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST_SUITE_END();
public:
void testAudioProperties()
{
Ogg::Speex::File f(TEST_FILE_PATH_C("empty.spx"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(53, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(-1, f.audioProperties()->bitrateNominal());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestSpeex);

View File

@ -38,6 +38,7 @@ class TestString : public CppUnit::TestFixture
CPPUNIT_TEST(testUTF16Decode);
CPPUNIT_TEST(testUTF16DecodeInvalidBOM);
CPPUNIT_TEST(testUTF16DecodeEmptyWithBOM);
CPPUNIT_TEST(testSurrogatePair);
CPPUNIT_TEST(testAppendCharDetach);
CPPUNIT_TEST(testAppendStringDetach);
CPPUNIT_TEST(testToInt);
@ -118,12 +119,10 @@ public:
CPPUNIT_ASSERT(memcmp(String("foo").data(String::Latin1).data(), "foo", 3) == 0);
CPPUNIT_ASSERT(memcmp(String("f").data(String::Latin1).data(), "f", 1) == 0);
ByteVector utf16 = unicode.data(String::UTF16);
// Check to make sure that the BOM is there and that the data size is correct
// Check to make sure that the BOM is there and that the data size is correct
const ByteVector utf16 = unicode.data(String::UTF16);
CPPUNIT_ASSERT(utf16.size() == 2 + (unicode.size() * 2));
CPPUNIT_ASSERT(unicode == String(utf16, String::UTF16));
}
@ -170,6 +169,21 @@ public:
CPPUNIT_ASSERT_EQUAL(String(), String(b, String::UTF16));
}
void testSurrogatePair()
{
// Make sure that a surrogate pair is converted into single UTF-8 char
// and vice versa.
const ByteVector v1("\xff\xfe\x42\xd8\xb7\xdf\xce\x91\x4b\x5c");
const ByteVector v2("\xf0\xa0\xae\xb7\xe9\x87\x8e\xe5\xb1\x8b");
const String s1(v1, String::UTF16);
CPPUNIT_ASSERT_EQUAL(s1.data(String::UTF8), v2);
const String s2(v2, String::UTF8);
CPPUNIT_ASSERT_EQUAL(s2.data(String::UTF16), v1);
}
void testAppendStringDetach()
{
String a("abc");
@ -336,3 +350,4 @@ public:
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);

View File

@ -1,7 +1,7 @@
#include <cppunit/extensions/HelperMacros.h>
#include <string>
#include <stdio.h>
#include <trueaudiofile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
using namespace std;
@ -11,6 +11,7 @@ class TestTrueAudio : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestTrueAudio);
CPPUNIT_TEST(testReadPropertiesWithoutID3v2);
CPPUNIT_TEST(testReadPropertiesWithTags);
CPPUNIT_TEST_SUITE_END();
public:
@ -20,6 +21,29 @@ public:
TrueAudio::File f(TEST_FILE_PATH_C("empty.tta"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(173, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(162496U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->ttaVersion());
}
void testReadPropertiesWithTags()
{
TrueAudio::File f(TEST_FILE_PATH_C("tagged.tta"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(173, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(162496U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->ttaVersion());
}
};

View File

@ -14,23 +14,66 @@ using namespace TagLib;
class TestWAV : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestWAV);
CPPUNIT_TEST(testLength);
CPPUNIT_TEST(testPCMProperties);
CPPUNIT_TEST(testALAWProperties);
CPPUNIT_TEST(testFloatProperties);
CPPUNIT_TEST(testZeroSizeDataChunk);
CPPUNIT_TEST(testID3v2Tag);
CPPUNIT_TEST(testInfoTag);
CPPUNIT_TEST(testStripTags);
CPPUNIT_TEST(testFormat);
CPPUNIT_TEST(testDuplicateTags);
CPPUNIT_TEST(testFuzzedFile1);
CPPUNIT_TEST(testFuzzedFile2);
CPPUNIT_TEST_SUITE_END();
public:
void testLength()
void testPCMProperties()
{
RIFF::WAV::File f(TEST_FILE_PATH_C("empty.wav"));
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3675, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(32, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(1000, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->sampleWidth());
CPPUNIT_ASSERT_EQUAL(3675U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->format());
}
void testALAWProperties()
{
RIFF::WAV::File f(TEST_FILE_PATH_C("alaw.wav"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(128, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(8000, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->sampleWidth());
CPPUNIT_ASSERT_EQUAL(28400U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(6, f.audioProperties()->format());
}
void testFloatProperties()
{
RIFF::WAV::File f(TEST_FILE_PATH_C("float64.wav"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(97, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(5645, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->sampleWidth());
CPPUNIT_ASSERT_EQUAL(4281U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->format());
}
void testZeroSizeDataChunk()
@ -142,15 +185,18 @@ public:
delete f;
}
void testFormat()
void testDuplicateTags()
{
RIFF::WAV::File f1(TEST_FILE_PATH_C("empty.wav"));
CPPUNIT_ASSERT_EQUAL(true, f1.isValid());
CPPUNIT_ASSERT_EQUAL((uint)1, f1.audioProperties()->format());
RIFF::WAV::File f(TEST_FILE_PATH_C("duplicate_tags.wav"));
RIFF::WAV::File f2(TEST_FILE_PATH_C("alaw.wav"));
CPPUNIT_ASSERT_EQUAL(true, f2.isValid());
CPPUNIT_ASSERT_EQUAL((uint)6, f2.audioProperties()->format());
// duplicate_tags.wav has duplicate ID3v2/INFO tags.
// title() returns "Title2" if can't skip the second tag.
CPPUNIT_ASSERT(f.hasID3v2Tag());
CPPUNIT_ASSERT_EQUAL(String("Title1"), f.ID3v2Tag()->title());
CPPUNIT_ASSERT(f.hasInfoTag());
CPPUNIT_ASSERT_EQUAL(String("Title1"), f.InfoTag()->title());
}
void testFuzzedFile1()

View File

@ -1,9 +1,9 @@
#include <cppunit/extensions/HelperMacros.h>
#include <string>
#include <stdio.h>
#include <tag.h>
#include <tbytevectorlist.h>
#include <wavpackfile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
using namespace std;
@ -12,29 +12,67 @@ using namespace TagLib;
class TestWavPack : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestWavPack);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testLengthScan);
CPPUNIT_TEST(testNoLengthProperties);
CPPUNIT_TEST(testMultiChannelProperties);
CPPUNIT_TEST(testTaggedProperties);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST_SUITE_END();
public:
void testBasic()
void testNoLengthProperties()
{
WavPack::File f(TEST_FILE_PATH_C("no_length.wv"));
WavPack::AudioProperties *props = f.audioProperties();
CPPUNIT_ASSERT_EQUAL(44100, props->sampleRate());
CPPUNIT_ASSERT_EQUAL(2, props->channels());
CPPUNIT_ASSERT_EQUAL(1, props->bitrate());
CPPUNIT_ASSERT_EQUAL(0x407, props->version());
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(true, f.audioProperties()->isLossless());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(163392U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
}
void testLengthScan()
void testMultiChannelProperties()
{
WavPack::File f(TEST_FILE_PATH_C("no_length.wv"));
WavPack::AudioProperties *props = f.audioProperties();
CPPUNIT_ASSERT_EQUAL(4, props->length());
WavPack::File f(TEST_FILE_PATH_C("four_channels.wv"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3833, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(112, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(4, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isLossless());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(169031U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
}
void testTaggedProperties()
{
WavPack::File f(TEST_FILE_PATH_C("tagged.wv"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(172, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isLossless());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
}
void testFuzzedFile()
{
WavPack::File f(TEST_FILE_PATH_C("infloop.wv"));
CPPUNIT_ASSERT(f.isValid());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestWavPack);

View File

@ -27,24 +27,27 @@ inline string testFilePath(const string &filename)
inline string copyFile(const string &filename, const string &ext)
{
char *newname_c = tempnam(NULL, NULL);
string newname = string(newname_c) + ext;
free(newname_c);
string oldname = testFilePath(filename) + ext;
char testFileName[1024];
#ifdef _WIN32
CopyFileA(oldname.c_str(), newname.c_str(), FALSE);
SetFileAttributesA(newname.c_str(), GetFileAttributesA(newname.c_str()) & ~FILE_ATTRIBUTE_READONLY);
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
#else
char buffer[4096];
int bytes;
int inf = open(oldname.c_str(), O_RDONLY);
int outf = open(newname.c_str(), O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
while((bytes = read(inf, buffer, sizeof(buffer))) > 0)
write(outf, buffer, bytes);
close(outf);
close(inf);
snprintf(testFileName, sizeof(testFileName), "/%s/taglib-test-XXXXXX%s", P_tmpdir, ext.c_str());
static_cast<void>(mkstemps(testFileName, 6));
#endif
return newname;
string sourceFileName = testFilePath(filename) + ext;
ifstream source(sourceFileName.c_str(), std::ios::binary);
ofstream destination(testFileName, std::ios::binary);
destination << source.rdbuf();
return string(testFileName);
}
inline void deleteFile(const string &filename)
@ -75,7 +78,7 @@ inline bool fileEqual(const string &filename1, const string &filename2)
if(n1 == 0) break;
if(memcmp(buf1, buf2, n1) != 0) return false;
if(memcmp(buf1, buf2, static_cast<size_t>(n1)) != 0) return false;
}
return stream1.good() == stream2.good();