From 74e4d18616130fa74208587ee0b12cd778172c9d Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 11 Jan 2018 14:45:26 +0100 Subject: tst_sanity: exclude internal helper types Test file names against registered QML types to avoid including any internal helper types like CursorDelegate.qml and RectangularGlow.qml. Change-Id: Ia3079ea215eea59f7e405a50c3170fb4530f4239 Reviewed-by: Mitch Curtis --- tests/auto/sanity/BLACKLIST | 6 ------ tests/auto/sanity/tst_sanity.cpp | 10 ++++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/auto/sanity/BLACKLIST b/tests/auto/sanity/BLACKLIST index 965790e7..b2b1a905 100644 --- a/tests/auto/sanity/BLACKLIST +++ b/tests/auto/sanity/BLACKLIST @@ -1,5 +1,3 @@ -[signalHandlers:material/CursorDelegate.qml] -* [attachedObjects:material/ComboBox.qml] * [attachedObjects:material/Switch.qml] @@ -8,7 +6,3 @@ * [attachedObjects:universal/ComboBox.qml] * -[functions:material/RectangularGlow.qml] -* -[anchors:material/RectangularGlow.qml] -* diff --git a/tests/auto/sanity/tst_sanity.cpp b/tests/auto/sanity/tst_sanity.cpp index 2988c96c..ae442b4a 100644 --- a/tests/auto/sanity/tst_sanity.cpp +++ b/tests/auto/sanity/tst_sanity.cpp @@ -42,6 +42,7 @@ #include #include #include +#include Q_GLOBAL_STATIC(QObjectList, qt_qobjects) @@ -138,12 +139,17 @@ private: void tst_Sanity::initTestCase() { + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData(QString("import QtQuick.Templates 2.%1; Control { }").arg(QT_VERSION_MINOR - 7).toUtf8(), QUrl()); + + const QStringList qmlTypeNames = QQmlMetaType::qmlTypeNames(); + QDirIterator it(QQC2_IMPORT_PATH, QStringList() << "*.qml" << "*.js", QDir::Files, QDirIterator::Subdirectories); - const QStringList excludeDirs = QStringList() << QStringLiteral("snippets") << QStringLiteral("designer"); while (it.hasNext()) { it.next(); QFileInfo info = it.fileInfo(); - if (!excludeDirs.contains(info.dir().dirName())) + if (qmlTypeNames.contains(QStringLiteral("QtQuick.Templates/") + info.baseName())) files.insert(info.dir().dirName() + "/" + info.fileName(), info.filePath()); } } -- cgit v1.2.3 From fd7106f51d846cc02e500a5b36e846448665a47c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 11 Jan 2018 14:47:45 +0100 Subject: tst_sanity: unblacklist ComboBox ComboBox no longer creates a popup instance at construction time. Change-Id: Ie036d75acbd2a7a391c1ed1af590409f4eddd587 Reviewed-by: Mitch Curtis --- tests/auto/sanity/BLACKLIST | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/sanity/BLACKLIST b/tests/auto/sanity/BLACKLIST index b2b1a905..42ad3448 100644 --- a/tests/auto/sanity/BLACKLIST +++ b/tests/auto/sanity/BLACKLIST @@ -1,8 +1,4 @@ -[attachedObjects:material/ComboBox.qml] -* [attachedObjects:material/Switch.qml] * [attachedObjects:material/SwitchDelegate.qml] * -[attachedObjects:universal/ComboBox.qml] -* -- cgit v1.2.3 From 842fa74658be458ef7c51f00901220d232ad8330 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 2 Jan 2018 16:26:03 +0100 Subject: tst_sanity: check for internal IDs Task-number: QTBUG-65341 Change-Id: I51bd3390a18e50e37dfdd880dfa8df262d478b04 Reviewed-by: Mitch Curtis --- tests/auto/sanity/BLACKLIST | 6 ++++ tests/auto/sanity/tst_sanity.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) (limited to 'tests') diff --git a/tests/auto/sanity/BLACKLIST b/tests/auto/sanity/BLACKLIST index 42ad3448..112c9fba 100644 --- a/tests/auto/sanity/BLACKLIST +++ b/tests/auto/sanity/BLACKLIST @@ -2,3 +2,9 @@ * [attachedObjects:material/SwitchDelegate.qml] * +[ids:controls/Tumbler.qml] +* +[ids:material/Tumbler.qml] +* +[ids:universal/Tumbler.qml] +* diff --git a/tests/auto/sanity/tst_sanity.cpp b/tests/auto/sanity/tst_sanity.cpp index ae442b4a..c99c42cb 100644 --- a/tests/auto/sanity/tst_sanity.cpp +++ b/tests/auto/sanity/tst_sanity.cpp @@ -74,6 +74,8 @@ private slots: void anchors_data(); void attachedObjects(); void attachedObjects_data(); + void ids(); + void ids_data(); private: QQmlEngine engine; @@ -262,6 +264,71 @@ void tst_Sanity::anchors_data() QTest::newRow(qPrintable(it.key())) << it.key() << it.value(); } +class IdValidator : public BaseValidator +{ +public: + IdValidator() : m_depth(0) { } + +protected: + bool visit(QQmlJS::AST::UiObjectBinding *) override + { + ++m_depth; + return true; + } + + void endVisit(QQmlJS::AST::UiObjectBinding *) override + { + --m_depth; + } + + bool visit(QQmlJS::AST::UiScriptBinding *node) override + { + if (m_depth == 0) + return true; + + QQmlJS::AST::UiQualifiedId *id = node->qualifiedId; + if (id && id->name == QStringLiteral("id")) + addError(QString("Internal IDs are not allowed (%1)").arg(extractName(node->statement)), node); + return true; + } + +private: + QString extractName(QQmlJS::AST::Statement *statement) + { + QQmlJS::AST::ExpressionStatement *expressionStatement = static_cast(statement); + if (!expressionStatement) + return QString(); + + QQmlJS::AST::IdentifierExpression *expression = static_cast(expressionStatement->expression); + if (!expression) + return QString(); + + return expression->name.toString(); + } + + int m_depth; +}; + +void tst_Sanity::ids() +{ + QFETCH(QString, control); + QFETCH(QString, filePath); + + IdValidator validator; + if (!validator.validate(filePath)) + QFAIL(qPrintable(validator.errors())); +} + +void tst_Sanity::ids_data() +{ + QTest::addColumn("control"); + QTest::addColumn("filePath"); + + QMap::const_iterator it; + for (it = files.constBegin(); it != files.constEnd(); ++it) + QTest::newRow(qPrintable(it.key())) << it.key() << it.value(); +} + static void addTestRows(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist = QStringList()) { // We cannot use QQmlComponent to load QML files directly from the source tree. -- cgit v1.2.3 From d61567f3cfa100aeab865bd6b436de87970575f5 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 11 Jan 2018 15:19:14 +0100 Subject: Tumbler: cleanup internal IDs We can already cleanup the internal IDs even if Tumbler doesn't have deferred execution enabled. Change-Id: Ide9a0a6c6d1680c6df6b968b5702a6270fea3326 Reviewed-by: Mitch Curtis --- tests/auto/sanity/BLACKLIST | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/sanity/BLACKLIST b/tests/auto/sanity/BLACKLIST index 112c9fba..42ad3448 100644 --- a/tests/auto/sanity/BLACKLIST +++ b/tests/auto/sanity/BLACKLIST @@ -2,9 +2,3 @@ * [attachedObjects:material/SwitchDelegate.qml] * -[ids:controls/Tumbler.qml] -* -[ids:material/Tumbler.qml] -* -[ids:universal/Tumbler.qml] -* -- cgit v1.2.3