summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-03-03 03:06:33 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-03-03 03:06:33 (GMT)
commit070601edc397b9cebc8bffd3f1a18da9a5180b21 (patch)
treeb90bad60361766958f3fc5d5ebc7369eddcd714e /tests/auto
parenta2bddc74ca9d0c09f7c79077e0fbd981f1e9eccb (diff)
parent5d4eeb039e92a3e2ac9b31f91a4274e3d5aea459 (diff)
downloadQt-070601edc397b9cebc8bffd3f1a18da9a5180b21.zip
Qt-070601edc397b9cebc8bffd3f1a18da9a5180b21.tar.gz
Qt-070601edc397b9cebc8bffd3f1a18da9a5180b21.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/declarative.pro2
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/script.js5
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml27
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro9
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp184
5 files changed, 227 insertions, 0 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 4ee6d8c..99a32d9 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/declarative/declarative.pro
@@ -56,6 +56,8 @@ SUBDIRS += \
qdeclarativexmllistmodel \ # Cover
qpacketprotocol \ # Cover
qdeclarativerepeater \ # Cover
+ qdeclarativeworkerscript \ # Cover
+ qdeclarativeworkerlistmodel \ # Cover
qdeclarativevaluetypes \ # Cover
qdeclarativexmlhttprequest \ # Cover
qdeclarativeimageprovider \ # Cover
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js
new file mode 100644
index 0000000..09199de
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js
@@ -0,0 +1,5 @@
+WorkerScript.onMessage = function(msg) {
+ WorkerScript.sendMessage(msg)
+}
+
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml
new file mode 100644
index 0000000..2982010
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml
@@ -0,0 +1,27 @@
+import Qt 4.6
+
+WorkerScript {
+ id: worker
+ source: "script.js"
+
+ property bool done : false
+ property var response
+
+ function testSend(value) {
+ worker.sendMessage(value)
+ }
+
+ function testSendLiteral(value) {
+ eval('worker.sendMessage(' + value +')')
+ }
+
+ function compareLiteralResponse(expected) {
+ var e = eval('(' + expected + ')')
+ return worker.response == e
+ }
+
+ onMessage: {
+ worker.done = true
+ worker.response = messageObject
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro b/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro
new file mode 100644
index 0000000..0543ff6
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro
@@ -0,0 +1,9 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative
+QT += script
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qdeclarativeworkerscript.cpp
+
+# Define SRCDIR equal to test's source directory
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
new file mode 100644
index 0000000..841a0ee
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
@@ -0,0 +1,184 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <QtCore/qdebug.h>
+#include <QtScript/qscriptengine.h>
+
+#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtDeclarative/qdeclarativeengine.h>
+#include <QtDeclarative/qdeclarativeitem.h>
+
+#include <private/qdeclarativeworkerscript_p.h>
+#include "../../../shared/util.h"
+
+Q_DECLARE_METATYPE(QList<QObject*>)
+Q_DECLARE_METATYPE(QScriptValue)
+
+class tst_QDeclarativeWorkerScript : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QDeclarativeWorkerScript() {}
+private slots:
+ void source();
+ void source_data();
+ void messaging();
+ void messaging_data();
+ void messaging_sendQObjectList();
+ void messaging_sendJsObject();
+
+private:
+ void waitForEchoMessage(QDeclarativeWorkerScript *worker) {
+ const QMetaObject *mo = worker->metaObject();
+ int index = mo->indexOfProperty("done");
+ QVERIFY(index >= 0);
+ QTRY_COMPARE(mo->property(index).read(worker).toBool(), true);
+ QTRY_COMPARE(mo->property(mo->indexOfProperty("done")).read(worker).toBool(), true);
+ }
+
+ QDeclarativeEngine m_engine;
+};
+
+void tst_QDeclarativeWorkerScript::source()
+{
+ QFETCH(QUrl, source);
+ QFETCH(bool, valid);
+
+ QDeclarativeComponent component(&m_engine);
+ component.setData("import Qt 4.6\nWorkerScript { source: '" + source.toString().toUtf8() + "'; }", QUrl());
+
+ if (!valid) {
+ QByteArray w = "WorkerScript: Cannot find source file \"" + source.toString().toUtf8() + "\"";
+ QTest::ignoreMessage(QtWarningMsg, w.constData());
+ }
+ QDeclarativeWorkerScript *item = qobject_cast<QDeclarativeWorkerScript*>(component.create());
+ QVERIFY(item != 0);
+
+ QCOMPARE(item->source(), source);
+
+ qApp->processEvents();
+}
+
+void tst_QDeclarativeWorkerScript::source_data()
+{
+ QTest::addColumn<QUrl>("source");
+ QTest::addColumn<bool>("valid");
+
+ QTest::newRow("valid") << QUrl::fromLocalFile(SRCDIR "/data/worker.qml") << true;
+ QTest::newRow("invalid") << QUrl("file:///asdjfk.js") << false;
+}
+
+void tst_QDeclarativeWorkerScript::messaging()
+{
+ QFETCH(QVariant, value);
+
+ QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml");
+ QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+ waitForEchoMessage(worker);
+
+ const QMetaObject *mo = worker->metaObject();
+ QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value<QVariant>(), value);
+
+ qApp->processEvents();
+}
+
+void tst_QDeclarativeWorkerScript::messaging_data()
+{
+ QTest::addColumn<QVariant>("value");
+
+ QTest::newRow("invalid") << QVariant();
+ QTest::newRow("bool") << qVariantFromValue(true);
+ QTest::newRow("int") << qVariantFromValue(1001);
+ QTest::newRow("real") << qVariantFromValue(10334.323);
+ QTest::newRow("string") << qVariantFromValue(QString("More cheeeese, Gromit!"));
+ QTest::newRow("variant list") << qVariantFromValue((QVariantList() << "a" << "b" << "c"));
+}
+
+void tst_QDeclarativeWorkerScript::messaging_sendQObjectList()
+{
+ // Not allowed to send QObjects other than QDeclarativeWorkerListModelAgent
+ // instances. If objects are sent in a list, they will be sent as 'undefined'
+ // js values.
+
+ QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml");
+ QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QVariantList objects;
+ for (int i=0; i<3; i++)
+ objects << qVariantFromValue(new QObject(this));
+
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, qVariantFromValue(objects))));
+ waitForEchoMessage(worker);
+
+ const QMetaObject *mo = worker->metaObject();
+ QVariantList result = mo->property(mo->indexOfProperty("response")).read(worker).value<QVariantList>();
+ QCOMPARE(result, (QVariantList() << QVariant() << QVariant() << QVariant()));
+
+ qApp->processEvents();
+}
+
+void tst_QDeclarativeWorkerScript::messaging_sendJsObject()
+{
+ QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml");
+ QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QString jsObject = "{'spell power': 3101, 'haste': 1125}";
+
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSendLiteral", Q_ARG(QVariant, jsObject)));
+ waitForEchoMessage(worker);
+
+ QVariant result = qVariantFromValue(false);
+ QVERIFY(QMetaObject::invokeMethod(worker, "compareLiteralResponse", Qt::DirectConnection,
+ Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, jsObject)));
+ QVERIFY(result.toBool());
+
+ qApp->processEvents();
+}
+
+QTEST_MAIN(tst_QDeclarativeWorkerScript)
+
+#include "tst_qdeclarativeworkerscript.moc"
+