aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-06-14 16:28:25 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-06-14 16:10:05 +0000
commitf5b24fd48d494d2c43c34cab84f34d1f2e4e33a8 (patch)
tree531080c80560d23f854b16cc2ff3aa4ea63ebd32 /tests
parent55a6938b3204b28976d456be9f9f68bf44c22051 (diff)
Auto test anchors & attached objects
Rename the former tst_declarative to tst_sanity and extend it with tests to prevent: a) use of anchors, and b) multiple attached object instances of the same type. Anchors are not allowed for two reasons: - performance (QQuickAnchors is a QObject), and - to let users relayout delegates (x/y/width/height bindings can be overridden, anchors not so easily) Multiple attached object instances (eg. Theme) can easily happen by accident. "Theme.fooColor" can be used in the control root, but in all delegate items, "control.Theme.fooColor" must be used instead. Change-Id: I4045d5bd717fa21db79d1c3bd618fc450e292fa4 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro4
-rw-r--r--tests/auto/sanity/sanity.pro (renamed from tests/auto/declarative/declarative.pro)4
-rw-r--r--tests/auto/sanity/tst_sanity.cpp (renamed from tests/auto/declarative/tst_declarative.cpp)117
3 files changed, 106 insertions, 19 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index fca8731c..a5cbd53c 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -1,5 +1,5 @@
TEMPLATE = subdirs
SUBDIRS += \
controls \
- declarative \
- extras
+ extras \
+ sanity
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/sanity/sanity.pro
index aae8c20e..436dc7dd 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/sanity/sanity.pro
@@ -1,9 +1,9 @@
TEMPLATE = app
-TARGET = tst_declarative
+TARGET = tst_sanity
QT += qml testlib core-private qml-private
CONFIG += testcase
osx:CONFIG -= app_bundle
SOURCES += \
- $$PWD/tst_declarative.cpp
+ $$PWD/tst_sanity.cpp
diff --git a/tests/auto/declarative/tst_declarative.cpp b/tests/auto/sanity/tst_sanity.cpp
index d16046da..eb7c5375 100644
--- a/tests/auto/declarative/tst_declarative.cpp
+++ b/tests/auto/sanity/tst_sanity.cpp
@@ -36,28 +36,62 @@
#include <QtTest>
#include <QtQml>
+#include <QtCore/private/qhooks_p.h>
#include <QtQml/private/qqmljsengine_p.h>
#include <QtQml/private/qqmljslexer_p.h>
#include <QtQml/private/qqmljsparser_p.h>
#include <QtQml/private/qqmljsast_p.h>
#include <QtQml/private/qqmljsastvisitor_p.h>
-class tst_Declarative : public QObject
+Q_GLOBAL_STATIC(QObjectList, qt_qobjects)
+
+extern "C" Q_DECL_EXPORT void qt_addQObject(QObject *object)
+{
+ qt_qobjects->append(object);
+}
+
+extern "C" Q_DECL_EXPORT void qt_removeQObject(QObject *object)
+{
+ qt_qobjects->removeAll(object);
+}
+
+class tst_Sanity : public QObject
{
Q_OBJECT
private slots:
+ void init();
+ void cleanup();
void initTestCase();
- void testFiles();
- void testFunctions();
- void testFunctions_data();
- void testSignalHandlers();
- void testSignalHandlers_data();
+
+ void jsFiles();
+ void functions();
+ void functions_data();
+ void signalHandlers();
+ void signalHandlers_data();
+ void anchors();
+ void anchors_data();
+ void attachedObjects();
+ void attachedObjects_data();
private:
+ QQmlEngine engine;
QMap<QString, QString> files;
};
+void tst_Sanity::init()
+{
+ qtHookData[QHooks::AddQObject] = reinterpret_cast<quintptr>(&qt_addQObject);
+ qtHookData[QHooks::RemoveQObject] = reinterpret_cast<quintptr>(&qt_removeQObject);
+}
+
+void tst_Sanity::cleanup()
+{
+ qt_qobjects->clear();
+ qtHookData[QHooks::AddQObject] = 0;
+ qtHookData[QHooks::RemoveQObject] = 0;
+}
+
class BaseValidator : public QQmlJS::AST::Visitor
{
public:
@@ -109,7 +143,7 @@ static QMap<QString, QString> listQmlFiles(const QDir &dir)
return files;
}
-void tst_Declarative::initTestCase()
+void tst_Sanity::initTestCase()
{
QQmlEngine engine;
foreach (const QString &path, engine.importPathList()) {
@@ -119,11 +153,11 @@ void tst_Declarative::initTestCase()
}
}
-void tst_Declarative::testFiles()
+void tst_Sanity::jsFiles()
{
QMap<QString, QString>::const_iterator it;
for (it = files.begin(); it != files.end(); ++it) {
- if (QFileInfo(it.value()).suffix() == QString("js"))
+ if (QFileInfo(it.value()).suffix() == QStringLiteral("js"))
QFAIL(qPrintable(it.value() + ": JS files are not allowed"));
}
}
@@ -138,7 +172,7 @@ protected:
}
};
-void tst_Declarative::testFunctions()
+void tst_Sanity::functions()
{
QFETCH(QString, control);
QFETCH(QString, filePath);
@@ -148,7 +182,7 @@ void tst_Declarative::testFunctions()
QFAIL(qPrintable(validator.errors()));
}
-void tst_Declarative::testFunctions_data()
+void tst_Sanity::functions_data()
{
QTest::addColumn<QString>("control");
QTest::addColumn<QString>("filePath");
@@ -175,7 +209,7 @@ protected:
}
};
-void tst_Declarative::testSignalHandlers()
+void tst_Sanity::signalHandlers()
{
QFETCH(QString, control);
QFETCH(QString, filePath);
@@ -185,7 +219,60 @@ void tst_Declarative::testSignalHandlers()
QFAIL(qPrintable(validator.errors()));
}
-void tst_Declarative::testSignalHandlers_data()
+void tst_Sanity::signalHandlers_data()
+{
+ QTest::addColumn<QString>("control");
+ QTest::addColumn<QString>("filePath");
+
+ QMap<QString, QString>::const_iterator it;
+ for (it = files.begin(); it != files.end(); ++it)
+ QTest::newRow(qPrintable(it.key())) << it.key() << it.value();
+}
+
+void tst_Sanity::anchors()
+{
+ QFETCH(QString, control);
+ QFETCH(QString, filePath);
+
+ QQmlComponent component(&engine);
+ component.loadUrl(QUrl::fromLocalFile(filePath));
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(object.data());
+ foreach (QObject *object, *qt_qobjects)
+ QVERIFY2(!object->inherits("QQuickAnchors"), "Anchors are not allowed");
+}
+
+void tst_Sanity::anchors_data()
+{
+ QTest::addColumn<QString>("control");
+ QTest::addColumn<QString>("filePath");
+
+ QMap<QString, QString>::const_iterator it;
+ for (it = files.begin(); it != files.end(); ++it)
+ QTest::newRow(qPrintable(it.key())) << it.key() << it.value();
+}
+
+void tst_Sanity::attachedObjects()
+{
+ QFETCH(QString, control);
+ QFETCH(QString, filePath);
+
+ QQmlComponent component(&engine);
+ component.loadUrl(QUrl::fromLocalFile(filePath));
+
+ QSet<QString> classNames;
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(object.data());
+ foreach (QObject *object, *qt_qobjects) {
+ QString className = object->metaObject()->className();
+ if (className.endsWith("Attached"))
+ QVERIFY2(!classNames.contains(className), qPrintable(QString("Multiple instances of attached type %1").arg(className)));
+ classNames.insert(className);
+ }
+}
+
+void tst_Sanity::attachedObjects_data()
{
QTest::addColumn<QString>("control");
QTest::addColumn<QString>("filePath");
@@ -195,6 +282,6 @@ void tst_Declarative::testSignalHandlers_data()
QTest::newRow(qPrintable(it.key())) << it.key() << it.value();
}
-QTEST_MAIN(tst_Declarative)
+QTEST_MAIN(tst_Sanity)
-#include "tst_declarative.moc"
+#include "tst_sanity.moc"