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 00000000..e85bd338 Binary files /dev/null and b/tests/data/matroska.mka differ 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);