diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2012-04-11 14:56:22 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2012-04-11 16:05:03 +0200 |
commit | a896d4b39ec3d45ba708d9b36ea9c864b1df2136 (patch) | |
tree | 45cfe153cce6114c2c76c48dc0bdabde2a8cf3e3 /tests/auto/qml | |
parent | 24fb8dc27eddfdd62bd2c3a6e863cbf433762cd6 (diff) | |
parent | 65bfc35429e845cf6b76d58107360a1360a654fc (diff) |
Merge remote-tracking branch 'origin/master' into api_changes
Conflicts:
src/qml/debugger/qqmlprofilerservice_p.h
src/qml/qml/qqmlboundsignal.cpp
src/qml/qml/v4/qv4bindings.cpp
src/quick/items/qquickshadereffect.cpp
src/quick/particles/qquickcustomparticle.cpp
src/quick/qtquick2.cpp
Change-Id: Ia9c6517035ae912fa75e77473a452bd3383def56
Diffstat (limited to 'tests/auto/qml')
44 files changed, 1029 insertions, 115 deletions
diff --git a/tests/auto/qml/debugger/qqmldebugclient/tst_qqmldebugclient.cpp b/tests/auto/qml/debugger/qqmldebugclient/tst_qqmldebugclient.cpp index 2d52ea9f50..036641cdfc 100644 --- a/tests/auto/qml/debugger/qqmldebugclient/tst_qqmldebugclient.cpp +++ b/tests/auto/qml/debugger/qqmldebugclient/tst_qqmldebugclient.cpp @@ -81,7 +81,6 @@ void tst_QQmlDebugClient::initTestCase() QQmlDebugTestClient client("tst_QQmlDebugClient::handshake()", m_conn); QQmlDebugTestService service("tst_QQmlDebugClient::handshake()"); - QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Connection established."); for (int i = 0; i < 50; ++i) { // try for 5 seconds ... m_conn->connectToHost("127.0.0.1", PORT); @@ -173,7 +172,6 @@ void tst_QQmlDebugClient::sequentialConnect() QTest::qWait(100); connection2.connectToHost("127.0.0.1", PORT); - QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Connection established."); QVERIFY(connection2.waitForConnected()); QVERIFY(connection2.isConnected()); QTRY_VERIFY(client2.state() == QQmlDebugClient::Enabled); diff --git a/tests/auto/qml/debugger/qqmldebugservice/tst_qqmldebugservice.cpp b/tests/auto/qml/debugger/qqmldebugservice/tst_qqmldebugservice.cpp index 8eb1523af9..12acb9feae 100644 --- a/tests/auto/qml/debugger/qqmldebugservice/tst_qqmldebugservice.cpp +++ b/tests/auto/qml/debugger/qqmldebugservice/tst_qqmldebugservice.cpp @@ -81,8 +81,6 @@ void tst_QQmlDebugService::initTestCase() m_conn = new QQmlDebugConnection(this); - - QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Connection established."); for (int i = 0; i < 50; ++i) { // try for 5 seconds ... m_conn->connectToHost("127.0.0.1", PORT); diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp index 9639a36065..0c5dfddffa 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp @@ -50,12 +50,14 @@ struct QmlObjectData { QString objectType; int objectId; int contextId; + int parentId; }; QDataStream &operator>>(QDataStream &ds, QmlObjectData &data) { ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString - >> data.objectName >> data.objectType >> data.objectId >> data.contextId; + >> data.objectName >> data.objectType >> data.objectId >> data.contextId + >> data.parentId; return ds; } diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index b66ba289ce..cc1193b0f1 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -205,7 +205,7 @@ void tst_QQmlEngineDebugService::recursiveObjectTest( // signal properties are fake - they are generated from QQmlAbstractBoundSignal children if (p.name.startsWith("on") && p.name.length() > 2 && p.name[2].isUpper()) { QString signal = p.value.toString(); - QQmlExpression *expr = QQmlPropertyPrivate::signalExpression(QQmlProperty(o, p.name)); + QQmlBoundSignalExpression *expr = QQmlPropertyPrivate::signalExpression(QQmlProperty(o, p.name)); QVERIFY(expr && expr->expression() == signal); QVERIFY(p.valueTypeName.isEmpty()); QVERIFY(p.binding.isEmpty()); @@ -328,7 +328,6 @@ void tst_QQmlEngineDebugService::initTestCase() m_conn = new QQmlDebugConnection(this); m_conn->connectToHost("127.0.0.1", 3768); - QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Connection established."); bool ok = m_conn->waitForConnected(); QVERIFY(ok); QTRY_VERIFY(QQmlDebugService::hasDebuggingClient()); diff --git a/tests/auto/qml/debugger/qv8profilerservice/tst_qv8profilerservice.cpp b/tests/auto/qml/debugger/qv8profilerservice/tst_qv8profilerservice.cpp index 497d544390..2961cedd51 100644 --- a/tests/auto/qml/debugger/qv8profilerservice/tst_qv8profilerservice.cpp +++ b/tests/auto/qml/debugger/qv8profilerservice/tst_qv8profilerservice.cpp @@ -77,8 +77,11 @@ public: V8MaximumMessage }; + enum ServiceState { NotRunning, Running } serviceState; + QV8ProfilerClient(QQmlDebugConnection *connection) : QQmlDebugClient(QLatin1String("V8Profiler"), connection) + , serviceState(NotRunning) { } @@ -165,12 +168,15 @@ void QV8ProfilerClient::messageReceived(const QByteArray &message) switch (messageType) { case QV8ProfilerClient::V8Entry: { + QCOMPARE(serviceState, Running); QV8ProfilerData entry; stream >> entry.filename >> entry.functionname >> entry.lineNumber >> entry.totalTime >> entry.selfTime >> entry.treeLevel; traceMessages.append(entry); break; } case QV8ProfilerClient::V8Complete: + QCOMPARE(serviceState, Running); + serviceState = NotRunning; emit complete(); break; case QV8ProfilerClient::V8SnapshotChunk: { @@ -183,6 +189,8 @@ void QV8ProfilerClient::messageReceived(const QByteArray &message) emit snapshot(); break; case QV8ProfilerClient::V8Started: + QCOMPARE(serviceState, NotRunning); + serviceState = Running; emit started(); break; default: @@ -208,15 +216,16 @@ void tst_QV8ProfilerService::connect(bool block, const QString &testFile) m_process = new QQmlDebugProcess(executable); m_process->start(QStringList() << arguments); if (!m_process->waitForSessionStart()) { - QString failMsg = QString("Could not launch app '%1'.\nApplication output:\n%2").arg( - executable, m_process->output()); + QString failMsg = QString("Could not launch app '%1'.").arg(executable); QFAIL(qPrintable(failMsg)); } - QQmlDebugConnection *m_connection = new QQmlDebugConnection(); + m_connection = new QQmlDebugConnection(); m_client = new QV8ProfilerClient(m_connection); m_connection->connectToHost(QLatin1String("127.0.0.1"), PORT); + if (!m_connection->waitForConnected()) + QFAIL("Could not connect to debugger port."); } void tst_QV8ProfilerService::cleanup() @@ -226,7 +235,6 @@ void tst_QV8ProfilerService::cleanup() delete m_process; delete m_connection; - delete m_client; } void tst_QV8ProfilerService::blockingConnectWithTraceEnabled() @@ -235,8 +243,6 @@ void tst_QV8ProfilerService::blockingConnectWithTraceEnabled() QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->startProfiling(""); - QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(started())), - "No start signal received in time."); m_client->stopProfiling(""); QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(complete())), "No trace received in time."); @@ -254,8 +260,6 @@ void tst_QV8ProfilerService::blockingConnectWithTraceDisabled() QFAIL(qPrintable(failMsg)); } m_client->startProfiling(""); - QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(started())), - "No start signal received in time."); m_client->stopProfiling(""); QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(complete())), "No trace received in time."); @@ -267,8 +271,6 @@ void tst_QV8ProfilerService::nonBlockingConnect() QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->startProfiling(""); - QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(started())), - "No start signal received in time."); m_client->stopProfiling(""); QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(complete())), "No trace received in time."); @@ -290,9 +292,6 @@ void tst_QV8ProfilerService::profileOnExit() QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->startProfiling(""); - QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(started())), - "No start signal received in time."); - QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(complete())), "No trace received in time."); //QVERIFY(!m_client->traceMessages.isEmpty()); @@ -305,8 +304,6 @@ void tst_QV8ProfilerService::console() m_client->stopProfiling(""); - QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(started())), - "No start signal received in time."); QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(complete())), "No trace received in time."); QVERIFY(!m_client->traceMessages.isEmpty()); diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index ac9fa5fae2..925f5372cd 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -123,7 +123,7 @@ bool QQmlDebugProcess::waitForSessionStart() qWarning() << "Could not start up " << m_executable; return false; } - m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents); + m_eventLoop.exec(); return m_started; } @@ -161,9 +161,6 @@ void QQmlDebugProcess::processAppOutput() m_eventLoop.quit(); continue; } - if (line.contains("Connection established.")) { - continue; - } } } m_mutex.unlock(); diff --git a/tests/auto/qml/qmlmin/tst_qmlmin.cpp b/tests/auto/qml/qmlmin/tst_qmlmin.cpp index 3be7919404..6f0b2e45a2 100644 --- a/tests/auto/qml/qmlmin/tst_qmlmin.cpp +++ b/tests/auto/qml/qmlmin/tst_qmlmin.cpp @@ -158,6 +158,10 @@ with a lower case letter. void tst_qmlmin::qmlMinify_data() { +#if defined(QTEST_CROSS_COMPILED) + return; +#endif + QTest::addColumn<QString>("file"); QString examples = QLatin1String(SRCDIR) + "/../../../../examples/"; @@ -173,11 +177,10 @@ void tst_qmlmin::qmlMinify_data() void tst_qmlmin::qmlMinify() { - QFETCH(QString, file); - #if defined(QTEST_CROSS_COMPILED) QSKIP("sources not available when cross compiled"); #endif + QFETCH(QString, file); QProcess qmlminify; qmlminify.start(qmlminPath, QStringList() << QLatin1String("--verify-only") << file); diff --git a/tests/auto/qml/qqmlecmascript/data/InnerObject.qml b/tests/auto/qml/qqmlecmascript/data/InnerObject.qml new file mode 100644 index 0000000000..a8ed9593d1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/InnerObject.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +QtObject { + property int foo1: 100 + property int foo2: 100 + property int foo3: { return 100; } + property int foo4: { return 100; } + + property string bar1: 'Hello' + property string bar2: 'Hello' + property string bar3: { return 'Hello'; } + property string bar4: { return 'Hello'; } +} diff --git a/tests/auto/qml/qqmlecmascript/data/OuterObject.qml b/tests/auto/qml/qqmlecmascript/data/OuterObject.qml new file mode 100644 index 0000000000..da571a9732 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/OuterObject.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + property InnerObject inner: InnerObject {} +} diff --git a/tests/auto/qml/qqmlecmascript/data/deleteLaterObjectMethodCall.qml b/tests/auto/qml/qqmlecmascript/data/deleteLaterObjectMethodCall.qml new file mode 100644 index 0000000000..d1418e57a1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deleteLaterObjectMethodCall.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + property var fn + + property var c: Component { + MyQmlObject { + function go() { + try { methodNoArgs(); } catch(e) { } + } + } + } + + Component.onCompleted: { + var f = c.createObject().go; + + gc(); + + f(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/ownershipQmlIncubated.qml b/tests/auto/qml/qqmlecmascript/data/ownershipQmlIncubated.qml new file mode 100644 index 0000000000..6f536b27ca --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ownershipQmlIncubated.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 + +Item { + id: root + + property QtObject incubatedItem + + Component.onCompleted: { + var component = Qt.createComponent("PropertyVarBaseItem.qml"); + + var incubator = component.incubateObject(root); + if (incubator.status != Component.Ready) { + incubator.onStatusChanged = function(status) { + if (status == Component.Ready) { + incubatedItem = incubator.object; + } + } + } else { + incubatedItem = incubator.object; + } + } + + function deleteIncubatedItem() { + incubatedItem.destroy(); + gc(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/replaceBinding.qml b/tests/auto/qml/qqmlecmascript/data/replaceBinding.qml new file mode 100644 index 0000000000..670231a144 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/replaceBinding.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 + +OuterObject { + property bool success: false + + inner.foo1: 200 + inner.foo2: { return 200; } + inner.foo3: 200 + inner.foo4: { return 200; } + + inner.bar1: 'Goodbye' + inner.bar2: { return 'Goodbye' } + inner.bar3: 'Goodbye' + inner.bar4: { return 'Goodbye' } + + Component.onCompleted: { + success = (inner.foo1 == 200 && + inner.foo2 == 200 && + inner.foo3 == 200 && + inner.foo4 == 200 && + inner.bar1 == 'Goodbye' && + inner.bar2 == 'Goodbye' && + inner.bar3 == 'Goodbye' && + inner.bar4 == 'Goodbye'); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/singleV8BindingDestroyedDuringEvaluation.qml b/tests/auto/qml/qqmlecmascript/data/singleV8BindingDestroyedDuringEvaluation.qml new file mode 100644 index 0000000000..ae84f028a5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/singleV8BindingDestroyedDuringEvaluation.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + MyQmlObject { + value: if (1) 3 + } + + MyQmlObject { + value: { deleteMe(), 2 } + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index b3bf92fe81..c2d490e3c5 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -135,6 +135,7 @@ private slots: void ownershipCustomReturnValue(); void ownershipRootObject(); void ownershipConsistency(); + void ownershipQmlIncubated(); void qlistqobjectMethods(); void strictlyEquals(); void compiled(); @@ -183,7 +184,7 @@ private slots: void assignSequenceTypes(); void qtbug_22464(); void qtbug_21580(); - + void singleV8BindingDestroyedDuringEvaluation(); void bug1(); void bug2(); void dynamicCreationCrash(); @@ -246,12 +247,13 @@ private slots: void invokableWithQObjectDerived(); void realTypePrecision(); void registeredFlagMethod(); - + void deleteLaterObjectMethodCall(); void automaticSemicolon(); void unaryExpression(); void switchStatement(); void withStatement(); void tryStatement(); + void replaceBinding(); private: static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -1902,6 +1904,16 @@ void tst_qqmlecmascript::qtbug_21580() delete object; } +// Causes a v8 binding, but not all v8 bindings to be destroyed during evaluation +void tst_qqmlecmascript::singleV8BindingDestroyedDuringEvaluation() +{ + QQmlComponent component(&engine, testFileUrl("singleV8BindingDestroyedDuringEvaluation.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + delete object; +} + // QTBUG-6781 void tst_qqmlecmascript::bug1() { @@ -3009,6 +3021,24 @@ void tst_qqmlecmascript::ownershipConsistency() delete object; } +void tst_qqmlecmascript::ownershipQmlIncubated() +{ + QQmlComponent component(&engine, testFileUrl("ownershipQmlIncubated.qml")); + QObject *object = component.create(); + QVERIFY(object); + + QTRY_VERIFY(object->property("incubatedItem").value<QObject*>() != 0); + + QMetaObject::invokeMethod(object, "deleteIncubatedItem"); + + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::processEvents(); + + QVERIFY(object->property("incubatedItem").value<QObject*>() == 0); + + delete object; +} + class QListQObjectMethodsObject : public QObject { Q_OBJECT @@ -6000,6 +6030,13 @@ void tst_qqmlecmascript::dynamicString() QString::fromLatin1("string:Hello World false:0 true:1 uint32:100 int32:-100 double:3.14159 date:2011-02-11 05::30:50!")); } +void tst_qqmlecmascript::deleteLaterObjectMethodCall() +{ + QQmlComponent component(&engine, testFileUrl("deleteLaterObjectMethodCall.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); +} + void tst_qqmlecmascript::automaticSemicolon() { QQmlComponent component(&engine, testFileUrl("automaticSemicolon.qml")); @@ -6408,6 +6445,18 @@ void tst_qqmlecmascript::registeredFlagMethod() delete object; } +// QTBUG-23138 +void tst_qqmlecmascript::replaceBinding() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("replaceBinding.qml")); + QObject *obj = c.create(); + QVERIFY(obj != 0); + + QVERIFY(obj->property("success").toBool()); + delete obj; +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 837a9d2604..4720269313 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -181,7 +181,7 @@ private slots: private: QQmlEngine engine; - void testType(const QString& qml, const QString& type, const QString& error); + void testType(const QString& qml, const QString& type, const QString& error, bool partialMatch = false); }; #define DETERMINE_ERRORS(errorfile,expected,actual)\ @@ -1480,7 +1480,7 @@ void tst_qqmllanguage::reservedWords() } // Check that first child of qml is of given type. Empty type insists on error. -void tst_qqmllanguage::testType(const QString& qml, const QString& type, const QString& expectederror) +void tst_qqmllanguage::testType(const QString& qml, const QString& type, const QString& expectederror, bool partialMatch) { QQmlComponent component(&engine); component.setData(qml.toUtf8(), TEST_FILE("empty.qml")); // just a file for relative local imports @@ -1495,7 +1495,7 @@ void tst_qqmllanguage::testType(const QString& qml, const QString& type, const Q actualerror.append("; "); actualerror.append(e.description()); } - QCOMPARE(actualerror,expectederror); + QCOMPARE(actualerror.left(partialMatch ? expectederror.length(): -1),expectederror); } else { VERIFY_ERRORS(0); QObject *object = component.create(); @@ -1616,13 +1616,13 @@ void tst_qqmllanguage::importsBuiltin_data() "import com.nokia.Test 1.12\n" "Test {}" << (!qmlCheckTypes()?"TestType2":"") - << (!qmlCheckTypes()?"":"Test is ambiguous. Found in com/nokia/Test in version 1.12 and 1.11"); + << (!qmlCheckTypes()?"":"Test is ambiguous. Found in com/nokia/Test/ in version 1.12 and 1.11"); QTest::newRow("multiversion 2") << "import com.nokia.Test 1.11\n" "import com.nokia.Test 1.12\n" "OldTest {}" << (!qmlCheckTypes()?"TestType":"") - << (!qmlCheckTypes()?"":"OldTest is ambiguous. Found in com/nokia/Test in version 1.12 and 1.11"); + << (!qmlCheckTypes()?"":"OldTest is ambiguous. Found in com/nokia/Test/ in version 1.12 and 1.11"); QTest::newRow("qualified multiversion 3") << "import com.nokia.Test 1.0 as T0\n" "import com.nokia.Test 1.8 as T8\n" @@ -1691,7 +1691,7 @@ void tst_qqmllanguage::importsLocal_data() "import com.nokia.Test 1.0\n" "Test {}" << (!qmlCheckTypes()?"TestType":"") - << (!qmlCheckTypes()?"":"Test is ambiguous. Found in com/nokia/Test and in subdir"); + << (!qmlCheckTypes()?"":"Test is ambiguous. Found in com/nokia/Test/ and in subdir/"); } void tst_qqmllanguage::importsLocal() @@ -1841,32 +1841,37 @@ void tst_qqmllanguage::importsOrder_data() QTest::addColumn<QString>("qml"); QTest::addColumn<QString>("type"); QTest::addColumn<QString>("error"); + QTest::addColumn<bool>("partialMatch"); QTest::newRow("double import") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.4\n" "InstalledTest {}" << (!qmlCheckTypes()?"QQuickText":"") - << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest in version 1.4 and 1.4"); + << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest/ in version 1.4 and 1.4") + << false; QTest::newRow("installed import overrides 1") << "import com.nokia.installedtest 1.0\n" "import com.nokia.installedtest 1.4\n" "InstalledTest {}" << (!qmlCheckTypes()?"QQuickText":"") - << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest in version 1.4 and 1.0"); + << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest/ in version 1.4 and 1.0") + << false; QTest::newRow("installed import overrides 2") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" << (!qmlCheckTypes()?"QQuickRectangle":"") - << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest in version 1.0 and 1.4"); + << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest/ in version 1.0 and 1.4") + << false; QTest::newRow("installed import re-overrides 1") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "import com.nokia.installedtest 1.4\n" "InstalledTest {}" << (!qmlCheckTypes()?"QQuickText":"") - << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest in version 1.4 and 1.0"); + << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest/ in version 1.4 and 1.0") + << false; QTest::newRow("installed import re-overrides 2") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" @@ -1874,41 +1879,47 @@ void tst_qqmllanguage::importsOrder_data() "import com.nokia.installedtest 1.0\n" "InstalledTest {}" << (!qmlCheckTypes()?"QQuickRectangle":"") - << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest in version 1.0 and 1.4"); - + << (!qmlCheckTypes()?"":"InstalledTest is ambiguous. Found in lib/com/nokia/installedtest/ in version 1.0 and 1.4") + << false; QTest::newRow("installed import versus builtin 1") << "import com.nokia.installedtest 1.5\n" "import QtQuick 2.0\n" "Rectangle {}" << (!qmlCheckTypes()?"QQuickRectangle":"") - << (!qmlCheckTypes()?"":"Rectangle is ambiguous. Found in Qt and in lib/com/nokia/installedtest"); + << (!qmlCheckTypes()?"":"Rectangle is ambiguous. Found in file://") + << true; QTest::newRow("installed import versus builtin 2") << "import QtQuick 2.0\n" "import com.nokia.installedtest 1.5\n" "Rectangle {}" << (!qmlCheckTypes()?"QQuickText":"") - << (!qmlCheckTypes()?"":"Rectangle is ambiguous. Found in lib/com/nokia/installedtest and in Qt"); + << (!qmlCheckTypes()?"":"Rectangle is ambiguous. Found in lib/com/nokia/installedtest/ and in file://") + << true; QTest::newRow("namespaces cannot be overridden by types 1") << "import QtQuick 2.0 as Rectangle\n" "import com.nokia.installedtest 1.5\n" "Rectangle {}" - << "" - << "Namespace Rectangle cannot be used as a type"; + << "" + << "Namespace Rectangle cannot be used as a type" + << false; QTest::newRow("namespaces cannot be overridden by types 2") << "import QtQuick 2.0 as Rectangle\n" "import com.nokia.installedtest 1.5\n" "Rectangle.Image {}" - << "QQuickImage" - << ""; + << "QQuickImage" + << "" + << false; QTest::newRow("local last 1") << "LocalLast {}" - << "QQuickText" - << ""; + << "QQuickText" + << "" + << false; QTest::newRow("local last 2") << "import com.nokia.installedtest 1.0\n" "LocalLast {}" << (!qmlCheckTypes()?"QQuickRectangle":"")// i.e. from com.nokia.installedtest, not data/LocalLast.qml - << (!qmlCheckTypes()?"":"LocalLast is ambiguous. Found in lib/com/nokia/installedtest and in local directory"); + << (!qmlCheckTypes()?"":"LocalLast is ambiguous. Found in lib/com/nokia/installedtest/ and in ") + << false; } void tst_qqmllanguage::importsOrder() @@ -1916,7 +1927,8 @@ void tst_qqmllanguage::importsOrder() QFETCH(QString, qml); QFETCH(QString, type); QFETCH(QString, error); - testType(qml,type,error); + QFETCH(bool, partialMatch); + testType(qml,type,error,partialMatch); } void tst_qqmllanguage::importIncorrectCase() diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.errors.txt b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.errors.txt new file mode 100644 index 0000000000..262193788b --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.errors.txt @@ -0,0 +1 @@ +1:1:module "com.nokia.AutoTestQmlNestedPluginType.Nested" is not installed diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.qml b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.qml new file mode 100644 index 0000000000..b3f9ac6c3f --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.1.qml @@ -0,0 +1,5 @@ +import com.nokia.AutoTestQmlNestedPluginType.Nested 1.0 +import com.nokia.AutoTestQmlNestedPluginType 1.0 + +MyNestedPluginType { +} diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.2.qml b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.2.qml new file mode 100644 index 0000000000..cb8e0e33d1 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.2.qml @@ -0,0 +1,5 @@ +import com.nokia.AutoTestQmlNestedPluginType 1.0 +import com.nokia.AutoTestQmlNestedPluginType.Nested 1.0 + +MyNestedPluginType { +} diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.errors.txt b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.errors.txt new file mode 100644 index 0000000000..f0c73e336f --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.errors.txt @@ -0,0 +1 @@ +3:1:MyNestedPluginType is not a type diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.qml b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.qml new file mode 100644 index 0000000000..69c6a34f46 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.3.qml @@ -0,0 +1,4 @@ +import com.nokia.AutoTestQmlNestedPluginType 1.0 + +MyNestedPluginType { +} diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.errors.txt b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.errors.txt new file mode 100644 index 0000000000..9743ae4f68 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.errors.txt @@ -0,0 +1 @@ +2:1:module "com.nokia.AutoTestQmlNestedPluginType.Nested" version 6.66 is not installed diff --git a/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.qml b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.qml new file mode 100644 index 0000000000..dce8b7564a --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/importsNested.4.qml @@ -0,0 +1,5 @@ +import com.nokia.AutoTestQmlNestedPluginType 1.0 +import com.nokia.AutoTestQmlNestedPluginType.Nested 6.66 + +MyNestedPluginType { +} diff --git a/tests/auto/qml/qqmlmoduleplugin/imports/com/nokia/AutoTestQmlNestedPluginType/qmldir b/tests/auto/qml/qqmlmoduleplugin/imports/com/nokia/AutoTestQmlNestedPluginType/qmldir new file mode 100644 index 0000000000..f6ed20dda4 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/imports/com/nokia/AutoTestQmlNestedPluginType/qmldir @@ -0,0 +1 @@ +plugin nestedPlugin diff --git a/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.cpp b/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.cpp new file mode 100644 index 0000000000..2d0af471c2 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QStringList> +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QDebug> + +class MyPluginType : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString value READ value) + +public: + MyPluginType(QObject *parent=0) : QObject(parent) {} + + QString value() const { return "Hello"; } +}; + +class MyNestedPluginType : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString value READ value) + +public: + MyNestedPluginType(QObject *parent=0) : QObject(parent) {} + + QString value() const { return "Goodbye"; } +}; + + +class MyPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "../empty.json") + +public: + MyPlugin() {} + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "com.nokia.AutoTestQmlNestedPluginType"); + qmlRegisterType<MyPluginType>(uri, 1, 0, "MyPluginType"); + + QString nestedUri(uri); + nestedUri += QLatin1String(".Nested"); + + qmlRegisterType<MyNestedPluginType>(nestedUri.toLatin1().constData(), 1, 0, "MyNestedPluginType"); + } +}; + +#include "nestedPlugin.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.pro b/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.pro new file mode 100644 index 0000000000..94dc236a4c --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/nestedPlugin/nestedPlugin.pro @@ -0,0 +1,7 @@ +TEMPLATE = lib +CONFIG += nestedPlugin +SOURCES = nestedPlugin.cpp +QT = core qml +DESTDIR = ../imports/com/nokia/AutoTestQmlNestedPluginType + +QT += core-private gui-private qml-private diff --git a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro index 42eedc20f2..6da88320cd 100644 --- a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro +++ b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro @@ -1,6 +1,6 @@ QT = core TEMPLATE = subdirs -SUBDIRS = plugin plugin.2 plugin.2.1 pluginWrongCase pluginWithQmlFile pluginMixed pluginVersion +SUBDIRS = plugin plugin.2 plugin.2.1 pluginWrongCase pluginWithQmlFile pluginMixed pluginVersion nestedPlugin tst_qqmlmoduleplugin_pro.depends += plugin SUBDIRS += tst_qqmlmoduleplugin.pro diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index b574bad595..f6c165840d 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -70,6 +70,8 @@ private slots: void versionNotInstalled_data(); void implicitQmldir(); void implicitQmldir_data(); + void importsNested(); + void importsNested_data(); private: QString m_importsDirectory; @@ -347,6 +349,47 @@ void tst_qqmlmoduleplugin::implicitQmldir() delete obj; } +void tst_qqmlmoduleplugin::importsNested_data() +{ + QTest::addColumn<QString>("file"); + QTest::addColumn<QString>("errorFile"); + + // Note: no other test case should import the plugin used for this test, or the + // wrong order test will pass spuriously + QTest::newRow("wrongOrder") << "importsNested.1.qml" << "importsNested.1.errors.txt"; + QTest::newRow("missingImport") << "importsNested.3.qml" << "importsNested.3.errors.txt"; + QTest::newRow("invalidVersion") << "importsNested.4.qml" << "importsNested.4.errors.txt"; + QTest::newRow("correctOrder") << "importsNested.2.qml" << QString(); +} +void tst_qqmlmoduleplugin::importsNested() +{ + QFETCH(QString, file); + QFETCH(QString, errorFile); + + // Note: because imports are cached between test case data rows (and the plugins remain loaded), + // these tests should really be run in new instances of the app... + + QQmlEngine engine; + engine.addImportPath(m_importsDirectory); + + if (!errorFile.isEmpty()) { + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); + } + + QQmlComponent component(&engine, testFile(file)); + QObject *obj = component.create(); + + if (errorFile.isEmpty()) { + if (qgetenv("DEBUG") != "" && !component.errors().isEmpty()) + qWarning() << "Unexpected Errors:" << component.errors(); + QVERIFY(obj); + delete obj; + } else { + QList<QQmlError> errors = component.errors(); + VERIFY_ERRORS(errorFile.toLatin1().constData()); + QVERIFY(!obj); + } +} QTEST_MAIN(tst_qqmlmoduleplugin) diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp index 00b64e04a1..cb42be91d7 100644 --- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp +++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp @@ -165,6 +165,10 @@ and ensures that the subnode's source locations are inside parent node's source void tst_qqmlparser::qmlParser_data() { +#if defined(QTEST_CROSS_COMPILED) + return; +#endif + QTest::addColumn<QString>("file"); QString examples = QLatin1String(SRCDIR) + "/../../../../examples/"; @@ -180,11 +184,10 @@ void tst_qqmlparser::qmlParser_data() void tst_qqmlparser::qmlParser() { - QFETCH(QString, file); - #if defined(QTEST_CROSS_COMPILED) QSKIP("sources not available when cross compiled"); #endif + QFETCH(QString, file); using namespace QQmlJS; diff --git a/tests/auto/qml/qqmlproperty/data/invalidBinding.qml b/tests/auto/qml/qqmlproperty/data/invalidBinding.qml new file mode 100644 index 0000000000..e2bb1d172d --- /dev/null +++ b/tests/auto/qml/qqmlproperty/data/invalidBinding.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +Item { + property Text text: myText + + property Rectangle rectangle1: myText + property Rectangle rectangle2: eval('getMyText()') // eval to force non-shared (v8) binding + + function getMyText() { return myText; } + + Text { + id: myText + + anchors.verticalCenter: parent // invalid binding + } +} diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index aa22450bd3..f2521e93ef 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -45,6 +45,7 @@ #include <QtQml/qqmlproperty.h> #include <QtQml/private/qqmlproperty_p.h> #include <private/qqmlbinding_p.h> +#include <private/qqmlboundsignal_p.h> #include <QtWidgets/QLineEdit> #include <QtCore/qfileinfo.h> #include <QtCore/qdir.h> @@ -133,6 +134,7 @@ private slots: void aliasPropertyBindings(); void noContext(); void assignEmptyVariantMap(); + void warnOnInvalidBinding(); void copy(); private: @@ -145,8 +147,9 @@ void tst_qqmlproperty::qmlmetaproperty() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -178,8 +181,8 @@ void tst_qqmlproperty::qmlmetaproperty() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -248,8 +251,9 @@ void tst_qqmlproperty::qmlmetaproperty_object() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -281,8 +285,8 @@ void tst_qqmlproperty::qmlmetaproperty_object() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -295,8 +299,9 @@ void tst_qqmlproperty::qmlmetaproperty_object() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -330,8 +335,8 @@ void tst_qqmlproperty::qmlmetaproperty_object() QVERIFY(binding != 0); QVERIFY(QQmlPropertyPrivate::binding(prop) == binding.data()); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -349,8 +354,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -382,8 +388,8 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -396,8 +402,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -431,8 +438,8 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QVERIFY(binding != 0); QVERIFY(QQmlPropertyPrivate::binding(prop) == binding.data()); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -445,8 +452,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -478,9 +486,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression != 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == expression.data()); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(!sigExprWatcher.wasDeleted()); + QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == sigExpr); QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("clicked()")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -493,8 +501,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -526,9 +535,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression != 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == expression.data()); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(!sigExprWatcher.wasDeleted()); + QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == sigExpr); QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -546,8 +555,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_context() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -579,8 +589,8 @@ void tst_qqmlproperty::qmlmetaproperty_object_context() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -593,8 +603,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_context() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -628,8 +639,8 @@ void tst_qqmlproperty::qmlmetaproperty_object_context() QVERIFY(binding != 0); QVERIFY(QQmlPropertyPrivate::binding(prop) == binding.data()); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -647,8 +658,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -680,8 +692,8 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), -1); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -694,8 +706,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -729,8 +742,8 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QVERIFY(binding != 0); QVERIFY(QQmlPropertyPrivate::binding(prop) == binding.data()); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression == 0); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(sigExprWatcher.wasDeleted()); QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -743,8 +756,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -776,9 +790,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression != 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == expression.data()); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(!sigExprWatcher.wasDeleted()); + QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == sigExpr); QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("clicked()")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -791,8 +805,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QWeakPointer<QQmlAbstractBinding> binding(QQmlAbstractBinding::getPointer(new QQmlBinding(QLatin1String("null"), 0, engine.rootContext()))); static_cast<QQmlBinding *>(binding.data())->setTarget(prop); QVERIFY(binding != 0); - QWeakPointer<QQmlExpression> expression(new QQmlExpression()); - QVERIFY(expression != 0); + QQmlBoundSignalExpression *sigExpr = new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1); + QQmlAbstractExpression::DeleteWatcher sigExprWatcher(sigExpr); + QVERIFY(sigExpr != 0 && !sigExprWatcher.wasDeleted()); QObject *obj = new QObject; @@ -824,9 +839,9 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context() QVERIFY(QQmlPropertyPrivate::setBinding(prop, binding.data()) == 0); QVERIFY(binding == 0); QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == 0); - QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, expression.data()) == 0); - QVERIFY(expression != 0); - QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == expression.data()); + QVERIFY(QQmlPropertyPrivate::setSignalExpression(prop, sigExpr) == 0); + QVERIFY(!sigExprWatcher.wasDeleted()); + QVERIFY(QQmlPropertyPrivate::signalExpression(prop) == sigExpr); QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()")); QCOMPARE(QQmlPropertyPrivate::valueTypeCoreIndex(prop), -1); @@ -972,7 +987,7 @@ void tst_qqmlproperty::read() QQmlProperty p(&o, "onClicked"); QCOMPARE(p.read(), QVariant()); - QVERIFY(0 == QQmlPropertyPrivate::setSignalExpression(p, new QQmlExpression())); + QVERIFY(0 == QQmlPropertyPrivate::setSignalExpression(p, new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1))); QVERIFY(0 != QQmlPropertyPrivate::signalExpression(p)); QCOMPARE(p.read(), QVariant()); @@ -984,7 +999,7 @@ void tst_qqmlproperty::read() QQmlProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.read(), QVariant()); - QVERIFY(0 == QQmlPropertyPrivate::setSignalExpression(p, new QQmlExpression())); + QVERIFY(0 == QQmlPropertyPrivate::setSignalExpression(p, new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1))); QVERIFY(0 != QQmlPropertyPrivate::signalExpression(p)); QCOMPARE(p.read(), QVariant()); @@ -1140,7 +1155,7 @@ void tst_qqmlproperty::write() QQmlProperty p(&o, "onClicked"); QCOMPARE(p.write(QVariant("console.log(1921)")), false); - QVERIFY(0 == QQmlPropertyPrivate::setSignalExpression(p, new QQmlExpression())); + QVERIFY(0 == QQmlPropertyPrivate::setSignalExpression(p, new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1))); QVERIFY(0 != QQmlPropertyPrivate::signalExpression(p)); QCOMPARE(p.write(QVariant("console.log(1921)")), false); @@ -1154,7 +1169,7 @@ void tst_qqmlproperty::write() QQmlProperty p(&o, "onPropertyWithNotifyChanged"); QCOMPARE(p.write(QVariant("console.log(1921)")), false); - QVERIFY(0 == QQmlPropertyPrivate::setSignalExpression(p, new QQmlExpression())); + QVERIFY(0 == QQmlPropertyPrivate::setSignalExpression(p, new QQmlBoundSignalExpression(QQmlContextData::get(engine.rootContext()), 0, QLatin1String("null"), false, QString(), -1, -1))); QVERIFY(0 != QQmlPropertyPrivate::signalExpression(p)); QCOMPARE(p.write(QVariant("console.log(1921)")), false); @@ -1708,6 +1723,29 @@ void tst_qqmlproperty::assignEmptyVariantMap() delete obj; } +void tst_qqmlproperty::warnOnInvalidBinding() +{ + QUrl testUrl(testFileUrl("invalidBinding.qml")); + QString expectedWarning; + + // V4 error message for property-to-property binding + expectedWarning = testUrl.toString() + QString::fromLatin1(":6:36: Unable to assign QQuickText to QQuickRectangle"); + QTest::ignoreMessage(QtWarningMsg, expectedWarning.toLatin1().constData()); + + // V8 error message for function-to-property binding + expectedWarning = testUrl.toString() + QString::fromLatin1(":7:36: Unable to assign QQuickText to QQuickRectangle"); + QTest::ignoreMessage(QtWarningMsg, expectedWarning.toLatin1().constData()); + + // V8 error message for invalid binding to anchor + expectedWarning = testUrl.toString() + QString::fromLatin1(":14: Unable to assign QQuickItem_QML_7 to QQuickAnchorLine"); + QTest::ignoreMessage(QtWarningMsg, expectedWarning.toLatin1().constData()); + + QQmlComponent component(&engine, testUrl); + QObject *obj = component.create(); + QVERIFY(obj); + delete obj; +} + void tst_qqmlproperty::initTestCase() { QQmlDataTest::initTestCase(); diff --git a/tests/auto/qml/qqmlqt/data/dateTimeConversion.qml b/tests/auto/qml/qqmlqt/data/dateTimeConversion.qml index 641ba6e1ca..300074dec1 100644 --- a/tests/auto/qml/qqmlqt/data/dateTimeConversion.qml +++ b/tests/auto/qml/qqmlqt/data/dateTimeConversion.qml @@ -11,4 +11,10 @@ QtObject { property variant qdatetime4: new Date(2001,1,2) // 2001/02/02 hh:mm:ss.zzz property variant qdatetime5: new Date(1999,0,1,2,3,4) // 1999/01/01 02:03:04.zzz property variant qdatetime6: new Date(2008,1,24,14,15,38,200) // 2008/02/24 14:15:38.200 + + // Use UTC for historical dates to avoid DST issues + property variant qdatetime7: new Date(Date.UTC(1970,0,1,0,0,0,0)) // 1970/01/01 00:00:00.000 + property variant qdatetime8: new Date(Date.UTC(1586,1,2)) // 1586/02/02 hh:mm:ss.zzz + property variant qdatetime9: new Date(Date.UTC(955,0,1,0,0,0,0)) // 955/01/01 00:00:00.000 + property variant qdatetime10: new Date(Date.UTC(113,1,24,14,15,38,200)) // 113/02/24 14:15:38.200 } diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp index a1d7291565..c81e6771b8 100644 --- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp +++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp @@ -480,6 +480,10 @@ void tst_qqmlqt::dateTimeConversion() QDateTime dateTime4(QDate(2001,2,2), QTime(0,0,0,0)); QDateTime dateTime5(QDate(1999,1,1), QTime(2,3,4,0)); QDateTime dateTime6(QDate(2008,2,24), QTime(14,15,38,200)); + QDateTime dateTime7(QDate(1970,1,1), QTime(0,0,0,0), Qt::UTC); + QDateTime dateTime8(QDate(1586,2,2), QTime(0,0,0,0), Qt::UTC); + QDateTime dateTime9(QDate(955,1,1), QTime(0,0,0,0), Qt::UTC); + QDateTime dateTime10(QDate(113,2,24), QTime(14,15,38,200), Qt::UTC); QQmlEngine eng; QQmlComponent component(&eng, testFileUrl("dateTimeConversion.qml")); @@ -493,6 +497,10 @@ void tst_qqmlqt::dateTimeConversion() QCOMPARE(obj->property("qdatetime4").toDateTime(), dateTime4); QCOMPARE(obj->property("qdatetime5").toDateTime(), dateTime5); QCOMPARE(obj->property("qdatetime6").toDateTime(), dateTime6); + QCOMPARE(obj->property("qdatetime7").toDateTime(), dateTime7); + QCOMPARE(obj->property("qdatetime8").toDateTime(), dateTime8); + QCOMPARE(obj->property("qdatetime9").toDateTime(), dateTime9); + QCOMPARE(obj->property("qdatetime10").toDateTime(), dateTime10); } void tst_qqmlqt::dateTimeFormatting() diff --git a/tests/auto/qml/v4/data/conversions.1.qml b/tests/auto/qml/v4/data/conversions.1.qml new file mode 100644 index 0000000000..b3abde770a --- /dev/null +++ b/tests/auto/qml/v4/data/conversions.1.qml @@ -0,0 +1,13 @@ +import Qt.v4 1.0 + +Conversion { + // test assigning bool prop to other proptypes. + boolProp: true + intProp: boolProp + floatProp: boolProp + doubleProp: boolProp + qrealProp: boolProp + qstringProp: boolProp + qurlProp: boolProp + vec3Prop: Qt.vector3d(boolProp, boolProp, boolProp) +} diff --git a/tests/auto/qml/v4/data/conversions.2.qml b/tests/auto/qml/v4/data/conversions.2.qml new file mode 100644 index 0000000000..2fd0453ac2 --- /dev/null +++ b/tests/auto/qml/v4/data/conversions.2.qml @@ -0,0 +1,13 @@ +import Qt.v4 1.0 + +Conversion { + // test assigning int prop to other proptypes. + boolProp: intProp + intProp: 4 + floatProp: intProp + doubleProp: intProp + qrealProp: intProp + qstringProp: intProp + qurlProp: intProp + vec3Prop: Qt.vector3d(intProp, intProp, intProp) +} diff --git a/tests/auto/qml/v4/data/conversions.3.qml b/tests/auto/qml/v4/data/conversions.3.qml new file mode 100644 index 0000000000..66f0761a25 --- /dev/null +++ b/tests/auto/qml/v4/data/conversions.3.qml @@ -0,0 +1,13 @@ +import Qt.v4 1.0 + +Conversion { + // test assigning float prop to other proptypes. + boolProp: floatProp + intProp: floatProp + floatProp: 4.4 + doubleProp: floatProp + qrealProp: floatProp + qstringProp: floatProp + qurlProp: floatProp + vec3Prop: Qt.vector3d(floatProp, floatProp, floatProp) +} diff --git a/tests/auto/qml/v4/data/conversions.4.qml b/tests/auto/qml/v4/data/conversions.4.qml new file mode 100644 index 0000000000..ccf0035313 --- /dev/null +++ b/tests/auto/qml/v4/data/conversions.4.qml @@ -0,0 +1,13 @@ +import Qt.v4 1.0 + +Conversion { + // test assigning double prop to other prop types + boolProp: doubleProp + intProp: doubleProp + floatProp: doubleProp + doubleProp: 4.444444444 + qrealProp: doubleProp + qstringProp: doubleProp + qurlProp: doubleProp + vec3Prop: Qt.vector3d(doubleProp, doubleProp, doubleProp) +} diff --git a/tests/auto/qml/v4/data/conversions.5.qml b/tests/auto/qml/v4/data/conversions.5.qml new file mode 100644 index 0000000000..26dc3b7195 --- /dev/null +++ b/tests/auto/qml/v4/data/conversions.5.qml @@ -0,0 +1,13 @@ +import Qt.v4 1.0 + +Conversion { + // test assigning qreal prop to other prop types + boolProp: qrealProp + intProp: qrealProp + floatProp: qrealProp + doubleProp: qrealProp + qrealProp: 4.44 + qstringProp: qrealProp + qurlProp: qrealProp + vec3Prop: Qt.vector3d(qrealProp, qrealProp, qrealProp) +} diff --git a/tests/auto/qml/v4/data/conversions.6.qml b/tests/auto/qml/v4/data/conversions.6.qml new file mode 100644 index 0000000000..573b227ada --- /dev/null +++ b/tests/auto/qml/v4/data/conversions.6.qml @@ -0,0 +1,13 @@ +import Qt.v4 1.0 + +Conversion { + // test assigning string prop to other proptypes. + boolProp: qstringProp + intProp: qstringProp + floatProp: qstringProp + doubleProp: qstringProp + qrealProp: qstringProp + qstringProp: "4" + qurlProp: qstringProp + vec3Prop: Qt.vector3d(qstringProp, qstringProp, qstringProp) +} diff --git a/tests/auto/qml/v4/data/conversions.7.qml b/tests/auto/qml/v4/data/conversions.7.qml new file mode 100644 index 0000000000..5112b06b1e --- /dev/null +++ b/tests/auto/qml/v4/data/conversions.7.qml @@ -0,0 +1,13 @@ +import Qt.v4 1.0 + +Conversion { + // test assigning url prop to other proptypes. + boolProp: qurlProp + intProp: qurlProp + floatProp: qurlProp + doubleProp: qurlProp + qrealProp: qurlProp + qstringProp: qurlProp + qurlProp: "4" + vec3Prop: Qt.vector3d(qurlProp, qurlProp, qurlProp) +} diff --git a/tests/auto/qml/v4/data/conversions.8.qml b/tests/auto/qml/v4/data/conversions.8.qml new file mode 100644 index 0000000000..18bf160e7e --- /dev/null +++ b/tests/auto/qml/v4/data/conversions.8.qml @@ -0,0 +1,13 @@ +import Qt.v4 1.0 + +Conversion { + // test assigning vector prop to other proptypes. + boolProp: vec3Prop + intProp: vec3Prop + floatProp: vec3Prop + doubleProp: vec3Prop + qrealProp: vec3Prop + qstringProp: vec3Prop + qurlProp: vec3Prop + vec3Prop: Qt.vector3d(4, 4, 4) +} diff --git a/tests/auto/qml/v4/data/subscriptions.1.qml b/tests/auto/qml/v4/data/subscriptions.1.qml new file mode 100644 index 0000000000..607233819e --- /dev/null +++ b/tests/auto/qml/v4/data/subscriptions.1.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +Rectangle { + id: root + width: 400 + height: 400 + + property real targetHeight: menuItems.height + 1 + property real heightValue: if (1) menuItems.height //this must be v8? + property bool boolProp: menuItems.height > heightValue //this must be v4? + + Column { + id: menuItems + Item { height: 200; width: 10 } + } +} diff --git a/tests/auto/qml/v4/testtypes.cpp b/tests/auto/qml/v4/testtypes.cpp index c879cf2226..80ccf007a5 100644 --- a/tests/auto/qml/v4/testtypes.cpp +++ b/tests/auto/qml/v4/testtypes.cpp @@ -46,4 +46,5 @@ void registerTypes() { qmlRegisterType<ResultObject>("Qt.v4", 1,0, "Result"); qmlRegisterType<NestedObject>(); + qmlRegisterType<ConversionObject>("Qt.v4", 1, 0, "Conversion"); } diff --git a/tests/auto/qml/v4/testtypes.h b/tests/auto/qml/v4/testtypes.h index 18b5b27b36..04dd82e8fe 100644 --- a/tests/auto/qml/v4/testtypes.h +++ b/tests/auto/qml/v4/testtypes.h @@ -42,6 +42,8 @@ #define TESTTYPES_H #include <QtCore/qobject.h> +#include <QtCore/qurl.h> +#include <QVector3D> class NestedObject : public QObject { @@ -80,6 +82,61 @@ private: NestedObject m_nested2; }; +class ConversionObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool boolProp READ boolProp WRITE setBoolProp NOTIFY boolPropChanged) + Q_PROPERTY(int intProp READ intProp WRITE setIntProp NOTIFY intPropChanged) + Q_PROPERTY(float floatProp READ floatProp WRITE setFloatProp NOTIFY floatPropChanged) + Q_PROPERTY(double doubleProp READ doubleProp WRITE setDoubleProp NOTIFY doublePropChanged) + Q_PROPERTY(qreal qrealProp READ qrealProp WRITE setQrealProp NOTIFY qrealPropChanged) + Q_PROPERTY(QString qstringProp READ qstringProp WRITE setQstringProp NOTIFY qstringPropChanged) + Q_PROPERTY(QUrl qurlProp READ qurlProp WRITE setQurlProp NOTIFY qurlPropChanged) + Q_PROPERTY(QVector3D vec3Prop READ vec3Prop WRITE setVec3Prop NOTIFY vec3PropChanged) + +public: + ConversionObject() : m_boolProp(false), m_intProp(0), m_floatProp(0.0), m_doubleProp(0.0), m_qrealProp(0.0) {} + ~ConversionObject() {} + + bool boolProp() const { return m_boolProp; } + void setBoolProp(bool v) { m_boolProp = v; emit boolPropChanged(); } + int intProp() const { return m_intProp; } + void setIntProp(int v) { m_intProp = v; emit intPropChanged(); } + float floatProp() const { return m_floatProp; } + void setFloatProp(float v) { m_floatProp = v; emit floatPropChanged(); } + double doubleProp() const { return m_doubleProp; } + void setDoubleProp(double v) { m_doubleProp = v; emit doublePropChanged(); } + qreal qrealProp() const { return m_qrealProp; } + void setQrealProp(qreal v) { m_qrealProp = v; emit qrealPropChanged(); } + QString qstringProp() const { return m_qstringProp; } + void setQstringProp(const QString& v) { m_qstringProp = v; emit qstringPropChanged(); } + QUrl qurlProp() const { return m_qurlProp; } + void setQurlProp(const QUrl& v) { m_qurlProp = v; emit qurlPropChanged(); } + QVector3D vec3Prop() const { return m_vec3Prop; } + void setVec3Prop(const QVector3D& v) { m_vec3Prop = v; emit vec3PropChanged(); } + +signals: + void boolPropChanged(); + void intPropChanged(); + void floatPropChanged(); + void doublePropChanged(); + void qrealPropChanged(); + void qstringPropChanged(); + void qurlPropChanged(); + void vec3PropChanged(); + +private: + bool m_boolProp; + int m_intProp; + float m_floatProp; + double m_doubleProp; + qreal m_qrealProp; + QString m_qstringProp; + QUrl m_qurlProp; + QVector3D m_vec3Prop; +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/v4/tst_v4.cpp b/tests/auto/qml/v4/tst_v4.cpp index 47fa10b595..dfb7cc48c7 100644 --- a/tests/auto/qml/v4/tst_v4.cpp +++ b/tests/auto/qml/v4/tst_v4.cpp @@ -46,6 +46,7 @@ #include <QtQml/qqmlcomponent.h> #include <QtCore/qdebug.h> #include <QtGui/qcolor.h> +#include <QtCore/qnumeric.h> #include <private/qv4compiler_p.h> @@ -83,6 +84,12 @@ private slots: void mathMin(); void moduleApi(); + void conversions_data(); + void conversions(); + void subscriptions(); + + void debuggingDumpInstructions(); // this test should be last. + private: QQmlEngine engine; }; @@ -135,6 +142,14 @@ void tst_v4::qtscript_data() QTest::newRow("unary minus") << "unaryMinus.qml"; QTest::newRow("null qobject") << "nullQObject.qml"; QTest::newRow("qobject -> bool") << "objectToBool.qml"; + QTest::newRow("conversion from bool") << "conversions.1.qml"; // QTBUG-24706 + QTest::newRow("conversion from int") << "conversions.2.qml"; // QTBUG-24706 + QTest::newRow("conversion from float") << "conversions.3.qml"; + QTest::newRow("conversion from double") << "conversions.4.qml"; // QTBUG-24706 + QTest::newRow("conversion from real") << "conversions.5.qml"; // QTBUG-24706 + QTest::newRow("conversion from string") << "conversions.6.qml"; // QTBUG-24706 + QTest::newRow("conversion from url") << "conversions.7.qml"; // QTBUG-24706 + QTest::newRow("conversion from vec3") << "conversions.8.qml"; } void tst_v4::unnecessaryReeval() @@ -630,6 +645,334 @@ void tst_v4::moduleApi() delete o; } +void tst_v4::conversions_data() +{ + QTest::addColumn<QUrl>("file"); + QTest::addColumn<QStringList>("warnings"); + QTest::addColumn<bool>("boolProp"); + QTest::addColumn<int>("intProp"); + QTest::addColumn<float>("floatProp"); + QTest::addColumn<double>("doubleProp"); + QTest::addColumn<qreal>("qrealProp"); + QTest::addColumn<QString>("qstringProp"); + QTest::addColumn<QUrl>("qurlProp"); + QTest::addColumn<QVector3D>("vec3Prop"); + + QTest::newRow("from bool") << testFileUrl("conversions.1.qml") + << (QStringList() << (testFileUrl("conversions.1.qml").toString() + QLatin1String(":11:15: Unable to assign bool to QUrl"))) + << true + << (int)true + << (float)1.0 + << (double)1.0 + << (qreal)1.0 + << QString(QLatin1String("true")) + << QUrl() // cannot assign bool to url. + << QVector3D(1, 1, 1); + + QTest::newRow("from integer") << testFileUrl("conversions.2.qml") + << (QStringList() << (testFileUrl("conversions.2.qml").toString() + QLatin1String(":11:15: Unable to assign int to QUrl"))) + << (bool)4 + << 4 + << (float)4.0 + << (double)4.0 + << (qreal)4.0 + << QString(QLatin1String("4")) + << QUrl() // cannot assign int to url. + << QVector3D(4, 4, 4); + + QTest::newRow("from float") << testFileUrl("conversions.3.qml") + << (QStringList() << (testFileUrl("conversions.3.qml").toString() + QLatin1String(":11:15: Unable to assign number to QUrl"))) + << (bool)4.4 + << (int)4.4 + << (float)4.4 + << (double)((float)4.4) + << (qreal)((float)4.4) + << QString::number((double)((float)4.4), 'g', 16) + << QUrl() // cannot assign number to url. + << QVector3D(4.4, 4.4, 4.4); + + QTest::newRow("from double") << testFileUrl("conversions.4.qml") + << (QStringList() << (testFileUrl("conversions.4.qml").toString() + QLatin1String(":11:15: Unable to assign number to QUrl"))) + << (bool)4.444444444 + << (int)4.444444444 + << (float)4.444444444 + << (double)4.444444444 + << (qreal)4.444444444 + << QString::number((double)4.444444444, 'g', 16) + << QUrl() // cannot assign number to url. + << QVector3D(4.444444444, 4.444444444, 4.444444444); + + QTest::newRow("from qreal") << testFileUrl("conversions.5.qml") + << (QStringList() << (testFileUrl("conversions.5.qml").toString() + QLatin1String(":11:15: Unable to assign number to QUrl"))) + << (bool)4.44 + << (int)4.44 + << (float)4.44 + << (double)4.44 + << (qreal)4.44 + << QString(QLatin1String("4.44")) + << QUrl() // cannot assign number to url. + << QVector3D(4.44, 4.44, 4.44); + + QTest::newRow("from string") << testFileUrl("conversions.6.qml") + << (QStringList()) + << true + << 4 + << (float)4.0 + << (double)4.0 + << (qreal)4.0 + << QString(QLatin1String("4")) + << QUrl(testFileUrl("").toString() + QString(QLatin1String("4"))) + << QVector3D(4, 4, 4); + + // QTBUG-24706 + QTest::newRow("from url") << testFileUrl("conversions.7.qml") + << (QStringList() << (testFileUrl("conversions.7.qml").toString() + QLatin1String(":6:14: Unable to assign QUrl to int")) + << (testFileUrl("conversions.7.qml").toString() + QLatin1String(":7:16: Unable to assign QUrl to number")) + << (testFileUrl("conversions.7.qml").toString() + QLatin1String(":8:17: Unable to assign QUrl to number")) + << (testFileUrl("conversions.7.qml").toString() + QLatin1String(":9:16: Unable to assign QUrl to number"))) + << true + << 0 + << (float) 0 + << (double) 0 + << (qreal) 0 + << QString(testFileUrl("").toString() + QString(QLatin1String("4"))) + << QUrl(testFileUrl("").toString() + QString(QLatin1String("4"))) + << QVector3D(qQNaN(), qQNaN(), qQNaN()); + + QTest::newRow("from vector") << testFileUrl("conversions.8.qml") + << (QStringList() << (testFileUrl("conversions.8.qml").toString() + QLatin1String(":11: Unable to assign QVector3D to QUrl")) + << (testFileUrl("conversions.8.qml").toString() + QLatin1String(":10: Unable to assign QVector3D to QString")) + << (testFileUrl("conversions.8.qml").toString() + QLatin1String(":9: Unable to assign QVector3D to double")) + << (testFileUrl("conversions.8.qml").toString() + QLatin1String(":8: Unable to assign QVector3D to double")) + << (testFileUrl("conversions.8.qml").toString() + QLatin1String(":7: Unable to assign QVector3D to float")) + << (testFileUrl("conversions.8.qml").toString() + QLatin1String(":6: Unable to assign QVector3D to int"))) + << true // non-null therefore true + << (int)0 // the other values should be the default-ctor values. + << (float)0 + << (double)0 + << (qreal)0 + << QString() + << QUrl() + << QVector3D(4, 4, 4); // except this one. +} + +#define COMPARE_NUMBER(type, prop, expected) \ + if (qIsNaN(expected)) \ + QVERIFY(qIsNaN(qvariant_cast<type>(prop))); \ + else \ + QCOMPARE((prop), QVariant::fromValue<type>(expected)); + +void tst_v4::conversions() +{ + QFETCH(QUrl, file); + QFETCH(QStringList, warnings); + QFETCH(bool, boolProp); + QFETCH(int, intProp); + QFETCH(float, floatProp); + QFETCH(double, doubleProp); + QFETCH(qreal, qrealProp); + QFETCH(QString, qstringProp); + QFETCH(QUrl, qurlProp); + QFETCH(QVector3D, vec3Prop); + + foreach (const QString &w, warnings) + QTest::ignoreMessage(QtWarningMsg, qPrintable(w)); + + QQmlComponent component(&engine, file); + QObject *o = component.create(); + QVERIFY(o != 0); + QCOMPARE(o->property("boolProp"), QVariant::fromValue<bool>(boolProp)); + QCOMPARE(o->property("intProp"), QVariant::fromValue<int>(intProp)); + COMPARE_NUMBER(float, o->property("floatProp"), floatProp); + COMPARE_NUMBER(double, o->property("doubleProp"), doubleProp); + COMPARE_NUMBER(qreal, o->property("qrealProp"), qrealProp); + QCOMPARE(o->property("qstringProp"), QVariant::fromValue<QString>(qstringProp)); + QCOMPARE(o->property("qurlProp"), QVariant::fromValue<QUrl>(qurlProp)); + + QVector3D vec3 = qvariant_cast<QVector3D>(o->property("vec3Prop")); + COMPARE_NUMBER(qreal, QVariant::fromValue<qreal>(vec3.x()), vec3Prop.x()); + COMPARE_NUMBER(qreal, QVariant::fromValue<qreal>(vec3.y()), vec3Prop.y()); + COMPARE_NUMBER(qreal, QVariant::fromValue<qreal>(vec3.z()), vec3Prop.z()); + delete o; +} + +void tst_v4::subscriptions() +{ + { + QQmlComponent component(&engine, testFileUrl("subscriptions.1.qml")); + + QObject *o = component.create(); + QVERIFY(o != 0); + + QObject *ro = qobject_cast<QObject *>(o); + QVERIFY(ro != 0); + + QCOMPARE(ro->property("targetHeight"), QVariant::fromValue<qreal>(201)); + + delete o; + } +} + +static QStringList messages; +static void msgHandler(QtMsgType, const char *msg) +{ + messages << QLatin1String(msg); +} + +static QByteArray getAddress(int address) +{ + return QByteArray::number(address); +} + +static QByteArray getLeading(int address) +{ + QByteArray leading; + if (address != -1) { + leading = getAddress(address); + leading.prepend(QByteArray(8 - leading.count(), ' ')); + } + return leading; +} + +#include <private/qv4instruction_p.h> +void tst_v4::debuggingDumpInstructions() +{ + QStringList expectedPreAddress; + expectedPreAddress << "\t\tNoop"; + expectedPreAddress << "\t0:0:"; + expectedPreAddress << "\t\tSubscribe\t\tObject_Reg(0) Notify_Signal(0) -> Subscribe_Slot(0)"; + expectedPreAddress << "\t\tSubscribeId\t\tId_Offset(0) -> Subscribe_Slot(0)"; + expectedPreAddress << "\t\tFetchAndSubscribe\tObject_Reg(0) Fast_Accessor(0x0) -> Output_Reg(0) Subscription_Slot(0)"; + expectedPreAddress << "\t\tLoadId\t\t\tId_Offset(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadScope\t\t-> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadRoot\t\t-> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadModuleObject\t\t) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadAttached\t\tObject_Reg(0) Attached_Index(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tUnaryNot\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tUnaryMinusNumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tUnaryMinusInt\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tUnaryPlusNumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tUnaryPlusInt\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertBoolToInt\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertBoolToNumber\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertBoolToString\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertIntToBool\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertIntToNumber\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertIntToString\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertNumberToBool\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertNumberToInt\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertNumberToString\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertStringToBool\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertStringToInt\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertStringToNumber\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertStringToUrl\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertStringToColor\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertUrlToBool\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertUrlToString\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertColorToBool\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertColorToString\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertObjectToBool\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tConvertNullToObject\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tResolveUrl\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathSinNumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathCosNumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathAbsNumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathRoundNumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathFloorNumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathCeilNumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathPINumber\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadNull\t\tConstant(null) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadNumber\t\tConstant(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadInt\t\t\tConstant(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadBool\t\tConstant(false) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLoadString\t\tString_DataIndex(0) String_Length(0) -> Output_Register(0)"; + expectedPreAddress << "\t\tEnableV4Test\t\tString_DataIndex(0) String_Length(0)"; + expectedPreAddress << "\t\tTestV4Store\t\tInput_Reg(0) Reg_Type(0)"; + expectedPreAddress << "\t\tBitAndInt\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tBitOrInt\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tBitXorInt\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tAddNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tAddString\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tSubNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMulNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tDivNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tModNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLShiftInt\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tRShiftInt\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tURShiftInt\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tGtNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLtNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tGeNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLeNumber\t\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tEqualNumber\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tNotEqualNumber\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tStrictEqualNumber\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tStrictNotEqualNumber\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tGtString\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLtString\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tGeString\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tLeString\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tEqualString\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tNotEqualString\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tStrictEqualString\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tStrictNotEqualString\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tEqualObject\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tNotEqualObject\t\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tStrictEqualObject\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tStrictNotEqualObject\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathMaxNumber\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tMathMinNumber\tInput_Reg(0) Input_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tNewString\t\tRegister(0)"; + expectedPreAddress << "\t\tNewUrl\t\t\tRegister(0)"; + expectedPreAddress << "\t\tCleanupRegister\t\tRegister(0)"; + expectedPreAddress << "\t\tCopy\t\t\tInput_Reg(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tFetch\t\t\tObject_Reg(0) Property_Index(0) -> Output_Reg(0)"; + expectedPreAddress << "\t\tStore\t\t\tInput_Reg(0) -> Object_Reg(0) Property_Index(0)"; + expectedPreAddress << "\t\tJump\t\t\tAddress(UNIT_TEST_JUMP_ADDRESS) [if false == Input_Reg(0)]"; //(address + size() + i->jump.count) + expectedPreAddress << "\t\tBranchTrue\t\tAddress(UNIT_TEST_BRANCH_ADDRESS) [if true == Input_Reg(0)]"; //(address + size() + i->branchop.offset) + expectedPreAddress << "\t\tBranchFalse\t\tAddress(UNIT_TEST_BRANCH_ADDRESS) [if false == Input_Reg(0)]"; //(address + size() + i->branchop.offset) + expectedPreAddress << "\t\tBranch\t\t\tAddress(UNIT_TEST_BRANCH_ADDRESS)"; //(address + size() + i->branchop.offset) + expectedPreAddress << "\t\tBlock\t\t\tMask(0)"; + expectedPreAddress << "\t\tThrow\t\t\tInputReg(0)"; + expectedPreAddress << "\t\tInitString\t\tString_DataIndex(0) -> String_Slot(0)"; + QStringList expected; + + messages = QStringList(); + QtMsgHandler old = qInstallMsgHandler(msgHandler); + + QQmlJS::Bytecode bc; +#define DUMP_INSTR_IN_UNIT_TEST(I, FMT) { QQmlJS::V4InstrData<QQmlJS::V4Instr::I> i; memset(&i, 0, sizeof(i)); bc.append(i); } + FOR_EACH_V4_INSTR(DUMP_INSTR_IN_UNIT_TEST); +#undef DUMP_INSTR_IN_UNIT_TEST // NOTE: we memset in order to ensure stable output. + const char *start = bc.constData(); + const char *end = start + bc.size(); + const char *codeAddr = start; + int whichExpected = 0; +#define DUMP_INSTR_SIZE_IN_UNIT_TEST(I, FMT) { \ + QString currExpected = whichExpected < expectedPreAddress.size() ? expectedPreAddress.at(whichExpected++) : QString(); \ + currExpected.prepend(getLeading(codeAddr - start)); \ + expected.append(currExpected); \ + codeAddr += QQmlJS::V4Instr::size(static_cast<QQmlJS::V4Instr::Type>(QQmlJS::V4Instr::I)); \ + } + FOR_EACH_V4_INSTR(DUMP_INSTR_SIZE_IN_UNIT_TEST); +#undef DUMP_INSTR_SIZE_IN_UNIT_TEST // so that we generate the correct address for each instruction comparison + bc.dump(start, end); + + // ensure that the output was expected. + qInstallMsgHandler(old); + QCOMPARE(messages.count(), expected.count()); + for (int ii = 0; ii < messages.count(); ++ii) { + // Calculating the destination address of a null jump/branch instruction is tricky + // so instead we simply don't compare that part of those instructions. + QRegExp ignoreAddress("\\bAddress\\((\\w*)\\)"); + ignoreAddress.setMinimal(true); + QString expectOut = expected.at(ii); expectOut.replace(ignoreAddress, ""); + QString actualOut = messages.at(ii); actualOut.replace(ignoreAddress, ""); + QCOMPARE(actualOut, expectOut); + } +} + + QTEST_MAIN(tst_v4) #include "tst_v4.moc" |