From 6bf8177796d33a433fd43e2da45caa7e4d241611 Mon Sep 17 00:00:00 2001 From: Sebastian Rachuj Date: Tue, 21 May 2013 11:58:03 +0200 Subject: [PATCH] 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); } };