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