Mercurial > hg > svcore
comparison data/fileio/test/EncodingTest.h @ 1345:c0cdacc47f4e 3.0-integration
Add filename encoding tests
author | Chris Cannam |
---|---|
date | Fri, 06 Jan 2017 12:11:08 +0000 |
parents | |
children | 75ad55315db4 |
comparison
equal
deleted
inserted
replaced
1344:980afe3f1a76 | 1345:c0cdacc47f4e |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #ifndef TEST_AUDIO_ENCODINGS_H | |
16 #define TEST_AUDIO_ENCODINGS_H | |
17 | |
18 // Quick tests for filename encodings and encoding of ID3 data. Not a | |
19 // test of audio codecs. | |
20 | |
21 #include "../AudioFileReaderFactory.h" | |
22 #include "../AudioFileReader.h" | |
23 | |
24 #include <cmath> | |
25 | |
26 #include <QObject> | |
27 #include <QtTest> | |
28 #include <QDir> | |
29 | |
30 #include <iostream> | |
31 | |
32 using namespace std; | |
33 | |
34 static QString encodingDir = "svcore/data/fileio/test/encodings"; | |
35 | |
36 static const char *mapping[][2] = { | |
37 { u8"id3v2-iso-8859-1", u8"Café de Paris" }, | |
38 { u8"id3v2-ucs-2", u8"Café de 重庆" }, | |
39 { u8"Tëmple of Spörks", u8"Tëmple of Spörks" }, | |
40 { u8"スポークの寺院", u8"スポークの寺院" } | |
41 }; | |
42 static const int mappingCount = 4; | |
43 | |
44 class EncodingTest : public QObject | |
45 { | |
46 Q_OBJECT | |
47 | |
48 const char *strOf(QString s) { | |
49 return strdup(s.toLocal8Bit().data()); | |
50 } | |
51 | |
52 private slots: | |
53 void init() | |
54 { | |
55 if (!QDir(encodingDir).exists()) { | |
56 cerr << "ERROR: Audio encoding file directory \"" << encodingDir << "\" does not exist" << endl; | |
57 QVERIFY2(QDir(encodingDir).exists(), "Audio encoding file directory not found"); | |
58 } | |
59 } | |
60 | |
61 void read_data() | |
62 { | |
63 QTest::addColumn<QString>("audiofile"); | |
64 QStringList files = QDir(encodingDir).entryList(QDir::Files); | |
65 foreach (QString filename, files) { | |
66 QTest::newRow(strOf(filename)) << filename; | |
67 } | |
68 } | |
69 | |
70 void read() | |
71 { | |
72 QFETCH(QString, audiofile); | |
73 | |
74 AudioFileReaderFactory::Parameters params; | |
75 AudioFileReader *reader = | |
76 AudioFileReaderFactory::createReader | |
77 (encodingDir + "/" + audiofile, params); | |
78 | |
79 QVERIFY(reader != nullptr); | |
80 | |
81 QStringList fileAndExt = audiofile.split("."); | |
82 QString file = fileAndExt[0]; | |
83 QString extension = fileAndExt[1]; | |
84 | |
85 if (extension == "mp3") { | |
86 | |
87 QString title = reader->getTitle(); | |
88 QVERIFY(title != QString()); | |
89 | |
90 bool found = false; | |
91 for (int m = 0; m < mappingCount; ++m) { | |
92 if (file == QString::fromUtf8(mapping[m][0])) { | |
93 found = true; | |
94 QCOMPARE(title, QString::fromUtf8(mapping[m][1])); | |
95 break; | |
96 } | |
97 } | |
98 | |
99 if (!found) { | |
100 cerr << "Failed to find filename \"" | |
101 << file << "\" in title mapping array" << endl; | |
102 QVERIFY(found); | |
103 } | |
104 } | |
105 } | |
106 }; | |
107 | |
108 #endif |