summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/data/model.qml24
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/data/script.js12
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/qdeclarativelistmodel.pro3
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp235
-rw-r--r--tests/auto/declarative/qdeclarativeworkerlistmodel/data/model.qml14
-rw-r--r--tests/auto/declarative/qdeclarativeworkerlistmodel/data/script.js6
-rw-r--r--tests/auto/declarative/qdeclarativeworkerlistmodel/qdeclarativeworkerlistmodel.pro9
-rw-r--r--tests/auto/declarative/qdeclarativeworkerlistmodel/tst_qdeclarativeworkerlistmodel.cpp193
8 files changed, 258 insertions, 238 deletions
diff --git a/tests/auto/declarative/qdeclarativelistmodel/data/model.qml b/tests/auto/declarative/qdeclarativelistmodel/data/model.qml
new file mode 100644
index 0000000..97e3030
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistmodel/data/model.qml
@@ -0,0 +1,24 @@
+import Qt 4.6
+
+Item {
+ id: item
+ property var model
+ property bool done: false
+
+ function evalExpressionViaWorker(expr) {
+ done = false
+ if (expr[expr.length-1] == ';')
+ expr = expr.substring(0, expr.length-1)
+ var cmds = expr.split(';')
+
+ worker.sendMessage({'commands': cmds, 'model': model})
+ }
+
+ WorkerScript {
+ id: worker
+ source: "script.js"
+ onMessage: {
+ item.done = true
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativelistmodel/data/script.js b/tests/auto/declarative/qdeclarativelistmodel/data/script.js
new file mode 100644
index 0000000..bfeeb8b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistmodel/data/script.js
@@ -0,0 +1,12 @@
+WorkerScript.onMessage = function(msg) {
+ try {
+ for (var i=0; i<msg.commands.length; i++) {
+ var c = 'msg.model.' + msg.commands[i]
+ eval(c)
+ }
+ msg.model.sync()
+ } catch(e) { }
+ WorkerScript.sendMessage({'done': true})
+}
+
+
diff --git a/tests/auto/declarative/qdeclarativelistmodel/qdeclarativelistmodel.pro b/tests/auto/declarative/qdeclarativelistmodel/qdeclarativelistmodel.pro
index d728d08..8813242 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/qdeclarativelistmodel.pro
+++ b/tests/auto/declarative/qdeclarativelistmodel/qdeclarativelistmodel.pro
@@ -4,3 +4,6 @@ QT += script
macx:CONFIG -= app_bundle
SOURCES += tst_qdeclarativelistmodel.cpp
+
+# Define SRCDIR equal to test's source directory
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
index 1b59608..95ac2c0 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
@@ -39,10 +39,15 @@
**
****************************************************************************/
#include <qtest.h>
+#include <QtDeclarative/private/qdeclarativeitem_p.h>
#include <QtDeclarative/private/qdeclarativelistmodel_p.h>
#include <QtDeclarative/private/qdeclarativeexpression_p.h>
#include <QDeclarativeComponent>
-#include <QDebug>
+
+#include <QtCore/qtimer.h>
+#include <QtCore/qdebug.h>
+
+#include "../../../shared/util.h"
class tst_QDeclarativeListModel : public QObject
{
@@ -50,6 +55,11 @@ class tst_QDeclarativeListModel : public QObject
public:
tst_QDeclarativeListModel() {}
+private:
+ QScriptValue nestedListValue(QScriptEngine *eng) const;
+ QDeclarativeItem *createWorkerTest(QDeclarativeEngine *eng, QDeclarativeComponent *component, QDeclarativeListModel *model);
+ void waitForWorker(QDeclarativeItem *item);
+
private slots:
void static_types();
void static_types_data();
@@ -58,10 +68,50 @@ private slots:
void static_nestedElements_data();
void dynamic_data();
void dynamic();
+ void dynamic_worker_data();
+ void dynamic_worker();
+ void convertNestedToFlat_fail();
+ void convertNestedToFlat_fail_data();
+ void convertNestedToFlat_ok();
+ void convertNestedToFlat_ok_data();
void error_data();
void error();
};
+QScriptValue tst_QDeclarativeListModel::nestedListValue(QScriptEngine *eng) const
+{
+ QScriptValue list = eng->newArray();
+ list.setProperty(0, eng->newObject());
+ list.setProperty(1, eng->newObject());
+ QScriptValue sv = eng->newObject();
+ sv.setProperty("foo", list);
+ return sv;
+}
+
+QDeclarativeItem *tst_QDeclarativeListModel::createWorkerTest(QDeclarativeEngine *eng, QDeclarativeComponent *component, QDeclarativeListModel *model)
+{
+ QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component->create());
+ QDeclarativeEngine::setContextForObject(model, eng->rootContext());
+ if (item)
+ item->setProperty("model", qVariantFromValue(model));
+ return item;
+}
+
+void tst_QDeclarativeListModel::waitForWorker(QDeclarativeItem *item)
+{
+ QEventLoop loop;
+ QTimer timer;
+ timer.setSingleShot(true);
+ connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+
+ QDeclarativeProperty prop(item, "done");
+ QVERIFY(prop.isValid());
+ QVERIFY(prop.connectNotifySignal(&loop, SLOT(quit())));
+ timer.start(10000);
+ loop.exec();
+ QVERIFY(timer.isActive());
+}
+
void tst_QDeclarativeListModel::static_i18n()
{
QString expect = QString::fromUtf8("na\303\257ve");
@@ -149,10 +199,10 @@ void tst_QDeclarativeListModel::dynamic_data()
QTest::newRow("remove2b") << "{append({'foo':123});append({'foo':456});remove(0);get(0).foo}" << 456 << "";
QTest::newRow("remove2c") << "{append({'foo':123});append({'foo':456});remove(1);get(0).foo}" << 123 << "";
QTest::newRow("remove3") << "{append({'foo':123});remove(0);get(0).foo}" << 0 << "QML ListModel (unknown location) get: index 0 out of range";
- QTest::newRow("remove3a") << "{append({'foo':123});remove(-1)}" << 0 << "QML ListModel (unknown location) remove: index -1 out of range";
+ QTest::newRow("remove3a") << "{append({'foo':123});remove(-1);count}" << 1 << "QML ListModel (unknown location) remove: index -1 out of range";
QTest::newRow("remove4a") << "{remove(0)}" << 0 << "QML ListModel (unknown location) remove: index 0 out of range";
- QTest::newRow("remove4b") << "{append({'foo':123});remove(0);remove(0)}" << 0 << "QML ListModel (unknown location) remove: index 0 out of range";
- QTest::newRow("remove4c") << "{append({'foo':123});remove(1)}" << 0 << "QML ListModel (unknown location) remove: index 1 out of range";
+ QTest::newRow("remove4b") << "{append({'foo':123});remove(0);remove(0);count}" << 0 << "QML ListModel (unknown location) remove: index 0 out of range";
+ QTest::newRow("remove4c") << "{append({'foo':123});remove(1);count}" << 1 << "QML ListModel (unknown location) remove: index 1 out of range";
QTest::newRow("insert1") << "{insert(0,{'foo':123});count}" << 1 << "";
QTest::newRow("insert2") << "{insert(1,{'foo':123});count}" << 0 << "QML ListModel (unknown location) insert: index 1 out of range";
@@ -161,7 +211,7 @@ void tst_QDeclarativeListModel::dynamic_data()
QTest::newRow("insert3c") << "{append({'foo':123});insert(1,{'foo':456});get(1).foo}" << 456 << "";
QTest::newRow("insert3d") << "{append({'foo':123});insert(0,{'foo':456});get(0).foo}" << 456 << "";
QTest::newRow("insert3e") << "{append({'foo':123});insert(0,{'foo':456});get(1).foo}" << 123 << "";
- QTest::newRow("insert4") << "{append({'foo':123});insert(-1,{'foo':456})}" << 0 << "QML ListModel (unknown location) insert: index -1 out of range";
+ QTest::newRow("insert4") << "{append({'foo':123});insert(-1,{'foo':456});count}" << 1 << "QML ListModel (unknown location) insert: index -1 out of range";
QTest::newRow("insert5a") << "{insert(0,123)}" << 0 << "QML ListModel (unknown location) insert: value is not an object";
QTest::newRow("insert5b") << "{insert(0,[1,2,3])}" << 0 << "QML ListModel (unknown location) insert: value is not an object";
@@ -171,8 +221,8 @@ void tst_QDeclarativeListModel::dynamic_data()
QTest::newRow("set3b") << "{append({'foo':123,'bar':456});set(0,{'foo':999});get(0).bar}" << 456 << "";
QTest::newRow("set4a") << "{set(0,{'foo':456})}" << 0 << "QML ListModel (unknown location) set: index 0 out of range";
QTest::newRow("set4c") << "{set(-1,{'foo':456})}" << 0 << "QML ListModel (unknown location) set: index -1 out of range";
- QTest::newRow("set5a") << "{append({'foo':123,'bar':456});set(0,123)}" << 0 << "QML ListModel (unknown location) set: value is not an object";
- QTest::newRow("set5b") << "{append({'foo':123,'bar':456});set(0,[1,2,3])}" << 0 << "QML ListModel (unknown location) set: value is not an object";
+ QTest::newRow("set5a") << "{append({'foo':123,'bar':456});set(0,123);count}" << 1 << "QML ListModel (unknown location) set: value is not an object";
+ QTest::newRow("set5b") << "{append({'foo':123,'bar':456});set(0,[1,2,3]);count}" << 1 << "QML ListModel (unknown location) set: value is not an object";
QTest::newRow("set6") << "{append({'foo':123});set(1,{'foo':456});count}" << 2 << "";
QTest::newRow("setprop1") << "{append({'foo':123});setProperty(0,'foo',456);count}" << 1 << "";
@@ -181,7 +231,7 @@ void tst_QDeclarativeListModel::dynamic_data()
QTest::newRow("setprop3b") << "{append({'foo':123,'bar':456});setProperty(0,'foo',999);get(0).bar}" << 456 << "";
QTest::newRow("setprop4a") << "{setProperty(0,'foo',456)}" << 0 << "QML ListModel (unknown location) set: index 0 out of range";
QTest::newRow("setprop4b") << "{setProperty(-1,'foo',456)}" << 0 << "QML ListModel (unknown location) set: index -1 out of range";
- QTest::newRow("setprop4c") << "{append({'foo':123,'bar':456});setProperty(1,'foo',456)}" << 0 << "QML ListModel (unknown location) set: index 1 out of range";
+ QTest::newRow("setprop4c") << "{append({'foo':123,'bar':456});setProperty(1,'foo',456);count}" << 1 << "QML ListModel (unknown location) set: index 1 out of range";
QTest::newRow("setprop5") << "{append({'foo':123,'bar':456});append({'foo':111});setProperty(1,'bar',222);get(1).bar}" << 222 << "";
QTest::newRow("move1a") << "{append({'foo':123});append({'foo':456});move(0,1,1);count}" << 2 << "";
@@ -193,16 +243,22 @@ void tst_QDeclarativeListModel::dynamic_data()
QTest::newRow("move2b") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,1,2);get(0).foo}" << 789 << "";
QTest::newRow("move2c") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,1,2);get(1).foo}" << 123 << "";
QTest::newRow("move2d") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,1,2);get(2).foo}" << 456 << "";
- QTest::newRow("move3a") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,0,3)}" << 0 << "QML ListModel (unknown location) move: out of range";
- QTest::newRow("move3b") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,-1,1)}" << 0 << "QML ListModel (unknown location) move: out of range";
- QTest::newRow("move3c") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,0,-1)}" << 0 << "QML ListModel (unknown location) move: out of range";
- QTest::newRow("move3d") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,3,1)}" << 0 << "QML ListModel (unknown location) move: out of range";
+ QTest::newRow("move3a") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,0,3);count}" << 3 << "QML ListModel (unknown location) move: out of range";
+ QTest::newRow("move3b") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,-1,1);count}" << 3 << "QML ListModel (unknown location) move: out of range";
+ QTest::newRow("move3c") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,0,-1);count}" << 3 << "QML ListModel (unknown location) move: out of range";
+ QTest::newRow("move3d") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,3,1);count}" << 3 << "QML ListModel (unknown location) move: out of range";
- // Structured model
+ // Nested models
- QTest::newRow("listprop1a") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]});count}" << 1 << "";
- QTest::newRow("listprop1b") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]});get(0).bars.get(1).a}" << 2 << "";
- QTest::newRow("listprop2a") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]});get(0).bars.append({'a':4});get(0).bars.get(3).a}" << 4 << "";
+ QTest::newRow("nested-append1") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]});count}" << 1 << "";
+ QTest::newRow("nested-append2") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]});get(0).bars.get(1).a}" << 2 << "";
+ QTest::newRow("nested-append3") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]});get(0).bars.append({'a':4});get(0).bars.get(3).a}" << 4 << "";
+
+ QTest::newRow("nested-insert") << "{append({'foo':123});insert(0,{'bars':[{'a':1},{'b':2},{'c':3}]});get(0).bars.get(0).a}" << 1 << "";
+ QTest::newRow("nested-set") << "{append({'foo':123});set(0,{'foo':[{'x':123}]});get(0).foo.get(0).x}" << 123 << "";
+
+ // XXX
+ //QTest::newRow("nested-setprop") << "{append({'foo':123});setProperty(0,'foo',[{'x':123}]);get(0).foo.get(0).x}" << 123 << "";
}
void tst_QDeclarativeListModel::dynamic()
@@ -218,6 +274,7 @@ void tst_QDeclarativeListModel::dynamic()
QDeclarativeExpression e(engine.rootContext(), script, &model);
if (!warning.isEmpty())
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1());
+
int actual = e.value().toInt();
if (e.hasError())
qDebug() << e.error(); // errors not expected
@@ -225,6 +282,152 @@ void tst_QDeclarativeListModel::dynamic()
QCOMPARE(actual,result);
}
+void tst_QDeclarativeListModel::dynamic_worker_data()
+{
+ dynamic_data();
+}
+
+void tst_QDeclarativeListModel::dynamic_worker()
+{
+ QFETCH(QString, script);
+ QFETCH(int, result);
+ QFETCH(QString, warning);
+
+ QDeclarativeListModel model;
+ QDeclarativeEngine eng;
+ QDeclarativeComponent component(&eng, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeItem *item = createWorkerTest(&eng, &component, &model);
+ QVERIFY(item != 0);
+
+ if (script[0] == QLatin1Char('{') && script[script.length()-1] == QLatin1Char('}'))
+ script = script.mid(1, script.length() - 2);
+ QString finalTest = script.split(';').last();
+ QString scriptWithoutFinalTest = script.mid(0, script.indexOf(finalTest));
+
+ if (!warning.isEmpty())
+ QTest::ignoreMessage(QtWarningMsg, warning.toLatin1());
+
+ if (!scriptWithoutFinalTest.isEmpty()) {
+ if (QByteArray(QTest::currentDataTag()).startsWith("nested"))
+ QTest::ignoreMessage(QtWarningMsg, "QML ListModel (unknown location) Cannot add nested list values when modifying or after modification from a worker script");
+ QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", Q_ARG(QVariant, scriptWithoutFinalTest)));
+ waitForWorker(item);
+ }
+
+ QDeclarativeExpression e(eng.rootContext(), finalTest, &model);
+ if (QByteArray(QTest::currentDataTag()).startsWith("nested"))
+ QVERIFY(e.value().toInt() != result);
+ else
+ QCOMPARE(e.value().toInt(), result);
+
+ QEventLoop loop;
+ QTimer timer;
+ timer.setSingleShot(true);
+ connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+ connect(item, SIGNAL(destroyed(QObject*)), &loop, SLOT(quit()));
+ timer.start(10000);
+ item->deleteLater();
+ loop.exec();
+
+ QTest::ignoreMessage(QtWarningMsg, "QThread: Destroyed while thread is still running");
+ qApp->processEvents();
+}
+
+void tst_QDeclarativeListModel::convertNestedToFlat_fail()
+{
+ // If a model has nested data, it cannot be used at all from a worker script
+
+ QFETCH(QString, script);
+
+ QDeclarativeListModel model;
+ QDeclarativeEngine eng;
+ QDeclarativeComponent component(&eng, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeItem *item = createWorkerTest(&eng, &component, &model);
+ QVERIFY(item != 0);
+
+ QScriptEngine s_eng;
+ QScriptValue plainData = s_eng.newObject();
+ plainData.setProperty("foo", QScriptValue(123));
+ model.append(plainData);
+ model.append(nestedListValue(&s_eng));
+ QCOMPARE(model.count(), 2);
+
+ QTest::ignoreMessage(QtWarningMsg, "QML ListModel (unknown location) List contains nested list values and cannot be used from a worker script");
+ QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", Q_ARG(QVariant, script)));
+ waitForWorker(item);
+
+ QCOMPARE(model.count(), 2);
+
+ delete item;
+ QTest::ignoreMessage(QtWarningMsg, "QThread: Destroyed while thread is still running");
+ qApp->processEvents();
+}
+
+void tst_QDeclarativeListModel::convertNestedToFlat_fail_data()
+{
+ QTest::addColumn<QString>("script");
+
+ QTest::newRow("clear") << "clear()";
+ QTest::newRow("remove") << "remove(0)";
+ QTest::newRow("append") << "append({'x':1})";
+ QTest::newRow("insert") << "insert(0, {'x':1})";
+ QTest::newRow("set") << "set(0, {'foo':1})";
+ QTest::newRow("setProperty") << "setProperty(0, 'foo', 1})";
+ QTest::newRow("move") << "move(0, 1, 1})";
+ QTest::newRow("get") << "get(0)";
+}
+
+void tst_QDeclarativeListModel::convertNestedToFlat_ok()
+{
+ // If a model only has plain data, it can be modified from a worker script. However,
+ // once the model is used from a worker script, it no longer accepts nested data
+
+ QFETCH(QString, script);
+
+ QDeclarativeListModel model;
+ QDeclarativeEngine eng;
+ QDeclarativeComponent component(&eng, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeItem *item = createWorkerTest(&eng, &component, &model);
+ QVERIFY(item != 0);
+
+ QScriptEngine s_eng;
+ QScriptValue plainData = s_eng.newObject();
+ plainData.setProperty("foo", QScriptValue(123));
+ model.append(plainData);
+ QCOMPARE(model.count(), 1);
+
+ QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", Q_ARG(QVariant, script)));
+ waitForWorker(item);
+
+ // can still add plain data
+ int count = model.count();
+ model.append(plainData);
+ QCOMPARE(model.count(), count+1);
+
+ QScriptValue nested = nestedListValue(&s_eng);
+ const char *warning = "QML ListModel (unknown location) Cannot add nested list values when modifying or after modification from a worker script";
+
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ model.append(nested);
+
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ model.insert(0, nested);
+
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ model.set(0, nested);
+
+ QCOMPARE(model.count(), count+1);
+
+ delete item;
+ QTest::ignoreMessage(QtWarningMsg, "QThread: Destroyed while thread is still running");
+ qApp->processEvents();
+}
+
+void tst_QDeclarativeListModel::convertNestedToFlat_ok_data()
+{
+ convertNestedToFlat_fail_data();
+}
+
void tst_QDeclarativeListModel::static_types_data()
{
QTest::addColumn<QString>("qml");
diff --git a/tests/auto/declarative/qdeclarativeworkerlistmodel/data/model.qml b/tests/auto/declarative/qdeclarativeworkerlistmodel/data/model.qml
deleted file mode 100644
index be94e00..0000000
--- a/tests/auto/declarative/qdeclarativeworkerlistmodel/data/model.qml
+++ /dev/null
@@ -1,14 +0,0 @@
-import Qt 4.6
-
-Item {
- property alias model: model
-
- WorkerListModel { id: model }
-
- function workerModifyModel(cmd) { worker.sendMessage({'command': cmd, 'model': model}) }
-
- WorkerScript {
- id: worker
- source: "script.js"
- }
-}
diff --git a/tests/auto/declarative/qdeclarativeworkerlistmodel/data/script.js b/tests/auto/declarative/qdeclarativeworkerlistmodel/data/script.js
deleted file mode 100644
index 8ee62b4..0000000
--- a/tests/auto/declarative/qdeclarativeworkerlistmodel/data/script.js
+++ /dev/null
@@ -1,6 +0,0 @@
-WorkerScript.onMessage = function(msg) {
- eval("msg.model." + msg.command)
- msg.model.sync()
-}
-
-
diff --git a/tests/auto/declarative/qdeclarativeworkerlistmodel/qdeclarativeworkerlistmodel.pro b/tests/auto/declarative/qdeclarativeworkerlistmodel/qdeclarativeworkerlistmodel.pro
deleted file mode 100644
index 960dbe1..0000000
--- a/tests/auto/declarative/qdeclarativeworkerlistmodel/qdeclarativeworkerlistmodel.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-load(qttest_p4)
-contains(QT_CONFIG,declarative): QT += declarative
-QT += script
-macx:CONFIG -= app_bundle
-
-SOURCES += tst_qdeclarativeworkerlistmodel.cpp
-
-# Define SRCDIR equal to test's source directory
-DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qdeclarativeworkerlistmodel/tst_qdeclarativeworkerlistmodel.cpp b/tests/auto/declarative/qdeclarativeworkerlistmodel/tst_qdeclarativeworkerlistmodel.cpp
deleted file mode 100644
index 11a7447..0000000
--- a/tests/auto/declarative/qdeclarativeworkerlistmodel/tst_qdeclarativeworkerlistmodel.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/****************************************************************************
-**
-** 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 <QtDeclarative/qdeclarativecomponent.h>
-#include <QtDeclarative/qdeclarativeengine.h>
-#include <QtDeclarative/qdeclarativeitem.h>
-
-#include <private/qdeclarativeworkerscript_p.h>
-#include <private/qdeclarativelistmodel_p.h>
-#include "../../../shared/util.h"
-
-
-
-class tst_QDeclarativeWorkerListModel : public QObject
-{
- Q_OBJECT
-public:
- tst_QDeclarativeWorkerListModel() {}
-private slots:
- void clear();
- void remove();
- void append();
- void insert();
- void get();
- void set();
-
-private:
- QByteArray modificationWarning() const {
- QString file = QUrl::fromLocalFile(SRCDIR "/data/model.qml").toString();
- return QString("QML WorkerListModel (" + file + ":6:5) List can only be modified from a WorkerScript").toUtf8();
- }
-
- QDeclarativeEngine m_engine;
-};
-
-void tst_QDeclarativeWorkerListModel::clear()
-{
- QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml");
- QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
- QVERIFY(item != 0);
- QDeclarativeWorkerListModel *model = item->property("model").value<QDeclarativeWorkerListModel*>();
- QVERIFY(model != 0);
-
- QCOMPARE(model->count(), 0);
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})")));
- QTRY_COMPARE(model->count(), 1);
-
- QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData());
- model->clear();
- QCOMPARE(model->count(), 1);
-
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "clear()")));
- QTRY_COMPARE(model->count(), 0);
-
- qApp->processEvents();
-}
-
-void tst_QDeclarativeWorkerListModel::remove()
-{
- QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml");
- QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
- QVERIFY(item != 0);
- QDeclarativeWorkerListModel *model = item->property("model").value<QDeclarativeWorkerListModel*>();
- QVERIFY(model != 0);
-
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})")));
- QTRY_COMPARE(model->count(), 1);
-
- QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData());
- model->remove(0);
- QCOMPARE(model->count(), 1);
-
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "remove(0)")));
- QTRY_COMPARE(model->count(), 0);
-
- qApp->processEvents();
-}
-
-void tst_QDeclarativeWorkerListModel::append()
-{
- QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml");
- QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
- QVERIFY(item != 0);
- QDeclarativeWorkerListModel *model = item->property("model").value<QDeclarativeWorkerListModel*>();
- QVERIFY(model != 0);
-
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})")));
- QTRY_COMPARE(model->count(), 1);
-
- QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData());
- model->append(QScriptValue(1));
- QCOMPARE(model->count(), 1);
-
- qApp->processEvents();
-}
-
-void tst_QDeclarativeWorkerListModel::insert()
-{
- QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml");
- QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
- QVERIFY(item != 0);
- QDeclarativeWorkerListModel *model = item->property("model").value<QDeclarativeWorkerListModel*>();
- QVERIFY(model != 0);
-
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "insert(0, {'name': 'A'})")));
- QTRY_COMPARE(model->count(), 1);
-
- QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData());
- model->insert(0, QScriptValue(1));
- QCOMPARE(model->count(), 1);
-
- qApp->processEvents();
-}
-
-void tst_QDeclarativeWorkerListModel::get()
-{
- QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml");
- QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
- QVERIFY(item != 0);
- QDeclarativeWorkerListModel *model = item->property("model").value<QDeclarativeWorkerListModel*>();
- QVERIFY(model != 0);
-
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})")));
- QTRY_COMPARE(model->count(), 1);
- QCOMPARE(model->get(0).property("name").toString(), QString("A"));
-
- qApp->processEvents();
-}
-
-void tst_QDeclarativeWorkerListModel::set()
-{
- QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml");
- QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
- QVERIFY(item != 0);
- QDeclarativeWorkerListModel *model = item->property("model").value<QDeclarativeWorkerListModel*>();
- QVERIFY(model != 0);
-
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})")));
- QTRY_COMPARE(model->count(), 1);
-
- QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData());
- model->set(0, QScriptValue(1));
-
- QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "set(0, {'name': 'Z'})")));
- QTRY_COMPARE(model->get(0).property("name").toString(), QString("Z"));
-
- qApp->processEvents();
-}
-
-QTEST_MAIN(tst_QDeclarativeWorkerListModel)
-
-#include "tst_qdeclarativeworkerlistmodel.moc"
-