mirror of
https://github.com/taglib/taglib.git
synced 2025-07-21 06:24:19 -04:00
Merge branch 'master' into merge-master-to-taglib2
# Conflicts: # config.h.cmake # taglib/ogg/xiphcomment.cpp # taglib/taglib_config.h.cmake # taglib/toolkit/tbytevector.cpp # taglib/toolkit/trefcounter.cpp # taglib/toolkit/tstring.cpp # taglib/toolkit/tutils.h # taglib/toolkit/tzlib.cpp # taglib/xm/xmfile.cpp # tests/test_string.cpp # tests/test_xiphcomment.cpp
This commit is contained in:
BIN
tests/data/lowercase-fields.ogg
Normal file
BIN
tests/data/lowercase-fields.ogg
Normal file
Binary file not shown.
@ -46,6 +46,7 @@ class TestByteVector : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testIntegerConversion);
|
||||
CPPUNIT_TEST(testFloatingPointConversion);
|
||||
CPPUNIT_TEST(testReplace);
|
||||
CPPUNIT_TEST(testReplaceAndDetach);
|
||||
CPPUNIT_TEST(testIterator);
|
||||
CPPUNIT_TEST(testResize);
|
||||
CPPUNIT_TEST(testAppend1);
|
||||
@ -312,6 +313,45 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void testReplaceAndDetach()
|
||||
{
|
||||
{
|
||||
ByteVector a("abcdabf");
|
||||
ByteVector b = a;
|
||||
a.replace(ByteVector("a"), ByteVector("x"));
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("xbcdxbf"), a);
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), b);
|
||||
}
|
||||
{
|
||||
ByteVector a("abcdabf");
|
||||
ByteVector b = a;
|
||||
a.replace('a', 'x');
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("xbcdxbf"), a);
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), b);
|
||||
}
|
||||
{
|
||||
ByteVector a("abcdabf");
|
||||
ByteVector b = a;
|
||||
a.replace(ByteVector("ab"), ByteVector("xy"));
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("xycdxyf"), a);
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), b);
|
||||
}
|
||||
{
|
||||
ByteVector a("abcdabf");
|
||||
ByteVector b = a;
|
||||
a.replace(ByteVector("a"), ByteVector("<a>"));
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("<a>bcd<a>bf"), a);
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), b);
|
||||
}
|
||||
{
|
||||
ByteVector a("ab<c>dab<c>");
|
||||
ByteVector b = a;
|
||||
a.replace(ByteVector("<c>"), ByteVector("c"));
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabc"), a);
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("ab<c>dab<c>"), b);
|
||||
}
|
||||
}
|
||||
|
||||
void testIterator()
|
||||
{
|
||||
ByteVector v1("taglib");
|
||||
|
@ -62,6 +62,7 @@ class TestFLAC : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testUpdateID3v2);
|
||||
CPPUNIT_TEST(testEmptyID3v2);
|
||||
CPPUNIT_TEST(testStripTags);
|
||||
CPPUNIT_TEST(testRemoveXiphField);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -493,6 +494,28 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void testRemoveXiphField()
|
||||
{
|
||||
ScopedFileCopy copy("silence-44-s", ".flac");
|
||||
|
||||
{
|
||||
FLAC::File f(copy.fileName().c_str());
|
||||
f.xiphComment(true)->setTitle("XiphComment Title");
|
||||
f.ID3v2Tag(true)->setTitle("ID3v2 Title");
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
FLAC::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("XiphComment Title"), f.xiphComment()->title());
|
||||
f.xiphComment()->removeFields("TITLE");
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
FLAC::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String(), f.xiphComment()->title());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);
|
||||
|
@ -32,12 +32,13 @@ using namespace TagLib;
|
||||
class TestList : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestList);
|
||||
CPPUNIT_TEST(testList);
|
||||
CPPUNIT_TEST(testAppend);
|
||||
CPPUNIT_TEST(testDetach);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testList()
|
||||
void testAppend()
|
||||
{
|
||||
List<int> l1;
|
||||
List<int> l2;
|
||||
@ -51,14 +52,25 @@ public:
|
||||
l3.append(2);
|
||||
l3.append(3);
|
||||
l3.append(4);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)4, l1.size());
|
||||
CPPUNIT_ASSERT(l1 == l3);
|
||||
|
||||
List<int> l4 = l1;
|
||||
List<int>::Iterator it = l4.find(3);
|
||||
*it = 33;
|
||||
CPPUNIT_ASSERT_EQUAL(l1[2], 3);
|
||||
CPPUNIT_ASSERT_EQUAL(l4[2], 33);
|
||||
}
|
||||
|
||||
void testDetach()
|
||||
{
|
||||
List<int> l1;
|
||||
l1.append(1);
|
||||
l1.append(2);
|
||||
l1.append(3);
|
||||
l1.append(4);
|
||||
|
||||
List<int> l2 = l1;
|
||||
List<int>::Iterator it = l2.find(3);
|
||||
*it = 33;
|
||||
CPPUNIT_ASSERT_EQUAL(3, l1[2]);
|
||||
CPPUNIT_ASSERT_EQUAL(33, l2[2]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestList);
|
||||
|
@ -34,6 +34,7 @@ class TestMap : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestMap);
|
||||
CPPUNIT_TEST(testInsert);
|
||||
CPPUNIT_TEST(testDetach);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -42,19 +43,28 @@ public:
|
||||
{
|
||||
Map<String, int> m1;
|
||||
m1.insert("foo", 3);
|
||||
m1.insert("bar", 5);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, m1.size());
|
||||
CPPUNIT_ASSERT_EQUAL(3, m1["foo"]);
|
||||
CPPUNIT_ASSERT_EQUAL(5, m1["bar"]);
|
||||
m1.insert("foo", 7);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, m1.size());
|
||||
CPPUNIT_ASSERT_EQUAL(7, m1["foo"]);
|
||||
CPPUNIT_ASSERT_EQUAL(5, m1["bar"]);
|
||||
}
|
||||
|
||||
m1.insert("alice", 5);
|
||||
m1.insert("bob", 9);
|
||||
void testDetach()
|
||||
{
|
||||
Map<String, int> m1;
|
||||
m1.insert("alice", 5);
|
||||
m1.insert("bob", 9);
|
||||
m1.insert("carol", 11);
|
||||
|
||||
Map<String, int> m2 = m1;
|
||||
Map<String, int>::Iterator it = m2.find("bob");
|
||||
(*it).second = 99;
|
||||
CPPUNIT_ASSERT_EQUAL(m1["bob"], 9);
|
||||
CPPUNIT_ASSERT_EQUAL(m2["bob"], 99);
|
||||
CPPUNIT_ASSERT_EQUAL(9, m1["bob"]);
|
||||
CPPUNIT_ASSERT_EQUAL(99, m2["bob"]);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -42,7 +42,8 @@ class TestOGG : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestOGG);
|
||||
CPPUNIT_TEST(testSimple);
|
||||
CPPUNIT_TEST(testSplitPackets);
|
||||
CPPUNIT_TEST(testSplitPackets1);
|
||||
CPPUNIT_TEST(testSplitPackets2);
|
||||
CPPUNIT_TEST(testDictInterface1);
|
||||
CPPUNIT_TEST(testDictInterface2);
|
||||
CPPUNIT_TEST(testAudioProperties);
|
||||
@ -67,7 +68,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void testSplitPackets()
|
||||
void testSplitPackets1()
|
||||
{
|
||||
ScopedFileCopy copy("empty", ".ogg");
|
||||
string newname = copy.fileName();
|
||||
@ -110,6 +111,33 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void testSplitPackets2()
|
||||
{
|
||||
ScopedFileCopy copy("empty", ".ogg");
|
||||
string newname = copy.fileName();
|
||||
|
||||
const String text = longText(60890, true);
|
||||
|
||||
{
|
||||
Ogg::Vorbis::File f(newname.c_str());
|
||||
f.tag()->setTitle(text);
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
Ogg::Vorbis::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT(f.isValid());
|
||||
CPPUNIT_ASSERT_EQUAL(text, f.tag()->title());
|
||||
|
||||
f.tag()->setTitle("ABCDE");
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
Ogg::Vorbis::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT(f.isValid());
|
||||
CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
|
||||
}
|
||||
}
|
||||
|
||||
void testDictInterface1()
|
||||
{
|
||||
ScopedFileCopy copy("empty", ".ogg");
|
||||
|
@ -50,6 +50,7 @@ class TestString : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testEncodeNonLatin1);
|
||||
CPPUNIT_TEST(testEncodeEmpty);
|
||||
CPPUNIT_TEST(testIterator);
|
||||
CPPUNIT_TEST(testRedundantUTF8);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -109,6 +110,9 @@ public:
|
||||
CPPUNIT_ASSERT(String(" foo ").stripWhiteSpace() == String("foo"));
|
||||
CPPUNIT_ASSERT(String("foo ").stripWhiteSpace() == String("foo"));
|
||||
CPPUNIT_ASSERT(String(" foo").stripWhiteSpace() == String("foo"));
|
||||
CPPUNIT_ASSERT(String("foo").stripWhiteSpace() == String("foo"));
|
||||
CPPUNIT_ASSERT(String("f o o").stripWhiteSpace() == String("f o o"));
|
||||
CPPUNIT_ASSERT(String(" f o o ").stripWhiteSpace() == String("f o o"));
|
||||
|
||||
CPPUNIT_ASSERT(memcmp(String("foo").data(String::Latin1).data(), "foo", 3) == 0);
|
||||
CPPUNIT_ASSERT(memcmp(String("f").data(String::Latin1).data(), "f", 1) == 0);
|
||||
@ -265,6 +269,8 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(String("01"), String("0123456").substr(0, 2));
|
||||
CPPUNIT_ASSERT_EQUAL(String("12"), String("0123456").substr(1, 2));
|
||||
CPPUNIT_ASSERT_EQUAL(String("123456"), String("0123456").substr(1, 200));
|
||||
CPPUNIT_ASSERT_EQUAL(String("0123456"), String("0123456").substr(0, 7));
|
||||
CPPUNIT_ASSERT_EQUAL(String("0123456"), String("0123456").substr(0, 200));
|
||||
}
|
||||
|
||||
void testNewline()
|
||||
@ -332,6 +338,15 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(L'i', *it1);
|
||||
CPPUNIT_ASSERT_EQUAL(L'I', *it2);
|
||||
}
|
||||
|
||||
void testRedundantUTF8()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(String("/"), String(ByteVector("\x2F"), String::UTF8));
|
||||
CPPUNIT_ASSERT(String(ByteVector("\xC0\xAF"), String::UTF8).isEmpty());
|
||||
CPPUNIT_ASSERT(String(ByteVector("\xE0\x80\xAF"), String::UTF8).isEmpty());
|
||||
CPPUNIT_ASSERT(String(ByteVector("\xF0\x80\x80\xAF"), String::UTF8).isEmpty());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
|
||||
|
@ -42,10 +42,12 @@ class TestXiphComment : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testSetYear);
|
||||
CPPUNIT_TEST(testTrack);
|
||||
CPPUNIT_TEST(testSetTrack);
|
||||
CPPUNIT_TEST(testInvalidKeys);
|
||||
CPPUNIT_TEST(testInvalidKeys1);
|
||||
CPPUNIT_TEST(testInvalidKeys2);
|
||||
CPPUNIT_TEST(testClearComment);
|
||||
CPPUNIT_TEST(testRemoveFields);
|
||||
CPPUNIT_TEST(testPicture);
|
||||
CPPUNIT_TEST(testLowercaseFields);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -90,19 +92,32 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(String("3"), cmt.fieldListMap()["TRACKNUMBER"].front());
|
||||
}
|
||||
|
||||
void testInvalidKeys()
|
||||
void testInvalidKeys1()
|
||||
{
|
||||
PropertyMap map;
|
||||
map[""] = String("invalid key: empty string");
|
||||
map["A=B"] = String("invalid key: contains '='");
|
||||
map["A~B"] = String("invalid key: contains '~'");
|
||||
map["A\x7F" "B"] = String("invalid key: contains '\x7F'");
|
||||
map[L"A\x3456" "B"] = String("invalid key: Unicode");
|
||||
|
||||
Ogg::XiphComment cmt;
|
||||
PropertyMap unsuccessful = cmt.setProperties(map);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)3, unsuccessful.size());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)5, unsuccessful.size());
|
||||
CPPUNIT_ASSERT(cmt.properties().isEmpty());
|
||||
}
|
||||
|
||||
void testInvalidKeys2()
|
||||
{
|
||||
Ogg::XiphComment cmt;
|
||||
cmt.addField("", "invalid key: empty string");
|
||||
cmt.addField("A=B", "invalid key: contains '='");
|
||||
cmt.addField("A~B", "invalid key: contains '~'");
|
||||
cmt.addField("A\x7F" "B", "invalid key: contains '\x7F'");
|
||||
cmt.addField(L"A\x3456" "B", "invalid key: Unicode");
|
||||
CPPUNIT_ASSERT_EQUAL(0U, cmt.fieldCount());
|
||||
}
|
||||
|
||||
void testClearComment()
|
||||
{
|
||||
ScopedFileCopy copy("empty", ".ogg");
|
||||
@ -178,6 +193,23 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void testLowercaseFields()
|
||||
{
|
||||
const ScopedFileCopy copy("lowercase-fields", ".ogg");
|
||||
{
|
||||
Ogg::Vorbis::File f(copy.fileName().c_str());
|
||||
List<FLAC::Picture *> lst = f.tag()->pictureList();
|
||||
CPPUNIT_ASSERT_EQUAL(String("TEST TITLE"), f.tag()->title());
|
||||
CPPUNIT_ASSERT_EQUAL(String("TEST ARTIST"), f.tag()->artist());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, lst.size());
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
Ogg::Vorbis::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.find("METADATA_BLOCK_PICTURE") > 0);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestXiphComment);
|
||||
|
Reference in New Issue
Block a user