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 |
#include <qgraphicslayoutitem.h>
|
|
45 |
#include <float.h>
|
|
46 |
#include <limits.h>
|
|
47 |
|
|
48 |
class tst_QGraphicsLayoutItem : public QObject {
|
|
49 |
Q_OBJECT
|
|
50 |
|
|
51 |
public slots:
|
|
52 |
void initTestCase();
|
|
53 |
void cleanupTestCase();
|
|
54 |
void init();
|
|
55 |
void cleanup();
|
|
56 |
|
|
57 |
private slots:
|
|
58 |
void qgraphicslayoutitem();
|
|
59 |
|
|
60 |
void contentsRect();
|
|
61 |
void effectiveSizeHint_data();
|
|
62 |
void effectiveSizeHint();
|
|
63 |
void getContentsMargins();
|
|
64 |
void isLayout_data();
|
|
65 |
void isLayout();
|
|
66 |
void maximumSize();
|
|
67 |
void minimumSize();
|
|
68 |
void parentLayoutItem_data();
|
|
69 |
void parentLayoutItem();
|
|
70 |
void preferredSize();
|
|
71 |
void setMaximumSize_data();
|
|
72 |
void setMaximumSize();
|
|
73 |
void setMinimumSize_data();
|
|
74 |
void setMinimumSize();
|
|
75 |
void setPreferredSize_data();
|
|
76 |
void setPreferredSize();
|
|
77 |
void setSizePolicy_data();
|
|
78 |
void setSizePolicy();
|
|
79 |
};
|
|
80 |
|
|
81 |
// Subclass that exposes the protected functions.
|
|
82 |
class SubQGraphicsLayoutItem : public QGraphicsLayoutItem {
|
|
83 |
public:
|
|
84 |
SubQGraphicsLayoutItem(QGraphicsLayoutItem *par = 0, bool layout = false)
|
|
85 |
: QGraphicsLayoutItem(par, layout), updateGeometryCalled(0)
|
|
86 |
{}
|
|
87 |
|
|
88 |
// QGraphicsLayoutItem::geometry is a pure virtual function
|
|
89 |
QRectF geometry() const
|
|
90 |
{ return QRectF(); }
|
|
91 |
|
|
92 |
// QGraphicsLayoutItem::setGeometry is a pure virtual function
|
|
93 |
void setGeometry(QRectF const& rect)
|
|
94 |
{ Q_UNUSED(rect); }
|
|
95 |
|
|
96 |
// QGraphicsLayoutItem::sizeHint is a pure virtual function
|
|
97 |
QSizeF sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const
|
|
98 |
{ Q_UNUSED(which); Q_UNUSED(constraint); return QSizeF(); }
|
|
99 |
|
|
100 |
void updateGeometry()
|
|
101 |
{ updateGeometryCalled++; QGraphicsLayoutItem::updateGeometry(); }
|
|
102 |
int updateGeometryCalled;
|
|
103 |
|
|
104 |
};
|
|
105 |
|
|
106 |
// This will be called before the first test function is executed.
|
|
107 |
// It is only called once.
|
|
108 |
void tst_QGraphicsLayoutItem::initTestCase()
|
|
109 |
{
|
|
110 |
}
|
|
111 |
|
|
112 |
// This will be called after the last test function is executed.
|
|
113 |
// It is only called once.
|
|
114 |
void tst_QGraphicsLayoutItem::cleanupTestCase()
|
|
115 |
{
|
|
116 |
}
|
|
117 |
|
|
118 |
// This will be called before each test function is executed.
|
|
119 |
void tst_QGraphicsLayoutItem::init()
|
|
120 |
{
|
|
121 |
}
|
|
122 |
|
|
123 |
// This will be called after every test function.
|
|
124 |
void tst_QGraphicsLayoutItem::cleanup()
|
|
125 |
{
|
|
126 |
}
|
|
127 |
|
|
128 |
void tst_QGraphicsLayoutItem::qgraphicslayoutitem()
|
|
129 |
{
|
|
130 |
SubQGraphicsLayoutItem layoutItem;
|
|
131 |
layoutItem.contentsRect();
|
|
132 |
layoutItem.effectiveSizeHint(Qt::MinimumSize);
|
|
133 |
layoutItem.geometry();
|
|
134 |
QCOMPARE(layoutItem.isLayout(), false);
|
|
135 |
layoutItem.maximumSize();
|
|
136 |
layoutItem.minimumSize();
|
|
137 |
QCOMPARE(layoutItem.parentLayoutItem(), (QGraphicsLayoutItem*)0);
|
|
138 |
layoutItem.preferredSize();
|
|
139 |
layoutItem.sizePolicy();
|
|
140 |
layoutItem.sizeHint(Qt::MinimumSize);
|
|
141 |
}
|
|
142 |
|
|
143 |
// QRectF contentsRect() const public
|
|
144 |
void tst_QGraphicsLayoutItem::contentsRect()
|
|
145 |
{
|
|
146 |
SubQGraphicsLayoutItem layoutItem;
|
|
147 |
QRectF f = layoutItem.contentsRect();
|
|
148 |
QCOMPARE(f, QRectF(QPoint(), QSizeF(0, 0)));
|
|
149 |
}
|
|
150 |
Q_DECLARE_METATYPE(Qt::SizeHint)
|
|
151 |
void tst_QGraphicsLayoutItem::effectiveSizeHint_data()
|
|
152 |
{
|
|
153 |
QTest::addColumn<Qt::SizeHint>("sizeHint");
|
|
154 |
QTest::addColumn<QSizeF>("constraint");
|
|
155 |
for (int i = 0; i < 15; ++i) {
|
|
156 |
QTestData &data = QTest::newRow(QString("%1").arg(i).toLatin1());
|
|
157 |
switch(i % 5) {
|
|
158 |
case 0: data << Qt::MinimumSize; break;
|
|
159 |
case 1: data << Qt::PreferredSize; break;
|
|
160 |
case 2: data << Qt::MaximumSize; break;
|
|
161 |
case 3: data << Qt::MinimumDescent; break;
|
|
162 |
case 4: data << Qt::NSizeHints; break;
|
|
163 |
}
|
|
164 |
switch(i % 3) {
|
|
165 |
case 0: data << QSizeF(-1, -1); break;
|
|
166 |
case 1: data << QSizeF(0, 0); break;
|
|
167 |
case 2: data << QSizeF(10, 10); break;
|
|
168 |
}
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
// QSizeF effectiveSizeHint(Qt::SizeHint which, QSizeF const& constraint = QSize()) const public
|
|
173 |
void tst_QGraphicsLayoutItem::effectiveSizeHint()
|
|
174 |
{
|
|
175 |
QFETCH(Qt::SizeHint, sizeHint);
|
|
176 |
QFETCH(QSizeF, constraint);
|
|
177 |
SubQGraphicsLayoutItem layoutItem;
|
|
178 |
QSizeF r = layoutItem.effectiveSizeHint(sizeHint, constraint);
|
|
179 |
if (constraint.width() != -1)
|
|
180 |
QCOMPARE(r.width(), constraint.width());
|
|
181 |
if (constraint.height() != -1)
|
|
182 |
QCOMPARE(r.height(), constraint.height());
|
|
183 |
}
|
|
184 |
|
|
185 |
// void getContentsMargins(qreal* left, qreal* top, qreal* right, qreal* bottom) const public
|
|
186 |
void tst_QGraphicsLayoutItem::getContentsMargins()
|
|
187 |
{
|
|
188 |
SubQGraphicsLayoutItem layoutItem;
|
|
189 |
qreal left;
|
|
190 |
qreal top;
|
|
191 |
qreal right;
|
|
192 |
qreal bottom;
|
|
193 |
layoutItem.getContentsMargins(&left, &top, &right, &bottom);
|
|
194 |
QCOMPARE(left, (qreal)0);
|
|
195 |
QCOMPARE(top, (qreal)0);
|
|
196 |
QCOMPARE(right, (qreal)0);
|
|
197 |
QCOMPARE(bottom, (qreal)0);
|
|
198 |
}
|
|
199 |
|
|
200 |
void tst_QGraphicsLayoutItem::isLayout_data()
|
|
201 |
{
|
|
202 |
QTest::addColumn<bool>("isLayout");
|
|
203 |
QTest::newRow("no") << false;
|
|
204 |
QTest::newRow("yes") << true;
|
|
205 |
}
|
|
206 |
|
|
207 |
// bool isLayout() const public
|
|
208 |
void tst_QGraphicsLayoutItem::isLayout()
|
|
209 |
{
|
|
210 |
QFETCH(bool, isLayout);
|
|
211 |
SubQGraphicsLayoutItem layoutItem(0, isLayout);
|
|
212 |
QCOMPARE(layoutItem.isLayout(), isLayout);
|
|
213 |
}
|
|
214 |
|
|
215 |
// QSizeF maximumSize() const public
|
|
216 |
void tst_QGraphicsLayoutItem::maximumSize()
|
|
217 |
{
|
|
218 |
SubQGraphicsLayoutItem layoutItem;
|
|
219 |
QCOMPARE(layoutItem.maximumSize(), QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
|
220 |
// layoutItem.effectiveSizeHint(Qt::MaximumSize);
|
|
221 |
}
|
|
222 |
|
|
223 |
// QSizeF minimumSize() const public
|
|
224 |
void tst_QGraphicsLayoutItem::minimumSize()
|
|
225 |
{
|
|
226 |
SubQGraphicsLayoutItem layoutItem;
|
|
227 |
QCOMPARE(layoutItem.minimumSize(), QSizeF(0, 0));
|
|
228 |
// layoutItem.effectiveSizeHint(Qt::MinimumSize);
|
|
229 |
}
|
|
230 |
|
|
231 |
void tst_QGraphicsLayoutItem::parentLayoutItem_data()
|
|
232 |
{
|
|
233 |
QTest::addColumn<bool>("parent");
|
|
234 |
QTest::newRow("no") << false;
|
|
235 |
QTest::newRow("yes") << true;
|
|
236 |
}
|
|
237 |
|
|
238 |
// QGraphicsLayoutItem* parentLayoutItem() const public
|
|
239 |
void tst_QGraphicsLayoutItem::parentLayoutItem()
|
|
240 |
{
|
|
241 |
QFETCH(bool, parent);
|
|
242 |
SubQGraphicsLayoutItem parentLayout;
|
|
243 |
SubQGraphicsLayoutItem layoutItem(parent ? &parentLayout : 0);
|
|
244 |
QCOMPARE(layoutItem.parentLayoutItem(), static_cast<QGraphicsLayoutItem*>( parent ? &parentLayout : 0));
|
|
245 |
}
|
|
246 |
|
|
247 |
// QSizeF preferredSize() const public
|
|
248 |
void tst_QGraphicsLayoutItem::preferredSize()
|
|
249 |
{
|
|
250 |
SubQGraphicsLayoutItem layoutItem;
|
|
251 |
QCOMPARE(layoutItem.preferredSize(), QSizeF(0, 0));
|
|
252 |
// layoutItem.effectiveSizeHint(Qt::PreferredSize));
|
|
253 |
}
|
|
254 |
|
|
255 |
void tst_QGraphicsLayoutItem::setMaximumSize_data()
|
|
256 |
{
|
|
257 |
QTest::addColumn<QSizeF>("size");
|
|
258 |
QTest::addColumn<QSizeF>("outputSize");
|
|
259 |
QTest::newRow("-1") << QSizeF(-1, -1) << QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
|
260 |
QTest::newRow("0") << QSizeF(0, 0) << QSizeF(0, 0);
|
|
261 |
QTest::newRow("10") << QSizeF(10, 10) << QSizeF(10, 10);
|
|
262 |
}
|
|
263 |
|
|
264 |
// void setMaximumSize(QSizeF const& size) public
|
|
265 |
void tst_QGraphicsLayoutItem::setMaximumSize()
|
|
266 |
{
|
|
267 |
QFETCH(QSizeF, size);
|
|
268 |
QFETCH(QSizeF, outputSize);
|
|
269 |
SubQGraphicsLayoutItem layoutItem;
|
|
270 |
QSizeF oldSize = layoutItem.maximumSize();
|
|
271 |
layoutItem.setMaximumSize(size);
|
|
272 |
if (size.isValid())
|
|
273 |
QCOMPARE(layoutItem.updateGeometryCalled, (oldSize == size) ? 0 : 1);
|
|
274 |
else
|
|
275 |
QVERIFY(!layoutItem.updateGeometryCalled);
|
|
276 |
layoutItem.setMinimumSize(1, 1);
|
|
277 |
|
|
278 |
QVERIFY(layoutItem.maximumSize().width() <= outputSize.width());
|
|
279 |
QVERIFY(layoutItem.maximumSize().height() <= outputSize.height());
|
|
280 |
QVERIFY(layoutItem.minimumSize().width() <= outputSize.width());
|
|
281 |
QVERIFY(layoutItem.minimumSize().height() <= outputSize.height());
|
|
282 |
QVERIFY(layoutItem.preferredSize().width() <= outputSize.width());
|
|
283 |
QVERIFY(layoutItem.preferredSize().height() <= outputSize.height());
|
|
284 |
}
|
|
285 |
|
|
286 |
void tst_QGraphicsLayoutItem::setMinimumSize_data()
|
|
287 |
{
|
|
288 |
QTest::addColumn<QSizeF>("size");
|
|
289 |
QTest::addColumn<QSizeF>("outputSize");
|
|
290 |
QTest::newRow("-1") << QSizeF(-1, -1) << QSizeF(0, 0);
|
|
291 |
QTest::newRow("0") << QSizeF(0, 0) << QSizeF(0, 0);
|
|
292 |
QTest::newRow("10") << QSizeF(10, 10) << QSizeF(10, 10);
|
|
293 |
}
|
|
294 |
|
|
295 |
// void setMinimumSize(QSizeF const& size) public
|
|
296 |
void tst_QGraphicsLayoutItem::setMinimumSize()
|
|
297 |
{
|
|
298 |
QFETCH(QSizeF, size);
|
|
299 |
QFETCH(QSizeF, outputSize);
|
|
300 |
SubQGraphicsLayoutItem layoutItem;
|
|
301 |
QSizeF oldSize = layoutItem.minimumSize();
|
|
302 |
|
|
303 |
layoutItem.setMinimumSize(size);
|
|
304 |
if (size.isValid()) {
|
|
305 |
QEXPECT_FAIL("0", "updateGeometry() is called when it doesn't have to be.", Continue);
|
|
306 |
QCOMPARE(layoutItem.updateGeometryCalled, (oldSize == size) ? 0 : 1);
|
|
307 |
} else {
|
|
308 |
QVERIFY(!layoutItem.updateGeometryCalled);
|
|
309 |
}
|
|
310 |
layoutItem.setMaximumSize(5, 5);
|
|
311 |
QEXPECT_FAIL("10", "layoutItem.maximumSize().width() < size.width()", Abort);
|
|
312 |
QVERIFY(layoutItem.maximumSize().width() >= size.width());
|
|
313 |
QVERIFY(layoutItem.maximumSize().height() >= size.height());
|
|
314 |
QVERIFY(layoutItem.minimumSize().width() >= size.width());
|
|
315 |
QVERIFY(layoutItem.minimumSize().height() >= size.height());
|
|
316 |
QVERIFY(layoutItem.preferredSize().width() >= size.width());
|
|
317 |
QVERIFY(layoutItem.preferredSize().height() >= size.height());
|
|
318 |
}
|
|
319 |
|
|
320 |
void tst_QGraphicsLayoutItem::setPreferredSize_data()
|
|
321 |
{
|
|
322 |
QTest::addColumn<QSizeF>("size");
|
|
323 |
QTest::newRow("-1") << QSizeF(-1, -1);
|
|
324 |
QTest::newRow("0") << QSizeF(0, 0);
|
|
325 |
QTest::newRow("10") << QSizeF(10, 10);
|
|
326 |
}
|
|
327 |
|
|
328 |
// void setPreferredSize(QSizeF const& size) public
|
|
329 |
void tst_QGraphicsLayoutItem::setPreferredSize()
|
|
330 |
{
|
|
331 |
QFETCH(QSizeF, size);
|
|
332 |
SubQGraphicsLayoutItem layoutItem;
|
|
333 |
QSizeF oldSize = layoutItem.preferredSize();
|
|
334 |
layoutItem.setPreferredSize(size);
|
|
335 |
if (size.isValid())
|
|
336 |
QCOMPARE(layoutItem.preferredSize(), size);
|
|
337 |
|
|
338 |
if (size.isValid()) {
|
|
339 |
QEXPECT_FAIL("0", "updateGeometry() is called when it doesn't have to be.", Continue);
|
|
340 |
QCOMPARE(layoutItem.updateGeometryCalled, (oldSize == size) ? 0 : 1);
|
|
341 |
} else {
|
|
342 |
QVERIFY(!layoutItem.updateGeometryCalled);
|
|
343 |
}
|
|
344 |
}
|
|
345 |
|
|
346 |
void tst_QGraphicsLayoutItem::setSizePolicy_data()
|
|
347 |
{
|
|
348 |
QTest::addColumn<QSizePolicy>("policy");
|
|
349 |
QTest::newRow("default") << QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, QSizePolicy::DefaultType);
|
|
350 |
QTest::newRow("rand") << QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
|
351 |
}
|
|
352 |
|
|
353 |
// void setSizePolicy(QSizePolicy const& policy) public
|
|
354 |
void tst_QGraphicsLayoutItem::setSizePolicy()
|
|
355 |
{
|
|
356 |
QFETCH(QSizePolicy, policy);
|
|
357 |
SubQGraphicsLayoutItem layoutItem;
|
|
358 |
QSizePolicy defaultPolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType);
|
|
359 |
QCOMPARE(layoutItem.sizePolicy(), defaultPolicy);
|
|
360 |
|
|
361 |
layoutItem.setSizePolicy(policy);
|
|
362 |
QCOMPARE(layoutItem.sizePolicy(), policy);
|
|
363 |
QCOMPARE(layoutItem.updateGeometryCalled, (defaultPolicy == policy) ? 0 : 1);
|
|
364 |
}
|
|
365 |
|
|
366 |
QTEST_MAIN(tst_QGraphicsLayoutItem)
|
|
367 |
#include "tst_qgraphicslayoutitem.moc"
|
|
368 |
|