Added a few testcases

This commit is contained in:
Sebastian Rachuj
2013-05-20 20:44:12 +02:00
parent 09e7df8509
commit 8f31d882b0
5 changed files with 109 additions and 4 deletions

View File

@ -40,7 +40,7 @@ public:
{
document->seek(0);
ByteVector magical = document->readBlock(4);
if(static_cast<ulli>(magical.toInt64BE(0)) != Header::EBML)
if(static_cast<ulli>(magical.toUInt32BE(0)) != Header::EBML)
return 0;
FilePrivate *d = new FilePrivate(document);
Element *head = d->root.getChild(Header::EBML);

View File

@ -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)

View File

@ -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})

BIN
tests/data/matroska.mka Normal file

Binary file not shown.

100
tests/test_matroska.cpp Normal file
View File

@ -0,0 +1,100 @@
#include <string>
#include <stdio.h>
#include <tag.h>
#include <tpropertymap.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
#include <ebmlmatroskafile.h>
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);