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>
This commit is contained in:
parent
55a6938b32
commit
f5b24fd48d
|
@ -12,8 +12,8 @@
|
||||||
/examples/quick/extras/drawer/drawer
|
/examples/quick/extras/drawer/drawer
|
||||||
|
|
||||||
/tests/auto/controls/tst_controls
|
/tests/auto/controls/tst_controls
|
||||||
/tests/auto/declarative/tst_declarative
|
|
||||||
/tests/auto/extras/tst_extras
|
/tests/auto/extras/tst_extras
|
||||||
|
/tests/auto/sanity/tst_sanity
|
||||||
/tests/benchmarks/creationtime/tst_creationtime
|
/tests/benchmarks/creationtime/tst_creationtime
|
||||||
/tests/benchmarks/objectcount/tst_objectcount
|
/tests/benchmarks/objectcount/tst_objectcount
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
SUBDIRS += \
|
SUBDIRS += \
|
||||||
controls \
|
controls \
|
||||||
declarative \
|
extras \
|
||||||
extras
|
sanity
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = tst_declarative
|
TARGET = tst_sanity
|
||||||
|
|
||||||
QT += qml testlib core-private qml-private
|
QT += qml testlib core-private qml-private
|
||||||
CONFIG += testcase
|
CONFIG += testcase
|
||||||
osx:CONFIG -= app_bundle
|
osx:CONFIG -= app_bundle
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/tst_declarative.cpp
|
$$PWD/tst_sanity.cpp
|
|
@ -36,28 +36,62 @@
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
#include <QtQml>
|
#include <QtQml>
|
||||||
|
#include <QtCore/private/qhooks_p.h>
|
||||||
#include <QtQml/private/qqmljsengine_p.h>
|
#include <QtQml/private/qqmljsengine_p.h>
|
||||||
#include <QtQml/private/qqmljslexer_p.h>
|
#include <QtQml/private/qqmljslexer_p.h>
|
||||||
#include <QtQml/private/qqmljsparser_p.h>
|
#include <QtQml/private/qqmljsparser_p.h>
|
||||||
#include <QtQml/private/qqmljsast_p.h>
|
#include <QtQml/private/qqmljsast_p.h>
|
||||||
#include <QtQml/private/qqmljsastvisitor_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
|
Q_OBJECT
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void init();
|
||||||
|
void cleanup();
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void testFiles();
|
|
||||||
void testFunctions();
|
void jsFiles();
|
||||||
void testFunctions_data();
|
void functions();
|
||||||
void testSignalHandlers();
|
void functions_data();
|
||||||
void testSignalHandlers_data();
|
void signalHandlers();
|
||||||
|
void signalHandlers_data();
|
||||||
|
void anchors();
|
||||||
|
void anchors_data();
|
||||||
|
void attachedObjects();
|
||||||
|
void attachedObjects_data();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QQmlEngine engine;
|
||||||
QMap<QString, QString> files;
|
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
|
class BaseValidator : public QQmlJS::AST::Visitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -109,7 +143,7 @@ static QMap<QString, QString> listQmlFiles(const QDir &dir)
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Declarative::initTestCase()
|
void tst_Sanity::initTestCase()
|
||||||
{
|
{
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
foreach (const QString &path, engine.importPathList()) {
|
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;
|
QMap<QString, QString>::const_iterator it;
|
||||||
for (it = files.begin(); it != files.end(); ++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"));
|
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, control);
|
||||||
QFETCH(QString, filePath);
|
QFETCH(QString, filePath);
|
||||||
|
@ -148,7 +182,7 @@ void tst_Declarative::testFunctions()
|
||||||
QFAIL(qPrintable(validator.errors()));
|
QFAIL(qPrintable(validator.errors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Declarative::testFunctions_data()
|
void tst_Sanity::functions_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("control");
|
QTest::addColumn<QString>("control");
|
||||||
QTest::addColumn<QString>("filePath");
|
QTest::addColumn<QString>("filePath");
|
||||||
|
@ -175,7 +209,7 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_Declarative::testSignalHandlers()
|
void tst_Sanity::signalHandlers()
|
||||||
{
|
{
|
||||||
QFETCH(QString, control);
|
QFETCH(QString, control);
|
||||||
QFETCH(QString, filePath);
|
QFETCH(QString, filePath);
|
||||||
|
@ -185,7 +219,7 @@ void tst_Declarative::testSignalHandlers()
|
||||||
QFAIL(qPrintable(validator.errors()));
|
QFAIL(qPrintable(validator.errors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Declarative::testSignalHandlers_data()
|
void tst_Sanity::signalHandlers_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("control");
|
QTest::addColumn<QString>("control");
|
||||||
QTest::addColumn<QString>("filePath");
|
QTest::addColumn<QString>("filePath");
|
||||||
|
@ -195,6 +229,59 @@ void tst_Declarative::testSignalHandlers_data()
|
||||||
QTest::newRow(qPrintable(it.key())) << it.key() << it.value();
|
QTest::newRow(qPrintable(it.key())) << it.key() << it.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_Declarative)
|
void tst_Sanity::anchors()
|
||||||
|
{
|
||||||
|
QFETCH(QString, control);
|
||||||
|
QFETCH(QString, filePath);
|
||||||
|
|
||||||
#include "tst_declarative.moc"
|
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");
|
||||||
|
|
||||||
|
QMap<QString, QString>::const_iterator it;
|
||||||
|
for (it = files.begin(); it != files.end(); ++it)
|
||||||
|
QTest::newRow(qPrintable(it.key())) << it.key() << it.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(tst_Sanity)
|
||||||
|
|
||||||
|
#include "tst_sanity.moc"
|
Loading…
Reference in New Issue