diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-01-20 01:00:27 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-01-20 07:04:47 +0000 |
commit | b9519d9630d9192cb49b97c7c9fe30d43ab1ee4a (patch) | |
tree | 512b32a0e2dea84a89a01e89a1b7868f3c1c8a37 /tests/auto | |
parent | 0ced82a8cf8472a79b08db05d441caf778ac9131 (diff) | |
parent | e5f7c5f2712957d0e1753c629e4cce86a0e6bdbc (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
src/qml/qml/qqmlvaluetype.cpp
tests/auto/qml/qml.pro
Change-Id: I78f992f83212bb9fd5e09b64163f15f046185224
Diffstat (limited to 'tests/auto')
20 files changed, 479 insertions, 43 deletions
diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index 0ebf43eb6f..12befeb1ec 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -280,11 +280,11 @@ void tst_QQmlEngineDebugService::recursiveObjectTest( } else { QCOMPARE(ref.name, QString("<unknown value>")); } - } else if (pmeta.type() < QVariant::UserType && pmeta.userType() != QMetaType::QVariant) { + } else if (pmeta.userType() < QMetaType::User && pmeta.userType() != QMetaType::QVariant) { const QVariant expected = pmeta.read(o); QVERIFY2(p.value == expected, QString::fromLatin1("%1 != %2. Details: %3/%4/%5/%6") .arg(QTest::toString(p.value)).arg(QTest::toString(expected)).arg(p.name) - .arg(p.valueTypeName).arg(pmeta.type()).arg(pmeta.userType()).toUtf8()); + .arg(p.valueTypeName).arg(pmeta.userType()).arg(pmeta.userType()).toUtf8()); } if (p.name == "parent") diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 66a526fda8..28efb519ee 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -1543,7 +1543,7 @@ void tst_QJSEngine::valueConversion_QVariant() { QVariant tmp1; QVariant tmp2(QMetaType::QVariant, &tmp1); - QCOMPARE(QMetaType::Type(tmp2.type()), QMetaType::QVariant); + QCOMPARE(QMetaType::Type(tmp2.userType()), QMetaType::QVariant); QJSValue val1 = eng.toScriptValue(tmp1); QJSValue val2 = eng.toScriptValue(tmp2); @@ -1558,9 +1558,9 @@ void tst_QJSEngine::valueConversion_QVariant() QVariant tmp1(123); QVariant tmp2(QMetaType::QVariant, &tmp1); QVariant tmp3(QMetaType::QVariant, &tmp2); - QCOMPARE(QMetaType::Type(tmp1.type()), QMetaType::Int); - QCOMPARE(QMetaType::Type(tmp2.type()), QMetaType::QVariant); - QCOMPARE(QMetaType::Type(tmp3.type()), QMetaType::QVariant); + QCOMPARE(QMetaType::Type(tmp1.userType()), QMetaType::Int); + QCOMPARE(QMetaType::Type(tmp2.userType()), QMetaType::QVariant); + QCOMPARE(QMetaType::Type(tmp3.userType()), QMetaType::QVariant); QJSValue val1 = eng.toScriptValue(tmp2); QJSValue val2 = eng.toScriptValue(tmp3); diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp index 95f554776f..d6e85f973f 100644 --- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp +++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp @@ -1081,7 +1081,7 @@ void tst_QJSValue::toVariant() // We can't roundtrip a QRegExp this way, as toVariant() has no information on whether we // want QRegExp or QRegularExpression. It will always create a QRegularExpression. - QCOMPARE(var.type(), QMetaType::QRegularExpression); + QCOMPARE(var.userType(), QMetaType::QRegularExpression); QRegularExpression result = var.toRegularExpression(); QCOMPARE(result.pattern(), rx.pattern()); QCOMPARE(result.patternOptions() & QRegularExpression::CaseInsensitiveOption, 0); @@ -1134,7 +1134,7 @@ void tst_QJSValue::toVariant() QVERIFY(array.isArray()); QCOMPARE(array.property("length").toInt(), 2); QVariant ret = array.toVariant(); - QCOMPARE(ret.type(), QVariant::List); + QCOMPARE(ret.userType(), QVariant::List); QVariantList listOut = ret.toList(); QCOMPARE(listOut.size(), listIn.size()); for (int i = 0; i < listIn.size(); ++i) diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro index d9f3fdf1b8..f1712e41e3 100644 --- a/tests/auto/qml/qml.pro +++ b/tests/auto/qml/qml.pro @@ -91,7 +91,7 @@ SUBDIRS += $$METATYPETESTS qtConfig(process) { qtConfig(qml-debug): SUBDIRS += debugger !boot2qt { - SUBDIRS += qmllint qmlplugindump + SUBDIRS += qmlformat qmllint qmlplugindump } } diff --git a/tests/auto/qml/qmlformat/qmlformat.pro b/tests/auto/qml/qmlformat/qmlformat.pro index 9f8a44bc09..a6ae391711 100644 --- a/tests/auto/qml/qmlformat/qmlformat.pro +++ b/tests/auto/qml/qmlformat/qmlformat.pro @@ -3,6 +3,7 @@ TARGET = tst_qmlformat macos:CONFIG -= app_bundle SOURCES += tst_qmlformat.cpp +DEFINES += SRCDIR=\\\"$$PWD\\\" include (../../shared/util.pri) diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index 7ad9c99d83..95c8e88f21 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -42,11 +42,22 @@ private Q_SLOTS: void testFormat(); void testFormatNoSort(); + +#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled + void testExample(); + void testExample_data(); +#endif + private: QString readTestFile(const QString &path); QString runQmlformat(const QString &fileToFormat, bool sortImports, bool shouldSucceed); QString m_qmlformatPath; + QStringList m_excludedDirs; + QStringList m_invalidFiles; + + QStringList findFiles(const QDir &); + bool isInvalidFile(const QFileInfo &fileName) const; }; void TestQmlformat::initTestCase() @@ -60,6 +71,91 @@ void TestQmlformat::initTestCase() QString message = QStringLiteral("qmlformat executable not found (looked for %0)").arg(m_qmlformatPath); QFAIL(qPrintable(message)); } + + // Add directories you want excluded here + + // These snippets are not expected to run on their own. + m_excludedDirs << "doc/src/snippets/qml/visualdatamodel_rootindex"; + m_excludedDirs << "doc/src/snippets/qml/qtbinding"; + m_excludedDirs << "doc/src/snippets/qml/imports"; + m_excludedDirs << "doc/src/snippets/qtquick1/visualdatamodel_rootindex"; + m_excludedDirs << "doc/src/snippets/qtquick1/qtbinding"; + m_excludedDirs << "doc/src/snippets/qtquick1/imports"; + m_excludedDirs << "tests/manual/v4"; + m_excludedDirs << "tests/auto/qml/ecmascripttests"; + m_excludedDirs << "tests/auto/qml/qmllint"; + + // Add invalid files (i.e. files with syntax errors) + m_invalidFiles << "tests/auto/quick/qquickloader/data/InvalidSourceComponent.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/signal.2.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/signal.3.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/signal.5.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/property.4.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/empty.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/missingObject.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/insertedSemicolon.1.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/nonexistantProperty.5.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/invalidRoot.1.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/invalidQmlEnumValue.1.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/invalidQmlEnumValue.2.qml"; + m_invalidFiles << "tests/auto/qml/qquickfolderlistmodel/data/dummy.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.1.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.2.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.3.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.4.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.5.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.6.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/numberParsing_error.1.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/numberParsing_error.2.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/incrDecrSemicolon_error1.qml"; + m_invalidFiles << "tests/auto/qml/debugger/qqmlpreview/data/broken.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/fuzzed.2.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/fuzzed.3.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/requiredProperties.2.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/requiredProperties.3.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/nullishCoalescing_LHS_And.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/nullishCoalescing_LHS_And.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/nullishCoalescing_LHS_Or.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/nullishCoalescing_RHS_And.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/nullishCoalescing_RHS_Or.qml"; + m_invalidFiles << "tests/auto/qml/qqmllanguage/data/typeAnnotations.2.qml"; + m_invalidFiles << "tests/auto/qml/qqmlparser/data/disallowedtypeannotations/qmlnestedfunction.qml"; +} + +QStringList TestQmlformat::findFiles(const QDir &d) +{ + for (int ii = 0; ii < m_excludedDirs.count(); ++ii) { + QString s = m_excludedDirs.at(ii); + if (d.absolutePath().endsWith(s)) + return QStringList(); + } + + QStringList rv; + + QStringList files = d.entryList(QStringList() << QLatin1String("*.qml"), + QDir::Files); + foreach (const QString &file, files) { + rv << d.absoluteFilePath(file); + } + + QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | + QDir::NoSymLinks); + foreach (const QString &dir, dirs) { + QDir sub = d; + sub.cd(dir); + rv << findFiles(sub); + } + + return rv; +} + +bool TestQmlformat::isInvalidFile(const QFileInfo &fileName) const +{ + for (const QString &invalidFile : m_invalidFiles) { + if (fileName.absoluteFilePath().endsWith(invalidFile)) + return true; + } + return false; } QString TestQmlformat::readTestFile(const QString &path) @@ -74,18 +170,46 @@ QString TestQmlformat::readTestFile(const QString &path) void TestQmlformat::testFormat() { - QCOMPARE(runQmlformat("Example1.qml", true, true), readTestFile("Example1.formatted.qml")); + QCOMPARE(runQmlformat(testFile("Example1.qml"), true, true), readTestFile("Example1.formatted.qml")); } void TestQmlformat::testFormatNoSort() { - QCOMPARE(runQmlformat("Example1.qml", false, true), readTestFile("Example1.formatted.nosort.qml")); + QCOMPARE(runQmlformat(testFile("Example1.qml"), false, true), readTestFile("Example1.formatted.nosort.qml")); } +#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled +void TestQmlformat::testExample_data() +{ + QTest::addColumn<QString>("file"); + + QString examples = QLatin1String(SRCDIR) + "/../../../../examples/"; + QString tests = QLatin1String(SRCDIR) + "/../../../../tests/"; + + QStringList files; + files << findFiles(QDir(examples)); + files << findFiles(QDir(tests)); + + for (const QString &file : files) + QTest::newRow(qPrintable(file)) << file; +} +#endif + +#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled +void TestQmlformat::testExample() +{ + QFETCH(QString, file); + QString output = runQmlformat(file, true, !isInvalidFile(file)); + + if (!isInvalidFile(file)) + QVERIFY(!output.isEmpty()); +} +#endif + QString TestQmlformat::runQmlformat(const QString &fileToFormat, bool sortImports, bool shouldSucceed) { QStringList args; - args << testFile(fileToFormat); + args << fileToFormat; if (!sortImports) args << "-n"; diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index 3233e7f105..03e3262e7b 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -36,7 +36,6 @@ #include <QtCore/qregularexpression.h> #include <QtQml/qqmllist.h> #include <QtCore/qrect.h> -#include <QtGui/qmatrix.h> #include <QtGui/qcolor.h> #include <QtGui/qvector3d.h> #include <QtGui/QFont> diff --git a/tests/auto/qml/qqmllanguage/data/unsupportedProperty.errors.txt b/tests/auto/qml/qqmllanguage/data/unsupportedProperty.errors.txt index 3cd626de86..b45c320c20 100644 --- a/tests/auto/qml/qqmllanguage/data/unsupportedProperty.errors.txt +++ b/tests/auto/qml/qqmllanguage/data/unsupportedProperty.errors.txt @@ -1 +1 @@ -3:13:Invalid property assignment: unsupported type "QMatrix" +3:16:Invalid property assignment: unsupported type "QTransform" diff --git a/tests/auto/qml/qqmllanguage/data/unsupportedProperty.qml b/tests/auto/qml/qqmllanguage/data/unsupportedProperty.qml index 9f19680368..ec8171dd2c 100644 --- a/tests/auto/qml/qqmllanguage/data/unsupportedProperty.qml +++ b/tests/auto/qml/qqmllanguage/data/unsupportedProperty.qml @@ -1,4 +1,4 @@ import Test 1.0 MyQmlObject { - matrix: "1,0,0,0,1,0,0,0,1" + transform: "1,0,0,0,1,0,0,0,1" } diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp index 0ddb1b1491..31a4135d89 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.cpp +++ b/tests/auto/qml/qqmllanguage/testtypes.cpp @@ -121,6 +121,7 @@ void registerTypes() qmlRegisterTypesAndRevisions<Extended, Foreign, ForeignExtended>("Test", 1); qmlRegisterTypesAndRevisions<BareSingleton>("Test", 1); + qmlRegisterTypesAndRevisions<UncreatableSingleton>("Test", 1); } QVariant myCustomVariantTypeConverter(const QString &data) @@ -213,3 +214,9 @@ bool MyQmlObject::event(QEvent *event) m_childAddedEventCount++; return QObject::event(event); } + +UncreatableSingleton *UncreatableSingleton::instance() +{ + static UncreatableSingleton instance; + return &instance; +} diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h index a7410e190b..39502372e6 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.h +++ b/tests/auto/qml/qqmllanguage/testtypes.h @@ -31,7 +31,7 @@ #include <QtCore/qobject.h> #include <QtCore/qrect.h> #include <QtCore/qdatetime.h> -#include <QtGui/qmatrix.h> +#include <QtGui/qtransform.h> #include <QtGui/qcolor.h> #include <QtGui/qvector2d.h> #include <QtGui/qvector3d.h> @@ -104,7 +104,7 @@ class MyQmlObject : public QObject, public MyInterface Q_PROPERTY(QString readOnlyString READ readOnlyString) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) Q_PROPERTY(QRect rect READ rect WRITE setRect) - Q_PROPERTY(QMatrix matrix READ matrix WRITE setMatrix) //assumed to be unsupported by QML + Q_PROPERTY(QTransform transform READ transform WRITE setTransform) //assumed to be unsupported by QML Q_PROPERTY(MyInterface *interfaceProperty READ interface WRITE setInterface) Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal) Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType) @@ -129,8 +129,8 @@ public: QRect rect() const { return QRect(); } void setRect(const QRect&) {} - QMatrix matrix() const { return QMatrix(); } - void setMatrix(const QMatrix&) {} + QTransform transform() const { return QTransform(); } + void setTransform(const QTransform &) {} MyInterface *interface() const { return m_interface; } void setInterface(MyInterface *iface) { m_interface = iface; } @@ -1468,6 +1468,19 @@ public: } }; +class UncreatableSingleton : public QObject +{ + Q_OBJECT + QML_SINGLETON + QML_ELEMENT + +public: + static UncreatableSingleton *instance(); + +private: + UncreatableSingleton() { setObjectName("uncreatable"); } +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 7b4662a5cd..089daf3ed5 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -5378,25 +5378,34 @@ void tst_qqmllanguage::listContainingDeletedObject() void tst_qqmllanguage::overrideSingleton() { - auto check = [](const QString &name) { + auto check = [](const QString &name, const QByteArray &singletonElement) { const QByteArray testQml = "import Test 1.0\n" "import QtQml 2.0\n" - "QtObject { objectName: BareSingleton.objectName }"; + "QtObject { objectName: " + singletonElement + ".objectName }"; QQmlEngine engine; QQmlComponent component(&engine, nullptr); - component.setData(testQml, QUrl()); + component.setData(testQml, QUrl("singleton.qml")); QVERIFY(component.isReady()); QScopedPointer<QObject> obj(component.create()); QCOMPARE(obj->objectName(), name); }; - check("statically registered"); + check("statically registered", "BareSingleton"); BareSingleton singleton; singleton.setObjectName("dynamically registered"); qmlRegisterSingletonInstance("Test", 1, 0, "BareSingleton", &singleton); - check("dynamically registered"); + check("dynamically registered", "BareSingleton"); + + QTest::ignoreMessage( + QtWarningMsg, + "singleton.qml:3: TypeError: Cannot read property 'objectName' of undefined"); + check("", "UncreatableSingleton"); + + qmlRegisterSingletonInstance("Test", 1, 0, "UncreatableSingleton", + UncreatableSingleton::instance()); + check("uncreatable", "UncreatableSingleton"); } QTEST_MAIN(tst_qqmllanguage) diff --git a/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp b/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp index 8efaedf5b5..e25d555d61 100644 --- a/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp +++ b/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp @@ -45,6 +45,9 @@ class tst_qqmllistreference : public QQmlDataTest public: tst_qqmllistreference() {} +private: + void modeData(); + private slots: void initTestCase(); void qmllistreference(); @@ -56,12 +59,19 @@ private slots: void canAt(); void canClear(); void canCount(); + void canReplace(); + void canRemoveLast(); void isReadable(); void isManipulable(); void append(); void at(); + void clear_data() { modeData(); } void clear(); void count(); + void replace_data() { modeData(); } + void replace(); + void removeLast_data() { modeData(); } + void removeLast(); void copy(); void qmlmetaproperty(); void engineTypes(); @@ -76,7 +86,67 @@ class TestType : public QObject Q_PROPERTY(int intProperty READ intProperty) public: - TestType() : property(this, data) {} + enum Mode { + SyntheticClear, + SyntheticReplace, + SyntheticClearAndReplace, + SyntheticRemoveLast, + SyntheticRemoveLastAndReplace, + AutomaticReference, + AutomaticPointer + }; + + static void append(QQmlListProperty<TestType> *p, TestType *v) { + reinterpret_cast<QList<TestType *> *>(p->data)->append(v); + } + static int count(QQmlListProperty<TestType> *p) { + return reinterpret_cast<QList<TestType *> *>(p->data)->count(); + } + static TestType *at(QQmlListProperty<TestType> *p, int idx) { + return reinterpret_cast<QList<TestType *> *>(p->data)->at(idx); + } + static void clear(QQmlListProperty<TestType> *p) { + return reinterpret_cast<QList<TestType *> *>(p->data)->clear(); + } + static void replace(QQmlListProperty<TestType> *p, int idx, TestType *v) { + return reinterpret_cast<QList<TestType *> *>(p->data)->replace(idx, v); + } + static void removeLast(QQmlListProperty<TestType> *p) { + return reinterpret_cast<QList<TestType *> *>(p->data)->removeLast(); + } + + TestType(Mode mode = AutomaticReference) + { + switch (mode) { + case SyntheticClear: + property = QQmlListProperty<TestType>(this, &data, append, count, at, nullptr, + replace, removeLast); + break; + case SyntheticReplace: + property = QQmlListProperty<TestType>(this, &data, append, count, at, clear, + nullptr, removeLast); + break; + case SyntheticClearAndReplace: + property = QQmlListProperty<TestType>(this, &data, append, count, at, nullptr, + nullptr, removeLast); + break; + case SyntheticRemoveLast: + property = QQmlListProperty<TestType>(this, &data, append, count, at, clear, + replace, nullptr); + break; + case SyntheticRemoveLastAndReplace: + property = QQmlListProperty<TestType>(this, &data, append, count, at, clear, + nullptr, nullptr); + break; + case AutomaticReference: + property = QQmlListProperty<TestType>(this, data); + break; + case AutomaticPointer: + property = QQmlListProperty<TestType>(this, &data); + break; + } + } + QQmlListProperty<TestType> dataProperty() { return property; } int intProperty() const { return 10; } @@ -84,6 +154,20 @@ public: QQmlListProperty<TestType> property; }; +Q_DECLARE_METATYPE(TestType::Mode) + +void tst_qqmllistreference::modeData() +{ + QTest::addColumn<TestType::Mode>("mode"); + QTest::addRow("AutomaticReference") << TestType::AutomaticReference; + QTest::addRow("AutomaticPointer") << TestType::AutomaticPointer; + QTest::addRow("SyntheticClear") << TestType::SyntheticClear; + QTest::addRow("SyntheticReplace") << TestType::SyntheticReplace; + QTest::addRow("SyntheticClearAndReplace") << TestType::SyntheticClearAndReplace; + QTest::addRow("SyntheticRemoveLast") << TestType::SyntheticRemoveLast; + QTest::addRow("SyntheticRemoveLastAndReplace") << TestType::SyntheticRemoveLastAndReplace; +} + void tst_qqmllistreference::initTestCase() { QQmlDataTest::initTestCase(); @@ -340,6 +424,64 @@ void tst_qqmllistreference::canCount() } } +void tst_qqmllistreference::canReplace() +{ + QScopedPointer<TestType> tt(new TestType); + + { + QQmlListReference ref; + QVERIFY(!ref.canReplace()); + } + + { + QQmlListReference ref(tt.data(), "blah"); + QVERIFY(!ref.canReplace()); + } + + { + QQmlListReference ref(tt.data(), "data"); + QVERIFY(ref.canReplace()); + tt.reset(); + QVERIFY(!ref.canReplace()); + } + + { + TestType tt; + tt.property.replace = nullptr; + QQmlListReference ref(&tt, "data"); + QVERIFY(!ref.canReplace()); + } +} + +void tst_qqmllistreference::canRemoveLast() +{ + QScopedPointer<TestType> tt(new TestType); + + { + QQmlListReference ref; + QVERIFY(!ref.canRemoveLast()); + } + + { + QQmlListReference ref(tt.data(), "blah"); + QVERIFY(!ref.canRemoveLast()); + } + + { + QQmlListReference ref(tt.data(), "data"); + QVERIFY(ref.canRemoveLast()); + tt.reset(); + QVERIFY(!ref.canRemoveLast()); + } + + { + TestType tt; + tt.property.removeLast = nullptr; + QQmlListReference ref(&tt, "data"); + QVERIFY(!ref.canRemoveLast()); + } +} + void tst_qqmllistreference::isReadable() { TestType *tt = new TestType; @@ -474,7 +616,8 @@ void tst_qqmllistreference::at() void tst_qqmllistreference::clear() { - TestType *tt = new TestType; + QFETCH(TestType::Mode, mode); + TestType *tt = new TestType(mode); tt->data.append(tt); tt->data.append(0); tt->data.append(tt); @@ -540,6 +683,70 @@ void tst_qqmllistreference::count() } } +void tst_qqmllistreference::replace() +{ + QFETCH(TestType::Mode, mode); + QScopedPointer<TestType> tt(new TestType(mode)); + tt->data.append(tt.get()); + tt->data.append(nullptr); + tt->data.append(tt.get()); + + { + QQmlListReference ref(tt.get(), "data"); + QVERIFY(ref.replace(1, tt.get())); + QCOMPARE(ref.at(1), tt.get()); + QVERIFY(ref.replace(2, nullptr)); + QCOMPARE(ref.at(2), nullptr); + QCOMPARE(ref.count(), 3); + tt.reset(); + QVERIFY(!ref.replace(0, tt.get())); + } + + { + TestType tt; + tt.data.append(&tt); + tt.property.replace = nullptr; + QQmlListReference ref(&tt, "data"); + QVERIFY(!ref.replace(0, nullptr)); + } +} + +void tst_qqmllistreference::removeLast() +{ + QFETCH(TestType::Mode, mode); + QScopedPointer<TestType> tt(new TestType(mode)); + tt->data.append(tt.get()); + tt->data.append(nullptr); + tt->data.append(tt.get()); + + { + QQmlListReference ref; + QVERIFY(!ref.removeLast()); + } + + { + QQmlListReference ref(tt.get(), "blah"); + QVERIFY(!ref.removeLast()); + } + + { + QQmlListReference ref(tt.get(), "data"); + QCOMPARE(tt->data.count(), 3); + QVERIFY(ref.removeLast()); + QCOMPARE(tt->data.count(), 2); + tt.reset(); + QVERIFY(!ref.removeLast()); + } + + { + TestType tt; + tt.property.removeLast = nullptr; + QQmlListReference ref(&tt, "data"); + ref.append(&tt); + QVERIFY(!ref.removeLast()); + } +} + void tst_qqmllistreference::copy() { TestType tt; diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp index c846ee32df..e3094db708 100644 --- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp +++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp @@ -449,7 +449,7 @@ void tst_qqmllocale::firstDayOfWeek() Q_ARG(QVariant, QVariant(locale))); QVariant val = obj->property("firstDayOfWeek"); - QCOMPARE(val.type(), QVariant::Int); + QCOMPARE(val.userType(), QMetaType::Int); int day = int(QLocale(locale).firstDayOfWeek()); if (day == 7) // JS Date days in range 0(Sunday) to 6(Saturday) diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index 72295044a5..296d1b14e0 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -157,7 +157,7 @@ void tst_qqmlmetatype::initTestCase() void tst_qqmlmetatype::qmlParserStatusCast() { - QVERIFY(!QQmlMetaType::qmlType(QVariant::Int).isValid()); + QVERIFY(!QQmlMetaType::qmlType(QMetaType::Int).isValid()); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()).isValid()); QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()).parserStatusCast(), -1); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<ValueSourceTestType *>()).isValid()); @@ -177,7 +177,7 @@ void tst_qqmlmetatype::qmlParserStatusCast() void tst_qqmlmetatype::qmlPropertyValueSourceCast() { - QVERIFY(!QQmlMetaType::qmlType(QVariant::Int).isValid()); + QVERIFY(!QQmlMetaType::qmlType(QMetaType::Int).isValid()); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()).isValid()); QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()).propertyValueSourceCast(), -1); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<ParserStatusTestType *>()).isValid()); @@ -197,7 +197,7 @@ void tst_qqmlmetatype::qmlPropertyValueSourceCast() void tst_qqmlmetatype::qmlPropertyValueInterceptorCast() { - QVERIFY(!QQmlMetaType::qmlType(QVariant::Int).isValid()); + QVERIFY(!QQmlMetaType::qmlType(QMetaType::Int).isValid()); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()).isValid()); QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId<TestType *>()).propertyValueInterceptorCast(), -1); QVERIFY(QQmlMetaType::qmlType(qMetaTypeId<ParserStatusTestType *>()).isValid()); @@ -256,8 +256,8 @@ void tst_qqmlmetatype::prettyTypeName() void tst_qqmlmetatype::isList() { - QCOMPARE(QQmlMetaType::isList(QVariant::Invalid), false); - QCOMPARE(QQmlMetaType::isList(QVariant::Int), false); + QCOMPARE(QQmlMetaType::isList(QMetaType::UnknownType), false); + QCOMPARE(QQmlMetaType::isList(QMetaType::Int), false); QQmlListProperty<TestType> list; @@ -327,10 +327,10 @@ void tst_qqmlmetatype::externalEnums() QScopedPointer<QObject> obj(c.create()); QVERIFY(obj); QVariant a = obj->property("a"); - QCOMPARE(a.type(), QVariant::Int); + QCOMPARE(a.userType(), QVariant::Int); QCOMPARE(a.toInt(), int(QStandardPaths::DocumentsLocation)); QVariant b = obj->property("b"); - QCOMPARE(b.type(), QVariant::Int); + QCOMPARE(b.userType(), QVariant::Int); QCOMPARE(b.toInt(), int(QStandardPaths::DocumentsLocation)); } @@ -394,10 +394,10 @@ void tst_qqmlmetatype::unregisterCustomType() QObject *controller = obj->findChild<QObject *>("controller"); QVERIFY(qobject_cast<Controller1 *>(controller)); QVariant stringVal = controller->property("string"); - QCOMPARE(stringVal.type(), QVariant::String); + QCOMPARE(stringVal.userType(), QVariant::String); QCOMPARE(stringVal.toString(), QStringLiteral("Controller #1")); QVariant enumVal = controller->property("enumVal"); - QCOMPARE(enumVal.type(), QVariant::Int); + QCOMPARE(enumVal.userType(), QVariant::Int); QCOMPARE(enumVal.toInt(), 1); } QQmlMetaType::unregisterType(controllerId); @@ -417,10 +417,10 @@ void tst_qqmlmetatype::unregisterCustomType() QObject *controller = obj->findChild<QObject *>("controller"); QVERIFY(qobject_cast<Controller2 *>(controller)); QVariant stringVal = controller->property("string"); - QCOMPARE(stringVal.type(), QVariant::String); + QCOMPARE(stringVal.userType(), QVariant::String); QCOMPARE(stringVal.toString(), QStringLiteral("Controller #2")); QVariant enumVal = controller->property("enumVal"); - QCOMPARE(enumVal.type(), QVariant::Int); + QCOMPARE(enumVal.userType(), QVariant::Int); QCOMPARE(enumVal.toInt(), 111); } QQmlMetaType::unregisterType(controllerId); @@ -440,10 +440,10 @@ void tst_qqmlmetatype::unregisterCustomType() QObject *controller = obj->findChild<QObject *>("controller"); QVERIFY(qobject_cast<Controller1 *>(controller)); QVariant stringVal = controller->property("string"); - QCOMPARE(stringVal.type(), QVariant::String); + QCOMPARE(stringVal.userType(), QVariant::String); QCOMPARE(stringVal.toString(), QStringLiteral("Controller #1")); QVariant enumVal = controller->property("enumVal"); - QCOMPARE(enumVal.type(), QVariant::Int); + QCOMPARE(enumVal.userType(), QVariant::Int); QCOMPARE(enumVal.toInt(), 1); } } @@ -489,7 +489,7 @@ void tst_qqmlmetatype::unregisterCustomSingletonType() QScopedPointer<QObject> obj(c.create()); QVERIFY(obj.data()); QVariant stringVal = obj->property("text"); - QCOMPARE(stringVal.type(), QVariant::String); + QCOMPARE(stringVal.userType(), QVariant::String); QCOMPARE(stringVal.toString(), QStringLiteral("StaticProvider #1")); } QQmlMetaType::unregisterType(staticProviderId); @@ -505,7 +505,7 @@ void tst_qqmlmetatype::unregisterCustomSingletonType() QScopedPointer<QObject> obj(c.create()); QVERIFY(obj.data()); QVariant stringVal = obj->property("text"); - QCOMPARE(stringVal.type(), QVariant::String); + QCOMPARE(stringVal.userType(), QVariant::String); QCOMPARE(stringVal.toString(), QStringLiteral("StaticProvider #2")); } QQmlMetaType::unregisterType(staticProviderId); @@ -521,7 +521,7 @@ void tst_qqmlmetatype::unregisterCustomSingletonType() QScopedPointer<QObject> obj(c.create()); QVERIFY(obj.data()); QVariant stringVal = obj->property("text"); - QCOMPARE(stringVal.type(), QVariant::String); + QCOMPARE(stringVal.userType(), QVariant::String); QCOMPARE(stringVal.toString(), QStringLiteral("StaticProvider #1")); } } diff --git a/tests/auto/qml/qqmlvaluetypes/data/qmlproperty_read.qml b/tests/auto/qml/qqmlvaluetypes/data/qmlproperty_read.qml new file mode 100644 index 0000000000..b9c9ee779b --- /dev/null +++ b/tests/auto/qml/qqmlvaluetypes/data/qmlproperty_read.qml @@ -0,0 +1,9 @@ +import Test 1.0 +import QtQml 2.0 + +MyTypeObject { + property QtObject colorPropertyObject: colorProperty.object + property string colorPropertyName: colorProperty.name + property QtObject invalidPropertyObject: invalidProperty.object + property string invalidPropertyName: invalidProperty.name +} diff --git a/tests/auto/qml/qqmlvaluetypes/testtypes.h b/tests/auto/qml/qqmlvaluetypes/testtypes.h index 798c96e188..e11d831236 100644 --- a/tests/auto/qml/qqmlvaluetypes/testtypes.h +++ b/tests/auto/qml/qqmlvaluetypes/testtypes.h @@ -71,6 +71,8 @@ class MyTypeObject : public QObject Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY changed) Q_PROPERTY(QColor invalidColor READ invalidColor CONSTANT) Q_PROPERTY(QVariant variant READ variant NOTIFY changed) + Q_PROPERTY(QQmlProperty colorProperty READ colorProperty CONSTANT) + Q_PROPERTY(QQmlProperty invalidProperty READ invalidProperty CONSTANT) public: MyTypeObject() : @@ -173,6 +175,10 @@ public: QVariant variant() const { return sizef(); } + QQmlProperty colorProperty() { return QQmlProperty(this, "color"); } + + QQmlProperty invalidProperty() const { return QQmlProperty(); } + void emitRunScript() { emit runScript(); } signals: diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 3e9047cc5a..7c75743311 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -67,6 +67,7 @@ private slots: void color(); void variant(); void locale(); + void qmlproperty(); void bindingAssignment(); void bindingRead(); @@ -360,6 +361,20 @@ void tst_qqmlvaluetypes::locale() } } +void tst_qqmlvaluetypes::qmlproperty() +{ + QQmlComponent component(&engine, testFileUrl("qmlproperty_read.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != nullptr); + + QCOMPARE(object->property("colorPropertyObject").value<QObject *>(), object); + QCOMPARE(object->property("colorPropertyName").toString(), "color"); + QCOMPARE(object->property("invalidPropertyObject").value<QObject *>(), nullptr); + QCOMPARE(object->property("invalidPropertyName").toString(), ""); + + delete object; +} + void tst_qqmlvaluetypes::sizereadonly() { { diff --git a/tests/auto/quick/qquicktext/data/displaySuperscriptedTag.qml b/tests/auto/quick/qquicktext/data/displaySuperscriptedTag.qml new file mode 100644 index 0000000000..b0ed21a0c8 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/displaySuperscriptedTag.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +Rectangle { + width: 200 + height: 200 + color: "white" + Text { + objectName: "text" + textFormat: Text.RichText + anchors.fill: parent + color: "black" + // display a black rectangle at the top left of the text + text: "<span style=\"background-color:rgba(255,255,255,255);vertical-align:super;\">█</span>This is a test" + verticalAlignment: Text.AlignTop + horizontalAlignment: Text.AlignLeft + font.pixelSize: 30 + } +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 06ce730091..a64c9372da 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -168,6 +168,8 @@ private slots: void transparentBackground(); + void displaySuperscriptedTag(); + private: QStringList standard; QStringList richText; @@ -4507,6 +4509,32 @@ void tst_qquicktext::transparentBackground() QCOMPARE(color.blue(), 255); QCOMPARE(color.green(), 255); } + +void tst_qquicktext::displaySuperscriptedTag() +{ + if ((QGuiApplication::platformName() == QLatin1String("offscreen")) + || (QGuiApplication::platformName() == QLatin1String("minimal"))) + QSKIP("Skipping due to grabToImage not functional on offscreen/minimimal platforms"); + + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("displaySuperscriptedTag.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickText *text = window->findChild<QQuickText *>("text"); + QVERIFY(text); + + QImage img = window->grabWindow(); + QCOMPARE(img.isNull(), false); + + QColor color = img.pixelColor(1, static_cast<int>(text->contentHeight()) / 4 * 3); + QCOMPARE(color.red(), 255); + QCOMPARE(color.blue(), 255); + QCOMPARE(color.green(), 255); +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" |