diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-03-17 02:56:52 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-03-17 02:56:52 (GMT) |
commit | 20470e30d11733ada5443ff993d8518aa14737ca (patch) | |
tree | 81a53040ba43bfb378eeb1a9c4382a887ab8e467 /tests/auto/declarative | |
parent | dc829ac31694f382bf7b8a0702f73409762e36f0 (diff) | |
download | Qt-20470e30d11733ada5443ff993d8518aa14737ca.zip Qt-20470e30d11733ada5443ff993d8518aa14737ca.tar.gz Qt-20470e30d11733ada5443ff993d8518aa14737ca.tar.bz2 |
Tests for default count(), get() values should be run on the worker
list model instead of being ignored. Also do some cleaning up in the
list model.
Diffstat (limited to 'tests/auto/declarative')
3 files changed, 31 insertions, 28 deletions
diff --git a/tests/auto/declarative/qdeclarativelistmodel/data/model.qml b/tests/auto/declarative/qdeclarativelistmodel/data/model.qml index 97e3030..ebd4ebf 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/data/model.qml +++ b/tests/auto/declarative/qdeclarativelistmodel/data/model.qml @@ -4,20 +4,18 @@ Item { id: item property var model property bool done: false + property var result - function evalExpressionViaWorker(expr) { + function evalExpressionViaWorker(commands) { done = false - if (expr[expr.length-1] == ';') - expr = expr.substring(0, expr.length-1) - var cmds = expr.split(';') - - worker.sendMessage({'commands': cmds, 'model': model}) + worker.sendMessage({'commands': commands, 'model': model}) } WorkerScript { id: worker source: "script.js" onMessage: { + item.result = messageObject.result item.done = true } } diff --git a/tests/auto/declarative/qdeclarativelistmodel/data/script.js b/tests/auto/declarative/qdeclarativelistmodel/data/script.js index bfeeb8b..66a4acb 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/data/script.js +++ b/tests/auto/declarative/qdeclarativelistmodel/data/script.js @@ -1,12 +1,13 @@ WorkerScript.onMessage = function(msg) { + var result = null try { for (var i=0; i<msg.commands.length; i++) { var c = 'msg.model.' + msg.commands[i] - eval(c) + result = eval(c) } msg.model.sync() } catch(e) { } - WorkerScript.sendMessage({'done': true}) + WorkerScript.sendMessage({'done': true, 'result': result}) } diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 95ac2c0..78e5912 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -301,34 +301,38 @@ void tst_QDeclarativeListModel::dynamic_worker() 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)); + QVariantList operations; + foreach (const QString &s, script.split(';')) { + if (!s.isEmpty()) + operations << s; + } if (!warning.isEmpty()) QTest::ignoreMessage(QtWarningMsg, warning.toLatin1()); - if (!scriptWithoutFinalTest.isEmpty()) { + if (operations.count() == 1) { + // test count(), get() return the correct default values in the worker list model + QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", + Q_ARG(QVariant, operations))); + waitForWorker(item); + QCOMPARE(QDeclarativeProperty(item, "result").read().toInt(), result); + } else { + // execute a set of commands on the worker list model, then check the + // changes are reflected in the list model in the main thread 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))); + QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", + Q_ARG(QVariant, operations.mid(0, operations.length()-1)))); 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(); + QDeclarativeExpression e(eng.rootContext(), operations.last().toString(), &model); + if (QByteArray(QTest::currentDataTag()).startsWith("nested")) + QVERIFY(e.value().toInt() != result); + else + QCOMPARE(e.value().toInt(), result); + } + delete item; QTest::ignoreMessage(QtWarningMsg, "QThread: Destroyed while thread is still running"); qApp->processEvents(); } @@ -354,7 +358,7 @@ void tst_QDeclarativeListModel::convertNestedToFlat_fail() 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); + waitForWorker(item); QCOMPARE(model.count(), 2); |