Chris@1345: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1345: Chris@1345: /* Chris@1345: Sonic Visualiser Chris@1345: An audio file viewer and annotation editor. Chris@1345: Centre for Digital Music, Queen Mary, University of London. Chris@1345: Chris@1345: This program is free software; you can redistribute it and/or Chris@1345: modify it under the terms of the GNU General Public License as Chris@1345: published by the Free Software Foundation; either version 2 of the Chris@1345: License, or (at your option) any later version. See the file Chris@1345: COPYING included with this distribution for more information. Chris@1345: */ Chris@1345: Chris@1345: #ifndef TEST_AUDIO_ENCODINGS_H Chris@1345: #define TEST_AUDIO_ENCODINGS_H Chris@1345: Chris@1345: // Quick tests for filename encodings and encoding of ID3 data. Not a Chris@1345: // test of audio codecs. Chris@1345: Chris@1345: #include "../AudioFileReaderFactory.h" Chris@1345: #include "../AudioFileReader.h" Chris@1345: Chris@1345: #include Chris@1345: Chris@1345: #include Chris@1345: #include Chris@1345: #include Chris@1345: Chris@1345: #include Chris@1345: Chris@1345: using namespace std; Chris@1345: Chris@1345: static QString encodingDir = "svcore/data/fileio/test/encodings"; Chris@1345: Chris@1345: static const char *mapping[][2] = { Chris@1345: { u8"id3v2-iso-8859-1", u8"Café de Paris" }, Chris@1345: { u8"id3v2-ucs-2", u8"Café de 重庆" }, Chris@1345: { u8"Tëmple of Spörks", u8"Tëmple of Spörks" }, Chris@1345: { u8"スポークの寺院", u8"スポークの寺院" } Chris@1345: }; Chris@1345: static const int mappingCount = 4; Chris@1345: Chris@1345: class EncodingTest : public QObject Chris@1345: { Chris@1345: Q_OBJECT Chris@1345: Chris@1345: const char *strOf(QString s) { Chris@1345: return strdup(s.toLocal8Bit().data()); Chris@1345: } Chris@1345: Chris@1345: private slots: Chris@1345: void init() Chris@1345: { Chris@1345: if (!QDir(encodingDir).exists()) { Chris@1345: cerr << "ERROR: Audio encoding file directory \"" << encodingDir << "\" does not exist" << endl; Chris@1345: QVERIFY2(QDir(encodingDir).exists(), "Audio encoding file directory not found"); Chris@1345: } Chris@1345: } Chris@1345: Chris@1345: void read_data() Chris@1345: { Chris@1345: QTest::addColumn("audiofile"); Chris@1345: QStringList files = QDir(encodingDir).entryList(QDir::Files); Chris@1345: foreach (QString filename, files) { Chris@1345: QTest::newRow(strOf(filename)) << filename; Chris@1345: } Chris@1345: } Chris@1345: Chris@1345: void read() Chris@1345: { Chris@1345: QFETCH(QString, audiofile); Chris@1345: Chris@1345: AudioFileReaderFactory::Parameters params; Chris@1345: AudioFileReader *reader = Chris@1345: AudioFileReaderFactory::createReader Chris@1345: (encodingDir + "/" + audiofile, params); Chris@1345: Chris@1345: QVERIFY(reader != nullptr); Chris@1345: Chris@1345: QStringList fileAndExt = audiofile.split("."); Chris@1345: QString file = fileAndExt[0]; Chris@1345: QString extension = fileAndExt[1]; Chris@1345: Chris@1345: if (extension == "mp3") { Chris@1345: Chris@1345: QString title = reader->getTitle(); Chris@1345: QVERIFY(title != QString()); Chris@1345: Chris@1345: bool found = false; Chris@1345: for (int m = 0; m < mappingCount; ++m) { Chris@1345: if (file == QString::fromUtf8(mapping[m][0])) { Chris@1345: found = true; Chris@1345: QCOMPARE(title, QString::fromUtf8(mapping[m][1])); Chris@1345: break; Chris@1345: } Chris@1345: } Chris@1345: Chris@1345: if (!found) { Chris@1345: cerr << "Failed to find filename \"" Chris@1345: << file << "\" in title mapping array" << endl; Chris@1345: QVERIFY(found); Chris@1345: } Chris@1345: } Chris@1345: } Chris@1345: }; Chris@1345: Chris@1345: #endif