From befa5724f12d20f6a3bf9ab96b2690200fad32f8 Mon Sep 17 00:00:00 2001 From: Sebastian Rachuj Date: Wed, 15 May 2013 16:51:54 +0200 Subject: [PATCH 1/5] Removed unnecessary casts in EBML::Element --- taglib/ebml/ebmlelement.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taglib/ebml/ebmlelement.cpp b/taglib/ebml/ebmlelement.cpp index 32ce46de..00a9b7e7 100644 --- a/taglib/ebml/ebmlelement.cpp +++ b/taglib/ebml/ebmlelement.cpp @@ -101,7 +101,7 @@ public: // for the id) ByteVector createVInt(ulli number, bool addOne = true, bool shortest = true) { - ByteVector vint = ByteVector::fromUInt64BE(static_cast(number)); + ByteVector vint = ByteVector::fromUInt64BE(number); // Do we actually need to calculate the length of the variable length // integer? If not, then prepend the 0b0000 0001 if necessary and return the @@ -388,7 +388,7 @@ EBML::Element *EBML::Element::addElement(EBML::ulli id, signed long long number) EBML::Element *EBML::Element::addElement(EBML::ulli id, EBML::ulli number) { - return addElement(id, ByteVector::fromUInt64BE(static_cast(number))); + return addElement(id, ByteVector::fromUInt64BE(number)); } EBML::Element *EBML::Element::addElement(EBML::ulli id, long double number) @@ -457,7 +457,7 @@ void EBML::Element::setAsInt(signed long long number) void EBML::Element::setAsUnsigned(EBML::ulli number) { - setAsBinary(ByteVector::fromUInt64BE(static_cast(number))); + setAsBinary(ByteVector::fromUInt64BE(number)); } void EBML::Element::setAsFloat(long double) From 09e7df8509c8851eebabaf2b9c7606b522c0db53 Mon Sep 17 00:00:00 2001 From: Sebastian Rachuj Date: Wed, 15 May 2013 16:54:31 +0200 Subject: [PATCH 2/5] Added return for find --- taglib/ebml/matroska/ebmlmatroskafile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/taglib/ebml/matroska/ebmlmatroskafile.cpp b/taglib/ebml/matroska/ebmlmatroskafile.cpp index a43a9783..ad093fdc 100644 --- a/taglib/ebml/matroska/ebmlmatroskafile.cpp +++ b/taglib/ebml/matroska/ebmlmatroskafile.cpp @@ -373,6 +373,7 @@ public: if(i->second.second == ttv) return i; } + return document->d->tags.end(); } // Updates the given information From 8f31d882b010c3d6bc79b060b2bb5a26318e7f94 Mon Sep 17 00:00:00 2001 From: Sebastian Rachuj Date: Mon, 20 May 2013 20:44:12 +0200 Subject: [PATCH 3/5] Added a few testcases --- taglib/ebml/ebmlfile.cpp | 2 +- taglib/ebml/matroska/ebmlmatroskafile.cpp | 8 +- tests/CMakeLists.txt | 3 + tests/data/matroska.mka | Bin 0 -> 4707 bytes tests/test_matroska.cpp | 100 ++++++++++++++++++++++ 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 tests/data/matroska.mka create mode 100644 tests/test_matroska.cpp diff --git a/taglib/ebml/ebmlfile.cpp b/taglib/ebml/ebmlfile.cpp index 9dbb73e0..e9f4ce9f 100644 --- a/taglib/ebml/ebmlfile.cpp +++ b/taglib/ebml/ebmlfile.cpp @@ -40,7 +40,7 @@ public: { document->seek(0); ByteVector magical = document->readBlock(4); - if(static_cast(magical.toInt64BE(0)) != Header::EBML) + if(static_cast(magical.toUInt32BE(0)) != Header::EBML) return 0; FilePrivate *d = new FilePrivate(document); Element *head = d->root.getChild(Header::EBML); diff --git a/taglib/ebml/matroska/ebmlmatroskafile.cpp b/taglib/ebml/matroska/ebmlmatroskafile.cpp index ad093fdc..93ff80cc 100644 --- a/taglib/ebml/matroska/ebmlmatroskafile.cpp +++ b/taglib/ebml/matroska/ebmlmatroskafile.cpp @@ -126,9 +126,11 @@ public: EBML::Matroska::File::~File() { - delete d->tag; - delete d->audio; - delete d; + if (d) { + delete d->tag; + delete d->audio; + delete d; + } } EBML::Matroska::File::File(FileName file) : EBML::File(file), d(0) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a369b5a1..7a5bbbf9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,6 +24,8 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/s3m ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/it ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/xm + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ebml + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ebml/matroska ) SET(test_runner_SRCS @@ -64,6 +66,7 @@ SET(test_runner_SRCS test_xm.cpp test_mpc.cpp test_opus.cpp + test_matroska.cpp ) INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIR}) diff --git a/tests/data/matroska.mka b/tests/data/matroska.mka new file mode 100644 index 0000000000000000000000000000000000000000..e85bd338b1a86f6912a1d5ab544468e788fd6840 GIT binary patch literal 4707 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 BFTDT& literal 0 HcmV?d00001 diff --git a/tests/test_matroska.cpp b/tests/test_matroska.cpp new file mode 100644 index 00000000..7e026334 --- /dev/null +++ b/tests/test_matroska.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include +#include "utils.h" + +#include + +using namespace std; +using namespace TagLib; + +class TestMatroska : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(TestMatroska); + CPPUNIT_TEST(testPredefined); + CPPUNIT_TEST(testInsertAndExtract); + CPPUNIT_TEST_SUITE_END(); + +public: + void testPredefined() + { + ScopedFileCopy copy("matroska", ".mka"); + string filename = copy.fileName(); + + EBML::Matroska::File f(filename.c_str()); + CPPUNIT_ASSERT(f.isValid()); + + PropertyMap pm = f.properties(); + PropertyMap::Iterator i = pm.find("ENCODER"); + CPPUNIT_ASSERT(i != f.properties().end()); + + CPPUNIT_ASSERT_EQUAL(String("Lavf54.63.104"), i->second.front()); + } + + void testInsertAndExtract() + { + ScopedFileCopy copy("matroska", ".mka"); + string filename = copy.fileName(); + + EBML::Matroska::File f1(filename.c_str()); + CPPUNIT_ASSERT(f1.isValid()); + + Tag* t = f1.tag(); + + CPPUNIT_ASSERT(t != 0); + t->setTitle("Seconds of Silence"); + t->setArtist("Nobody"); + t->setAlbum("TagLib Test Suite"); + t->setComment("Well, there's nothing to say - a few special signs: ©’…ä–€ſ"); + t->setGenre("Air"); + t->setYear(2013); + t->setTrack(15); + + CPPUNIT_ASSERT(f1.save()); + + EBML::Matroska::File f2(filename.c_str()); + CPPUNIT_ASSERT(f2.isValid()); + + t = f2.tag(); + + CPPUNIT_ASSERT(t != 0); + CPPUNIT_ASSERT_EQUAL(String("Seconds of Silence"), t->title()); + CPPUNIT_ASSERT_EQUAL(String("Nobody"), t->artist()); + CPPUNIT_ASSERT_EQUAL(String("TagLib Test Suite"), t->album()); + CPPUNIT_ASSERT_EQUAL(String("Well, there's nothing to say - a few special signs: ©’…ä–€ſ"), t->comment()); + CPPUNIT_ASSERT_EQUAL(String("Air"), t->genre()); + CPPUNIT_ASSERT_EQUAL(2013u, t->year()); + CPPUNIT_ASSERT_EQUAL(15u, t->track()); + + PropertyMap pm = f2.properties(); + pm.erase("COMMENT"); + f2.setProperties(pm); + + CPPUNIT_ASSERT(f2.save()); + + EBML::Matroska::File f3(filename.c_str()); + CPPUNIT_ASSERT(f3.isValid()); + + pm = f3.properties(); + PropertyMap::Iterator i = pm.find("GENRE"); + + CPPUNIT_ASSERT(i != pm.end()); + CPPUNIT_ASSERT_EQUAL(String("Air"), i->second.front()); + } + + void testAudioProperties() + { + ScopedFileCopy copy("matroska", ".mka"); + string filename = copy.fileName(); + + EBML::Matroska::File f(filename.c_str()); + CPPUNIT_ASSERT(f.isValid()); + + AudioProperties* a = f.audioProperties(); + CPPUNIT_ASSERT(a != 0); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(TestMatroska); From 6bf8177796d33a433fd43e2da45caa7e4d241611 Mon Sep 17 00:00:00 2001 From: Sebastian Rachuj Date: Tue, 21 May 2013 11:58:03 +0200 Subject: [PATCH 4/5] Completed testcases and fixed some bugs, that were found because of the them --- taglib/ebml/matroska/ebmlmatroskaaudio.cpp | 11 ++++++----- taglib/ebml/matroska/ebmlmatroskafile.cpp | 8 ++++---- tests/test_matroska.cpp | 8 ++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/taglib/ebml/matroska/ebmlmatroskaaudio.cpp b/taglib/ebml/matroska/ebmlmatroskaaudio.cpp index 8f3cdd00..dee0a3d3 100644 --- a/taglib/ebml/matroska/ebmlmatroskaaudio.cpp +++ b/taglib/ebml/matroska/ebmlmatroskaaudio.cpp @@ -44,10 +44,11 @@ public: Element *value; if(info && (value = info->getChild(Constants::Duration))) { - length = static_cast(value->getAsFloat()); - if((value = info->getChild(Constants::TimecodeScale))){ - length = static_cast(length / (value->getAsUnsigned() * (1.0 / 1000000000))); - } + length = static_cast(value->getAsFloat() / 1000000000.L); + if((value = info->getChild(Constants::TimecodeScale))) + length *= value->getAsUnsigned(); + else + length *= 1000000; } info = elem->getChild(Constants::Tracks); @@ -59,7 +60,7 @@ public: // Dirty bitrate: document->seek(0, File::End); - bitrate = static_cast(8 * document->tell() / length / 1000); + bitrate = static_cast(8 * document->tell() / ((length > 0) ? length : 1)); if((value = info->getChild(Constants::Channels))) channels = static_cast(value->getAsUnsigned()); diff --git a/taglib/ebml/matroska/ebmlmatroskafile.cpp b/taglib/ebml/matroska/ebmlmatroskafile.cpp index 93ff80cc..5325ca3a 100644 --- a/taglib/ebml/matroska/ebmlmatroskafile.cpp +++ b/taglib/ebml/matroska/ebmlmatroskafile.cpp @@ -64,8 +64,8 @@ public: List entries = elem->getChildren(Constants::Tag); for(List::Iterator i = entries.begin(); i != entries.end(); ++i) { Element *target = (*i)->getChild(Constants::Targets); - ulli ttvalue = 0; - if(target && (target = (*i)->getChild(Constants::TargetTypeValue))) + ulli ttvalue = 50; // 50 is default (see spec.) + if(target && (target = target->getChild(Constants::TargetTypeValue))) ttvalue = target->getAsUnsigned(); // Load all SimpleTags @@ -198,7 +198,7 @@ bool EBML::Matroska::File::save() return false; // C++11 features would be nice: for(auto &i : d->tags) { /* ... */ } - // Well, here we just iterate over each extracted element. + // Well, here we just iterate each extracted element. for(List > >::Iterator i = d->tags.begin(); i != d->tags.end(); ++i) { @@ -218,7 +218,7 @@ bool EBML::Matroska::File::save() target->addElement(Constants::TargetType, Constants::TRACK); else if(i->second.second == Constants::MostCommonGroupingValue) target->addElement(Constants::TargetType, Constants::ALBUM); - + target->addElement(Constants::TargetTypeValue, i->second.second); } diff --git a/tests/test_matroska.cpp b/tests/test_matroska.cpp index 7e026334..a8fb6e9d 100644 --- a/tests/test_matroska.cpp +++ b/tests/test_matroska.cpp @@ -6,6 +6,7 @@ #include "utils.h" #include +#include using namespace std; using namespace TagLib; @@ -15,6 +16,7 @@ class TestMatroska : public CppUnit::TestFixture CPPUNIT_TEST_SUITE(TestMatroska); CPPUNIT_TEST(testPredefined); CPPUNIT_TEST(testInsertAndExtract); + CPPUNIT_TEST(testAudioProperties); CPPUNIT_TEST_SUITE_END(); public: @@ -94,6 +96,12 @@ public: AudioProperties* a = f.audioProperties(); CPPUNIT_ASSERT(a != 0); + + // Not a very nice assertion... + CPPUNIT_ASSERT_EQUAL(a->length(), 0); + // Bitrate is not nice and thus not tested. + CPPUNIT_ASSERT_EQUAL(a->sampleRate(), 44100); + CPPUNIT_ASSERT_EQUAL(a->channels(), 2); } }; From 4be506fae2ea0e6fb7c3635a021a6c1a2abb0952 Mon Sep 17 00:00:00 2001 From: Sebastian Rachuj Date: Tue, 21 May 2013 12:03:43 +0200 Subject: [PATCH 5/5] Corrected indentation --- taglib/ebml/matroska/ebmlmatroskaaudio.cpp | 2 +- tests/test_matroska.cpp | 174 ++++++++++----------- 2 files changed, 88 insertions(+), 88 deletions(-) diff --git a/taglib/ebml/matroska/ebmlmatroskaaudio.cpp b/taglib/ebml/matroska/ebmlmatroskaaudio.cpp index dee0a3d3..e2a8251d 100644 --- a/taglib/ebml/matroska/ebmlmatroskaaudio.cpp +++ b/taglib/ebml/matroska/ebmlmatroskaaudio.cpp @@ -48,7 +48,7 @@ public: if((value = info->getChild(Constants::TimecodeScale))) length *= value->getAsUnsigned(); else - length *= 1000000; + length *= 1000000; } info = elem->getChild(Constants::Tracks); diff --git a/tests/test_matroska.cpp b/tests/test_matroska.cpp index a8fb6e9d..339f9a78 100644 --- a/tests/test_matroska.cpp +++ b/tests/test_matroska.cpp @@ -13,96 +13,96 @@ using namespace TagLib; class TestMatroska : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(TestMatroska); - CPPUNIT_TEST(testPredefined); - CPPUNIT_TEST(testInsertAndExtract); - CPPUNIT_TEST(testAudioProperties); - CPPUNIT_TEST_SUITE_END(); - + CPPUNIT_TEST_SUITE(TestMatroska); + CPPUNIT_TEST(testPredefined); + CPPUNIT_TEST(testInsertAndExtract); + CPPUNIT_TEST(testAudioProperties); + CPPUNIT_TEST_SUITE_END(); + public: - void testPredefined() - { - ScopedFileCopy copy("matroska", ".mka"); - string filename = copy.fileName(); - - EBML::Matroska::File f(filename.c_str()); - CPPUNIT_ASSERT(f.isValid()); - - PropertyMap pm = f.properties(); - PropertyMap::Iterator i = pm.find("ENCODER"); - CPPUNIT_ASSERT(i != f.properties().end()); - - CPPUNIT_ASSERT_EQUAL(String("Lavf54.63.104"), i->second.front()); - } + void testPredefined() + { + ScopedFileCopy copy("matroska", ".mka"); + string filename = copy.fileName(); + + EBML::Matroska::File f(filename.c_str()); + CPPUNIT_ASSERT(f.isValid()); + + PropertyMap pm = f.properties(); + PropertyMap::Iterator i = pm.find("ENCODER"); + CPPUNIT_ASSERT(i != f.properties().end()); + + CPPUNIT_ASSERT_EQUAL(String("Lavf54.63.104"), i->second.front()); + } - void testInsertAndExtract() - { - ScopedFileCopy copy("matroska", ".mka"); - string filename = copy.fileName(); - - EBML::Matroska::File f1(filename.c_str()); - CPPUNIT_ASSERT(f1.isValid()); - - Tag* t = f1.tag(); - - CPPUNIT_ASSERT(t != 0); - t->setTitle("Seconds of Silence"); - t->setArtist("Nobody"); - t->setAlbum("TagLib Test Suite"); - t->setComment("Well, there's nothing to say - a few special signs: ©’…ä–€ſ"); - t->setGenre("Air"); - t->setYear(2013); - t->setTrack(15); - - CPPUNIT_ASSERT(f1.save()); - - EBML::Matroska::File f2(filename.c_str()); - CPPUNIT_ASSERT(f2.isValid()); - - t = f2.tag(); - - CPPUNIT_ASSERT(t != 0); - CPPUNIT_ASSERT_EQUAL(String("Seconds of Silence"), t->title()); - CPPUNIT_ASSERT_EQUAL(String("Nobody"), t->artist()); - CPPUNIT_ASSERT_EQUAL(String("TagLib Test Suite"), t->album()); - CPPUNIT_ASSERT_EQUAL(String("Well, there's nothing to say - a few special signs: ©’…ä–€ſ"), t->comment()); - CPPUNIT_ASSERT_EQUAL(String("Air"), t->genre()); - CPPUNIT_ASSERT_EQUAL(2013u, t->year()); - CPPUNIT_ASSERT_EQUAL(15u, t->track()); - - PropertyMap pm = f2.properties(); - pm.erase("COMMENT"); - f2.setProperties(pm); - - CPPUNIT_ASSERT(f2.save()); - - EBML::Matroska::File f3(filename.c_str()); - CPPUNIT_ASSERT(f3.isValid()); - - pm = f3.properties(); - PropertyMap::Iterator i = pm.find("GENRE"); - - CPPUNIT_ASSERT(i != pm.end()); - CPPUNIT_ASSERT_EQUAL(String("Air"), i->second.front()); - } + void testInsertAndExtract() + { + ScopedFileCopy copy("matroska", ".mka"); + string filename = copy.fileName(); + + EBML::Matroska::File f1(filename.c_str()); + CPPUNIT_ASSERT(f1.isValid()); + + Tag* t = f1.tag(); + + CPPUNIT_ASSERT(t != 0); + t->setTitle("Seconds of Silence"); + t->setArtist("Nobody"); + t->setAlbum("TagLib Test Suite"); + t->setComment("Well, there's nothing to say - a few special signs: ©’…ä–€ſ"); + t->setGenre("Air"); + t->setYear(2013); + t->setTrack(15); + + CPPUNIT_ASSERT(f1.save()); + + EBML::Matroska::File f2(filename.c_str()); + CPPUNIT_ASSERT(f2.isValid()); + + t = f2.tag(); + + CPPUNIT_ASSERT(t != 0); + CPPUNIT_ASSERT_EQUAL(String("Seconds of Silence"), t->title()); + CPPUNIT_ASSERT_EQUAL(String("Nobody"), t->artist()); + CPPUNIT_ASSERT_EQUAL(String("TagLib Test Suite"), t->album()); + CPPUNIT_ASSERT_EQUAL(String("Well, there's nothing to say - a few special signs: ©’…ä–€ſ"), t->comment()); + CPPUNIT_ASSERT_EQUAL(String("Air"), t->genre()); + CPPUNIT_ASSERT_EQUAL(2013u, t->year()); + CPPUNIT_ASSERT_EQUAL(15u, t->track()); + + PropertyMap pm = f2.properties(); + pm.erase("COMMENT"); + f2.setProperties(pm); + + CPPUNIT_ASSERT(f2.save()); + + EBML::Matroska::File f3(filename.c_str()); + CPPUNIT_ASSERT(f3.isValid()); + + pm = f3.properties(); + PropertyMap::Iterator i = pm.find("GENRE"); + + CPPUNIT_ASSERT(i != pm.end()); + CPPUNIT_ASSERT_EQUAL(String("Air"), i->second.front()); + } - void testAudioProperties() - { - ScopedFileCopy copy("matroska", ".mka"); - string filename = copy.fileName(); - - EBML::Matroska::File f(filename.c_str()); - CPPUNIT_ASSERT(f.isValid()); - - AudioProperties* a = f.audioProperties(); - CPPUNIT_ASSERT(a != 0); - - // Not a very nice assertion... - CPPUNIT_ASSERT_EQUAL(a->length(), 0); - // Bitrate is not nice and thus not tested. - CPPUNIT_ASSERT_EQUAL(a->sampleRate(), 44100); - CPPUNIT_ASSERT_EQUAL(a->channels(), 2); - } + void testAudioProperties() + { + ScopedFileCopy copy("matroska", ".mka"); + string filename = copy.fileName(); + + EBML::Matroska::File f(filename.c_str()); + CPPUNIT_ASSERT(f.isValid()); + + AudioProperties* a = f.audioProperties(); + CPPUNIT_ASSERT(a != 0); + + // Not a very nice assertion... + CPPUNIT_ASSERT_EQUAL(a->length(), 0); + // Bitrate is not nice and thus not tested. + CPPUNIT_ASSERT_EQUAL(a->sampleRate(), 44100); + CPPUNIT_ASSERT_EQUAL(a->channels(), 2); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(TestMatroska);