0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
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 |
//TESTED_CLASS=
|
|
51 |
//TESTED_FILES=
|
|
52 |
|
|
53 |
class tst_QPen : public QObject
|
|
54 |
{
|
|
55 |
Q_OBJECT
|
|
56 |
|
|
57 |
public:
|
|
58 |
tst_QPen();
|
|
59 |
|
|
60 |
private slots:
|
|
61 |
void getSetCheck();
|
|
62 |
void operator_eq_eq();
|
|
63 |
void operator_eq_eq_data();
|
|
64 |
|
|
65 |
void stream();
|
|
66 |
void stream_data();
|
|
67 |
|
|
68 |
void constructor();
|
|
69 |
void constructor_data();
|
|
70 |
};
|
|
71 |
|
|
72 |
// Testing get/set functions
|
|
73 |
void tst_QPen::getSetCheck()
|
|
74 |
{
|
|
75 |
QPen obj1;
|
|
76 |
// qreal QPen::miterLimit()
|
|
77 |
// void QPen::setMiterLimit(qreal)
|
|
78 |
obj1.setMiterLimit(0.0);
|
|
79 |
QCOMPARE(0.0, obj1.miterLimit());
|
|
80 |
obj1.setMiterLimit(qreal(1.1));
|
|
81 |
QCOMPARE(qreal(1.1), obj1.miterLimit());
|
|
82 |
|
|
83 |
// qreal QPen::widthF()
|
|
84 |
// void QPen::setWidthF(qreal)
|
|
85 |
obj1.setWidthF(0.0);
|
|
86 |
QCOMPARE(0.0, obj1.widthF());
|
|
87 |
obj1.setWidthF(qreal(1.1));
|
|
88 |
QCOMPARE(qreal(1.1), obj1.widthF());
|
|
89 |
|
|
90 |
// int QPen::width()
|
|
91 |
// void QPen::setWidth(int)
|
|
92 |
for (int i = 0; i < 100; ++i) {
|
|
93 |
obj1.setWidth(i);
|
|
94 |
QCOMPARE(i, obj1.width());
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
Q_DECLARE_METATYPE(QPen)
|
|
99 |
Q_DECLARE_METATYPE(QBrush)
|
|
100 |
|
|
101 |
tst_QPen::tst_QPen()
|
|
102 |
|
|
103 |
{
|
|
104 |
}
|
|
105 |
|
|
106 |
void tst_QPen::operator_eq_eq_data()
|
|
107 |
{
|
|
108 |
QTest::addColumn<QPen>("pen1");
|
|
109 |
QTest::addColumn<QPen>("pen2");
|
|
110 |
QTest::addColumn<bool>("isEqual");
|
|
111 |
|
|
112 |
QTest::newRow("differentColor") << QPen(Qt::red)
|
|
113 |
<< QPen(Qt::blue)
|
|
114 |
<< bool(FALSE);
|
|
115 |
QTest::newRow("differentWidth") << QPen(Qt::red, 2)
|
|
116 |
<< QPen(Qt::red, 3)
|
|
117 |
<< bool(FALSE);
|
|
118 |
QTest::newRow("differentPenStyle") << QPen(Qt::red, 2, Qt::DashLine)
|
|
119 |
<< QPen(Qt::red, 2, Qt::DotLine)
|
|
120 |
<< bool(FALSE);
|
|
121 |
QTest::newRow("differentCapStyle") << QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::BevelJoin)
|
|
122 |
<< QPen(Qt::red, 2, Qt::DashLine, Qt::SquareCap, Qt::BevelJoin)
|
|
123 |
<< bool(FALSE);
|
|
124 |
QTest::newRow("differentJoinStyle") << QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::BevelJoin)
|
|
125 |
<< QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::MiterJoin)
|
|
126 |
<< bool(FALSE);
|
|
127 |
QTest::newRow("same") << QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::BevelJoin)
|
|
128 |
<< QPen(Qt::red, 2, Qt::DashLine, Qt::RoundCap, Qt::BevelJoin)
|
|
129 |
<< bool(TRUE);
|
|
130 |
|
|
131 |
}
|
|
132 |
|
|
133 |
void tst_QPen::operator_eq_eq()
|
|
134 |
{
|
|
135 |
QFETCH(QPen, pen1);
|
|
136 |
QFETCH(QPen, pen2);
|
|
137 |
QFETCH(bool, isEqual);
|
|
138 |
QCOMPARE(pen1 == pen2, isEqual);
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
void tst_QPen::constructor_data()
|
|
143 |
{
|
|
144 |
QTest::addColumn<QPen>("pen");
|
|
145 |
QTest::addColumn<QBrush>("brush");
|
|
146 |
QTest::addColumn<double>("width");
|
|
147 |
QTest::addColumn<int>("style");
|
|
148 |
QTest::addColumn<int>("capStyle");
|
|
149 |
QTest::addColumn<int>("joinStyle");
|
|
150 |
|
|
151 |
QTest::newRow("solid_black") << QPen() << QBrush(Qt::black) << 0. << (int)Qt::SolidLine
|
|
152 |
<< (int) Qt::SquareCap << (int)Qt::BevelJoin;
|
|
153 |
QTest::newRow("solid_red") << QPen(Qt::red) << QBrush(Qt::red) << 0. << (int)Qt::SolidLine
|
|
154 |
<< (int)Qt::SquareCap << (int)Qt::BevelJoin;
|
|
155 |
QTest::newRow("full") << QPen(QBrush(QLinearGradient(0, 0, 100, 100)), 10,
|
|
156 |
Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)
|
|
157 |
<< QBrush(QLinearGradient(0, 0, 100, 100)) << 10. << (int)Qt::SolidLine
|
|
158 |
<< (int)Qt::RoundCap << (int)Qt::MiterJoin;
|
|
159 |
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
void tst_QPen::constructor()
|
|
164 |
{
|
|
165 |
QFETCH(QPen, pen);
|
|
166 |
QFETCH(QBrush, brush);
|
|
167 |
QFETCH(double, width);
|
|
168 |
QFETCH(int, style);
|
|
169 |
QFETCH(int, capStyle);
|
|
170 |
QFETCH(int, joinStyle);
|
|
171 |
|
|
172 |
QCOMPARE(pen.style(), Qt::PenStyle(style));
|
|
173 |
QCOMPARE(pen.capStyle(), Qt::PenCapStyle(capStyle));
|
|
174 |
QCOMPARE(pen.joinStyle(), Qt::PenJoinStyle(joinStyle));
|
|
175 |
QCOMPARE(pen.widthF(), width);
|
|
176 |
QCOMPARE(pen.brush(), brush);
|
|
177 |
}
|
|
178 |
|
|
179 |
|
|
180 |
void tst_QPen::stream_data()
|
|
181 |
{
|
|
182 |
QTest::addColumn<QPen>("pen");
|
|
183 |
|
|
184 |
QTest::newRow("solid_black") << QPen();
|
|
185 |
QTest::newRow("solid_red") << QPen(Qt::red);
|
|
186 |
QTest::newRow("full") << QPen(QBrush(QLinearGradient(0, 0, 100, 100)), 10, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin);
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
void tst_QPen::stream()
|
|
191 |
{
|
|
192 |
QFETCH(QPen, pen);
|
|
193 |
|
|
194 |
QByteArray bytes;
|
|
195 |
|
|
196 |
{
|
|
197 |
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
|
198 |
stream << pen;
|
|
199 |
}
|
|
200 |
|
|
201 |
QPen cmp;
|
|
202 |
{
|
|
203 |
QDataStream stream(&bytes, QIODevice::ReadOnly);
|
|
204 |
stream >> cmp;
|
|
205 |
}
|
|
206 |
|
|
207 |
QCOMPARE(pen.widthF(), cmp.widthF());
|
|
208 |
QCOMPARE(pen.style(), cmp.style());
|
|
209 |
QCOMPARE(pen.capStyle(), cmp.capStyle());
|
|
210 |
QCOMPARE(pen.joinStyle(), cmp.joinStyle());
|
|
211 |
QCOMPARE(pen.brush(), cmp.brush());
|
|
212 |
|
|
213 |
QCOMPARE(pen, cmp);
|
|
214 |
}
|
|
215 |
|
|
216 |
|
|
217 |
QTEST_APPLESS_MAIN(tst_QPen)
|
|
218 |
#include "tst_qpen.moc"
|