diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-24 04:13:15 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-24 04:18:58 (GMT) |
commit | a1c1ff8561e8aefe4b4d09af1273bcb98c192772 (patch) | |
tree | 822b629abfce43ca3a068c3850a138f529f2180c /tests/auto/declarative/visual/tst_visual.cpp | |
parent | 09b117a97edd0791fb2c30f7a73704c926327ba3 (diff) | |
download | Qt-a1c1ff8561e8aefe4b4d09af1273bcb98c192772.zip Qt-a1c1ff8561e8aefe4b4d09af1273bcb98c192772.tar.gz Qt-a1c1ff8561e8aefe4b4d09af1273bcb98c192772.tar.bz2 |
Update visual autotests and visual autotest infrastructure
Diffstat (limited to 'tests/auto/declarative/visual/tst_visual.cpp')
-rw-r--r-- | tests/auto/declarative/visual/tst_visual.cpp | 232 |
1 files changed, 199 insertions, 33 deletions
diff --git a/tests/auto/declarative/visual/tst_visual.cpp b/tests/auto/declarative/visual/tst_visual.cpp index 10823e8..458b96e 100644 --- a/tests/auto/declarative/visual/tst_visual.cpp +++ b/tests/auto/declarative/visual/tst_visual.cpp @@ -1,7 +1,10 @@ #include <qtest.h> #include <QmlView> #include <QApplication> -#include <QFxTestView> +#include <QLibraryInfo> +#include <QDir> +#include <QDebug> +#include <QProcess> #include <QFile> static QString testdir; @@ -9,66 +12,229 @@ class tst_visual : public QObject { Q_OBJECT public: - tst_visual() {} + tst_visual(); + + static QString toTestScript(const QString &); + static QString viewer(); private slots: + void visual_data(); void visual(); + +private: + QString qmlviewer; + QStringList findQmlFiles(const QDir &d); }; -#ifdef QT_OPENGL_ES -#define RASTER_TESTDIR "/data/opengl" + +tst_visual::tst_visual() +{ + qmlviewer = viewer(); +} + +QString tst_visual::viewer() +{ + QString binaries = QLibraryInfo::location(QLibraryInfo::BinariesPath); + + QString qmlviewer; + +#if defined(Q_WS_MAC) + qmlviewer = QDir(binaries).absoluteFilePath("qmlviewer.app/Contents/MacOS/qmlviewer"); +#elif defined(Q_WS_WIN) + qmlviewer = QDir(binaries).absoluteFilePath("qmlviewer.exe"); #else -#define RASTER_TESTDIR "/data/raster" + qmlviewer = QDir(binaries).absoluteFilePath("qmlviewer"); #endif + return qmlviewer; +} + +void tst_visual::visual_data() +{ + QTest::addColumn<QString>("file"); + QTest::addColumn<QString>("testdata"); + + QStringList files; + files << findQmlFiles(QDir(QT_TEST_SOURCE_DIR)); + + foreach (const QString &file, files) { + QString testdata = toTestScript(file); + if (testdata.isEmpty()) + continue; + + QTest::newRow(file.toLatin1().constData()) << file << testdata; + } +} + void tst_visual::visual() { - QVERIFY(!testdir.isEmpty()); + QFETCH(QString, file); + QFETCH(QString, testdata); + + QStringList arguments; + arguments << "-script" << testdata + << "-scriptopts" << "play,testimages,exitoncomplete,exitonfailure" + << file; + QProcess p; + p.start(qmlviewer, arguments); + QVERIFY(p.waitForFinished()); + QCOMPARE(p.exitStatus(), QProcess::NormalExit); + QCOMPARE(p.exitCode(), 0); +} - QString filename = QLatin1String(QT_TEST_SOURCE_DIR) + "/" + testdir + "/test"; - qWarning() << "Using config:" << filename; - QFile configFile(filename); - QVERIFY(configFile.open(QIODevice::ReadOnly)); +QString tst_visual::toTestScript(const QString &file) +{ + if (!file.endsWith(".qml")) + return QString(); - QString testfile = configFile.readLine().trimmed(); - QVERIFY(!testfile.isEmpty()); + int index = file.lastIndexOf(QDir::separator()); + if (index == -1) + return QString(); - if(testfile.startsWith("QTDIR/")) { - testfile.remove(0, 6); - testfile.prepend(QLatin1String(QT_TEST_SOURCE_DIR) + "/../../../../"); - } else { - testfile.prepend(QLatin1String(QT_TEST_SOURCE_DIR) + "/" + testdir + "/"); + QString testdata = file.left(index + 1) + + QString("data") + QDir::separator() + + file.mid(index + 1, file.length() - index - 5); + + return testdata; +} + +QStringList tst_visual::findQmlFiles(const QDir &d) +{ + QStringList rv; + + QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"), + QDir::Files); + foreach (const QString &file, files) { + if (file.at(0).isLower()) { + rv << d.absoluteFilePath(file); + } + } + + QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | + QDir::NoSymLinks); + foreach (const QString &dir, dirs) { + if (dir == "data") + continue; + + QDir sub = d; + sub.cd(dir); + rv << findQmlFiles(sub); } - QFxTestView *view = new QFxTestView(testfile, QLatin1String(QT_TEST_SOURCE_DIR) + "/" + testdir + RASTER_TESTDIR); - QVERIFY(view->runTest()); + return rv; +} + +enum Mode { Record, Play, TestVisuals, UpdateVisuals, Test }; + +void action(Mode mode, const QString &file) +{ + Q_ASSERT(mode != Test); + + QString testdata = tst_visual::toTestScript(file); + + if (Record == mode) { + QStringList arguments; + arguments << "-script" << testdata + << "-scriptopts" << "record,saveonexit" + << file; + QProcess p; + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.start(tst_visual::viewer(), arguments); + p.waitForFinished(); + } else if (Play == mode) { + QStringList arguments; + arguments << "-script" << testdata + << "-scriptopts" << "play,testimages,exitoncomplete" + << file; + QProcess p; + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.start(tst_visual::viewer(), arguments); + p.waitForFinished(); + } else if (TestVisuals == mode) { + QStringList arguments; + arguments << "-script" << testdata + << "-scriptopts" << "play" + << file; + QProcess p; + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.start(tst_visual::viewer(), arguments); + p.waitForFinished(); + } else if (UpdateVisuals == mode) { + QStringList arguments; + arguments << "-script" << testdata + << "-scriptopts" << "play,record,exitoncomplete,saveonexit" + << file; + QProcess p; + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.start(tst_visual::viewer(), arguments); + p.waitForFinished(); + } } -#include <QtTest/qtest_gui.h> +void usage() +{ + fprintf(stderr, "\n"); + fprintf(stderr, "QML related options\n"); + fprintf(stderr, " -record file : record new test data for file\n"); + fprintf(stderr, " -play file : playback test data for file, printing errors\n"); + fprintf(stderr, " -testvisuals file : playback test data for file, without errors\n"); + fprintf(stderr, " -updatevisuals file : playback test data for file, accept new visuals for file\n"); +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + Mode mode = Test; + QString file; + bool showHelp = false; -int main(int argc, char *argv[]) -{ int newArgc = 1; char **newArgv = new char*[argc]; - newArgv[0] = argv[0]; - QApplication app(newArgc, newArgv); - - for(int ii = 1; ii < argc; ii++) { - if(QLatin1String(argv[ii]) == "-testdir" && (ii + 1) < argc) { - testdir = QLatin1String(argv[ii + 1]); - ii++; + for (int ii = 1; ii < argc; ++ii) { + QString arg(argv[ii]); + if (arg == "-play" && (ii + 1) < argc) { + mode = Play; + file = argv[++ii]; + } else if (arg == "-record" && (ii + 1) < argc) { + mode = Record; + file = argv[++ii]; + } else if (arg == "-testvisuals" && (ii + 1) < argc) { + mode = TestVisuals; + file = argv[++ii]; + } else if (arg == "-updatevisuals" && (ii + 1) < argc) { + mode = UpdateVisuals; + file = argv[++ii]; } else { newArgv[newArgc++] = argv[ii]; } + + if (arg == "-help") { + atexit(usage); + showHelp = true; + } } - tst_visual tc; - int rv = QTest::qExec(&tc, newArgc, newArgv); + if (mode == Test || showHelp) { + tst_visual tc; + return QTest::qExec(&tc, newArgc, newArgv); + } else { + if (!file.endsWith(QLatin1String(".qml"))) { + qWarning() << "Error: Invalid file name (must end in .qml)"; + return -1; + } + QDir d = QDir::current(); + QString absFile = d.absoluteFilePath(file); + if (!QFile::exists(absFile)) { + qWarning() << "Error: File does not exist"; + return -1; + } - delete [] newArgv; - return rv; + action(mode, absFile); + return 0; + } } #include "tst_visual.moc" |