mirror of
https://github.com/taglib/taglib.git
synced 2025-07-18 21:14:23 -04:00
fixed mod property names and added unit test for xm
This commit is contained in:
@ -52,6 +52,7 @@ SET(test_runner_SRCS
|
||||
test_wav.cpp
|
||||
test_wavpack.cpp
|
||||
test_mod.cpp
|
||||
test_xm.cpp
|
||||
)
|
||||
IF(WITH_MP4)
|
||||
SET(test_runner_SRCS ${test_runner_SRCS}
|
||||
|
BIN
tests/data/changed_title.xm
Normal file
BIN
tests/data/changed_title.xm
Normal file
Binary file not shown.
BIN
tests/data/test.xm
Normal file
BIN
tests/data/test.xm
Normal file
Binary file not shown.
@ -1,9 +1,27 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2011 by Mathias Panzenböck
|
||||
email : grosser.meister.morti@gmx.net
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
|
||||
* MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <modfile.h>
|
||||
#include <stdlib.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
@ -11,116 +29,67 @@ using namespace TagLib;
|
||||
|
||||
class TestMod : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestMod);
|
||||
CPPUNIT_TEST(testRead);
|
||||
CPPUNIT_TEST(testChangeTitle);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
CPPUNIT_TEST_SUITE(TestMod);
|
||||
CPPUNIT_TEST(testRead);
|
||||
CPPUNIT_TEST(testChangeTitle);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void testRead()
|
||||
{
|
||||
testRead(TEST_FILE_PATH_C("test.mod"), "title of song");
|
||||
}
|
||||
void testRead()
|
||||
{
|
||||
testRead(TEST_FILE_PATH_C("test.mod"), "title of song");
|
||||
}
|
||||
|
||||
void testChangeTitle()
|
||||
{
|
||||
ScopedFileCopy copy("test", ".mod");
|
||||
{
|
||||
Mod::File file(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(file.tag() != 0);
|
||||
file.tag()->setTitle("changed title");
|
||||
CPPUNIT_ASSERT(file.save());
|
||||
}
|
||||
{
|
||||
testRead(copy.fileName().c_str(), "changed title");
|
||||
}
|
||||
{
|
||||
assertFileEqual(
|
||||
copy.fileName().c_str(),
|
||||
TEST_FILE_PATH_C("changed_title.mod"));
|
||||
}
|
||||
}
|
||||
void testChangeTitle()
|
||||
{
|
||||
ScopedFileCopy copy("test", ".mod");
|
||||
{
|
||||
Mod::File file(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(file.tag() != 0);
|
||||
file.tag()->setTitle("changed title");
|
||||
CPPUNIT_ASSERT(file.save());
|
||||
}
|
||||
testRead(copy.fileName().c_str(), "changed title");
|
||||
CPPUNIT_ASSERT(fileEqual(
|
||||
copy.fileName(),
|
||||
TEST_FILE_PATH_C("changed_title.mod")));
|
||||
}
|
||||
|
||||
private:
|
||||
class Closer
|
||||
{
|
||||
public:
|
||||
Closer(FILE *stream) : m_stream(stream)
|
||||
{
|
||||
}
|
||||
void testRead(FileName fileName, const String &title)
|
||||
{
|
||||
Mod::File file(fileName);
|
||||
|
||||
~Closer()
|
||||
{
|
||||
if (m_stream)
|
||||
{
|
||||
fclose(m_stream);
|
||||
}
|
||||
}
|
||||
private:
|
||||
FILE *m_stream;
|
||||
};
|
||||
CPPUNIT_ASSERT(file.isValid());
|
||||
|
||||
void assertFileEqual(const char *file1, const char *file2)
|
||||
{
|
||||
char buf1[BUFSIZ];
|
||||
char buf2[BUFSIZ];
|
||||
Mod::Properties *p = file.audioProperties();
|
||||
Mod::Tag *t = file.tag();
|
||||
|
||||
CPPUNIT_ASSERT(0 != p);
|
||||
CPPUNIT_ASSERT(0 != t);
|
||||
|
||||
FILE *stream1 = fopen(file1, "rb");
|
||||
FILE *stream2 = fopen(file2, "rb");
|
||||
|
||||
Closer closer1(stream1);
|
||||
Closer closer2(stream2);
|
||||
|
||||
CPPUNIT_ASSERT(stream1 != 0);
|
||||
CPPUNIT_ASSERT(stream2 != 0);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
size_t n1 = fread(buf1, 1, BUFSIZ, stream1);
|
||||
size_t n2 = fread(buf2, 1, BUFSIZ, stream2);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(n1, n2);
|
||||
|
||||
if (n1 == 0) break;
|
||||
|
||||
CPPUNIT_ASSERT(memcmp(buf1, buf2, n1) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
void testRead(FileName fileName, const String &title)
|
||||
{
|
||||
Mod::File file(fileName);
|
||||
|
||||
CPPUNIT_ASSERT(file.isValid());
|
||||
|
||||
Mod::Properties *p = file.audioProperties();
|
||||
Mod::Tag *t = file.tag();
|
||||
|
||||
CPPUNIT_ASSERT(0 != p);
|
||||
CPPUNIT_ASSERT(0 != t);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->length());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
|
||||
CPPUNIT_ASSERT_EQUAL(8, p->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(31U, p->instrumentCount());
|
||||
CPPUNIT_ASSERT_EQUAL(1U, p->patternCount());
|
||||
CPPUNIT_ASSERT_EQUAL(title, t->title());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
|
||||
CPPUNIT_ASSERT_EQUAL(String(
|
||||
"Instrument names\n"
|
||||
"are abused as\n"
|
||||
"comments in\n"
|
||||
"module file formats.\n"
|
||||
"-+-+-+-+-+-+-+-+-+-+-+\n"
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||
), t->comment());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
|
||||
CPPUNIT_ASSERT_EQUAL(0U, t->year());
|
||||
CPPUNIT_ASSERT_EQUAL(0U, t->track());
|
||||
CPPUNIT_ASSERT_EQUAL(String("StarTrekker"), t->trackerName());
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->length());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
|
||||
CPPUNIT_ASSERT_EQUAL(8, p->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(31U, p->instrumentCount());
|
||||
CPPUNIT_ASSERT_EQUAL(1U, p->tableLength());
|
||||
CPPUNIT_ASSERT_EQUAL(title, t->title());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
|
||||
CPPUNIT_ASSERT_EQUAL(String(
|
||||
"Instrument names\n"
|
||||
"are abused as\n"
|
||||
"comments in\n"
|
||||
"module file formats.\n"
|
||||
"-+-+-+-+-+-+-+-+-+-+-+\n"
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||
), t->comment());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
|
||||
CPPUNIT_ASSERT_EQUAL(0U, t->year());
|
||||
CPPUNIT_ASSERT_EQUAL(0U, t->track());
|
||||
CPPUNIT_ASSERT_EQUAL(String("StarTrekker"), t->trackerName());
|
||||
}
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestMod);
|
||||
|
110
tests/test_xm.cpp
Normal file
110
tests/test_xm.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2011 by Mathias Panzenböck
|
||||
email : grosser.meister.morti@gmx.net
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
|
||||
* MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <xmfile.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestXM : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestXM);
|
||||
CPPUNIT_TEST(testRead);
|
||||
CPPUNIT_TEST(testChangeTitle);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void testRead()
|
||||
{
|
||||
testRead(TEST_FILE_PATH_C("test.xm"), "title of song");
|
||||
}
|
||||
|
||||
void testChangeTitle()
|
||||
{
|
||||
ScopedFileCopy copy("test", ".xm");
|
||||
{
|
||||
XM::File file(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(file.tag() != 0);
|
||||
file.tag()->setTitle("changed title");
|
||||
CPPUNIT_ASSERT(file.save());
|
||||
}
|
||||
testRead(copy.fileName().c_str(), "changed title");
|
||||
CPPUNIT_ASSERT(fileEqual(
|
||||
copy.fileName(),
|
||||
TEST_FILE_PATH_C("changed_title.xm")));
|
||||
}
|
||||
|
||||
private:
|
||||
void testRead(FileName fileName, const String &title)
|
||||
{
|
||||
XM::File file(fileName);
|
||||
|
||||
CPPUNIT_ASSERT(file.isValid());
|
||||
|
||||
XM::Properties *p = file.audioProperties();
|
||||
Mod::Tag *t = file.tag();
|
||||
|
||||
CPPUNIT_ASSERT(0 != p);
|
||||
CPPUNIT_ASSERT(0 != t);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->length());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
|
||||
CPPUNIT_ASSERT_EQUAL(8, p->channels());
|
||||
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->tableLength());
|
||||
CPPUNIT_ASSERT_EQUAL((TagLib::ushort)260, p->version());
|
||||
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 0, p->restartPosition());
|
||||
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->patternCount());
|
||||
CPPUNIT_ASSERT_EQUAL((TagLib::ushort)128, p->instrumentCount());
|
||||
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->flags());
|
||||
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 6, p->tempo());
|
||||
CPPUNIT_ASSERT_EQUAL((TagLib::ushort)125, p->bpmSpeed());
|
||||
CPPUNIT_ASSERT_EQUAL(title, t->title());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
|
||||
CPPUNIT_ASSERT_EQUAL(String(
|
||||
"Instrument names\n"
|
||||
"are abused as\n"
|
||||
"comments in\n"
|
||||
"module file formats.\n"
|
||||
"-+-+-+-+-+-+-+-+-+-+-+\n"
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||
"\n\n\n"
|
||||
"Sample\n"
|
||||
"names\n"
|
||||
"are sometimes\n"
|
||||
"also abused as\n"
|
||||
"comments."
|
||||
), t->comment());
|
||||
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
|
||||
CPPUNIT_ASSERT_EQUAL(0U, t->year());
|
||||
CPPUNIT_ASSERT_EQUAL(0U, t->track());
|
||||
CPPUNIT_ASSERT_EQUAL(String("MilkyTracker "), t->trackerName());
|
||||
}
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestXM);
|
@ -9,7 +9,9 @@
|
||||
#include <sys/fcntl.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -45,6 +47,35 @@ inline void deleteFile(const string &filename)
|
||||
remove(filename.c_str());
|
||||
}
|
||||
|
||||
inline bool fileEqual(const string &filename1, const string &filename2)
|
||||
{
|
||||
char buf1[BUFSIZ];
|
||||
char buf2[BUFSIZ];
|
||||
|
||||
ifstream stream1(filename1.c_str(), ios_base::in | ios_base::binary);
|
||||
ifstream stream2(filename2.c_str(), ios_base::in | ios_base::binary);
|
||||
|
||||
if(!stream1 && !stream2) return true;
|
||||
if(!stream1 || !stream2) return false;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
stream1.read(buf1, BUFSIZ);
|
||||
stream2.read(buf2, BUFSIZ);
|
||||
|
||||
streamsize n1 = stream1.gcount();
|
||||
streamsize n2 = stream2.gcount();
|
||||
|
||||
if(n1 != n2) return false;
|
||||
|
||||
if(n1 == 0) break;
|
||||
|
||||
if(memcmp(buf1, buf2, n1) != 0) return false;
|
||||
}
|
||||
|
||||
return stream1.good() == stream2.good();
|
||||
}
|
||||
|
||||
class ScopedFileCopy
|
||||
{
|
||||
public:
|
||||
|
Reference in New Issue
Block a user