Chris@1345
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1345
|
2
|
Chris@1345
|
3 /*
|
Chris@1345
|
4 Sonic Visualiser
|
Chris@1345
|
5 An audio file viewer and annotation editor.
|
Chris@1345
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1345
|
7
|
Chris@1345
|
8 This program is free software; you can redistribute it and/or
|
Chris@1345
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1345
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1345
|
11 License, or (at your option) any later version. See the file
|
Chris@1345
|
12 COPYING included with this distribution for more information.
|
Chris@1345
|
13 */
|
Chris@1345
|
14
|
Chris@1345
|
15 #ifndef TEST_AUDIO_ENCODINGS_H
|
Chris@1345
|
16 #define TEST_AUDIO_ENCODINGS_H
|
Chris@1345
|
17
|
Chris@1345
|
18 // Quick tests for filename encodings and encoding of ID3 data. Not a
|
Chris@1345
|
19 // test of audio codecs.
|
Chris@1345
|
20
|
Chris@1345
|
21 #include "../AudioFileReaderFactory.h"
|
Chris@1345
|
22 #include "../AudioFileReader.h"
|
Chris@1345
|
23
|
Chris@1345
|
24 #include <cmath>
|
Chris@1345
|
25
|
Chris@1345
|
26 #include <QObject>
|
Chris@1345
|
27 #include <QtTest>
|
Chris@1345
|
28 #include <QDir>
|
Chris@1345
|
29
|
Chris@1345
|
30 #include <iostream>
|
Chris@1345
|
31
|
Chris@1345
|
32 using namespace std;
|
Chris@1345
|
33
|
Chris@1346
|
34 const char utf8_name_cdp_1[] = "Caf\303\251 de Paris";
|
Chris@1346
|
35 const char utf8_name_cdp_2[] = "Caf\303\251 de \351\207\215\345\272\206";
|
Chris@1347
|
36 const char utf8_name_tsprk[] = "T\303\253mple of Sp\303\266rks";
|
Chris@1346
|
37 const char utf8_name_sprkt[] = "\343\202\271\343\203\235\343\203\274\343\202\257\343\201\256\345\257\272\351\231\242";
|
Chris@1345
|
38
|
Chris@1345
|
39 static const char *mapping[][2] = {
|
Chris@1346
|
40 { "id3v2-iso-8859-1", utf8_name_cdp_1 },
|
Chris@1346
|
41 { "id3v2-ucs-2", utf8_name_cdp_2 },
|
Chris@1346
|
42 { utf8_name_tsprk, utf8_name_tsprk },
|
Chris@1346
|
43 { utf8_name_sprkt, utf8_name_sprkt },
|
Chris@1345
|
44 };
|
Chris@1345
|
45 static const int mappingCount = 4;
|
Chris@1345
|
46
|
Chris@1345
|
47 class EncodingTest : public QObject
|
Chris@1345
|
48 {
|
Chris@1345
|
49 Q_OBJECT
|
Chris@1345
|
50
|
Chris@1346
|
51 private:
|
Chris@1346
|
52 QString testDirBase;
|
Chris@1346
|
53 QString encodingDir;
|
Chris@1346
|
54
|
Chris@1346
|
55 public:
|
Chris@1346
|
56 EncodingTest(QString base) {
|
Chris@1346
|
57 if (base == "") {
|
Chris@1346
|
58 base = "svcore/data/fileio/test";
|
Chris@1346
|
59 }
|
Chris@1346
|
60 testDirBase = base;
|
Chris@1346
|
61 encodingDir = base + "/encodings";
|
Chris@1346
|
62 }
|
Chris@1346
|
63
|
Chris@1346
|
64 private:
|
Chris@1345
|
65 const char *strOf(QString s) {
|
Chris@1345
|
66 return strdup(s.toLocal8Bit().data());
|
Chris@1345
|
67 }
|
Chris@1345
|
68
|
Chris@1345
|
69 private slots:
|
Chris@1345
|
70 void init()
|
Chris@1345
|
71 {
|
Chris@1345
|
72 if (!QDir(encodingDir).exists()) {
|
Chris@1345
|
73 cerr << "ERROR: Audio encoding file directory \"" << encodingDir << "\" does not exist" << endl;
|
Chris@1345
|
74 QVERIFY2(QDir(encodingDir).exists(), "Audio encoding file directory not found");
|
Chris@1345
|
75 }
|
Chris@1345
|
76 }
|
Chris@1345
|
77
|
Chris@1345
|
78 void read_data()
|
Chris@1345
|
79 {
|
Chris@1345
|
80 QTest::addColumn<QString>("audiofile");
|
Chris@1345
|
81 QStringList files = QDir(encodingDir).entryList(QDir::Files);
|
Chris@1345
|
82 foreach (QString filename, files) {
|
Chris@1345
|
83 QTest::newRow(strOf(filename)) << filename;
|
Chris@1345
|
84 }
|
Chris@1345
|
85 }
|
Chris@1345
|
86
|
Chris@1345
|
87 void read()
|
Chris@1345
|
88 {
|
Chris@1345
|
89 QFETCH(QString, audiofile);
|
Chris@1345
|
90
|
Chris@1345
|
91 AudioFileReaderFactory::Parameters params;
|
Chris@1346
|
92 AudioFileReader *reader =
|
Chris@1346
|
93 AudioFileReaderFactory::createReader
|
Chris@1346
|
94 (encodingDir + "/" + audiofile, params);
|
Chris@1345
|
95
|
Chris@1345
|
96 QVERIFY(reader != nullptr);
|
Chris@1345
|
97
|
Chris@1345
|
98 QStringList fileAndExt = audiofile.split(".");
|
Chris@1345
|
99 QString file = fileAndExt[0];
|
Chris@1345
|
100 QString extension = fileAndExt[1];
|
Chris@1345
|
101
|
Chris@1345
|
102 if (extension == "mp3") {
|
Chris@1345
|
103
|
Chris@1345
|
104 QString title = reader->getTitle();
|
Chris@1345
|
105 QVERIFY(title != QString());
|
Chris@1345
|
106
|
Chris@1345
|
107 bool found = false;
|
Chris@1345
|
108 for (int m = 0; m < mappingCount; ++m) {
|
Chris@1345
|
109 if (file == QString::fromUtf8(mapping[m][0])) {
|
Chris@1345
|
110 found = true;
|
Chris@1346
|
111 QString expected = QString::fromUtf8(mapping[m][1]);
|
Chris@1346
|
112 if (title != expected) {
|
Chris@1346
|
113 cerr << "Title does not match expected: codepoints are" << endl;
|
Chris@1346
|
114 cerr << "Title (" << title.length() << "ch): ";
|
Chris@1346
|
115 for (int i = 0; i < title.length(); ++i) {
|
Chris@1346
|
116 cerr << title[i].unicode() << " ";
|
Chris@1346
|
117 }
|
Chris@1346
|
118 cerr << endl;
|
Chris@1346
|
119 cerr << "Expected (" << expected.length() << "ch): ";
|
Chris@1346
|
120 for (int i = 0; i < expected.length(); ++i) {
|
Chris@1346
|
121 cerr << expected[i].unicode() << " ";
|
Chris@1346
|
122 }
|
Chris@1346
|
123 cerr << endl;
|
Chris@1346
|
124 }
|
Chris@1346
|
125 QCOMPARE(title, expected);
|
Chris@1345
|
126 break;
|
Chris@1345
|
127 }
|
Chris@1345
|
128 }
|
Chris@1345
|
129
|
Chris@1345
|
130 if (!found) {
|
Chris@1346
|
131 cerr << "Couldn't find filename \""
|
Chris@1345
|
132 << file << "\" in title mapping array" << endl;
|
Chris@1346
|
133 QSKIP("Couldn't find filename in title mapping array");
|
Chris@1345
|
134 }
|
Chris@1345
|
135 }
|
Chris@1345
|
136 }
|
Chris@1345
|
137 };
|
Chris@1345
|
138
|
Chris@1345
|
139 #endif
|