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>
50 class tst_QPen : public QObject
60 void operator_eq_eq();
61 void operator_eq_eq_data();
67 void constructor_data();
70 // Testing get/set functions
71 void tst_QPen::getSetCheck()
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());
81 // qreal QPen::widthF()
82 // void QPen::setWidthF(qreal)
84 QCOMPARE(0.0, obj1.widthF());
85 obj1.setWidthF(qreal(1.1));
86 QCOMPARE(qreal(1.1), obj1.widthF());
89 // void QPen::setWidth(int)
90 for (int i = 0; i < 100; ++i) {
92 QCOMPARE(i, obj1.width());
98 QPen p1(Qt::black), p2(Qt::white);
100 QCOMPARE(p1.color(), QColor(Qt::white));
101 QCOMPARE(p2.color(), QColor(Qt::black));
104 Q_DECLARE_METATYPE(QPen)
105 Q_DECLARE_METATYPE(QBrush)
112 void tst_QPen::operator_eq_eq_data()
114 QTest::addColumn<QPen>("pen1");
115 QTest::addColumn<QPen>("pen2");
116 QTest::addColumn<bool>("isEqual");
118 QTest::newRow("differentColor") << QPen(Qt::red)
121 QTest::newRow("differentWidth") << QPen(Qt::red, 2)
124 QTest::newRow("differentPenStyle") << QPen(Qt::red, 2, Qt::DashLine)
125 << QPen(Qt::red, 2, Qt::DotLine)
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)
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)
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)
139 void tst_QPen::operator_eq_eq()
143 QFETCH(bool, isEqual);
144 QCOMPARE(pen1 == pen2, isEqual);
148 void tst_QPen::constructor_data()
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");
157 QTest::newRow("solid_black") << QPen() << QBrush(Qt::black) << 1. << (int)Qt::SolidLine
158 << (int) Qt::SquareCap << (int)Qt::BevelJoin;
159 QTest::newRow("solid_red") << QPen(Qt::red) << QBrush(Qt::red) << 1. << (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;
169 void tst_QPen::constructor()
172 QFETCH(QBrush, brush);
173 QFETCH(double, width);
175 QFETCH(int, capStyle);
176 QFETCH(int, joinStyle);
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);
186 void tst_QPen::stream_data()
188 QTest::addColumn<QPen>("pen");
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);
196 void tst_QPen::stream()
203 QDataStream stream(&bytes, QIODevice::WriteOnly);
209 QDataStream stream(&bytes, QIODevice::ReadOnly);
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());
222 QTEST_APPLESS_MAIN(tst_QPen)
223 #include "tst_qpen.moc"