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>
47 Q_DECLARE_METATYPE(QPolygonF)
49 class tst_QGraphicsPolygonItem : public QObject
55 void cleanupTestCase();
60 void qgraphicspolygonitem_data();
61 void qgraphicspolygonitem();
62 void boundingRect_data();
68 void isObscuredBy_data();
70 void opaqueArea_data();
76 void extension_data();
78 void setExtension_data();
80 void supportsExtension_data();
81 void supportsExtension();
84 // Subclass that exposes the protected functions.
85 class SubQGraphicsPolygonItem : public QGraphicsPolygonItem
89 UserExtension = QGraphicsItem::UserExtension
92 SubQGraphicsPolygonItem(QGraphicsItem *parent = 0) : QGraphicsPolygonItem(parent)
96 SubQGraphicsPolygonItem(const QPolygonF &polygon, QGraphicsItem *parent = 0) : QGraphicsPolygonItem(polygon, parent)
100 QVariant call_extension(QVariant const& variant) const
101 { return SubQGraphicsPolygonItem::extension(variant); }
103 void call_setExtension(SubQGraphicsPolygonItem::Extension extension, QVariant const& variant)
104 { return SubQGraphicsPolygonItem::setExtension((QGraphicsItem::Extension)extension, variant); }
106 bool call_supportsExtension(SubQGraphicsPolygonItem::Extension extension) const
107 { return SubQGraphicsPolygonItem::supportsExtension((QGraphicsItem::Extension)extension); }
110 // This will be called before the first test function is executed.
111 // It is only called once.
112 void tst_QGraphicsPolygonItem::initTestCase()
116 // This will be called after the last test function is executed.
117 // It is only called once.
118 void tst_QGraphicsPolygonItem::cleanupTestCase()
122 // This will be called before each test function is executed.
123 void tst_QGraphicsPolygonItem::init()
127 // This will be called after every test function.
128 void tst_QGraphicsPolygonItem::cleanup()
132 void tst_QGraphicsPolygonItem::qgraphicspolygonitem_data()
136 void tst_QGraphicsPolygonItem::qgraphicspolygonitem()
138 SubQGraphicsPolygonItem item;
141 item.contains(QPoint());
142 item.isObscuredBy(0);
147 item.call_extension(QVariant());
148 item.call_setExtension(SubQGraphicsPolygonItem::UserExtension, QVariant());
149 item.call_supportsExtension(SubQGraphicsPolygonItem::UserExtension);
152 item.setFillRule(Qt::OddEvenFill);
153 item.setPolygon(QPolygonF());
156 void tst_QGraphicsPolygonItem::boundingRect_data()
158 QTest::addColumn<QPolygonF>("polygon");
159 QTest::addColumn<QRectF>("boundingRect");
160 QTest::newRow("null") << QPolygonF() << QRectF();
162 example << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);
163 QTest::newRow("example") << example << example.boundingRect();
164 // ### set pen width?
167 // public QRectF boundingRect() const
168 void tst_QGraphicsPolygonItem::boundingRect()
170 QFETCH(QPolygonF, polygon);
171 QFETCH(QRectF, boundingRect);
173 SubQGraphicsPolygonItem item(polygon);
174 item.setPen(QPen(Qt::black, 0));
175 QCOMPARE(item.boundingRect(), boundingRect);
178 void tst_QGraphicsPolygonItem::contains_data()
180 QTest::addColumn<QPolygonF>("polygon");
181 QTest::addColumn<QPointF>("point");
182 QTest::addColumn<bool>("contains");
183 QTest::newRow("null") << QPolygonF() << QPointF() << false;
186 // public bool contains(QPointF const& point) const
187 void tst_QGraphicsPolygonItem::contains()
189 QFETCH(QPolygonF, polygon);
190 QFETCH(QPointF, point);
191 QFETCH(bool, contains);
193 SubQGraphicsPolygonItem item(polygon);
195 QCOMPARE(item.contains(point), contains);
198 Q_DECLARE_METATYPE(Qt::FillRule)
199 void tst_QGraphicsPolygonItem::fillRule_data()
201 QTest::addColumn<QPolygonF>("polygon");
202 QTest::addColumn<Qt::FillRule>("fillRule");
203 QTest::newRow("OddEvenFill") << QPolygonF() << Qt::OddEvenFill;
204 QTest::newRow("WindingFill") << QPolygonF() << Qt::WindingFill;
207 // public Qt::FillRule fillRule() const
208 void tst_QGraphicsPolygonItem::fillRule()
210 QFETCH(QPolygonF, polygon);
211 QFETCH(Qt::FillRule, fillRule);
213 SubQGraphicsPolygonItem item(polygon);
215 item.setFillRule(fillRule);
216 QCOMPARE(item.fillRule(), fillRule);
217 // ### Check that the painting is different?
220 void tst_QGraphicsPolygonItem::isObscuredBy_data()
222 QTest::addColumn<QPolygonF>("polygon");
223 QTest::addColumn<QPolygonF>("otherPolygon");
224 QTest::addColumn<bool>("isObscuredBy");
225 QTest::newRow("null") << QPolygonF() << QPolygonF() << false;
226 //QTest::newRow("ontop-inside") << QPixmap(10, 10) << QPixmap(5, 5) << false;
227 //QTest::newRow("ontop-larger") << QPixmap(10, 10) << QPixmap(11, 11) << true;
230 // public bool isObscuredBy(QGraphicsItem const* item) const
231 void tst_QGraphicsPolygonItem::isObscuredBy()
233 QFETCH(QPolygonF, polygon);
234 QFETCH(QPolygonF, otherPolygon);
235 QFETCH(bool, isObscuredBy);
236 SubQGraphicsPolygonItem item(polygon);
237 SubQGraphicsPolygonItem otherItem(otherPolygon);
238 QCOMPARE(item.isObscuredBy(&otherItem), isObscuredBy);
241 Q_DECLARE_METATYPE(QPainterPath)
242 void tst_QGraphicsPolygonItem::opaqueArea_data()
244 QTest::addColumn<QPolygonF>("polygon");
245 QTest::addColumn<QPainterPath>("opaqueArea");
246 QTest::newRow("null") << QPolygonF() << QPainterPath();
247 // Currently QGraphicsPolygonItem just calls QGraphicsItem test there
250 // public QPainterPath opaqueArea() const
251 void tst_QGraphicsPolygonItem::opaqueArea()
253 QFETCH(QPolygonF, polygon);
254 QFETCH(QPainterPath, opaqueArea);
256 SubQGraphicsPolygonItem item(polygon);
257 QCOMPARE(item.opaqueArea(), opaqueArea);
260 void tst_QGraphicsPolygonItem::polygon_data()
262 QTest::addColumn<QPolygonF>("polygon");
263 QTest::newRow("null") << QPolygonF();
265 example << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);
266 QTest::newRow("example") << example;
269 // public QPolygonF polygon() const
270 void tst_QGraphicsPolygonItem::polygon()
272 QFETCH(QPolygonF, polygon);
274 SubQGraphicsPolygonItem item;
275 item.setPolygon(polygon);
276 QCOMPARE(item.polygon(), polygon);
279 void tst_QGraphicsPolygonItem::shape_data()
281 QTest::addColumn<QPainterPath>("shape");
282 QTest::newRow("null") << QPainterPath();
283 // ### what should a normal shape look like?
286 // public QPainterPath shape() const
287 void tst_QGraphicsPolygonItem::shape()
289 QFETCH(QPainterPath, shape);
291 SubQGraphicsPolygonItem item;
292 QCOMPARE(item.shape(), shape);
295 Q_DECLARE_METATYPE(QVariant)
296 void tst_QGraphicsPolygonItem::extension_data()
298 QTest::addColumn<QVariant>("variant");
299 QTest::addColumn<QVariant>("extension");
300 QTest::newRow("null") << QVariant() << QVariant();
303 // protected QVariant extension(QVariant const& variant) const
304 void tst_QGraphicsPolygonItem::extension()
306 QFETCH(QVariant, variant);
307 QFETCH(QVariant, extension);
309 SubQGraphicsPolygonItem item;
311 QCOMPARE(item.call_extension(variant), extension);
314 Q_DECLARE_METATYPE(SubQGraphicsPolygonItem::Extension)
315 void tst_QGraphicsPolygonItem::setExtension_data()
317 QTest::addColumn<SubQGraphicsPolygonItem::Extension>("extension");
318 QTest::addColumn<QVariant>("variant");
319 QTest::newRow("null") << SubQGraphicsPolygonItem::Extension() << QVariant();
322 // protected void setExtension(SubQGraphicsPolygonItem::Extension extension, QVariant const& variant)
323 void tst_QGraphicsPolygonItem::setExtension()
325 QFETCH(SubQGraphicsPolygonItem::Extension, extension);
326 QFETCH(QVariant, variant);
328 SubQGraphicsPolygonItem item;
329 item.call_setExtension(extension, variant);
332 void tst_QGraphicsPolygonItem::supportsExtension_data()
334 QTest::addColumn<SubQGraphicsPolygonItem::Extension>("extension");
335 QTest::addColumn<bool>("supportsExtension");
336 QTest::newRow("null") << SubQGraphicsPolygonItem::Extension() << false;
339 // protected bool supportsExtension(SubQGraphicsPolygonItem::Extension extension) const
340 void tst_QGraphicsPolygonItem::supportsExtension()
342 QFETCH(SubQGraphicsPolygonItem::Extension, extension);
343 QFETCH(bool, supportsExtension);
345 SubQGraphicsPolygonItem item;
346 QCOMPARE(item.call_supportsExtension(extension), supportsExtension);
349 QTEST_MAIN(tst_QGraphicsPolygonItem)
350 #include "tst_qgraphicspolygonitem.moc"