aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/sanity/tst_sanity.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2018-01-15 12:49:07 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2018-01-15 12:49:07 +0100
commite8106ba7700e1666d1dbb3a9f1a579146dfdb681 (patch)
tree2f22b1429b8b74c59649004db586114f3e12e128 /tests/auto/sanity/tst_sanity.cpp
parent589d52b3b64a4b5221738a28df08be2eae4d12b2 (diff)
parentd61567f3cfa100aeab865bd6b436de87970575f5 (diff)
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts: src/quicktemplates2/qquickcontrol.cpp tests/auto/sanity/tst_sanity.cpp Change-Id: I62a79fd7788fec635b9917fc91bacd7338b547fd
Diffstat (limited to 'tests/auto/sanity/tst_sanity.cpp')
-rw-r--r--tests/auto/sanity/tst_sanity.cpp77
1 files changed, 75 insertions, 2 deletions
diff --git a/tests/auto/sanity/tst_sanity.cpp b/tests/auto/sanity/tst_sanity.cpp
index f6e1c78b..df440ebd 100644
--- a/tests/auto/sanity/tst_sanity.cpp
+++ b/tests/auto/sanity/tst_sanity.cpp
@@ -42,6 +42,7 @@
#include <QtQml/private/qqmljsparser_p.h>
#include <QtQml/private/qqmljsast_p.h>
#include <QtQml/private/qqmljsastvisitor_p.h>
+#include <QtQml/private/qqmlmetatype_p.h>
Q_GLOBAL_STATIC(QObjectList, qt_qobjects)
@@ -73,6 +74,8 @@ private slots:
void anchors_data();
void attachedObjects();
void attachedObjects_data();
+ void ids();
+ void ids_data();
private:
QQmlEngine engine;
@@ -138,12 +141,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") << QStringLiteral("Sketch");
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());
}
}
@@ -256,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<QQmlJS::AST::ExpressionStatement *>(statement);
+ if (!expressionStatement)
+ return QString();
+
+ QQmlJS::AST::IdentifierExpression *expression = static_cast<QQmlJS::AST::IdentifierExpression *>(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<QString>("control");
+ QTest::addColumn<QString>("filePath");
+
+ QMap<QString, QString>::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.