# HG changeset patch # User Chris Cannam # Date 1483704668 0 # Node ID c0cdacc47f4e1ed71cc45e99dfeaf2a866be81a5 # Parent 980afe3f1a7659d6ad8b1775b3692eb6e44bcb4e Add filename encoding tests diff -r 980afe3f1a76 -r c0cdacc47f4e data/fileio/test/EncodingTest.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/EncodingTest.h Fri Jan 06 12:11:08 2017 +0000 @@ -0,0 +1,108 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef TEST_AUDIO_ENCODINGS_H +#define TEST_AUDIO_ENCODINGS_H + +// Quick tests for filename encodings and encoding of ID3 data. Not a +// test of audio codecs. + +#include "../AudioFileReaderFactory.h" +#include "../AudioFileReader.h" + +#include + +#include +#include +#include + +#include + +using namespace std; + +static QString encodingDir = "svcore/data/fileio/test/encodings"; + +static const char *mapping[][2] = { + { u8"id3v2-iso-8859-1", u8"Café de Paris" }, + { u8"id3v2-ucs-2", u8"Café de 重庆" }, + { u8"Tëmple of Spörks", u8"Tëmple of Spörks" }, + { u8"スポークの寺院", u8"スポークの寺院" } +}; +static const int mappingCount = 4; + +class EncodingTest : public QObject +{ + Q_OBJECT + + const char *strOf(QString s) { + return strdup(s.toLocal8Bit().data()); + } + +private slots: + void init() + { + if (!QDir(encodingDir).exists()) { + cerr << "ERROR: Audio encoding file directory \"" << encodingDir << "\" does not exist" << endl; + QVERIFY2(QDir(encodingDir).exists(), "Audio encoding file directory not found"); + } + } + + void read_data() + { + QTest::addColumn("audiofile"); + QStringList files = QDir(encodingDir).entryList(QDir::Files); + foreach (QString filename, files) { + QTest::newRow(strOf(filename)) << filename; + } + } + + void read() + { + QFETCH(QString, audiofile); + + AudioFileReaderFactory::Parameters params; + AudioFileReader *reader = + AudioFileReaderFactory::createReader + (encodingDir + "/" + audiofile, params); + + QVERIFY(reader != nullptr); + + QStringList fileAndExt = audiofile.split("."); + QString file = fileAndExt[0]; + QString extension = fileAndExt[1]; + + if (extension == "mp3") { + + QString title = reader->getTitle(); + QVERIFY(title != QString()); + + bool found = false; + for (int m = 0; m < mappingCount; ++m) { + if (file == QString::fromUtf8(mapping[m][0])) { + found = true; + QCOMPARE(title, QString::fromUtf8(mapping[m][1])); + break; + } + } + + if (!found) { + cerr << "Failed to find filename \"" + << file << "\" in title mapping array" << endl; + QVERIFY(found); + } + } + } +}; + +#endif diff -r 980afe3f1a76 -r c0cdacc47f4e data/fileio/test/encodings/Tëmple of Spörks.mp3 Binary file data/fileio/test/encodings/Tëmple of Spörks.mp3 has changed diff -r 980afe3f1a76 -r c0cdacc47f4e data/fileio/test/encodings/id3v2-iso-8859-1.mp3 Binary file data/fileio/test/encodings/id3v2-iso-8859-1.mp3 has changed diff -r 980afe3f1a76 -r c0cdacc47f4e data/fileio/test/encodings/id3v2-ucs-2.mp3 Binary file data/fileio/test/encodings/id3v2-ucs-2.mp3 has changed diff -r 980afe3f1a76 -r c0cdacc47f4e data/fileio/test/encodings/スポークの寺院.mp3 Binary file data/fileio/test/encodings/スポークの寺院.mp3 has changed diff -r 980afe3f1a76 -r c0cdacc47f4e data/fileio/test/files.pri --- a/data/fileio/test/files.pri Fri Jan 06 11:21:09 2017 +0000 +++ b/data/fileio/test/files.pri Fri Jan 06 12:11:08 2017 +0000 @@ -1,7 +1,8 @@ TEST_HEADERS += \ AudioFileReaderTest.h \ - AudioTestData.h + AudioTestData.h \ + EncodingTest.h TEST_SOURCES += \ svcore-data-fileio-test.cpp diff -r 980afe3f1a76 -r c0cdacc47f4e data/fileio/test/svcore-data-fileio-test.cpp --- a/data/fileio/test/svcore-data-fileio-test.cpp Fri Jan 06 11:21:09 2017 +0000 +++ b/data/fileio/test/svcore-data-fileio-test.cpp Fri Jan 06 12:11:08 2017 +0000 @@ -13,6 +13,7 @@ */ #include "AudioFileReaderTest.h" +#include "EncodingTest.h" #include @@ -32,6 +33,12 @@ else ++bad; } + { + EncodingTest t; + if (QTest::qExec(&t, argc, argv) == 0) ++good; + else ++bad; + } + if (bad > 0) { cerr << "\n********* " << bad << " test suite(s) failed!\n" << endl; return 1;