diff options
Diffstat (limited to 'tests/auto/qml')
14 files changed, 319 insertions, 91 deletions
diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml index a36d0cae91..0fa9f1ffd8 100644 --- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml +++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml @@ -36,6 +36,7 @@ Item { var b = {a: "hello", d: 1 } var c var d = 12 + console.log("Component.onCompleted"); } function foo() { var a = [1, 2] diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp index 8d1a165243..3aa3a5c87e 100644 --- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp +++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp @@ -142,24 +142,36 @@ void tst_QQmlDebuggingEnabler::cleanup() void tst_QQmlDebuggingEnabler::data() { + QTest::addColumn<QString>("connector"); QTest::addColumn<bool>("blockMode"); QTest::addColumn<QStringList>("services"); - QTest::newRow("noblock,all") << false << QStringList(); - QTest::newRow("block,all") << true << QStringList(); - QTest::newRow("noblock,debugger") << false << QQmlDebuggingEnabler::debuggerServices(); - QTest::newRow("block,debugger") << true << QQmlDebuggingEnabler::debuggerServices(); - QTest::newRow("noblock,inspector") << false << QQmlDebuggingEnabler::inspectorServices(); - QTest::newRow("block,inspector") << true << QQmlDebuggingEnabler::inspectorServices(); - QTest::newRow("noblock,profiler") << false << QQmlDebuggingEnabler::profilerServices(); - QTest::newRow("block,profiler") << true << QQmlDebuggingEnabler::profilerServices(); - QTest::newRow("noblock,debugger+inspector") - << false << QQmlDebuggingEnabler::debuggerServices() + - QQmlDebuggingEnabler::inspectorServices(); - QTest::newRow("block,debugger+inspector") - << true << QQmlDebuggingEnabler::debuggerServices() + - QQmlDebuggingEnabler::inspectorServices(); - + QStringList connectors({ + QLatin1String("QQmlDebugServer"), + QLatin1String("QQmlNativeDebugConnector") + }); + + QList<bool> blockModes({ true, false }); + + QList<QStringList> serviceLists({ + QStringList(), + QQmlDebuggingEnabler::nativeDebuggerServices(), + QQmlDebuggingEnabler::debuggerServices(), + QQmlDebuggingEnabler::inspectorServices(), + QQmlDebuggingEnabler::profilerServices(), + QQmlDebuggingEnabler::debuggerServices() + QQmlDebuggingEnabler::inspectorServices() + }); + + foreach (const QString &connector, connectors) { + foreach (bool blockMode, blockModes) { + foreach (const QStringList &serviceList, serviceLists) { + QString name = connector + QLatin1Char(',') + + QLatin1String(blockMode ? "block" : "noblock") + QLatin1Char(',') + + serviceList.join(QLatin1Char('-')); + QTest::newRow(name.toUtf8().constData()) << connector << blockMode << serviceList; + } + } + } } void tst_QQmlDebuggingEnabler::qmlscene_data() @@ -169,27 +181,36 @@ void tst_QQmlDebuggingEnabler::qmlscene_data() void tst_QQmlDebuggingEnabler::qmlscene() { + QFETCH(QString, connector); QFETCH(bool, blockMode); QFETCH(QStringList, services); - connection = new QQmlDebugConnection(); - QList<QQmlDebugClient *> clients = QQmlDebugTest::createOtherClients(connection); process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", this); process->setMaximumBindErrors(1); process->start(QStringList() - << QString::fromLatin1("-qmljsdebugger=port:5555,5565%1%2%3") + << QString::fromLatin1("-qmljsdebugger=connector:%1%2%3%4") + .arg(connector + (connector == QLatin1String("QQmlDebugServer") ? + QLatin1String(",port:5555,5565") : QString())) .arg(blockMode ? QLatin1String(",block") : QString()) .arg(services.isEmpty() ? QString() : QString::fromLatin1(",services:")) .arg(services.isEmpty() ? QString() : services.join(",")) << testFile(QLatin1String("test.qml"))); - QVERIFY(process->waitForSessionStart()); - connection->connectToHost("127.0.0.1", process->debugPort()); - QVERIFY(connection->waitForConnected()); - foreach (QQmlDebugClient *client, clients) - QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ? - QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); + if (connector == QLatin1String("QQmlDebugServer")) { + QVERIFY(process->waitForSessionStart()); + connection = new QQmlDebugConnection(); + QList<QQmlDebugClient *> clients = QQmlDebugTest::createOtherClients(connection); + connection->connectToHost("127.0.0.1", process->debugPort()); + QVERIFY(connection->waitForConnected()); + foreach (QQmlDebugClient *client, clients) + QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ? + QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); + } + + QCOMPARE(process->state(), QLatin1String("running")); + if (!blockMode) + QTRY_VERIFY(process->output().contains(QLatin1String("qml: Component.onCompleted"))); } void tst_QQmlDebuggingEnabler::custom_data() @@ -199,13 +220,12 @@ void tst_QQmlDebuggingEnabler::custom_data() void tst_QQmlDebuggingEnabler::custom() { + QFETCH(QString, connector); QFETCH(bool, blockMode); QFETCH(QStringList, services); const int portFrom = 5555; const int portTo = 5565; - connection = new QQmlDebugConnection(); - QList<QQmlDebugClient *> clients = QQmlDebugTest::createOtherClients(connection); process = new QQmlDebugProcess(QCoreApplication::applicationDirPath() + QLatin1String("/qqmldebuggingenablerserver"), this); process->setMaximumBindErrors(portTo - portFrom); @@ -214,18 +234,28 @@ void tst_QQmlDebuggingEnabler::custom() if (blockMode) args << QLatin1String("-block"); - args << QString::number(portFrom) << QString::number(portTo); + args << QLatin1String("-connector") << connector + << QString::number(portFrom) << QString::number(portTo); + if (!services.isEmpty()) args << QLatin1String("-services") << services; process->start(args); - QVERIFY(process->waitForSessionStart()); - connection->connectToHost("127.0.0.1", process->debugPort()); - QVERIFY(connection->waitForConnected()); - foreach (QQmlDebugClient *client, clients) - QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ? - QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); + if (connector == QLatin1String("QQmlDebugServer")) { + QVERIFY(process->waitForSessionStart()); + connection = new QQmlDebugConnection(); + QList<QQmlDebugClient *> clients = QQmlDebugTest::createOtherClients(connection); + connection->connectToHost("127.0.0.1", process->debugPort()); + QVERIFY(connection->waitForConnected()); + foreach (QQmlDebugClient *client, clients) + QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ? + QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); + } + + QCOMPARE(process->state(), QLatin1String("running")); + if (!blockMode) + QTRY_VERIFY(process->output().contains(QLatin1String("QQmlEngine created"))); } QTEST_MAIN(tst_QQmlDebuggingEnabler) diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp index cfbb31f9e1..a064bbbacc 100644 --- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp +++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp @@ -28,6 +28,7 @@ #include <QtCore/qcoreapplication.h> #include <QtCore/qlibraryinfo.h> +#include <QtCore/qdebug.h> #include <QtQml/qqmldebug.h> #include <QtQml/qqmlengine.h> @@ -40,12 +41,18 @@ int main(int argc, char *argv[]) QCoreApplication app(argc, argv); QStringList arguments = app.arguments(); arguments.removeFirst(); + QString connector = QLatin1String("QQmlDebugServer"); if (arguments.size() && arguments.first() == QLatin1String("-block")) { block = QQmlDebuggingEnabler::WaitForClient; arguments.removeFirst(); } + if (arguments.size() >= 2 && arguments.first() == QLatin1String("-connector")) { + arguments.removeFirst(); + connector = arguments.takeFirst(); + } + if (arguments.size() >= 2) { portFrom = arguments.takeFirst().toInt(); portTo = arguments.takeFirst().toInt(); @@ -54,12 +61,20 @@ int main(int argc, char *argv[]) if (arguments.size() && arguments.takeFirst() == QLatin1String("-services")) QQmlDebuggingEnabler::setServices(arguments); - if (!portFrom || !portTo) - qFatal("Port range has to be specified."); + if (connector == QLatin1String("QQmlDebugServer")) { + if (!portFrom || !portTo) + qFatal("Port range has to be specified."); + + while (portFrom <= portTo) + QQmlDebuggingEnabler::startTcpDebugServer(portFrom++, block); + } else if (connector == QLatin1String("QQmlNativeDebugConnector")) { + QVariantHash configuration; + configuration[QLatin1String("block")] = (block == QQmlDebuggingEnabler::WaitForClient); + QQmlDebuggingEnabler::startDebugConnector(connector, configuration); + } - while (portFrom <= portTo) - QQmlDebuggingEnabler::startTcpDebugServer(portFrom++, block); QQmlEngine engine; + qDebug() << "QQmlEngine created\n"; Q_UNUSED(engine); return app.exec(); } diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro index 79e772c1ee..cbaf3b5309 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro +++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro @@ -9,6 +9,7 @@ SOURCES += tst_qqmldebugjs.cpp INCLUDEPATH += ../../shared include(../../../../shared/util.pri) include(../../shared/debugutil.pri) +include(../../shared/qqmlenginedebugclient.pri) TESTDATA = data/* diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp index d1150be831..31b8d63ec2 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp +++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include "debugutil_p.h" +#include "../../shared/qqmlenginedebugclient.h" #include "../../../../shared/util.h" #include <private/qqmldebugclient_p.h> @@ -52,6 +53,7 @@ const char *STEPACTION = "stepaction"; const char *STEPCOUNT = "stepcount"; const char *EXPRESSION = "expression"; const char *FRAME = "frame"; +const char *CONTEXT = "context"; const char *GLOBAL = "global"; const char *DISABLEBREAK = "disable_break"; const char *HANDLES = "handles"; @@ -215,6 +217,8 @@ private slots: void evaluateInLocalScope_data() { targetData(); } void evaluateInLocalScope(); + void evaluateInContext(); + void getScripts_data() { targetData(); } void getScripts(); @@ -257,7 +261,7 @@ public: void interrupt(); void continueDebugging(StepAction stepAction); - void evaluate(QString expr, int frame = -1); + void evaluate(QString expr, int frame = -1, int context = -1); void lookup(QList<int> handles, bool includeSource = false); void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false); void frame(int number = -1); @@ -280,6 +284,7 @@ signals: void connected(); void interruptRequested(); void result(); + void failure(); void stopped(); private: @@ -340,13 +345,14 @@ void QJSDebugClient::continueDebugging(StepAction action) sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } -void QJSDebugClient::evaluate(QString expr, int frame) +void QJSDebugClient::evaluate(QString expr, int frame, int context) { // { "seq" : <number>, // "type" : "request", // "command" : "evaluate", // "arguments" : { "expression" : <expression to evaluate>, - // "frame" : <number> + // "frame" : <number>, + // "context" : <object ID> // } // } VARIANTMAPINIT; @@ -358,6 +364,9 @@ void QJSDebugClient::evaluate(QString expr, int frame) if (frame != -1) args.setProperty(QLatin1String(FRAME),QJSValue(frame)); + if (context != -1) + args.setProperty(QLatin1String(CONTEXT), QJSValue(context)); + if (!args.isUndefined()) { jsonVal.setProperty(QLatin1String(ARGUMENTS),args); } @@ -684,6 +693,7 @@ void QJSDebugClient::messageReceived(const QByteArray &data) if (type == "response") { if (!value.value("success").toBool()) { + emit failure(); qDebug() << "Received success == false response from application"; return; } @@ -1394,6 +1404,58 @@ void tst_QQmlDebugJS::evaluateInLocalScope() QCOMPARE(body.value("value").toInt(),10); } +void tst_QQmlDebugJS::evaluateInContext() +{ + connection = new QQmlDebugConnection(); + process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + + "/qmlscene", this); + client = new QJSDebugClient(connection); + QScopedPointer<QQmlEngineDebugClient> engineClient(new QQmlEngineDebugClient(connection)); + process->start(QStringList() << QLatin1String(BLOCKMODE) << testFile(ONCOMPLETED_QMLFILE)); + + QVERIFY(process->waitForSessionStart()); + + connection->connectToHost("127.0.0.1", process->debugPort()); + QVERIFY(connection->waitForConnected()); + + QTRY_COMPARE(client->state(), QQmlEngineDebugClient::Enabled); + QTRY_COMPARE(engineClient->state(), QQmlEngineDebugClient::Enabled); + client->connect(); + + // "a" not accessible without extra context + client->evaluate(QLatin1String("a + 10"), -1, -1); + QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(failure()))); + + bool success = false; + engineClient->queryAvailableEngines(&success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result()))); + + QVERIFY(engineClient->engines().count()); + engineClient->queryRootContexts(engineClient->engines()[0].debugId, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result()))); + + auto contexts = engineClient->rootContext().contexts; + QCOMPARE(contexts.count(), 1); + auto objects = contexts[0].objects; + QCOMPARE(objects.count(), 1); + engineClient->queryObjectRecursive(objects[0], &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result()))); + auto object = engineClient->object(); + + // "a" accessible in context of surrounding object + client->evaluate(QLatin1String("a + 10"), -1, object.debugId); + QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + + QString jsonString = client->response; + QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + QTRY_COMPARE(body.value("value").toInt(), 20); +} + void tst_QQmlDebugJS::getScripts() { //void scripts(int types = -1, QList<int> ids = QList<int>(), bool includeSource = false, QVariant filter = QVariant()); diff --git a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp index a503da4e4b..8d21a8a45a 100644 --- a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp +++ b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp @@ -51,12 +51,6 @@ private: QQmlDebugConnection *m_conn; QQmlDebugTestService *m_service; - bool connect(); - -signals: - void waiting(); - void parallel(); - private slots: void initTestCase(); @@ -75,12 +69,13 @@ void tst_QQmlDebugLocal::initTestCase() const QString waitingMsg = QString("QML Debugger: Connecting to socket %1...").arg(fileName); QTest::ignoreMessage(QtDebugMsg, waitingMsg.toLatin1().constData()); + QQmlDebuggingEnabler::connectToLocalDebugger(fileName); + + QTest::qWait(1000); m_conn = new QQmlDebugConnection(this); m_conn->startLocalServer(fileName); - QQmlDebuggingEnabler::connectToLocalDebugger(fileName); - new QQmlEngine(this); QQmlDebugTestClient client("tst_QQmlDebugLocal::handshake()", m_conn); diff --git a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp index a23b7e37eb..6793596174 100644 --- a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp @@ -41,6 +41,7 @@ #include <private/qv4isel_moth_p.h> #include <private/qv4string_p.h> #include <private/qqmlbuiltinfunctions_p.h> +#include <private/qqmldebugservice_p.h> using namespace QV4; using namespace QV4::Debugging; @@ -203,8 +204,8 @@ public slots: while (!m_expressionRequests.isEmpty()) { Q_ASSERT(debugger->state() == QV4Debugger::Paused); ExpressionRequest request = m_expressionRequests.takeFirst(); - ExpressionEvalJob job(debugger->engine(), request.frameNr, request.expression, - &collector); + ExpressionEvalJob job(debugger->engine(), request.frameNr, request.context, + request.expression, &collector); debugger->runInEngine(&job); m_expressionResults << job.returnValue(); m_expressionRefs << job.refs(); @@ -276,6 +277,7 @@ public: struct ExpressionRequest { QString expression; int frameNr; + int context; }; QVector<ExpressionRequest> m_expressionRequests; QList<QJsonObject> m_expressionResults; @@ -726,24 +728,34 @@ void tst_qv4debugger::evaluateExpression() TestAgent::ExpressionRequest request; request.expression = "x"; request.frameNr = 0; + request.context = -1; // no extra context m_debuggerAgent->m_expressionRequests << request; request.expression = "x"; request.frameNr = 1; m_debuggerAgent->m_expressionRequests << request; + request.context = 5355; // invalid context object + m_debuggerAgent->m_expressionRequests << request; + + QObject object; // some object without QML context + request.context = QQmlDebugService::idForObject(&object); + m_debuggerAgent->m_expressionRequests << request; + debugger()->addBreakPoint("evaluateExpression", 3); evaluateJavaScript(script, "evaluateExpression"); - QCOMPARE(m_debuggerAgent->m_expressionRefs.count(), 2); + QCOMPARE(m_debuggerAgent->m_expressionRefs.count(), 4); QCOMPARE(m_debuggerAgent->m_expressionRefs[0].size(), 1); QJsonObject result0 = m_debuggerAgent->m_expressionRefs[0].first().toObject(); QCOMPARE(result0.value("type").toString(), QStringLiteral("number")); QCOMPARE(result0.value("value").toInt(), 10); - QCOMPARE(m_debuggerAgent->m_expressionRefs[1].size(), 1); - QJsonObject result1 = m_debuggerAgent->m_expressionRefs[1].first().toObject(); - QCOMPARE(result1.value("type").toString(), QStringLiteral("number")); - QCOMPARE(result1.value("value").toInt(), 20); + for (int i = 1; i < 4; ++i) { + QCOMPARE(m_debuggerAgent->m_expressionRefs[i].size(), 1); + QJsonObject result1 = m_debuggerAgent->m_expressionRefs[1].first().toObject(); + QCOMPARE(result1.value("type").toString(), QStringLiteral("number")); + QCOMPARE(result1.value("value").toInt(), 20); + } } QTEST_MAIN(tst_qv4debugger) diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 52df4c0642..82bc3d0c59 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -1040,6 +1040,8 @@ void tst_QJSEngine::builtinFunctionNames_data() QTest::newRow("Array.prototype.toString") << QString("Array.prototype.toString") << QString("toString"); QTest::newRow("Array.prototype.toLocaleString") << QString("Array.prototype.toLocaleString") << QString("toLocaleString"); QTest::newRow("Array.prototype.concat") << QString("Array.prototype.concat") << QString("concat"); + QTest::newRow("Array.prototype.find") << QString("Array.prototype.find") << QString("find"); + QTest::newRow("Array.prototype.findIndex") << QString("Array.prototype.findIndex") << QString("findIndex"); QTest::newRow("Array.prototype.join") << QString("Array.prototype.join") << QString("join"); QTest::newRow("Array.prototype.pop") << QString("Array.prototype.pop") << QString("pop"); QTest::newRow("Array.prototype.push") << QString("Array.prototype.push") << QString("push"); @@ -2149,12 +2151,27 @@ void tst_QJSEngine::jsNumberClass() QJSValue ret = eng.evaluate("new Number(123).toExponential()"); QVERIFY(ret.isString()); QCOMPARE(ret.toString(), QString::fromLatin1("1.23e+2")); + ret = eng.evaluate("new Number(123).toExponential(1)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("1.2e+2")); + ret = eng.evaluate("new Number(123).toExponential(2)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("1.23e+2")); + ret = eng.evaluate("new Number(123).toExponential(3)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("1.230e+2")); } QVERIFY(proto.property("toFixed").isCallable()); { QJSValue ret = eng.evaluate("new Number(123).toFixed()"); QVERIFY(ret.isString()); QCOMPARE(ret.toString(), QString::fromLatin1("123")); + ret = eng.evaluate("new Number(123).toFixed(1)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("123.0")); + ret = eng.evaluate("new Number(123).toFixed(2)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("123.00")); } QVERIFY(proto.property("toPrecision").isCallable()); { diff --git a/tests/auto/qml/qqmlmoduleplugin/data/works22.qml b/tests/auto/qml/qqmlmoduleplugin/data/works22.qml new file mode 100644 index 0000000000..571a7e754d --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/data/works22.qml @@ -0,0 +1,3 @@ +import org.qtproject.AutoTestQmlPluginType 2.2 + +MyPluginType { valueOnlyIn2: 123 } diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.2.2.pro b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.2.2.pro new file mode 100644 index 0000000000..eec5f23a7b --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.2.2.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +CONFIG += plugin +SOURCES = plugin.cpp +QT = core qml +DESTDIR = ../imports/org/qtproject/AutoTestQmlPluginType.2.2 + +QT += core-private gui-private qml-private + +IMPORT_FILES = \ + qmldir + +include (../../../shared/imports.pri) diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.cpp b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.cpp new file mode 100644 index 0000000000..ecec870374 --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QStringList> +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QDebug> + +class MyPluginType : public QObject +{ + Q_OBJECT + Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int valueOnlyIn2 READ value WRITE setValue) + +public: + MyPluginType(QObject *parent=0) : QObject(parent) + { + qWarning("import2.2 worked"); + } + + int value() const { return v; } + void setValue(int i) { v = i; } + +private: + int v; +}; + + +class MyPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + MyPlugin() + { + qWarning("plugin2.2 created"); + } + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "org.qtproject.AutoTestQmlPluginType"); + qmlRegisterType<MyPluginType>(uri, 2, 0, "MyPluginType"); + qmlRegisterModule(uri, 2, 2); + } +}; + +#include "plugin.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/qmldir b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/qmldir new file mode 100644 index 0000000000..0a8b5d46eb --- /dev/null +++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/qmldir @@ -0,0 +1 @@ +plugin plugin diff --git a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro index 889968f6cc..0f548aa6f8 100644 --- a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro +++ b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro @@ -20,7 +20,8 @@ SUBDIRS =\ protectedModule\ plugin/childplugin\ plugin.2/childplugin\ - plugin.2.1/childplugin + plugin.2.1/childplugin\ + plugin.2.2 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 265492b435..8600e1e8ab 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -52,8 +52,7 @@ public: private slots: virtual void initTestCase(); void importsPlugin(); - void importsPlugin2(); - void importsPlugin21(); + void importsPlugin_data(); void importsMixedQmlCppPlugin(); void incorrectPluginCase(); void importPluginWithQmlFile(); @@ -70,6 +69,7 @@ private slots: void importStrictModule(); void importStrictModule_data(); void importProtectedModule(); + void importVersionedModule(); void importsChildPlugin(); void importsChildPlugin2(); void importsChildPlugin21(); @@ -130,29 +130,15 @@ void tst_qqmlmoduleplugin::initTestCase() void tst_qqmlmoduleplugin::importsPlugin() { - QQmlEngine engine; - engine.addImportPath(m_importsDirectory); - QTest::ignoreMessage(QtWarningMsg, "plugin created"); - QTest::ignoreMessage(QtWarningMsg, "import worked"); - QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType' does not contain a module identifier directive - it cannot be protected from external registrations."); - QQmlComponent component(&engine, testFileUrl(QStringLiteral("works.qml"))); - foreach (QQmlError err, component.errors()) - qWarning() << err; - VERIFY_ERRORS(0); - QObject *object = component.create(); - QVERIFY(object != 0); - QCOMPARE(object->property("value").toInt(),123); - delete object; -} + QFETCH(QString, suffix); + QFETCH(QString, qmlFile); -void tst_qqmlmoduleplugin::importsPlugin2() -{ QQmlEngine engine; engine.addImportPath(m_importsDirectory); - QTest::ignoreMessage(QtWarningMsg, "plugin2 created"); - QTest::ignoreMessage(QtWarningMsg, "import2 worked"); + QTest::ignoreMessage(QtWarningMsg, qPrintable(QString("plugin%1 created").arg(suffix))); + QTest::ignoreMessage(QtWarningMsg, qPrintable(QString("import%1 worked").arg(suffix))); QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType' does not contain a module identifier directive - it cannot be protected from external registrations."); - QQmlComponent component(&engine, testFileUrl(QStringLiteral("works2.qml"))); + QQmlComponent component(&engine, testFileUrl(qmlFile)); foreach (QQmlError err, component.errors()) qWarning() << err; VERIFY_ERRORS(0); @@ -162,21 +148,15 @@ void tst_qqmlmoduleplugin::importsPlugin2() delete object; } -void tst_qqmlmoduleplugin::importsPlugin21() +void tst_qqmlmoduleplugin::importsPlugin_data() { - QQmlEngine engine; - engine.addImportPath(m_importsDirectory); - QTest::ignoreMessage(QtWarningMsg, "plugin2.1 created"); - QTest::ignoreMessage(QtWarningMsg, "import2.1 worked"); - QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType' does not contain a module identifier directive - it cannot be protected from external registrations."); - QQmlComponent component(&engine, testFileUrl(QStringLiteral("works21.qml"))); - foreach (QQmlError err, component.errors()) - qWarning() << err; - VERIFY_ERRORS(0); - QObject *object = component.create(); - QVERIFY(object != 0); - QCOMPARE(object->property("value").toInt(),123); - delete object; + QTest::addColumn<QString>("suffix"); + QTest::addColumn<QString>("qmlFile"); + + QTest::newRow("1.0") << "" << "works.qml"; + QTest::newRow("2.0") << "2" << "works2.qml"; + QTest::newRow("2.1") << "2.1" << "works21.qml"; + QTest::newRow("2.2") << "2.2" << "works22.qml"; } void tst_qqmlmoduleplugin::incorrectPluginCase() @@ -578,6 +558,32 @@ void tst_qqmlmoduleplugin::importProtectedModule() QVERIFY(object != 0); } +void tst_qqmlmoduleplugin::importVersionedModule() +{ + qmlRegisterType<QObject>("org.qtproject.VersionedModule", 1, 0, "TestType"); + qmlRegisterModule("org.qtproject.VersionedModule", 1, 1); + + QQmlEngine engine; + engine.addImportPath(m_importsDirectory); + + QUrl url(testFileUrl("empty.qml")); + + QQmlComponent component(&engine); + component.setData("import org.qtproject.VersionedModule 1.0\n TestType {}\n", url); + QScopedPointer<QObject> object10(component.create()); + QVERIFY(!object10.isNull()); + + component.setData("import org.qtproject.VersionedModule 1.1\n TestType {}\n", url); + QScopedPointer<QObject> object11(component.create()); + QVERIFY(!object11.isNull()); + + component.setData("import org.qtproject.VersionedModule 1.2\n TestType {}\n", url); + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); + QScopedPointer<QObject> object12(component.create()); + QVERIFY(object12.isNull()); + QCOMPARE(component.errorString(), QString("%1:1 module \"org.qtproject.VersionedModule\" version 1.2 is not installed\n").arg(url.toString())); +} + void tst_qqmlmoduleplugin::importsChildPlugin() { QQmlEngine engine; |