author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 <qgraphicsitem.h> |
|
45 |
#include <qgraphicsscene.h> |
|
46 |
#include <qgraphicssceneevent.h> |
|
47 |
#include <qgraphicsview.h> |
|
48 |
#include <qstyleoption.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
#include <private/qobject_p.h> |
0 | 50 |
#include "../../shared/util.h" |
51 |
||
52 |
class tst_QGraphicsObject : public QObject { |
|
53 |
Q_OBJECT |
|
54 |
||
55 |
public slots: |
|
56 |
void initTestCase(); |
|
57 |
void cleanupTestCase(); |
|
58 |
void init(); |
|
59 |
void cleanup(); |
|
60 |
||
61 |
private slots: |
|
62 |
void pos(); |
|
63 |
void x(); |
|
64 |
void y(); |
|
65 |
void z(); |
|
66 |
void opacity(); |
|
67 |
void enabled(); |
|
68 |
void visible(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
void deleted(); |
0 | 70 |
}; |
71 |
||
72 |
||
73 |
// This will be called before the first test function is executed. |
|
74 |
// It is only called once. |
|
75 |
void tst_QGraphicsObject::initTestCase() |
|
76 |
{ |
|
77 |
} |
|
78 |
||
79 |
// This will be called after the last test function is executed. |
|
80 |
// It is only called once. |
|
81 |
void tst_QGraphicsObject::cleanupTestCase() |
|
82 |
{ |
|
83 |
} |
|
84 |
||
85 |
// This will be called before each test function is executed. |
|
86 |
void tst_QGraphicsObject::init() |
|
87 |
{ |
|
88 |
} |
|
89 |
||
90 |
// This will be called after every test function. |
|
91 |
void tst_QGraphicsObject::cleanup() |
|
92 |
{ |
|
93 |
} |
|
94 |
||
95 |
||
96 |
class MyGraphicsObject : public QGraphicsObject |
|
97 |
{ |
|
98 |
public: |
|
99 |
MyGraphicsObject() : QGraphicsObject() {} |
|
100 |
virtual QRectF boundingRect() const { return QRectF(); } |
|
101 |
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} |
|
102 |
}; |
|
103 |
||
104 |
void tst_QGraphicsObject::pos() |
|
105 |
{ |
|
106 |
MyGraphicsObject object; |
|
107 |
QSignalSpy xSpy(&object, SIGNAL(xChanged())); |
|
108 |
QSignalSpy ySpy(&object, SIGNAL(yChanged())); |
|
109 |
QVERIFY(object.pos() == QPointF(0, 0)); |
|
110 |
object.setPos(10, 10); |
|
111 |
QCOMPARE(xSpy.count(), 1); |
|
112 |
QCOMPARE(ySpy.count(), 1); |
|
113 |
||
114 |
QVERIFY(object.pos() == QPointF(10,10)); |
|
115 |
||
116 |
object.setPos(10, 10); |
|
117 |
QCOMPARE(xSpy.count(), 1); |
|
118 |
QCOMPARE(ySpy.count(), 1); |
|
119 |
||
120 |
object.setProperty("pos", QPointF(0, 0)); |
|
121 |
QCOMPARE(xSpy.count(), 2); |
|
122 |
QCOMPARE(ySpy.count(), 2); |
|
123 |
QVERIFY(object.property("pos") == QPointF(0,0)); |
|
124 |
||
125 |
object.setProperty("pos", QPointF(10, 0)); |
|
126 |
QCOMPARE(xSpy.count(), 3); |
|
127 |
QCOMPARE(ySpy.count(), 2); |
|
128 |
QVERIFY(object.property("pos") == QPointF(10,0)); |
|
129 |
||
130 |
object.setProperty("pos", QPointF(10, 10)); |
|
131 |
QCOMPARE(xSpy.count(), 3); |
|
132 |
QCOMPARE(ySpy.count(), 3); |
|
133 |
QVERIFY(object.property("pos") == QPointF(10, 10)); |
|
134 |
} |
|
135 |
||
136 |
void tst_QGraphicsObject::x() |
|
137 |
{ |
|
138 |
MyGraphicsObject object; |
|
139 |
QSignalSpy xSpy(&object, SIGNAL(xChanged())); |
|
140 |
QSignalSpy ySpy(&object, SIGNAL(yChanged())); |
|
141 |
QVERIFY(object.pos() == QPointF(0, 0)); |
|
142 |
object.setX(10); |
|
143 |
QCOMPARE(xSpy.count(), 1); |
|
144 |
QCOMPARE(ySpy.count(), 0); |
|
145 |
||
146 |
QVERIFY(object.pos() == QPointF(10, 0)); |
|
147 |
QVERIFY(object.x() == 10); |
|
148 |
||
149 |
object.setX(10); |
|
150 |
QCOMPARE(xSpy.count(), 1); |
|
151 |
QCOMPARE(ySpy.count(), 0); |
|
152 |
||
153 |
object.setProperty("x", 0); |
|
154 |
QCOMPARE(xSpy.count(), 2); |
|
155 |
QCOMPARE(ySpy.count(), 0); |
|
156 |
QVERIFY(object.property("x") == 0); |
|
157 |
} |
|
158 |
||
159 |
void tst_QGraphicsObject::y() |
|
160 |
{ |
|
161 |
MyGraphicsObject object; |
|
162 |
QSignalSpy xSpy(&object, SIGNAL(xChanged())); |
|
163 |
QSignalSpy ySpy(&object, SIGNAL(yChanged())); |
|
164 |
QVERIFY(object.pos() == QPointF(0, 0)); |
|
165 |
object.setY(10); |
|
166 |
QCOMPARE(xSpy.count(), 0); |
|
167 |
QCOMPARE(ySpy.count(), 1); |
|
168 |
||
169 |
QVERIFY(object.pos() == QPointF(0, 10)); |
|
170 |
QVERIFY(object.y() == 10); |
|
171 |
||
172 |
object.setY(10); |
|
173 |
QCOMPARE(xSpy.count(), 0); |
|
174 |
QCOMPARE(ySpy.count(), 1); |
|
175 |
||
176 |
object.setProperty("y", 0); |
|
177 |
QCOMPARE(xSpy.count(), 0); |
|
178 |
QCOMPARE(ySpy.count(), 2); |
|
179 |
QVERIFY(object.property("y") == 0); |
|
180 |
} |
|
181 |
||
182 |
void tst_QGraphicsObject::z() |
|
183 |
{ |
|
184 |
MyGraphicsObject object; |
|
185 |
QSignalSpy zSpy(&object, SIGNAL(zChanged())); |
|
186 |
QVERIFY(object.zValue() == 0); |
|
187 |
object.setZValue(10); |
|
188 |
QCOMPARE(zSpy.count(), 1); |
|
189 |
||
190 |
QVERIFY(object.zValue() == 10); |
|
191 |
||
192 |
object.setZValue(10); |
|
193 |
QCOMPARE(zSpy.count(), 1); |
|
194 |
||
195 |
object.setProperty("z", 0); |
|
196 |
QCOMPARE(zSpy.count(), 2); |
|
197 |
QVERIFY(object.property("z") == 0); |
|
198 |
} |
|
199 |
||
200 |
void tst_QGraphicsObject::opacity() |
|
201 |
{ |
|
202 |
MyGraphicsObject object; |
|
203 |
QSignalSpy spy(&object, SIGNAL(opacityChanged())); |
|
204 |
QVERIFY(object.opacity() == 1.); |
|
205 |
object.setOpacity(0); |
|
206 |
QCOMPARE(spy.count(), 1); |
|
207 |
||
208 |
QVERIFY(object.opacity() == 0.); |
|
209 |
||
210 |
object.setOpacity(0); |
|
211 |
QCOMPARE(spy.count(), 1); |
|
212 |
||
213 |
object.setProperty("opacity", .5); |
|
214 |
QCOMPARE(spy.count(), 2); |
|
215 |
QVERIFY(object.property("opacity") == .5); |
|
216 |
} |
|
217 |
||
218 |
void tst_QGraphicsObject::enabled() |
|
219 |
{ |
|
220 |
MyGraphicsObject object; |
|
221 |
QSignalSpy spy(&object, SIGNAL(enabledChanged())); |
|
222 |
QVERIFY(object.isEnabled() == true); |
|
223 |
object.setEnabled(false); |
|
224 |
QCOMPARE(spy.count(), 1); |
|
225 |
||
226 |
QVERIFY(object.isEnabled() == false); |
|
227 |
||
228 |
object.setEnabled(false); |
|
229 |
QCOMPARE(spy.count(), 1); |
|
230 |
||
231 |
object.setProperty("enabled", true); |
|
232 |
QCOMPARE(spy.count(), 2); |
|
233 |
QVERIFY(object.property("enabled") == true); |
|
234 |
} |
|
235 |
||
236 |
void tst_QGraphicsObject::visible() |
|
237 |
{ |
|
238 |
MyGraphicsObject object; |
|
239 |
QSignalSpy spy(&object, SIGNAL(visibleChanged())); |
|
240 |
QVERIFY(object.isVisible() == true); |
|
241 |
object.setVisible(false); |
|
242 |
QCOMPARE(spy.count(), 1); |
|
243 |
||
244 |
QVERIFY(object.isVisible() == false); |
|
245 |
||
246 |
object.setVisible(false); |
|
247 |
QCOMPARE(spy.count(), 1); |
|
248 |
||
249 |
object.setProperty("visible", true); |
|
250 |
QCOMPARE(spy.count(), 2); |
|
251 |
QVERIFY(object.property("visible") == true); |
|
252 |
} |
|
253 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
class DeleteTester : public QGraphicsObject |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
DeleteTester(bool *w, bool *pw, QGraphicsItem *parent = 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
: QGraphicsObject(parent), wasDeleted(w), parentWasDeleted(pw) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
{ } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
~DeleteTester() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
*wasDeleted = QObjectPrivate::get(this)->wasDeleted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
if (QGraphicsItem *p = parentItem()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
if (QGraphicsObject *o = p->toGraphicsObject()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
*parentWasDeleted = QObjectPrivate::get(o)->wasDeleted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
{ } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
QRectF boundingRect() const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
{ return QRectF(); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
bool *wasDeleted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
bool *parentWasDeleted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
void tst_QGraphicsObject::deleted() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
bool item1_parentWasDeleted = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
bool item1_wasDeleted = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
bool item2_parentWasDeleted = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
bool item2_wasDeleted = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
DeleteTester *item1 = new DeleteTester(&item1_wasDeleted, &item1_parentWasDeleted); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
DeleteTester *item2 = new DeleteTester(&item2_wasDeleted, &item2_parentWasDeleted, item1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
delete item1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
QVERIFY(!item1_wasDeleted); // destructor not called yet |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
QVERIFY(!item1_parentWasDeleted); // no parent |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
QVERIFY(!item2_wasDeleted); // destructor not called yet |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
QVERIFY(item2_parentWasDeleted); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
} |
0 | 294 |
|
295 |
QTEST_MAIN(tst_QGraphicsObject) |
|
296 |
#include "tst_qgraphicsobject.moc" |
|
297 |