summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/declarative/binding
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-07-17 08:43:46 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-07-17 08:43:46 (GMT)
commit5f4cfb9209781129c12ea4c91829787499bb38b1 (patch)
tree9eaef05ebe3e72472f6dd6b43694895bc218c955 /tests/benchmarks/declarative/binding
parentb27bc8ef235e4e72cbe2ca0ee9d8f4587e564976 (diff)
downloadQt-5f4cfb9209781129c12ea4c91829787499bb38b1.zip
Qt-5f4cfb9209781129c12ea4c91829787499bb38b1.tar.gz
Qt-5f4cfb9209781129c12ea4c91829787499bb38b1.tar.bz2
Add some basic QML benchmarks
Diffstat (limited to 'tests/benchmarks/declarative/binding')
-rw-r--r--tests/benchmarks/declarative/binding/binding.pro8
-rw-r--r--tests/benchmarks/declarative/binding/idproperty.txt7
-rw-r--r--tests/benchmarks/declarative/binding/localproperty.txt3
-rw-r--r--tests/benchmarks/declarative/binding/objectproperty.txt5
-rw-r--r--tests/benchmarks/declarative/binding/testtypes.cpp3
-rw-r--r--tests/benchmarks/declarative/binding/testtypes.h41
-rw-r--r--tests/benchmarks/declarative/binding/tst_binding.cpp126
7 files changed, 193 insertions, 0 deletions
diff --git a/tests/benchmarks/declarative/binding/binding.pro b/tests/benchmarks/declarative/binding/binding.pro
new file mode 100644
index 0000000..26ee4fa
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/binding.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_binding
+QT += declarative
+
+SOURCES += tst_binding.cpp testtypes.cpp
+HEADERS += testtypes.h
+
diff --git a/tests/benchmarks/declarative/binding/idproperty.txt b/tests/benchmarks/declarative/binding/idproperty.txt
new file mode 100644
index 0000000..0a98e0d
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/idproperty.txt
@@ -0,0 +1,7 @@
+MyQmlObject {
+ id: MyObject
+
+ MyQmlObject {
+ result: ###
+ }
+}
diff --git a/tests/benchmarks/declarative/binding/localproperty.txt b/tests/benchmarks/declarative/binding/localproperty.txt
new file mode 100644
index 0000000..4694d99
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/localproperty.txt
@@ -0,0 +1,3 @@
+MyQmlObject {
+ result: ###
+}
diff --git a/tests/benchmarks/declarative/binding/objectproperty.txt b/tests/benchmarks/declarative/binding/objectproperty.txt
new file mode 100644
index 0000000..597c965
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/objectproperty.txt
@@ -0,0 +1,5 @@
+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..60e69e2
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/testtypes.cpp
@@ -0,0 +1,3 @@
+#include "testtypes.h"
+
+QML_DEFINE_TYPE(MyQmlObject, MyQmlObject);
diff --git a/tests/benchmarks/declarative/binding/testtypes.h b/tests/benchmarks/declarative/binding/testtypes.h
new file mode 100644
index 0000000..20bf5f7
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/testtypes.h
@@ -0,0 +1,41 @@
+#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..e593382
--- /dev/null
+++ b/tests/benchmarks/declarative/binding/tst_binding.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+****************************************************************************/
+
+#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") << "objectproperty.txt" << "object.value";
+ QTest::newRow("object.value + 10") << "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") << "localproperty.txt" << "value";
+ QTest::newRow("value + 10") << "localproperty.txt" << "value + 10";
+ QTest::newRow("value + value + 10") << "localproperty.txt" << "value + value + 10";
+
+ QTest::newRow("MyObject.value") << "idproperty.txt" << "MyObject.value";
+ QTest::newRow("MyObject.value + 10") << "idproperty.txt" << "MyObject.value + 10";
+ QTest::newRow("MyObject.value + MyObject.value + 10") << "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"