diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-07-12 20:36:14 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-07-12 20:36:48 +0200 |
commit | 880a143eb572de3e8a6734cc663ed4b6e309b99d (patch) | |
tree | 4d1ad149dff7d9708e5981ea7b0ec7f8aee24bbf /tests | |
parent | c433b78660923b6268653b437a2a04078de0f058 (diff) | |
parent | a6057b46eebc71772d584ea5d318d130e2f40a19 (diff) |
Merge remote-tracking branch 'origin/dev' into wip/qt6
Change-Id: I4476733af61fcf3a2af1d121a4585c3fae1c240e
Diffstat (limited to 'tests')
51 files changed, 420 insertions, 24 deletions
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp index 5462e6c8ae..102acf73d6 100644 --- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp +++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp @@ -36,6 +36,7 @@ #include <QSysInfo> #include <QLoggingCategory> #include <private/qqmlcomponent_p.h> +#include <private/qqmlscriptdata_p.h> #include <qtranslator.h> #include "../../shared/util.h" diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp index 23be541a72..1f0115b926 100644 --- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp +++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp @@ -34,6 +34,7 @@ #include <private/qv4codegen_p.h> #include <private/qqmlcomponent_p.h> #include <private/qv4executablecompilationunit_p.h> +#include <private/qqmlscriptdata_p.h> #include <QQmlComponent> #include <QQmlEngine> #include <QQmlFileSelector> diff --git a/tests/auto/qml/qmllint/data/FromRoot.qml b/tests/auto/qml/qmllint/data/FromRoot.qml new file mode 100644 index 0000000000..021c09285e --- /dev/null +++ b/tests/auto/qml/qmllint/data/FromRoot.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Item { + id: root + property int unqualified: 42 + + Item { + Item { + x: unqualified // user defined property from root + } + + QtObject { + property int check: x // existing property from root + } + } + +} diff --git a/tests/auto/qml/qmllint/data/FromRootDirectParent.qml b/tests/auto/qml/qmllint/data/FromRootDirectParent.qml new file mode 100644 index 0000000000..c0bfd0f26b --- /dev/null +++ b/tests/auto/qml/qmllint/data/FromRootDirectParent.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +Item { + id: root + property int unqualified: 42 + + Item { + x: unqualified // user defined property from root + } + + QtObject { + property int check: x // existing property from root + } +} diff --git a/tests/auto/qml/qmllint/data/IdFromOuterSpace.qml b/tests/auto/qml/qmllint/data/IdFromOuterSpace.qml new file mode 100644 index 0000000000..774a1cfc7c --- /dev/null +++ b/tests/auto/qml/qmllint/data/IdFromOuterSpace.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + x: alien.x + + Component.onCompleted: { + console.log(alien); + } +} diff --git a/tests/auto/qml/qmllint/data/SignalHandler.qml b/tests/auto/qml/qmllint/data/SignalHandler.qml new file mode 100644 index 0000000000..bdf503e3dc --- /dev/null +++ b/tests/auto/qml/qmllint/data/SignalHandler.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +MouseArea { + onDoubleClicked: console.log(mouse); +} diff --git a/tests/auto/qml/qmllint/data/WithStatement.qml b/tests/auto/qml/qmllint/data/WithStatement.qml new file mode 100644 index 0000000000..5641f21eeb --- /dev/null +++ b/tests/auto/qml/qmllint/data/WithStatement.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Item { + Item { + id: target + property int test: 42 + } + Component.onCompleted: { + with(target) { + console.log(test); + } + } +} diff --git a/tests/auto/qml/qmllint/main.cpp b/tests/auto/qml/qmllint/main.cpp index eedbd7c2f2..038826790b 100644 --- a/tests/auto/qml/qmllint/main.cpp +++ b/tests/auto/qml/qmllint/main.cpp @@ -38,6 +38,8 @@ private Q_SLOTS: void initTestCase(); void test(); void test_data(); + void testUnqualified(); + void testUnqualified_data(); private: QString m_qmllintPath; }; @@ -69,6 +71,49 @@ void TestQmllint::test_data() QTest::newRow("Invalid_syntax_JS") << QStringLiteral("failure1.js") << false; } +void TestQmllint::testUnqualified() +{ + QFETCH(QString, filename); + QFETCH(QString, warningMessage); + QFETCH(int, warningLine); + QFETCH(int, warningColumn); + filename.prepend(QStringLiteral("data/")); + QStringList args; + args << QStringLiteral("-U") << filename; + + QProcess process; + process.start(m_qmllintPath, args); + QVERIFY(process.waitForFinished()); + QVERIFY(process.exitStatus() == QProcess::NormalExit); + QVERIFY(process.exitCode()); + QString output = process.readAllStandardError(); + QVERIFY(output.contains(QString::asprintf("Warning: unqualified access at %d:%d", warningLine, warningColumn))); + QVERIFY(output.contains(warningMessage)); +} + +void TestQmllint::testUnqualified_data() +{ + QTest::addColumn<QString>("filename"); + QTest::addColumn<QString>("warningMessage"); + QTest::addColumn<int>("warningLine"); + QTest::addColumn<int>("warningColumn"); + + // check for false positive due to and warning about with statement + QTest::newRow("WithStatement") << QStringLiteral("WithStatement.qml") << QStringLiteral("with statements are strongly discouraged") << 10 << 25; + // id from nowhere (as with setContextProperty) + QTest::newRow("IdFromOuterSpaceDirect") << QStringLiteral("IdFromOuterSpace.qml") << "alien.x" << 4 << 8; + QTest::newRow("IdFromOuterSpaceAccess") << QStringLiteral("IdFromOuterSpace.qml") << "console.log(alien)" << 7 << 21; + // access property of root object + QTest::newRow("FromRootDirect") << QStringLiteral("FromRoot.qml") << QStringLiteral("x: root.unqualified") << 9 << 16; // new property + QTest::newRow("FromRootAccess") << QStringLiteral("FromRoot.qml") << QStringLiteral("property int check: root.x") << 13 << 33; // builtin property + // access property of root object from direct child + QTest::newRow("FromRootDirectParentDirect") << QStringLiteral("FromRootDirectParent.qml") << QStringLiteral("x: parent.unqualified") << 8 << 12; + QTest::newRow("FromRootDirectParentAccess") << QStringLiteral("FromRootDirectParent.qml") << QStringLiteral("property int check: parent.x") << 12 << 29; + // access injected name from signal + QTest::newRow("SignalHandler") << QStringLiteral("SignalHandler.qml") << QStringLiteral("onDoubleClicked: function(mouse) {...") << 4 << 34; + +} + void TestQmllint::test() { QFETCH(QString, filename); diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 6a3bf53a31..71d3e8fe5f 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -120,6 +120,7 @@ private slots: void setNonExistentInitialProperty(); void relativeUrl_data(); void relativeUrl(); + void setDataNoEngineNoSegfault(); private: QQmlEngine engine; @@ -655,6 +656,17 @@ void tst_qqmlcomponent::relativeUrl() QVERIFY2(!component.isError(), qPrintable(component.errorString())); } +void tst_qqmlcomponent::setDataNoEngineNoSegfault() +{ + QQmlEngine eng; + QQmlComponent comp; + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Must provide an engine before calling setData"); + comp.setData("import QtQuick 1.0; QtObject { }", QUrl("")); + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Must provide an engine before calling create"); + auto c = comp.create(); + QVERIFY(!c); +} + QTEST_MAIN(tst_qqmlcomponent) #include "tst_qqmlcomponent.moc" diff --git a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp index dc29363fcf..7e6a0f79f9 100644 --- a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp +++ b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp @@ -428,7 +428,7 @@ void tst_qqmlconnections::noAcceleratedGlobalLookup() QVERIFY(c.isReady()); QScopedPointer<QObject> object(c.create()); const QVariant val = object->property("testEnum"); - QCOMPARE(val.type(), QMetaType::Int); + QCOMPARE(val.type(), int(QMetaType::Int)); QCOMPARE(val.toInt(), int(Proxy::EnumValue)); } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index b1a1ed4dec..d603ca6907 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -47,6 +47,7 @@ #include <private/qv4alloca_p.h> #include <private/qv4runtime_p.h> #include <private/qv4object_p.h> +#include <private/qv4script_p.h> #include <private/qqmlcomponentattached_p.h> #include <private/qv4objectiterator_p.h> #include <private/qqmlabstractbinding_p.h> diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index e55cd6f7a0..66d50cfe39 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -43,6 +43,7 @@ #include <QQmlIncubationController> #include <QTemporaryDir> #include <private/qqmlengine_p.h> +#include <private/qqmltypedata_p.h> #include <QQmlAbstractUrlInterceptor> class tst_qqmlengine : public QQmlDataTest diff --git a/tests/auto/qml/qqmllanguage/data/functionParameterTypes.qml b/tests/auto/qml/qqmllanguage/data/functionParameterTypes.qml new file mode 100644 index 0000000000..26931a4f10 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/functionParameterTypes.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 as QQ +import QtQml 2.0 as Core +QQ.Item { + id: root + function returnItem() : Core.QtObject { return root; } + function takeString(arg: string) { return arg; } +} diff --git a/tests/auto/qml/qqmllanguage/data/signalParameterTypes.3.qml b/tests/auto/qml/qqmllanguage/data/signalParameterTypes.3.qml new file mode 100644 index 0000000000..6dee30de95 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/signalParameterTypes.3.qml @@ -0,0 +1,19 @@ +import QtQml 2.0 + +QtObject { + id: root + + property bool success: false + + signal testSignal(param: bool) + + function handleTestSignal(param) { + success = param + } + + Component.onCompleted: { + success = false; + root.testSignal.connect(handleTestSignal) + root.testSignal(true); + } +} diff --git a/tests/auto/qml/qqmllanguage/data/typeAnnotations.2.errors.txt b/tests/auto/qml/qqmllanguage/data/typeAnnotations.2.errors.txt new file mode 100644 index 0000000000..b316acae30 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/typeAnnotations.2.errors.txt @@ -0,0 +1 @@ +5:14:Type annotations are not permitted in variable declarations diff --git a/tests/auto/qml/qqmllanguage/data/typeAnnotations.2.qml b/tests/auto/qml/qqmllanguage/data/typeAnnotations.2.qml new file mode 100644 index 0000000000..655fe4c226 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/typeAnnotations.2.qml @@ -0,0 +1,8 @@ +import QtQml 2.0 + +QtObject { + function notYet() { + var x: string = "ko" + return x + } +} diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp index d6215307bf..ffb1d51971 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.cpp +++ b/tests/auto/qml/qqmllanguage/testtypes.cpp @@ -27,6 +27,8 @@ ****************************************************************************/ #include "testtypes.h" +#include <private/qv4qmlcontext_p.h> + static QObject *myTypeObjectSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 8cbb39974e..a54c4b35d4 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -208,6 +208,7 @@ private slots: void remoteLoadCrash(); void signalWithDefaultArg(); void signalParameterTypes(); + void functionParameterTypes(); // regression tests for crashes void crash1(); @@ -622,6 +623,8 @@ void tst_qqmllanguage::errors_data() QTest::newRow("fuzzed.2") << "fuzzed.2.qml" << "fuzzed.2.errors.txt" << false; QTest::newRow("bareQmlImport") << "bareQmlImport.qml" << "bareQmlImport.errors.txt" << false; + + QTest::newRow("typeAnnotations.2") << "typeAnnotations.2.qml" << "typeAnnotations.2.errors.txt" << false; } @@ -3696,6 +3699,38 @@ void tst_qqmllanguage::signalParameterTypes() QVERIFY(obj != nullptr); QVERIFY(obj->property("success").toBool()); } + + // dynamic signal connections + { + QQmlComponent component(&engine, testFileUrl("signalParameterTypes.3.qml")); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(obj != nullptr); + QVERIFY(obj->property("success").toBool()); + } +} + +void tst_qqmllanguage::functionParameterTypes() +{ + QQmlComponent component(&engine, testFileUrl("functionParameterTypes.qml")); + QScopedPointer<QObject> obj(component.create()); + QVERIFY2(!obj.isNull(), qPrintable(component.errorString())); + const QMetaObject *metaObject = obj->metaObject(); + + { + QMetaMethod slot = metaObject->method(metaObject->indexOfSlot("returnItem()")); + QVERIFY(slot.isValid()); + QCOMPARE(slot.returnType(), QMetaType::type("QObject*")); + QObject *returnedPtr = nullptr; + slot.invoke(obj.data(), Qt::DirectConnection, Q_RETURN_ARG(QObject*, returnedPtr)); + QCOMPARE(returnedPtr, obj.data()); + } + + { + QMetaMethod slot = metaObject->method(metaObject->indexOfSlot("takeString(QString)")); + QVERIFY(slot.isValid()); + QCOMPARE(slot.parameterCount(), 1); + QCOMPARE(slot.parameterType(0), int(QMetaType::QString)); + } } // QTBUG-20639 diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index 3148ffb5a5..82aa265465 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -103,7 +103,7 @@ public: qmlRegisterModule(uri, 1, 0); } - void initializeEngine(QQmlEngine *engine, const char *uri) override + void initializeEngine(QQmlEngine *, const char *) override { initializeEngineEntered.lock(); leavingInitializeEngine.lock(); diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/anonfunctionexpr.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/anonfunctionexpr.js new file mode 100644 index 0000000000..f660edb69e --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/anonfunctionexpr.js @@ -0,0 +1,3 @@ +(function () : string { + return "ko" +}) diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/classmemberparam.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/classmemberparam.js new file mode 100644 index 0000000000..ab85d90880 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/classmemberparam.js @@ -0,0 +1,6 @@ + +class Foo { + member(param: string) { + return "ko" + } +} diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/classreturnvalue.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/classreturnvalue.js new file mode 100644 index 0000000000..a7da9e0ca7 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/classreturnvalue.js @@ -0,0 +1,6 @@ + +class Foo { + member(): string { + return "ko" + } +} diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/function.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/function.js new file mode 100644 index 0000000000..4d6021e835 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/function.js @@ -0,0 +1,4 @@ + +function x() : string { + return "ok" +} diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/functionexpr.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/functionexpr.js new file mode 100644 index 0000000000..33f2abbb61 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/functionexpr.js @@ -0,0 +1,3 @@ +(function x() : string { + return "ko" +}) diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/functionparams.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/functionparams.js new file mode 100644 index 0000000000..2c23628e3f --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/functionparams.js @@ -0,0 +1,3 @@ + +function test(x: string, y: string) { +} diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/iteration.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/iteration.js new file mode 100644 index 0000000000..a6cc00e38a --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/iteration.js @@ -0,0 +1,3 @@ + +for (var i: int = 0; i < 100; ++i) { +} diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/iteration2.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/iteration2.js new file mode 100644 index 0000000000..24d5acce98 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/iteration2.js @@ -0,0 +1,5 @@ + +let y = [1, 2, 3]; + +for (let x: int of y) { +} diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/qmlnestedfunction.qml b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/qmlnestedfunction.qml new file mode 100644 index 0000000000..f435bf1b25 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/qmlnestedfunction.qml @@ -0,0 +1,9 @@ +import QtQuick 2.12 as MyQuick +MyQuick.Item { + function factory(param: string) : MyQuick.Item { + function nested(foo: string) { + return this + } + return nested() + } +} diff --git a/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/variables.js b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/variables.js new file mode 100644 index 0000000000..bf332ac7a8 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/disallowedtypeannotations/variables.js @@ -0,0 +1,2 @@ + +var x: string = "ko" diff --git a/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_bool.qml b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_bool.qml new file mode 100644 index 0000000000..79a9ede3d4 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_bool.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 +QtObject { + function test() : bool { return true; } +} diff --git a/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_double.qml b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_double.qml new file mode 100644 index 0000000000..f58e4b92d9 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_double.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 +QtObject { + function test() : double { return 0; } +} diff --git a/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_int.qml b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_int.qml new file mode 100644 index 0000000000..267ad7191f --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_int.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 +QtObject { + function test() : int { return 0; } +} diff --git a/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_real.qml b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_real.qml new file mode 100644 index 0000000000..9973819ad2 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_real.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 +QtObject { + function test() : real { return 0; } +} diff --git a/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_string.qml b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_string.qml new file mode 100644 index 0000000000..e632ec7154 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_string.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 +QtObject { + function test(s: string) {} +} diff --git a/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_url.qml b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_url.qml new file mode 100644 index 0000000000..ebf3f32561 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/typeannotations/basic_qmltypes_url.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 +QtObject { + function test(u: url) {} +} diff --git a/tests/auto/qml/qqmlparser/data/typeannotations/parametrized.qml b/tests/auto/qml/qqmlparser/data/typeannotations/parametrized.qml new file mode 100644 index 0000000000..d80b5e3f87 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/typeannotations/parametrized.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 as MyQuick +MyQuick.Item { + function factory() : list<MyQuick.Item> { + } +} diff --git a/tests/auto/qml/qqmlparser/data/typeannotations/qmlfunction.qml b/tests/auto/qml/qqmlparser/data/typeannotations/qmlfunction.qml new file mode 100644 index 0000000000..cd5c1f51e5 --- /dev/null +++ b/tests/auto/qml/qqmlparser/data/typeannotations/qmlfunction.qml @@ -0,0 +1,6 @@ +import QtQuick 2.12 as MyQuick +MyQuick.Item { + function factory(param: string) : MyQuick.Item { + return this + } +} diff --git a/tests/auto/qml/qqmlparser/qqmlparser.pro b/tests/auto/qml/qqmlparser/qqmlparser.pro index 74cb620f06..d8e4b0dd06 100644 --- a/tests/auto/qml/qqmlparser/qqmlparser.pro +++ b/tests/auto/qml/qqmlparser/qqmlparser.pro @@ -7,3 +7,7 @@ SOURCES += tst_qqmlparser.cpp DEFINES += SRCDIR=\\\"$$PWD\\\" cross_compile: DEFINES += QTEST_CROSS_COMPILED + +TESTDATA = data/* + +include (../../shared/util.pri) diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp index 5f58df75d4..9d8818d01e 100644 --- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp +++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp @@ -32,12 +32,14 @@ #include <private/qqmljsastvisitor_p.h> #include <private/qqmljsast_p.h> +#include "../../shared/util.h" + #include <qtest.h> #include <QDir> #include <QDebug> #include <cstdlib> -class tst_qqmlparser : public QObject +class tst_qqmlparser : public QQmlDataTest { Q_OBJECT public: @@ -56,6 +58,10 @@ private slots: void leadingSemicolonInClass(); void templatedReadonlyProperty(); void qmlImportInJSRequiresFullVersion(); + void typeAnnotations_data(); + void typeAnnotations(); + void disallowedTypeAnnotations_data(); + void disallowedTypeAnnotations(); private: QStringList excludedDirs; @@ -88,7 +94,7 @@ public: qDebug() << "first source loc failed: node:" << node->kind << "at" << node->firstSourceLocation().startLine << "/" << node->firstSourceLocation().startColumn << "parent" << parent->kind << "at" << parent->firstSourceLocation().startLine << "/" << parent->firstSourceLocation().startColumn; if (node->lastSourceLocation().end() > parentEnd) - qDebug() << "first source loc failed: node:" << node->kind << "at" << node->lastSourceLocation().startLine << "/" << node->lastSourceLocation().startColumn + qDebug() << "last source loc failed: node:" << node->kind << "at" << node->lastSourceLocation().startLine << "/" << node->lastSourceLocation().startColumn << "parent" << parent->kind << "at" << parent->lastSourceLocation().startLine << "/" << parent->lastSourceLocation().startColumn; QVERIFY(node->firstSourceLocation().begin() >= parentBegin); @@ -114,6 +120,27 @@ public: } }; +struct TypeAnnotationObserver: public AST::Visitor +{ + bool typeAnnotationSeen = false; + + void operator()(AST::Node *node) + { + AST::Node::accept(node, this); + } + + virtual bool visit(AST::TypeAnnotation *) + { + typeAnnotationSeen = true; + return true; + } + + void throwRecursionDepthError() final + { + QFAIL("Maximum statement or expression depth exceeded"); + } +}; + } tst_qqmlparser::tst_qqmlparser() @@ -122,6 +149,7 @@ tst_qqmlparser::tst_qqmlparser() void tst_qqmlparser::initTestCase() { + QQmlDataTest::initTestCase(); // Add directories you want excluded here // These snippets are not expected to run on their own. @@ -334,6 +362,82 @@ void tst_qqmlparser::qmlImportInJSRequiresFullVersion() } } +void tst_qqmlparser::typeAnnotations_data() +{ + QTest::addColumn<QString>("file"); + + QString tests = dataDirectory() + "/typeannotations/"; + + QStringList files; + files << findFiles(QDir(tests)); + + for (const QString &file: qAsConst(files)) + QTest::newRow(qPrintable(file)) << file; +} + +void tst_qqmlparser::typeAnnotations() +{ + using namespace QQmlJS; + + QFETCH(QString, file); + + QString code; + + QFile f(file); + if (f.open(QFile::ReadOnly)) + code = QString::fromUtf8(f.readAll()); + + const bool qmlMode = file.endsWith(QLatin1String(".qml")); + + Engine engine; + Lexer lexer(&engine); + lexer.setCode(code, 1, qmlMode); + Parser parser(&engine); + bool ok = qmlMode ? parser.parse() : parser.parseProgram(); + QVERIFY(ok); + + check::TypeAnnotationObserver observer; + observer(parser.rootNode()); + + QVERIFY(observer.typeAnnotationSeen); +} + +void tst_qqmlparser::disallowedTypeAnnotations_data() +{ + QTest::addColumn<QString>("file"); + + QString tests = dataDirectory() + "/disallowedtypeannotations/"; + + QStringList files; + files << findFiles(QDir(tests)); + + for (const QString &file: qAsConst(files)) + QTest::newRow(qPrintable(file)) << file; +} + +void tst_qqmlparser::disallowedTypeAnnotations() +{ + using namespace QQmlJS; + + QFETCH(QString, file); + + QString code; + + QFile f(file); + if (f.open(QFile::ReadOnly)) + code = QString::fromUtf8(f.readAll()); + + const bool qmlMode = file.endsWith(QLatin1String(".qml")); + + Engine engine; + Lexer lexer(&engine); + lexer.setCode(code, 1, qmlMode); + Parser parser(&engine); + bool ok = qmlMode ? parser.parse() : parser.parseProgram(); + QVERIFY(!ok); + QVERIFY2(parser.errorMessage().startsWith("Type annotations are not permitted "), qPrintable(parser.errorMessage())); +} + QTEST_MAIN(tst_qqmlparser) #include "tst_qqmlparser.moc" diff --git a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp index 3b17df9872..dcfe914af6 100644 --- a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp +++ b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp @@ -32,6 +32,7 @@ #include <QTranslator> #include <QQmlContext> #include <private/qqmlengine_p.h> +#include <private/qqmltypedata_p.h> #include "../../shared/util.h" class tst_qqmltranslation : public QQmlDataTest diff --git a/tests/auto/qml/qqmltypeloader/data/qrcRootPath.qml b/tests/auto/qml/qqmltypeloader/data/qrcRootPath.qml new file mode 100644 index 0000000000..bdbee4eb59 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/qrcRootPath.qml @@ -0,0 +1,4 @@ +import QtQml 2.12 +import "qrc:/" + +QtObject {} diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index 0c4abf19f4..7d69b4a156 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -28,6 +28,7 @@ #include <QtTest/QtTest> #include <QtQml/qqmlengine.h> +#include <QtQml/qqmlfile.h> #include <QtQml/qqmlnetworkaccessmanagerfactory.h> #include <QtQuick/qquickview.h> #include <QtQuick/qquickitem.h> @@ -35,6 +36,7 @@ #include <QtCore/qprocess.h> #endif #include <QtQml/private/qqmlengine_p.h> +#include <QtQml/private/qqmltypedata_p.h> #include <QtQml/private/qqmltypeloader_p.h> #include "../../shared/testhttpserver.h" #include "../../shared/util.h" @@ -56,6 +58,7 @@ private slots: void qmlSingletonWithinModule(); void multiSingletonModule(); void implicitComponentModule(); + void qrcRootPathUrl(); }; void tst_QQMLTypeLoader::testLoadComplete() @@ -503,6 +506,13 @@ void tst_QQMLTypeLoader::implicitComponentModule() checkCleanCacheLoad(QLatin1String("implicitComponentModule")); } +void tst_QQMLTypeLoader::qrcRootPathUrl() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("qrcRootPath.qml")); + QCOMPARE(component.status(), QQmlComponent::Ready); +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" diff --git a/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp b/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp index f3825b350f..9bcc21c77d 100644 --- a/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp +++ b/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp @@ -385,9 +385,10 @@ bool tst_drawingmodes::isRunningOnRhi() const decided = true; QQuickView dummy; dummy.show(); - QTest::qWaitForWindowExposed(&dummy); - QSGRendererInterface::GraphicsApi api = dummy.rendererInterface()->graphicsApi(); - retval = QSGRendererInterface::isApiRhiBased(api); + if (QTest::qWaitForWindowExposed(&dummy)) { + QSGRendererInterface::GraphicsApi api = dummy.rendererInterface()->graphicsApi(); + retval = QSGRendererInterface::isApiRhiBased(api); + } dummy.hide(); } return retval; diff --git a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp index bf582b820b..58bc3d40b5 100644 --- a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp +++ b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp @@ -136,7 +136,6 @@ void tst_MptaInterop::touchDrag() // TODO touchesThenPinch_data with press/release sequences somehow: vectors of touchpoint IDs? or a string representation? void tst_MptaInterop::touchesThenPinch() { - const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); QScopedPointer<QQuickView> windowPtr; createView(windowPtr, "pinchDragMPTA.qml"); QQuickView * window = windowPtr.data(); diff --git a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp index c5fdb6c1b9..d1f6d67aa1 100644 --- a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp +++ b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp @@ -338,7 +338,7 @@ void tst_QQuickAccessible::basicPropertiesTest() QCOMPARE(text2->rect().y(), item->rect().y() + 40); QCOMPARE(text2->role(), QAccessible::StaticText); QCOMPARE(item->indexOfChild(text2), 1); - QCOMPARE(text2->state().editable, 0); + QCOMPARE(text2->state().editable, 0u); QCOMPARE(text2->state().readOnly, 1); QCOMPARE(iface->indexOfChild(text2), -1); diff --git a/tests/auto/quick/qquickfontloader_static/tst_qquickfontloader_static.cpp b/tests/auto/quick/qquickfontloader_static/tst_qquickfontloader_static.cpp index c0f66bd709..7e848ef2fc 100644 --- a/tests/auto/quick/qquickfontloader_static/tst_qquickfontloader_static.cpp +++ b/tests/auto/quick/qquickfontloader_static/tst_qquickfontloader_static.cpp @@ -59,6 +59,8 @@ int main(int argc, char **argv) component.setData(qmltemplate, current); window.setContent(current, &component, component.create()); window.show(); - QTest::qWaitForWindowActive(&window); + if (!QTest::qWaitForWindowActive(&window)) + return EXIT_FAILURE; } + return 0; } diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index c722f2fc2c..34c18aa64b 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -1107,7 +1107,7 @@ class MyInterceptor : public QQmlAbstractUrlInterceptor { public: MyInterceptor(QUrl url) : QQmlAbstractUrlInterceptor(), m_url(url) {} - QUrl intercept(const QUrl &url, QQmlAbstractUrlInterceptor::DataType type) + QUrl intercept(const QUrl &url, QQmlAbstractUrlInterceptor::DataType) { if (url.scheme() == "interceptthis") return m_url; diff --git a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp index c79e665d94..9dc9ad53ea 100644 --- a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp +++ b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp @@ -669,7 +669,7 @@ public: emit finished(); } - QQuickTextureFactory *textureFactory() const + QQuickTextureFactory *textureFactory() const override { QImage image(50, 50, QImage::Format_RGB32); auto texture = QQuickTextureFactory::textureFactoryForImage(image); @@ -696,7 +696,7 @@ public: ~WaitingAsyncProvider() {} - QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) + QQuickImageResponse *requestImageResponse(const QString & /* id */, const QSize & /* requestedSize */) { auto response = new WaitingAsyncImageResponse(m_providerRemovedMutex, m_providerRemovedCond, m_providerRemoved, m_imageRequestedMutex, m_imageRequestedCondition, m_imageRequested); pool.start(response); diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index fbe56abda5..19967efcd9 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -50,7 +50,6 @@ using namespace QQuickViewTestUtil; using namespace QQuickVisualTestUtil; -static const char* kTableViewPropName = "tableView"; static const char* kDelegateObjectName = "tableViewDelegate"; static const char *kDelegatesCreatedCountProp = "delegatesCreatedCount"; static const char *kModelDataBindingProp = "modelDataBinding"; diff --git a/tests/auto/quick/rendernode/tst_rendernode.cpp b/tests/auto/quick/rendernode/tst_rendernode.cpp index b6028079f3..e75e9e30b9 100644 --- a/tests/auto/quick/rendernode/tst_rendernode.cpp +++ b/tests/auto/quick/rendernode/tst_rendernode.cpp @@ -49,8 +49,7 @@ public: view.setResizeMode(QQuickView::SizeViewToRootObject); view.setSource(testFileUrl(fileName)); view.setVisible(true); - QTest::qWaitForWindowExposed(&view); - return view.grabWindow(); + return QTest::qWaitForWindowExposed(&view) ? view.grabWindow() : QImage(); } //It is important for platforms that only are able to show fullscreen windows @@ -225,6 +224,7 @@ void tst_rendernode::renderOrder() QSKIP("Render nodes not yet supported with QRhi"); QImage fb = runTest("RenderOrder.qml"); + QVERIFY(!fb.isNull()); const qreal scaleFactor = QGuiApplication::primaryScreen()->devicePixelRatio(); QCOMPARE(fb.width(), qRound(200 * scaleFactor)); @@ -257,6 +257,7 @@ void tst_rendernode::messUpState() QSKIP("Render nodes not yet supported with QRhi"); QImage fb = runTest("MessUpState.qml"); + QVERIFY(!fb.isNull()); int x1 = 0; int x2 = fb.width() / 2; int x3 = fb.width() - 1; @@ -318,7 +319,7 @@ void tst_rendernode::matrix() qmlRegisterType<StateRecordingRenderNodeItem>("RenderNode", 1, 0, "StateRecorder"); StateRecordingRenderNode::matrices.clear(); - runTest("matrix.qml"); + QVERIFY(!runTest("matrix.qml").isNull()); QMatrix4x4 noRotateOffset; noRotateOffset.translate(20, 20); @@ -371,9 +372,10 @@ bool tst_rendernode::isRunningOnRhi() const decided = true; QQuickView dummy; dummy.show(); - QTest::qWaitForWindowExposed(&dummy); - QSGRendererInterface::GraphicsApi api = dummy.rendererInterface()->graphicsApi(); - retval = QSGRendererInterface::isApiRhiBased(api); + if (QTest::qWaitForWindowExposed(&dummy)) { + QSGRendererInterface::GraphicsApi api = dummy.rendererInterface()->graphicsApi(); + retval = QSGRendererInterface::isApiRhiBased(api); + } dummy.hide(); } return retval; diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index c15f1e941e..3f605348c3 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -75,8 +75,8 @@ public: delete node; node = new QSGNode; - const int w = width(); - const int h = height(); + const int w = int(width()); + const int h = int(height()); QQuickWindow *win = window(); for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { @@ -569,8 +569,8 @@ bool tst_SceneGraph::isRunningOnOpenGLDirectly() decided = true; QQuickView dummy; dummy.show(); - QTest::qWaitForWindowExposed(&dummy); - retval = dummy.rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL; + if (QTest::qWaitForWindowExposed(&dummy)) + retval = dummy.rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL; dummy.hide(); } return retval; |