1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
43 #include <QtTest/QtTest>
44 #include <qgraphicsitem.h>
46 Q_DECLARE_METATYPE(QPolygonF)
48 class tst_QGraphicsPolygonItem : public QObject
54 void cleanupTestCase();
59 void qgraphicspolygonitem_data();
60 void qgraphicspolygonitem();
61 void boundingRect_data();
67 void isObscuredBy_data();
69 void opaqueArea_data();
75 void extension_data();
77 void setExtension_data();
79 void supportsExtension_data();
80 void supportsExtension();
83 // Subclass that exposes the protected functions.
84 class SubQGraphicsPolygonItem : public QGraphicsPolygonItem
88 UserExtension = QGraphicsItem::UserExtension
91 SubQGraphicsPolygonItem(QGraphicsItem *parent = 0) : QGraphicsPolygonItem(parent)
95 SubQGraphicsPolygonItem(const QPolygonF &polygon, QGraphicsItem *parent = 0) : QGraphicsPolygonItem(polygon, parent)
99 QVariant call_extension(QVariant const& variant) const
100 { return SubQGraphicsPolygonItem::extension(variant); }
102 void call_setExtension(SubQGraphicsPolygonItem::Extension extension, QVariant const& variant)
103 { return SubQGraphicsPolygonItem::setExtension((QGraphicsItem::Extension)extension, variant); }
105 bool call_supportsExtension(SubQGraphicsPolygonItem::Extension extension) const
106 { return SubQGraphicsPolygonItem::supportsExtension((QGraphicsItem::Extension)extension); }
109 // This will be called before the first test function is executed.
110 // It is only called once.
111 void tst_QGraphicsPolygonItem::initTestCase()
115 // This will be called after the last test function is executed.
116 // It is only called once.
117 void tst_QGraphicsPolygonItem::cleanupTestCase()
121 // This will be called before each test function is executed.
122 void tst_QGraphicsPolygonItem::init()
126 // This will be called after every test function.
127 void tst_QGraphicsPolygonItem::cleanup()
131 void tst_QGraphicsPolygonItem::qgraphicspolygonitem_data()
135 void tst_QGraphicsPolygonItem::qgraphicspolygonitem()
137 SubQGraphicsPolygonItem item;
140 item.contains(QPoint());
141 item.isObscuredBy(0);
146 item.call_extension(QVariant());
147 item.call_setExtension(SubQGraphicsPolygonItem::UserExtension, QVariant());
148 item.call_supportsExtension(SubQGraphicsPolygonItem::UserExtension);
151 item.setFillRule(Qt::OddEvenFill);
152 item.setPolygon(QPolygonF());
155 void tst_QGraphicsPolygonItem::boundingRect_data()
157 QTest::addColumn<QPolygonF>("polygon");
158 QTest::addColumn<QRectF>("boundingRect");
159 QTest::newRow("null") << QPolygonF() << QRectF();
161 example << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);
162 QTest::newRow("example") << example << example.boundingRect();
163 // ### set pen width?
166 // public QRectF boundingRect() const
167 void tst_QGraphicsPolygonItem::boundingRect()
169 QFETCH(QPolygonF, polygon);
170 QFETCH(QRectF, boundingRect);
172 SubQGraphicsPolygonItem item(polygon);
173 QCOMPARE(item.boundingRect(), boundingRect);
176 void tst_QGraphicsPolygonItem::contains_data()
178 QTest::addColumn<QPolygonF>("polygon");
179 QTest::addColumn<QPointF>("point");
180 QTest::addColumn<bool>("contains");
181 QTest::newRow("null") << QPolygonF() << QPointF() << false;
184 // public bool contains(QPointF const& point) const
185 void tst_QGraphicsPolygonItem::contains()
187 QFETCH(QPolygonF, polygon);
188 QFETCH(QPointF, point);
189 QFETCH(bool, contains);
191 SubQGraphicsPolygonItem item(polygon);
193 QCOMPARE(item.contains(point), contains);
196 Q_DECLARE_METATYPE(Qt::FillRule)
197 void tst_QGraphicsPolygonItem::fillRule_data()
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;
205 // public Qt::FillRule fillRule() const
206 void tst_QGraphicsPolygonItem::fillRule()
208 QFETCH(QPolygonF, polygon);
209 QFETCH(Qt::FillRule, fillRule);
211 SubQGraphicsPolygonItem item(polygon);
213 item.setFillRule(fillRule);
214 QCOMPARE(item.fillRule(), fillRule);
215 // ### Check that the painting is different?
218 void tst_QGraphicsPolygonItem::isObscuredBy_data()
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;
228 // public bool isObscuredBy(QGraphicsItem const* item) const
229 void tst_QGraphicsPolygonItem::isObscuredBy()
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);
239 Q_DECLARE_METATYPE(QPainterPath)
240 void tst_QGraphicsPolygonItem::opaqueArea_data()
242 QTest::addColumn<QPolygonF>("polygon");
243 QTest::addColumn<QPainterPath>("opaqueArea");
244 QTest::newRow("null") << QPolygonF() << QPainterPath();
245 // Currently QGraphicsPolygonItem just calls QGraphicsItem test there
248 // public QPainterPath opaqueArea() const
249 void tst_QGraphicsPolygonItem::opaqueArea()
251 QFETCH(QPolygonF, polygon);
252 QFETCH(QPainterPath, opaqueArea);
254 SubQGraphicsPolygonItem item(polygon);
255 QCOMPARE(item.opaqueArea(), opaqueArea);
258 void tst_QGraphicsPolygonItem::polygon_data()
260 QTest::addColumn<QPolygonF>("polygon");
261 QTest::newRow("null") << QPolygonF();
263 example << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);
264 QTest::newRow("example") << example;
267 // public QPolygonF polygon() const
268 void tst_QGraphicsPolygonItem::polygon()
270 QFETCH(QPolygonF, polygon);
272 SubQGraphicsPolygonItem item;
273 item.setPolygon(polygon);
274 QCOMPARE(item.polygon(), polygon);
277 void tst_QGraphicsPolygonItem::shape_data()
279 QTest::addColumn<QPainterPath>("shape");
280 QTest::newRow("null") << QPainterPath();
281 // ### what should a normal shape look like?
284 // public QPainterPath shape() const
285 void tst_QGraphicsPolygonItem::shape()
287 QFETCH(QPainterPath, shape);
289 SubQGraphicsPolygonItem item;
290 QCOMPARE(item.shape(), shape);
293 Q_DECLARE_METATYPE(QVariant)
294 void tst_QGraphicsPolygonItem::extension_data()
296 QTest::addColumn<QVariant>("variant");
297 QTest::addColumn<QVariant>("extension");
298 QTest::newRow("null") << QVariant() << QVariant();
301 // protected QVariant extension(QVariant const& variant) const
302 void tst_QGraphicsPolygonItem::extension()
304 QFETCH(QVariant, variant);
305 QFETCH(QVariant, extension);
307 SubQGraphicsPolygonItem item;
309 QCOMPARE(item.call_extension(variant), extension);
312 Q_DECLARE_METATYPE(SubQGraphicsPolygonItem::Extension)
313 void tst_QGraphicsPolygonItem::setExtension_data()
315 QTest::addColumn<SubQGraphicsPolygonItem::Extension>("extension");
316 QTest::addColumn<QVariant>("variant");
317 QTest::newRow("null") << SubQGraphicsPolygonItem::Extension() << QVariant();
320 // protected void setExtension(SubQGraphicsPolygonItem::Extension extension, QVariant const& variant)
321 void tst_QGraphicsPolygonItem::setExtension()
323 QFETCH(SubQGraphicsPolygonItem::Extension, extension);
324 QFETCH(QVariant, variant);
326 SubQGraphicsPolygonItem item;
327 item.call_setExtension(extension, variant);
330 void tst_QGraphicsPolygonItem::supportsExtension_data()
332 QTest::addColumn<SubQGraphicsPolygonItem::Extension>("extension");
333 QTest::addColumn<bool>("supportsExtension");
334 QTest::newRow("null") << SubQGraphicsPolygonItem::Extension() << false;
337 // protected bool supportsExtension(SubQGraphicsPolygonItem::Extension extension) const
338 void tst_QGraphicsPolygonItem::supportsExtension()
340 QFETCH(SubQGraphicsPolygonItem::Extension, extension);
341 QFETCH(bool, supportsExtension);
343 SubQGraphicsPolygonItem item;
344 QCOMPARE(item.call_supportsExtension(extension), supportsExtension);
347 QTEST_MAIN(tst_QGraphicsPolygonItem)
348 #include "tst_qgraphicspolygonitem.moc"