2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:29:18 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 04:04:27 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-05-24 11:43:28 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-24 11:43:28 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <qtest.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <private/qqmlmetatype_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsItem>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QQmlContext>
|
2011-08-29 22:17:48 +00:00
|
|
|
#include <QtQuick1/private/qdeclarativetextinput_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <private/qobject_p.h>
|
|
|
|
|
|
|
|
class tst_creation : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
tst_creation();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void qobject_cpp();
|
|
|
|
void qobject_qml();
|
|
|
|
void qobject_qmltype();
|
|
|
|
void qobject_alloc();
|
|
|
|
|
|
|
|
void qobject_10flat_qml();
|
|
|
|
void qobject_10flat_cpp();
|
|
|
|
|
|
|
|
void qobject_10tree_qml();
|
|
|
|
void qobject_10tree_cpp();
|
|
|
|
|
|
|
|
void itemtree_notree_cpp();
|
|
|
|
void itemtree_objtree_cpp();
|
|
|
|
void itemtree_cpp();
|
|
|
|
void itemtree_data_cpp();
|
|
|
|
void itemtree_qml();
|
|
|
|
void itemtree_scene_cpp();
|
|
|
|
|
|
|
|
void elements_data();
|
|
|
|
void elements();
|
|
|
|
|
|
|
|
private:
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TestType : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_PROPERTY(QQmlListProperty<QObject> resources READ resources)
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_CLASSINFO("DefaultProperty", "resources")
|
|
|
|
public:
|
|
|
|
TestType(QObject *parent = 0)
|
|
|
|
: QObject(parent) {}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlListProperty<QObject> resources() {
|
|
|
|
return QQmlListProperty<QObject>(this, 0, resources_append);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
static void resources_append(QQmlListProperty<QObject> *p, QObject *o) {
|
2011-04-27 10:05:43 +00:00
|
|
|
o->setParent(p->object);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
tst_creation::tst_creation()
|
|
|
|
{
|
|
|
|
qmlRegisterType<TestType>("Qt.test", 1, 0, "TestType");
|
|
|
|
|
|
|
|
//get rid of initialization effects
|
2011-08-29 22:17:48 +00:00
|
|
|
QDeclarative1TextInput te;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline QUrl TEST_FILE(const QString &filename)
|
|
|
|
{
|
|
|
|
return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::qobject_cpp()
|
|
|
|
{
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *obj = new QObject;
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::qobject_qml()
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent component(&engine);
|
2012-01-31 06:52:36 +00:00
|
|
|
component.setData("import QtQuick 2.0\nQtObject {}", QUrl());
|
2011-04-27 10:05:43 +00:00
|
|
|
QObject *obj = component.create();
|
|
|
|
delete obj;
|
|
|
|
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *obj = component.create();
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::qobject_10flat_qml()
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent component(&engine);
|
2011-04-27 10:05:43 +00:00
|
|
|
component.setData("import Qt.test 1.0\nTestType { resources: [ TestType{},TestType{},TestType{},TestType{},TestType{},TestType{},TestType{},TestType{},TestType{},TestType{} ] }", QUrl());
|
|
|
|
QObject *obj = component.create();
|
|
|
|
delete obj;
|
|
|
|
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *obj = component.create();
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::qobject_10flat_cpp()
|
|
|
|
{
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *item = new TestType;
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
new TestType(item);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::qobject_10tree_qml()
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent component(&engine);
|
2011-04-27 10:05:43 +00:00
|
|
|
component.setData("import Qt.test 1.0\nTestType { TestType{ TestType { TestType{ TestType{ TestType{ TestType{ TestType{ TestType{ TestType{ TestType{ } } } } } } } } } } }", QUrl());
|
|
|
|
|
|
|
|
QObject *obj = component.create();
|
|
|
|
delete obj;
|
|
|
|
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *obj = component.create();
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::qobject_10tree_cpp()
|
|
|
|
{
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *item = new TestType;
|
|
|
|
QObject *root = item;
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
item = new TestType(item);
|
|
|
|
delete root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::qobject_qmltype()
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlType *t = QQmlMetaType::qmlType("QtQuick/QtObject", 2, 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *obj = t->create();
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct QObjectFakeData {
|
|
|
|
char data[sizeof(QObjectPrivate)];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct QObjectFake {
|
|
|
|
QObjectFake();
|
|
|
|
virtual ~QObjectFake();
|
|
|
|
private:
|
|
|
|
QObjectFakeData *d;
|
|
|
|
};
|
|
|
|
|
|
|
|
QObjectFake::QObjectFake()
|
|
|
|
{
|
|
|
|
d = new QObjectFakeData;
|
|
|
|
}
|
|
|
|
|
|
|
|
QObjectFake::~QObjectFake()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::qobject_alloc()
|
|
|
|
{
|
|
|
|
QBENCHMARK {
|
|
|
|
QObjectFake *obj = new QObjectFake;
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
struct QQmlGraphics_Derived : public QObject
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
void setParent_noEvent(QObject *parent) {
|
|
|
|
bool sce = d_ptr->sendChildEvents;
|
|
|
|
d_ptr->sendChildEvents = false;
|
|
|
|
setParent(parent);
|
|
|
|
d_ptr->sendChildEvents = sce;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
inline void QQmlGraphics_setParent_noEvent(QObject *object, QObject *parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
static_cast<QQmlGraphics_Derived *>(object)->setParent_noEvent(parent);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::itemtree_notree_cpp()
|
|
|
|
{
|
|
|
|
QBENCHMARK {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *item = new QQuickItem;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < 30; ++i) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *child = new QQuickItem;
|
2011-09-19 11:28:13 +00:00
|
|
|
Q_UNUSED(child);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::itemtree_objtree_cpp()
|
|
|
|
{
|
|
|
|
QBENCHMARK {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *item = new QQuickItem;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < 30; ++i) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *child = new QQuickItem;
|
|
|
|
QQmlGraphics_setParent_noEvent(child,item);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::itemtree_cpp()
|
|
|
|
{
|
|
|
|
QBENCHMARK {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *item = new QQuickItem;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < 30; ++i) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *child = new QQuickItem;
|
|
|
|
QQmlGraphics_setParent_noEvent(child,item);
|
2011-04-27 10:05:43 +00:00
|
|
|
child->setParentItem(item);
|
|
|
|
}
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::itemtree_data_cpp()
|
|
|
|
{
|
|
|
|
QBENCHMARK {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *item = new QQuickItem;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < 30; ++i) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *child = new QQuickItem;
|
|
|
|
QQmlGraphics_setParent_noEvent(child,item);
|
|
|
|
QQmlListReference ref(item, "data");
|
2011-04-27 10:05:43 +00:00
|
|
|
ref.append(child);
|
|
|
|
}
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::itemtree_qml()
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent component(&engine, TEST_FILE("item.qml"));
|
2011-04-27 10:05:43 +00:00
|
|
|
QObject *obj = component.create();
|
|
|
|
delete obj;
|
|
|
|
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *obj = component.create();
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::itemtree_scene_cpp()
|
|
|
|
{
|
|
|
|
QGraphicsScene scene;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *root = new QQuickItem;
|
2011-04-27 10:05:43 +00:00
|
|
|
scene.addItem(root);
|
|
|
|
QBENCHMARK {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *item = new QQuickItem;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < 30; ++i) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickItem *child = new QQuickItem;
|
|
|
|
QQmlGraphics_setParent_noEvent(child,item);
|
2011-04-27 10:05:43 +00:00
|
|
|
child->setParentItem(item);
|
|
|
|
}
|
|
|
|
item->setParentItem(root);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
delete root;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::elements_data()
|
|
|
|
{
|
2011-09-19 11:28:13 +00:00
|
|
|
QTest::addColumn<QString>("type");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QList<QString> types = QQmlMetaType::qmlTypeNames();
|
2011-09-19 11:28:13 +00:00
|
|
|
foreach (QString type, types)
|
|
|
|
QTest::newRow(type.toLatin1()) << type;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_creation::elements()
|
|
|
|
{
|
2011-09-19 11:28:13 +00:00
|
|
|
QFETCH(QString, type);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlType *t = QQmlMetaType::qmlType(type, 2, 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!t || !t->isCreatable())
|
2011-10-19 03:24:34 +00:00
|
|
|
QSKIP("Non-creatable type");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QBENCHMARK {
|
|
|
|
QObject *obj = t->create();
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_creation)
|
|
|
|
|
|
|
|
#include "tst_creation.moc"
|