summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-02-13 15:24:56 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-02-13 15:24:56 (GMT)
commitdcb2678f39345b66c5303e74c156654a8d13fe83 (patch)
treed2c7f2c9de464b1908316b94c07cc8ece831ad00 /tests/benchmarks
parent03a55630cfccf7f6ed01d865c541e07afb25c96e (diff)
parent6944a72cd26a5e3611ebd305ec665bc4c0fcee12 (diff)
downloadQt-dcb2678f39345b66c5303e74c156654a8d13fe83.zip
Qt-dcb2678f39345b66c5303e74c156654a8d13fe83.tar.gz
Qt-dcb2678f39345b66c5303e74c156654a8d13fe83.tar.bz2
Merge remote branch 'origin/master' into qt-master-from-4.6
Conflicts: tests/auto/qlineedit/tst_qlineedit.cpp tests/benchmarks/benchmarks.pro
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/benchmarks.pro2
-rw-r--r--tests/benchmarks/declarative/binding/binding.pro9
-rw-r--r--tests/benchmarks/declarative/binding/data/idproperty.txt9
-rw-r--r--tests/benchmarks/declarative/binding/data/localproperty.txt5
-rw-r--r--tests/benchmarks/declarative/binding/data/objectproperty.txt7
-rw-r--r--tests/benchmarks/declarative/binding/testtypes.cpp43
-rw-r--r--tests/benchmarks/declarative/binding/testtypes.h81
-rw-r--r--tests/benchmarks/declarative/binding/tst_binding.cpp160
-rw-r--r--tests/benchmarks/declarative/creation/creation.pro10
-rw-r--r--tests/benchmarks/declarative/creation/data/item.qml34
-rw-r--r--tests/benchmarks/declarative/creation/data/qobject.qml4
-rw-r--r--tests/benchmarks/declarative/creation/tst_creation.cpp375
-rw-r--r--tests/benchmarks/declarative/declarative.pro10
-rw-r--r--tests/benchmarks/declarative/painting/paintbenchmark.cpp309
-rw-r--r--tests/benchmarks/declarative/painting/paintbenchmark.pro13
-rw-r--r--tests/benchmarks/declarative/pointers/pointers.pro8
-rw-r--r--tests/benchmarks/declarative/pointers/tst_pointers.cpp77
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/myqmlobject.qml3
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/myqmlobject_binding.qml6
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/object.qml3
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/object_id.qml6
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/samegame/BoomBlock.qml55
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/blueStar.pngbin0 -> 278 bytes
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/blueStone.pngbin0 -> 2691 bytes
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/greenStar.pngbin0 -> 273 bytes
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/greenStone.pngbin0 -> 2662 bytes
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/redStar.pngbin0 -> 274 bytes
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/redStone.pngbin0 -> 2604 bytes
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/yellowStone.pngbin0 -> 2667 bytes
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/synthesized_properties.2.qml15
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/data/synthesized_properties.qml5
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro9
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/testtypes.cpp43
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/testtypes.h81
-rw-r--r--tests/benchmarks/declarative/qmlcomponent/tst_qmlcomponent.cpp118
-rw-r--r--tests/benchmarks/declarative/qmlgraphicsimage/image.pngbin0 -> 611 bytes
-rw-r--r--tests/benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro11
-rw-r--r--tests/benchmarks/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp102
-rw-r--r--tests/benchmarks/declarative/qmlmetaproperty/data/object.qml3
-rw-r--r--tests/benchmarks/declarative/qmlmetaproperty/data/synthesized_object.qml6
-rw-r--r--tests/benchmarks/declarative/qmlmetaproperty/qmlmetaproperty.pro8
-rw-r--r--tests/benchmarks/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp113
-rw-r--r--tests/benchmarks/declarative/qmltime/example.qml14
-rw-r--r--tests/benchmarks/declarative/qmltime/qmltime.cpp219
-rw-r--r--tests/benchmarks/declarative/qmltime/qmltime.pro8
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/anchors/empty.qml34
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/anchors/fill.qml41
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/anchors/null.qml27
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml34
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml34
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/item_creation/no_creation.qml12
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml34
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml37
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml34
-rw-r--r--tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml37
-rw-r--r--tests/benchmarks/declarative/script/data/CustomObject.qml7
-rw-r--r--tests/benchmarks/declarative/script/data/block.qml34
-rw-r--r--tests/benchmarks/declarative/script/data/signal_args.qml6
-rw-r--r--tests/benchmarks/declarative/script/data/signal_qml.qml6
-rw-r--r--tests/benchmarks/declarative/script/data/signal_unconnected.qml4
-rw-r--r--tests/benchmarks/declarative/script/data/signal_unusedArgs.qml6
-rw-r--r--tests/benchmarks/declarative/script/data/slot_complex.qml16
-rw-r--r--tests/benchmarks/declarative/script/data/slot_complex_js.qml18
-rw-r--r--tests/benchmarks/declarative/script/data/slot_simple.qml9
-rw-r--r--tests/benchmarks/declarative/script/data/slot_simple_js.qml13
-rw-r--r--tests/benchmarks/declarative/script/script.pro11
-rw-r--r--tests/benchmarks/declarative/script/tst_script.cpp618
67 files changed, 3056 insertions, 0 deletions
diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro
index c406d54..e318d02 100644
--- a/tests/benchmarks/benchmarks.pro
+++ b/tests/benchmarks/benchmarks.pro
@@ -5,4 +5,6 @@ SUBDIRS = \
network \
script \
svg
+
contains(QT_CONFIG, opengl): SUBDIRS += opengl
+contains(QT_CONFIG, declarative): SUBDIRS += declarative
diff --git a/tests/benchmarks/declarative/binding/binding.pro b/tests/benchmarks/declarative/binding/binding.pro
new file mode 100644
index 0000000..e25f186
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/binding.pro
@@ -0,0 +1,9 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_binding
+QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_binding.cpp testtypes.cpp
+HEADERS += testtypes.h
+
diff --git a/tests/benchmarks/declarative/binding/data/idproperty.txt b/tests/benchmarks/declarative/binding/data/idproperty.txt
new file mode 100644
index 0000000..71e3c4e
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/data/idproperty.txt
@@ -0,0 +1,9 @@
+import Test 1.0
+
+MyQmlObject {
+ id: MyObject
+
+ MyQmlObject {
+ result: ###
+ }
+}
diff --git a/tests/benchmarks/declarative/binding/data/localproperty.txt b/tests/benchmarks/declarative/binding/data/localproperty.txt
new file mode 100644
index 0000000..c7ca0ef
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/data/localproperty.txt
@@ -0,0 +1,5 @@
+import Test 1.0
+
+MyQmlObject {
+ result: ###
+}
diff --git a/tests/benchmarks/declarative/binding/data/objectproperty.txt b/tests/benchmarks/declarative/binding/data/objectproperty.txt
new file mode 100644
index 0000000..63fa74d
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/data/objectproperty.txt
@@ -0,0 +1,7 @@
+import Test 1.0
+
+MyQmlObject {
+ id: MyObject
+
+ result: ###
+}
diff --git a/tests/benchmarks/declarative/binding/testtypes.cpp b/tests/benchmarks/declarative/binding/testtypes.cpp
new file mode 100644
index 0000000..892738c
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/testtypes.cpp
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "testtypes.h"
+
+QML_DEFINE_TYPE(Test, 1, 0, MyQmlObject, MyQmlObject);
diff --git a/tests/benchmarks/declarative/binding/testtypes.h b/tests/benchmarks/declarative/binding/testtypes.h
new file mode 100644
index 0000000..c0586b1
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/testtypes.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef TESTTYPES_H
+#define TESTTYPES_H
+
+#include <QtCore/qobject.h>
+#include <QtDeclarative/qml.h>
+
+class MyQmlObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int result READ result WRITE setResult);
+ Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged);
+ Q_PROPERTY(MyQmlObject *object READ object WRITE setObject NOTIFY objectChanged);
+ Q_PROPERTY(QmlList<QObject *> *data READ data);
+ Q_CLASSINFO("DefaultProperty", "data");
+public:
+ MyQmlObject() : m_result(0), m_value(0), m_object(0) {}
+
+ int result() const { return m_result; }
+ void setResult(int r) { m_result = r; }
+
+ int value() const { return m_value; }
+ void setValue(int v) { m_value = v; emit valueChanged(); }
+
+ QmlList<QObject *> *data() { return &m_data; }
+
+ MyQmlObject *object() const { return m_object; }
+ void setObject(MyQmlObject *o) { m_object = o; emit objectChanged(); }
+
+signals:
+ void valueChanged();
+ void objectChanged();
+
+private:
+ QmlConcreteList<QObject *> m_data;
+ int m_result;
+ int m_value;
+ MyQmlObject *m_object;
+};
+QML_DECLARE_TYPE(MyQmlObject);
+
+#endif // TESTTYPES_H
diff --git a/tests/benchmarks/declarative/binding/tst_binding.cpp b/tests/benchmarks/declarative/binding/tst_binding.cpp
new file mode 100644
index 0000000..7b4875f
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/tst_binding.cpp
@@ -0,0 +1,160 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QFile>
+#include <QDebug>
+#include "testtypes.h"
+
+//TESTED_FILES=
+
+class tst_binding : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_binding();
+ virtual ~tst_binding();
+
+public slots:
+ void init();
+ void cleanup();
+
+private slots:
+ void objectproperty_data();
+ void objectproperty();
+ void basicproperty_data();
+ void basicproperty();
+
+private:
+ QmlEngine engine;
+};
+
+tst_binding::tst_binding()
+{
+}
+
+tst_binding::~tst_binding()
+{
+}
+
+void tst_binding::init()
+{
+}
+
+void tst_binding::cleanup()
+{
+}
+
+#define COMPONENT(filename, binding) \
+ QmlComponent c(&engine); \
+ { \
+ QFile f(filename); \
+ QVERIFY(f.open(QIODevice::ReadOnly)); \
+ QByteArray data = f.readAll(); \
+ data.replace("###", binding.toUtf8()); \
+ c.setData(data, QUrl()); \
+ QVERIFY(c.isReady()); \
+ }
+
+void tst_binding::objectproperty_data()
+{
+ QTest::addColumn<QString>("file");
+ QTest::addColumn<QString>("binding");
+
+ QTest::newRow("object.value") << "data/objectproperty.txt" << "object.value";
+ QTest::newRow("object.value + 10") << "data/objectproperty.txt" << "object.value + 10";
+}
+
+void tst_binding::objectproperty()
+{
+ QFETCH(QString, file);
+ QFETCH(QString, binding);
+
+ COMPONENT(file, binding);
+
+ MyQmlObject object1;
+ MyQmlObject object2;
+
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(c.create());
+ QVERIFY(object != 0);
+ object->setObject(&object2);
+
+ QBENCHMARK {
+ object->setObject(&object1);
+ object->setObject(&object2);
+ }
+}
+
+void tst_binding::basicproperty_data()
+{
+ QTest::addColumn<QString>("file");
+ QTest::addColumn<QString>("binding");
+
+ QTest::newRow("value") << "data/localproperty.txt" << "value";
+ QTest::newRow("value + 10") << "data/localproperty.txt" << "value + 10";
+ QTest::newRow("value + value + 10") << "data/localproperty.txt" << "value + value + 10";
+
+ QTest::newRow("MyObject.value") << "data/idproperty.txt" << "MyObject.value";
+ QTest::newRow("MyObject.value + 10") << "data/idproperty.txt" << "MyObject.value + 10";
+ QTest::newRow("MyObject.value + MyObject.value + 10") << "data/idproperty.txt" << "MyObject.value + MyObject.value + 10";
+}
+
+void tst_binding::basicproperty()
+{
+ QFETCH(QString, file);
+ QFETCH(QString, binding);
+
+ COMPONENT(file, binding);
+
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(c.create());
+ QVERIFY(object != 0);
+ object->setValue(10);
+
+ QBENCHMARK {
+ object->setValue(1);
+ }
+}
+
+QTEST_MAIN(tst_binding)
+#include "tst_binding.moc"
diff --git a/tests/benchmarks/declarative/creation/creation.pro b/tests/benchmarks/declarative/creation/creation.pro
new file mode 100644
index 0000000..fcc2987
--- /dev/null
+++ b/tests/benchmarks/declarative/creation/creation.pro
@@ -0,0 +1,10 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_creation
+QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_creation.cpp
+
+DEFINES += SRCDIR=\\\"$$PWD\\\"
+
diff --git a/tests/benchmarks/declarative/creation/data/item.qml b/tests/benchmarks/declarative/creation/data/item.qml
new file mode 100644
index 0000000..74d2f27
--- /dev/null
+++ b/tests/benchmarks/declarative/creation/data/item.qml
@@ -0,0 +1,34 @@
+import Qt 4.6
+
+Item {
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+ Item {}
+}
diff --git a/tests/benchmarks/declarative/creation/data/qobject.qml b/tests/benchmarks/declarative/creation/data/qobject.qml
new file mode 100644
index 0000000..99d010f
--- /dev/null
+++ b/tests/benchmarks/declarative/creation/data/qobject.qml
@@ -0,0 +1,4 @@
+import Qt 4.6
+
+QtObject {
+}
diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp
new file mode 100644
index 0000000..ae50309
--- /dev/null
+++ b/tests/benchmarks/declarative/creation/tst_creation.cpp
@@ -0,0 +1,375 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QmlMetaType>
+#include <QDebug>
+#include <QGraphicsScene>
+#include <QGraphicsItem>
+#include <QmlGraphicsItem>
+#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 objects_qmltype_data();
+ void objects_qmltype();
+
+ void qgraphicsitem();
+ void qgraphicsobject();
+ void qgraphicsitem14();
+ void qgraphicsitem_tree14();
+
+ void itemtree_notree_cpp();
+ void itemtree_objtree_cpp();
+ void itemtree_cpp();
+ void itemtree_data_cpp();
+ void itemtree_qml();
+ void itemtree_scene_cpp();
+
+private:
+ QmlEngine engine;
+};
+
+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()
+{
+ QmlComponent component(&engine, TEST_FILE("qobject.qml"));
+ QObject *obj = component.create();
+ delete obj;
+
+ QBENCHMARK {
+ QObject *obj = component.create();
+ delete obj;
+ }
+}
+
+void tst_creation::qobject_qmltype()
+{
+ QmlType *t = QmlMetaType::qmlType("Qt/QtObject", 4, 6);
+
+ 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;
+ }
+}
+
+void tst_creation::objects_qmltype_data()
+{
+ QTest::addColumn<QByteArray>("type");
+
+ QList<QByteArray> types = QmlMetaType::qmlTypeNames();
+ foreach (QByteArray type, types)
+ QTest::newRow(type.constData()) << type;
+}
+
+void tst_creation::objects_qmltype()
+{
+ QFETCH(QByteArray, type);
+ QmlType *t = QmlMetaType::qmlType(type, 4, 6);
+
+ QBENCHMARK {
+ QObject *obj = t->create();
+ delete obj;
+ }
+}
+
+class QGraphicsItemDummy : public QGraphicsItem
+{
+public:
+ virtual QRectF boundingRect() const { return QRectF(); }
+ virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
+};
+
+class QGraphicsObjectDummy : public QGraphicsObject
+{
+public:
+ virtual QRectF boundingRect() const { return QRectF(); }
+ virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
+};
+
+void tst_creation::qgraphicsitem()
+{
+ QBENCHMARK {
+ QGraphicsItemDummy *i = new QGraphicsItemDummy();
+ delete i;
+ }
+}
+
+void tst_creation::qgraphicsobject()
+{
+ QBENCHMARK {
+ QGraphicsObjectDummy *i = new QGraphicsObjectDummy();
+ delete i;
+ }
+}
+
+void tst_creation::qgraphicsitem14()
+{
+ QBENCHMARK {
+ QGraphicsItemDummy *i1 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i2 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i3 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i4 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i5 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i6 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i7 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i8 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i9 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i10 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i11 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i12 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i13 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i14 = new QGraphicsItemDummy();
+
+ delete i1;
+ delete i2;
+ delete i3;
+ delete i4;
+ delete i5;
+ delete i6;
+ delete i7;
+ delete i8;
+ delete i9;
+ delete i10;
+ delete i11;
+ delete i12;
+ delete i13;
+ delete i14;
+ }
+}
+
+void tst_creation::qgraphicsitem_tree14()
+{
+ QBENCHMARK {
+ // i1
+ // +-------------------------+
+ // i2 i3
+ // +-----------+ +-----+-----+
+ // i4 i5 i6 i7
+ // +----+ +--+ +--+--+ +----+
+ // i8 i9 i10 i11 i12 i13 i14
+
+ QGraphicsItemDummy *i1 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i2 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i3 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i4 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i5 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i6 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i7 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i8 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i9 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i10 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i11 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i12 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i13 = new QGraphicsItemDummy();
+ QGraphicsItemDummy *i14 = new QGraphicsItemDummy();
+
+ i14->setParentItem(i7);
+ i13->setParentItem(i7);
+ i12->setParentItem(i6);
+ i11->setParentItem(i6);
+ i10->setParentItem(i5);
+ i9->setParentItem(i4);
+ i8->setParentItem(i4);
+
+ i7->setParentItem(i3);
+ i6->setParentItem(i3);
+ i5->setParentItem(i2);
+ i4->setParentItem(i2);
+
+ i3->setParentItem(i1);
+ i2->setParentItem(i1);
+
+ delete i1;
+ }
+}
+
+struct QmlGraphics_DerivedObject : public QObject
+{
+ void setParent_noEvent(QObject *parent) {
+ bool sce = d_ptr->sendChildEvents;
+ d_ptr->sendChildEvents = false;
+ setParent(parent);
+ d_ptr->sendChildEvents = sce;
+ }
+};
+
+inline void QmlGraphics_setParent_noEvent(QObject *object, QObject *parent)
+{
+ static_cast<QmlGraphics_DerivedObject *>(object)->setParent_noEvent(parent);
+}
+
+void tst_creation::itemtree_notree_cpp()
+{
+ QBENCHMARK {
+ QmlGraphicsItem *item = new QmlGraphicsItem;
+ for (int i = 0; i < 30; ++i) {
+ QmlGraphicsItem *child = new QmlGraphicsItem;
+ }
+ delete item;
+ }
+}
+
+void tst_creation::itemtree_objtree_cpp()
+{
+ QBENCHMARK {
+ QmlGraphicsItem *item = new QmlGraphicsItem;
+ for (int i = 0; i < 30; ++i) {
+ QmlGraphicsItem *child = new QmlGraphicsItem;
+ QmlGraphics_setParent_noEvent(child,item);
+ }
+ delete item;
+ }
+}
+
+void tst_creation::itemtree_cpp()
+{
+ QBENCHMARK {
+ QmlGraphicsItem *item = new QmlGraphicsItem;
+ for (int i = 0; i < 30; ++i) {
+ QmlGraphicsItem *child = new QmlGraphicsItem;
+ QmlGraphics_setParent_noEvent(child,item);
+ child->setParentItem(item);
+ }
+ delete item;
+ }
+}
+
+void tst_creation::itemtree_data_cpp()
+{
+ QBENCHMARK {
+ QmlGraphicsItem *item = new QmlGraphicsItem;
+ for (int i = 0; i < 30; ++i) {
+ QmlGraphicsItem *child = new QmlGraphicsItem;
+ QmlGraphics_setParent_noEvent(child,item);
+ item->data()->append(child);
+ }
+ delete item;
+ }
+}
+
+void tst_creation::itemtree_qml()
+{
+ QmlComponent component(&engine, TEST_FILE("item.qml"));
+ QObject *obj = component.create();
+ delete obj;
+
+ QBENCHMARK {
+ QObject *obj = component.create();
+ delete obj;
+ }
+}
+
+void tst_creation::itemtree_scene_cpp()
+{
+ QGraphicsScene scene;
+ QmlGraphicsItem *root = new QmlGraphicsItem;
+ scene.addItem(root);
+ QBENCHMARK {
+ QmlGraphicsItem *item = new QmlGraphicsItem;
+ for (int i = 0; i < 30; ++i) {
+ QmlGraphicsItem *child = new QmlGraphicsItem;
+ QmlGraphics_setParent_noEvent(child,item);
+ child->setParentItem(item);
+ }
+ item->setParentItem(root);
+ delete item;
+ }
+ delete root;
+}
+
+
+QTEST_MAIN(tst_creation)
+
+#include "tst_creation.moc"
diff --git a/tests/benchmarks/declarative/declarative.pro b/tests/benchmarks/declarative/declarative.pro
new file mode 100644
index 0000000..8433de5
--- /dev/null
+++ b/tests/benchmarks/declarative/declarative.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS += \
+ binding \
+ creation \
+ pointers \
+ qmlcomponent \
+ qmlgraphicsimage \
+ qmlmetaproperty \
+ script \
+# qmltime
diff --git a/tests/benchmarks/declarative/painting/paintbenchmark.cpp b/tests/benchmarks/declarative/painting/paintbenchmark.cpp
new file mode 100644
index 0000000..d6a873c
--- /dev/null
+++ b/tests/benchmarks/declarative/painting/paintbenchmark.cpp
@@ -0,0 +1,309 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QPixmap>
+#include <QImage>
+#include <QPainter>
+#include <QGLWidget>
+#include <QTextLayout>
+#include <QVBoxLayout>
+#include <QTime>
+#include <QDebug>
+
+#ifdef HAVE_STATICTEXT
+#include <private/qstatictext_p.h>
+#endif
+
+int iterations = 20;
+const int count = 600;
+const int lines = 12;
+const int spacing = 36;
+QSizeF size(1000, 800);
+const qreal lineWidth = 1000;
+QString strings[lines];
+
+void paint_QTextLayout(QPainter &p, bool useCache)
+{
+ static bool first = true;
+ static QTextLayout *textLayout[lines];
+ if (first) {
+ for (int i = 0; i < lines; ++i) {
+ textLayout[i] = new QTextLayout(strings[i]);
+ int leading = p.fontMetrics().leading();
+ qreal height = 0;
+ qreal widthUsed = 0;
+ textLayout[i]->setCacheEnabled(useCache);
+ textLayout[i]->beginLayout();
+ while (1) {
+ QTextLine line = textLayout[i]->createLine();
+ if (!line.isValid())
+ break;
+
+ line.setLineWidth(lineWidth);
+ height += leading;
+ line.setPosition(QPointF(0, height));
+ height += line.height();
+ widthUsed = qMax(widthUsed, line.naturalTextWidth());
+ }
+ textLayout[i]->endLayout();
+ }
+ first = false;
+ }
+ for (int i = 0; i < count; ++i) {
+ for (int j = 0; j < lines; ++j) {
+ textLayout[j]->draw(&p, QPoint(0, j*spacing));
+ }
+ }
+}
+
+void paint_QTextLayout_noCache(QPainter &p)
+{
+ paint_QTextLayout(p, false);
+}
+
+void paint_QTextLayout_cache(QPainter &p)
+{
+ paint_QTextLayout(p, true);
+}
+
+#ifdef HAVE_STATICTEXT
+void paint_QStaticText(QPainter &p, bool useOptimizations)
+{
+ static QStaticText *staticText[lines];
+ static bool first = true;
+ if (first) {
+ for (int i = 0; i < lines; ++i) {
+ staticText[i] = new QStaticText(strings[i]);
+ staticText[i]->setUseBackendOptimizations(useOptimizations);
+ }
+ first = false;
+ }
+ for (int i = 0; i < count; ++i) {
+ for (int j = 0; j < lines; ++j) {
+ p.drawStaticText(QPointF(0, 30 + j*spacing), *staticText[j]);
+ }
+ }
+}
+
+void paint_QStaticText_noOptimizations(QPainter &p)
+{
+ paint_QStaticText(p, false);
+}
+
+void paint_QStaticText_optimizations(QPainter &p)
+{
+ paint_QStaticText(p, true);
+}
+#endif
+
+void paint_QPixmapCachedText(QPainter &p)
+{
+ static bool first = true;
+ static QPixmap cacheText[lines];
+ if (first) {
+ for (int i = 0; i < lines; ++i) {
+ QRectF trueSize;
+ trueSize = p.boundingRect(QRectF(QPointF(0,0), size), 0, strings[i]);
+ cacheText[i] = QPixmap(trueSize.size().toSize());
+ cacheText[i].fill(Qt::transparent);
+ QPainter paint(&cacheText[i]);
+ paint.setPen(Qt::black);
+ paint.drawText(QRectF(QPointF(0,0), trueSize.size().toSize()), strings[i]);
+ }
+ first = false;
+ }
+ for (int i = 0; i < count; i++) {
+ for (int j = 0; j < lines; ++j) {
+ p.drawPixmap(0,j*spacing,cacheText[j]);
+ }
+ }
+}
+
+void paint_RoundedRect(QPainter &p)
+{
+ p.setRenderHint(QPainter::Antialiasing, true);
+ p.setPen(Qt::black);
+ p.setBrush(Qt::red);
+ for (int i = 0; i < count; i++) {
+ for (int j = 0; j < lines; ++j) {
+ QSize size((j+1)*50, spacing-1);
+ p.drawRoundedRect(QRectF(QPointF(0,j*spacing), size), 8, 8);
+ }
+ }
+}
+
+void paint_QPixmapCachedRoundedRect(QPainter &p)
+{
+ static bool first = true;
+ static QPixmap cacheRect[lines];
+ if (first) {
+ for (int i = 0; i < lines; ++i) {
+ QSize size((i+1)*50, spacing-1);
+ cacheRect[i] = QPixmap(size);
+ cacheRect[i].fill(Qt::transparent);
+ QPainter paint(&cacheRect[i]);
+ paint.setRenderHint(QPainter::Antialiasing);
+ paint.setPen(Qt::black);
+ paint.setBrush(Qt::red);
+ paint.drawRoundedRect(QRect(QPoint(0,0), size), 8, 8);
+ }
+ first = false;
+ }
+ for (int i = 0; i < count; i++) {
+ for (int j = 0; j < lines; ++j) {
+ p.drawPixmap(0,j*spacing,cacheRect[j]);
+ }
+ }
+}
+
+typedef void(*PaintFunc)(QPainter &);
+
+struct {
+ const char *name;
+ PaintFunc func;
+} funcs[] = {
+ { "QTextLayoutNoCache", &paint_QTextLayout_noCache },
+ { "QTextLayoutWithCache", &paint_QTextLayout_cache },
+#ifdef HAVE_STATICTEXT
+ { "QStaticTextNoBackendOptimizations", &paint_QStaticText_noOptimizations },
+ { "QStaticTextWithBackendOptimizations", &paint_QStaticText_optimizations },
+#endif
+ { "CachedText", &paint_QPixmapCachedText },
+ { "RoundedRect", &paint_RoundedRect },
+ { "CachedRoundedRect", &paint_QPixmapCachedRoundedRect },
+ { 0, 0 }
+};
+
+PaintFunc testFunc = 0;
+
+class MyGLWidget : public QGLWidget
+{
+public:
+ MyGLWidget(const QGLFormat &format) : QGLWidget(format), frames(0) {
+ const char chars[] = "abcd efgh ijkl mnop qrst uvwx yz!$. ABCD 1234";
+ int len = strlen(chars);
+ for (int i = 0; i < lines; ++i) {
+ for (int j = 0; j < 60; j++) {
+ strings[i] += QChar(chars[rand() % len]);
+ }
+ }
+ }
+
+ void paintEvent(QPaintEvent *) {
+ static int last = 0;
+ static bool firstRun = true;
+ if (firstRun == 0) {
+ timer.start();
+ firstRun = false;
+ } else {
+ int elapsed = timer.elapsed();
+ qDebug() << "frame elapsed:" << elapsed - last;
+ last = elapsed;
+ }
+ QPainter p(this);
+ p.fillRect(rect(), Qt::white);
+ p.setPen(Qt::black);
+ QTime drawTimer;
+ drawTimer.start();
+ testFunc(p);
+ qDebug() << "draw time" << drawTimer.elapsed();
+ if (iterations--)
+ update();
+ else
+ qApp->quit();
+ }
+
+ QTime timer;
+ int frames;
+};
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ bool sampleBuffers = false;
+
+ for (int i = 1; i < argc; ++i) {
+ QString arg = argv[i];
+ if (arg == "-test") {
+ arg = argv[++i];
+ int j = 0;
+ while (funcs[j].name) {
+ if (arg == funcs[j].name) {
+ testFunc = funcs[j].func;
+ qDebug() << "Running test" << arg;
+ break;
+ }
+ ++j;
+ }
+ } else if (arg == "-iterations") {
+ arg = argv[++i];
+ iterations = arg.toInt();
+ } else if (arg == "-sampleBuffers") {
+ sampleBuffers = true;
+ }
+ }
+
+ if (testFunc == 0) {
+ qDebug() << "Usage: textspeed -test <test> [-sampleBuffers] [-iterations n]";
+ qDebug() << "where <test> can be:";
+ int j = 0;
+ while (funcs[j].name) {
+ qDebug() << " " << funcs[j].name;
+ ++j;
+ }
+ exit(1);
+ }
+
+ QWidget w;
+ QGLFormat format = QGLFormat::defaultFormat();
+ format.setSampleBuffers(sampleBuffers);
+ MyGLWidget *glw = new MyGLWidget(format);
+ glw->setAutoFillBackground(false);
+ QVBoxLayout *layout = new QVBoxLayout(&w);
+ w.setLayout(layout);
+ layout->addWidget(glw);
+ w.showFullScreen();
+ app.exec();
+
+ return 0;
+}
diff --git a/tests/benchmarks/declarative/painting/paintbenchmark.pro b/tests/benchmarks/declarative/painting/paintbenchmark.pro
new file mode 100644
index 0000000..2f98e8b
--- /dev/null
+++ b/tests/benchmarks/declarative/painting/paintbenchmark.pro
@@ -0,0 +1,13 @@
+######################################################################
+# Automatically generated by qmake (2.01a) fr 29. jan 13:57:52 2010
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += paintbenchmark.cpp
+QT += opengl
+CONFIG += console
diff --git a/tests/benchmarks/declarative/pointers/pointers.pro b/tests/benchmarks/declarative/pointers/pointers.pro
new file mode 100644
index 0000000..5180a2a
--- /dev/null
+++ b/tests/benchmarks/declarative/pointers/pointers.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+QT += declarative
+TEMPLATE = app
+TARGET = tst_pointers
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_pointers.cpp
+
diff --git a/tests/benchmarks/declarative/pointers/tst_pointers.cpp b/tests/benchmarks/declarative/pointers/tst_pointers.cpp
new file mode 100644
index 0000000..55c2e89
--- /dev/null
+++ b/tests/benchmarks/declarative/pointers/tst_pointers.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include "private/qmlguard_p.h"
+#include <QWeakPointer>
+
+class tst_pointers : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_pointers() {}
+
+private slots:
+ void qmlguard();
+ void weakPointer();
+};
+
+void tst_pointers::qmlguard()
+{
+ QObject *obj = new QObject;
+ QBENCHMARK {
+ QmlGuard<QObject> guardedObject;
+ guardedObject = obj;
+ }
+}
+
+void tst_pointers::weakPointer()
+{
+ QObject *obj = new QObject;
+ QBENCHMARK {
+ QWeakPointer<QObject> guardedObject;
+ guardedObject = obj;
+ }
+}
+
+QTEST_MAIN(tst_pointers)
+#include "tst_pointers.moc"
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/myqmlobject.qml b/tests/benchmarks/declarative/qmlcomponent/data/myqmlobject.qml
new file mode 100644
index 0000000..9c3f7f8
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/myqmlobject.qml
@@ -0,0 +1,3 @@
+import Qt.test 4.6
+
+MyQmlObject {}
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/myqmlobject_binding.qml b/tests/benchmarks/declarative/qmlcomponent/data/myqmlobject_binding.qml
new file mode 100644
index 0000000..e6cc4cf
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/myqmlobject_binding.qml
@@ -0,0 +1,6 @@
+import Qt.test 4.6
+
+MyQmlObject {
+ result: value
+}
+
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/object.qml b/tests/benchmarks/declarative/qmlcomponent/data/object.qml
new file mode 100644
index 0000000..0d2d49b
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/object.qml
@@ -0,0 +1,3 @@
+import Qt 4.6
+
+QtObject {}
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/object_id.qml b/tests/benchmarks/declarative/qmlcomponent/data/object_id.qml
new file mode 100644
index 0000000..69114af
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/object_id.qml
@@ -0,0 +1,6 @@
+import Qt 4.6
+
+QtObject {
+ id: Blah
+}
+
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/samegame/BoomBlock.qml b/tests/benchmarks/declarative/qmlcomponent/data/samegame/BoomBlock.qml
new file mode 100644
index 0000000..723e62a
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/samegame/BoomBlock.qml
@@ -0,0 +1,55 @@
+import Qt 4.6
+
+Item { id:block
+ property bool dying: false
+ property bool spawned: false
+ property int type: 0
+ property int targetX: 0
+ property int targetY: 0
+
+ x: SpringFollow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 }
+ y: SpringFollow { source: targetY; spring: 2; damping: 0.2 }
+
+ Image { id: img
+ source: {
+ if(type == 0){
+ "pics/redStone.png";
+ } else if(type == 1) {
+ "pics/blueStone.png";
+ } else {
+ "pics/greenStone.png";
+ }
+ }
+ opacity: 0
+ opacity: Behavior { NumberAnimation { duration: 200 } }
+ anchors.fill: parent
+ }
+
+ Particles { id: particles
+ width:1; height:1; anchors.centerIn: parent;
+ emissionRate: 0;
+ lifeSpan: 700; lifeSpanDeviation: 600;
+ angle: 0; angleDeviation: 360;
+ velocity: 100; velocityDeviation:30;
+ source: {
+ if(type == 0){
+ "pics/redStar.png";
+ } else if (type == 1) {
+ "pics/blueStar.png";
+ } else {
+ "pics/greenStar.png";
+ }
+ }
+ }
+
+ states: [
+ State{ name: "AliveState"; when: spawned == true && dying == false
+ PropertyChanges { target: img; opacity: 1 }
+ },
+ State{ name: "DeathState"; when: dying == true
+ StateChangeScript { script: particles.burst(50); }
+ PropertyChanges { target: img; opacity: 0 }
+ StateChangeScript { script: block.destroy(1000); }
+ }
+ ]
+}
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/blueStar.png b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/blueStar.png
new file mode 100644
index 0000000..ff9588f
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/blueStar.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/blueStone.png b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/blueStone.png
new file mode 100644
index 0000000..bf342e0
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/blueStone.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/greenStar.png b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/greenStar.png
new file mode 100644
index 0000000..cd06854
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/greenStar.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/greenStone.png b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/greenStone.png
new file mode 100644
index 0000000..5ac14a5
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/greenStone.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/redStar.png b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/redStar.png
new file mode 100644
index 0000000..0a4dffe
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/redStar.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/redStone.png b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/redStone.png
new file mode 100644
index 0000000..b099f60
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/redStone.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/yellowStone.png b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/yellowStone.png
new file mode 100644
index 0000000..c56124a
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/samegame/pics/yellowStone.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/synthesized_properties.2.qml b/tests/benchmarks/declarative/qmlcomponent/data/synthesized_properties.2.qml
new file mode 100644
index 0000000..27c5646
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/synthesized_properties.2.qml
@@ -0,0 +1,15 @@
+import Qt 4.6
+
+QtObject {
+ property int a
+ property bool b
+ property double c
+ property real d
+ property string e
+ property url f
+ property color g
+ property date h
+ property var i
+ property variant j
+}
+
diff --git a/tests/benchmarks/declarative/qmlcomponent/data/synthesized_properties.qml b/tests/benchmarks/declarative/qmlcomponent/data/synthesized_properties.qml
new file mode 100644
index 0000000..d08f35b
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/data/synthesized_properties.qml
@@ -0,0 +1,5 @@
+import Qt 4.6
+
+QtObject {
+ property int a
+}
diff --git a/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro b/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro
new file mode 100644
index 0000000..6a86f58
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/qmlcomponent.pro
@@ -0,0 +1,9 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qmlcomponent
+QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qmlcomponent.cpp testtypes.cpp
+HEADERS += testtypes.h
+
diff --git a/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp b/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp
new file mode 100644
index 0000000..56d20c6
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "testtypes.h"
+
+QML_DEFINE_TYPE(Qt.test, 4, 6, MyQmlObject, MyQmlObject);
diff --git a/tests/benchmarks/declarative/qmlcomponent/testtypes.h b/tests/benchmarks/declarative/qmlcomponent/testtypes.h
new file mode 100644
index 0000000..c0586b1
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/testtypes.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef TESTTYPES_H
+#define TESTTYPES_H
+
+#include <QtCore/qobject.h>
+#include <QtDeclarative/qml.h>
+
+class MyQmlObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int result READ result WRITE setResult);
+ Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged);
+ Q_PROPERTY(MyQmlObject *object READ object WRITE setObject NOTIFY objectChanged);
+ Q_PROPERTY(QmlList<QObject *> *data READ data);
+ Q_CLASSINFO("DefaultProperty", "data");
+public:
+ MyQmlObject() : m_result(0), m_value(0), m_object(0) {}
+
+ int result() const { return m_result; }
+ void setResult(int r) { m_result = r; }
+
+ int value() const { return m_value; }
+ void setValue(int v) { m_value = v; emit valueChanged(); }
+
+ QmlList<QObject *> *data() { return &m_data; }
+
+ MyQmlObject *object() const { return m_object; }
+ void setObject(MyQmlObject *o) { m_object = o; emit objectChanged(); }
+
+signals:
+ void valueChanged();
+ void objectChanged();
+
+private:
+ QmlConcreteList<QObject *> m_data;
+ int m_result;
+ int m_value;
+ MyQmlObject *m_object;
+};
+QML_DECLARE_TYPE(MyQmlObject);
+
+#endif // TESTTYPES_H
diff --git a/tests/benchmarks/declarative/qmlcomponent/tst_qmlcomponent.cpp b/tests/benchmarks/declarative/qmlcomponent/tst_qmlcomponent.cpp
new file mode 100644
index 0000000..f5a4540
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlcomponent/tst_qmlcomponent.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.qml in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QFile>
+#include <QDebug>
+#include "testtypes.h"
+
+//TESTED_FILES=
+
+
+class tst_qmlcomponent : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_qmlcomponent();
+ virtual ~tst_qmlcomponent();
+
+public slots:
+ void init();
+ void cleanup();
+
+private slots:
+ void creation_data();
+ void creation();
+
+private:
+ QmlEngine engine;
+};
+
+tst_qmlcomponent::tst_qmlcomponent()
+{
+}
+
+tst_qmlcomponent::~tst_qmlcomponent()
+{
+}
+
+void tst_qmlcomponent::init()
+{
+}
+
+void tst_qmlcomponent::cleanup()
+{
+}
+
+void tst_qmlcomponent::creation_data()
+{
+ QTest::addColumn<QString>("file");
+
+ QTest::newRow("Object") << "data/object.qml";
+ QTest::newRow("Object - Id") << "data/object_id.qml";
+ QTest::newRow("MyQmlObject") << "data/myqmlobject.qml";
+ QTest::newRow("MyQmlObject: basic binding") << "data/myqmlobject_binding.qml";
+ QTest::newRow("Synthesized properties") << "data/synthesized_properties.qml";
+ QTest::newRow("Synthesized properties.2") << "data/synthesized_properties.2.qml";
+ QTest::newRow("SameGame - BoomBlock") << "data/samegame/BoomBlock.qml";
+}
+
+void tst_qmlcomponent::creation()
+{
+ QFETCH(QString, file);
+
+ QmlComponent c(&engine, file);
+ QVERIFY(c.isReady());
+
+ QObject *obj = c.create();
+ delete obj;
+
+ QBENCHMARK {
+ QObject *obj = c.create();
+ delete obj;
+ }
+}
+
+QTEST_MAIN(tst_qmlcomponent)
+#include "tst_qmlcomponent.moc"
diff --git a/tests/benchmarks/declarative/qmlgraphicsimage/image.png b/tests/benchmarks/declarative/qmlgraphicsimage/image.png
new file mode 100644
index 0000000..623d362
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlgraphicsimage/image.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro b/tests/benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro
new file mode 100644
index 0000000..449d874
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlgraphicsimage/qmlgraphicsimage.pro
@@ -0,0 +1,11 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qmlgraphicsimage
+QT += declarative
+macx:CONFIG -= app_bundle
+CONFIG += release
+
+SOURCES += tst_qmlgraphicsimage.cpp
+
+DEFINES += SRCDIR=\\\"$$PWD\\\"
+
diff --git a/tests/benchmarks/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp b/tests/benchmarks/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp
new file mode 100644
index 0000000..f6a6432
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <private/qmlgraphicsimage_p.h>
+
+class tst_qmlgraphicsimage : public QObject
+{
+ Q_OBJECT
+public:
+ tst_qmlgraphicsimage() {}
+
+private slots:
+ void qmlgraphicsimage();
+ void qmlgraphicsimage_file();
+ void qmlgraphicsimage_url();
+
+private:
+ QmlEngine engine;
+};
+
+void tst_qmlgraphicsimage::qmlgraphicsimage()
+{
+ int x = 0;
+ QUrl url("image.png");
+ QBENCHMARK {
+ QUrl url2("http://localhost/image" + QString::number(x++) + ".png");
+ QmlGraphicsImage *image = new QmlGraphicsImage;
+ QmlEngine::setContextForObject(image, engine.rootContext());
+ delete image;
+ }
+}
+
+void tst_qmlgraphicsimage::qmlgraphicsimage_file()
+{
+ int x = 0;
+ QUrl url("image.png");
+ QBENCHMARK {
+ QUrl url2("http://localhost/image" + QString::number(x++) + ".png");
+ QmlGraphicsImage *image = new QmlGraphicsImage;
+ QmlEngine::setContextForObject(image, engine.rootContext());
+ image->setSource(url);
+ delete image;
+ }
+}
+
+void tst_qmlgraphicsimage::qmlgraphicsimage_url()
+{
+ int x = 0;
+ QUrl url("image.png");
+ QBENCHMARK {
+ QUrl url2("http://localhost/image" + QString::number(x++) + ".png");
+ QmlGraphicsImage *image = new QmlGraphicsImage;
+ QmlEngine::setContextForObject(image, engine.rootContext());
+ image->setSource(url2);
+ delete image;
+ }
+}
+
+QTEST_MAIN(tst_qmlgraphicsimage)
+
+#include "tst_qmlgraphicsimage.moc"
diff --git a/tests/benchmarks/declarative/qmlmetaproperty/data/object.qml b/tests/benchmarks/declarative/qmlmetaproperty/data/object.qml
new file mode 100644
index 0000000..11b95e1
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlmetaproperty/data/object.qml
@@ -0,0 +1,3 @@
+import Qt 4.6
+
+Item {}
diff --git a/tests/benchmarks/declarative/qmlmetaproperty/data/synthesized_object.qml b/tests/benchmarks/declarative/qmlmetaproperty/data/synthesized_object.qml
new file mode 100644
index 0000000..a923a0a
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlmetaproperty/data/synthesized_object.qml
@@ -0,0 +1,6 @@
+import Qt 4.6
+
+Item {
+ property int blah
+}
+
diff --git a/tests/benchmarks/declarative/qmlmetaproperty/qmlmetaproperty.pro b/tests/benchmarks/declarative/qmlmetaproperty/qmlmetaproperty.pro
new file mode 100644
index 0000000..c18a56b
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlmetaproperty/qmlmetaproperty.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qmlmetaproperty
+QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qmlmetaproperty.cpp
+
diff --git a/tests/benchmarks/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/benchmarks/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp
new file mode 100644
index 0000000..8d0e549
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QmlMetaProperty>
+#include <QFile>
+#include <QDebug>
+
+//TESTED_FILES=
+
+
+class tst_qmlmetaproperty : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_qmlmetaproperty();
+ virtual ~tst_qmlmetaproperty();
+
+public slots:
+ void init();
+ void cleanup();
+
+private slots:
+ void lookup_data();
+ void lookup();
+
+private:
+ QmlEngine engine;
+};
+
+tst_qmlmetaproperty::tst_qmlmetaproperty()
+{
+}
+
+tst_qmlmetaproperty::~tst_qmlmetaproperty()
+{
+}
+
+void tst_qmlmetaproperty::init()
+{
+}
+
+void tst_qmlmetaproperty::cleanup()
+{
+}
+
+void tst_qmlmetaproperty::lookup_data()
+{
+ QTest::addColumn<QString>("file");
+
+ QTest::newRow("Simple Object") << "data/object.qml";
+ QTest::newRow("Synthesized Object") << "data/synthesized_object.qml";
+}
+
+void tst_qmlmetaproperty::lookup()
+{
+ QFETCH(QString, file);
+
+ QmlComponent c(&engine, file);
+ QVERIFY(c.isReady());
+
+ QObject *obj = c.create();
+
+ QBENCHMARK {
+ QmlMetaProperty p(obj, "x");
+ }
+
+ delete obj;
+}
+
+QTEST_MAIN(tst_qmlmetaproperty)
+#include "tst_qmlmetaproperty.moc"
diff --git a/tests/benchmarks/declarative/qmltime/example.qml b/tests/benchmarks/declarative/qmltime/example.qml
new file mode 100644
index 0000000..68889f0
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/example.qml
@@ -0,0 +1,14 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+
+ property string name: "Bob Smith"
+
+ QmlTime.Timer {
+ component: Item {
+ Text { text: name }
+ }
+ }
+}
+
diff --git a/tests/benchmarks/declarative/qmltime/qmltime.cpp b/tests/benchmarks/declarative/qmltime/qmltime.cpp
new file mode 100644
index 0000000..2cc5d0d
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/qmltime.cpp
@@ -0,0 +1,219 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include <QApplication>
+#include <QTime>
+#include <QmlContext>
+#include <QGraphicsScene>
+#include <QGraphicsRectItem>
+
+class Timer : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QmlComponent *component READ component WRITE setComponent);
+
+public:
+ Timer();
+
+ QmlComponent *component() const;
+ void setComponent(QmlComponent *);
+
+ static Timer *timerInstance();
+
+ void run(uint);
+
+ bool willParent() const;
+ void setWillParent(bool p);
+
+private:
+ void runTest(QmlContext *, uint);
+
+ QmlComponent *m_component;
+ static Timer *m_timer;
+
+ bool m_willparent;
+ QGraphicsScene m_scene;
+ QGraphicsRectItem m_item;
+};
+QML_DECLARE_TYPE(Timer);
+QML_DEFINE_TYPE(QmlTime, 1, 0, Timer, Timer);
+
+Timer *Timer::m_timer = 0;
+
+Timer::Timer()
+: m_component(0), m_willparent(false)
+{
+ if (m_timer)
+ qWarning("Timer: Timer already registered");
+ m_timer = this;
+
+ m_scene.setItemIndexMethod(QGraphicsScene::NoIndex);
+ m_scene.addItem(&m_item);
+}
+
+QmlComponent *Timer::component() const
+{
+ return m_component;
+}
+
+void Timer::setComponent(QmlComponent *c)
+{
+ m_component = c;
+}
+
+Timer *Timer::timerInstance()
+{
+ return m_timer;
+}
+
+void Timer::run(uint iterations)
+{
+ QmlContext context(qmlContext(this));
+
+ QObject *o = m_component->create(&context);
+ QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o);
+ if (m_willparent && go)
+ go->setParentItem(&m_item);
+ delete o;
+
+ runTest(&context, iterations);
+}
+
+bool Timer::willParent() const
+{
+ return m_willparent;
+}
+
+void Timer::setWillParent(bool p)
+{
+ m_willparent = p;
+}
+
+void Timer::runTest(QmlContext *context, uint iterations)
+{
+ QTime t;
+ t.start();
+ for (uint ii = 0; ii < iterations; ++ii) {
+ QObject *o = m_component->create(context);
+ QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o);
+ if (m_willparent && go)
+ go->setParentItem(&m_item);
+ delete o;
+ }
+
+ int e = t.elapsed();
+
+ qWarning() << "Total:" << e << "ms, Per iteration:" << qreal(e) / qreal(iterations) << "ms";
+
+}
+
+void usage(const char *name)
+{
+ qWarning("Usage: %s [-iterations <count>] [-parent] <qml file>", name);
+ exit(-1);
+}
+
+int main(int argc, char ** argv)
+{
+ QApplication app(argc, argv);
+
+ uint iterations = 1024;
+ QString filename;
+ bool willParent = false;
+
+ for (int ii = 1; ii < argc; ++ii) {
+ QByteArray arg(argv[ii]);
+
+ if (arg == "-iterations") {
+ if (ii + 1 < argc) {
+ ++ii;
+ QByteArray its(argv[ii]);
+ bool ok = false;
+ iterations = its.toUInt(&ok);
+ if (!ok)
+ usage(argv[0]);
+ } else {
+ usage(argv[0]);
+ }
+ } else if (arg == "-parent") {
+ willParent = true;
+ } else {
+ filename = QLatin1String(argv[ii]);
+ }
+ }
+
+ if (filename.isEmpty())
+ usage(argv[0]);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, filename);
+ if (component.isError()) {
+ qWarning() << component.errors();
+ return -1;
+ }
+
+ QObject *obj = component.create();
+ if (!obj) {
+ qWarning() << component.errors();
+ return -1;
+ }
+
+ Timer *timer = Timer::timerInstance();
+ if (!timer) {
+ qWarning() << "A Tester.Timer instance is required.";
+ return -1;
+ }
+
+ timer->setWillParent(willParent);
+
+ if (!timer->component()) {
+ qWarning() << "The timer has no component";
+ return -1;
+ }
+
+ timer->run(iterations);
+
+ return 0;
+}
+
+#include "qmltime.moc"
diff --git a/tests/benchmarks/declarative/qmltime/qmltime.pro b/tests/benchmarks/declarative/qmltime/qmltime.pro
new file mode 100644
index 0000000..b077d1a
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/qmltime.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = qmltime
+QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += qmltime.cpp
+
diff --git a/tests/benchmarks/declarative/qmltime/tests/anchors/empty.qml b/tests/benchmarks/declarative/qmltime/tests/anchors/empty.qml
new file mode 100644
index 0000000..31c879b
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/anchors/empty.qml
@@ -0,0 +1,34 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ Item {
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.leftMargin: 0
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/benchmarks/declarative/qmltime/tests/anchors/fill.qml b/tests/benchmarks/declarative/qmltime/tests/anchors/fill.qml
new file mode 100644
index 0000000..23fe78e
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/anchors/fill.qml
@@ -0,0 +1,41 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ Item {
+ anchors.fill: parent
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.fill: parent
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.fill: parent
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.fill: parent
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.fill: parent
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.fill: parent
+ anchors.leftMargin: 0
+ }
+ Item {
+ anchors.fill: parent
+ anchors.leftMargin: 0
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/benchmarks/declarative/qmltime/tests/anchors/null.qml b/tests/benchmarks/declarative/qmltime/tests/anchors/null.qml
new file mode 100644
index 0000000..bc447ef
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/anchors/null.qml
@@ -0,0 +1,27 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ Item {
+ }
+ Item {
+ }
+ Item {
+ }
+ Item {
+ }
+ Item {
+ }
+ Item {
+ }
+ Item {
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml
new file mode 100644
index 0000000..210c515
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/children.qml
@@ -0,0 +1,34 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ children: [
+ Rectangle { },
+ Rectangle { },
+ Item { },
+ Image { },
+ Text { },
+ Item { },
+ Item { },
+ Image { },
+ Image { },
+ Row { },
+ Image { },
+ Image { },
+ Column { },
+ Row { },
+ Text { },
+ Text { },
+ Text { },
+ MouseRegion { }
+ ]
+
+ }
+ }
+ }
+
+}
diff --git a/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml
new file mode 100644
index 0000000..943634f
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/data.qml
@@ -0,0 +1,34 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ data: [
+ Rectangle { },
+ Rectangle { },
+ Item { },
+ Image { },
+ Text { },
+ Item { },
+ Item { },
+ Image { },
+ Image { },
+ Row { },
+ Image { },
+ Image { },
+ Column { },
+ Row { },
+ Text { },
+ Text { },
+ Text { },
+ MouseRegion { }
+ ]
+
+ }
+ }
+ }
+
+}
diff --git a/tests/benchmarks/declarative/qmltime/tests/item_creation/no_creation.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/no_creation.qml
new file mode 100644
index 0000000..f228c2a
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/no_creation.qml
@@ -0,0 +1,12 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ }
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml b/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml
new file mode 100644
index 0000000..ce986b5
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/item_creation/resources.qml
@@ -0,0 +1,34 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ resources: [
+ Rectangle { },
+ Rectangle { },
+ Item { },
+ Image { },
+ Text { },
+ Item { },
+ Item { },
+ Image { },
+ Image { },
+ Row { },
+ Image { },
+ Image { },
+ Column { },
+ Row { },
+ Text { },
+ Text { },
+ Text { },
+ MouseRegion { }
+ ]
+
+ }
+ }
+ }
+
+}
diff --git a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml
new file mode 100644
index 0000000..25e9c62
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/no_positioner.qml
@@ -0,0 +1,37 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ Rectangle { }
+ Rectangle { }
+ Item {
+ Image { }
+ Text { }
+ }
+
+ Item {
+ Item {
+ Image { }
+ Image { }
+ Item {
+ Image { }
+ Image { }
+ }
+ }
+
+ Item {
+ Item {
+ Text { }
+ Text { }
+ }
+ Text { }
+ }
+ }
+ MouseRegion { }
+ }
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml
new file mode 100644
index 0000000..ee3f9d1
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/null_positioner.qml
@@ -0,0 +1,34 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ Rectangle { }
+ Rectangle { }
+ Item {
+ Image { }
+ Text { }
+ }
+
+ Item {
+ Item {
+ Image { }
+ Image { }
+ Row { }
+ Image { }
+ Image { }
+ }
+
+ Column { }
+ Row { }
+ Text { }
+ Text { }
+ Text { }
+ }
+ MouseRegion { }
+ }
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml
new file mode 100644
index 0000000..4c46ec1
--- /dev/null
+++ b/tests/benchmarks/declarative/qmltime/tests/positioner_creation/positioner.qml
@@ -0,0 +1,37 @@
+import Qt 4.6
+import QmlTime 1.0 as QmlTime
+
+Item {
+ QmlTime.Timer {
+ component: Component {
+ Item {
+ Rectangle { }
+ Rectangle { }
+ Item {
+ Image { }
+ Text { }
+ }
+
+ Item {
+ Item {
+ Image { }
+ Image { }
+ Row {
+ Image { }
+ Image { }
+ }
+ }
+
+ Column {
+ Row {
+ Text { }
+ Text { }
+ }
+ Text { }
+ }
+ }
+ MouseRegion { }
+ }
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/script/data/CustomObject.qml b/tests/benchmarks/declarative/script/data/CustomObject.qml
new file mode 100644
index 0000000..22b7be7
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/CustomObject.qml
@@ -0,0 +1,7 @@
+import Qt 4.6
+
+QtObject {
+ property real prop1: 0
+ property real prop2: 1
+ property real prop3: 0
+}
diff --git a/tests/benchmarks/declarative/script/data/block.qml b/tests/benchmarks/declarative/script/data/block.qml
new file mode 100644
index 0000000..bb03d8d
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/block.qml
@@ -0,0 +1,34 @@
+import Qt 4.6
+
+Rectangle {
+ width: 200; height: 200
+ CustomObject { id: theObject }
+ function doSomethingDirect() {
+ theObject.prop1 = 0;
+
+ for (var i = 0; i < 60; ++i)
+ theObject.prop1 += theObject.prop2;
+
+ theObject.prop3 = theObject.prop1;
+ }
+
+ function doSomethingLocalObj() {
+ theObject.prop1 = 0;
+
+ var incrementObj = theObject;
+ for (var i = 0; i < 60; ++i)
+ incrementObj.prop1 += incrementObj.prop2;
+
+ incrementObj.prop3 = incrementObj.prop1;
+ }
+
+ function doSomethingLocal() {
+ theObject.prop1 = 0;
+
+ var increment = theObject.prop2;
+ for (var i = 0; i < 60; ++i)
+ theObject.prop1 += increment;
+
+ theObject.prop3 = theObject.prop1;
+ }
+}
diff --git a/tests/benchmarks/declarative/script/data/signal_args.qml b/tests/benchmarks/declarative/script/data/signal_args.qml
new file mode 100644
index 0000000..f02acc0
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/signal_args.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+TestObject {
+ onMySignalWithArgs: { var a = n; return a; }
+}
+
diff --git a/tests/benchmarks/declarative/script/data/signal_qml.qml b/tests/benchmarks/declarative/script/data/signal_qml.qml
new file mode 100644
index 0000000..ba53603
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/signal_qml.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+TestObject {
+ onMySignal: { var a = 1; return a; }
+}
+
diff --git a/tests/benchmarks/declarative/script/data/signal_unconnected.qml b/tests/benchmarks/declarative/script/data/signal_unconnected.qml
new file mode 100644
index 0000000..53d06d5
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/signal_unconnected.qml
@@ -0,0 +1,4 @@
+import Qt.test 1.0
+
+TestObject {
+}
diff --git a/tests/benchmarks/declarative/script/data/signal_unusedArgs.qml b/tests/benchmarks/declarative/script/data/signal_unusedArgs.qml
new file mode 100644
index 0000000..3ff9071
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/signal_unusedArgs.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+TestObject {
+ onMySignalWithArgs: { var a = 1; return a; }
+}
+
diff --git a/tests/benchmarks/declarative/script/data/slot_complex.qml b/tests/benchmarks/declarative/script/data/slot_complex.qml
new file mode 100644
index 0000000..d71120d
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/slot_complex.qml
@@ -0,0 +1,16 @@
+import Qt.test 1.0
+
+TestObject {
+ function myCustomFunction(b) {
+ var n = b;
+ var a = 1;
+ while (n > 0) {
+ a = a * n;
+ n--;
+ }
+ return a;
+ }
+
+ onMySignal: { for (var ii = 0; ii < 10000; ++ii) { myCustomFunction(10); } }
+}
+
diff --git a/tests/benchmarks/declarative/script/data/slot_complex_js.qml b/tests/benchmarks/declarative/script/data/slot_complex_js.qml
new file mode 100644
index 0000000..ed4f78b
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/slot_complex_js.qml
@@ -0,0 +1,18 @@
+import Qt.test 1.0
+
+TestObject {
+ Script {
+ function myCustomFunction(n) {
+ var a = 1;
+ while (n > 0) {
+ a = a * n;
+ n--;
+ }
+ return a;
+ }
+ }
+
+ onMySignal: { for (var ii = 0; ii < 10000; ++ii) { myCustomFunction(10); } }
+}
+
+
diff --git a/tests/benchmarks/declarative/script/data/slot_simple.qml b/tests/benchmarks/declarative/script/data/slot_simple.qml
new file mode 100644
index 0000000..4ba98d7
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/slot_simple.qml
@@ -0,0 +1,9 @@
+import Qt.test 1.0
+
+TestObject {
+ function myCustomFunction() {
+ return 0;
+ }
+
+ onMySignal: { for (var ii = 0; ii < 10000; ++ii) { myCustomFunction(); } }
+}
diff --git a/tests/benchmarks/declarative/script/data/slot_simple_js.qml b/tests/benchmarks/declarative/script/data/slot_simple_js.qml
new file mode 100644
index 0000000..a88265c
--- /dev/null
+++ b/tests/benchmarks/declarative/script/data/slot_simple_js.qml
@@ -0,0 +1,13 @@
+import Qt.test 1.0
+
+TestObject {
+
+ Script {
+ function myCustomFunction() {
+ return 0;
+ }
+ }
+
+ onMySignal: { for (var ii = 0; ii < 10000; ++ii) { myCustomFunction(); } }
+}
+
diff --git a/tests/benchmarks/declarative/script/script.pro b/tests/benchmarks/declarative/script/script.pro
new file mode 100644
index 0000000..48fea81
--- /dev/null
+++ b/tests/benchmarks/declarative/script/script.pro
@@ -0,0 +1,11 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_script
+QT += declarative script
+macx:CONFIG -= app_bundle
+CONFIG += release
+
+SOURCES += tst_script.cpp
+
+DEFINES += SRCDIR=\\\"$$PWD\\\"
+
diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp
new file mode 100644
index 0000000..36a0833
--- /dev/null
+++ b/tests/benchmarks/declarative/script/tst_script.cpp
@@ -0,0 +1,618 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <private/qmlengine_p.h>
+#include <private/qmlobjectscriptclass_p.h>
+#include <private/qmlgraphicsrectangle_p.h>
+#include <QScriptEngine>
+#include <QScriptValue>
+
+class tst_script : public QObject
+{
+ Q_OBJECT
+public:
+ tst_script() {}
+
+private slots:
+ void property_js();
+ void property_getter();
+ void property_getter_js();
+ void property_getter_qobject();
+ void property_getter_qmetaproperty();
+ void property_qobject();
+ void property_qmlobject();
+
+ void function_js();
+ void function_cpp();
+ void function_qobject();
+ void function_qmlobject();
+
+ void function_args_js();
+ void function_args_cpp();
+ void function_args_qobject();
+ void function_args_qmlobject();
+
+ void signal_unconnected();
+ void signal_qml();
+ void signal_args();
+ void signal_unusedArgs();
+
+ void slot_simple();
+ void slot_simple_js();
+ void slot_complex();
+ void slot_complex_js();
+
+ void block_data();
+ void block();
+private:
+};
+
+inline QUrl TEST_FILE(const QString &filename)
+{
+ return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
+}
+
+class TestObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int x READ x)
+
+public:
+ TestObject(QObject *parent = 0);
+
+ int x();
+
+ void emitMySignal() { emit mySignal(); }
+ void emitMySignalWithArgs(int n) { emit mySignalWithArgs(n); }
+
+signals:
+ void mySignal();
+ void mySignalWithArgs(int n);
+
+public slots:
+ int method() {
+ return x();
+ }
+
+ int methodArgs(int val) {
+ return val + x();
+ }
+
+private:
+ int m_x;
+};
+QML_DECLARE_TYPE(TestObject);
+QML_DEFINE_TYPE(Qt.test, 1, 0, TestObject, TestObject);
+
+TestObject::TestObject(QObject *parent)
+: QObject(parent), m_x(0)
+{
+}
+
+int TestObject::x()
+{
+ return m_x++;
+}
+
+#define PROPERTY_PROGRAM \
+ "(function(testObject) { return (function() { " \
+ " var test = 0; " \
+ " for (var ii = 0; ii < 10000; ++ii) { " \
+ " test += testObject.x; " \
+ " } " \
+ " return test; " \
+ "}); })"
+
+void tst_script::property_js()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.newObject();
+ v.setProperty(QLatin1String("x"), 10);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call().toNumber();
+ }
+}
+
+static QScriptValue property_getter_method(QScriptContext *, QScriptEngine *engine)
+{
+ static int x = 0;
+ return QScriptValue(engine,x++);
+}
+
+void tst_script::property_getter()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.newObject();
+ v.setProperty(QLatin1String("x"), engine.newFunction(property_getter_method),
+ QScriptValue::PropertyGetter);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+static TestObject *property_getter_qobject_object = 0;
+static QScriptValue property_getter_qobject_method(QScriptContext *, QScriptEngine *)
+{
+ static int idx = -1;
+ if (idx == -1)
+ idx = TestObject::staticMetaObject.indexOfProperty("x");
+
+ int value = 0;
+ void *args[] = { &value, 0 };
+ QMetaObject::metacall(property_getter_qobject_object, QMetaObject::ReadProperty, idx, args);
+
+ return QScriptValue(value);
+}
+
+static QScriptValue property_getter_qmetaproperty_method(QScriptContext *, QScriptEngine *)
+{
+ static int idx = -1;
+ if (idx == -1)
+ idx = TestObject::staticMetaObject.indexOfProperty("x");
+
+ int value = 0;
+ value = property_getter_qobject_object->metaObject()->property(idx).read(property_getter_qobject_object).toInt();
+
+ return QScriptValue(value);
+}
+
+void tst_script::property_getter_qobject()
+{
+ QScriptEngine engine;
+
+ TestObject to;
+ property_getter_qobject_object = &to;
+ QScriptValue v = engine.newObject();
+ v.setProperty(QLatin1String("x"), engine.newFunction(property_getter_qobject_method),
+ QScriptValue::PropertyGetter);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+ property_getter_qobject_object = 0;
+}
+
+void tst_script::property_getter_qmetaproperty()
+{
+ QScriptEngine engine;
+
+ TestObject to;
+ property_getter_qobject_object = &to;
+ QScriptValue v = engine.newObject();
+ v.setProperty(QLatin1String("x"), engine.newFunction(property_getter_qmetaproperty_method),
+ QScriptValue::PropertyGetter);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+ property_getter_qobject_object = 0;
+}
+
+
+void tst_script::property_getter_js()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.evaluate("(function() { var o = new Object; o._x = 0; o.__defineGetter__(\"x\", function() { return this._x++; }); return o; })").call();
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::property_qobject()
+{
+ QScriptEngine engine;
+
+ TestObject to;
+ QScriptValue v = engine.newQObject(&to);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(PROPERTY_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::property_qmlobject()
+{
+ QmlEngine qmlengine;
+
+ QScriptEngine *engine = QmlEnginePrivate::getScriptEngine(&qmlengine);
+ TestObject to;
+
+ QScriptValue v = QmlEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine->evaluate(PROPERTY_PROGRAM).call(engine->globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+#define FUNCTION_PROGRAM \
+ "(function(testObject) { return (function() { " \
+ " var test = 0; " \
+ " for (var ii = 0; ii < 10000; ++ii) { " \
+ " test += testObject.method(); " \
+ " } " \
+ " return test; " \
+ "}); })"
+
+void tst_script::function_js()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.evaluate("(function() { var o = new Object; o._x = 0; o.method = (function() { return this._x++; }); return o; })").call();
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(FUNCTION_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+static QScriptValue function_method(QScriptContext *, QScriptEngine *)
+{
+ static int x = 0;
+ return QScriptValue(x++);
+}
+
+void tst_script::function_cpp()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.newObject();
+ v.setProperty(QLatin1String("method"), engine.newFunction(function_method));
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(FUNCTION_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::function_qobject()
+{
+ QScriptEngine engine;
+
+ TestObject to;
+ QScriptValue v = engine.newQObject(&to);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(FUNCTION_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::function_qmlobject()
+{
+ QmlEngine qmlengine;
+
+ QScriptEngine *engine = QmlEnginePrivate::getScriptEngine(&qmlengine);
+ TestObject to;
+
+ QScriptValue v = QmlEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine->evaluate(FUNCTION_PROGRAM).call(engine->globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+#define FUNCTION_ARGS_PROGRAM \
+ "(function(testObject) { return (function() { " \
+ " var test = 0; " \
+ " for (var ii = 0; ii < 10000; ++ii) { " \
+ " test += testObject.methodArgs(ii); " \
+ " } " \
+ " return test; " \
+ "}); })"
+
+void tst_script::function_args_js()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.evaluate("(function() { var o = new Object; o._x = 0; o.methodArgs = (function(a) { return a + this._x++; }); return o; })").call();
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(FUNCTION_ARGS_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+static QScriptValue function_args_method(QScriptContext *ctxt, QScriptEngine *)
+{
+ static int x = 0;
+ return QScriptValue(ctxt->argument(0).toNumber() + x++);
+}
+
+void tst_script::function_args_cpp()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.newObject();
+ v.setProperty(QLatin1String("methodArgs"), engine.newFunction(function_args_method));
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(FUNCTION_ARGS_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::function_args_qobject()
+{
+ QScriptEngine engine;
+
+ TestObject to;
+ QScriptValue v = engine.newQObject(&to);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(FUNCTION_ARGS_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::function_args_qmlobject()
+{
+ QmlEngine qmlengine;
+
+ QScriptEngine *engine = QmlEnginePrivate::getScriptEngine(&qmlengine);
+ TestObject to;
+
+ QScriptValue v = QmlEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine->evaluate(FUNCTION_ARGS_PROGRAM).call(engine->globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::signal_unconnected()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("signal_unconnected.qml"));
+ TestObject *object = qobject_cast<TestObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QBENCHMARK {
+ object->emitMySignal();
+ }
+
+ delete object;
+}
+
+void tst_script::signal_qml()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("signal_qml.qml"));
+ TestObject *object = qobject_cast<TestObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QBENCHMARK {
+ object->emitMySignal();
+ }
+
+ delete object;
+}
+
+void tst_script::signal_args()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("signal_args.qml"));
+ TestObject *object = qobject_cast<TestObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QBENCHMARK {
+ object->emitMySignalWithArgs(11);
+ }
+
+ delete object;
+}
+
+void tst_script::signal_unusedArgs()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("signal_unusedArgs.qml"));
+ TestObject *object = qobject_cast<TestObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QBENCHMARK {
+ object->emitMySignalWithArgs(11);
+ }
+
+ delete object;
+}
+
+void tst_script::slot_simple()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("slot_simple.qml"));
+ TestObject *object = qobject_cast<TestObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QBENCHMARK {
+ object->emitMySignal();
+ }
+
+ delete object;
+}
+
+void tst_script::slot_simple_js()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("slot_simple_js.qml"));
+ TestObject *object = qobject_cast<TestObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QBENCHMARK {
+ object->emitMySignal();
+ }
+
+ delete object;
+}
+
+void tst_script::slot_complex()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("slot_complex.qml"));
+ TestObject *object = qobject_cast<TestObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QBENCHMARK {
+ object->emitMySignal();
+ }
+
+ delete object;
+}
+
+void tst_script::slot_complex_js()
+{
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("slot_complex_js.qml"));
+ TestObject *object = qobject_cast<TestObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QBENCHMARK {
+ object->emitMySignal();
+ }
+
+ delete object;
+}
+
+void tst_script::block_data()
+{
+ QTest::addColumn<QString>("methodName");
+ QTest::newRow("direct") << "doSomethingDirect()";
+ QTest::newRow("localObj") << "doSomethingLocalObj()";
+ QTest::newRow("local") << "doSomethingLocal()";
+}
+
+void tst_script::block()
+{
+ QFETCH(QString, methodName);
+ QmlEngine engine;
+ QmlComponent component(&engine, TEST_FILE("block.qml"));
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle *>(component.create());
+ QVERIFY(rect != 0);
+
+ int index = rect->metaObject()->indexOfMethod(methodName.toUtf8());
+ QVERIFY(index != -1);
+ QMetaMethod method = rect->metaObject()->method(index);
+
+ QBENCHMARK {
+ method.invoke(rect, Qt::DirectConnection);
+ }
+
+ delete rect;
+}
+
+QTEST_MAIN(tst_script)
+
+#include "tst_script.moc"