diff options
Diffstat (limited to 'tests/auto/qml')
45 files changed, 527 insertions, 72 deletions
diff --git a/tests/auto/qml/debugger/qdebugmessageservice/qdebugmessageservice.pro b/tests/auto/qml/debugger/qdebugmessageservice/qdebugmessageservice.pro index 9cf323ba36..3f2c0ca390 100644 --- a/tests/auto/qml/debugger/qdebugmessageservice/qdebugmessageservice.pro +++ b/tests/auto/qml/debugger/qdebugmessageservice/qdebugmessageservice.pro @@ -1,6 +1,6 @@ CONFIG += testcase TARGET = tst_qdebugmessageservice -QT += qml network testlib gui-private core-private +QT += network testlib gui-private core-private osx:CONFIG -= app_bundle SOURCES += tst_qdebugmessageservice.cpp diff --git a/tests/auto/qml/debugger/qpacketprotocol/qpacketprotocol.pro b/tests/auto/qml/debugger/qpacketprotocol/qpacketprotocol.pro index b1e3835844..dc0120cd87 100644 --- a/tests/auto/qml/debugger/qpacketprotocol/qpacketprotocol.pro +++ b/tests/auto/qml/debugger/qpacketprotocol/qpacketprotocol.pro @@ -6,4 +6,4 @@ SOURCES += tst_qpacketprotocol.cpp include(../shared/debugutil.pri) -QT += qml network testlib gui-private core-private +QT += network testlib gui-private core-private diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/data/encodeQmlScope.qml b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/data/encodeQmlScope.qml new file mode 100644 index 0000000000..7ea048044f --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/data/encodeQmlScope.qml @@ -0,0 +1,19 @@ +import QtQuick 2.0 + +Item { + property int a: 0 + property int b: 0 + onAChanged: console.log("inline") + onBChanged: { + console.log("extra braces"); + } + + Timer { + interval: 10 + running: true + onTriggered: { + parent.a += 10; + parent.b -= 10; + } + } +} diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro index 90623c75a6..52d70bd1b1 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro +++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro @@ -20,4 +20,5 @@ OTHER_FILES += data/test.qml data/test.js \ data/changeBreakpoint.qml \ data/stepAction.qml \ data/breakpointRelocation.qml \ - data/createComponent.qml + data/createComponent.qml \ + data/encodeQmlScope.qml diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp index 3cd359cf48..660afce216 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp +++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp @@ -124,6 +124,7 @@ const char *QUIT_QMLFILE = "quit.qml"; const char *CHANGEBREAKPOINT_QMLFILE = "changeBreakpoint.qml"; const char *STEPACTION_QMLFILE = "stepAction.qml"; const char *BREAKPOINTRELOCATION_QMLFILE = "breakpointRelocation.qml"; +const char *ENCODEQMLSCOPE_QMLFILE = "encodeQmlScope.qml"; #define VARIANTMAPINIT \ QString obj("{}"); \ @@ -217,6 +218,8 @@ private slots: void getScripts_data() { targetData(); } void getScripts(); + void encodeQmlScope(); + private: ConnectResult init(bool qmlscene, const QString &qmlFile = QString(TEST_QMLFILE), bool blockMode = true, bool restrictServices = false); @@ -1455,6 +1458,70 @@ void tst_QQmlDebugJS::getScripts() QVERIFY(scripts.first().toMap()[QStringLiteral("name")].toString().endsWith(QStringLiteral("data/test.qml"))); } +void tst_QQmlDebugJS::encodeQmlScope() +{ + QString file(ENCODEQMLSCOPE_QMLFILE); + QCOMPARE(init(true, file), ConnectSuccess); + + int numFrames = 0; + int numExpectedScopes = 0; + int numReceivedScopes = 0; + bool isStopped = false; + bool scopesFailed = false; + + QObject::connect(m_client, &QJSDebugClient::failure, this, [&]() { + qWarning() << "received failure" << m_client->response; + scopesFailed = true; + m_process->stop(); + numFrames = 2; + isStopped = false; + }); + + QObject::connect(m_client, &QJSDebugClient::stopped, this, [&]() { + m_client->frame(); + isStopped = true; + }); + + QObject::connect(m_client, &QJSDebugClient::result, this, [&]() { + const QVariantMap value = m_client->parser.call( + QJSValueList() << QJSValue(QString(m_client->response))).toVariant().toMap(); + + const QMap<QString, QVariant> body = value.value("body").toMap(); + const QString command = value.value("command").toString(); + + if (command == QString("scope")) { + // If the scope commands fail we get a failure() signal above. + if (++numReceivedScopes == numExpectedScopes) { + m_client->continueDebugging(QJSDebugClient::Continue); + isStopped = false; + } + } else if (command == QString("frame")) { + + // We want at least a global scope and some kind of local scope here. + const QList<QVariant> scopes = body.value("scopes").toList(); + if (scopes.length() < 2) + scopesFailed = true; + + for (const QVariant &scope : scopes) { + ++numExpectedScopes; + m_client->scope(scope.toMap().value("index").toInt()); + } + + ++numFrames; + } + }); + + m_client->setBreakpoint(file, 6); + m_client->setBreakpoint(file, 8); + m_client->connect(); + + QTRY_COMPARE(numFrames, 2); + QVERIFY(numExpectedScopes > 3); + QVERIFY(!scopesFailed); + QTRY_VERIFY(!isStopped); + QCOMPARE(numReceivedScopes, numExpectedScopes); +} + QList<QQmlDebugClient *> tst_QQmlDebugJS::createClients() { m_client = new QJSDebugClient(m_connection); diff --git a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp index 9f0501241d..5b3c0c5240 100644 --- a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp +++ b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp @@ -32,7 +32,6 @@ #include <private/qqmldebugconnector_p.h> #include <private/qqmldebugconnection_p.h> -#include <QtQml/qqmldebug.h> #include <QtQml/qqmlengine.h> #include <QtTest/qtest.h> diff --git a/tests/auto/qml/debugger/qqmlenginecontrol/qqmlenginecontrol.pro b/tests/auto/qml/debugger/qqmlenginecontrol/qqmlenginecontrol.pro index 73455bd903..36957628b2 100644 --- a/tests/auto/qml/debugger/qqmlenginecontrol/qqmlenginecontrol.pro +++ b/tests/auto/qml/debugger/qqmlenginecontrol/qqmlenginecontrol.pro @@ -8,7 +8,7 @@ include(../shared/debugutil.pri) TESTDATA = data/* -QT += core qml testlib gui-private core-private +QT += core testlib gui-private core-private OTHER_FILES += \ data/test.qml \ diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro index 5f58e5ec7f..54244c6d16 100644 --- a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro +++ b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro @@ -1,7 +1,7 @@ CONFIG += testcase TARGET = tst_qqmlenginedebuginspectorintegration -QT += qml testlib gui-private core-private +QT += testlib gui-private core-private osx:CONFIG -= app_bundle SOURCES += tst_qqmlenginedebuginspectorintegration.cpp diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro index 33ee023c06..ed4224446e 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro @@ -10,4 +10,4 @@ include(../shared/debugutil.pri) DEFINES += QT_QML_DEBUG_NO_WARNING -QT += core-private qml-private quick-private testlib gui-private +QT += quick qml-private testlib diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index 89217e7556..417b75e760 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -53,6 +53,9 @@ #include <QtCore/qdebug.h> #include <QtCore/qthread.h> #include <QtCore/qabstractitemmodel.h> +#include <QtCore/qjsonobject.h> +#include <QtCore/qjsonarray.h> +#include <QtCore/qjsondocument.h> #define QVERIFYOBJECT(statement) \ do {\ @@ -82,6 +85,40 @@ public: QModelIndex modelIndex() { return QModelIndex(); } }; +class JsonTest : public QObject +{ + Q_OBJECT + Q_PROPERTY(QJsonObject data READ data WRITE setData NOTIFY dataChanged) + +public: + JsonTest(QObject *parent = 0) : QObject(parent) + { + m_data["foo"] = QJsonValue(12); + m_data["ttt"] = QJsonArray({4, 5, 4, 3, 2}); + m_data["a"] = QJsonValue(QJsonValue::Null); + m_data["b"] = QJsonValue(QJsonValue::Undefined); + m_data["c"] = QJsonValue("fffff"); + } + + QJsonObject data() const { return m_data; } + +signals: + void dataChanged(const QJsonObject &data); + +public slots: + void setData(const QJsonObject &data) + { + if (data != m_data) { + m_data = data; + emit dataChanged(data); + } + } + +private: + QJsonObject m_data; +}; + + class tst_QQmlEngineDebugService : public QObject { Q_OBJECT @@ -139,6 +176,7 @@ private slots: void regression_QTCREATORBUG_7451(); void queryObjectWithNonStreamableTypes(); + void jsonData(); void asynchronousCreate(); void invalidContexts(); void createObjectOnDestruction(); @@ -363,6 +401,11 @@ void tst_QQmlEngineDebugService::initTestCase() "CustomTypes {}" ; + qmlRegisterType<JsonTest>("JsonTest", 1, 0, "JsonTest"); + qml << "import JsonTest 1.0\n" + "JsonTest {}" + ; + for (int i=0; i<qml.count(); i++) { QQmlComponent component(m_engine); component.setData(qml[i], QUrl::fromLocalFile("")); @@ -676,7 +719,7 @@ void tst_QQmlEngineDebugService::queryRootContexts() // root context query sends only root object data - it doesn't fill in // the children or property info QCOMPARE(context.objects.count(), 0); - QCOMPARE(context.contexts.count(), 6); + QCOMPARE(context.contexts.count(), 7); QVERIFY(context.contexts[0].debugId >= 0); QCOMPARE(context.contexts[0].name, QString("tst_QQmlDebug_childContext")); } @@ -915,6 +958,24 @@ void tst_QQmlEngineDebugService::queryObjectWithNonStreamableTypes() QVariant(QLatin1String("QModelIndex()"))); } +void tst_QQmlEngineDebugService::jsonData() +{ + bool success; + + QmlDebugObjectReference rootObject = findRootObject(5, true); + QVERIFY(!rootObject.className.isEmpty()); + + m_dbg->queryObject(rootObject, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + + QmlDebugObjectReference obj = m_dbg->object(); + QVERIFY(!obj.className.isEmpty()); + + QCOMPARE(findProperty(obj.properties, "data").value, + QJsonDocument::fromJson("{\"a\":null,\"c\":\"fffff\",\"foo\":12,\"ttt\":[4,5,4,3,2]}") + .toVariant()); +} void tst_QQmlEngineDebugService::queryExpressionResult() { diff --git a/tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro b/tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro index fd07255ae5..3d4473c693 100644 --- a/tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro +++ b/tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro @@ -1,7 +1,7 @@ CONFIG += testcase TARGET = tst_qqmlinspector -QT += qml testlib gui-private core-private +QT += testlib gui-private core-private osx:CONFIG -= app_bundle SOURCES += tst_qqmlinspector.cpp diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro b/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro index 7c78b5fcb3..2a685ed877 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro +++ b/tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro @@ -8,7 +8,7 @@ include(../shared/debugutil.pri) TESTDATA = data/* -QT += core qml testlib testlib-private gui-private core-private +QT += testlib gui-private OTHER_FILES += \ data/pixmapCacheTest.qml \ diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp index 562804bc45..3cb315b355 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp +++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp @@ -34,13 +34,12 @@ #include <private/qqmldebugconnection_p.h> #include <QtTest/qtest.h> -#include <private/qtestresult_p.h> #include <QtCore/qlibraryinfo.h> #include <QtGui/private/qguiapplication_p.h> #include <QtGui/qpa/qplatformintegration.h> -class QQmlProfilerTestClient : public QQmlProfilerEventReceiver, public QQmlProfilerDefinitions +class QQmlProfilerTestClient : public QQmlProfilerEventReceiver { Q_OBJECT @@ -229,8 +228,8 @@ private: bool m_isComplete = false; // Don't use ({...}) here as MSVC will interpret that as the "QVector(int size)" ctor. - const QVector<qint64> m_rangeStart = (QVector<qint64>() << QQmlProfilerDefinitions::RangeStart); - const QVector<qint64> m_rangeEnd = (QVector<qint64>() << QQmlProfilerDefinitions::RangeEnd); + const QVector<qint64> m_rangeStart = (QVector<qint64>() << RangeStart); + const QVector<qint64> m_rangeEnd = (QVector<qint64>() << RangeEnd); }; #define VERIFY(type, position, expected, checks, numbers) \ @@ -247,7 +246,7 @@ QQmlDebugTest::ConnectResult tst_QQmlProfilerService::connect( // ### Still using qmlscene due to QTBUG-33377 return QQmlDebugTest::connect( QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", - restrictServices ? QQmlDebuggingEnabler::profilerServices().join(',') : QString(), + restrictServices ? "CanvasFrameRate,EngineControl,DebugMessages" : QString(), testFile(file), block); } @@ -272,15 +271,11 @@ void tst_QQmlProfilerService::checkTraceReceived() QVector<qint64> numbers; // must start with "StartTrace" - QQmlProfilerEventType expected(QQmlProfilerDefinitions::Event, - QQmlProfilerDefinitions::MaximumRangeType, - QQmlProfilerDefinitions::StartTrace); + QQmlProfilerEventType expected(Event, MaximumRangeType, StartTrace); VERIFY(MessageListAsynchronous, 0, expected, CheckMessageType | CheckDetailType, numbers); // must end with "EndTrace" - expected = QQmlProfilerEventType(QQmlProfilerDefinitions::Event, - QQmlProfilerDefinitions::MaximumRangeType, - QQmlProfilerDefinitions::EndTrace); + expected = QQmlProfilerEventType(Event, MaximumRangeType, EndTrace); VERIFY(MessageListAsynchronous, m_client->asynchronousMessages.length() - 1, expected, CheckMessageType | CheckDetailType, numbers); } @@ -299,15 +294,15 @@ void tst_QQmlProfilerService::checkJsHeap() const qint64 amount = message.number<qint64>(0); const QQmlProfilerEventType &type = m_client->types.at(message.typeIndex()); switch (type.detailType()) { - case QV4::Profiling::HeapPage: + case HeapPage: allocated += amount; seen_alloc = true; break; - case QV4::Profiling::SmallItem: + case SmallItem: used += amount; seen_small = true; break; - case QV4::Profiling::LargeItem: + case LargeItem: allocated += amount; used += amount; seen_large = true; @@ -548,28 +543,27 @@ void tst_QQmlProfilerService::pixmapCacheData() checkTraceReceived(); checkJsHeap(); - auto createType = [](QQmlProfilerDefinitions::PixmapEventType type) { - return QQmlProfilerEventType(QQmlProfilerDefinitions::PixmapCacheEvent, - QQmlProfilerDefinitions::MaximumRangeType, type); + auto createType = [](PixmapEventType type) { + return QQmlProfilerEventType(PixmapCacheEvent, MaximumRangeType, type); }; QVector<qint64> numbers; // image starting to load - VERIFY(MessageListPixmap, 0, createType(QQmlProfilerDefinitions::PixmapLoadingStarted), + VERIFY(MessageListPixmap, 0, createType(PixmapLoadingStarted), CheckMessageType | CheckDetailType, numbers); // image size numbers = QVector<qint64>({2, 2, 1}); - VERIFY(MessageListPixmap, 1, createType(QQmlProfilerDefinitions::PixmapSizeKnown), + VERIFY(MessageListPixmap, 1, createType(PixmapSizeKnown), CheckMessageType | CheckDetailType | CheckNumbers, numbers); // image loaded - VERIFY(MessageListPixmap, 2, createType(QQmlProfilerDefinitions::PixmapLoadingFinished), + VERIFY(MessageListPixmap, 2, createType(PixmapLoadingFinished), CheckMessageType | CheckDetailType, numbers); // cache size - VERIFY(MessageListPixmap, 3, createType(QQmlProfilerDefinitions::PixmapCacheCountChanged), + VERIFY(MessageListPixmap, 3, createType(PixmapCacheCountChanged), CheckMessageType | CheckDetailType, numbers); } @@ -597,8 +591,8 @@ void tst_QQmlProfilerService::scenegraphData() if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) { foreach (const QQmlProfilerEvent &msg, m_client->asynchronousMessages) { const QQmlProfilerEventType &type = m_client->types.at(msg.typeIndex()); - if (type.message() == QQmlProfilerDefinitions::SceneGraphFrame) { - if (type.detailType() == QQmlProfilerDefinitions::SceneGraphContextFrame) { + if (type.message() == SceneGraphFrame) { + if (type.detailType() == SceneGraphContextFrame) { contextFrameTime = msg.timestamp(); break; } @@ -610,7 +604,7 @@ void tst_QQmlProfilerService::scenegraphData() #endif foreach (const QQmlProfilerEvent &msg, m_client->asynchronousMessages) { const QQmlProfilerEventType &type = m_client->types.at(msg.typeIndex()); - if (type.detailType() == QQmlProfilerDefinitions::SceneGraphRendererFrame) { + if (type.detailType() == SceneGraphRendererFrame) { QVERIFY(msg.timestamp() >= contextFrameTime); renderFrameTime = msg.timestamp(); break; @@ -621,7 +615,7 @@ void tst_QQmlProfilerService::scenegraphData() foreach (const QQmlProfilerEvent &msg, m_client->asynchronousMessages) { const QQmlProfilerEventType &type = m_client->types.at(msg.typeIndex()); - if (type.detailType() == QQmlProfilerDefinitions::SceneGraphRenderLoopFrame) { + if (type.detailType() == SceneGraphRenderLoopFrame) { if (msg.timestamp() >= contextFrameTime) { // Make sure SceneGraphRenderLoopFrame is not between SceneGraphContextFrame and // SceneGraphRendererFrame. A SceneGraphRenderLoopFrame before everything else is @@ -664,8 +658,7 @@ void tst_QQmlProfilerService::signalSourceLocation() auto createType = [](int line, int column) { return QQmlProfilerEventType( - QQmlProfilerDefinitions::MaximumMessage, - QQmlProfilerDefinitions::HandlingSignal, -1, + MaximumMessage, HandlingSignal, -1, QQmlProfilerEventLocation(QLatin1String("signalSourceLocation.qml"), line, column)); }; @@ -684,23 +677,21 @@ void tst_QQmlProfilerService::javascript() checkTraceReceived(); checkJsHeap(); - VERIFY(MessageListJavaScript, 2, QQmlProfilerEventType(QQmlProfilerDefinitions::MaximumMessage, - QQmlProfilerDefinitions::Javascript), + VERIFY(MessageListJavaScript, 2, QQmlProfilerEventType(MaximumMessage, Javascript), CheckMessageType | CheckDetailType | CheckNumbers, m_rangeStart); VERIFY(MessageListJavaScript, 3, - QQmlProfilerEventType(QQmlProfilerDefinitions::MaximumMessage, - QQmlProfilerDefinitions::Javascript, -1, - QQmlProfilerEventLocation(QLatin1String("javascript.qml"), 4, 5)), + QQmlProfilerEventType( + MaximumMessage, Javascript, -1, + QQmlProfilerEventLocation(QLatin1String("javascript.qml"), 4, 5)), CheckType | CheckNumbers, m_rangeStart); VERIFY(MessageListJavaScript, 4, QQmlProfilerEventType( - QQmlProfilerDefinitions::MaximumMessage, QQmlProfilerDefinitions::Javascript, -1, + MaximumMessage, Javascript, -1, QQmlProfilerEventLocation(), QLatin1String("something")), CheckMessageType | CheckDetailType | CheckDataEndsWith | CheckNumbers, m_rangeStart); - VERIFY(MessageListJavaScript, 10, QQmlProfilerEventType(QQmlProfilerDefinitions::MaximumMessage, - QQmlProfilerDefinitions::Javascript), + VERIFY(MessageListJavaScript, 10, QQmlProfilerEventType(MaximumMessage, Javascript), CheckMessageType | CheckDetailType | CheckNumbers, m_rangeEnd); } @@ -726,8 +717,7 @@ void tst_QQmlProfilerService::translationBinding() checkTraceReceived(); checkJsHeap(); - const QQmlProfilerEventType type(QQmlProfilerDefinitions::MaximumMessage, - QQmlProfilerDefinitions::Binding); + const QQmlProfilerEventType type(MaximumMessage, Binding); VERIFY(MessageListQML, 4, type, CheckDetailType | CheckMessageType | CheckNumbers, m_rangeStart); @@ -746,7 +736,7 @@ void tst_QQmlProfilerService::memory() int smallItems = 0; for (auto message : m_client->jsHeapMessages) { const QQmlProfilerEventType &type = m_client->types[message.typeIndex()]; - if (type.detailType() == QV4::Profiling::SmallItem) + if (type.detailType() == SmallItem) ++smallItems; } @@ -756,8 +746,7 @@ void tst_QQmlProfilerService::memory() static bool hasCompileEvents(const QVector<QQmlProfilerEventType> &types) { for (const QQmlProfilerEventType &type : types) { - if (type.message() == QQmlProfilerDefinitions::MaximumMessage - && type.rangeType() == QQmlProfilerDefinitions::Compiling) + if (type.message() == MaximumMessage && type.rangeType() == Compiling) return true; } return false; @@ -776,29 +765,29 @@ void tst_QQmlProfilerService::compile() checkTraceReceived(); checkJsHeap(); - QQmlProfilerDefinitions::Message rangeStage = QQmlProfilerDefinitions::MaximumMessage; + Message rangeStage = MaximumMessage; for (auto message : m_client->qmlMessages) { const QQmlProfilerEventType &type = m_client->types[message.typeIndex()]; - if (type.rangeType() == QQmlProfilerDefinitions::Compiling) { + if (type.rangeType() == Compiling) { switch (rangeStage) { - case QQmlProfilerDefinitions::MaximumMessage: - QCOMPARE(message.rangeStage(), QQmlProfilerDefinitions::RangeStart); + case MaximumMessage: + QCOMPARE(message.rangeStage(), RangeStart); break; - case QQmlProfilerDefinitions::RangeStart: - QCOMPARE(message.rangeStage(), QQmlProfilerDefinitions::RangeEnd); + case RangeStart: + QCOMPARE(message.rangeStage(), RangeEnd); break; default: QFAIL("Wrong range stage"); } rangeStage = message.rangeStage(); - QCOMPARE(type.message(), QQmlProfilerDefinitions::MaximumMessage); + QCOMPARE(type.message(), MaximumMessage); QCOMPARE(type.location().filename(), testFileUrl("test.qml").toString()); QCOMPARE(type.location().line(), 0); QCOMPARE(type.location().column(), 0); } } - QCOMPARE(rangeStage, QQmlProfilerDefinitions::RangeEnd); + QCOMPARE(rangeStage, RangeEnd); } QTEST_MAIN(tst_QQmlProfilerService) diff --git a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp index 4ce0f9fd89..c65c592f10 100644 --- a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp @@ -297,6 +297,7 @@ private slots: // context access: void readArguments_data() { redundancy_data(); } void readArguments(); + void readComplicatedArguments(); void readLocals_data() { redundancy_data(); } void readLocals(); void readObject_data() { redundancy_data(); } @@ -549,6 +550,27 @@ void tst_qv4debugger::readArguments() QCOMPARE(frame0.value(QStringLiteral("b")).toString(), QStringLiteral("two")); } +void tst_qv4debugger::readComplicatedArguments() +{ + m_debuggerAgent->collector.setRedundantRefs(false); + m_debuggerAgent->m_captureContextInfo = true; + QString script = + "var f = function(a) {\n" + " a = 12;\n" + " return a;\n" + "}\n" + "f(1, 2);\n"; + debugger()->addBreakPoint("readArguments", 3); + evaluateJavaScript(script, "readArguments"); + QVERIFY(m_debuggerAgent->m_wasPaused); + QVERIFY(m_debuggerAgent->m_capturedScope.size() > 1); + const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedScope.at(0); + QCOMPARE(frame0.size(), 1); + QVERIFY(frame0.contains(QStringLiteral("a"))); + QCOMPARE(frame0.type(QStringLiteral("a")), QStringLiteral("number")); + QCOMPARE(frame0.value(QStringLiteral("a")).toInt(), 12); +} + void tst_qv4debugger::readLocals() { QFETCH(bool, redundantRefs); diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index 8ecbe53822..b118b22c64 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -31,8 +31,6 @@ #include <private/qqmldebugconnection_p.h> -#include <QtQml/qqmldebug.h> - #include <QtCore/qeventloop.h> #include <QtCore/qtimer.h> @@ -52,15 +50,23 @@ bool QQmlDebugTest::waitForSignal(QObject *receiver, const char *member, int tim QList<QQmlDebugClient *> QQmlDebugTest::createOtherClients(QQmlDebugConnection *connection) { QList<QQmlDebugClient *> ret; - foreach (const QString &service, QQmlDebuggingEnabler::debuggerServices()) { + + static const auto debuggerServices + = QStringList({"V8Debugger", "QmlDebugger", "DebugMessages"}); + static const auto inspectorServices + = QStringList({"QmlInspector"}); + static const auto profilerServices + = QStringList({"CanvasFrameRate", "EngineControl", "DebugMessages"}); + + for (const QString &service : debuggerServices) { if (!connection->client(service)) ret << new QQmlDebugClient(service, connection); } - foreach (const QString &service, QQmlDebuggingEnabler::inspectorServices()) { + for (const QString &service : inspectorServices) { if (!connection->client(service)) ret << new QQmlDebugClient(service, connection); } - foreach (const QString &service, QQmlDebuggingEnabler::profilerServices()) { + for (const QString &service : profilerServices) { if (!connection->client(service)) ret << new QQmlDebugClient(service, connection); } diff --git a/tests/auto/qml/ecmascripttests/test262 b/tests/auto/qml/ecmascripttests/test262 -Subproject 40b4f28e98c416a092e26aa17489bf94ccb8bf4 +Subproject e505c11eebe5a389a7d47a4bf570c66469740b0 diff --git a/tests/auto/qml/ecmascripttests/test262.py b/tests/auto/qml/ecmascripttests/test262.py index ae4c54df9d..e055c7a8e7 100755 --- a/tests/auto/qml/ecmascripttests/test262.py +++ b/tests/auto/qml/ecmascripttests/test262.py @@ -555,7 +555,7 @@ def Main(): # Uncomment the next line for more logging info. #logging.basicConfig(level=logging.DEBUG) # Some date tests rely on being run in pacific time and the USA's locale: - os.environ["TZ"] = "America/Vancouver" + os.environ["TZ"] = "America/Los_Angeles" # it *matters* that this is (7m8s) *East* of PST's nominal meridian ! os.environ["LANG"] = "en_US.UTF-8" os.environ["LC_TIME"] = "en_US.UTF-8" parser = BuildOptions() diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index f862cdb048..bb923951a8 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -201,10 +201,13 @@ private slots: void basicBlockMergeAfterLoopPeeling(); + void modulusCrash(); void malformedExpression(); void scriptScopes(); + void protoChanges_QTBUG68369(); + signals: void testSignal(); }; @@ -4135,6 +4138,15 @@ void tst_QJSEngine::basicBlockMergeAfterLoopPeeling() } +void tst_QJSEngine::modulusCrash() +{ + QJSEngine engine; + QJSValue result = engine.evaluate( + "var a = -2147483648; var b = -1; var c = a % b; c;" + ); + QVERIFY(result.isNumber() && result.toNumber() == 0.); +} + void tst_QJSEngine::malformedExpression() { QJSEngine engine; @@ -4157,6 +4169,22 @@ void tst_QJSEngine::scriptScopes() QCOMPARE(use.toInt(), 42); } +void tst_QJSEngine::protoChanges_QTBUG68369() +{ + QJSEngine engine; + QJSValue ok = engine.evaluate( + "var o = { x: true };" + "var p1 = {};" + "var p2 = {};" + "o.__proto__ = p1;" + "o.__proto__ = p2;" + "o.__proto__ = p1;" + "p1.y = true;" + "o.y" + ); + QVERIFY(ok.toBool() == true); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" diff --git a/tests/auto/qml/qmlcachegen/Enums.qml b/tests/auto/qml/qmlcachegen/Enums.qml new file mode 100644 index 0000000000..830babb73e --- /dev/null +++ b/tests/auto/qml/qmlcachegen/Enums.qml @@ -0,0 +1,9 @@ +import QtQml 2.0 +QtObject { + enum Test { + First = 100, + Second = 200 + } + property int value: 0 + Component.onCompleted: value = Enums.Second +} diff --git a/tests/auto/qml/qmlcachegen/jsimport.qml b/tests/auto/qml/qmlcachegen/jsimport.qml new file mode 100644 index 0000000000..9c40878e60 --- /dev/null +++ b/tests/auto/qml/qmlcachegen/jsimport.qml @@ -0,0 +1,6 @@ +import QtQml 2.0 +import "script.js" as Script + +QtObject { + property int value: Script.getter() +} diff --git a/tests/auto/qml/qmlcachegen/library.js b/tests/auto/qml/qmlcachegen/library.js new file mode 100644 index 0000000000..51fb41dc23 --- /dev/null +++ b/tests/auto/qml/qmlcachegen/library.js @@ -0,0 +1,4 @@ + +function getter() { + return 42; +} diff --git a/tests/auto/qml/qmlcachegen/qmlcachegen.pro b/tests/auto/qml/qmlcachegen/qmlcachegen.pro index a2f963e8c3..40de4548a7 100644 --- a/tests/auto/qml/qmlcachegen/qmlcachegen.pro +++ b/tests/auto/qml/qmlcachegen/qmlcachegen.pro @@ -12,4 +12,8 @@ RESOURCES += versionchecks.qml RESOURCES += trickypaths.qrc +RESOURCES += jsimport.qml script.js library.js + +RESOURCES += Enums.qml + QT += core-private qml-private testlib diff --git a/tests/auto/qml/qmlcachegen/script.js b/tests/auto/qml/qmlcachegen/script.js new file mode 100644 index 0000000000..fa55f9069e --- /dev/null +++ b/tests/auto/qml/qmlcachegen/script.js @@ -0,0 +1,6 @@ + +.import "library.js" as Library + +function getter() { + return Library.getter() +} diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp index 5c1692f086..3b7d268f7b 100644 --- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp +++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp @@ -54,6 +54,10 @@ private slots: void workerScripts(); void trickyPaths(); + + void scriptImport(); + + void enums(); }; // A wrapper around QQmlComponent to ensure the temporary reference counts @@ -416,6 +420,24 @@ void tst_qmlcachegen::trickyPaths() QCOMPARE(obj->property("success").toInt(), 42); } +void tst_qmlcachegen::scriptImport() +{ + QQmlEngine engine; + CleanlyLoadingComponent component(&engine, QUrl("qrc:///jsimport.qml")); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QTRY_COMPARE(obj->property("value").toInt(), 42); +} + +void tst_qmlcachegen::enums() +{ + QQmlEngine engine; + CleanlyLoadingComponent component(&engine, QUrl("qrc:///Enums.qml")); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QTRY_COMPARE(obj->property("value").toInt(), 200); +} + QTEST_GUILESS_MAIN(tst_qmlcachegen) #include "tst_qmlcachegen.moc" diff --git a/tests/auto/qml/qqmlcomponent/data/InitialPropertyTest.qml b/tests/auto/qml/qqmlcomponent/data/InitialPropertyTest.qml new file mode 100644 index 0000000000..7de276f2d8 --- /dev/null +++ b/tests/auto/qml/qqmlcomponent/data/InitialPropertyTest.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 +QtObject { + property bool ok: false +} diff --git a/tests/auto/qml/qqmlcomponent/data/nonExistentInitialProperty.qml b/tests/auto/qml/qqmlcomponent/data/nonExistentInitialProperty.qml new file mode 100644 index 0000000000..ef89e46088 --- /dev/null +++ b/tests/auto/qml/qqmlcomponent/data/nonExistentInitialProperty.qml @@ -0,0 +1,9 @@ +import QtQml 2.0 +QtObject { + property Component factory: Qt.createComponent(Qt.resolvedUrl("InitialPropertyTest.qml"), Component.PreferSynchronous) + property var incubator + function startIncubation() + { + incubator = factory.incubateObject(null, { ok: true, nonExistent: 42 }, Qt.Asynchronous) + } +} diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 6a0dc28ca4..3a70890362 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -117,6 +117,7 @@ private slots: void recursion(); void recursionContinuation(); void callingContextForInitialProperties(); + void setNonExistentInitialProperty(); void relativeUrl_data(); void relativeUrl(); @@ -583,6 +584,23 @@ void tst_qqmlcomponent::callingContextForInitialProperties() QVERIFY(checker->scopeObject->metaObject()->indexOfProperty("incubatedObject") != -1); } +void tst_qqmlcomponent::setNonExistentInitialProperty() +{ + QQmlIncubationController controller; + QQmlEngine engine; + engine.setIncubationController(&controller); + QQmlComponent component(&engine, testFileUrl("nonExistentInitialProperty.qml")); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QMetaObject::invokeMethod(obj.data(), "startIncubation"); + QJSValue incubatorStatus = obj->property("incubator").value<QJSValue>(); + incubatorStatus.property("forceCompletion").callWithInstance(incubatorStatus); + QJSValue objectWrapper = incubatorStatus.property("object"); + QVERIFY(objectWrapper.isQObject()); + QPointer<QObject> object(objectWrapper.toQObject()); + QVERIFY(object->property("ok").toBool()); +} + void tst_qqmlcomponent::relativeUrl_data() { QTest::addColumn<QUrl>("url"); diff --git a/tests/auto/qml/qqmlengine/data/qrcurls.js b/tests/auto/qml/qqmlengine/data/qrcurls.js new file mode 100644 index 0000000000..15a4d5a70c --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qrcurls.js @@ -0,0 +1 @@ +function someFunction() {} diff --git a/tests/auto/qml/qqmlengine/data/qrcurls.qml b/tests/auto/qml/qqmlengine/data/qrcurls.qml new file mode 100644 index 0000000000..e879577e10 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qrcurls.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 + +QtObject { +} diff --git a/tests/auto/qml/qqmlengine/qqmlengine.pro b/tests/auto/qml/qqmlengine/qqmlengine.pro index 8d1e149d62..d2eb92bfd5 100644 --- a/tests/auto/qml/qqmlengine/qqmlengine.pro +++ b/tests/auto/qml/qqmlengine/qqmlengine.pro @@ -12,3 +12,7 @@ boot2qt: { # GC corruption test is too heavy for qemu-arm DEFINES += SKIP_GCCORRUPTION_TEST } + +RESOURCES += \ + data/qrcurls.qml \ + data/qrcurls.js diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 52e18011cb..95098648fa 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -77,6 +77,8 @@ private slots: void testGCCorruption(); void testGroupedPropertyRevisions(); void componentFromEval(); + void qrcUrls(); + void cppSignalAndEval(); public slots: QObject *createAQObjectForOwnershipTest () @@ -897,6 +899,63 @@ void tst_qqmlengine::componentFromEval() QVERIFY(!item.isNull()); } +void tst_qqmlengine::qrcUrls() +{ + QQmlEngine engine; + QQmlEnginePrivate *pEngine = QQmlEnginePrivate::get(&engine); + + { + QQmlRefPointer<QQmlTypeData> oneQml(pEngine->typeLoader.getType(QUrl("qrc:/qrcurls.qml")), + QQmlRefPointer<QQmlTypeData>::Adopt); + QVERIFY(oneQml != nullptr); + QQmlRefPointer<QQmlTypeData> twoQml(pEngine->typeLoader.getType(QUrl("qrc:///qrcurls.qml")), + QQmlRefPointer<QQmlTypeData>::Adopt); + QVERIFY(twoQml != nullptr); + QCOMPARE(oneQml, twoQml); + } + + { + QQmlRefPointer<QQmlTypeData> oneJS(pEngine->typeLoader.getType(QUrl("qrc:/qrcurls.js")), + QQmlRefPointer<QQmlTypeData>::Adopt); + QVERIFY(oneJS != nullptr); + QQmlRefPointer<QQmlTypeData> twoJS(pEngine->typeLoader.getType(QUrl("qrc:///qrcurls.js")), + QQmlRefPointer<QQmlTypeData>::Adopt); + QVERIFY(twoJS != nullptr); + QCOMPARE(oneJS, twoJS); + } +} + +class ObjectCaller : public QObject +{ + Q_OBJECT +signals: + void doubleReply(const double a); +}; + +void tst_qqmlengine::cppSignalAndEval() +{ + ObjectCaller objectCaller; + QQmlEngine engine; + engine.rootContext()->setContextProperty(QLatin1Literal("CallerCpp"), &objectCaller); + QQmlComponent c(&engine); + c.setData("import QtQuick 2.9\n" + "Item {\n" + " property var r: 0\n" + " Connections {\n" + " target: CallerCpp;\n" + " onDoubleReply: {\n" + " eval('var z = 1');\n" + " r = a;\n" + " }\n" + " }\n" + "}", + QUrl(QStringLiteral("qrc:/main.qml"))); + QScopedPointer<QObject> object(c.create()); + QVERIFY(!object.isNull()); + emit objectCaller.doubleReply(1.1234); + QCOMPARE(object->property("r"), 1.1234); +} + QTEST_MAIN(tst_qqmlengine) #include "tst_qqmlengine.moc" diff --git a/tests/auto/qml/qqmlinfo/data/Component.qml b/tests/auto/qml/qqmlinfo/data/Component.qml new file mode 100644 index 0000000000..fefbbfae76 --- /dev/null +++ b/tests/auto/qml/qqmlinfo/data/Component.qml @@ -0,0 +1,8 @@ +import QtQml 2.0 + +QtObject { + property Component delegate: Component { + QtObject { + } + } +} diff --git a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp index ada3f9e37b..5ff72de0a0 100644 --- a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp +++ b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp @@ -50,6 +50,7 @@ private slots: void types(); void chaining(); void messageTypes(); + void component(); private: QQmlEngine engine; @@ -216,6 +217,19 @@ void tst_qqmlinfo::messageTypes() qmlWarning(nullptr) << QLatin1String("warning"); } +void tst_qqmlinfo::component() +{ + QQmlComponent component(&engine, testFileUrl("Component.qml")); + QScopedPointer<QObject> object(component.create()); + QVERIFY(object != nullptr); + QQmlComponent *delegate = qobject_cast<QQmlComponent*>(object->property("delegate").value<QObject*>()); + QVERIFY(delegate); + + QString message = component.url().toString() + ":4:34: QML Component: Delegate error"; + QTest::ignoreMessage(QtInfoMsg, qPrintable(message)); + qmlInfo(delegate) << "Delegate error"; +} + QTEST_MAIN(tst_qqmlinfo) #include "tst_qqmlinfo.moc" diff --git a/tests/auto/qml/qqmlinstantiator/stringmodel.h b/tests/auto/qml/qqmlinstantiator/stringmodel.h index b01817375a..6ae3cbb6ee 100644 --- a/tests/auto/qml/qqmlinstantiator/stringmodel.h +++ b/tests/auto/qml/qqmlinstantiator/stringmodel.h @@ -60,7 +60,7 @@ public: endInsertRows(); } - int rowCount(const QModelIndex &) const + int rowCount(const QModelIndex &) const override { return items.count(); } @@ -70,7 +70,7 @@ public: return roles; } - virtual int columnCount(const QModelIndex &) const + int columnCount(const QModelIndex &) const override { return 1; } @@ -80,7 +80,7 @@ public: return rowCount(QModelIndex()) > 0; } - virtual QModelIndex index(int row, int column, const QModelIndex &parent) const + QModelIndex index(int row, int column, const QModelIndex &parent) const override { Q_UNUSED(column); if (row>=0 && row<rowCount(parent)) @@ -89,12 +89,12 @@ public: return QModelIndex(); } - virtual QModelIndex parent(const QModelIndex &) const + QModelIndex parent(const QModelIndex &) const override { return QModelIndex(); } - QVariant data (const QModelIndex & index, int role) const + QVariant data (const QModelIndex & index, int role) const override { int row = index.row(); if ((row<0) || (row>=items.count())) diff --git a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp index 6b8002cce5..21b0508e4d 100644 --- a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp +++ b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp @@ -204,6 +204,7 @@ void tst_qqmllistmodelworkerscript::dynamic_data() QTest::newRow("get4") << "{append({'foo':123});get(0).foo}" << 123 << "" << dr; QTest::newRow("get-modify1") << "{append({'foo':123,'bar':456});get(0).foo = 333;get(0).foo}" << 333 << "" << dr; QTest::newRow("get-modify2") << "{append({'z':1});append({'foo':123,'bar':456});get(1).bar = 999;get(1).bar}" << 999 << "" << dr; + QTest::newRow("get-set") << "{append({'foo':123});get(0).foo;setProperty(0, 'foo', 999);get(0).foo}" << 999 << "" << dr; QTest::newRow("append1") << "{append({'foo':123});count}" << 1 << "" << dr; QTest::newRow("append2") << "{append({'foo':123,'bar':456});count}" << 1 << "" << dr; diff --git a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro index 0d8de91931..345bc59615 100644 --- a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro +++ b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro @@ -6,4 +6,8 @@ macx:CONFIG -= app_bundle TESTDATA = data/* include (../../shared/util.pri) +qmlfiles.files = data/CompositeType.qml +qmlfiles.prefix = /tstqqmlmetatype +RESOURCES += qmlfiles + QT += core-private gui-private qml-private testlib diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index ff3361ff82..1d0d353668 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -62,6 +62,8 @@ private slots: void defaultObject(); void unregisterCustomType(); void unregisterCustomSingletonType(); + + void normalizeUrls(); }; class TestType : public QObject @@ -523,6 +525,18 @@ void tst_qqmlmetatype::unregisterCustomSingletonType() } } +void tst_qqmlmetatype::normalizeUrls() +{ + const QUrl url("qrc:///tstqqmlmetatype/data/CompositeType.qml"); + QVERIFY(!QQmlMetaType::qmlType(url).isValid()); + const auto registrationId = qmlRegisterType(url, "Test", 1, 0, "ResourceCompositeType"); + QVERIFY(QQmlMetaType::qmlType(url, /*includeNonFileImports=*/true).isValid()); + QUrl normalizedURL("qrc:/tstqqmlmetatype/data/CompositeType.qml"); + QVERIFY(QQmlMetaType::qmlType(normalizedURL, /*includeNonFileImports=*/true).isValid()); + qmlUnregisterType(registrationId); + QVERIFY(!QQmlMetaType::qmlType(url, /*includeNonFileImports=*/true).isValid()); +} + QTEST_MAIN(tst_qqmlmetatype) #include "tst_qqmlmetatype.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index fac3ff15fd..97ca3fa1de 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -29,6 +29,7 @@ #include <qdir.h> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> +#include <QtQml/qqmlcontext.h> #include <QtQml/qqmlextensionplugin.h> #include <QtCore/qjsondocument.h> #include <QtCore/qjsonarray.h> @@ -332,6 +333,29 @@ void tst_qqmlmoduleplugin::remoteImportWithUnquotedUri() VERIFY_ERRORS(0); } +static QByteArray msgComponentError(const QQmlComponent &c, const QQmlEngine *engine /* = 0 */) +{ + QString result; + const QList<QQmlError> errors = c.errors(); + QTextStream str(&result); + str << "Component '" << c.url().toString() << "' has " << errors.size() << " errors: '"; + for (int i = 0; i < errors.size(); ++i) { + if (i) + str << ", '"; + str << errors.at(i).toString() << '\''; + } + if (!engine) { + if (QQmlContext *context = c.creationContext()) + engine = context->engine(); + } + if (engine) { + str << " Import paths: (" << engine->importPathList().join(QStringLiteral(", ")) + << ") Plugin paths: (" << engine->pluginPathList().join(QStringLiteral(", ")) + << ')'; + } + return result.toLocal8Bit(); +} + // QTBUG-17324 void tst_qqmlmoduleplugin::importsMixedQmlCppPlugin() @@ -345,7 +369,7 @@ void tst_qqmlmoduleplugin::importsMixedQmlCppPlugin() QQmlComponent component(&engine, testFileUrl(QStringLiteral("importsMixedQmlCppPlugin.qml"))); QObject *o = component.create(); - QVERIFY2(o != nullptr, QQmlDataTest::msgComponentError(component, &engine)); + QVERIFY2(o != nullptr, msgComponentError(component, &engine)); QCOMPARE(o->property("test").toBool(), true); delete o; } @@ -354,7 +378,7 @@ void tst_qqmlmoduleplugin::importsMixedQmlCppPlugin() QQmlComponent component(&engine, testFileUrl(QStringLiteral("importsMixedQmlCppPlugin.2.qml"))); QObject *o = component.create(); - QVERIFY2(o != nullptr, QQmlDataTest::msgComponentError(component, &engine)); + QVERIFY2(o != nullptr, msgComponentError(component, &engine)); QCOMPARE(o->property("test").toBool(), true); QCOMPARE(o->property("test2").toBool(), true); delete o; diff --git a/tests/auto/qml/qqmltypeloader/data/Base.qml b/tests/auto/qml/qqmltypeloader/data/Base.qml new file mode 100644 index 0000000000..431c659424 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/Base.qml @@ -0,0 +1,3 @@ +import QtQml 2.0 + +QtObject {} diff --git a/tests/auto/qml/qqmltypeloader/data/Load.qml b/tests/auto/qml/qqmltypeloader/data/Load.qml new file mode 100644 index 0000000000..0b893bb5cd --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/Load.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +Item { + property int xy: loader.xy + Loader { + id: loader + asynchronous: true + source: 'Base.qml' + property int xy: item.xy + } +} diff --git a/tests/auto/qml/qqmltypeloader/data/redirected/Imported.qml b/tests/auto/qml/qqmltypeloader/data/redirected/Imported.qml new file mode 100644 index 0000000000..62954fe1b2 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/redirected/Imported.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property int xy: 323232 +} diff --git a/tests/auto/qml/qqmltypeloader/data/redirected/Redirected.qml b/tests/auto/qml/qqmltypeloader/data/redirected/Redirected.qml new file mode 100644 index 0000000000..40fec5ed31 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/redirected/Redirected.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +Imported { + +} diff --git a/tests/auto/qml/qqmltypeloader/data/redirected/qmldir b/tests/auto/qml/qqmltypeloader/data/redirected/qmldir new file mode 100644 index 0000000000..8eb1fa5c18 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/redirected/qmldir @@ -0,0 +1 @@ +Imported 1.0 Imported.qml diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index c10a8a08c1..d336d033a3 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -33,6 +33,7 @@ #include <QtQuick/qquickitem.h> #include <QtQml/private/qqmlengine_p.h> #include <QtQml/private/qqmltypeloader_p.h> +#include "../../shared/testhttpserver.h" #include "../../shared/util.h" class tst_QQMLTypeLoader : public QQmlDataTest @@ -48,6 +49,7 @@ private slots: void keepSingleton(); void keepRegistrations(); void intercept(); + void redirect(); }; void tst_QQMLTypeLoader::testLoadComplete() @@ -410,6 +412,22 @@ void tst_QQMLTypeLoader::intercept() QVERIFY(factory.loadedFiles.contains(QLatin1String(QT_TESTCASE_BUILDDIR) + "/Slow/qmldir")); } +void tst_QQMLTypeLoader::redirect() +{ + TestHTTPServer server; + QVERIFY2(server.listen(), qPrintable(server.errorString())); + QVERIFY(server.serveDirectory(dataDirectory())); + server.addRedirect("Base.qml", server.urlString("/redirected/Redirected.qml")); + + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(server.urlString("/Load.qml"), QQmlComponent::Asynchronous); + QTRY_VERIFY2(component.isReady(), qPrintable(component.errorString())); + + QObject *object = component.create(); + QTRY_COMPARE(object->property("xy").toInt(), 323232); +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro index 3a20e94741..0352561e03 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro @@ -3,7 +3,12 @@ TARGET = tst_qqmltypeloader QT += qml testlib qml-private quick macx:CONFIG -= app_bundle -SOURCES += tst_qqmltypeloader.cpp +SOURCES += \ + tst_qqmltypeloader.cpp \ + ../../shared/testhttpserver.cpp + +HEADERS += \ + ../../shared/testhttpserver.h include (../../shared/util.pri) |