|
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 <qgraphicsitem.h> |
|
45 #include <qgraphicsscene.h> |
|
46 #include <qgraphicssceneevent.h> |
|
47 #include <qgraphicsview.h> |
|
48 #include <qstyleoption.h> |
|
49 #include "../../shared/util.h" |
|
50 |
|
51 class tst_QGraphicsObject : public QObject { |
|
52 Q_OBJECT |
|
53 |
|
54 public slots: |
|
55 void initTestCase(); |
|
56 void cleanupTestCase(); |
|
57 void init(); |
|
58 void cleanup(); |
|
59 |
|
60 private slots: |
|
61 void pos(); |
|
62 void x(); |
|
63 void y(); |
|
64 void z(); |
|
65 void opacity(); |
|
66 void enabled(); |
|
67 void visible(); |
|
68 }; |
|
69 |
|
70 |
|
71 // This will be called before the first test function is executed. |
|
72 // It is only called once. |
|
73 void tst_QGraphicsObject::initTestCase() |
|
74 { |
|
75 } |
|
76 |
|
77 // This will be called after the last test function is executed. |
|
78 // It is only called once. |
|
79 void tst_QGraphicsObject::cleanupTestCase() |
|
80 { |
|
81 } |
|
82 |
|
83 // This will be called before each test function is executed. |
|
84 void tst_QGraphicsObject::init() |
|
85 { |
|
86 } |
|
87 |
|
88 // This will be called after every test function. |
|
89 void tst_QGraphicsObject::cleanup() |
|
90 { |
|
91 } |
|
92 |
|
93 |
|
94 class MyGraphicsObject : public QGraphicsObject |
|
95 { |
|
96 public: |
|
97 MyGraphicsObject() : QGraphicsObject() {} |
|
98 virtual QRectF boundingRect() const { return QRectF(); } |
|
99 virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} |
|
100 }; |
|
101 |
|
102 void tst_QGraphicsObject::pos() |
|
103 { |
|
104 MyGraphicsObject object; |
|
105 QSignalSpy xSpy(&object, SIGNAL(xChanged())); |
|
106 QSignalSpy ySpy(&object, SIGNAL(yChanged())); |
|
107 QVERIFY(object.pos() == QPointF(0, 0)); |
|
108 object.setPos(10, 10); |
|
109 QCOMPARE(xSpy.count(), 1); |
|
110 QCOMPARE(ySpy.count(), 1); |
|
111 |
|
112 QVERIFY(object.pos() == QPointF(10,10)); |
|
113 |
|
114 object.setPos(10, 10); |
|
115 QCOMPARE(xSpy.count(), 1); |
|
116 QCOMPARE(ySpy.count(), 1); |
|
117 |
|
118 object.setProperty("pos", QPointF(0, 0)); |
|
119 QCOMPARE(xSpy.count(), 2); |
|
120 QCOMPARE(ySpy.count(), 2); |
|
121 QVERIFY(object.property("pos") == QPointF(0,0)); |
|
122 |
|
123 object.setProperty("pos", QPointF(10, 0)); |
|
124 QCOMPARE(xSpy.count(), 3); |
|
125 QCOMPARE(ySpy.count(), 2); |
|
126 QVERIFY(object.property("pos") == QPointF(10,0)); |
|
127 |
|
128 object.setProperty("pos", QPointF(10, 10)); |
|
129 QCOMPARE(xSpy.count(), 3); |
|
130 QCOMPARE(ySpy.count(), 3); |
|
131 QVERIFY(object.property("pos") == QPointF(10, 10)); |
|
132 } |
|
133 |
|
134 void tst_QGraphicsObject::x() |
|
135 { |
|
136 MyGraphicsObject object; |
|
137 QSignalSpy xSpy(&object, SIGNAL(xChanged())); |
|
138 QSignalSpy ySpy(&object, SIGNAL(yChanged())); |
|
139 QVERIFY(object.pos() == QPointF(0, 0)); |
|
140 object.setX(10); |
|
141 QCOMPARE(xSpy.count(), 1); |
|
142 QCOMPARE(ySpy.count(), 0); |
|
143 |
|
144 QVERIFY(object.pos() == QPointF(10, 0)); |
|
145 QVERIFY(object.x() == 10); |
|
146 |
|
147 object.setX(10); |
|
148 QCOMPARE(xSpy.count(), 1); |
|
149 QCOMPARE(ySpy.count(), 0); |
|
150 |
|
151 object.setProperty("x", 0); |
|
152 QCOMPARE(xSpy.count(), 2); |
|
153 QCOMPARE(ySpy.count(), 0); |
|
154 QVERIFY(object.property("x") == 0); |
|
155 } |
|
156 |
|
157 void tst_QGraphicsObject::y() |
|
158 { |
|
159 MyGraphicsObject object; |
|
160 QSignalSpy xSpy(&object, SIGNAL(xChanged())); |
|
161 QSignalSpy ySpy(&object, SIGNAL(yChanged())); |
|
162 QVERIFY(object.pos() == QPointF(0, 0)); |
|
163 object.setY(10); |
|
164 QCOMPARE(xSpy.count(), 0); |
|
165 QCOMPARE(ySpy.count(), 1); |
|
166 |
|
167 QVERIFY(object.pos() == QPointF(0, 10)); |
|
168 QVERIFY(object.y() == 10); |
|
169 |
|
170 object.setY(10); |
|
171 QCOMPARE(xSpy.count(), 0); |
|
172 QCOMPARE(ySpy.count(), 1); |
|
173 |
|
174 object.setProperty("y", 0); |
|
175 QCOMPARE(xSpy.count(), 0); |
|
176 QCOMPARE(ySpy.count(), 2); |
|
177 QVERIFY(object.property("y") == 0); |
|
178 } |
|
179 |
|
180 void tst_QGraphicsObject::z() |
|
181 { |
|
182 MyGraphicsObject object; |
|
183 QSignalSpy zSpy(&object, SIGNAL(zChanged())); |
|
184 QVERIFY(object.zValue() == 0); |
|
185 object.setZValue(10); |
|
186 QCOMPARE(zSpy.count(), 1); |
|
187 |
|
188 QVERIFY(object.zValue() == 10); |
|
189 |
|
190 object.setZValue(10); |
|
191 QCOMPARE(zSpy.count(), 1); |
|
192 |
|
193 object.setProperty("z", 0); |
|
194 QCOMPARE(zSpy.count(), 2); |
|
195 QVERIFY(object.property("z") == 0); |
|
196 } |
|
197 |
|
198 void tst_QGraphicsObject::opacity() |
|
199 { |
|
200 MyGraphicsObject object; |
|
201 QSignalSpy spy(&object, SIGNAL(opacityChanged())); |
|
202 QVERIFY(object.opacity() == 1.); |
|
203 object.setOpacity(0); |
|
204 QCOMPARE(spy.count(), 1); |
|
205 |
|
206 QVERIFY(object.opacity() == 0.); |
|
207 |
|
208 object.setOpacity(0); |
|
209 QCOMPARE(spy.count(), 1); |
|
210 |
|
211 object.setProperty("opacity", .5); |
|
212 QCOMPARE(spy.count(), 2); |
|
213 QVERIFY(object.property("opacity") == .5); |
|
214 } |
|
215 |
|
216 void tst_QGraphicsObject::enabled() |
|
217 { |
|
218 MyGraphicsObject object; |
|
219 QSignalSpy spy(&object, SIGNAL(enabledChanged())); |
|
220 QVERIFY(object.isEnabled() == true); |
|
221 object.setEnabled(false); |
|
222 QCOMPARE(spy.count(), 1); |
|
223 |
|
224 QVERIFY(object.isEnabled() == false); |
|
225 |
|
226 object.setEnabled(false); |
|
227 QCOMPARE(spy.count(), 1); |
|
228 |
|
229 object.setProperty("enabled", true); |
|
230 QCOMPARE(spy.count(), 2); |
|
231 QVERIFY(object.property("enabled") == true); |
|
232 } |
|
233 |
|
234 void tst_QGraphicsObject::visible() |
|
235 { |
|
236 MyGraphicsObject object; |
|
237 QSignalSpy spy(&object, SIGNAL(visibleChanged())); |
|
238 QVERIFY(object.isVisible() == true); |
|
239 object.setVisible(false); |
|
240 QCOMPARE(spy.count(), 1); |
|
241 |
|
242 QVERIFY(object.isVisible() == false); |
|
243 |
|
244 object.setVisible(false); |
|
245 QCOMPARE(spy.count(), 1); |
|
246 |
|
247 object.setProperty("visible", true); |
|
248 QCOMPARE(spy.count(), 2); |
|
249 QVERIFY(object.property("visible") == true); |
|
250 } |
|
251 |
|
252 |
|
253 QTEST_MAIN(tst_QGraphicsObject) |
|
254 #include "tst_qgraphicsobject.moc" |
|
255 |