tests/auto/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 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 
       
    43 #include <QtTest/QtTest>
       
    44 #include <qgraphicsitem.h>
       
    45 
       
    46 Q_DECLARE_METATYPE(QPolygonF)
       
    47 
       
    48 class tst_QGraphicsPolygonItem : public QObject
       
    49 {
       
    50     Q_OBJECT
       
    51 
       
    52 public slots:
       
    53     void initTestCase();
       
    54     void cleanupTestCase();
       
    55     void init();
       
    56     void cleanup();
       
    57 
       
    58 private slots:
       
    59     void qgraphicspolygonitem_data();
       
    60     void qgraphicspolygonitem();
       
    61     void boundingRect_data();
       
    62     void boundingRect();
       
    63     void contains_data();
       
    64     void contains();
       
    65     void fillRule_data();
       
    66     void fillRule();
       
    67     void isObscuredBy_data();
       
    68     void isObscuredBy();
       
    69     void opaqueArea_data();
       
    70     void opaqueArea();
       
    71     void polygon_data();
       
    72     void polygon();
       
    73     void shape_data();
       
    74     void shape();
       
    75     void extension_data();
       
    76     void extension();
       
    77     void setExtension_data();
       
    78     void setExtension();
       
    79     void supportsExtension_data();
       
    80     void supportsExtension();
       
    81 };
       
    82 
       
    83 // Subclass that exposes the protected functions.
       
    84 class SubQGraphicsPolygonItem : public QGraphicsPolygonItem
       
    85 {
       
    86 public:
       
    87     enum Extension {
       
    88         UserExtension = QGraphicsItem::UserExtension
       
    89     };
       
    90 
       
    91     SubQGraphicsPolygonItem(QGraphicsItem *parent = 0) : QGraphicsPolygonItem(parent)
       
    92     {
       
    93     }
       
    94 
       
    95     SubQGraphicsPolygonItem(const QPolygonF &polygon, QGraphicsItem *parent = 0) : QGraphicsPolygonItem(polygon, parent)
       
    96     {
       
    97     }
       
    98 
       
    99     QVariant call_extension(QVariant const& variant) const
       
   100         { return SubQGraphicsPolygonItem::extension(variant); }
       
   101 
       
   102     void call_setExtension(SubQGraphicsPolygonItem::Extension extension, QVariant const& variant)
       
   103         { return SubQGraphicsPolygonItem::setExtension((QGraphicsItem::Extension)extension, variant); }
       
   104 
       
   105     bool call_supportsExtension(SubQGraphicsPolygonItem::Extension extension) const
       
   106         { return SubQGraphicsPolygonItem::supportsExtension((QGraphicsItem::Extension)extension); }
       
   107 };
       
   108 
       
   109 // This will be called before the first test function is executed.
       
   110 // It is only called once.
       
   111 void tst_QGraphicsPolygonItem::initTestCase()
       
   112 {
       
   113 }
       
   114 
       
   115 // This will be called after the last test function is executed.
       
   116 // It is only called once.
       
   117 void tst_QGraphicsPolygonItem::cleanupTestCase()
       
   118 {
       
   119 }
       
   120 
       
   121 // This will be called before each test function is executed.
       
   122 void tst_QGraphicsPolygonItem::init()
       
   123 {
       
   124 }
       
   125 
       
   126 // This will be called after every test function.
       
   127 void tst_QGraphicsPolygonItem::cleanup()
       
   128 {
       
   129 }
       
   130 
       
   131 void tst_QGraphicsPolygonItem::qgraphicspolygonitem_data()
       
   132 {
       
   133 }
       
   134 
       
   135 void tst_QGraphicsPolygonItem::qgraphicspolygonitem()
       
   136 {
       
   137     SubQGraphicsPolygonItem item;
       
   138 
       
   139     item.boundingRect();
       
   140     item.contains(QPoint());
       
   141     item.isObscuredBy(0);
       
   142     item.opaqueArea();
       
   143     //item.paint();
       
   144     item.shape();
       
   145     item.type();
       
   146     item.call_extension(QVariant());
       
   147     item.call_setExtension(SubQGraphicsPolygonItem::UserExtension, QVariant());
       
   148     item.call_supportsExtension(SubQGraphicsPolygonItem::UserExtension);
       
   149     item.fillRule();
       
   150     item.polygon();
       
   151     item.setFillRule(Qt::OddEvenFill);
       
   152     item.setPolygon(QPolygonF());
       
   153 }
       
   154 
       
   155 void tst_QGraphicsPolygonItem::boundingRect_data()
       
   156 {
       
   157     QTest::addColumn<QPolygonF>("polygon");
       
   158     QTest::addColumn<QRectF>("boundingRect");
       
   159     QTest::newRow("null") << QPolygonF() << QRectF();
       
   160     QPolygonF example;
       
   161     example << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);
       
   162     QTest::newRow("example") << example << example.boundingRect();
       
   163     // ### set pen width?
       
   164 }
       
   165 
       
   166 // public QRectF boundingRect() const
       
   167 void tst_QGraphicsPolygonItem::boundingRect()
       
   168 {
       
   169     QFETCH(QPolygonF, polygon);
       
   170     QFETCH(QRectF, boundingRect);
       
   171 
       
   172     SubQGraphicsPolygonItem item(polygon);
       
   173     QCOMPARE(item.boundingRect(), boundingRect);
       
   174 }
       
   175 
       
   176 void tst_QGraphicsPolygonItem::contains_data()
       
   177 {
       
   178     QTest::addColumn<QPolygonF>("polygon");
       
   179     QTest::addColumn<QPointF>("point");
       
   180     QTest::addColumn<bool>("contains");
       
   181     QTest::newRow("null") << QPolygonF() << QPointF() << false;
       
   182 }
       
   183 
       
   184 // public bool contains(QPointF const& point) const
       
   185 void tst_QGraphicsPolygonItem::contains()
       
   186 {
       
   187     QFETCH(QPolygonF, polygon);
       
   188     QFETCH(QPointF, point);
       
   189     QFETCH(bool, contains);
       
   190 
       
   191     SubQGraphicsPolygonItem item(polygon);
       
   192 
       
   193     QCOMPARE(item.contains(point), contains);
       
   194 }
       
   195 
       
   196 Q_DECLARE_METATYPE(Qt::FillRule)
       
   197 void tst_QGraphicsPolygonItem::fillRule_data()
       
   198 {
       
   199     QTest::addColumn<QPolygonF>("polygon");
       
   200     QTest::addColumn<Qt::FillRule>("fillRule");
       
   201     QTest::newRow("OddEvenFill") << QPolygonF() << Qt::OddEvenFill;
       
   202     QTest::newRow("WindingFill") << QPolygonF() << Qt::WindingFill;
       
   203 }
       
   204 
       
   205 // public Qt::FillRule fillRule() const
       
   206 void tst_QGraphicsPolygonItem::fillRule()
       
   207 {
       
   208     QFETCH(QPolygonF, polygon);
       
   209     QFETCH(Qt::FillRule, fillRule);
       
   210 
       
   211     SubQGraphicsPolygonItem item(polygon);
       
   212 
       
   213     item.setFillRule(fillRule);
       
   214     QCOMPARE(item.fillRule(), fillRule);
       
   215     // ### Check that the painting is different?
       
   216 }
       
   217 
       
   218 void tst_QGraphicsPolygonItem::isObscuredBy_data()
       
   219 {
       
   220     QTest::addColumn<QPolygonF>("polygon");
       
   221     QTest::addColumn<QPolygonF>("otherPolygon");
       
   222     QTest::addColumn<bool>("isObscuredBy");
       
   223     QTest::newRow("null") << QPolygonF() << QPolygonF() << false;
       
   224     //QTest::newRow("ontop-inside") << QPixmap(10, 10) << QPixmap(5, 5) << false;
       
   225     //QTest::newRow("ontop-larger") << QPixmap(10, 10) << QPixmap(11, 11) << true;
       
   226 }
       
   227 
       
   228 // public bool isObscuredBy(QGraphicsItem const* item) const
       
   229 void tst_QGraphicsPolygonItem::isObscuredBy()
       
   230 {
       
   231     QFETCH(QPolygonF, polygon);
       
   232     QFETCH(QPolygonF, otherPolygon);
       
   233     QFETCH(bool, isObscuredBy);
       
   234     SubQGraphicsPolygonItem item(polygon);
       
   235     SubQGraphicsPolygonItem otherItem(otherPolygon);
       
   236     QCOMPARE(item.isObscuredBy(&otherItem), isObscuredBy);
       
   237 }
       
   238 
       
   239 Q_DECLARE_METATYPE(QPainterPath)
       
   240 void tst_QGraphicsPolygonItem::opaqueArea_data()
       
   241 {
       
   242     QTest::addColumn<QPolygonF>("polygon");
       
   243     QTest::addColumn<QPainterPath>("opaqueArea");
       
   244     QTest::newRow("null") << QPolygonF() << QPainterPath();
       
   245     // Currently QGraphicsPolygonItem just calls QGraphicsItem test there
       
   246 }
       
   247 
       
   248 // public QPainterPath opaqueArea() const
       
   249 void tst_QGraphicsPolygonItem::opaqueArea()
       
   250 {
       
   251     QFETCH(QPolygonF, polygon);
       
   252     QFETCH(QPainterPath, opaqueArea);
       
   253 
       
   254     SubQGraphicsPolygonItem item(polygon);
       
   255     QCOMPARE(item.opaqueArea(), opaqueArea);
       
   256 }
       
   257 
       
   258 void tst_QGraphicsPolygonItem::polygon_data()
       
   259 {
       
   260     QTest::addColumn<QPolygonF>("polygon");
       
   261     QTest::newRow("null") << QPolygonF();
       
   262     QPolygonF example;
       
   263     example << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);
       
   264     QTest::newRow("example") << example;
       
   265 }
       
   266 
       
   267 // public QPolygonF polygon() const
       
   268 void tst_QGraphicsPolygonItem::polygon()
       
   269 {
       
   270     QFETCH(QPolygonF, polygon);
       
   271 
       
   272     SubQGraphicsPolygonItem item;
       
   273     item.setPolygon(polygon);
       
   274     QCOMPARE(item.polygon(), polygon);
       
   275 }
       
   276 
       
   277 void tst_QGraphicsPolygonItem::shape_data()
       
   278 {
       
   279     QTest::addColumn<QPainterPath>("shape");
       
   280     QTest::newRow("null") << QPainterPath();
       
   281     // ### what should a normal shape look like?
       
   282 }
       
   283 
       
   284 // public QPainterPath shape() const
       
   285 void tst_QGraphicsPolygonItem::shape()
       
   286 {
       
   287     QFETCH(QPainterPath, shape);
       
   288 
       
   289     SubQGraphicsPolygonItem item;
       
   290     QCOMPARE(item.shape(), shape);
       
   291 }
       
   292 
       
   293 Q_DECLARE_METATYPE(QVariant)
       
   294 void tst_QGraphicsPolygonItem::extension_data()
       
   295 {
       
   296     QTest::addColumn<QVariant>("variant");
       
   297     QTest::addColumn<QVariant>("extension");
       
   298     QTest::newRow("null") << QVariant() << QVariant();
       
   299 }
       
   300 
       
   301 // protected QVariant extension(QVariant const& variant) const
       
   302 void tst_QGraphicsPolygonItem::extension()
       
   303 {
       
   304     QFETCH(QVariant, variant);
       
   305     QFETCH(QVariant, extension);
       
   306 
       
   307     SubQGraphicsPolygonItem item;
       
   308 
       
   309     QCOMPARE(item.call_extension(variant), extension);
       
   310 }
       
   311 
       
   312 Q_DECLARE_METATYPE(SubQGraphicsPolygonItem::Extension)
       
   313 void tst_QGraphicsPolygonItem::setExtension_data()
       
   314 {
       
   315     QTest::addColumn<SubQGraphicsPolygonItem::Extension>("extension");
       
   316     QTest::addColumn<QVariant>("variant");
       
   317     QTest::newRow("null") << SubQGraphicsPolygonItem::Extension() << QVariant();
       
   318 }
       
   319 
       
   320 // protected void setExtension(SubQGraphicsPolygonItem::Extension extension, QVariant const& variant)
       
   321 void tst_QGraphicsPolygonItem::setExtension()
       
   322 {
       
   323     QFETCH(SubQGraphicsPolygonItem::Extension, extension);
       
   324     QFETCH(QVariant, variant);
       
   325 
       
   326     SubQGraphicsPolygonItem item;
       
   327     item.call_setExtension(extension, variant);
       
   328 }
       
   329 
       
   330 void tst_QGraphicsPolygonItem::supportsExtension_data()
       
   331 {
       
   332     QTest::addColumn<SubQGraphicsPolygonItem::Extension>("extension");
       
   333     QTest::addColumn<bool>("supportsExtension");
       
   334     QTest::newRow("null") << SubQGraphicsPolygonItem::Extension() << false;
       
   335 }
       
   336 
       
   337 // protected bool supportsExtension(SubQGraphicsPolygonItem::Extension extension) const
       
   338 void tst_QGraphicsPolygonItem::supportsExtension()
       
   339 {
       
   340     QFETCH(SubQGraphicsPolygonItem::Extension, extension);
       
   341     QFETCH(bool, supportsExtension);
       
   342 
       
   343     SubQGraphicsPolygonItem item;
       
   344     QCOMPARE(item.call_supportsExtension(extension), supportsExtension);
       
   345 }
       
   346 
       
   347 QTEST_MAIN(tst_QGraphicsPolygonItem)
       
   348 #include "tst_qgraphicspolygonitem.moc"
       
   349