comment writing support and more tests for mod and xm

This commit is contained in:
Mathias Panzenböck
2011-06-19 04:27:51 +02:00
parent 0143c3ee63
commit 6afb7c04b3
11 changed files with 755 additions and 128 deletions

BIN
tests/data/stripped.xm Normal file

Binary file not shown.

View File

@ -20,43 +20,63 @@
***************************************************************************/
#include <cppunit/extensions/HelperMacros.h>
#include <string>
#include <modfile.h>
#include "utils.h"
using namespace std;
using namespace TagLib;
static const String titleBefore("title of song");
static const String titleAfter("changed title");
static const String commentBefore(
"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");
static const String newComment(
"This line will be truncated because it is too long for a mod instrument name.\n"
"This line is ok.");
static const String commentAfter(
"This line will be trun\n"
"This line is ok.\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");
class TestMod : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestMod);
CPPUNIT_TEST(testRead);
CPPUNIT_TEST(testChangeTitle);
CPPUNIT_TEST(testReadTags);
CPPUNIT_TEST(testWriteTags);
CPPUNIT_TEST_SUITE_END();
public:
void testRead()
void testReadTags()
{
testRead(TEST_FILE_PATH_C("test.mod"), "title of song");
testRead(TEST_FILE_PATH_C("test.mod"), titleBefore, commentBefore);
}
void testChangeTitle()
void testWriteTags()
{
ScopedFileCopy copy("test", ".mod");
{
Mod::File file(copy.fileName().c_str());
CPPUNIT_ASSERT(file.tag() != 0);
file.tag()->setTitle("changed title");
file.tag()->setTitle(titleAfter);
file.tag()->setComment(newComment);
CPPUNIT_ASSERT(file.save());
}
testRead(copy.fileName().c_str(), "changed title");
testRead(copy.fileName().c_str(), titleAfter, commentAfter);
CPPUNIT_ASSERT(fileEqual(
copy.fileName(),
TEST_FILE_PATH_C("changed_title.mod")));
TEST_FILE_PATH_C("changed.mod")));
}
private:
void testRead(FileName fileName, const String &title)
void testRead(FileName fileName, const String &title, const String &comment)
{
Mod::File file(fileName);
@ -77,14 +97,7 @@ private:
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(comment, t->comment());
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
CPPUNIT_ASSERT_EQUAL(0U, t->year());
CPPUNIT_ASSERT_EQUAL(0U, t->track());

View File

@ -21,42 +21,148 @@
#include <cppunit/extensions/HelperMacros.h>
#include <string>
#include <sstream>
#include <xmfile.h>
#include "utils.h"
using namespace std;
using namespace TagLib;
static const String titleBefore("title of song");
static const String titleAfter("changed title");
static const String trackerNameBefore("MilkyTracker ");
static const String trackerNameAfter("TagLib");
static const String commentBefore(
"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.");
static const String newCommentShort(
"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 names\n"
"are sometimes\n"
"also abused as\n"
"comments.");
static const String newCommentLong(
"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 names\n"
"are sometimes\n"
"also abused as\n"
"comments.\n"
"\n\n\n\n\n\n\n"
"TEST");
static const String commentAfter(
"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 names\n"
"are sometimes\n"
"also abused as\n"
"comments.\n");
class TestXM : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestXM);
CPPUNIT_TEST(testRead);
CPPUNIT_TEST(testChangeTitle);
CPPUNIT_TEST(testReadTags);
CPPUNIT_TEST(testReadStrippedTags);
CPPUNIT_TEST(testWriteTagsShort);
CPPUNIT_TEST(testWriteTagsLong);
CPPUNIT_TEST_SUITE_END();
public:
void testRead()
void testReadTags()
{
testRead(TEST_FILE_PATH_C("test.xm"), "title of song");
testRead(TEST_FILE_PATH_C("test.xm"), titleBefore,
commentBefore, trackerNameBefore);
}
void testChangeTitle()
void testReadStrippedTags()
{
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")));
XM::File file(TEST_FILE_PATH_C("stripped.xm"));
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) 0, p->version());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 0 , p->restartPosition());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->patternCount());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 0, 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(titleBefore, t->title());
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
CPPUNIT_ASSERT_EQUAL(String::null, 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::null, t->trackerName());
}
void testWriteTagsShort()
{
testWriteTags(newCommentShort);
}
void testWriteTagsLong()
{
testWriteTags(newCommentLong);
}
private:
void testRead(FileName fileName, const String &title)
void testRead(FileName fileName, const String &title,
const String &comment, const String &trackerName)
{
XM::File file(fileName);
@ -72,9 +178,9 @@ private:
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->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());
@ -83,27 +189,29 @@ private:
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(comment, 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_ASSERT_EQUAL(trackerName, t->trackerName());
}
void testWriteTags(const String &comment)
{
ScopedFileCopy copy("test", ".xm");
{
XM::File file(copy.fileName().c_str());
CPPUNIT_ASSERT(file.tag() != 0);
file.tag()->setTitle(titleAfter);
file.tag()->setComment(comment);
file.tag()->setTrackerName(trackerNameAfter);
CPPUNIT_ASSERT(file.save());
}
testRead(copy.fileName().c_str(), titleAfter,
commentAfter, trackerNameAfter);
CPPUNIT_ASSERT(fileEqual(
copy.fileName(),
TEST_FILE_PATH_C("changed.xm")));
}
};