option(WITH_MP4 "Enable MP4 tag reading/writing code" OFF)
add_definitions(-DHAVE_CONFIG_H)
+set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
## the following are directories where stuff will be installed to
set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)")
#cmakedefine NO_ITUNES_HACKS 1
#cmakedefine WITH_ASF 1
#cmakedefine WITH_MP4 1
+
+#cmakedefine TESTS_DIR "@TESTS_DIR@"
+
void testProperties399()
{
- APE::File f("data/mac-399.ape");
+ APE::File f(TEST_FILE_PATH_C("mac-399.ape"));
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
void testProperties396()
{
- APE::File f("data/mac-396.ape");
+ APE::File f(TEST_FILE_PATH_C("mac-396.ape"));
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
void testProperties390()
{
- APE::File f("data/mac-390-hdr.ape");
+ APE::File f(TEST_FILE_PATH_C("mac-390-hdr.ape"));
CPPUNIT_ASSERT_EQUAL(15, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
void testProperties()
{
- ASF::File f("data/silence-1.wma");
+ ASF::File f(TEST_FILE_PATH_C("silence-1.wma"));
CPPUNIT_ASSERT_EQUAL(4, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
void testRead()
{
- ASF::File f("data/silence-1.wma");
+ ASF::File f(TEST_FILE_PATH_C("silence-1.wma"));
CPPUNIT_ASSERT_EQUAL(String("test"), f.tag()->title());
}
void testOGA_FLAC()
{
- FileRef *f = new FileRef("data/empty_flac.oga");
+ FileRef *f = new FileRef(TEST_FILE_PATH_C("empty_flac.oga"));
CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f->file()) == NULL);
CPPUNIT_ASSERT(dynamic_cast<Ogg::FLAC::File *>(f->file()) != NULL);
}
void testOGA_Vorbis()
{
- FileRef *f = new FileRef("data/empty_vorbis.oga");
+ FileRef *f = new FileRef(TEST_FILE_PATH_C("empty_vorbis.oga"));
CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f->file()) != NULL);
CPPUNIT_ASSERT(dynamic_cast<Ogg::FLAC::File *>(f->file()) == NULL);
}
void testSignature()
{
- FLAC::File f("data/no-tags.flac");
+ FLAC::File f(TEST_FILE_PATH_C("no-tags.flac"));
CPPUNIT_ASSERT_EQUAL(ByteVector("a1b141f766e9849ac3db1030a20a3c77"), f.audioProperties()->signature().toHex());
}
void testUnsynchDecode()
{
- MPEG::File f("data/unsynch.id3", false);
+ MPEG::File f(TEST_FILE_PATH_C("unsynch.id3"), false);
CPPUNIT_ASSERT(f.tag());
CPPUNIT_ASSERT_EQUAL(String("My babe just cares for me"), f.tag()->title());
}
void testBrokenFrame1()
{
- MPEG::File f("data/broken-tenc.id3", false);
+ MPEG::File f(TEST_FILE_PATH_C("broken-tenc.id3"), false);
CPPUNIT_ASSERT(f.tag());
CPPUNIT_ASSERT(!f.ID3v2Tag()->frameListMap().contains("TENC"));
}
void testItunes24FrameSize()
{
- MPEG::File f("data/005411.id3", false);
+ MPEG::File f(TEST_FILE_PATH_C("005411.id3"), false);
CPPUNIT_ASSERT(f.tag());
CPPUNIT_ASSERT(f.ID3v2Tag()->frameListMap().contains("TIT2"));
CPPUNIT_ASSERT_EQUAL(String("Sunshine Superman"), f.ID3v2Tag()->frameListMap()["TIT2"].front()->toString());
void testUpdateDate22()
{
- MPEG::File f("data/id3v22-tda.mp3", false);
+ MPEG::File f(TEST_FILE_PATH_C("id3v22-tda.mp3"), false);
CPPUNIT_ASSERT(f.tag());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(2010), f.tag()->year());
}
void testUpdateFullDate22()
{
- MPEG::File f("data/id3v22-tda.mp3", false);
+ MPEG::File f(TEST_FILE_PATH_C("id3v22-tda.mp3"), false);
CPPUNIT_ASSERT(f.tag());
CPPUNIT_ASSERT_EQUAL(String("2010-04-03"), f.ID3v2Tag()->frameListMap()["TDRC"].front()->toString());
}
void testCompressedFrameWithBrokenLength()
{
- MPEG::File f("data/compressed_id3_frame.mp3", false);
+ MPEG::File f(TEST_FILE_PATH_C("compressed_id3_frame.mp3"), false);
CPPUNIT_ASSERT(f.ID3v2Tag()->frameListMap().contains("APIC"));
ID3v2::AttachedPictureFrame *frame =
static_cast<TagLib::ID3v2::AttachedPictureFrame*>(f.ID3v2Tag()->frameListMap()["APIC"].front());
void testProperties()
{
- MP4::File f("data/has-tags.m4a");
+ MP4::File f(TEST_FILE_PATH_C("has-tags.m4a"));
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
void testCheckValid()
{
- MP4::File f("data/empty.aiff");
+ MP4::File f(TEST_FILE_PATH_C("empty.aiff"));
CPPUNIT_ASSERT(!f.isValid());
- MP4::File f2("data/has-tags.m4a");
+ MP4::File f2(TEST_FILE_PATH_C("has-tags.m4a"));
CPPUNIT_ASSERT(f2.isValid());
}
void testGnre()
{
- MP4::File *f = new MP4::File("data/gnre.m4a");
+ MP4::File *f = new MP4::File(TEST_FILE_PATH_C("gnre.m4a"));
CPPUNIT_ASSERT_EQUAL(TagLib::String("Ska"), f->tag()->genre());
delete f;
}
void testCovrRead()
{
- MP4::File *f = new MP4::File("data/has-tags.m4a");
+ MP4::File *f = new MP4::File(TEST_FILE_PATH_C("has-tags.m4a"));
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr"));
MP4::CoverArtList l = f->tag()->itemListMap()["covr"].toCoverArtList();
CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size());
void testCovrRead2()
{
- MP4::File *f = new MP4::File("data/covr-junk.m4a");
+ MP4::File *f = new MP4::File(TEST_FILE_PATH_C("covr-junk.m4a"));
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr"));
MP4::CoverArtList l = f->tag()->itemListMap()["covr"].toCoverArtList();
CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size());
void testVersion2DurationWithXingHeader()
{
- MPEG::File f("data/mpeg2.mp3");
+ MPEG::File f(TEST_FILE_PATH_C("mpeg2.mp3"));
CPPUNIT_ASSERT_EQUAL(5387, f.audioProperties()->length());
}
#include <string>
#include <stdio.h>
#include <trueaudiofile.h>
+#include "utils.h"
using namespace std;
using namespace TagLib;
void testReadPropertiesWithoutID3v2()
{
- TrueAudio::File f("data/empty.tta");
+ TrueAudio::File f(TEST_FILE_PATH_C("empty.tta"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
}
void testLength()
{
- RIFF::WAV::File f("data/empty.wav");
+ RIFF::WAV::File f(TEST_FILE_PATH_C("empty.wav"));
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
}
void testBasic()
{
- WavPack::File f("data/no_length.wv");
+ WavPack::File f(TEST_FILE_PATH_C("no_length.wv"));
WavPack::Properties *props = f.audioProperties();
CPPUNIT_ASSERT_EQUAL(44100, props->sampleRate());
CPPUNIT_ASSERT_EQUAL(2, props->channels());
void testLengthScan()
{
- WavPack::File f("data/no_length.wv");
+ WavPack::File f(TEST_FILE_PATH_C("no_length.wv"));
WavPack::Properties *props = f.audioProperties();
CPPUNIT_ASSERT_EQUAL(4, props->length());
}
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#ifdef _WIN32
#include <windows.h>
#else
using namespace std;
+inline string testFilePath(const string &filename)
+{
+ return string(TESTS_DIR "data/") + filename;
+}
+
+#define TEST_FILE_PATH_C(f) testFilePath(f).c_str()
+
inline string copyFile(const string &filename, const string &ext)
{
string newname = string(tempnam(NULL, NULL)) + ext;
- string oldname = string("data/") + filename + ext;
+ string oldname = testFilePath(filename) + ext;
#ifdef _WIN32
CopyFile(oldname.c_str(), newname.c_str(), FALSE);
SetFileAttributes(newname.c_str(), GetFileAttributes(newname.c_str()) & ~FILE_ATTRIBUTE_READONLY);