/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
** This file is part of the test suite of the Qt Toolkit.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <private/qdeclarativeworkerscript_p.h>
#include <private/qdeclarativeengine_p.h>
-#include "../shared/util.h"
-#include "../../../shared/util.h"
-
-inline QUrl TEST_FILE(const QString &filename)
-{
- return QUrl::fromLocalFile(TESTDATA(filename));
-}
+#include "../../shared/util.h"
-
-class tst_QDeclarativeWorkerScript : public QObject
+class tst_QDeclarativeWorkerScript : public QDeclarativeDataTest
{
Q_OBJECT
public:
void messaging_data();
void messaging_sendQObjectList();
void messaging_sendJsObject();
+ void messaging_sendExternalObject();
void script_with_pragma();
void script_included();
void scriptError_onLoad();
void tst_QDeclarativeWorkerScript::source()
{
- QDeclarativeComponent component(&m_engine, TESTDATA("worker.qml"));
+ QDeclarativeComponent component(&m_engine, testFileUrl("worker.qml"));
QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
QVERIFY(worker != 0);
const QMetaObject *mo = worker->metaObject();
waitForEchoMessage(worker);
QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value<QVariant>(), value);
- QUrl source = QUrl::fromLocalFile(TESTDATA("script_fixed_return.js"));
+ QUrl source = testFileUrl("script_fixed_return.js");
worker->setSource(source);
QCOMPARE(worker->source(), source);
QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
{
QFETCH(QVariant, value);
- QDeclarativeComponent component(&m_engine, TESTDATA("worker.qml"));
+ QDeclarativeComponent component(&m_engine, testFileUrl("worker.qml"));
QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
QVERIFY(worker != 0);
// instances. If objects are sent in a list, they will be sent as 'undefined'
// js values.
- QDeclarativeComponent component(&m_engine, TESTDATA("worker.qml"));
+ QDeclarativeComponent component(&m_engine, testFileUrl("worker.qml"));
QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
QVERIFY(worker != 0);
void tst_QDeclarativeWorkerScript::messaging_sendJsObject()
{
- QDeclarativeComponent component(&m_engine, TESTDATA("worker.qml"));
+ QDeclarativeComponent component(&m_engine, testFileUrl("worker.qml"));
QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
QVERIFY(worker != 0);
delete worker;
}
+void tst_QDeclarativeWorkerScript::messaging_sendExternalObject()
+{
+ QDeclarativeComponent component(&m_engine, testFileUrl("externalObjectWorker.qml"));
+ QObject *obj = component.create();
+ QVERIFY(obj);
+ QMetaObject::invokeMethod(obj, "testExternalObject");
+ QTest::qWait(100); // shouldn't crash.
+ delete obj;
+}
+
void tst_QDeclarativeWorkerScript::script_with_pragma()
{
QVariant value(100);
- QDeclarativeComponent component(&m_engine, TESTDATA("worker_pragma.qml"));
+ QDeclarativeComponent component(&m_engine, testFileUrl("worker_pragma.qml"));
QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
QVERIFY(worker != 0);
void tst_QDeclarativeWorkerScript::script_included()
{
- QDeclarativeComponent component(&m_engine, TESTDATA("worker_include.qml"));
+ QDeclarativeComponent component(&m_engine, testFileUrl("worker_include.qml"));
QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
QVERIFY(worker != 0);
void tst_QDeclarativeWorkerScript::scriptError_onLoad()
{
- QDeclarativeComponent component(&m_engine, TESTDATA("worker_error_onLoad.qml"));
+ QDeclarativeComponent component(&m_engine, testFileUrl("worker_error_onLoad.qml"));
QtMsgHandler previousMsgHandler = qInstallMsgHandler(qdeclarativeworkerscript_warningsHandler);
QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
QVERIFY(worker != 0);
QTRY_COMPARE(qdeclarativeworkerscript_lastWarning,
- TEST_FILE("script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Unexpected identifier"));
+ testFileUrl("script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Unexpected identifier"));
qInstallMsgHandler(previousMsgHandler);
qApp->processEvents();
void tst_QDeclarativeWorkerScript::scriptError_onCall()
{
- QDeclarativeComponent component(&m_engine, TESTDATA("worker_error_onCall.qml"));
+ QDeclarativeComponent component(&m_engine, testFileUrl("worker_error_onCall.qml"));
QDeclarativeWorkerScript *worker = qobject_cast<QDeclarativeWorkerScript*>(component.create());
QVERIFY(worker != 0);
QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
QTRY_COMPARE(qdeclarativeworkerscript_lastWarning,
- TEST_FILE("script_error_onCall.js").toString() + QLatin1String(":4: ReferenceError: Can't find variable: getData"));
+ testFileUrl("script_error_onCall.js").toString() + QLatin1String(":4: ReferenceError: Can't find variable: getData"));
qInstallMsgHandler(previousMsgHandler);
qApp->processEvents();
{
for (int ii = 0; ii < 100; ++ii) {
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, TESTDATA("stressDispose.qml"));
+ QDeclarativeComponent component(&engine, testFileUrl("stressDispose.qml"));
QObject *o = component.create();
QVERIFY(o);
delete o;