summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/corelib/codecs/qtextcodec/qtextcodec.pro2
-rwxr-xr-xtests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro2
-rw-r--r--tests/benchmarks/corelib/io/qfileinfo/main.cpp44
-rw-r--r--tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp52
-rw-r--r--tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp47
-rw-r--r--tests/benchmarks/corelib/thread/qmutex/qmutex.pro6
-rw-r--r--tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp131
-rw-r--r--tests/benchmarks/corelib/tools/qstring/qstring.pro2
-rw-r--r--tests/benchmarks/declarative/binding/binding.pro2
-rw-r--r--tests/benchmarks/declarative/compilation/compilation.pro2
-rw-r--r--tests/benchmarks/declarative/creation/creation.pro2
-rw-r--r--tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro2
-rw-r--r--tests/benchmarks/declarative/qdeclarativeimage/qdeclarativeimage.pro2
-rw-r--r--tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro2
-rw-r--r--tests/benchmarks/declarative/qmltime/qmltime.pro2
-rw-r--r--tests/benchmarks/declarative/script/script.pro2
-rw-r--r--tests/benchmarks/declarative/typeimports/typeimports.pro2
-rw-r--r--tests/benchmarks/gui/graphicsview/qgraphicsview/qgraphicsview.pro2
-rw-r--r--tests/benchmarks/gui/image/qimagereader/qimagereader.pro6
-rw-r--r--tests/benchmarks/gui/kernel/qguimetatype/qguimetatype.pro6
-rw-r--r--tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp113
-rw-r--r--tests/benchmarks/gui/kernel/qguivariant/qguivariant.pro6
-rw-r--r--tests/benchmarks/gui/kernel/qguivariant/tst_qguivariant.cpp111
-rw-r--r--tests/benchmarks/gui/text/qtext/qtext.pro2
-rw-r--r--tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp90
-rw-r--r--tests/benchmarks/script/qscriptqobject/qscriptqobject.pro7
-rw-r--r--tests/benchmarks/script/qscriptqobject/tst_qscriptqobject.cpp1237
27 files changed, 1865 insertions, 19 deletions
diff --git a/tests/benchmarks/corelib/codecs/qtextcodec/qtextcodec.pro b/tests/benchmarks/corelib/codecs/qtextcodec/qtextcodec.pro
index 23f0e00..f26d623 100644
--- a/tests/benchmarks/corelib/codecs/qtextcodec/qtextcodec.pro
+++ b/tests/benchmarks/corelib/codecs/qtextcodec/qtextcodec.pro
@@ -6,7 +6,7 @@ SOURCES += main.cpp
wince*:{
DEFINES += SRCDIR=\\\"\\\"
} else:symbian* {
- addFiles.sources = utf-8.txt
+ addFiles.files = utf-8.txt
addFiles.path = .
DEPLOYMENT += addFiles
TARGET.EPOCHEAPSIZE="0x100 0x1000000"
diff --git a/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro b/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro
index 320746c..17d164d 100755
--- a/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro
+++ b/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro
@@ -16,7 +16,7 @@ SOURCES += qfilesystemiterator.cpp
HEADERS += qfilesystemiterator.h
wince*|symbian: {
- corelibdir.sources = $$QT_SOURCE_TREE/src/corelib
+ corelibdir.files = $$QT_SOURCE_TREE/src/corelib
corelibdir.path = ./depot/src
DEPLOYMENT += corelibdir
}
diff --git a/tests/benchmarks/corelib/io/qfileinfo/main.cpp b/tests/benchmarks/corelib/io/qfileinfo/main.cpp
index 025787f..b272bda 100644
--- a/tests/benchmarks/corelib/io/qfileinfo/main.cpp
+++ b/tests/benchmarks/corelib/io/qfileinfo/main.cpp
@@ -43,15 +43,20 @@
#include <QtTest/QtTest>
#include <QtCore/QCoreApplication>
#include <QtCore/QFileInfo>
+#include <QtCore/QFile>
#include "private/qfsfileengine_p.h"
+#include "../../../../shared/filesystem.h"
class qfileinfo : public QObject
{
Q_OBJECT
private slots:
void canonicalFileNamePerformance();
-
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+ void symLinkTargetPerformanceLNK();
+ void symLinkTargetPerformanceMounpoint();
+#endif
void initTestCase();
void cleanupTestCase();
public:
@@ -78,6 +83,43 @@ void qfileinfo::canonicalFileNamePerformance()
}
}
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+void qfileinfo::symLinkTargetPerformanceLNK()
+{
+ QVERIFY(QFile::link("file","link.lnk"));
+ QFileInfo info("link.lnk");
+ info.setCaching(false);
+ QVERIFY(info.isSymLink());
+ QString linkTarget;
+ QBENCHMARK {
+ for(int i=0; i<100; i++)
+ linkTarget = info.readLink();
+ }
+ QVERIFY(QFile::remove("link.lnk"));
+}
+
+void qfileinfo::symLinkTargetPerformanceMounpoint()
+{
+ wchar_t buffer[MAX_PATH];
+ QString rootPath = QDir::toNativeSeparators(QDir::rootPath());
+ QVERIFY(GetVolumeNameForVolumeMountPointW(rootPath.utf16(), buffer, MAX_PATH));
+ QString rootVolume = QString::fromWCharArray(buffer);
+ QString mountpoint = "mountpoint";
+ rootVolume.replace("\\\\?\\","\\??\\");
+ FileSystem::createNtfsJunction(rootVolume, mountpoint);
+
+ QFileInfo info(mountpoint);
+ info.setCaching(false);
+ QVERIFY(info.isSymLink());
+ QString linkTarget;
+ QBENCHMARK {
+ for(int i=0; i<100; i++)
+ linkTarget = info.readLink();
+ }
+ QVERIFY(QDir().rmdir(mountpoint));
+}
+#endif
+
QTEST_MAIN(qfileinfo)
#include "main.moc"
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 36399af..ebeea84 100644
--- a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -71,6 +71,11 @@ private slots:
void isRegisteredBuiltin();
void isRegisteredCustom();
void isRegisteredNotRegistered();
+
+ void constructCoreType_data();
+ void constructCoreType();
+ void constructCoreTypeCopy_data();
+ void constructCoreTypeCopy();
};
tst_QMetaType::tst_QMetaType()
@@ -229,5 +234,52 @@ void tst_QMetaType::isRegisteredNotRegistered()
}
}
+void tst_QMetaType::constructCoreType_data()
+{
+ QTest::addColumn<int>("typeId");
+ for (int i = 0; i <= QMetaType::LastCoreType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+ for (int i = QMetaType::FirstCoreExtType; i <= QMetaType::LastCoreExtType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+ // GUI types are tested in tst_QGuiMetaType.
+}
+
+// Tests how fast QMetaType can default-construct and destroy a Qt
+// core type. The purpose of this benchmark is to measure the overhead
+// of using type id-based creation compared to creating the type
+// directly (i.e. "T *t = new T(); delete t;").
+void tst_QMetaType::constructCoreType()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i) {
+ void *data = QMetaType::construct(typeId, (void *)0);
+ QMetaType::destroy(typeId, data);
+ }
+ }
+}
+
+void tst_QMetaType::constructCoreTypeCopy_data()
+{
+ constructCoreType_data();
+}
+
+// Tests how fast QMetaType can copy-construct and destroy a Qt core
+// type. The purpose of this benchmark is to measure the overhead of
+// using type id-based creation compared to creating the type directly
+// (i.e. "T *t = new T(other); delete t;").
+void tst_QMetaType::constructCoreTypeCopy()
+{
+ QFETCH(int, typeId);
+ QVariant other(typeId, (void *)0);
+ const void *copy = other.constData();
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i) {
+ void *data = QMetaType::construct(typeId, copy);
+ QMetaType::destroy(typeId, data);
+ }
+ }
+}
+
QTEST_MAIN(tst_QMetaType)
#include "tst_qmetatype.moc"
diff --git a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
index 58cec4f..5e19c1b 100644
--- a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -71,6 +71,11 @@ private slots:
void floatVariantValue();
void rectVariantValue();
void stringVariantValue();
+
+ void createCoreType_data();
+ void createCoreType();
+ void createCoreTypeCopy_data();
+ void createCoreTypeCopy();
};
void tst_qvariant::testBound()
@@ -220,6 +225,48 @@ void tst_qvariant::stringVariantValue()
}
}
+void tst_qvariant::createCoreType_data()
+{
+ QTest::addColumn<int>("typeId");
+ for (int i = 0; i <= QMetaType::LastCoreType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+ for (int i = QMetaType::FirstCoreExtType; i <= QMetaType::LastCoreExtType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+}
+
+// Tests how fast a Qt core type can be default-constructed by a
+// QVariant. The purpose of this benchmark is to measure the overhead
+// of creating (and destroying) a QVariant compared to creating the
+// type directly.
+void tst_qvariant::createCoreType()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ QVariant(typeId, (void *)0);
+ }
+}
+
+void tst_qvariant::createCoreTypeCopy_data()
+{
+ createCoreType_data();
+}
+
+// Tests how fast a Qt core type can be copy-constructed by a
+// QVariant. The purpose of this benchmark is to measure the overhead
+// of creating (and destroying) a QVariant compared to creating the
+// type directly.
+void tst_qvariant::createCoreTypeCopy()
+{
+ QFETCH(int, typeId);
+ QVariant other(typeId, (void *)0);
+ const void *copy = other.constData();
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ QVariant(typeId, copy);
+ }
+}
+
QTEST_MAIN(tst_qvariant)
#include "tst_qvariant.moc"
diff --git a/tests/benchmarks/corelib/thread/qmutex/qmutex.pro b/tests/benchmarks/corelib/thread/qmutex/qmutex.pro
new file mode 100644
index 0000000..eda2f11
--- /dev/null
+++ b/tests/benchmarks/corelib/thread/qmutex/qmutex.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qmutex
+
+SOURCES += tst_qmutex.cpp
+
diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
new file mode 100644
index 0000000..fded508
--- /dev/null
+++ b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** 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 <qtest.h>
+#include <QtCore>
+
+#include <math.h>
+
+//TESTED_FILES=
+
+
+class tst_QMutex : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QMutex();
+ virtual ~tst_QMutex();
+
+private slots:
+ void noThread_data();
+ void noThread();
+};
+
+tst_QMutex::tst_QMutex()
+{
+}
+
+tst_QMutex::~tst_QMutex()
+{
+}
+
+void tst_QMutex::noThread_data()
+{
+ QTest::addColumn<int>("t");
+
+ QTest::newRow("noLock") << 1;
+ QTest::newRow("QMutexInline") << 2;
+ QTest::newRow("QMutex") << 3;
+ QTest::newRow("QMutexLocker") << 4;
+}
+
+void tst_QMutex::noThread()
+{
+ volatile int count = 0;
+ const int N = 5000000;
+ QMutex mtx;
+
+ QFETCH(int, t);
+ switch(t) {
+ case 1:
+ QBENCHMARK {
+ count = 0;
+ for (int i = 0; i < N; i++) {
+ count++;
+ }
+ }
+ break;
+ case 2:
+ QBENCHMARK {
+ count = 0;
+ for (int i = 0; i < N; i++) {
+ mtx.lockInline();
+ count++;
+ mtx.unlockInline();
+ }
+ }
+ break;
+ case 3:
+ QBENCHMARK {
+ count = 0;
+ for (int i = 0; i < N; i++) {
+ mtx.lock();
+ count++;
+ mtx.unlock();
+ }
+ }
+ break;
+ case 4:
+ QBENCHMARK {
+ count = 0;
+ for (int i = 0; i < N; i++) {
+ QMutexLocker locker(&mtx);
+ count++;
+ }
+ }
+ break;
+ }
+ QCOMPARE(int(count), N);
+}
+
+QTEST_MAIN(tst_QMutex)
+#include "tst_qmutex.moc"
diff --git a/tests/benchmarks/corelib/tools/qstring/qstring.pro b/tests/benchmarks/corelib/tools/qstring/qstring.pro
index e8720e1..e43e400 100644
--- a/tests/benchmarks/corelib/tools/qstring/qstring.pro
+++ b/tests/benchmarks/corelib/tools/qstring/qstring.pro
@@ -6,7 +6,7 @@ SOURCES += main.cpp data.cpp
wince*:{
DEFINES += SRCDIR=\\\"\\\"
} else:symbian* {
- addFiles.sources = utf-8.txt
+ addFiles.files = utf-8.txt
addFiles.path = .
DEPLOYMENT += addFiles
TARGET.EPOCHEAPSIZE="0x100 0x1000000"
diff --git a/tests/benchmarks/declarative/binding/binding.pro b/tests/benchmarks/declarative/binding/binding.pro
index c1a8223..ceaabeb 100644
--- a/tests/benchmarks/declarative/binding/binding.pro
+++ b/tests/benchmarks/declarative/binding/binding.pro
@@ -8,7 +8,7 @@ SOURCES += tst_binding.cpp testtypes.cpp
HEADERS += testtypes.h
symbian {
- data.sources = data
+ data.files = data
data.path = .
DEPLOYMENT = data
} else {
diff --git a/tests/benchmarks/declarative/compilation/compilation.pro b/tests/benchmarks/declarative/compilation/compilation.pro
index 9277187..9ab2a25 100644
--- a/tests/benchmarks/declarative/compilation/compilation.pro
+++ b/tests/benchmarks/declarative/compilation/compilation.pro
@@ -9,7 +9,7 @@ CONFIG += release
SOURCES += tst_compilation.cpp
symbian {
- data.sources += data
+ data.files += data
data.path = .
DEPLOYMENT += data
} else {
diff --git a/tests/benchmarks/declarative/creation/creation.pro b/tests/benchmarks/declarative/creation/creation.pro
index 6540fa2..74cb47f 100644
--- a/tests/benchmarks/declarative/creation/creation.pro
+++ b/tests/benchmarks/declarative/creation/creation.pro
@@ -7,7 +7,7 @@ macx:CONFIG -= app_bundle
SOURCES += tst_creation.cpp
symbian {
- data.sources = data
+ data.files = data
data.path = .
DEPLOYMENT += data
} else {
diff --git a/tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro b/tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro
index b2f39c1..4693a82 100644
--- a/tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro
+++ b/tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro
@@ -8,7 +8,7 @@ SOURCES += tst_qdeclarativecomponent.cpp testtypes.cpp
HEADERS += testtypes.h
symbian {
- data.sources = data
+ data.files = data
data.path = .
DEPLOYMENT += data
} else {
diff --git a/tests/benchmarks/declarative/qdeclarativeimage/qdeclarativeimage.pro b/tests/benchmarks/declarative/qdeclarativeimage/qdeclarativeimage.pro
index a68792b..c4d5609 100644
--- a/tests/benchmarks/declarative/qdeclarativeimage/qdeclarativeimage.pro
+++ b/tests/benchmarks/declarative/qdeclarativeimage/qdeclarativeimage.pro
@@ -8,7 +8,7 @@ CONFIG += release
SOURCES += tst_qdeclarativeimage.cpp
symbian {
- importFiles.sources = image.png
+ importFiles.files = image.png
importFiles.path =
DEPLOYMENT = importFiles
} else {
diff --git a/tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro b/tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro
index 65ee7e0..765e37a 100644
--- a/tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro
+++ b/tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro
@@ -7,7 +7,7 @@ macx:CONFIG -= app_bundle
SOURCES += tst_qdeclarativemetaproperty.cpp
symbian {
- data.sources += data
+ data.files += data
data.path = .
DEPLOYMENT += data
} else {
diff --git a/tests/benchmarks/declarative/qmltime/qmltime.pro b/tests/benchmarks/declarative/qmltime/qmltime.pro
index 6f5ad5e..273a60a 100644
--- a/tests/benchmarks/declarative/qmltime/qmltime.pro
+++ b/tests/benchmarks/declarative/qmltime/qmltime.pro
@@ -8,7 +8,7 @@ SOURCES += qmltime.cpp
symbian {
TARGET.CAPABILITY = "All -TCB"
- example.sources = example.qml tests
+ example.files = example.qml tests
example.path = .
DEPLOYMENT += example
}
diff --git a/tests/benchmarks/declarative/script/script.pro b/tests/benchmarks/declarative/script/script.pro
index 685ba03..d6cb708 100644
--- a/tests/benchmarks/declarative/script/script.pro
+++ b/tests/benchmarks/declarative/script/script.pro
@@ -8,7 +8,7 @@ CONFIG += release
SOURCES += tst_script.cpp
symbian {
- importFiles.sources = data
+ importFiles.files = data
importFiles.path =
DEPLOYMENT = importFiles
} else {
diff --git a/tests/benchmarks/declarative/typeimports/typeimports.pro b/tests/benchmarks/declarative/typeimports/typeimports.pro
index a5df3f0..56834e6 100644
--- a/tests/benchmarks/declarative/typeimports/typeimports.pro
+++ b/tests/benchmarks/declarative/typeimports/typeimports.pro
@@ -7,7 +7,7 @@ macx:CONFIG -= app_bundle
SOURCES += tst_typeimports.cpp
symbian {
- data.sources = data
+ data.files = data
data.path = .
DEPLOYMENT += data
} else {
diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/qgraphicsview.pro b/tests/benchmarks/gui/graphicsview/qgraphicsview/qgraphicsview.pro
index 6e044f9..bfa374c 100644
--- a/tests/benchmarks/gui/graphicsview/qgraphicsview/qgraphicsview.pro
+++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/qgraphicsview.pro
@@ -9,7 +9,7 @@ include(chiptester/chiptester.pri)
symbian {
qt_not_deployed {
- plugins.sources = qjpeg.dll
+ plugins.files = qjpeg.dll
plugins.path = imageformats
DEPLOYMENT += plugins
}
diff --git a/tests/benchmarks/gui/image/qimagereader/qimagereader.pro b/tests/benchmarks/gui/image/qimagereader/qimagereader.pro
index d67f4be..db5ffcd 100644
--- a/tests/benchmarks/gui/image/qimagereader/qimagereader.pro
+++ b/tests/benchmarks/gui/image/qimagereader/qimagereader.pro
@@ -11,15 +11,15 @@ SOURCES += tst_qimagereader.cpp
QT += network
wince*: {
- addFiles.sources = images
+ addFiles.files = images
addFiles.path = .
CONFIG(debug, debug|release):{
- imageFormatsPlugins.sources = $$(QTDIR)/plugins/imageformats/*d4.dll
+ imageFormatsPlugins.files = $$(QTDIR)/plugins/imageformats/*d4.dll
}
CONFIG(release, debug|release):{
- imageFormatsPlugins.sources = $$(QTDIR)/plugins/imageformats/*[^d]4.dll
+ imageFormatsPlugins.files = $$(QTDIR)/plugins/imageformats/*[^d]4.dll
}
imageFormatsPlugins.path = imageformats
DEPLOYMENT += addFiles imageFormatsPlugins
diff --git a/tests/benchmarks/gui/kernel/qguimetatype/qguimetatype.pro b/tests/benchmarks/gui/kernel/qguimetatype/qguimetatype.pro
new file mode 100644
index 0000000..7ef99e4
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qguimetatype/qguimetatype.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qguimetatype
+
+SOURCES += tst_qguimetatype.cpp
+
diff --git a/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp
new file mode 100644
index 0000000..f94767b
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** 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 <qtest.h>
+#include <QtCore/qmetatype.h>
+
+class tst_QGuiMetaType : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QGuiMetaType();
+ virtual ~tst_QGuiMetaType();
+
+private slots:
+ void constructGuiType_data();
+ void constructGuiType();
+ void constructGuiTypeCopy_data();
+ void constructGuiTypeCopy();
+};
+
+tst_QGuiMetaType::tst_QGuiMetaType()
+{
+}
+
+tst_QGuiMetaType::~tst_QGuiMetaType()
+{
+}
+
+void tst_QGuiMetaType::constructGuiType_data()
+{
+ QTest::addColumn<int>("typeId");
+ for (int i = QMetaType::FirstGuiType; i <= QMetaType::LastGuiType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+}
+
+// Tests how fast QMetaType can default-construct and destroy a Qt GUI
+// type. The purpose of this benchmark is to measure the overhead of
+// using type id-based creation compared to creating the type directly
+// (i.e. "T *t = new T(); delete t;").
+void tst_QGuiMetaType::constructGuiType()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i) {
+ void *data = QMetaType::construct(typeId, (void *)0);
+ QMetaType::destroy(typeId, data);
+ }
+ }
+}
+
+void tst_QGuiMetaType::constructGuiTypeCopy_data()
+{
+ constructGuiType_data();
+}
+
+// Tests how fast QMetaType can copy-construct and destroy a Qt GUI
+// type. The purpose of this benchmark is to measure the overhead of
+// using type id-based creation compared to creating the type directly
+// (i.e. "T *t = new T(other); delete t;").
+void tst_QGuiMetaType::constructGuiTypeCopy()
+{
+ QFETCH(int, typeId);
+ QVariant other(typeId, (void *)0);
+ const void *copy = other.constData();
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i) {
+ void *data = QMetaType::construct(typeId, copy);
+ QMetaType::destroy(typeId, data);
+ }
+ }
+}
+
+QTEST_MAIN(tst_QGuiMetaType)
+#include "tst_qguimetatype.moc"
diff --git a/tests/benchmarks/gui/kernel/qguivariant/qguivariant.pro b/tests/benchmarks/gui/kernel/qguivariant/qguivariant.pro
new file mode 100644
index 0000000..4e05dd7
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qguivariant/qguivariant.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qguivariant
+
+SOURCES += tst_qguivariant.cpp
+
diff --git a/tests/benchmarks/gui/kernel/qguivariant/tst_qguivariant.cpp b/tests/benchmarks/gui/kernel/qguivariant/tst_qguivariant.cpp
new file mode 100644
index 0000000..4016be1
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qguivariant/tst_qguivariant.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** 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 <qtest.h>
+#include <QtCore/qvariant.h>
+
+#define ITERATION_COUNT 1e5
+
+class tst_QGuiVariant : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QGuiVariant();
+ virtual ~tst_QGuiVariant();
+
+private slots:
+ void createGuiType_data();
+ void createGuiType();
+ void createGuiTypeCopy_data();
+ void createGuiTypeCopy();
+};
+
+tst_QGuiVariant::tst_QGuiVariant()
+{
+}
+
+tst_QGuiVariant::~tst_QGuiVariant()
+{
+}
+
+void tst_QGuiVariant::createGuiType_data()
+{
+ QTest::addColumn<int>("typeId");
+ for (int i = QMetaType::FirstGuiType; i <= QMetaType::LastGuiType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+}
+
+// Tests how fast a Qt GUI type can be default-constructed by a
+// QVariant. The purpose of this benchmark is to measure the overhead
+// of creating (and destroying) a QVariant compared to creating the
+// type directly.
+void tst_QGuiVariant::createGuiType()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ QVariant(typeId, (void *)0);
+ }
+}
+
+void tst_QGuiVariant::createGuiTypeCopy_data()
+{
+ createGuiType_data();
+}
+
+// Tests how fast a Qt GUI type can be copy-constructed by a
+// QVariant. The purpose of this benchmark is to measure the overhead
+// of creating (and destroying) a QVariant compared to creating the
+// type directly.
+void tst_QGuiVariant::createGuiTypeCopy()
+{
+ QFETCH(int, typeId);
+ QVariant other(typeId, (void *)0);
+ const void *copy = other.constData();
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ QVariant(typeId, copy);
+ }
+}
+
+QTEST_MAIN(tst_QGuiVariant)
+#include "tst_qguivariant.moc"
diff --git a/tests/benchmarks/gui/text/qtext/qtext.pro b/tests/benchmarks/gui/text/qtext/qtext.pro
index a1b6a22..1c18302 100644
--- a/tests/benchmarks/gui/text/qtext/qtext.pro
+++ b/tests/benchmarks/gui/text/qtext/qtext.pro
@@ -6,7 +6,7 @@ SOURCES += main.cpp
symbian* {
TARGET.CAPABILITY = ALL -TCB
- addFiles.sources = bidi.txt
+ addFiles.files = bidi.txt
addFiles.path = .
DEPLOYMENT += addFiles
} else {
diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 90ae153..6b94f3c 100644
--- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -51,6 +51,8 @@
#include "../../../../auto/network-settings.h"
+Q_DECLARE_METATYPE(QSharedPointer<char>)
+
class TimedSender: public QThread
{
Q_OBJECT
@@ -465,7 +467,8 @@ private slots:
void httpUploadPerformance();
void httpDownloadPerformance_data();
void httpDownloadPerformance();
-
+ void httpDownloadPerformanceDownloadBuffer_data();
+ void httpDownloadPerformanceDownloadBuffer();
};
void tst_qnetworkreply::httpLatency()
@@ -649,6 +652,91 @@ void tst_qnetworkreply::httpDownloadPerformance()
qint64 elapsed = time.elapsed();
qDebug() << "tst_QNetworkReply::httpDownloadPerformance" << elapsed << "msec, "
<< ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec";
+};
+
+enum HttpDownloadPerformanceDownloadBufferTestType {
+ JustDownloadBuffer,
+ DownloadBufferButUseRead,
+ NoDownloadBuffer
+};
+Q_DECLARE_METATYPE(HttpDownloadPerformanceDownloadBufferTestType)
+
+class HttpDownloadPerformanceClientDownloadBuffer : QObject {
+ Q_OBJECT
+private:
+ HttpDownloadPerformanceDownloadBufferTestType testType;
+ QNetworkReply *reply;
+ qint64 uploadSize;
+ QList<qint64> bytesAvailableList;
+public:
+ HttpDownloadPerformanceClientDownloadBuffer (QNetworkReply *reply, HttpDownloadPerformanceDownloadBufferTestType testType, qint64 uploadSize)
+ : testType(testType), reply(reply), uploadSize(uploadSize)
+ {
+ connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot()));
+ }
+
+ public slots:
+ void finishedSlot() {
+ if (testType == JustDownloadBuffer) {
+ // We have a download buffer and use it. This should be the fastest benchmark result.
+ QVariant downloadBufferAttribute = reply->attribute(QNetworkRequest::DownloadBufferAttribute);
+ QSharedPointer<char> data = downloadBufferAttribute.value<QSharedPointer<char> >();
+ } else if (testType == DownloadBufferButUseRead) {
+ // We had a download buffer but we benchmark here the "legacy" read() way to access it
+ char* replyData = (char*) qMalloc(uploadSize);
+ QVERIFY(reply->read(replyData, uploadSize) == uploadSize);
+ qFree(replyData);
+ } else if (testType == NoDownloadBuffer) {
+ // We did not have a download buffer but we still need to benchmark having the data, e.g. reading it all.
+ // This should be the slowest benchmark result.
+ char* replyData = (char*) qMalloc(uploadSize);
+ QVERIFY(reply->read(replyData, uploadSize) == uploadSize);
+ qFree(replyData);
+ }
+
+ QMetaObject::invokeMethod(&QTestEventLoop::instance(), "exitLoop", Qt::QueuedConnection);
+ }
+};
+
+void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer_data()
+{
+ QTest::addColumn<HttpDownloadPerformanceDownloadBufferTestType>("testType");
+
+ QTest::newRow("use-download-buffer") << JustDownloadBuffer;
+ QTest::newRow("use-download-buffer-but-use-read") << DownloadBufferButUseRead;
+ QTest::newRow("do-not-use-download-buffer") << NoDownloadBuffer;
+}
+
+// Please note that the whole "zero copy" download buffer API is private right now. Do not use it.
+void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer()
+{
+ QFETCH(HttpDownloadPerformanceDownloadBufferTestType, testType);
+
+ // On my Linux Desktop the results are already visible with 128 kB, however we use this to have good results.
+#if defined(Q_OS_SYMBIAN) || defined(Q_WS_WINCE_WM)
+ // Show some mercy to non-desktop platform/s
+ enum {UploadSize = 4*1024*1024}; // 4 MB
+#else
+ enum {UploadSize = 32*1024*1024}; // 32 MB
+#endif
+
+ HttpDownloadPerformanceServer server(UploadSize, true, false);
+
+ QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/?bare=1"));
+ if (testType == JustDownloadBuffer || testType == DownloadBufferButUseRead)
+ request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 1024*1024*128); // 128 MB is max allowed
+
+ QNetworkAccessManager manager;
+ QNetworkReplyPtr reply = manager.get(request);
+
+ HttpDownloadPerformanceClientDownloadBuffer client(reply, testType, UploadSize);
+
+ QBENCHMARK_ONCE {
+ QTestEventLoop::instance().enterLoop(40);
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QVERIFY(reply->isFinished());
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ }
}
QTEST_MAIN(tst_qnetworkreply)
diff --git a/tests/benchmarks/script/qscriptqobject/qscriptqobject.pro b/tests/benchmarks/script/qscriptqobject/qscriptqobject.pro
new file mode 100644
index 0000000..30bc447
--- /dev/null
+++ b/tests/benchmarks/script/qscriptqobject/qscriptqobject.pro
@@ -0,0 +1,7 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qscriptqobject
+
+SOURCES += tst_qscriptqobject.cpp
+
+QT += script
diff --git a/tests/benchmarks/script/qscriptqobject/tst_qscriptqobject.cpp b/tests/benchmarks/script/qscriptqobject/tst_qscriptqobject.cpp
new file mode 100644
index 0000000..e68db06
--- /dev/null
+++ b/tests/benchmarks/script/qscriptqobject/tst_qscriptqobject.cpp
@@ -0,0 +1,1237 @@
+/****************************************************************************
+**
+** 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 <qtest.h>
+#include <QtGui>
+#include <QtScript>
+
+#define ITERATION_COUNT 1e4
+
+struct CustomType
+{
+ int a;
+};
+Q_DECLARE_METATYPE(CustomType)
+
+class PropertyTestObject : public QObject
+{
+ Q_OBJECT
+ Q_ENUMS(EnumType)
+ Q_FLAGS(FlagsType)
+ Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty)
+ Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
+ Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty)
+ Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)
+ Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)
+ Q_PROPERTY(QObject* qobjectProperty READ qobjectProperty WRITE setQObjectProperty)
+ Q_PROPERTY(CustomType customProperty READ customProperty WRITE setCustomProperty)
+ Q_PROPERTY(EnumType enumProperty READ enumProperty WRITE setEnumProperty)
+ Q_PROPERTY(FlagsType flagsProperty READ flagsProperty WRITE setFlagsProperty)
+public:
+ enum EnumType {
+ NoEnumValue = 0,
+ FirstEnumValue = 1,
+ SecondEnumValue = 2,
+ ThirdEnumValue = 4
+ };
+ Q_DECLARE_FLAGS(FlagsType, EnumType)
+
+ PropertyTestObject(QObject *parent = 0)
+ : QObject(parent),
+ m_boolProperty(false),
+ m_intProperty(123),
+ m_doubleProperty(123),
+ m_stringProperty("hello"),
+ m_variantProperty(double(123)),
+ m_qobjectProperty(this),
+ m_enumProperty(SecondEnumValue),
+ m_flagsProperty(FirstEnumValue | ThirdEnumValue)
+ { }
+
+ bool boolProperty() const
+ { return m_boolProperty; }
+ void setBoolProperty(bool value)
+ { m_boolProperty = value; }
+
+ int intProperty() const
+ { return m_intProperty; }
+ void setIntProperty(int value)
+ { m_intProperty = value; }
+
+ int doubleProperty() const
+ { return m_doubleProperty; }
+ void setDoubleProperty(double value)
+ { m_doubleProperty = value; }
+
+ QString stringProperty() const
+ { return m_stringProperty; }
+ void setStringProperty(const QString &value)
+ { m_stringProperty = value; }
+
+ QVariant variantProperty() const
+ { return m_variantProperty; }
+ void setVariantProperty(const QVariant &value)
+ { m_variantProperty = value; }
+
+ QObject *qobjectProperty() const
+ { return m_qobjectProperty; }
+ void setQObjectProperty(QObject *qobject)
+ { m_qobjectProperty = qobject; }
+
+ CustomType customProperty() const
+ { return m_customProperty; }
+ void setCustomProperty(const CustomType &value)
+ { m_customProperty = value; }
+
+ EnumType enumProperty() const
+ { return m_enumProperty; }
+ void setEnumProperty(EnumType value)
+ { m_enumProperty = value; }
+
+ FlagsType flagsProperty() const
+ { return m_flagsProperty; }
+ void setFlagsProperty(FlagsType value)
+ { m_flagsProperty = value; }
+
+private:
+ bool m_boolProperty;
+ int m_intProperty;
+ double m_doubleProperty;
+ QString m_stringProperty;
+ QVariant m_variantProperty;
+ QObject *m_qobjectProperty;
+ CustomType m_customProperty;
+ EnumType m_enumProperty;
+ FlagsType m_flagsProperty;
+};
+
+class SlotTestObject : public QObject
+{
+ Q_OBJECT
+public:
+ SlotTestObject(QObject *parent = 0)
+ : QObject(parent),
+ m_string(QString::fromLatin1("hello")),
+ m_variant(123)
+ { }
+
+public Q_SLOTS:
+ void voidSlot() { }
+ void boolSlot(bool) { }
+ void intSlot(int) { }
+ void doubleSlot(double) { }
+ void stringSlot(const QString &) { }
+ void variantSlot(const QVariant &) { }
+ void qobjectSlot(QObject *) { }
+ void customTypeSlot(const CustomType &) { }
+
+ bool returnBoolSlot() { return true; }
+ int returnIntSlot() { return 123; }
+ double returnDoubleSlot() { return 123.0; }
+ QString returnStringSlot() { return m_string; }
+ QVariant returnVariantSlot() { return m_variant; }
+ QObject *returnQObjectSlot() { return this; }
+ CustomType returnCustomTypeSlot() { return m_custom; }
+
+ void fourDoubleSlot(double, double, double, double) { }
+ void sixDoubleSlot(double, double, double, double, double, double) { }
+ void eightDoubleSlot(double, double, double, double, double, double, double, double) { }
+
+ void fourStringSlot(const QString &, const QString &, const QString &, const QString &) { }
+ void sixStringSlot(const QString &, const QString &, const QString &, const QString &,
+ const QString &, const QString &) { }
+ void eightStringSlot(const QString &, const QString &, const QString &, const QString &,
+ const QString &, const QString &, const QString &, const QString &) { }
+
+private:
+ QString m_string;
+ QVariant m_variant;
+ CustomType m_custom;
+};
+
+class SignalTestObject : public QObject
+{
+ Q_OBJECT
+public:
+ SignalTestObject(QObject *parent = 0)
+ : QObject(parent)
+ { }
+
+ void emitVoidSignal()
+ { emit voidSignal(); }
+ void emitBoolSignal(bool value)
+ { emit boolSignal(value); }
+ void emitIntSignal(int value)
+ { emit intSignal(value); }
+ void emitDoubleSignal(double value)
+ { emit doubleSignal(value); }
+ void emitStringSignal(const QString &value)
+ { emit stringSignal(value); }
+ void emitVariantSignal(const QVariant &value)
+ { emit variantSignal(value); }
+ void emitQObjectSignal(QObject *object)
+ { emit qobjectSignal(object); }
+ void emitCustomTypeSignal(const CustomType &value)
+ { emit customTypeSignal(value); }
+
+Q_SIGNALS:
+ void voidSignal();
+ void boolSignal(bool);
+ void intSignal(int);
+ void doubleSignal(double);
+ void stringSignal(const QString &);
+ void variantSignal(const QVariant &);
+ void qobjectSignal(QObject *);
+ void customTypeSignal(const CustomType &);
+};
+
+class OverloadedSlotTestObject : public QObject
+{
+ Q_OBJECT
+public:
+ OverloadedSlotTestObject(QObject *parent = 0)
+ : QObject(parent)
+ { }
+
+public Q_SLOTS:
+ void overloadedSlot() { }
+ void overloadedSlot(bool) { }
+ void overloadedSlot(double) { }
+ void overloadedSlot(const QString &) { }
+};
+
+class QtScriptablePropertyTestObject
+ : public PropertyTestObject, public QScriptable
+{
+};
+
+class QtScriptableSlotTestObject
+ : public SlotTestObject, public QScriptable
+{
+};
+
+class tst_QScriptQObject : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QScriptQObject();
+ virtual ~tst_QScriptQObject();
+
+private slots:
+ void initTestCase();
+
+ void readMetaProperty_data();
+ void readMetaProperty();
+
+ void writeMetaProperty_data();
+ void writeMetaProperty();
+
+ void readDynamicProperty_data();
+ void readDynamicProperty();
+
+ void writeDynamicProperty_data();
+ void writeDynamicProperty();
+
+ void readMethodByName_data();
+ void readMethodByName();
+
+ void readMethodBySignature_data();
+ void readMethodBySignature();
+
+ void readChild_data();
+ void readChild();
+
+ void readOneOfManyChildren_data();
+ void readOneOfManyChildren();
+
+ void readPrototypeProperty_data();
+ void readPrototypeProperty();
+
+ void readScriptProperty_data();
+ void readScriptProperty();
+
+ void readNoSuchProperty_data();
+ void readNoSuchProperty();
+
+ void readAllMetaProperties();
+
+ void callSlot_data();
+ void callSlot();
+
+ void callOverloadedSlot_data();
+ void callOverloadedSlot();
+
+ void voidSignalHandler();
+ void boolSignalHandler();
+ void intSignalHandler();
+ void doubleSignalHandler();
+ void stringSignalHandler();
+ void variantSignalHandler();
+ void qobjectSignalHandler();
+ void customTypeSignalHandler();
+
+ void readButtonMetaProperty_data();
+ void readButtonMetaProperty();
+
+ void writeButtonMetaProperty_data();
+ void writeButtonMetaProperty();
+
+ void readDynamicButtonProperty_data();
+ void readDynamicButtonProperty();
+
+ void writeDynamicButtonProperty_data();
+ void writeDynamicButtonProperty();
+
+ void readButtonMethodByName_data();
+ void readButtonMethodByName();
+
+ void readButtonMethodBySignature_data();
+ void readButtonMethodBySignature();
+
+ void readButtonChild_data();
+ void readButtonChild();
+
+ void readButtonPrototypeProperty_data();
+ void readButtonPrototypeProperty();
+
+ void readButtonScriptProperty_data();
+ void readButtonScriptProperty();
+
+ void readNoSuchButtonProperty_data();
+ void readNoSuchButtonProperty();
+
+ void callButtonMethod_data();
+ void callButtonMethod();
+
+ void readAllButtonMetaProperties();
+
+ void readQScriptableMetaProperty_data();
+ void readQScriptableMetaProperty();
+
+ void writeQScriptableMetaProperty_data();
+ void writeQScriptableMetaProperty();
+
+ void callQScriptableSlot_data();
+ void callQScriptableSlot();
+
+private:
+ void readMetaProperty_dataHelper(const QMetaObject *mo);
+ void readMethodByName_dataHelper(const QMetaObject *mo);
+ void readMethodBySignature_dataHelper(const QMetaObject *mo);
+ void readAllMetaPropertiesHelper(QObject *o);
+
+ void readPropertyHelper(QScriptEngine &engine, const QScriptValue &object,
+ const QString &propertyName, const QString &argTemplate = ".%0");
+ void writePropertyHelper(QScriptEngine &engine, const QScriptValue &object,
+ const QString &propertyName, const QScriptValue &value,
+ const QString &argTemplate = ".%0");
+
+ void callMethodHelper(QScriptEngine &engine, QObject *object,
+ const QString &propertyName, const QString &arguments);
+ void signalHandlerHelper(QScriptEngine &engine, QObject *object, const char *signal);
+};
+
+tst_QScriptQObject::tst_QScriptQObject()
+{
+}
+
+tst_QScriptQObject::~tst_QScriptQObject()
+{
+}
+
+void tst_QScriptQObject::initTestCase()
+{
+ qMetaTypeId<CustomType>();
+}
+
+void tst_QScriptQObject::readMetaProperty_dataHelper(const QMetaObject *mo)
+{
+ QTest::addColumn<QString>("propertyName");
+
+ for (int i = 0; i < mo->propertyCount(); ++i) {
+ QMetaProperty prop = mo->property(i);
+ if (!qstrcmp(prop.name(), "default"))
+ continue; // skip reserved word
+ QTest::newRow(prop.name()) << prop.name();
+ }
+}
+
+void tst_QScriptQObject::readMethodByName_dataHelper(const QMetaObject *mo)
+{
+ QTest::addColumn<QString>("propertyName");
+
+ QSet<QByteArray> uniqueNames;
+ for (int i = 0; i < mo->methodCount(); ++i) {
+ QMetaMethod method = mo->method(i);
+ if (method.access() == QMetaMethod::Private)
+ continue;
+ QByteArray signature = method.signature();
+ QByteArray name = signature.left(signature.indexOf('('));
+ if (uniqueNames.contains(name))
+ continue;
+ QTest::newRow(name) << QString::fromLatin1(name);
+ uniqueNames.insert(name);
+ }
+}
+
+void tst_QScriptQObject::readMethodBySignature_dataHelper(const QMetaObject *mo)
+{
+ QTest::addColumn<QString>("propertyName");
+
+ for (int i = 0; i < mo->methodCount(); ++i) {
+ QMetaMethod method = mo->method(i);
+ if (method.access() == QMetaMethod::Private)
+ continue;
+ QTest::newRow(method.signature()) << QString::fromLatin1(method.signature());
+ }
+}
+
+void tst_QScriptQObject::readAllMetaPropertiesHelper(QObject *o)
+{
+ QString code = QString::fromLatin1(
+ "(function() {\n"
+ " for (var i = 0; i < 100; ++i) {\n");
+ const QMetaObject *mo = o->metaObject();
+ for (int i = 0; i < mo->propertyCount(); ++i) {
+ QMetaProperty prop = mo->property(i);
+ if (!qstrcmp(prop.name(), "default"))
+ continue; // skip reserved word
+ code.append(QString::fromLatin1(" this.%0;\n").arg(prop.name()));
+ }
+ code.append(
+ " }\n"
+ "})");
+
+ QScriptEngine engine;
+ QScriptValue fun = engine.evaluate(code);
+ QVERIFY(fun.isFunction());
+
+ QScriptValue wrapper = engine.newQObject(o);
+ QBENCHMARK {
+ fun.call(wrapper);
+ }
+ QVERIFY(!engine.hasUncaughtException());
+}
+
+void tst_QScriptQObject::readPropertyHelper(
+ QScriptEngine &engine, const QScriptValue &object,
+ const QString &propertyName, const QString &argTemplate)
+{
+ QString code = QString::fromLatin1(
+ "(function() {\n"
+ " for (var i = 0; i < %0; ++i)\n"
+ " this%1;\n"
+ "})").arg(ITERATION_COUNT).arg(argTemplate.arg(propertyName));
+ QScriptValue fun = engine.evaluate(code);
+ QVERIFY(fun.isFunction());
+
+ QBENCHMARK {
+ fun.call(object);
+ }
+ QVERIFY(!engine.hasUncaughtException());
+}
+
+void tst_QScriptQObject::writePropertyHelper(
+ QScriptEngine &engine, const QScriptValue &object,
+ const QString &propertyName, const QScriptValue &value,
+ const QString &argTemplate)
+{
+ QVERIFY(value.isValid());
+ QString code = QString::fromLatin1(
+ "(function(v) {\n"
+ " for (var i = 0; i < %0; ++i)\n"
+ " this%1 = v;\n"
+ "})").arg(ITERATION_COUNT).arg(argTemplate.arg(propertyName));
+ QScriptValue fun = engine.evaluate(code);
+ QVERIFY(fun.isFunction());
+
+ QScriptValueList args;
+ args << value;
+ QBENCHMARK {
+ fun.call(object, args);
+ }
+ QVERIFY(!engine.hasUncaughtException());
+}
+
+void tst_QScriptQObject::callMethodHelper(
+ QScriptEngine &engine, QObject *object,
+ const QString &propertyName, const QString &arguments)
+{
+ QScriptValue wrapper = engine.newQObject(object);
+ QScriptValue method = wrapper.property(propertyName);
+ QVERIFY(method.isFunction());
+
+ // Generate code that calls the function directly; in this way
+ // only function call performance is measured, not function lookup
+ // as well.
+ QString code = QString::fromLatin1(
+ "(function(f) {\n"
+ " for (var i = 0; i < %0; ++i)\n"
+ " f(%1);\n"
+ "})").arg(ITERATION_COUNT).arg(arguments);
+ QScriptValue fun = engine.evaluate(code);
+ QVERIFY(fun.isFunction());
+
+ QScriptValueList args;
+ args << method;
+ QBENCHMARK {
+ fun.call(wrapper, args);
+ }
+ QVERIFY(!engine.hasUncaughtException());
+}
+
+void tst_QScriptQObject::signalHandlerHelper(
+ QScriptEngine &engine, QObject *object, const char *signal)
+{
+ QScriptValue handler = engine.evaluate("(function(a) { return a; })");
+ QVERIFY(handler.isFunction());
+ QVERIFY(qScriptConnect(object, signal, QScriptValue(), handler));
+}
+
+void tst_QScriptQObject::readMetaProperty_data()
+{
+ readMetaProperty_dataHelper(&PropertyTestObject::staticMetaObject);
+}
+
+// Reads a meta-object-defined property from JS. The purpose of this
+// benchmark is to measure the overhead of reading a property from JS
+// compared to calling the property getter directly from C++ without
+// introspection or value conversion (that's the fastest we could
+// possibly hope to get).
+void tst_QScriptQObject::readMetaProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ PropertyTestObject testObject;
+ readPropertyHelper(engine, engine.newQObject(&testObject), propertyName);
+}
+
+void tst_QScriptQObject::writeMetaProperty_data()
+{
+ readMetaProperty_data();
+}
+
+// Writes a meta-object-defined property from JS. The purpose of this
+// benchmark is to measure the overhead of writing a property from JS
+// compared to calling the property setter directly from C++ without
+// introspection or value conversion (that's the fastest we could
+// possibly hope to get).
+void tst_QScriptQObject::writeMetaProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ PropertyTestObject testObject;
+ QScriptValue wrapper = engine.newQObject(&testObject);
+ QScriptValue value = wrapper.property(propertyName);
+ writePropertyHelper(engine, wrapper, propertyName, value);
+}
+
+void tst_QScriptQObject::readDynamicProperty_data()
+{
+ QTest::addColumn<QVariant>("value");
+
+ QTest::newRow("bool") << QVariant(false);
+ QTest::newRow("int") << QVariant(123);
+ QTest::newRow("double") << QVariant(double(123.0));
+ QTest::newRow("string") << QVariant(QString::fromLatin1("hello"));
+ QTest::newRow("QObject*") << qVariantFromValue((QObject*)this);
+ QTest::newRow("CustomType") << qVariantFromValue(CustomType());
+}
+
+// Reads a dynamic property from JS. The purpose of this benchmark is
+// to measure the overhead of reading a dynamic property from JS
+// versus calling QObject::property(aDynamicProperty) directly from
+// C++.
+void tst_QScriptQObject::readDynamicProperty()
+{
+ QFETCH(QVariant, value);
+
+ QObject testObject;
+ const char *propertyName = "dynamicProperty";
+ testObject.setProperty(propertyName, value);
+ QVERIFY(testObject.dynamicPropertyNames().contains(propertyName));
+
+ QScriptEngine engine;
+ readPropertyHelper(engine, engine.newQObject(&testObject), propertyName);
+}
+
+void tst_QScriptQObject::writeDynamicProperty_data()
+{
+ readDynamicProperty_data();
+}
+
+// Writes an existing dynamic property from JS. The purpose of this
+// benchmark is to measure the overhead of writing a dynamic property
+// from JS versus calling QObject::setProperty(aDynamicProperty,
+// aVariant) directly from C++.
+void tst_QScriptQObject::writeDynamicProperty()
+{
+ QFETCH(QVariant, value);
+
+ QObject testObject;
+ const char *propertyName = "dynamicProperty";
+ testObject.setProperty(propertyName, value);
+ QVERIFY(testObject.dynamicPropertyNames().contains(propertyName));
+
+ QScriptEngine engine;
+ writePropertyHelper(engine, engine.newQObject(&testObject), propertyName,
+ qScriptValueFromValue(&engine, value));
+}
+
+void tst_QScriptQObject::readMethodByName_data()
+{
+ readMethodByName_dataHelper(&SlotTestObject::staticMetaObject);
+}
+
+// Reads a meta-object-defined method from JS by name. The purpose of
+// this benchmark is to measure the overhead of resolving a method
+// from JS (effectively, creating and returning a JS wrapper function
+// object for a C++ method).
+void tst_QScriptQObject::readMethodByName()
+{
+ readMetaProperty();
+}
+
+void tst_QScriptQObject::readMethodBySignature_data()
+{
+ readMethodBySignature_dataHelper(&SlotTestObject::staticMetaObject);
+}
+
+// Reads a meta-object-defined method from JS by signature. The
+// purpose of this benchmark is to measure the overhead of resolving a
+// method from JS (effectively, creating and returning a JS wrapper
+// function object for a C++ method).
+void tst_QScriptQObject::readMethodBySignature()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ SlotTestObject testObject;
+ readPropertyHelper(engine, engine.newQObject(&testObject), propertyName, "['%0']");
+}
+
+void tst_QScriptQObject::readChild_data()
+{
+ QTest::addColumn<QString>("propertyName");
+
+ QTest::newRow("child") << "child";
+}
+
+// Reads a child object from JS. The purpose of this benchmark is to
+// measure the overhead of reading a child object from JS compared to
+// calling e.g. qFindChild() directly from C++, when the test object
+// is a plain QObject with only one child.
+void tst_QScriptQObject::readChild()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QObject testObject;
+ QObject *child = new QObject(&testObject);
+ child->setObjectName(propertyName);
+ readPropertyHelper(engine, engine.newQObject(&testObject), propertyName);
+}
+
+void tst_QScriptQObject::readOneOfManyChildren_data()
+{
+ QTest::addColumn<QString>("propertyName");
+
+ QTest::newRow("child0") << "child0";
+ QTest::newRow("child50") << "child50";
+ QTest::newRow("child99") << "child99";
+}
+
+// Reads a child object from JS for an object that has many
+// children. The purpose of this benchmark is to measure the overhead
+// of reading a child object from JS compared to calling
+// e.g. qFindChild() directly from C++.
+void tst_QScriptQObject::readOneOfManyChildren()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QObject testObject;
+ for (int i = 0; i < 100; ++i) {
+ QObject *child = new QObject(&testObject);
+ child->setObjectName(QString::fromLatin1("child%0").arg(i));
+ }
+ readPropertyHelper(engine, engine.newQObject(&testObject), propertyName);
+}
+
+void tst_QScriptQObject::readPrototypeProperty_data()
+{
+ QTest::addColumn<QString>("propertyName");
+
+ // Inherited from Object.prototype.
+ QTest::newRow("hasOwnProperty") << "hasOwnProperty";
+ QTest::newRow("isPrototypeOf") << "isPrototypeOf";
+ QTest::newRow("propertyIsEnumerable") << "propertyIsEnumerable";
+ QTest::newRow("valueOf") << "valueOf";
+}
+
+// Reads a property that's inherited from a prototype object. The
+// purpose of this benchmark is to measure the overhead of resolving a
+// prototype property (i.e., how long it takes the binding to
+// determine that the QObject doesn't have the property itself).
+void tst_QScriptQObject::readPrototypeProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ PropertyTestObject testObject;
+ readPropertyHelper(engine, engine.newQObject(&testObject), propertyName);
+}
+
+void tst_QScriptQObject::readScriptProperty_data()
+{
+ QTest::addColumn<QString>("propertyName");
+
+ QTest::newRow("scriptProperty") << "scriptProperty";
+}
+
+// Reads a JS (non-Qt) property of a wrapper object. The purpose of
+// this benchmark is to measure the overhead of reading a property
+// that only exists on the wrapper object, not on the underlying
+// QObject.
+void tst_QScriptQObject::readScriptProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ PropertyTestObject testObject;
+ QScriptValue wrapper = engine.newQObject(&testObject);
+ wrapper.setProperty(propertyName, 123);
+ QVERIFY(wrapper.property(propertyName).isValid());
+ QVERIFY(!testObject.property(propertyName.toLatin1()).isValid());
+
+ readPropertyHelper(engine, wrapper, propertyName);
+}
+
+void tst_QScriptQObject::readNoSuchProperty_data()
+{
+ QTest::addColumn<QString>("propertyName");
+
+ QTest::newRow("noSuchProperty") << "noSuchProperty";
+}
+
+// Reads a non-existing (undefined) property of a wrapper object. The
+// purpose of this benchmark is to measure the overhead of reading a
+// property that doesn't exist (i.e., how long it takes the binding to
+// determine this).
+void tst_QScriptQObject::readNoSuchProperty()
+{
+ readMetaProperty();
+}
+
+// Reads all meta-object-defined properties from JS. The purpose of
+// this benchmark is to measure the overhead of reading different
+// properties in sequence, not just the same one repeatedly (like
+// readMetaProperty() does).
+void tst_QScriptQObject::readAllMetaProperties()
+{
+ PropertyTestObject testObject;
+ readAllMetaPropertiesHelper(&testObject);
+}
+
+void tst_QScriptQObject::callSlot_data()
+{
+ QTest::addColumn<QString>("propertyName");
+ QTest::addColumn<QString>("arguments");
+
+ QTest::newRow("voidSlot()") << "voidSlot" << "";
+
+ QTest::newRow("boolSlot(true)") << "boolSlot" << "true";
+ QTest::newRow("intSlot(123)") << "intSlot" << "123";
+ QTest::newRow("doubleSlot(123)") << "doubleSlot" << "123";
+ QTest::newRow("stringSlot('hello')") << "stringSlot" << "'hello'";
+ QTest::newRow("variantSlot(123)") << "variantSlot" << "123";
+ QTest::newRow("qobjectSlot(this)") << "qobjectSlot" << "this"; // assumes 'this' is a QObject
+
+ QTest::newRow("returnBoolSlot()") << "returnBoolSlot" << "";
+ QTest::newRow("returnIntSlot()") << "returnIntSlot" << "";
+ QTest::newRow("returnDoubleSlot()") << "returnDoubleSlot" << "";
+ QTest::newRow("returnStringSlot()") << "returnStringSlot" << "";
+ QTest::newRow("returnVariantSlot()") << "returnVariantSlot" << "";
+ QTest::newRow("returnQObjectSlot()") << "returnQObjectSlot" << "";
+ QTest::newRow("returnCustomTypeSlot()") << "returnCustomTypeSlot" << "";
+
+ // Implicit conversion.
+ QTest::newRow("boolSlot(0)") << "boolSlot" << "0";
+ QTest::newRow("intSlot('123')") << "intSlot" << "'123'";
+ QTest::newRow("doubleSlot('123')") << "doubleSlot" << "'123'";
+ QTest::newRow("stringSlot(123)") << "stringSlot" << "123";
+
+ // Many arguments.
+ QTest::newRow("fourDoubleSlot(1,2,3,4)") << "fourDoubleSlot" << "1,2,3,4";
+ QTest::newRow("sixDoubleSlot(1,2,3,4,5,6)") << "sixDoubleSlot" << "1,2,3,4,5,6";
+ QTest::newRow("eightDoubleSlot(1,2,3,4,5,6,7,8)") << "eightDoubleSlot" << "1,2,3,4,5,6,7,8";
+
+ QTest::newRow("fourStringSlot('a','b','c','d')") << "fourStringSlot" << "'a','b','c','d'";
+ QTest::newRow("sixStringSlot('a','b','c','d','e','f')") << "sixStringSlot" << "'a','b','c','d','e','f'";
+ QTest::newRow("eightStringSlot('a','b','c','d','e','f','g','h')") << "eightStringSlot" << "'a','b','c','d','e','f','g','h'";
+}
+
+// Calls a slot from JS. The purpose of this benchmark is to measure
+// the overhead of calling a slot from JS compared to calling the slot
+// directly from C++ without introspection or value conversion (that's
+// the fastest we could possibly hope to get). The slots themselves
+// don't do any work.
+void tst_QScriptQObject::callSlot()
+{
+ QFETCH(QString, propertyName);
+ QFETCH(QString, arguments);
+
+ QScriptEngine engine;
+ SlotTestObject testObject;
+ callMethodHelper(engine, &testObject, propertyName, arguments);
+}
+
+void tst_QScriptQObject::callOverloadedSlot_data()
+{
+ QTest::addColumn<QString>("propertyName");
+ QTest::addColumn<QString>("arguments");
+
+ QTest::newRow("overloadedSlot()") << "overloadedSlot" << "";
+ QTest::newRow("overloadedSlot(true)") << "overloadedSlot" << "true";
+ QTest::newRow("overloadedSlot(123)") << "overloadedSlot" << "123";
+ QTest::newRow("overloadedSlot('hello')") << "overloadedSlot" << "'hello'";
+}
+
+// Calls an overloaded slot from JS. The purpose of this benchmark is
+// to measure the overhead of calling an overloaded slot from JS
+// compared to calling the overloaded slot directly from C++ without
+// introspection or value conversion (that's the fastest we could
+// possibly hope to get).
+void tst_QScriptQObject::callOverloadedSlot()
+{
+ QFETCH(QString, propertyName);
+ QFETCH(QString, arguments);
+
+ QScriptEngine engine;
+ OverloadedSlotTestObject testObject;
+ callMethodHelper(engine, &testObject, propertyName, arguments);
+}
+
+// Benchmarks for JS signal handling. The purpose of these benchmarks
+// is to measure the overhead of dispatching a Qt signal to JS code
+// compared to a normal C++ signal-to-slot dispatch.
+
+void tst_QScriptQObject::voidSignalHandler()
+{
+ SignalTestObject testObject;
+ QScriptEngine engine;
+ signalHandlerHelper(engine, &testObject, SIGNAL(voidSignal()));
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ testObject.emitVoidSignal();
+ }
+}
+
+void tst_QScriptQObject::boolSignalHandler()
+{
+ SignalTestObject testObject;
+ QScriptEngine engine;
+ signalHandlerHelper(engine, &testObject, SIGNAL(boolSignal(bool)));
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ testObject.emitBoolSignal(true);
+ }
+}
+
+void tst_QScriptQObject::intSignalHandler()
+{
+ SignalTestObject testObject;
+ QScriptEngine engine;
+ signalHandlerHelper(engine, &testObject, SIGNAL(intSignal(int)));
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ testObject.emitIntSignal(123);
+ }
+}
+
+void tst_QScriptQObject::doubleSignalHandler()
+{
+ SignalTestObject testObject;
+ QScriptEngine engine;
+ signalHandlerHelper(engine, &testObject, SIGNAL(doubleSignal(double)));
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ testObject.emitDoubleSignal(123.0);
+ }
+}
+
+void tst_QScriptQObject::stringSignalHandler()
+{
+ SignalTestObject testObject;
+ QScriptEngine engine;
+ signalHandlerHelper(engine, &testObject, SIGNAL(stringSignal(QString)));
+ QString value = QString::fromLatin1("hello");
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ testObject.emitStringSignal(value);
+ }
+}
+
+void tst_QScriptQObject::variantSignalHandler()
+{
+ SignalTestObject testObject;
+ QScriptEngine engine;
+ signalHandlerHelper(engine, &testObject, SIGNAL(variantSignal(QVariant)));
+ QVariant value = 123;
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ testObject.emitVariantSignal(value);
+ }
+}
+
+void tst_QScriptQObject::qobjectSignalHandler()
+{
+ SignalTestObject testObject;
+ QScriptEngine engine;
+ signalHandlerHelper(engine, &testObject, SIGNAL(qobjectSignal(QObject*)));
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ testObject.emitQObjectSignal(this);
+ }
+}
+
+void tst_QScriptQObject::customTypeSignalHandler()
+{
+ SignalTestObject testObject;
+ QScriptEngine engine;
+ signalHandlerHelper(engine, &testObject, SIGNAL(customTypeSignal(CustomType)));
+ CustomType value;
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ testObject.emitCustomTypeSignal(value);
+ }
+}
+
+void tst_QScriptQObject::readButtonMetaProperty_data()
+{
+ readMetaProperty_dataHelper(&QPushButton::staticMetaObject);
+}
+
+// Reads a meta-object-defined property from JS. The purpose of this
+// benchmark is to measure the overhead of reading a property from JS
+// compared to calling the property getter directly from C++ without
+// introspection or value conversion (that's the fastest we could
+// possibly hope to get).
+void tst_QScriptQObject::readButtonMetaProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QPushButton pb;
+ readPropertyHelper(engine, engine.newQObject(&pb), propertyName);
+}
+
+void tst_QScriptQObject::writeButtonMetaProperty_data()
+{
+ readButtonMetaProperty_data();
+}
+
+// Writes a meta-object-defined property from JS. The purpose of this
+// benchmark is to measure the overhead of writing a property from JS
+// compared to calling the property setter directly from C++ without
+// introspection or value conversion (that's the fastest we could
+// possibly hope to get).
+void tst_QScriptQObject::writeButtonMetaProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QPushButton pb;
+ QVariant value = pb.property(propertyName.toLatin1());
+ writePropertyHelper(engine, engine.newQObject(&pb), propertyName,
+ qScriptValueFromValue(&engine, value));
+}
+
+void tst_QScriptQObject::readDynamicButtonProperty_data()
+{
+ readDynamicProperty_data();
+}
+
+// Reads a dynamic property from JS. The purpose of this benchmark is
+// to measure the overhead of reading a dynamic property from JS
+// versus calling QObject::property(aDynamicProperty) directly from
+// C++.
+void tst_QScriptQObject::readDynamicButtonProperty()
+{
+ QFETCH(QVariant, value);
+
+ QPushButton pb;
+ const char *propertyName = "dynamicProperty";
+ pb.setProperty(propertyName, value);
+ QVERIFY(pb.dynamicPropertyNames().contains(propertyName));
+
+ QScriptEngine engine;
+ readPropertyHelper(engine, engine.newQObject(&pb), propertyName);
+}
+
+void tst_QScriptQObject::writeDynamicButtonProperty_data()
+{
+ readDynamicButtonProperty_data();
+}
+
+// Writes an existing dynamic property from JS. The purpose of this
+// benchmark is to measure the overhead of writing a dynamic property
+// from JS versus calling QObject::setProperty(aDynamicProperty,
+// aVariant) directly from C++.
+void tst_QScriptQObject::writeDynamicButtonProperty()
+{
+ QFETCH(QVariant, value);
+
+ QPushButton pb;
+ const char *propertyName = "dynamicProperty";
+ pb.setProperty(propertyName, value);
+ QVERIFY(pb.dynamicPropertyNames().contains(propertyName));
+
+ QScriptEngine engine;
+ writePropertyHelper(engine, engine.newQObject(&pb), propertyName,
+ qScriptValueFromValue(&engine, value));
+}
+
+void tst_QScriptQObject::readButtonMethodByName_data()
+{
+ readMethodByName_dataHelper(&QPushButton::staticMetaObject);
+}
+
+// Reads a meta-object-defined method from JS by name. The purpose of
+// this benchmark is to measure the overhead of resolving a method
+// from JS (effectively, creating and returning a JS wrapper function
+// object for a C++ method).
+void tst_QScriptQObject::readButtonMethodByName()
+{
+ readButtonMetaProperty();
+}
+
+void tst_QScriptQObject::readButtonMethodBySignature_data()
+{
+ readMethodBySignature_dataHelper(&QPushButton::staticMetaObject);
+}
+
+// Reads a meta-object-defined method from JS by signature. The
+// purpose of this benchmark is to measure the overhead of resolving a
+// method from JS (effectively, creating and returning a JS wrapper
+// function object for a C++ method).
+void tst_QScriptQObject::readButtonMethodBySignature()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QPushButton pb;
+ readPropertyHelper(engine, engine.newQObject(&pb), propertyName, "['%0']");
+}
+
+void tst_QScriptQObject::readButtonChild_data()
+{
+ QTest::addColumn<QString>("propertyName");
+
+ QTest::newRow("child") << "child";
+}
+
+// Reads a child object from JS. The purpose of this benchmark is to
+// measure the overhead of reading a child object from JS compared to
+// calling e.g. qFindChild() directly from C++.
+void tst_QScriptQObject::readButtonChild()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QPushButton pb;
+ QObject *child = new QObject(&pb);
+ child->setObjectName(propertyName);
+ readPropertyHelper(engine, engine.newQObject(&pb), propertyName);
+}
+
+void tst_QScriptQObject::readButtonPrototypeProperty_data()
+{
+ readPrototypeProperty_data();
+}
+
+// Reads a property that's inherited from a prototype object. The
+// purpose of this benchmark is to measure the overhead of resolving a
+// prototype property (i.e., how long does it take the binding to
+// determine that the QObject doesn't have the property itself).
+void tst_QScriptQObject::readButtonPrototypeProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QPushButton pb;
+ readPropertyHelper(engine, engine.newQObject(&pb), propertyName);
+}
+
+void tst_QScriptQObject::readButtonScriptProperty_data()
+{
+ readScriptProperty_data();
+}
+
+// Reads a JS (non-Qt) property of a wrapper object. The purpose of
+// this benchmark is to measure the overhead of reading a property
+// that only exists on the wrapper object, not on the underlying
+// QObject.
+void tst_QScriptQObject::readButtonScriptProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QPushButton pb;
+ QScriptValue wrapper = engine.newQObject(&pb);
+ wrapper.setProperty(propertyName, 123);
+ QVERIFY(wrapper.property(propertyName).isValid());
+ QVERIFY(!pb.property(propertyName.toLatin1()).isValid());
+
+ readPropertyHelper(engine, wrapper, propertyName);
+}
+
+void tst_QScriptQObject::readNoSuchButtonProperty_data()
+{
+ readNoSuchProperty_data();
+}
+
+// Reads a non-existing (undefined) property of a wrapper object. The
+// purpose of this benchmark is to measure the overhead of reading a
+// property that doesn't exist (i.e., how long does it take the
+// binding to determine that it doesn't exist).
+void tst_QScriptQObject::readNoSuchButtonProperty()
+{
+ readButtonMetaProperty();
+}
+
+void tst_QScriptQObject::callButtonMethod_data()
+{
+ QTest::addColumn<QString>("propertyName");
+ QTest::addColumn<QString>("arguments");
+
+ QTest::newRow("click()") << "click" << "";
+ QTest::newRow("animateClick(50)") << "animateClick" << "10";
+ QTest::newRow("setChecked(true)") << "setChecked" << "true";
+ QTest::newRow("close()") << "close" << "";
+ QTest::newRow("setWindowTitle('foo')") << "setWindowTitle" << "'foo'";
+}
+
+// Calls a slot from JS. The purpose of this benchmark is to measure
+// the overhead of calling a slot from JS compared to calling the slot
+// directly from C++ without introspection or value conversion (that's
+// the fastest we could possibly hope to get).
+void tst_QScriptQObject::callButtonMethod()
+{
+ QFETCH(QString, propertyName);
+ QFETCH(QString, arguments);
+
+ QScriptEngine engine;
+ QPushButton pb;
+ callMethodHelper(engine, &pb, propertyName, arguments);
+}
+
+// Reads all meta-object-defined properties from JS. The purpose of
+// this benchmark is to measure the overhead of reading different
+// properties in sequence, not just the same one repeatedly (like
+// readButtonMetaProperty() does).
+void tst_QScriptQObject::readAllButtonMetaProperties()
+{
+ QPushButton pb;
+ readAllMetaPropertiesHelper(&pb);
+}
+
+void tst_QScriptQObject::readQScriptableMetaProperty_data()
+{
+ readMetaProperty_dataHelper(&QtScriptablePropertyTestObject::staticMetaObject);
+}
+
+// Reads a meta-object-defined property from JS for an object that
+// subclasses QScriptable. The purpose of this benchmark is to measure
+// the overhead compared to reading a property of a non-QScriptable
+// (see readMetaProperty()).
+void tst_QScriptQObject::readQScriptableMetaProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QtScriptablePropertyTestObject testObject;
+ readPropertyHelper(engine, engine.newQObject(&testObject), propertyName);
+}
+
+void tst_QScriptQObject::writeQScriptableMetaProperty_data()
+{
+ readMetaProperty_data();
+}
+
+// Writes a meta-object-defined property from JS for an object that
+// subclasses QScriptable. The purpose of this benchmark is to measure
+// the overhead compared to writing a property of a non-QScriptable
+// object (see writeMetaProperty()).
+void tst_QScriptQObject::writeQScriptableMetaProperty()
+{
+ QFETCH(QString, propertyName);
+
+ QScriptEngine engine;
+ QtScriptablePropertyTestObject testObject;
+ QVariant value = testObject.property(propertyName.toLatin1());
+ writePropertyHelper(engine, engine.newQObject(&testObject), propertyName,
+ qScriptValueFromValue(&engine, value));
+}
+
+void tst_QScriptQObject::callQScriptableSlot_data()
+{
+ callSlot_data();
+}
+
+// Calls a slot from JS for an object that subclasses QScriptable. The
+// purpose of this benchmark is to measure the overhead compared to
+// calling a slot of a non-QScriptable object (see callSlot()).
+void tst_QScriptQObject::callQScriptableSlot()
+{
+ QFETCH(QString, propertyName);
+ QFETCH(QString, arguments);
+
+ QScriptEngine engine;
+ QtScriptableSlotTestObject testObject;
+ callMethodHelper(engine, &testObject, propertyName, arguments);
+}
+
+QTEST_MAIN(tst_QScriptQObject)
+#include "tst_qscriptqobject.moc"