diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2010-11-19 08:29:11 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2010-11-19 08:29:11 (GMT) |
commit | 1960713543e2a5fee76df7dbf06ea70cf277d696 (patch) | |
tree | 03c83f4775e178f4f16535586baefff28b62488b /tests/auto/declarative | |
parent | d4cd9c899e705ff01f597f0007def8fbd3ab8b39 (diff) | |
download | Qt-1960713543e2a5fee76df7dbf06ea70cf277d696.zip Qt-1960713543e2a5fee76df7dbf06ea70cf277d696.tar.gz Qt-1960713543e2a5fee76df7dbf06ea70cf277d696.tar.bz2 |
Initial commit of qmlvisualaids
A tool to make it easier to do the platform visual updating. Needs to be
streamlined at least a little in order to make it feasible to stay up to
date.
Task-number: QTBUG-14792
Diffstat (limited to 'tests/auto/declarative')
9 files changed, 391 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/Button.qml b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/Button.qml new file mode 100644 index 0000000..600079f --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/Button.qml @@ -0,0 +1,19 @@ +import Qt 4.7 + +Rectangle { + width: txt.width + 16 + height: txt.height + 8 + radius: 4 + border.color: "black" + property alias caption: txt.text + signal triggered + Text{ + id: txt + text: "Button" + anchors.centerIn: parent + } + MouseArea{ + anchors.fill: parent + onClicked: parent.triggered() + } +} diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/Comparison.qml b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/Comparison.qml new file mode 100644 index 0000000..43b10d4 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/Comparison.qml @@ -0,0 +1,75 @@ +import Qt 4.7 + +Item{ + width: 1000 + height:800 + Row{ + spacing: 4 + Button{ + caption: "run" + onTriggered: test.runTest() + } + + Button{ + caption: "update" + onTriggered: test.updateVisuals() + } + + Button{ + caption: "platform" + onTriggered: test.updatePlatformVisuals() + } + } + + Rectangle { + y: 180 + width: 1000 + height: 620 + Row{ + id: grid + spacing: 4 + Text{ + width: 300 + height: 200 + text: test.testName + clip: true; wrapMode: Text.WordWrap + } + Text{ + width: 300 + height: 200 + text: test.testCase + clip: true; wrapMode: Text.WordWrap + } + Text{ + width: 300 + height: 200 + text: test.testScript + clip: true; wrapMode: Text.WordWrap + } + } + Item{ + y: 200 + Row{ + ListView{ + width: 200; height: 400 + delegate: Rectangle{ width: 200; height: 200; color: "blue"; Image{ source: modelData }} + model: test.goodImages; + } + ListView{ + width: 200; height: 400 + delegate: Rectangle{ width: 200; height: 200; color: "blue"; Image{ source: modelData }} + model: test.diffImages; + } + ListView{ + width: 200; height: 400 + delegate: Rectangle{ width: 200; height: 200; color: "blue"; Image{ source: modelData }} + model: test.badImages; + } + } + } + MouseArea{ + anchors.fill: parent + onClicked: test.moveOn(); + } + } +} diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/main.cpp b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/main.cpp new file mode 100644 index 0000000..2d35350 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/main.cpp @@ -0,0 +1,14 @@ +#include <QtGui/QApplication> +#include <QtDeclarative> +#include "mainwindow.h" +#include <cstring> +#include <cstdio> +#include <cstdlib> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow *m = new MainWindow; + m->show(); + return a.exec(); +} diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/mainwindow.cpp b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/mainwindow.cpp new file mode 100644 index 0000000..49614ec --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/mainwindow.cpp @@ -0,0 +1,74 @@ +#include "mainwindow.h" +#include <QMessageBox> +#include <QDebug> + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), testIdx(-1) +{ + createMenus(); + view = new QDeclarativeView(this); + setCentralWidget(view); + view->setResizeMode(QDeclarativeView::SizeViewToRootObject); + curTest = new TestModel(this); + connect(curTest, SIGNAL(moveOn()), + this, SLOT(runTests())); + + view->engine()->rootContext()->setContextProperty("test", curTest); + view->setSource(QUrl("qrc:qml/Comparison.qml")); +} + +void MainWindow::runAllTests() +{ + tests.clear(); + testIdx = 0; + + QString visualTest = "./tst_qmlvisual";//TODO: Crossplatform + + QProcess p;//TODO: Error checking here + p.setProcessChannelMode(QProcess::MergedChannels); + p.start(visualTest, QStringList()); + p.waitForFinished(-1);//Can't time out, because it takes an indeterminate and long time + + QString output = QString(p.readAllStandardOutput()); + QRegExp re("QDeclarativeTester\\( \"([^\"]*)\" \\)"); + int offset=0; + while((offset = re.indexIn(output, offset)) != -1){ + tests << re.cap(1); + offset++; + } + + if(tests.count()) + QMessageBox::information(this, "Test Results", QString("Tests completed. %1 test failures occurred.").arg(tests.count())); + else + QMessageBox::information(this, "Test Results", "Tests completed. All tests passed!"); + + runTests(); +} + +void MainWindow::runTests() +{ + if(testIdx >= tests.size()) + testIdx = -1; + if(testIdx == -1) + return; + showFixScreen(tests[testIdx++]); +} + +void MainWindow::showFixScreen(const QString &path) +{ + if(curTest->setTest(path)){ + view->engine()->rootContext()->setContextProperty("test", curTest); //signal connects to runTests + }else{ + QMessageBox::critical(this, "Test Error", QString("Cannot find test %1.").arg(path)); + runTests(); + } +} + +void MainWindow::createMenus() +{ + QMenu *tests = this->menuBar()->addMenu("Tests"); + tests->addAction("Run All", this, SLOT(runAllTests())); + tests->addSeparator(); + tests->addAction("About Qt...", qApp, SLOT(aboutQt())); + tests->addAction("Quit", qApp, SLOT(quit())); +} diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/mainwindow.h b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/mainwindow.h new file mode 100644 index 0000000..0209064 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/mainwindow.h @@ -0,0 +1,31 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QtDeclarative> +#include <QtGui> +#include <QtCore> +#include "testmodel.h" + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + explicit MainWindow(QWidget *parent = 0); + void createMenus(); + +signals: + +public slots: + void runTests(); + void runAllTests(); + void showFixScreen(const QString& path); + +private: + QDeclarativeView* view; + TestModel *curTest; + QStringList tests; + int testIdx; +}; + +#endif // MAINWINDOW_H diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/qmlvisual.pro b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/qmlvisual.pro new file mode 100644 index 0000000..d18c235 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/qmlvisual.pro @@ -0,0 +1,26 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-11-19T09:48:39 +# +#------------------------------------------------- + +QT += core gui declarative + +TARGET = ../../qmlvisualaids +TEMPLATE = app + + +SOURCES += main.cpp \ + testmodel.cpp \ + mainwindow.cpp + +HEADERS += \ + testmodel.h \ + mainwindow.h + +OTHER_FILES += \ + Comparison.qml \ + Button.qml + +RESOURCES += \ + qmlvisual.qrc diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/qmlvisual.qrc b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/qmlvisual.qrc new file mode 100644 index 0000000..d79b64c --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/qmlvisual.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/qml" lang="qml"> + <file>Comparison.qml</file> + <file>Button.qml</file> + </qresource> +</RCC> diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/testmodel.cpp b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/testmodel.cpp new file mode 100644 index 0000000..4aec14b --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/testmodel.cpp @@ -0,0 +1,96 @@ +#include "testmodel.h" +#include <QProcess> +#include <QDebug> +#include <QFile> + +TestModel::TestModel(QObject *parent) : + QObject(parent), _testName("Invalid") +{ + +} + +//testPath is the path to the test script, and assumes the file under test has the same name and is in the dir above +bool TestModel::setTest(const QString &testPath) +{ + _good.clear(); + _bad.clear(); + _diff.clear(); + + _testScriptPath = testPath; + if(!_testScriptPath.endsWith(".qml")) + _testScriptPath += ".qml"; + _testName = _testScriptPath.split('/').last(); + + //Assumed that the test case is in the directory above and has the same name as the script + _testPath = _testScriptPath.left(_testScriptPath.lastIndexOf('/', _testScriptPath.lastIndexOf('/') - 1)) + + '/' + _testName; + + bool ret = QFile::exists(_testPath) && QFile::exists(_testScriptPath); + if(!ret) + return ret; + + QFile test(_testPath); + test.open(QFile::ReadOnly | QFile::Text); + _testCase = test.readAll(); + + QFile script(_testScriptPath); + script.open(QFile::ReadOnly | QFile::Text); + _testScript = script.readAll(); + + QString base = _testScriptPath; + base.chop(4);//remove .qml, replace with .%1.png + base += ".%1.png"; + int c = 0; + while (QFile::exists(base.arg(c))) { + _good << "file://" + base.arg(c); + if(QFile::exists(base.arg(c) + ".reject.png")) + _bad << "file://" + base.arg(c) + ".reject.png"; + else + _bad << ""; + + if(QFile::exists(base.arg(c) + ".diff.png")) + _diff << "file://" + base.arg(c) + ".diff.png"; + else + _diff << ""; + + c++; + } + + return ret; +} + +//returns true iff running the test changed the failure images. +bool TestModel::runTest() +{ + launchTester("-play"); + return false;//TODO: Actually check that +} + +void TestModel::updateVisuals() +{ + launchTester("-updatevisuals"); +} + +void TestModel::updatePlatformVisuals() +{ + launchTester("-updateplatformvisuals"); +} + +void TestModel::launchTester(const QString &args) +{ + QStringList arguments; + arguments << args << _testPath; + + QString visualTest; +#if defined(Q_WS_WIN) || defined(Q_WS_S60) + visualTest = "tst_qmlvisual.exe"; +#else + visualTest = "./tst_qmlvisual"; +#endif + + QProcess p; + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.start(visualTest, arguments); + p.waitForFinished(); +} + diff --git a/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/testmodel.h b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/testmodel.h new file mode 100644 index 0000000..fd64dc2 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/shared/qmlvisualaids/testmodel.h @@ -0,0 +1,50 @@ +#ifndef TESTMODEL_H +#define TESTMODEL_H + +#include <QObject> +#include <QString> +#include <QStringList> + +class TestModel : public QObject +{ + Q_OBJECT + Q_PROPERTY(int snapshotCount READ snapshotCount CONSTANT) + Q_PROPERTY(QStringList goodImages READ goodImages CONSTANT)//List of image locatoins + Q_PROPERTY(QStringList badImages READ badImages CONSTANT) + Q_PROPERTY(QStringList diffImages READ diffImages CONSTANT) + Q_PROPERTY(QString testName READ testName CONSTANT) //The qml file name + Q_PROPERTY(QString testCase READ testCase CONSTANT) //The actual contents, not the location + Q_PROPERTY(QString testScript READ testScript CONSTANT) //The actual contents, not the location +public: + explicit TestModel(QObject *parent = 0); + bool setTest(const QString &testPath);//testPath is the path to the test script, and assumes the file under test has the same name and is in the dir above + + int snapshotCount() { return _count; } + QString testCase() { return _testCase; } + QString testName() { return _testName; } + QString testScript() {return _testScript; } + QStringList goodImages() {return _good;} + QStringList badImages() { return _bad; } + QStringList diffImages() {return _diff;} + +signals: + void moveOn(); + +public slots: + bool runTest();//returns true iff running the test changed the failure images. + void updateVisuals(); + void updatePlatformVisuals(); + +private: + void launchTester(const QString &args); + + int _count; + QStringList _good,_bad,_diff; + QString _testCase; + QString _testScript; + QString _testPath; + QString _testScriptPath; + QString _testName; +}; + +#endif // TESTMODEL_H |