Make it possible to run the test suite out of the source tree

This commit is contained in:
Lukáš Lalinský 2011-04-11 18:32:40 +02:00
parent 2fa8c93776
commit 4cda0eeb7b
13 changed files with 41 additions and 26 deletions

View File

@ -12,6 +12,7 @@ option(WITH_ASF "Enable ASF tag reading/writing code" OFF)
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)")

View File

@ -6,3 +6,6 @@
#cmakedefine NO_ITUNES_HACKS 1
#cmakedefine WITH_ASF 1
#cmakedefine WITH_MP4 1
#cmakedefine TESTS_DIR "@TESTS_DIR@"

View File

@ -22,7 +22,7 @@ public:
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());
@ -31,7 +31,7 @@ public:
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());
@ -40,7 +40,7 @@ public:
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());

View File

@ -28,7 +28,7 @@ public:
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());
@ -37,7 +37,7 @@ public:
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());
}

View File

@ -137,14 +137,14 @@ public:
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);
}

View File

@ -28,7 +28,7 @@ public:
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());
}

View File

@ -73,7 +73,7 @@ public:
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());
}
@ -114,7 +114,7 @@ public:
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"));
}
@ -382,7 +382,7 @@ public:
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());
@ -463,14 +463,14 @@ public:
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());
}
@ -536,7 +536,7 @@ public:
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());

View File

@ -30,7 +30,7 @@ public:
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());
@ -40,9 +40,9 @@ public:
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());
}
@ -156,14 +156,14 @@ public:
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());
@ -202,7 +202,7 @@ public:
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());

View File

@ -21,7 +21,7 @@ public:
void testVersion2DurationWithXingHeader()
{
MPEG::File f("data/mpeg2.mp3");
MPEG::File f(TEST_FILE_PATH_C("mpeg2.mp3"));
CPPUNIT_ASSERT_EQUAL(5387, f.audioProperties()->length());
}

View File

@ -2,6 +2,7 @@
#include <string>
#include <stdio.h>
#include <trueaudiofile.h>
#include "utils.h"
using namespace std;
using namespace TagLib;
@ -16,7 +17,7 @@ public:
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());
}

View File

@ -19,7 +19,7 @@ public:
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());
}

View File

@ -20,7 +20,7 @@ public:
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());
@ -30,7 +30,7 @@ public:
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());
}

View File

@ -1,3 +1,6 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef _WIN32
#include <windows.h>
#else
@ -10,10 +13,17 @@
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);