mirror of
https://github.com/taglib/taglib.git
synced 2025-07-18 21:14:23 -04:00
Add my old WMA and MP4 code. It is disabled by default, must be explicitly enabled to be compiled.
Scott: If you think this is really a bad idea, please revert. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@883108 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
@ -3,10 +3,12 @@ if(BUILD_TESTS)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/toolkit
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/asf
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v1
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2/frames
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mp4
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/trueaudio
|
||||
)
|
||||
|
||||
@ -23,6 +25,12 @@ SET(test_runner_SRCS
|
||||
test_id3v1.cpp
|
||||
test_id3v2.cpp
|
||||
)
|
||||
IF(WITH_MP4)
|
||||
SET(test_runner_SRCS ${test_runner_SRCS} test_mp4.cpp)
|
||||
ENDIF(WITH_MP4)
|
||||
IF(WITH_ASF)
|
||||
SET(test_runner_SRCS ${test_runner_SRCS} test_asf.cpp)
|
||||
ENDIF(WITH_ASF)
|
||||
|
||||
ADD_EXECUTABLE(test_runner ${test_runner_SRCS})
|
||||
TARGET_LINK_LIBRARIES(test_runner tag ${CPPUNIT_LIBRARIES})
|
||||
|
BIN
tests/data/click.wv
Normal file
BIN
tests/data/click.wv
Normal file
Binary file not shown.
BIN
tests/data/has-tags.m4a
Normal file
BIN
tests/data/has-tags.m4a
Normal file
Binary file not shown.
BIN
tests/data/no-tags.3g2
Normal file
BIN
tests/data/no-tags.3g2
Normal file
Binary file not shown.
BIN
tests/data/no-tags.m4a
Normal file
BIN
tests/data/no-tags.m4a
Normal file
Binary file not shown.
BIN
tests/data/silence-1.wma
Normal file
BIN
tests/data/silence-1.wma
Normal file
Binary file not shown.
103
tests/test_asf.cpp
Normal file
103
tests/test_asf.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <tag.h>
|
||||
#include <tstringlist.h>
|
||||
#include <tbytevectorlist.h>
|
||||
#include <asffile.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestASF : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestASF);
|
||||
CPPUNIT_TEST(testProperties);
|
||||
CPPUNIT_TEST(testRead);
|
||||
CPPUNIT_TEST(testSaveMultipleValues);
|
||||
CPPUNIT_TEST(testSaveStream);
|
||||
CPPUNIT_TEST(testSaveLanguage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testProperties()
|
||||
{
|
||||
ASF::File f("data/silence-1.wma");
|
||||
CPPUNIT_ASSERT_EQUAL(4, f.audioProperties()->length());
|
||||
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate());
|
||||
}
|
||||
|
||||
void testRead()
|
||||
{
|
||||
ASF::File f("data/silence-1.wma");
|
||||
CPPUNIT_ASSERT_EQUAL(String("test"), f.tag()->title());
|
||||
}
|
||||
|
||||
void testSaveMultipleValues()
|
||||
{
|
||||
string newname = copyFile("silence-1", ".wma");
|
||||
|
||||
ASF::File *f = new ASF::File(newname.c_str());
|
||||
ASF::AttributeList values;
|
||||
values.append("Foo");
|
||||
values.append("Bar");
|
||||
f->tag()->attributeListMap()["WM/AlbumTitle"] = values;
|
||||
f->save();
|
||||
delete f;
|
||||
|
||||
f = new ASF::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(2, (int)f->tag()->attributeListMap()["WM/AlbumTitle"].size());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
void testSaveStream()
|
||||
{
|
||||
string newname = copyFile("silence-1", ".wma");
|
||||
|
||||
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->save();
|
||||
delete f;
|
||||
|
||||
f = new ASF::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(43, f->tag()->attributeListMap()["WM/AlbumTitle"][0].stream());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
void testSaveLanguage()
|
||||
{
|
||||
string newname = copyFile("silence-1", ".wma");
|
||||
|
||||
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->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());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestASF);
|
@ -11,11 +11,15 @@ using namespace TagLib;
|
||||
class TestFileRef : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestFileRef);
|
||||
CPPUNIT_TEST(testASF);
|
||||
CPPUNIT_TEST(testMusepack);
|
||||
CPPUNIT_TEST(testVorbis);
|
||||
CPPUNIT_TEST(testSpeex);
|
||||
CPPUNIT_TEST(testFLAC);
|
||||
CPPUNIT_TEST(testMP3);
|
||||
CPPUNIT_TEST(testMP4_1);
|
||||
CPPUNIT_TEST(testMP4_2);
|
||||
CPPUNIT_TEST(testMP4_3);
|
||||
CPPUNIT_TEST(testTrueAudio);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
@ -71,6 +75,11 @@ public:
|
||||
fileRefSave("click", ".mpc");
|
||||
}
|
||||
|
||||
void testASF()
|
||||
{
|
||||
fileRefSave("silence-1", ".wma");
|
||||
}
|
||||
|
||||
void testVorbis()
|
||||
{
|
||||
fileRefSave("empty", ".ogg");
|
||||
@ -96,6 +105,21 @@ public:
|
||||
fileRefSave("empty", ".tta");
|
||||
}
|
||||
|
||||
void testMP4_1()
|
||||
{
|
||||
fileRefSave("has-tags", ".m4a");
|
||||
}
|
||||
|
||||
void testMP4_2()
|
||||
{
|
||||
fileRefSave("no-tags", ".m4a");
|
||||
}
|
||||
|
||||
void testMP4_3()
|
||||
{
|
||||
fileRefSave("no-tags", ".3g2");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestFileRef);
|
||||
|
103
tests/test_mp4.cpp
Normal file
103
tests/test_mp4.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <tag.h>
|
||||
#include <mp4tag.h>
|
||||
#include <tbytevectorlist.h>
|
||||
#include <mp4atom.h>
|
||||
#include <mp4file.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestMP4 : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestMP4);
|
||||
CPPUNIT_TEST(testProperties);
|
||||
CPPUNIT_TEST(testFreeForm);
|
||||
CPPUNIT_TEST(testUpdateStco);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testProperties()
|
||||
{
|
||||
MP4::File f("data/has-tags.m4a");
|
||||
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
|
||||
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::Properties *)f.audioProperties())->bitsPerSample());
|
||||
}
|
||||
|
||||
void testUpdateStco()
|
||||
{
|
||||
string filename = copyFile("no-tags", ".3g2");
|
||||
|
||||
MP4::File *f = new MP4::File(filename.c_str());
|
||||
f->tag()->setArtist(ByteVector(3000, 'x'));
|
||||
|
||||
ByteVectorList data1;
|
||||
{
|
||||
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);
|
||||
unsigned int count = data.mid(0, 4).toUInt();
|
||||
int pos = 4;
|
||||
while (count--) {
|
||||
unsigned int offset = data.mid(pos, 4).toUInt();
|
||||
f->seek(offset);
|
||||
data1.append(f->readBlock(20));
|
||||
pos += 4;
|
||||
}
|
||||
}
|
||||
|
||||
f->save();
|
||||
delete f;
|
||||
f = new MP4::File(filename.c_str());
|
||||
|
||||
{
|
||||
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);
|
||||
unsigned int count = data.mid(0, 4).toUInt();
|
||||
int pos = 4, i = 0;
|
||||
while (count--) {
|
||||
unsigned int offset = data.mid(pos, 4).toUInt();
|
||||
f->seek(offset);
|
||||
CPPUNIT_ASSERT_EQUAL(data1[i], f->readBlock(20));
|
||||
pos += 4;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
delete f;
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
void testFreeForm()
|
||||
{
|
||||
string filename = copyFile("has-tags", ".m4a");
|
||||
|
||||
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");
|
||||
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]);
|
||||
f->save();
|
||||
delete f;
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4);
|
Reference in New Issue
Block a user