diff options
author | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
commit | 8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch) | |
tree | a17e1a767a89542ab59907462206d7dcf2e504b2 /tests/benchmarks/qgraphicsscene | |
download | Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.zip Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.gz Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.bz2 |
Long live Qt for S60!
Diffstat (limited to 'tests/benchmarks/qgraphicsscene')
-rw-r--r-- | tests/benchmarks/qgraphicsscene/qgraphicsscene.pro | 6 | ||||
-rw-r--r-- | tests/benchmarks/qgraphicsscene/tst_qgraphicsscene.cpp | 226 |
2 files changed, 232 insertions, 0 deletions
diff --git a/tests/benchmarks/qgraphicsscene/qgraphicsscene.pro b/tests/benchmarks/qgraphicsscene/qgraphicsscene.pro new file mode 100644 index 0000000..b460e2a --- /dev/null +++ b/tests/benchmarks/qgraphicsscene/qgraphicsscene.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qgraphicsscene + +SOURCES += tst_qgraphicsscene.cpp + diff --git a/tests/benchmarks/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/benchmarks/qgraphicsscene/tst_qgraphicsscene.cpp new file mode 100644 index 0000000..106a5e5 --- /dev/null +++ b/tests/benchmarks/qgraphicsscene/tst_qgraphicsscene.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QGraphicsItem> +#include <QGraphicsScene> +#include <QGraphicsView> + +//TESTED_FILES= + +class tst_QGraphicsScene : public QObject +{ + Q_OBJECT + +public: + tst_QGraphicsScene(); + virtual ~tst_QGraphicsScene(); + +public slots: + void init(); + void cleanup(); + +private slots: + void construct(); + void addItem_data(); + void addItem(); + void itemAt_data(); + void itemAt(); +}; + +tst_QGraphicsScene::tst_QGraphicsScene() +{ +} + +tst_QGraphicsScene::~tst_QGraphicsScene() +{ +} + +void tst_QGraphicsScene::init() +{ +} + +void tst_QGraphicsScene::cleanup() +{ +} + +void tst_QGraphicsScene::construct() +{ + QBENCHMARK { + QGraphicsScene scene; + } +} + +void tst_QGraphicsScene::addItem_data() +{ + QTest::addColumn<int>("indexMethod"); + QTest::addColumn<QRectF>("sceneRect"); + QTest::addColumn<int>("numItems_X"); + QTest::addColumn<int>("numItems_Y"); + QTest::addColumn<int>("itemType"); + QTest::addColumn<QRectF>("itemRect"); + + QTest::newRow("null") << 0 << QRectF() << 0 << 0 << 0 << QRectF(); + QTest::newRow("0 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF() << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,0)") << 0 << QRectF() << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF() << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF(0, 0, 100, 100) << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF(0, 0, 250, 250) << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF(0, 0, 1000, 1000) << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 0 << QRectF(0, 0, 2500, 2500) << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF(0, 0, 100, 100) << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF(0, 0, 250, 250) << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF(0, 0, 1000, 1000) << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("0 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 0 << QRectF(0, 0, 2500, 2500) << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF() << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF() << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 10 x 10 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF(0, 0, 100, 100) << 10 << 10 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 25 x 25 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF(0, 0, 250, 250) << 25 << 25 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 100 x 100 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF(0, 0, 1000, 1000) << 100 << 100 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 250 x 250 QGraphicsRectItem (0,0,10,10)") << 1 << QRectF(0, 0, 2500, 2500) << 250 << 250 << int(QGraphicsRectItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 10 x 10 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF(0, 0, 100, 100) << 10 << 10 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 25 x 25 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF(0, 0, 250, 250) << 25 << 25 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 100 x 100 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF(0, 0, 1000, 1000) << 100 << 100 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); + QTest::newRow("1 QRectF() 250 x 250 QGraphicsEllipseItem (0,0,10,10)") << 1 << QRectF(0, 0, 2500, 2500) << 250 << 250 << int(QGraphicsEllipseItem::Type) << QRectF(0, 0, 10, 10); +} + +void tst_QGraphicsScene::addItem() +{ + QFETCH(int, indexMethod); + QFETCH(QRectF, sceneRect); + QFETCH(int, numItems_X); + QFETCH(int, numItems_Y); + QFETCH(int, itemType); + QFETCH(QRectF, itemRect); + + QGraphicsScene scene; + scene.setItemIndexMethod(indexMethod ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex); + if (!sceneRect.isNull()) + scene.setSceneRect(sceneRect); + + QBENCHMARK { + QGraphicsItem *item = 0; + for (int y = 0; y < numItems_Y; ++y) { + for (int x = 0; x < numItems_X; ++x) { + switch (itemType) { + case QGraphicsRectItem::Type: + item = new QGraphicsRectItem(itemRect); + break; + case QGraphicsEllipseItem::Type: + default: + item = new QGraphicsEllipseItem(itemRect); + break; + } + item->setPos(x * itemRect.width(), y * itemRect.height()); + scene.addItem(item); + } + } + scene.itemAt(0, 0); + } +} + +void tst_QGraphicsScene::itemAt_data() +{ + QTest::addColumn<int>("bspTreeDepth"); + QTest::addColumn<QRectF>("sceneRect"); + QTest::addColumn<int>("numItems_X"); + QTest::addColumn<int>("numItems_Y"); + QTest::addColumn<QRectF>("itemRect"); + + QTest::newRow("null") << 0 << QRectF() << 0 << 0 << QRectF(); + QTest::newRow("NoIndex 10x10") << -1 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20); + QTest::newRow("NoIndex 25x25") << -1 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20); + QTest::newRow("NoIndex 100x100") << -1 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20); + QTest::newRow("NoIndex 250x250") << -1 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20); + QTest::newRow("BspTreeIndex depth=auto 10x10") << 0 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20); + QTest::newRow("BspTreeIndex depth=auto 25x25") << 0 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20); + QTest::newRow("BspTreeIndex depth=auto 100x100") << 0 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20); + QTest::newRow("BspTreeIndex depth=auto 250x250") << 0 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20); + QTest::newRow("BspTreeIndex depth=16 10x10") << 16 << QRectF() << 10 << 10 << QRectF(-10, -10, 20, 20); + QTest::newRow("BspTreeIndex depth=16 25x25") << 16 << QRectF() << 25 << 25 << QRectF(-10, -10, 20, 20); + QTest::newRow("BspTreeIndex depth=16 100x100") << 16 << QRectF() << 100 << 100 << QRectF(-10, -10, 20, 20); + QTest::newRow("BspTreeIndex depth=16 250x250") << 16 << QRectF() << 250 << 250 << QRectF(-10, -10, 20, 20); +} + +void tst_QGraphicsScene::itemAt() +{ + QFETCH(int, bspTreeDepth); + QFETCH(QRectF, sceneRect); + QFETCH(int, numItems_X); + QFETCH(int, numItems_Y); + QFETCH(QRectF, itemRect); + + QGraphicsScene scene; + scene.setItemIndexMethod(bspTreeDepth >= 0 ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex); + if (bspTreeDepth > 0) + scene.setBspTreeDepth(bspTreeDepth); + if (!sceneRect.isNull()) + scene.setSceneRect(sceneRect); + + QGraphicsItem *item = 0; + for (int y = 0; y < numItems_Y; ++y) { + for (int x = 0; x < numItems_X; ++x) { + QGraphicsRectItem *item = new QGraphicsRectItem(itemRect); + item->setPos((x - numItems_X/2) * itemRect.width(), (y - numItems_Y/2) * itemRect.height()); + scene.addItem(item); + } + } + + scene.itemAt(0, 0); // triggers indexing + + QBENCHMARK { + scene.itemAt(0, 0); + } +} + +QTEST_MAIN(tst_QGraphicsScene) +#include "tst_qgraphicsscene.moc" |