35a71ba0a92e785e520b85cf0b02d7758f7c32cb
[profile/ivi/qtbase.git] / tests / auto / gui / painting / qpen / tst_qpen.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
45 #include "qpen.h"
46 #include "qbrush.h"
47
48 #include <qdebug.h>
49
50 class tst_QPen : public QObject
51 {
52     Q_OBJECT
53
54 public:
55     tst_QPen();
56
57 private slots:
58     void getSetCheck();
59     void swap();
60     void operator_eq_eq();
61     void operator_eq_eq_data();
62
63     void stream();
64     void stream_data();
65
66     void constructor();
67     void constructor_data();
68 };
69
70 // Testing get/set functions
71 void tst_QPen::getSetCheck()
72 {
73     QPen obj1;
74     // qreal QPen::miterLimit()
75     // void QPen::setMiterLimit(qreal)
76     obj1.setMiterLimit(0.0);
77     QCOMPARE(0.0, obj1.miterLimit());
78     obj1.setMiterLimit(qreal(1.1));
79     QCOMPARE(qreal(1.1), obj1.miterLimit());
80
81     // qreal QPen::widthF()
82     // void QPen::setWidthF(qreal)
83     obj1.setWidthF(0.0);
84     QCOMPARE(0.0, obj1.widthF());
85     obj1.setWidthF(qreal(1.1));
86     QCOMPARE(qreal(1.1), obj1.widthF());
87
88     // int QPen::width()
89     // void QPen::setWidth(int)
90     for (int i = 0; i < 100; ++i) {
91         obj1.setWidth(i);
92         QCOMPARE(i, obj1.width());
93     }
94 }
95
96 void tst_QPen::swap()
97 {
98     QPen p1(Qt::black), p2(Qt::white);
99     p1.swap(p2);
100     QCOMPARE(p1.color(), QColor(Qt::white));
101     QCOMPARE(p2.color(), QColor(Qt::black));
102 }
103
104 Q_DECLARE_METATYPE(QPen)
105 Q_DECLARE_METATYPE(QBrush)
106
107 tst_QPen::tst_QPen()
108
109 {
110 }
111
112 void tst_QPen::operator_eq_eq_data()
113 {
114     QTest::addColumn<QPen>("pen1");
115     QTest::addColumn<QPen>("pen2");
116     QTest::addColumn<bool>("isEqual");
117
118     QTest::newRow("differentColor") << QPen(Qt::red)
119                                  << QPen(Qt::blue)
120                                  << false;
121     QTest::newRow("differentWidth") << QPen(Qt::red, 2)
122                                  << QPen(Qt::red, 3)
123                                  << false;
124     QTest::newRow("differentPenStyle") << QPen(Qt::red, 2, Qt::DashLine)
125                                     << QPen(Qt::red, 2, Qt::DotLine)
126                                     << false;
127     QTest::newRow("differentCapStyle") << QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::BevelJoin)
128                                     << QPen(Qt::red, 2, Qt::DashLine, Qt::SquareCap, Qt::BevelJoin)
129                                     << false;
130     QTest::newRow("differentJoinStyle") << QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::BevelJoin)
131                                      << QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin)
132                                      << false;
133     QTest::newRow("same") << QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::BevelJoin)
134                        << QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::BevelJoin)
135                        << true;
136
137 }
138
139 void tst_QPen::operator_eq_eq()
140 {
141     QFETCH(QPen, pen1);
142     QFETCH(QPen, pen2);
143     QFETCH(bool, isEqual);
144     QCOMPARE(pen1 == pen2, isEqual);
145 }
146
147
148 void tst_QPen::constructor_data()
149 {
150     QTest::addColumn<QPen>("pen");
151     QTest::addColumn<QBrush>("brush");
152     QTest::addColumn<double>("width");
153     QTest::addColumn<int>("style");
154     QTest::addColumn<int>("capStyle");
155     QTest::addColumn<int>("joinStyle");
156
157     QTest::newRow("solid_black") << QPen() << QBrush(Qt::black) << 0. << (int)Qt::SolidLine
158                               << (int) Qt::SquareCap << (int)Qt::BevelJoin;
159     QTest::newRow("solid_red") << QPen(Qt::red) << QBrush(Qt::red) << 0. << (int)Qt::SolidLine
160                             << (int)Qt::SquareCap << (int)Qt::BevelJoin;
161     QTest::newRow("full") << QPen(QBrush(QLinearGradient(0, 0, 100, 100)), 10,
162                                Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)
163                        << QBrush(QLinearGradient(0, 0, 100, 100)) << 10. << (int)Qt::SolidLine
164                        << (int)Qt::RoundCap << (int)Qt::MiterJoin;
165
166 }
167
168
169 void tst_QPen::constructor()
170 {
171     QFETCH(QPen, pen);
172     QFETCH(QBrush, brush);
173     QFETCH(double, width);
174     QFETCH(int, style);
175     QFETCH(int, capStyle);
176     QFETCH(int, joinStyle);
177
178     QCOMPARE(pen.style(), Qt::PenStyle(style));
179     QCOMPARE(pen.capStyle(), Qt::PenCapStyle(capStyle));
180     QCOMPARE(pen.joinStyle(), Qt::PenJoinStyle(joinStyle));
181     QCOMPARE(pen.widthF(), width);
182     QCOMPARE(pen.brush(), brush);
183 }
184
185
186 void tst_QPen::stream_data()
187 {
188     QTest::addColumn<QPen>("pen");
189
190     QTest::newRow("solid_black") << QPen();
191     QTest::newRow("solid_red") << QPen(Qt::red);
192     QTest::newRow("full") << QPen(QBrush(QLinearGradient(0, 0, 100, 100)), 10, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin);
193 }
194
195
196 void tst_QPen::stream()
197 {
198     QFETCH(QPen, pen);
199
200     QByteArray bytes;
201
202     {
203         QDataStream stream(&bytes, QIODevice::WriteOnly);
204         stream << pen;
205     }
206
207     QPen cmp;
208     {
209         QDataStream stream(&bytes, QIODevice::ReadOnly);
210         stream >> cmp;
211     }
212
213     QCOMPARE(pen.widthF(), cmp.widthF());
214     QCOMPARE(pen.style(), cmp.style());
215     QCOMPARE(pen.capStyle(), cmp.capStyle());
216     QCOMPARE(pen.joinStyle(), cmp.joinStyle());
217     QCOMPARE(pen.brush(), cmp.brush());
218
219     QCOMPARE(pen, cmp);
220 }
221
222 QTEST_APPLESS_MAIN(tst_QPen)
223 #include "tst_qpen.moc"