mirror of
https://github.com/taglib/taglib.git
synced 2025-11-12 20:52:52 -05:00
added unit test for one flavour of .mod files
This commit is contained in:
@ -19,6 +19,10 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ogg/flac
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/flac
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/wavpack
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mod
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/s3m
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/it
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/xm
|
||||
)
|
||||
|
||||
SET(test_runner_SRCS
|
||||
@ -47,6 +51,7 @@ SET(test_runner_SRCS
|
||||
test_apetag.cpp
|
||||
test_wav.cpp
|
||||
test_wavpack.cpp
|
||||
test_mod.cpp
|
||||
)
|
||||
IF(WITH_MP4)
|
||||
SET(test_runner_SRCS ${test_runner_SRCS}
|
||||
@ -67,5 +72,4 @@ ADD_CUSTOM_TARGET(check
|
||||
./test_runner
|
||||
DEPENDS test_runner
|
||||
)
|
||||
|
||||
endif(BUILD_TESTS)
|
||||
|
||||
BIN
tests/data/changed_title.mod
Normal file
BIN
tests/data/changed_title.mod
Normal file
Binary file not shown.
BIN
tests/data/test.mod
Normal file
BIN
tests/data/test.mod
Normal file
Binary file not shown.
126
tests/test_mod.cpp
Normal file
126
tests/test_mod.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
#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;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestMod : public CppUnit::TestFixture
|
||||
{
|
||||
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 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"));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
class Closer
|
||||
{
|
||||
public:
|
||||
Closer(FILE *stream) : m_stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
~Closer()
|
||||
{
|
||||
if (m_stream)
|
||||
{
|
||||
fclose(m_stream);
|
||||
}
|
||||
}
|
||||
private:
|
||||
FILE *m_stream;
|
||||
};
|
||||
|
||||
void assertFileEqual(const char *file1, const char *file2)
|
||||
{
|
||||
char buf1[BUFSIZ];
|
||||
char buf2[BUFSIZ];
|
||||
|
||||
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_TEST_SUITE_REGISTRATION(TestMod);
|
||||
Reference in New Issue
Block a user