diff 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
line wrap: on
line diff
--- a/data/fileio/test/EncodingTest.h	Fri Jan 06 12:11:08 2017 +0000
+++ b/data/fileio/test/EncodingTest.h	Fri Jan 06 15:44:55 2017 +0000
@@ -31,13 +31,16 @@
 
 using namespace std;
 
-static QString encodingDir = "svcore/data/fileio/test/encodings";
+const char utf8_name_cdp_1[] = "Caf\303\251 de Paris";
+const char utf8_name_cdp_2[] = "Caf\303\251 de \351\207\215\345\272\206";
+const char utf8_name_tsprk[] = "T\303\253mple of Sp\303\253rks";
+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";
 
 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"スポークの寺院" }
+    { "id3v2-iso-8859-1", utf8_name_cdp_1 },
+    { "id3v2-ucs-2", utf8_name_cdp_2 },
+    { utf8_name_tsprk, utf8_name_tsprk },
+    { utf8_name_sprkt, utf8_name_sprkt },
 };
 static const int mappingCount = 4;
 
@@ -45,6 +48,20 @@
 {
     Q_OBJECT
 
+private:
+    QString testDirBase;
+    QString encodingDir;
+
+public:
+    EncodingTest(QString base) {
+        if (base == "") {
+            base = "svcore/data/fileio/test";
+        }
+        testDirBase = base;
+        encodingDir = base + "/encodings";
+    }
+
+private:
     const char *strOf(QString s) {
         return strdup(s.toLocal8Bit().data());
     }
@@ -72,9 +89,9 @@
         QFETCH(QString, audiofile);
 
         AudioFileReaderFactory::Parameters params;
-	AudioFileReader *reader =
-	    AudioFileReaderFactory::createReader
-	    (encodingDir + "/" + audiofile, params);
+        AudioFileReader *reader =
+            AudioFileReaderFactory::createReader
+            (encodingDir + "/" + audiofile, params);
 
         QVERIFY(reader != nullptr);
 
@@ -91,15 +108,29 @@
             for (int m = 0; m < mappingCount; ++m) {
                 if (file == QString::fromUtf8(mapping[m][0])) {
                     found = true;
-                    QCOMPARE(title, QString::fromUtf8(mapping[m][1]));
+                    QString expected = QString::fromUtf8(mapping[m][1]);
+                    if (title != expected) {
+                        cerr << "Title does not match expected: codepoints are" << endl;
+                        cerr << "Title (" << title.length() << "ch): ";
+                        for (int i = 0; i < title.length(); ++i) {
+                            cerr << title[i].unicode() << " ";
+                        }
+                        cerr << endl;
+                        cerr << "Expected (" << expected.length() << "ch): ";
+                        for (int i = 0; i < expected.length(); ++i) {
+                            cerr << expected[i].unicode() << " ";
+                        }
+                        cerr << endl;
+                    }
+                    QCOMPARE(title, expected);
                     break;
                 }
             }
 
             if (!found) {
-                cerr << "Failed to find filename \""
+                cerr << "Couldn't find filename \""
                      << file << "\" in title mapping array" << endl;
-                QVERIFY(found);
+                QSKIP("Couldn't find filename in title mapping array");
             }
         }
     }