Mercurial > hg > svcore
changeset 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 |
files | data/fileio/MP3FileReader.cpp data/fileio/test/AudioFileReaderTest.h data/fileio/test/EncodingTest.h data/fileio/test/svcore-data-fileio-test.cpp |
diffstat | 4 files changed, 101 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fileio/MP3FileReader.cpp Fri Jan 06 12:11:08 2017 +0000 +++ b/data/fileio/MP3FileReader.cpp Fri Jan 06 15:44:55 2017 +0000 @@ -34,6 +34,8 @@ #include <QFileInfo> +#include <QTextCodec> + #ifdef _MSC_VER #include <io.h> #define open _open @@ -75,6 +77,8 @@ CodedAudioFileReader::setFramesToTrim(DEFAULT_DECODER_DELAY, 0); } + SVDEBUG << "Codec for locale is " << (const char *)(QTextCodec::codecForLocale()->name().data()) << endl; + struct stat stat; if (::stat(m_path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) { m_error = QString("File %1 does not exist.").arg(m_path);
--- a/data/fileio/test/AudioFileReaderTest.h Fri Jan 06 12:11:08 2017 +0000 +++ b/data/fileio/test/AudioFileReaderTest.h Fri Jan 06 15:44:55 2017 +0000 @@ -32,13 +32,26 @@ using namespace std; -static QString audioDir = "svcore/data/fileio/test/testfiles"; -static QString diffDir = "svcore/data/fileio/test/diffs"; - class AudioFileReaderTest : public QObject { Q_OBJECT +private: + QString testDirBase; + QString audioDir; + QString diffDir; + +public: + AudioFileReaderTest(QString base) { + if (base == "") { + base = "svcore/data/fileio/test"; + } + testDirBase = base; + audioDir = base + "/testfiles"; + diffDir = base + "/diffs"; + } + +private: const char *strOf(QString s) { return strdup(s.toLocal8Bit().data()); } @@ -174,7 +187,8 @@ void init() { if (!QDir(audioDir).exists()) { - cerr << "ERROR: Audio test file directory \"" << audioDir << "\" does not exist" << endl; + QString cwd = QDir::currentPath(); + cerr << "ERROR: Audio test file directory \"" << audioDir << "\" does not exist (cwd = " << cwd << ")" << endl; QVERIFY2(QDir(audioDir).exists(), "Audio test file directory not found"); } if (!QDir(diffDir).exists() && !QDir().mkpath(diffDir)) { @@ -398,14 +412,14 @@ delete[] ptrs; } - for (int c = 0; c < channels; ++c) { + for (int c = 0; c < channels; ++c) { double maxDiff = 0.0; double totalDiff = 0.0; double totalSqrDiff = 0.0; - int maxIndex = 0; + int maxIndex = 0; - for (int i = 0; i < refFrames; ++i) { + for (int i = 0; i < refFrames; ++i) { int ix = i + offset; if (ix >= read) { cerr << "ERROR: audiofile " << audiofile << " reads truncated (read-rate reference frames " << i << " onward, of " << refFrames << ", are lost)" << endl; @@ -418,10 +432,10 @@ continue; } - double diff = fabs(test[ix * channels + c] - + double diff = fabs(test[ix * channels + c] - reference[i * channels + c]); - totalDiff += diff; + totalDiff += diff; totalSqrDiff += diff * diff; // in edge areas, record this only if it exceeds edgeLimit @@ -435,25 +449,25 @@ maxDiff = diff; maxIndex = i; } - } - } + } + } - double meanDiff = totalDiff / double(refFrames); + double meanDiff = totalDiff / double(refFrames); double rmsDiff = sqrt(totalSqrDiff / double(refFrames)); /* - cerr << "channel " << c << ": mean diff " << meanDiff << endl; + cerr << "channel " << c << ": mean diff " << meanDiff << endl; cerr << "channel " << c << ": rms diff " << rmsDiff << endl; cerr << "channel " << c << ": max diff " << maxDiff << " at " << maxIndex << endl; */ if (rmsDiff >= rmsLimit) { - cerr << "ERROR: for audiofile " << audiofile << ": RMS diff = " << rmsDiff << " for channel " << c << " (limit = " << rmsLimit << ")" << endl; + cerr << "ERROR: for audiofile " << audiofile << ": RMS diff = " << rmsDiff << " for channel " << c << " (limit = " << rmsLimit << ")" << endl; QVERIFY(rmsDiff < rmsLimit); } - if (maxDiff >= maxLimit) { - cerr << "ERROR: for audiofile " << audiofile << ": max diff = " << maxDiff << " at frame " << maxIndex << " of " << read << " on channel " << c << " (limit = " << maxLimit << ", edge limit = " << edgeLimit << ", mean diff = " << meanDiff << ", rms = " << rmsDiff << ")" << endl; - QVERIFY(maxDiff < maxLimit); - } + if (maxDiff >= maxLimit) { + cerr << "ERROR: for audiofile " << audiofile << ": max diff = " << maxDiff << " at frame " << maxIndex << " of " << read << " on channel " << c << " (limit = " << maxLimit << ", edge limit = " << edgeLimit << ", mean diff = " << meanDiff << ", rms = " << rmsDiff << ")" << endl; + QVERIFY(maxDiff < maxLimit); + } // and check for spurious material at end
--- 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"); } } }
--- a/data/fileio/test/svcore-data-fileio-test.cpp Fri Jan 06 12:11:08 2017 +0000 +++ b/data/fileio/test/svcore-data-fileio-test.cpp Fri Jan 06 15:44:55 2017 +0000 @@ -23,20 +23,37 @@ { int good = 0, bad = 0; + QString testDir; + +#ifdef Q_OS_WIN + // incredible to have to hardcode this, but I just can't figure out how to + // get QMAKE_POST_LINK to add an arg to its command successfully on Windows + testDir = "../sonic-visualiser/svcore/data/fileio/test"; +#endif + + if (argc > 1) { + cerr << "argc = " << argc << endl; + testDir = argv[1]; + } + + if (testDir != "") { + cerr << "Setting test directory base path to \"" << testDir << "\"" << endl; + } + QCoreApplication app(argc, argv); app.setOrganizationName("Sonic Visualiser"); app.setApplicationName("test-fileio"); { - AudioFileReaderTest t; - if (QTest::qExec(&t, argc, argv) == 0) ++good; - else ++bad; + AudioFileReaderTest t(testDir); + if (QTest::qExec(&t, argc, argv) == 0) ++good; + else ++bad; } { - EncodingTest t; - if (QTest::qExec(&t, argc, argv) == 0) ++good; - else ++bad; + EncodingTest t(testDir); + if (QTest::qExec(&t, argc, argv) == 0) ++good; + else ++bad; } if (bad > 0) {