summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/auto/declarative/examples/examples.pro2
-rw-r--r--tests/auto/declarative/examples/tst_examples.cpp103
-rw-r--r--tools/qml/qmlruntime.cpp28
-rw-r--r--tools/qml/qmlruntime.h5
4 files changed, 42 insertions, 96 deletions
diff --git a/tests/auto/declarative/examples/examples.pro b/tests/auto/declarative/examples/examples.pro
index b316cb9..4c32524 100644
--- a/tests/auto/declarative/examples/examples.pro
+++ b/tests/auto/declarative/examples/examples.pro
@@ -4,6 +4,8 @@ macx:CONFIG -= app_bundle
SOURCES += tst_examples.cpp
+include(../../../../tools/qml/qml.pri)
+
DEFINES += SRCDIR=\\\"$$PWD\\\"
CONFIG += parallel_test
diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp
index e62aad2..c650346 100644
--- a/tests/auto/declarative/examples/tst_examples.cpp
+++ b/tests/auto/declarative/examples/tst_examples.cpp
@@ -43,8 +43,9 @@
#include <QDir>
#include <QProcess>
#include <QDebug>
-#include <QFutureSynchronizer>
-#include <QtConcurrentRun>
+#include "qmlruntime.h"
+#include <QDeclarativeView>
+#include <QDeclarativeError>
class tst_examples : public QObject
{
@@ -53,6 +54,7 @@ public:
tst_examples();
private slots:
+ void examples_data();
void examples();
void namingConvention();
@@ -173,8 +175,6 @@ QStringList tst_examples::findQmlFiles(const QDir &d)
return rv;
}
-
-
/*
This test runs all the examples in the declarative UI source tree and ensures
that they start and exit cleanly.
@@ -182,57 +182,9 @@ that they start and exit cleanly.
Examples are any .qml files under the examples/ or demos/ directory that start
with a lower case letter.
*/
-#define THREADS 5
-
-struct Example {
-public:
- Example() : result(Unknown) {}
-
- enum Result { Pass, Unknown, Fail };
- Result result;
- QString file;
- QString qmlruntime;
-
- void run();
-};
-
-void Example::run()
+void tst_examples::examples_data()
{
- QFileInfo fi(file);
- QFileInfo dir(fi.path());
- QString script = SRCDIR "/data/"+dir.baseName()+"/"+fi.baseName();
- QFileInfo testdata(script+".qml");
- QStringList arguments;
- arguments << "-script" << (testdata.exists() ? script : QLatin1String(SRCDIR "/data/dummytest"))
- << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure"
- << file;
-#ifdef Q_WS_QWS
- arguments << "-qws";
-#endif
-
- QProcess p;
- p.start(qmlruntime, arguments);
- if (!p.waitForFinished()) {
- result = Fail;
- return;
- }
-
- if (p.exitStatus() != QProcess::NormalExit || p.exitCode() != 0)
- qWarning() << p.readAllStandardOutput() << p.readAllStandardError();
-
- if (p.exitStatus() != QProcess::NormalExit ||
- p.exitCode() != 0) {
- result = Fail;
- return;
- } else {
- result = Pass;
- return;
- }
-}
-
-void tst_examples::examples()
-{
- QThreadPool::globalInstance()->setMaxThreadCount(5);
+ QTest::addColumn<QString>("file");
QString examples = QLatin1String(SRCDIR) + "/../../../../demos/declarative/";
QString demos = QLatin1String(SRCDIR) + "/../../../../examples/declarative/";
@@ -243,38 +195,31 @@ void tst_examples::examples()
files << findQmlFiles(QDir(demos));
files << findQmlFiles(QDir(snippets));
- QList<Example> tests;
-
- for (int ii = 0; ii < files.count(); ++ii) {
- Example e;
- e.file = files.at(ii);
- e.qmlruntime = qmlruntime;
- tests << e;
- }
+ foreach (const QString &file, files)
+ QTest::newRow(qPrintable(file)) << file;
+}
- QFutureSynchronizer<void> sync;
+static void silentErrorsMsgHandler(QtMsgType, const char *)
+{
+}
- for (int ii = 0; ii < tests.count(); ++ii) {
- Example *e = &tests[ii];
- QFuture<void> r = QtConcurrent::run(e, &Example::run);
- sync.addFuture(r);
- }
+void tst_examples::examples()
+{
+ QFETCH(QString, file);
- sync.waitForFinished();
+ QDeclarativeViewer viewer;
- QStringList failures;
- for (int ii = 0; ii < tests.count(); ++ii) {
- if (tests.at(ii).result != Example::Pass)
- failures << QDir::cleanPath(tests.at(ii).file);
- }
+ QtMsgHandler old = qInstallMsgHandler(silentErrorsMsgHandler);
+ QVERIFY(viewer.open(file));
+ qInstallMsgHandler(old);
- if (failures.count()) {
- QString error("Failed examples: ");
- error += failures.join(", ");
+ if (viewer.view()->status() == QDeclarativeView::Error)
+ qWarning() << viewer.view()->errors();
- QFAIL(qPrintable(error));
- }
+ QCOMPARE(viewer.view()->status(), QDeclarativeView::Ready);
+ viewer.show();
+ QTest::qWaitForWindowShown(&viewer);
}
QTEST_MAIN(tst_examples)
diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp
index 0a0ad9b..53409c1 100644
--- a/tools/qml/qmlruntime.cpp
+++ b/tools/qml/qmlruntime.cpp
@@ -550,6 +550,11 @@ QMenuBar *QDeclarativeViewer::menuBar() const
return mb;
}
+QDeclarativeView *QDeclarativeViewer::view() const
+{
+ return canvas;
+}
+
void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu)
{
QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu;
@@ -888,24 +893,19 @@ void QDeclarativeViewer::addPluginPath(const QString& plugin)
void QDeclarativeViewer::reload()
{
- openQml(currentFileOrUrl);
-}
-
-void QDeclarativeViewer::open(const QString& doc)
-{
- openQml(doc);
+ open(currentFileOrUrl);
}
void QDeclarativeViewer::openFile()
{
QString cur = canvas->source().toLocalFile();
if (useQmlFileBrowser) {
- openQml("qrc:/content/Browser.qml");
+ open("qrc:/content/Browser.qml");
} else {
QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)"));
if (!fileName.isEmpty()) {
QFileInfo fi(fileName);
- openQml(fi.absoluteFilePath());
+ open(fi.absoluteFilePath());
}
}
}
@@ -935,10 +935,10 @@ void QDeclarativeViewer::statusChanged()
void QDeclarativeViewer::launch(const QString& file_or_url)
{
- QMetaObject::invokeMethod(this, "openQml", Qt::QueuedConnection, Q_ARG(QString, file_or_url));
+ QMetaObject::invokeMethod(this, "open", Qt::QueuedConnection, Q_ARG(QString, file_or_url));
}
-void QDeclarativeViewer::openQml(const QString& file_or_url)
+bool QDeclarativeViewer::open(const QString& file_or_url)
{
currentFileOrUrl = file_or_url;
@@ -971,7 +971,7 @@ void QDeclarativeViewer::openQml(const QString& file_or_url)
if (fi.exists()) {
if (fi.suffix().toLower() != QLatin1String("qml")) {
qWarning() << "qml cannot open non-QML file" << fileName;
- return;
+ return false;
}
QDir dir(fi.path()+"/dummydata", "*.qml");
@@ -1002,7 +1002,7 @@ void QDeclarativeViewer::openQml(const QString& file_or_url)
}
} else {
qWarning() << "qml cannot find file:" << fileName;
- return;
+ return false;
}
}
@@ -1013,9 +1013,7 @@ void QDeclarativeViewer::openQml(const QString& file_or_url)
qWarning() << "Wall startup time:" << t.elapsed();
-#ifdef QTOPIA
- show();
-#endif
+ return true;
}
void QDeclarativeViewer::startNetwork()
diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h
index 8792d0c..2089dda 100644
--- a/tools/qml/qmlruntime.h
+++ b/tools/qml/qmlruntime.h
@@ -105,10 +105,11 @@ public:
QMenuBar *menuBar() const;
+ QDeclarativeView *view() const;
+
public slots:
void sceneResized(QSize size);
- void open(const QString&);
- void openQml(const QString&);
+ bool open(const QString&);
void openFile();
void reload();
void takeSnapShot();