From 7abc7b839223eaf05006fe35dceec690fee5ce3d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 8 Jan 2010 14:45:46 +1000 Subject: QML signal handler benchmark --- .../declarative/script/data/signal_args.qml | 6 ++ .../declarative/script/data/signal_qml.qml | 6 ++ .../declarative/script/data/signal_unconnected.qml | 4 ++ .../declarative/script/data/signal_unusedArgs.qml | 6 ++ tests/benchmarks/declarative/script/tst_script.cpp | 75 ++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 tests/benchmarks/declarative/script/data/signal_args.qml create mode 100644 tests/benchmarks/declarative/script/data/signal_qml.qml create mode 100644 tests/benchmarks/declarative/script/data/signal_unconnected.qml create mode 100644 tests/benchmarks/declarative/script/data/signal_unusedArgs.qml 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/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index 2aa7a9f..9da795d 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -71,9 +72,18 @@ private slots: void function_args_qobject(); void function_args_qmlobject(); + void signal_unconnected(); + void signal_qml(); + void signal_args(); + void signal_unusedArgs(); private: }; +inline QUrl TEST_FILE(const QString &filename) +{ + return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); +} + class TestObject : public QObject { Q_OBJECT @@ -84,6 +94,13 @@ public: 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(); @@ -96,6 +113,8 @@ public slots: 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) @@ -446,6 +465,62 @@ void tst_script::function_args_qmlobject() } } +void tst_script::signal_unconnected() +{ + QmlEngine engine; + QmlComponent component(&engine, TEST_FILE("signal_unconnected.qml")); + TestObject *object = qobject_cast(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(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(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(component.create()); + QVERIFY(object != 0); + + QBENCHMARK { + object->emitMySignalWithArgs(11); + } + + delete object; +} + QTEST_MAIN(tst_script) #include "tst_script.moc" -- cgit v0.12