Mercurial > hg > svcore
comparison data/fileio/test/EncodingTest.h @ 1346:75ad55315db4 3.0-integration
More work on getting tests (especially file encoding ones) running on Windows. Various problems here to do with interaction with test filenames in Hg repos
| author | Chris Cannam |
|---|---|
| date | Fri, 06 Jan 2017 15:44:55 +0000 |
| parents | c0cdacc47f4e |
| children | 281a8c9d4886 |
comparison
equal
deleted
inserted
replaced
| 1345:c0cdacc47f4e | 1346:75ad55315db4 |
|---|---|
| 29 | 29 |
| 30 #include <iostream> | 30 #include <iostream> |
| 31 | 31 |
| 32 using namespace std; | 32 using namespace std; |
| 33 | 33 |
| 34 static QString encodingDir = "svcore/data/fileio/test/encodings"; | 34 const char utf8_name_cdp_1[] = "Caf\303\251 de Paris"; |
| 35 const char utf8_name_cdp_2[] = "Caf\303\251 de \351\207\215\345\272\206"; | |
| 36 const char utf8_name_tsprk[] = "T\303\253mple of Sp\303\253rks"; | |
| 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"; | |
| 35 | 38 |
| 36 static const char *mapping[][2] = { | 39 static const char *mapping[][2] = { |
| 37 { u8"id3v2-iso-8859-1", u8"Café de Paris" }, | 40 { "id3v2-iso-8859-1", utf8_name_cdp_1 }, |
| 38 { u8"id3v2-ucs-2", u8"Café de 重庆" }, | 41 { "id3v2-ucs-2", utf8_name_cdp_2 }, |
| 39 { u8"Tëmple of Spörks", u8"Tëmple of Spörks" }, | 42 { utf8_name_tsprk, utf8_name_tsprk }, |
| 40 { u8"スポークの寺院", u8"スポークの寺院" } | 43 { utf8_name_sprkt, utf8_name_sprkt }, |
| 41 }; | 44 }; |
| 42 static const int mappingCount = 4; | 45 static const int mappingCount = 4; |
| 43 | 46 |
| 44 class EncodingTest : public QObject | 47 class EncodingTest : public QObject |
| 45 { | 48 { |
| 46 Q_OBJECT | 49 Q_OBJECT |
| 47 | 50 |
| 51 private: | |
| 52 QString testDirBase; | |
| 53 QString encodingDir; | |
| 54 | |
| 55 public: | |
| 56 EncodingTest(QString base) { | |
| 57 if (base == "") { | |
| 58 base = "svcore/data/fileio/test"; | |
| 59 } | |
| 60 testDirBase = base; | |
| 61 encodingDir = base + "/encodings"; | |
| 62 } | |
| 63 | |
| 64 private: | |
| 48 const char *strOf(QString s) { | 65 const char *strOf(QString s) { |
| 49 return strdup(s.toLocal8Bit().data()); | 66 return strdup(s.toLocal8Bit().data()); |
| 50 } | 67 } |
| 51 | 68 |
| 52 private slots: | 69 private slots: |
| 70 void read() | 87 void read() |
| 71 { | 88 { |
| 72 QFETCH(QString, audiofile); | 89 QFETCH(QString, audiofile); |
| 73 | 90 |
| 74 AudioFileReaderFactory::Parameters params; | 91 AudioFileReaderFactory::Parameters params; |
| 75 AudioFileReader *reader = | 92 AudioFileReader *reader = |
| 76 AudioFileReaderFactory::createReader | 93 AudioFileReaderFactory::createReader |
| 77 (encodingDir + "/" + audiofile, params); | 94 (encodingDir + "/" + audiofile, params); |
| 78 | 95 |
| 79 QVERIFY(reader != nullptr); | 96 QVERIFY(reader != nullptr); |
| 80 | 97 |
| 81 QStringList fileAndExt = audiofile.split("."); | 98 QStringList fileAndExt = audiofile.split("."); |
| 82 QString file = fileAndExt[0]; | 99 QString file = fileAndExt[0]; |
| 89 | 106 |
| 90 bool found = false; | 107 bool found = false; |
| 91 for (int m = 0; m < mappingCount; ++m) { | 108 for (int m = 0; m < mappingCount; ++m) { |
| 92 if (file == QString::fromUtf8(mapping[m][0])) { | 109 if (file == QString::fromUtf8(mapping[m][0])) { |
| 93 found = true; | 110 found = true; |
| 94 QCOMPARE(title, QString::fromUtf8(mapping[m][1])); | 111 QString expected = QString::fromUtf8(mapping[m][1]); |
| 112 if (title != expected) { | |
| 113 cerr << "Title does not match expected: codepoints are" << endl; | |
| 114 cerr << "Title (" << title.length() << "ch): "; | |
| 115 for (int i = 0; i < title.length(); ++i) { | |
| 116 cerr << title[i].unicode() << " "; | |
| 117 } | |
| 118 cerr << endl; | |
| 119 cerr << "Expected (" << expected.length() << "ch): "; | |
| 120 for (int i = 0; i < expected.length(); ++i) { | |
| 121 cerr << expected[i].unicode() << " "; | |
| 122 } | |
| 123 cerr << endl; | |
| 124 } | |
| 125 QCOMPARE(title, expected); | |
| 95 break; | 126 break; |
| 96 } | 127 } |
| 97 } | 128 } |
| 98 | 129 |
| 99 if (!found) { | 130 if (!found) { |
| 100 cerr << "Failed to find filename \"" | 131 cerr << "Couldn't find filename \"" |
| 101 << file << "\" in title mapping array" << endl; | 132 << file << "\" in title mapping array" << endl; |
| 102 QVERIFY(found); | 133 QSKIP("Couldn't find filename in title mapping array"); |
| 103 } | 134 } |
| 104 } | 135 } |
| 105 } | 136 } |
| 106 }; | 137 }; |
| 107 | 138 |
