tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
branchRCL_3
changeset 8 3f74d0d4af4c
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <qtest.h>
       
    43 #include <QGraphicsItem>
       
    44 #include <QGraphicsScene>
       
    45 #include <QGraphicsView>
       
    46 
       
    47 //TESTED_FILES=
       
    48 
       
    49 class tst_QGraphicsItem : public QObject
       
    50 {
       
    51     Q_OBJECT
       
    52 
       
    53 public:
       
    54     tst_QGraphicsItem();
       
    55     virtual ~tst_QGraphicsItem();
       
    56 
       
    57 public slots:
       
    58     void initTestCase();
       
    59     void init();
       
    60     void cleanup();
       
    61 
       
    62 private slots:
       
    63     void setParentItem();
       
    64     void setParentItem_deep();
       
    65     void setParentItem_deep_reversed();
       
    66     void deleteItemWithManyChildren();
       
    67     void setPos_data();
       
    68     void setPos();
       
    69     void setTransform_data();
       
    70     void setTransform();
       
    71     void rotate();
       
    72     void scale();
       
    73     void shear();
       
    74     void translate();
       
    75 };
       
    76 
       
    77 tst_QGraphicsItem::tst_QGraphicsItem()
       
    78 {
       
    79 }
       
    80 
       
    81 tst_QGraphicsItem::~tst_QGraphicsItem()
       
    82 {
       
    83 }
       
    84 
       
    85 static inline void processEvents()
       
    86 {
       
    87     QApplication::flush();
       
    88     QApplication::processEvents();
       
    89     QApplication::processEvents();
       
    90 }
       
    91 
       
    92 void tst_QGraphicsItem::initTestCase()
       
    93 {
       
    94     QApplication::flush();
       
    95     QTest::qWait(1500);
       
    96     processEvents();
       
    97 }
       
    98 
       
    99 void tst_QGraphicsItem::init()
       
   100 {
       
   101     processEvents();
       
   102 }
       
   103 
       
   104 void tst_QGraphicsItem::cleanup()
       
   105 {
       
   106 }
       
   107 
       
   108 void tst_QGraphicsItem::setParentItem()
       
   109 {
       
   110     QBENCHMARK {
       
   111         QGraphicsRectItem rect;
       
   112         QGraphicsRectItem *childRect = new QGraphicsRectItem;
       
   113         childRect->setParentItem(&rect);
       
   114     }
       
   115 }
       
   116 
       
   117 void tst_QGraphicsItem::setParentItem_deep()
       
   118 {
       
   119     QBENCHMARK {
       
   120         QGraphicsRectItem rect;
       
   121         QGraphicsRectItem *lastRect = &rect;
       
   122         for (int i = 0; i < 10; ++i) {
       
   123             QGraphicsRectItem *childRect = new QGraphicsRectItem;
       
   124             childRect->setParentItem(lastRect);
       
   125             lastRect = childRect;
       
   126         }
       
   127         QGraphicsItem *first = rect.children().first();
       
   128         first->setParentItem(0);
       
   129     }
       
   130 }
       
   131 
       
   132 void tst_QGraphicsItem::setParentItem_deep_reversed()
       
   133 {
       
   134     QBENCHMARK {
       
   135         QGraphicsRectItem *lastRect = new QGraphicsRectItem;
       
   136         for (int i = 0; i < 100; ++i) {
       
   137             QGraphicsRectItem *parentRect = new QGraphicsRectItem;
       
   138             lastRect->setParentItem(parentRect);
       
   139             lastRect = parentRect;
       
   140         }
       
   141         delete lastRect;
       
   142     }
       
   143 }
       
   144 
       
   145 void tst_QGraphicsItem::deleteItemWithManyChildren()
       
   146 {
       
   147     QBENCHMARK {
       
   148         QGraphicsRectItem *rect = new QGraphicsRectItem;
       
   149         for (int i = 0; i < 1000; ++i)
       
   150             new QGraphicsRectItem(rect);
       
   151         delete rect;
       
   152     }
       
   153 }
       
   154 
       
   155 void tst_QGraphicsItem::setPos_data()
       
   156 {
       
   157     QTest::addColumn<QPointF>("pos");
       
   158 
       
   159     QTest::newRow("0, 0") << QPointF(0, 0);
       
   160     QTest::newRow("10, 10") << QPointF(10, 10);
       
   161     QTest::newRow("-10, -10") << QPointF(-10, -10);
       
   162 }
       
   163 
       
   164 void tst_QGraphicsItem::setPos()
       
   165 {
       
   166     QFETCH(QPointF, pos);
       
   167 
       
   168     QGraphicsScene scene;
       
   169     QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100));
       
   170     processEvents();
       
   171 
       
   172     QBENCHMARK {
       
   173         rect->setPos(10, 10);
       
   174     }
       
   175 }
       
   176 
       
   177 void tst_QGraphicsItem::setTransform_data()
       
   178 {
       
   179     QTest::addColumn<QTransform>("transform");
       
   180 
       
   181     QTest::newRow("rotate 45z") << QTransform().rotate(45);
       
   182     QTest::newRow("scale 2x2") << QTransform().scale(2, 2);
       
   183     QTest::newRow("translate 100, 100") << QTransform().translate(100, 100);
       
   184     QTest::newRow("rotate 45x 45y 45z") << QTransform().rotate(45, Qt::XAxis)
       
   185         .rotate(45, Qt::YAxis).rotate(45, Qt::ZAxis);
       
   186 }
       
   187 
       
   188 void tst_QGraphicsItem::setTransform()
       
   189 {
       
   190     QFETCH(QTransform, transform);
       
   191 
       
   192     QGraphicsScene scene;
       
   193     QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 100, 100));
       
   194     processEvents();
       
   195 
       
   196     QBENCHMARK {
       
   197         item->setTransform(transform);
       
   198     }
       
   199 }
       
   200 
       
   201 void tst_QGraphicsItem::rotate()
       
   202 {
       
   203     QGraphicsScene scene;
       
   204     QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
       
   205     processEvents();
       
   206 
       
   207     QBENCHMARK {
       
   208         item->rotate(45);
       
   209     }
       
   210 }
       
   211 
       
   212 void tst_QGraphicsItem::scale()
       
   213 {
       
   214     QGraphicsScene scene;
       
   215     QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
       
   216     processEvents();
       
   217 
       
   218     QBENCHMARK {
       
   219         item->scale(2, 2);
       
   220     }
       
   221 }
       
   222 
       
   223 void tst_QGraphicsItem::shear()
       
   224 {
       
   225     QGraphicsScene scene;
       
   226     QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
       
   227     processEvents();
       
   228 
       
   229     QBENCHMARK {
       
   230         item->shear(1.5, 1.5);
       
   231     }
       
   232 }
       
   233 
       
   234 void tst_QGraphicsItem::translate()
       
   235 {
       
   236     QGraphicsScene scene;
       
   237     QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
       
   238     processEvents();
       
   239 
       
   240     QBENCHMARK {
       
   241         item->translate(100, 100);
       
   242     }
       
   243 }
       
   244 
       
   245 QTEST_MAIN(tst_QGraphicsItem)
       
   246 #include "tst_qgraphicsitem.moc"