Some preliminary work for unified dictionary tag interface support.

- toDict() and fromDict() for XiphComments
- toDict() for ID3v2 Tags
This commit is contained in:
Michael Helmling
2011-08-26 21:48:40 +02:00
parent bec3875b94
commit b262180857
11 changed files with 466 additions and 4 deletions

BIN
tests/data/test.ogg Normal file

Binary file not shown.

View File

@ -67,6 +67,7 @@ class TestID3v2 : public CppUnit::TestFixture
CPPUNIT_TEST(testDowngradeTo23);
// CPPUNIT_TEST(testUpdateFullDate22); TODO TYE+TDA should be upgraded to TDRC together
CPPUNIT_TEST(testCompressedFrameWithBrokenLength);
CPPUNIT_TEST(testDictInterface);
CPPUNIT_TEST_SUITE_END();
public:
@ -547,6 +548,29 @@ public:
CPPUNIT_ASSERT_EQUAL(TagLib::uint(86414), frame->picture().size());
}
void testDictInterface()
{
ScopedFileCopy copy("rare_frames", ".mp3");
string newname = copy.fileName();
MPEG::File f(newname.c_str());
TagDict dict = f.ID3v2Tag(false)->toDict();
CPPUNIT_ASSERT_EQUAL(uint(7), dict.size());
CPPUNIT_ASSERT_EQUAL(String("userTextData1"), dict["USERTEXTDESCRIPTION1"][0]);
CPPUNIT_ASSERT_EQUAL(String("userTextData2"), dict["USERTEXTDESCRIPTION1"][1]);
CPPUNIT_ASSERT_EQUAL(String("userTextData1"), dict["USERTEXTDESCRIPTION2"][0]);
CPPUNIT_ASSERT_EQUAL(String("userTextData2"), dict["USERTEXTDESCRIPTION2"][1]);
CPPUNIT_ASSERT_EQUAL(String("Pop"), dict["GENRE"][0]);
CPPUNIT_ASSERT_EQUAL(String("Pop"), dict["GENRE"][0]);
CPPUNIT_ASSERT_EQUAL(String("http://a.user.url"), dict["USERURL"][0]);
CPPUNIT_ASSERT_EQUAL(String("http://a.user.url/with/empty/description"), dict["URL"][0]);
CPPUNIT_ASSERT_EQUAL(String("12345678 [supermihi@web.de]"), dict["UNIQUEIDENTIFIER"][0]);
CPPUNIT_ASSERT_EQUAL(String("A COMMENT"), dict["COMMENT"][0]);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2);

View File

@ -17,6 +17,8 @@ class TestOGG : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(TestOGG);
CPPUNIT_TEST(testSimple);
CPPUNIT_TEST(testSplitPackets);
CPPUNIT_TEST(testDictInterface1);
CPPUNIT_TEST(testDictInterface2);
CPPUNIT_TEST_SUITE_END();
public:
@ -51,6 +53,51 @@ public:
delete f;
}
void testDictInterface1()
{
ScopedFileCopy copy("empty", ".ogg");
string newname = copy.fileName();
Vorbis::File *f = new Vorbis::File(newname.c_str());
CPPUNIT_ASSERT_EQUAL(uint(0), f->tag()->toDict().size());
TagDict newTags;
StringList values("value 1");
values.append("value 2");
newTags["ARTIST"] = values;
f->tag()->fromDict(newTags);
TagDict map = f->tag()->toDict();
CPPUNIT_ASSERT_EQUAL(uint(1), map.size());
CPPUNIT_ASSERT_EQUAL(uint(2), map["ARTIST"].size());
CPPUNIT_ASSERT_EQUAL(String("value 1"), map["ARTIST"][0]);
delete f;
}
void testDictInterface2()
{
ScopedFileCopy copy("test", ".ogg");
string newname = copy.fileName();
Vorbis::File *f = new Vorbis::File(newname.c_str());
TagDict tags = f->tag()->toDict();
CPPUNIT_ASSERT_EQUAL(uint(2), tags["UNUSUALTAG"].size());
CPPUNIT_ASSERT_EQUAL(String("usual value"), tags["UNUSUALTAG"][0]);
CPPUNIT_ASSERT_EQUAL(String("another value"), tags["UNUSUALTAG"][1]);
CPPUNIT_ASSERT_EQUAL(String(L"öäüoΣø"), tags["UNICODETAG"][0]);
tags["UNICODETAG"][0] = L"νεω ναλυε";
tags.erase("UNUSUALTAG");
f->tag()->fromDict(tags);
CPPUNIT_ASSERT_EQUAL(String(L"νεω ναλυε"), f->tag()->toDict()["UNICODETAG"][0]);
CPPUNIT_ASSERT_EQUAL(false, f->tag()->toDict().contains("UNUSUALTAG"));
delete f;
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestOGG);