author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
child 7 | 3f74d0d4af4c |
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 |
#define QT3_SUPPORT |
|
44 |
#include <QtTest/QtTest> |
|
45 |
||
46 |
||
47 |
#include <qcoreapplication.h> |
|
48 |
||
49 |
#include <qpointer.h> |
|
50 |
#include <qtimer.h> |
|
51 |
#include <qregexp.h> |
|
52 |
#include <qmetaobject.h> |
|
53 |
#include <qvariant.h> |
|
54 |
||
55 |
#include <QTcpServer> |
|
56 |
#include <QTcpSocket> |
|
57 |
#include <QThread> |
|
58 |
#include <QMutex> |
|
59 |
#include <QWaitCondition> |
|
60 |
#include <QProcess> |
|
61 |
||
62 |
#include "qobject.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
#ifdef QT_BUILD_INTERNAL |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
#include <private/qobject_p.h> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
|
0 | 67 |
|
68 |
#include <math.h> |
|
69 |
||
70 |
//TESTED_CLASS= |
|
71 |
//TESTED_FILES= |
|
72 |
||
73 |
class tst_QObject : public QObject |
|
74 |
{ |
|
75 |
Q_OBJECT |
|
76 |
||
77 |
public: |
|
78 |
tst_QObject(); |
|
79 |
virtual ~tst_QObject(); |
|
80 |
||
81 |
||
82 |
public slots: |
|
83 |
void initTestCase(); |
|
84 |
void cleanupTestCase(); |
|
85 |
void init(); |
|
86 |
void cleanup(); |
|
87 |
private slots: |
|
88 |
void disconnect(); |
|
89 |
void connectByName(); |
|
90 |
void connectSignalsToSignalsWithDefaultArguments(); |
|
91 |
void receivers(); |
|
92 |
void normalize(); |
|
93 |
void qobject_castTemplate(); |
|
94 |
void findChildren(); |
|
95 |
void connectDisconnectNotify_data(); |
|
96 |
void connectDisconnectNotify(); |
|
97 |
void emitInDefinedOrder(); |
|
98 |
void customTypes(); |
|
99 |
void streamCustomTypes(); |
|
100 |
void metamethod(); |
|
101 |
void namespaces(); |
|
102 |
void threadSignalEmissionCrash(); |
|
103 |
void thread(); |
|
104 |
void thread0(); |
|
105 |
void moveToThread(); |
|
106 |
void sender(); |
|
107 |
void declareInterface(); |
|
108 |
void qpointerResetBeforeDestroyedSignal(); |
|
109 |
void testUserData(); |
|
110 |
void childDeletesItsSibling(); |
|
111 |
void dynamicProperties(); |
|
112 |
void floatProperty(); |
|
113 |
void qrealProperty(); |
|
114 |
void property(); |
|
115 |
void recursiveSignalEmission(); |
|
116 |
void blockingQueuedConnection(); |
|
117 |
void compatibilityChildInsertedEvents(); |
|
118 |
void installEventFilter(); |
|
119 |
void deleteSelfInSlot(); |
|
120 |
void disconnectSelfInSlotAndDeleteAfterEmit(); |
|
121 |
void dumpObjectInfo(); |
|
122 |
void connectToSender(); |
|
123 |
void qobjectConstCast(); |
|
124 |
void uniqConnection(); |
|
125 |
void interfaceIid(); |
|
126 |
void deleteQObjectWhenDeletingEvent(); |
|
127 |
void overloads(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
void isSignalConnected(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
void qMetaObjectConnect(); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
130 |
void qMetaObjectDisconnectOne(); |
0 | 131 |
protected: |
132 |
}; |
|
133 |
||
134 |
tst_QObject::tst_QObject() |
|
135 |
{ |
|
136 |
||
137 |
} |
|
138 |
||
139 |
tst_QObject::~tst_QObject() |
|
140 |
{ |
|
141 |
||
142 |
} |
|
143 |
||
144 |
void tst_QObject::initTestCase() |
|
145 |
{ |
|
146 |
} |
|
147 |
||
148 |
void tst_QObject::cleanupTestCase() |
|
149 |
{ |
|
150 |
} |
|
151 |
||
152 |
void tst_QObject::init() |
|
153 |
{ |
|
154 |
} |
|
155 |
||
156 |
void tst_QObject::cleanup() |
|
157 |
{ |
|
158 |
} |
|
159 |
||
160 |
class SenderObject : public QObject |
|
161 |
{ |
|
162 |
Q_OBJECT |
|
163 |
||
164 |
public: |
|
165 |
SenderObject() : recursionCount(0) {} |
|
166 |
||
167 |
void emitSignal1AfterRecursion() |
|
168 |
{ |
|
169 |
if (recursionCount++ < 100) |
|
170 |
emitSignal1AfterRecursion(); |
|
171 |
else |
|
172 |
emitSignal1(); |
|
173 |
} |
|
174 |
||
175 |
void emitSignal1() { emit signal1(); } |
|
176 |
void emitSignal2() { emit signal2(); } |
|
177 |
void emitSignal3() { emit signal3(); } |
|
178 |
void emitSignal4() { emit signal4(); } |
|
179 |
||
180 |
signals: |
|
181 |
void signal1(); |
|
182 |
void signal2(); |
|
183 |
void signal3(); |
|
184 |
void signal4(); |
|
185 |
QT_MOC_COMPAT void signal5(); |
|
186 |
||
187 |
public slots: |
|
188 |
void aPublicSlot(){} |
|
189 |
||
190 |
public: |
|
191 |
Q_INVOKABLE void invoke1(){} |
|
192 |
Q_SCRIPTABLE void sinvoke1(){} |
|
193 |
protected: |
|
194 |
Q_INVOKABLE QT_MOC_COMPAT void invoke2(){} |
|
195 |
Q_INVOKABLE QT_MOC_COMPAT void invoke2(int){} |
|
196 |
Q_SCRIPTABLE QT_MOC_COMPAT void sinvoke2(){} |
|
197 |
private: |
|
198 |
Q_INVOKABLE void invoke3(int hinz = 0, int kunz = 0){Q_UNUSED(hinz) Q_UNUSED(kunz)} |
|
199 |
Q_SCRIPTABLE void sinvoke3(){} |
|
200 |
||
201 |
int recursionCount; |
|
202 |
}; |
|
203 |
||
204 |
class ReceiverObject : public QObject |
|
205 |
{ |
|
206 |
Q_OBJECT |
|
207 |
||
208 |
public: |
|
209 |
ReceiverObject() : sequence_slot1( 0 ), |
|
210 |
sequence_slot2( 0 ), |
|
211 |
sequence_slot3( 0 ), |
|
212 |
sequence_slot4( 0 ) {} |
|
213 |
||
214 |
void reset() { |
|
215 |
sequence_slot4 = 0; |
|
216 |
sequence_slot3 = 0; |
|
217 |
sequence_slot2 = 0; |
|
218 |
sequence_slot1 = 0; |
|
219 |
count_slot1 = 0; |
|
220 |
count_slot2 = 0; |
|
221 |
count_slot3 = 0; |
|
222 |
count_slot4 = 0; |
|
223 |
} |
|
224 |
||
225 |
int sequence_slot1; |
|
226 |
int sequence_slot2; |
|
227 |
int sequence_slot3; |
|
228 |
int sequence_slot4; |
|
229 |
int count_slot1; |
|
230 |
int count_slot2; |
|
231 |
int count_slot3; |
|
232 |
int count_slot4; |
|
233 |
||
234 |
bool called(int slot) { |
|
235 |
switch (slot) { |
|
236 |
case 1: return sequence_slot1; |
|
237 |
case 2: return sequence_slot2; |
|
238 |
case 3: return sequence_slot3; |
|
239 |
case 4: return sequence_slot4; |
|
240 |
default: return false; |
|
241 |
} |
|
242 |
} |
|
243 |
||
244 |
static int sequence; |
|
245 |
||
246 |
public slots: |
|
247 |
void slot1() { sequence_slot1 = ++sequence; count_slot1++; } |
|
248 |
void slot2() { sequence_slot2 = ++sequence; count_slot2++; } |
|
249 |
void slot3() { sequence_slot3 = ++sequence; count_slot3++; } |
|
250 |
void slot4() { sequence_slot4 = ++sequence; count_slot4++; } |
|
251 |
||
252 |
}; |
|
253 |
||
254 |
int ReceiverObject::sequence = 0; |
|
255 |
||
256 |
void tst_QObject::disconnect() |
|
257 |
{ |
|
258 |
SenderObject *s = new SenderObject; |
|
259 |
ReceiverObject *r1 = new ReceiverObject; |
|
260 |
ReceiverObject *r2 = new ReceiverObject; |
|
261 |
||
262 |
connect( s, SIGNAL( signal1() ), r1, SLOT( slot1() ) ); |
|
263 |
||
264 |
connect( s, SIGNAL( signal2() ), r1, SLOT( slot2() ) ); |
|
265 |
connect( s, SIGNAL( signal3() ), r1, SLOT( slot3() ) ); |
|
266 |
connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) ); |
|
267 |
||
268 |
s->emitSignal1(); |
|
269 |
s->emitSignal2(); |
|
270 |
s->emitSignal3(); |
|
271 |
s->emitSignal4(); |
|
272 |
||
273 |
QCOMPARE( r1->called(1), TRUE ); |
|
274 |
QCOMPARE( r1->called(2), TRUE ); |
|
275 |
QCOMPARE( r1->called(3), TRUE ); |
|
276 |
QCOMPARE( r1->called(4), TRUE ); |
|
277 |
r1->reset(); |
|
278 |
||
279 |
// usual disconnect with all parameters given |
|
280 |
bool ret = QObject::disconnect( s, SIGNAL( signal1() ), r1, SLOT( slot1() ) ); |
|
281 |
||
282 |
s->emitSignal1(); |
|
283 |
||
284 |
QCOMPARE( r1->called(1), FALSE ); |
|
285 |
r1->reset(); |
|
286 |
||
287 |
QCOMPARE( ret, TRUE ); |
|
288 |
ret = QObject::disconnect( s, SIGNAL( signal1() ), r1, SLOT( slot1() ) ); |
|
289 |
QCOMPARE( ret, FALSE ); |
|
290 |
||
291 |
// disconnect all signals from s from all slots from r1 |
|
292 |
QObject::disconnect( s, 0, r1, 0 ); |
|
293 |
||
294 |
s->emitSignal2(); |
|
295 |
s->emitSignal3(); |
|
296 |
s->emitSignal4(); |
|
297 |
||
298 |
QCOMPARE( r1->called(2), FALSE ); |
|
299 |
QCOMPARE( r1->called(3), FALSE ); |
|
300 |
QCOMPARE( r1->called(4), FALSE ); |
|
301 |
r1->reset(); |
|
302 |
||
303 |
connect( s, SIGNAL( signal1() ), r1, SLOT( slot1() ) ); |
|
304 |
connect( s, SIGNAL( signal1() ), r1, SLOT( slot2() ) ); |
|
305 |
connect( s, SIGNAL( signal1() ), r1, SLOT( slot3() ) ); |
|
306 |
connect( s, SIGNAL( signal2() ), r1, SLOT( slot4() ) ); |
|
307 |
||
308 |
// disconnect s's signal1() from all slots of r1 |
|
309 |
QObject::disconnect( s, SIGNAL( signal1() ), r1, 0 ); |
|
310 |
||
311 |
s->emitSignal1(); |
|
312 |
s->emitSignal2(); |
|
313 |
||
314 |
QCOMPARE( r1->called(1), FALSE ); |
|
315 |
QCOMPARE( r1->called(2), FALSE ); |
|
316 |
QCOMPARE( r1->called(3), FALSE ); |
|
317 |
QCOMPARE( r1->called(4), TRUE ); |
|
318 |
r1->reset(); |
|
319 |
// make sure all is disconnected again |
|
320 |
QObject::disconnect( s, 0, r1, 0 ); |
|
321 |
||
322 |
connect( s, SIGNAL( signal1() ), r1, SLOT( slot1() ) ); |
|
323 |
connect( s, SIGNAL( signal1() ), r2, SLOT( slot1() ) ); |
|
324 |
connect( s, SIGNAL( signal2() ), r1, SLOT( slot2() ) ); |
|
325 |
connect( s, SIGNAL( signal2() ), r2, SLOT( slot2() ) ); |
|
326 |
connect( s, SIGNAL( signal3() ), r1, SLOT( slot3() ) ); |
|
327 |
connect( s, SIGNAL( signal3() ), r2, SLOT( slot3() ) ); |
|
328 |
||
329 |
// disconnect signal1() from all receivers |
|
330 |
QObject::disconnect( s, SIGNAL( signal1() ), 0, 0 ); |
|
331 |
s->emitSignal1(); |
|
332 |
s->emitSignal2(); |
|
333 |
s->emitSignal3(); |
|
334 |
||
335 |
QCOMPARE( r1->called(1), FALSE ); |
|
336 |
QCOMPARE( r2->called(1), FALSE ); |
|
337 |
QCOMPARE( r1->called(2), TRUE ); |
|
338 |
QCOMPARE( r2->called(2), TRUE ); |
|
339 |
QCOMPARE( r1->called(2), TRUE ); |
|
340 |
QCOMPARE( r2->called(2), TRUE ); |
|
341 |
||
342 |
r1->reset(); |
|
343 |
r2->reset(); |
|
344 |
||
345 |
// disconnect all signals of s from all receivers |
|
346 |
QObject::disconnect( s, 0, 0, 0 ); |
|
347 |
||
348 |
QCOMPARE( r1->called(2), FALSE ); |
|
349 |
QCOMPARE( r2->called(2), FALSE ); |
|
350 |
QCOMPARE( r1->called(2), FALSE ); |
|
351 |
QCOMPARE( r2->called(2), FALSE ); |
|
352 |
||
353 |
delete r2; |
|
354 |
delete r1; |
|
355 |
delete s; |
|
356 |
} |
|
357 |
||
358 |
class AutoConnectSender : public QObject |
|
359 |
{ |
|
360 |
Q_OBJECT |
|
361 |
||
362 |
public: |
|
363 |
AutoConnectSender(QObject *parent) |
|
364 |
: QObject(parent) |
|
365 |
{} |
|
366 |
||
367 |
void emitSignalNoParams() { emit signalNoParams(); } |
|
368 |
void emitSignalWithParams(int i) { emit signalWithParams(i); } |
|
369 |
void emitSignalWithParams(int i, QString string) { emit signalWithParams(i, string); } |
|
370 |
void emitSignalManyParams(int i1, int i2, int i3, QString string, bool onoff) { emit signalManyParams(i1, i2, i3, string, onoff); } |
|
371 |
void emitSignalManyParams2(int i1, int i2, int i3, QString string, bool onoff) { emit signalManyParams2(i1, i2, i3, string, onoff); } |
|
372 |
void emitSignalLoopBack() { emit signalLoopBack(); } |
|
373 |
||
374 |
signals: |
|
375 |
void signalNoParams(); |
|
376 |
void signalWithParams(int i); |
|
377 |
void signalWithParams(int i, QString string); |
|
378 |
void signalManyParams(int i1, int i2, int i3, QString string, bool onoff); |
|
379 |
void signalManyParams(int i1, int i2, int i3, QString string, bool onoff, bool); |
|
380 |
void signalManyParams2(int i1, int i2, int i3, QString string, bool onoff); |
|
381 |
void signalLoopBack(); |
|
382 |
}; |
|
383 |
||
384 |
class AutoConnectReceiver : public QObject |
|
385 |
{ |
|
386 |
Q_OBJECT |
|
387 |
||
388 |
public: |
|
389 |
AutoConnectReceiver() |
|
390 |
{ |
|
391 |
reset(); |
|
392 |
||
393 |
connect(this, SIGNAL(on_Sender_signalLoopBack()), this, SLOT(slotLoopBack())); |
|
394 |
} |
|
395 |
||
396 |
void reset() { |
|
397 |
called_slot8 = 0; |
|
398 |
called_slot7 = 0; |
|
399 |
called_slot6 = 0; |
|
400 |
called_slot5 = 0; |
|
401 |
called_slot4 = 0; |
|
402 |
called_slot3 = 0; |
|
403 |
called_slot2 = 0; |
|
404 |
called_slot1 = 0; |
|
405 |
} |
|
406 |
||
407 |
int called_slot1; |
|
408 |
int called_slot2; |
|
409 |
int called_slot3; |
|
410 |
int called_slot4; |
|
411 |
int called_slot5; |
|
412 |
int called_slot6; |
|
413 |
int called_slot7; |
|
414 |
int called_slot8; |
|
415 |
||
416 |
bool called(int slot) { |
|
417 |
switch (slot) { |
|
418 |
case 1: return called_slot1; |
|
419 |
case 2: return called_slot2; |
|
420 |
case 3: return called_slot3; |
|
421 |
case 4: return called_slot4; |
|
422 |
case 5: return called_slot5; |
|
423 |
case 6: return called_slot6; |
|
424 |
case 7: return called_slot7; |
|
425 |
case 8: return called_slot8; |
|
426 |
default: return false; |
|
427 |
} |
|
428 |
} |
|
429 |
||
430 |
public slots: |
|
431 |
void on_Sender_signalNoParams() { ++called_slot1; } |
|
432 |
void on_Sender_signalWithParams(int i = 0) { ++called_slot2; } |
|
433 |
void on_Sender_signalWithParams(int i, QString string) { ++called_slot3; } |
|
434 |
void on_Sender_signalManyParams() { ++called_slot4; } |
|
435 |
void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff) { ++called_slot5; } |
|
436 |
void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff, bool dummy) { ++called_slot6; } |
|
437 |
void on_Sender_signalManyParams2(int i1, int i2, int i3, QString string, bool onoff) { ++called_slot7; } |
|
438 |
void slotLoopBack() { ++called_slot8; } |
|
439 |
||
440 |
protected slots: |
|
441 |
void o() { Q_ASSERT(0); } |
|
442 |
void on() { Q_ASSERT(0); } |
|
443 |
||
444 |
signals: |
|
445 |
void on_Sender_signalLoopBack(); |
|
446 |
}; |
|
447 |
||
448 |
void tst_QObject::connectByName() |
|
449 |
{ |
|
450 |
AutoConnectReceiver receiver; |
|
451 |
AutoConnectSender sender(&receiver); |
|
452 |
sender.setObjectName("Sender"); |
|
453 |
||
454 |
QMetaObject::connectSlotsByName(&receiver); |
|
455 |
||
456 |
sender.emitSignalNoParams(); |
|
457 |
QCOMPARE(receiver.called(1), true); |
|
458 |
QCOMPARE(receiver.called(2), false); |
|
459 |
QCOMPARE(receiver.called(3), false); |
|
460 |
QCOMPARE(receiver.called(4), false); |
|
461 |
QCOMPARE(receiver.called(5), false); |
|
462 |
QCOMPARE(receiver.called(6), false); |
|
463 |
QCOMPARE(receiver.called(7), false); |
|
464 |
QCOMPARE(receiver.called(8), false); |
|
465 |
receiver.reset(); |
|
466 |
||
467 |
sender.emitSignalWithParams(0); |
|
468 |
QCOMPARE(receiver.called(1), false); |
|
469 |
QCOMPARE(receiver.called(2), true); |
|
470 |
QCOMPARE(receiver.called(3), false); |
|
471 |
QCOMPARE(receiver.called(4), false); |
|
472 |
QCOMPARE(receiver.called(5), false); |
|
473 |
QCOMPARE(receiver.called(6), false); |
|
474 |
QCOMPARE(receiver.called(7), false); |
|
475 |
QCOMPARE(receiver.called(8), false); |
|
476 |
receiver.reset(); |
|
477 |
||
478 |
sender.emitSignalWithParams(0, "string"); |
|
479 |
QCOMPARE(receiver.called(1), false); |
|
480 |
QCOMPARE(receiver.called(2), false); |
|
481 |
QCOMPARE(receiver.called(3), true); |
|
482 |
QCOMPARE(receiver.called(4), false); |
|
483 |
QCOMPARE(receiver.called(5), false); |
|
484 |
QCOMPARE(receiver.called(6), false); |
|
485 |
QCOMPARE(receiver.called(7), false); |
|
486 |
QCOMPARE(receiver.called(8), false); |
|
487 |
receiver.reset(); |
|
488 |
||
489 |
sender.emitSignalManyParams(1, 2, 3, "string", true); |
|
490 |
QCOMPARE(receiver.called(1), false); |
|
491 |
QCOMPARE(receiver.called(2), false); |
|
492 |
QCOMPARE(receiver.called(3), false); |
|
493 |
QCOMPARE(receiver.called(4), true); |
|
494 |
QCOMPARE(receiver.called(5), true); |
|
495 |
QCOMPARE(receiver.called(6), false); |
|
496 |
QCOMPARE(receiver.called(7), false); |
|
497 |
QCOMPARE(receiver.called(8), false); |
|
498 |
receiver.reset(); |
|
499 |
||
500 |
sender.emitSignalManyParams2(1, 2, 3, "string", true); |
|
501 |
QCOMPARE(receiver.called(1), false); |
|
502 |
QCOMPARE(receiver.called(2), false); |
|
503 |
QCOMPARE(receiver.called(3), false); |
|
504 |
QCOMPARE(receiver.called(4), false); |
|
505 |
QCOMPARE(receiver.called(5), false); |
|
506 |
QCOMPARE(receiver.called(6), false); |
|
507 |
QCOMPARE(receiver.called(7), true); |
|
508 |
QCOMPARE(receiver.called(8), false); |
|
509 |
receiver.reset(); |
|
510 |
||
511 |
sender.emitSignalLoopBack(); |
|
512 |
QCOMPARE(receiver.called(1), false); |
|
513 |
QCOMPARE(receiver.called(2), false); |
|
514 |
QCOMPARE(receiver.called(3), false); |
|
515 |
QCOMPARE(receiver.called(4), false); |
|
516 |
QCOMPARE(receiver.called(5), false); |
|
517 |
QCOMPARE(receiver.called(6), false); |
|
518 |
QCOMPARE(receiver.called(7), false); |
|
519 |
QCOMPARE(receiver.called(8), true); |
|
520 |
receiver.reset(); |
|
521 |
} |
|
522 |
||
523 |
void tst_QObject::qobject_castTemplate() |
|
524 |
{ |
|
525 |
QObject *o = 0; |
|
526 |
QVERIFY( !::qobject_cast<QObject*>(o) ); |
|
527 |
||
528 |
o = new SenderObject; |
|
529 |
QVERIFY( ::qobject_cast<SenderObject*>(o) ); |
|
530 |
QVERIFY( ::qobject_cast<QObject*>(o) ); |
|
531 |
QVERIFY( !::qobject_cast<ReceiverObject*>(o) ); |
|
532 |
delete o; |
|
533 |
} |
|
534 |
||
535 |
void tst_QObject::findChildren() |
|
536 |
{ |
|
537 |
QObject o; |
|
538 |
QObject o1(&o); |
|
539 |
QObject o2(&o); |
|
540 |
QObject o11(&o1); |
|
541 |
QObject o12(&o1); |
|
542 |
QObject o111(&o11); |
|
543 |
QObject unnamed(&o); |
|
544 |
QTimer t1(&o); |
|
545 |
QTimer t121(&o12); |
|
546 |
QTimer emptyname(&o); |
|
547 |
||
548 |
o.setObjectName("o"); |
|
549 |
o1.setObjectName("o1"); |
|
550 |
o2.setObjectName("o2"); |
|
551 |
o11.setObjectName("o11"); |
|
552 |
o12.setObjectName("o12"); |
|
553 |
o111.setObjectName("o111"); |
|
554 |
t1.setObjectName("t1"); |
|
555 |
t121.setObjectName("t121"); |
|
556 |
emptyname.setObjectName(""); |
|
557 |
||
558 |
QObject *op = 0; |
|
559 |
||
560 |
op = qFindChild<QObject*>(&o, "o1"); |
|
561 |
QCOMPARE(op, &o1); |
|
562 |
op = qFindChild<QObject*>(&o, "o2"); |
|
563 |
QCOMPARE(op, &o2); |
|
564 |
op = qFindChild<QObject*>(&o, "o11"); |
|
565 |
QCOMPARE(op, &o11); |
|
566 |
op = qFindChild<QObject*>(&o, "o12"); |
|
567 |
QCOMPARE(op, &o12); |
|
568 |
op = qFindChild<QObject*>(&o, "o111"); |
|
569 |
QCOMPARE(op, &o111); |
|
570 |
op = qFindChild<QObject*>(&o, "t1"); |
|
571 |
QCOMPARE(op, static_cast<QObject *>(&t1)); |
|
572 |
op = qFindChild<QObject*>(&o, "t121"); |
|
573 |
QCOMPARE(op, static_cast<QObject *>(&t121)); |
|
574 |
op = qFindChild<QTimer*>(&o, "t1"); |
|
575 |
QCOMPARE(op, static_cast<QObject *>(&t1)); |
|
576 |
op = qFindChild<QTimer*>(&o, "t121"); |
|
577 |
QCOMPARE(op, static_cast<QObject *>(&t121)); |
|
578 |
op = qFindChild<QTimer*>(&o, "o12"); |
|
579 |
QCOMPARE(op, static_cast<QObject *>(0)); |
|
580 |
op = qFindChild<QObject*>(&o, "o"); |
|
581 |
QCOMPARE(op, static_cast<QObject *>(0)); |
|
582 |
op = qFindChild<QObject*>(&o, "harry"); |
|
583 |
QCOMPARE(op, static_cast<QObject *>(0)); |
|
584 |
op = qFindChild<QObject*>(&o, "o1"); |
|
585 |
QCOMPARE(op, &o1); |
|
586 |
||
587 |
QList<QObject*> l; |
|
588 |
QList<QTimer*> tl; |
|
589 |
||
590 |
l = qFindChildren<QObject*>(&o, "o1"); |
|
591 |
QCOMPARE(l.size(), 1); |
|
592 |
QCOMPARE(l.at(0), &o1); |
|
593 |
l = qFindChildren<QObject*>(&o, "o2"); |
|
594 |
QCOMPARE(l.size(), 1); |
|
595 |
QCOMPARE(l.at(0), &o2); |
|
596 |
l = qFindChildren<QObject*>(&o, "o11"); |
|
597 |
QCOMPARE(l.size(), 1); |
|
598 |
QCOMPARE(l.at(0), &o11); |
|
599 |
l = qFindChildren<QObject*>(&o, "o12"); |
|
600 |
QCOMPARE(l.size(), 1); |
|
601 |
QCOMPARE(l.at(0), &o12); |
|
602 |
l = qFindChildren<QObject*>(&o, "o111"); |
|
603 |
QCOMPARE(l.size(), 1); |
|
604 |
QCOMPARE(l.at(0), &o111); |
|
605 |
l = qFindChildren<QObject*>(&o, "t1"); |
|
606 |
QCOMPARE(l.size(), 1); |
|
607 |
QCOMPARE(l.at(0), static_cast<QObject *>(&t1)); |
|
608 |
l = qFindChildren<QObject*>(&o, "t121"); |
|
609 |
QCOMPARE(l.size(), 1); |
|
610 |
QCOMPARE(l.at(0), static_cast<QObject *>(&t121)); |
|
611 |
tl = qFindChildren<QTimer*>(&o, "t1"); |
|
612 |
QCOMPARE(tl.size(), 1); |
|
613 |
QCOMPARE(tl.at(0), &t1); |
|
614 |
tl = qFindChildren<QTimer*>(&o, "t121"); |
|
615 |
QCOMPARE(tl.size(), 1); |
|
616 |
QCOMPARE(tl.at(0), &t121); |
|
617 |
l = qFindChildren<QObject*>(&o, "o"); |
|
618 |
QCOMPARE(l.size(), 0); |
|
619 |
l = qFindChildren<QObject*>(&o, "harry"); |
|
620 |
QCOMPARE(l.size(), 0); |
|
621 |
tl = qFindChildren<QTimer*>(&o, "o12"); |
|
622 |
QCOMPARE(tl.size(), 0); |
|
623 |
l = qFindChildren<QObject*>(&o, "o1"); |
|
624 |
QCOMPARE(l.size(), 1); |
|
625 |
QCOMPARE(l.at(0), &o1); |
|
626 |
||
627 |
l = qFindChildren<QObject*>(&o, QRegExp("o.*")); |
|
628 |
QCOMPARE(l.size(), 5); |
|
629 |
QVERIFY(l.contains(&o1)); |
|
630 |
QVERIFY(l.contains(&o2)); |
|
631 |
QVERIFY(l.contains(&o11)); |
|
632 |
QVERIFY(l.contains(&o12)); |
|
633 |
QVERIFY(l.contains(&o111)); |
|
634 |
l = qFindChildren<QObject*>(&o, QRegExp("t.*")); |
|
635 |
QCOMPARE(l.size(), 2); |
|
636 |
QVERIFY(l.contains(&t1)); |
|
637 |
QVERIFY(l.contains(&t121)); |
|
638 |
tl = qFindChildren<QTimer*>(&o, QRegExp(".*")); |
|
639 |
QCOMPARE(tl.size(), 3); |
|
640 |
QVERIFY(tl.contains(&t1)); |
|
641 |
QVERIFY(tl.contains(&t121)); |
|
642 |
tl = qFindChildren<QTimer*>(&o, QRegExp("o.*")); |
|
643 |
QCOMPARE(tl.size(), 0); |
|
644 |
l = qFindChildren<QObject*>(&o, QRegExp("harry")); |
|
645 |
QCOMPARE(l.size(), 0); |
|
646 |
||
647 |
// empty and null string check |
|
648 |
op = qFindChild<QObject*>(&o); |
|
649 |
QCOMPARE(op, &o1); |
|
650 |
op = qFindChild<QObject*>(&o, ""); |
|
651 |
QCOMPARE(op, &unnamed); |
|
652 |
op = qFindChild<QObject*>(&o, "unnamed"); |
|
653 |
QCOMPARE(op, static_cast<QObject *>(0)); |
|
654 |
||
655 |
l = qFindChildren<QObject*>(&o); |
|
656 |
QCOMPARE(l.size(), 9); |
|
657 |
l = qFindChildren<QObject*>(&o, ""); |
|
658 |
QCOMPARE(l.size(), 2); |
|
659 |
l = qFindChildren<QObject*>(&o, "unnamed"); |
|
660 |
QCOMPARE(l.size(), 0); |
|
661 |
||
662 |
#ifndef QT_NO_MEMBER_TEMPLATES |
|
663 |
tl = o.findChildren<QTimer *>("t1"); |
|
664 |
QCOMPARE(tl.size(), 1); |
|
665 |
QCOMPARE(tl.at(0), &t1); |
|
666 |
#endif |
|
667 |
} |
|
668 |
||
669 |
||
670 |
class NotifyObject : public SenderObject, public ReceiverObject |
|
671 |
{ |
|
672 |
public: |
|
673 |
NotifyObject() : SenderObject(), ReceiverObject() |
|
674 |
{} |
|
675 |
||
676 |
QString org_signal; |
|
677 |
QString nw_signal; |
|
678 |
||
679 |
protected: |
|
680 |
void connectNotify( const char *signal ) |
|
681 |
{ |
|
682 |
org_signal = signal; |
|
683 |
nw_signal = QMetaObject::normalizedSignature(signal); |
|
684 |
}; |
|
685 |
void disconnectNotify( const char *signal ) |
|
686 |
{ |
|
687 |
org_signal = signal; |
|
688 |
nw_signal = QMetaObject::normalizedSignature(signal); |
|
689 |
}; |
|
690 |
}; |
|
691 |
||
692 |
void tst_QObject::connectDisconnectNotify_data() |
|
693 |
{ |
|
694 |
QTest::addColumn<QString>("a_signal"); |
|
695 |
QTest::addColumn<QString>("a_slot"); |
|
696 |
||
697 |
QTest::newRow("combo1") << SIGNAL( signal1() ) << SLOT( slot1() ); |
|
698 |
QTest::newRow("combo2") << SIGNAL( signal2(void) ) << SLOT( slot2( ) ); |
|
699 |
QTest::newRow("combo3") << SIGNAL( signal3( ) ) << SLOT( slot3(void) ); |
|
700 |
QTest::newRow("combo4") << SIGNAL( signal4( void ) )<< SLOT( slot4( void ) ); |
|
701 |
} |
|
702 |
||
703 |
void tst_QObject::connectDisconnectNotify() |
|
704 |
{ |
|
705 |
NotifyObject *s = new NotifyObject; |
|
706 |
NotifyObject *r = new NotifyObject; |
|
707 |
||
708 |
QFETCH(QString, a_signal); |
|
709 |
QFETCH(QString, a_slot); |
|
710 |
||
711 |
// Test connectNotify |
|
712 |
connect( (SenderObject*)s, a_signal.toLatin1(), (ReceiverObject*)r, a_slot.toLatin1() ); |
|
713 |
QCOMPARE( s->org_signal, s->nw_signal ); |
|
714 |
QCOMPARE( s->org_signal.toLatin1(), QMetaObject::normalizedSignature(a_signal.toLatin1().constData()) ); |
|
715 |
||
716 |
// Test disconnectNotify |
|
717 |
QObject::disconnect( (SenderObject*)s, a_signal.toLatin1(), (ReceiverObject*)r, a_slot.toLatin1() ); |
|
718 |
QCOMPARE( s->org_signal, s->nw_signal ); |
|
719 |
QCOMPARE( s->org_signal.toLatin1(), QMetaObject::normalizedSignature(a_signal.toLatin1().constData()) ); |
|
720 |
||
721 |
// Reconnect |
|
722 |
connect( (SenderObject*)s, a_signal.toLatin1(), (ReceiverObject*)r, a_slot.toLatin1() ); |
|
723 |
// Test disconnectNotify for a complete disconnect |
|
724 |
((SenderObject*)s)->disconnect((ReceiverObject*)r); |
|
725 |
||
726 |
delete s; |
|
727 |
delete r; |
|
728 |
} |
|
729 |
||
730 |
class SequenceObject : public ReceiverObject |
|
731 |
{ |
|
732 |
Q_OBJECT |
|
733 |
||
734 |
public: |
|
735 |
QObject *next; |
|
736 |
SequenceObject() : next(0) { } |
|
737 |
||
738 |
public slots: |
|
739 |
void slot1_disconnectThis() |
|
740 |
{ |
|
741 |
slot1(); |
|
742 |
disconnect(sender(), SIGNAL(signal1()), this, SLOT(slot1_disconnectThis())); |
|
743 |
} |
|
744 |
||
745 |
void slot2_reconnectThis() |
|
746 |
{ |
|
747 |
slot2(); |
|
748 |
||
749 |
const QObject *s = sender(); |
|
750 |
disconnect(s, SIGNAL(signal1()), this, SLOT(slot2_reconnectThis())); |
|
751 |
connect(s, SIGNAL(signal1()), this, SLOT(slot2_reconnectThis())); |
|
752 |
} |
|
753 |
||
754 |
void slot1_disconnectNext() |
|
755 |
{ |
|
756 |
slot1(); |
|
757 |
disconnect(sender(), SIGNAL(signal1()), next, SLOT(slot1())); |
|
758 |
} |
|
759 |
||
760 |
void slot2_reconnectNext() |
|
761 |
{ |
|
762 |
slot2(); |
|
763 |
||
764 |
// modify the connection list in 'this' |
|
765 |
disconnect(sender(), SIGNAL(signal1()), next, SLOT(slot2())); |
|
766 |
connect(sender(), SIGNAL(signal1()), next, SLOT(slot2())); |
|
767 |
||
768 |
// modify the sender list in 'this' |
|
769 |
connect(next, SIGNAL(destroyed()), this, SLOT(deleteLater())); |
|
770 |
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(deleteLater())); |
|
771 |
disconnect(next, SIGNAL(destroyed()), this, SLOT(deleteLater())); |
|
772 |
disconnect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(deleteLater())); |
|
773 |
} |
|
774 |
||
775 |
void slot1_deleteNext() |
|
776 |
{ |
|
777 |
slot1(); |
|
778 |
delete next; |
|
779 |
} |
|
780 |
||
781 |
void slot2_deleteSender() |
|
782 |
{ |
|
783 |
slot2(); |
|
784 |
delete sender(); |
|
785 |
} |
|
786 |
}; |
|
787 |
||
788 |
void tst_QObject::emitInDefinedOrder() |
|
789 |
{ |
|
790 |
SenderObject sender; |
|
791 |
ReceiverObject receiver1, receiver2, receiver3, receiver4; |
|
792 |
||
793 |
connect(&sender, SIGNAL(signal1()), &receiver1, SLOT(slot1())); |
|
794 |
connect(&sender, SIGNAL(signal1()), &receiver2, SLOT(slot1())); |
|
795 |
connect(&sender, SIGNAL(signal1()), &receiver3, SLOT(slot1())); |
|
796 |
connect(&sender, SIGNAL(signal1()), &receiver4, SLOT(slot1())); |
|
797 |
connect(&sender, SIGNAL(signal1()), &receiver1, SLOT(slot2())); |
|
798 |
connect(&sender, SIGNAL(signal1()), &receiver2, SLOT(slot2())); |
|
799 |
connect(&sender, SIGNAL(signal1()), &receiver3, SLOT(slot2())); |
|
800 |
connect(&sender, SIGNAL(signal1()), &receiver4, SLOT(slot2())); |
|
801 |
||
802 |
int sequence; |
|
803 |
ReceiverObject::sequence = sequence = 0; |
|
804 |
sender.emitSignal1(); |
|
805 |
QCOMPARE(receiver1.sequence_slot1, ++sequence); |
|
806 |
QCOMPARE(receiver2.sequence_slot1, ++sequence); |
|
807 |
QCOMPARE(receiver3.sequence_slot1, ++sequence); |
|
808 |
QCOMPARE(receiver4.sequence_slot1, ++sequence); |
|
809 |
QCOMPARE(receiver1.sequence_slot2, ++sequence); |
|
810 |
QCOMPARE(receiver2.sequence_slot2, ++sequence); |
|
811 |
QCOMPARE(receiver3.sequence_slot2, ++sequence); |
|
812 |
QCOMPARE(receiver4.sequence_slot2, ++sequence); |
|
813 |
||
814 |
QObject::disconnect(&sender, SIGNAL(signal1()), &receiver2, SLOT(slot1())); |
|
815 |
connect(&sender, SIGNAL(signal1()), &receiver2, SLOT(slot1())); |
|
816 |
||
817 |
ReceiverObject::sequence = sequence = 0; |
|
818 |
sender.emitSignal1(); |
|
819 |
QCOMPARE(receiver1.sequence_slot1, ++sequence); |
|
820 |
QCOMPARE(receiver3.sequence_slot1, ++sequence); |
|
821 |
QCOMPARE(receiver4.sequence_slot1, ++sequence); |
|
822 |
QCOMPARE(receiver1.sequence_slot2, ++sequence); |
|
823 |
QCOMPARE(receiver2.sequence_slot2, ++sequence); |
|
824 |
QCOMPARE(receiver3.sequence_slot2, ++sequence); |
|
825 |
QCOMPARE(receiver4.sequence_slot2, ++sequence); |
|
826 |
QCOMPARE(receiver2.sequence_slot1, ++sequence); |
|
827 |
||
828 |
QObject::disconnect(&sender, SIGNAL(signal1()), &receiver1, SLOT(slot1())); |
|
829 |
connect(&sender, SIGNAL(signal1()), &receiver1, SLOT(slot1())); |
|
830 |
||
831 |
ReceiverObject::sequence = sequence = 0; |
|
832 |
sender.emitSignal1(); |
|
833 |
QCOMPARE(receiver3.sequence_slot1, ++sequence); |
|
834 |
QCOMPARE(receiver4.sequence_slot1, ++sequence); |
|
835 |
QCOMPARE(receiver1.sequence_slot2, ++sequence); |
|
836 |
QCOMPARE(receiver2.sequence_slot2, ++sequence); |
|
837 |
QCOMPARE(receiver3.sequence_slot2, ++sequence); |
|
838 |
QCOMPARE(receiver4.sequence_slot2, ++sequence); |
|
839 |
QCOMPARE(receiver2.sequence_slot1, ++sequence); |
|
840 |
QCOMPARE(receiver1.sequence_slot1, ++sequence); |
|
841 |
||
842 |
// ensure emission order even if the connections change during emission |
|
843 |
SenderObject *sender2 = new SenderObject; |
|
844 |
SequenceObject seq1, seq2, *seq3 = new SequenceObject, seq4; |
|
845 |
seq1.next = &seq2; |
|
846 |
seq2.next = seq3; |
|
847 |
seq3->next = &seq4; |
|
848 |
||
849 |
// try 1 |
|
850 |
connect(sender2, SIGNAL(signal1()), &seq1, SLOT(slot1_disconnectThis())); |
|
851 |
connect(sender2, SIGNAL(signal1()), &seq2, SLOT(slot1_disconnectNext())); |
|
852 |
connect(sender2, SIGNAL(signal1()), seq3, SLOT(slot1())); |
|
853 |
connect(sender2, SIGNAL(signal1()), &seq4, SLOT(slot1())); |
|
854 |
connect(sender2, SIGNAL(signal1()), &seq1, SLOT(slot2_reconnectThis())); |
|
855 |
connect(sender2, SIGNAL(signal1()), &seq2, SLOT(slot2_reconnectNext())); |
|
856 |
connect(sender2, SIGNAL(signal1()), seq3, SLOT(slot2())); |
|
857 |
connect(sender2, SIGNAL(signal1()), &seq4, SLOT(slot2())); |
|
858 |
||
859 |
SequenceObject::sequence = sequence = 0; |
|
860 |
sender2->emitSignal1(); |
|
861 |
QCOMPARE(seq1.called(1), TRUE); |
|
862 |
QCOMPARE(seq2.called(1), TRUE); |
|
863 |
QCOMPARE(seq3->called(1), FALSE); |
|
864 |
QCOMPARE(seq4.called(1), TRUE); |
|
865 |
QCOMPARE(seq1.called(2), TRUE); |
|
866 |
QCOMPARE(seq2.called(2), TRUE); |
|
867 |
QCOMPARE(seq3->called(2), FALSE); |
|
868 |
QCOMPARE(seq4.called(2), TRUE); |
|
869 |
QCOMPARE(seq1.sequence_slot1, ++sequence); |
|
870 |
QCOMPARE(seq2.sequence_slot1, ++sequence); |
|
871 |
QCOMPARE(seq4.sequence_slot1, ++sequence); |
|
872 |
QCOMPARE(seq1.sequence_slot2, ++sequence); |
|
873 |
QCOMPARE(seq2.sequence_slot2, ++sequence); |
|
874 |
QCOMPARE(seq4.sequence_slot2, ++sequence); |
|
875 |
||
876 |
QObject::disconnect(sender2, 0, &seq1, 0); |
|
877 |
QObject::disconnect(sender2, 0, &seq2, 0); |
|
878 |
QObject::disconnect(sender2, 0, seq3, 0); |
|
879 |
QObject::disconnect(sender2, 0, &seq4, 0); |
|
880 |
seq1.reset(); |
|
881 |
seq2.reset(); |
|
882 |
seq3->reset(); |
|
883 |
seq4.reset(); |
|
884 |
||
885 |
// try 2 |
|
886 |
connect(sender2, SIGNAL(signal1()), &seq1, SLOT(slot2_reconnectThis())); |
|
887 |
connect(sender2, SIGNAL(signal1()), &seq2, SLOT(slot2_reconnectNext())); |
|
888 |
connect(sender2, SIGNAL(signal1()), seq3, SLOT(slot2())); |
|
889 |
connect(sender2, SIGNAL(signal1()), &seq4, SLOT(slot2())); |
|
890 |
connect(sender2, SIGNAL(signal1()), &seq1, SLOT(slot1_disconnectThis())); |
|
891 |
connect(sender2, SIGNAL(signal1()), &seq2, SLOT(slot1_disconnectNext())); |
|
892 |
connect(sender2, SIGNAL(signal1()), seq3, SLOT(slot1())); |
|
893 |
connect(sender2, SIGNAL(signal1()), &seq4, SLOT(slot1())); |
|
894 |
||
895 |
SequenceObject::sequence = sequence = 0; |
|
896 |
sender2->emitSignal1(); |
|
897 |
QCOMPARE(seq1.called(2), TRUE); |
|
898 |
QCOMPARE(seq2.called(2), TRUE); |
|
899 |
QCOMPARE(seq3->called(2), FALSE); |
|
900 |
QCOMPARE(seq4.called(2), TRUE); |
|
901 |
QCOMPARE(seq1.called(1), TRUE); |
|
902 |
QCOMPARE(seq2.called(1), TRUE); |
|
903 |
QCOMPARE(seq3->called(1), FALSE); |
|
904 |
QCOMPARE(seq4.called(1), TRUE); |
|
905 |
QCOMPARE(seq1.sequence_slot2, ++sequence); |
|
906 |
QCOMPARE(seq2.sequence_slot2, ++sequence); |
|
907 |
QCOMPARE(seq4.sequence_slot2, ++sequence); |
|
908 |
QCOMPARE(seq1.sequence_slot1, ++sequence); |
|
909 |
QCOMPARE(seq2.sequence_slot1, ++sequence); |
|
910 |
QCOMPARE(seq4.sequence_slot1, ++sequence); |
|
911 |
||
912 |
QObject::disconnect(sender2, 0, &seq1, 0); |
|
913 |
QObject::disconnect(sender2, 0, &seq2, 0); |
|
914 |
QObject::disconnect(sender2, 0, seq3, 0); |
|
915 |
QObject::disconnect(sender2, 0, &seq4, 0); |
|
916 |
seq1.reset(); |
|
917 |
seq2.reset(); |
|
918 |
seq3->reset(); |
|
919 |
seq4.reset(); |
|
920 |
||
921 |
// try 3 |
|
922 |
connect(sender2, SIGNAL(signal1()), &seq1, SLOT(slot1())); |
|
923 |
connect(sender2, SIGNAL(signal1()), &seq2, SLOT(slot1_disconnectNext())); |
|
924 |
connect(sender2, SIGNAL(signal1()), seq3, SLOT(slot1())); |
|
925 |
connect(sender2, SIGNAL(signal1()), &seq4, SLOT(slot1())); |
|
926 |
connect(sender2, SIGNAL(signal1()), &seq1, SLOT(slot2())); |
|
927 |
connect(sender2, SIGNAL(signal1()), &seq2, SLOT(slot2_reconnectNext())); |
|
928 |
connect(sender2, SIGNAL(signal1()), seq3, SLOT(slot2())); |
|
929 |
connect(sender2, SIGNAL(signal1()), &seq4, SLOT(slot2())); |
|
930 |
||
931 |
SequenceObject::sequence = sequence = 0; |
|
932 |
sender2->emitSignal1(); |
|
933 |
QCOMPARE(seq1.called(1), TRUE); |
|
934 |
QCOMPARE(seq2.called(1), TRUE); |
|
935 |
QCOMPARE(seq3->called(1), FALSE); |
|
936 |
QCOMPARE(seq4.called(1), TRUE); |
|
937 |
QCOMPARE(seq1.called(2), TRUE); |
|
938 |
QCOMPARE(seq2.called(2), TRUE); |
|
939 |
QCOMPARE(seq3->called(2), FALSE); |
|
940 |
QCOMPARE(seq4.called(2), TRUE); |
|
941 |
QCOMPARE(seq1.sequence_slot1, ++sequence); |
|
942 |
QCOMPARE(seq2.sequence_slot1, ++sequence); |
|
943 |
QCOMPARE(seq4.sequence_slot1, ++sequence); |
|
944 |
QCOMPARE(seq1.sequence_slot2, ++sequence); |
|
945 |
QCOMPARE(seq2.sequence_slot2, ++sequence); |
|
946 |
QCOMPARE(seq4.sequence_slot2, ++sequence); |
|
947 |
||
948 |
// ensure emission order even if objects are destroyed during emission |
|
949 |
QObject::disconnect(sender2, 0, &seq1, 0); |
|
950 |
QObject::disconnect(sender2, 0, &seq2, 0); |
|
951 |
QObject::disconnect(sender2, 0, seq3, 0); |
|
952 |
QObject::disconnect(sender2, 0, &seq4, 0); |
|
953 |
seq1.reset(); |
|
954 |
seq2.reset(); |
|
955 |
seq3->reset(); |
|
956 |
seq4.reset(); |
|
957 |
||
958 |
connect(sender2, SIGNAL(signal1()), &seq1, SLOT(slot1())); |
|
959 |
connect(sender2, SIGNAL(signal1()), &seq2, SLOT(slot1_deleteNext())); |
|
960 |
connect(sender2, SIGNAL(signal1()), seq3, SLOT(slot1())); |
|
961 |
connect(sender2, SIGNAL(signal1()), &seq4, SLOT(slot1())); |
|
962 |
connect(sender2, SIGNAL(signal1()), &seq1, SLOT(slot2())); |
|
963 |
connect(sender2, SIGNAL(signal1()), &seq2, SLOT(slot2_deleteSender())); |
|
964 |
connect(sender2, SIGNAL(signal1()), seq3, SLOT(slot2())); |
|
965 |
connect(sender2, SIGNAL(signal1()), &seq4, SLOT(slot2())); |
|
966 |
||
967 |
QPointer<SenderObject> psender = sender2; |
|
968 |
QPointer<SequenceObject> pseq3 = seq3; |
|
969 |
||
970 |
SequenceObject::sequence = sequence = 0; |
|
971 |
sender2->emitSignal1(); |
|
972 |
QCOMPARE(static_cast<QObject *>(psender), static_cast<QObject *>(0)); |
|
973 |
QCOMPARE(static_cast<QObject *>(pseq3), static_cast<QObject *>(0)); |
|
974 |
QCOMPARE(seq1.called(1), TRUE); |
|
975 |
QCOMPARE(seq2.called(1), TRUE); |
|
976 |
QCOMPARE(seq4.called(1), TRUE); |
|
977 |
QCOMPARE(seq1.called(2), TRUE); |
|
978 |
QCOMPARE(seq2.called(2), TRUE); |
|
979 |
QCOMPARE(seq4.called(2), FALSE); |
|
980 |
QCOMPARE(seq1.sequence_slot1, ++sequence); |
|
981 |
QCOMPARE(seq2.sequence_slot1, ++sequence); |
|
982 |
QCOMPARE(seq4.sequence_slot1, ++sequence); |
|
983 |
QCOMPARE(seq1.sequence_slot2, ++sequence); |
|
984 |
QCOMPARE(seq2.sequence_slot2, ++sequence); |
|
985 |
||
986 |
QPointer<SenderObject> psender3 = new SenderObject; |
|
987 |
connect(psender3, SIGNAL(signal1()), psender3, SIGNAL(signal2())); |
|
988 |
connect(psender3, SIGNAL(signal2()), &seq1, SLOT(slot2_deleteSender())); |
|
989 |
psender3->emitSignal1(); |
|
990 |
QVERIFY(!psender3); |
|
991 |
} |
|
992 |
||
993 |
static int instanceCount = 0; |
|
994 |
||
995 |
struct CustomType |
|
996 |
{ |
|
997 |
CustomType(int l1 = 0, int l2 = 0, int l3 = 0): i1(l1), i2(l2), i3(l3) |
|
998 |
{ ++instanceCount; } |
|
999 |
CustomType(const CustomType &other): i1(other.i1), i2(other.i2), i3(other.i3) |
|
1000 |
{ ++instanceCount; } |
|
1001 |
~CustomType() { --instanceCount; } |
|
1002 |
||
1003 |
int i1, i2, i3; |
|
1004 |
int value() { return i1 + i2 + i3; } |
|
1005 |
}; |
|
1006 |
||
1007 |
Q_DECLARE_METATYPE(CustomType*) |
|
1008 |
||
1009 |
class QCustomTypeChecker: public QObject |
|
1010 |
{ |
|
1011 |
Q_OBJECT |
|
1012 |
||
1013 |
public: |
|
1014 |
QCustomTypeChecker(QObject *parent = 0): QObject(parent) {} |
|
1015 |
void doEmit(CustomType ct) |
|
1016 |
{ emit signal1(ct); } |
|
1017 |
||
1018 |
public slots: |
|
1019 |
void slot1(CustomType ct); |
|
1020 |
||
1021 |
signals: |
|
1022 |
void signal1(CustomType ct); |
|
1023 |
||
1024 |
public: |
|
1025 |
CustomType received; |
|
1026 |
}; |
|
1027 |
||
1028 |
void QCustomTypeChecker::slot1(CustomType ct) |
|
1029 |
{ received = ct; } |
|
1030 |
||
1031 |
||
1032 |
void tst_QObject::customTypes() |
|
1033 |
{ |
|
1034 |
CustomType t0; |
|
1035 |
CustomType t1(1, 2, 3); |
|
1036 |
CustomType t2(2, 3, 4); |
|
1037 |
||
1038 |
{ |
|
1039 |
QCustomTypeChecker checker; |
|
1040 |
QCOMPARE(instanceCount, 4); |
|
1041 |
||
1042 |
connect(&checker, SIGNAL(signal1(CustomType)), &checker, SLOT(slot1(CustomType)), |
|
1043 |
Qt::DirectConnection); |
|
1044 |
QCOMPARE(checker.received.value(), 0); |
|
1045 |
checker.doEmit(t1); |
|
1046 |
QCOMPARE(checker.received.value(), t1.value()); |
|
1047 |
checker.received = t0; |
|
1048 |
||
1049 |
int idx = qRegisterMetaType<CustomType>("CustomType"); |
|
1050 |
QCOMPARE(QMetaType::type("CustomType"), idx); |
|
1051 |
||
1052 |
checker.disconnect(); |
|
1053 |
connect(&checker, SIGNAL(signal1(CustomType)), &checker, SLOT(slot1(CustomType)), |
|
1054 |
Qt::QueuedConnection); |
|
1055 |
QCOMPARE(instanceCount, 4); |
|
1056 |
checker.doEmit(t2); |
|
1057 |
QCOMPARE(instanceCount, 5); |
|
1058 |
QCOMPARE(checker.received.value(), t0.value()); |
|
1059 |
||
1060 |
QCoreApplication::processEvents(); |
|
1061 |
QCOMPARE(checker.received.value(), t2.value()); |
|
1062 |
QCOMPARE(instanceCount, 4); |
|
1063 |
||
1064 |
QVERIFY(QMetaType::isRegistered(idx)); |
|
1065 |
QCOMPARE(qRegisterMetaType<CustomType>("CustomType"), idx); |
|
1066 |
QCOMPARE(QMetaType::type("CustomType"), idx); |
|
1067 |
QVERIFY(QMetaType::isRegistered(idx)); |
|
1068 |
} |
|
1069 |
QCOMPARE(instanceCount, 3); |
|
1070 |
} |
|
1071 |
||
1072 |
QDataStream &operator<<(QDataStream &stream, const CustomType &ct) |
|
1073 |
{ |
|
1074 |
stream << ct.i1 << ct.i2 << ct.i3; |
|
1075 |
return stream; |
|
1076 |
} |
|
1077 |
||
1078 |
QDataStream &operator>>(QDataStream &stream, CustomType &ct) |
|
1079 |
{ |
|
1080 |
stream >> ct.i1; |
|
1081 |
stream >> ct.i2; |
|
1082 |
stream >> ct.i3; |
|
1083 |
return stream; |
|
1084 |
} |
|
1085 |
||
1086 |
void tst_QObject::streamCustomTypes() |
|
1087 |
{ |
|
1088 |
QByteArray ba; |
|
1089 |
||
1090 |
int idx = qRegisterMetaType<CustomType>("CustomType"); |
|
1091 |
qRegisterMetaTypeStreamOperators<CustomType>("CustomType"); |
|
1092 |
||
1093 |
{ |
|
1094 |
CustomType t1(1, 2, 3); |
|
1095 |
QCOMPARE(instanceCount, 1); |
|
1096 |
QDataStream stream(&ba, (QIODevice::OpenMode)QIODevice::WriteOnly); |
|
1097 |
QMetaType::save(stream, idx, &t1); |
|
1098 |
} |
|
1099 |
||
1100 |
QCOMPARE(instanceCount, 0); |
|
1101 |
||
1102 |
{ |
|
1103 |
CustomType t2; |
|
1104 |
QCOMPARE(instanceCount, 1); |
|
1105 |
QDataStream stream(&ba, (QIODevice::OpenMode)QIODevice::ReadOnly); |
|
1106 |
QMetaType::load(stream, idx, &t2); |
|
1107 |
QCOMPARE(instanceCount, 1); |
|
1108 |
QCOMPARE(t2.i1, 1); |
|
1109 |
QCOMPARE(t2.i2, 2); |
|
1110 |
QCOMPARE(t2.i3, 3); |
|
1111 |
} |
|
1112 |
QCOMPARE(instanceCount, 0); |
|
1113 |
} |
|
1114 |
||
1115 |
class PropertyObject : public QObject |
|
1116 |
{ |
|
1117 |
Q_OBJECT |
|
1118 |
Q_ENUMS(Alpha Priority) |
|
1119 |
||
1120 |
Q_PROPERTY(Alpha alpha READ alpha WRITE setAlpha) |
|
1121 |
Q_PROPERTY(Priority priority READ priority WRITE setPriority) |
|
1122 |
Q_PROPERTY(int number READ number WRITE setNumber) |
|
1123 |
Q_PROPERTY(QString string READ string WRITE setString) |
|
1124 |
Q_PROPERTY(QVariant variant READ variant WRITE setVariant) |
|
1125 |
Q_PROPERTY(CustomType* custom READ custom WRITE setCustom) |
|
1126 |
Q_PROPERTY(float myFloat READ myFloat WRITE setMyFloat) |
|
1127 |
Q_PROPERTY(qreal myQReal READ myQReal WRITE setMyQReal) |
|
1128 |
||
1129 |
public: |
|
1130 |
enum Alpha { |
|
1131 |
Alpha0, |
|
1132 |
Alpha1, |
|
1133 |
Alpha2 |
|
1134 |
}; |
|
1135 |
||
1136 |
enum Priority { High, Low, VeryHigh, VeryLow }; |
|
1137 |
||
1138 |
PropertyObject() |
|
1139 |
: m_alpha(Alpha0), m_priority(High), m_number(0), m_custom(0), m_float(42) |
|
1140 |
{} |
|
1141 |
||
1142 |
Alpha alpha() const { return m_alpha; } |
|
1143 |
void setAlpha(Alpha alpha) { m_alpha = alpha; } |
|
1144 |
||
1145 |
Priority priority() const { return m_priority; } |
|
1146 |
void setPriority(Priority priority) { m_priority = priority; } |
|
1147 |
||
1148 |
int number() const { return m_number; } |
|
1149 |
void setNumber(int number) { m_number = number; } |
|
1150 |
||
1151 |
QString string() const { return m_string; } |
|
1152 |
void setString(const QString &string) { m_string = string; } |
|
1153 |
||
1154 |
QVariant variant() const { return m_variant; } |
|
1155 |
void setVariant(const QVariant &variant) { m_variant = variant; } |
|
1156 |
||
1157 |
CustomType *custom() const { return m_custom; } |
|
1158 |
void setCustom(CustomType *custom) { m_custom = custom; } |
|
1159 |
||
1160 |
void setMyFloat(float value) { m_float = value; } |
|
1161 |
inline float myFloat() const { return m_float; } |
|
1162 |
||
1163 |
void setMyQReal(qreal value) { m_qreal = value; } |
|
1164 |
qreal myQReal() const { return m_qreal; } |
|
1165 |
||
1166 |
private: |
|
1167 |
Alpha m_alpha; |
|
1168 |
Priority m_priority; |
|
1169 |
int m_number; |
|
1170 |
QString m_string; |
|
1171 |
QVariant m_variant; |
|
1172 |
CustomType *m_custom; |
|
1173 |
float m_float; |
|
1174 |
qreal m_qreal; |
|
1175 |
}; |
|
1176 |
||
1177 |
Q_DECLARE_METATYPE(PropertyObject::Priority) |
|
1178 |
||
1179 |
void tst_QObject::threadSignalEmissionCrash() |
|
1180 |
{ |
|
1181 |
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
|
1182 |
int loopCount = 100; |
|
1183 |
#else |
|
1184 |
int loopCount = 1000; |
|
1185 |
#endif |
|
1186 |
for (int i = 0; i < loopCount; ++i) { |
|
1187 |
QTcpSocket socket; |
|
1188 |
socket.connectToHost("localhost", 80); |
|
1189 |
} |
|
1190 |
} |
|
1191 |
||
1192 |
class TestThread : public QThread |
|
1193 |
{ |
|
1194 |
Q_OBJECT |
|
1195 |
public: |
|
1196 |
inline void run() |
|
1197 |
{ |
|
1198 |
*object = new QObject; |
|
1199 |
*child = new QObject(*object); |
|
1200 |
mutex.lock(); |
|
1201 |
cond.wakeOne(); |
|
1202 |
cond.wait(&mutex); |
|
1203 |
mutex.unlock(); |
|
1204 |
} |
|
1205 |
||
1206 |
QObject **object, **child; |
|
1207 |
QMutex mutex; |
|
1208 |
QWaitCondition cond; |
|
1209 |
}; |
|
1210 |
||
1211 |
void tst_QObject::thread() |
|
1212 |
{ |
|
1213 |
QThread *currentThread = QThread::currentThread(); |
|
1214 |
// the current thread is the same as the QApplication |
|
1215 |
// thread... see tst_QApplication::thread() |
|
1216 |
||
1217 |
{ |
|
1218 |
QObject object; |
|
1219 |
// thread affinity for objects with no parent should be the |
|
1220 |
// current thread |
|
1221 |
QVERIFY(object.thread() != 0); |
|
1222 |
QCOMPARE(object.thread(), currentThread); |
|
1223 |
// children inherit their parent's thread |
|
1224 |
QObject child(&object); |
|
1225 |
QCOMPARE(child.thread(), object.thread()); |
|
1226 |
} |
|
1227 |
||
1228 |
QObject *object = 0; |
|
1229 |
QObject *child = 0; |
|
1230 |
||
1231 |
{ |
|
1232 |
TestThread thr; |
|
1233 |
QVERIFY(thr.thread() != 0); |
|
1234 |
QCOMPARE(thr.thread(), currentThread); |
|
1235 |
||
1236 |
thr.object = &object; |
|
1237 |
thr.child = &child; |
|
1238 |
||
1239 |
thr.mutex.lock(); |
|
1240 |
thr.start(); |
|
1241 |
thr.cond.wait(&thr.mutex); |
|
1242 |
||
1243 |
// thread affinity for an object with no parent should be the |
|
1244 |
// thread in which the object was created |
|
1245 |
QCOMPARE(object->thread(), (QThread *)&thr); |
|
1246 |
// children inherit their parent's thread |
|
1247 |
QCOMPARE(child->thread(), object->thread()); |
|
1248 |
||
1249 |
thr.cond.wakeOne(); |
|
1250 |
thr.mutex.unlock(); |
|
1251 |
thr.wait(); |
|
1252 |
||
1253 |
// even though the thread is no longer running, the affinity |
|
1254 |
// should not change |
|
1255 |
QCOMPARE(object->thread(), (QThread *)&thr); |
|
1256 |
QCOMPARE(child->thread(), object->thread()); |
|
1257 |
} |
|
1258 |
||
1259 |
// the thread has been destroyed, thread affinity should |
|
1260 |
// automatically reset to no thread |
|
1261 |
QCOMPARE(object->thread(), (QThread *)0); |
|
1262 |
QCOMPARE(child->thread(), object->thread()); |
|
1263 |
||
1264 |
delete object; |
|
1265 |
} |
|
1266 |
||
1267 |
class MoveToThreadObject : public QObject |
|
1268 |
{ |
|
1269 |
Q_OBJECT |
|
1270 |
public: |
|
1271 |
QThread *timerEventThread; |
|
1272 |
QThread *customEventThread; |
|
1273 |
QThread *slotThread; |
|
1274 |
||
1275 |
MoveToThreadObject(QObject *parent = 0) |
|
1276 |
: QObject(parent), timerEventThread(0), customEventThread(0), slotThread(0) |
|
1277 |
{ } |
|
1278 |
||
1279 |
void customEvent(QEvent *) |
|
1280 |
{ |
|
1281 |
Q_ASSERT(customEventThread == 0); |
|
1282 |
customEventThread = QThread::currentThread(); |
|
1283 |
emit theSignal(); |
|
1284 |
} |
|
1285 |
||
1286 |
void timerEvent(QTimerEvent *) |
|
1287 |
{ |
|
1288 |
Q_ASSERT(timerEventThread == 0); |
|
1289 |
timerEventThread = QThread::currentThread(); |
|
1290 |
emit theSignal(); |
|
1291 |
} |
|
1292 |
||
1293 |
public slots: |
|
1294 |
void theSlot() |
|
1295 |
{ |
|
1296 |
Q_ASSERT(slotThread == 0); |
|
1297 |
slotThread = QThread::currentThread(); |
|
1298 |
emit theSignal(); |
|
1299 |
} |
|
1300 |
||
1301 |
signals: |
|
1302 |
void theSignal(); |
|
1303 |
}; |
|
1304 |
||
1305 |
class MoveToThreadThread : public QThread |
|
1306 |
{ |
|
1307 |
public: |
|
1308 |
~MoveToThreadThread() |
|
1309 |
{ |
|
1310 |
if (isRunning()) { |
|
1311 |
terminate(); |
|
1312 |
wait(); |
|
1313 |
} |
|
1314 |
} |
|
1315 |
void start() |
|
1316 |
{ |
|
1317 |
QEventLoop eventLoop; |
|
1318 |
connect(this, SIGNAL(started()), &eventLoop, SLOT(quit()), Qt::QueuedConnection); |
|
1319 |
QThread::start(); |
|
1320 |
// wait for thread to start |
|
1321 |
(void) eventLoop.exec(); |
|
1322 |
} |
|
1323 |
void run() |
|
1324 |
{ (void) exec(); } |
|
1325 |
}; |
|
1326 |
||
1327 |
void tst_QObject::thread0() |
|
1328 |
{ |
|
1329 |
QObject *object = new QObject; |
|
1330 |
object->moveToThread(0); |
|
1331 |
QObject *child = new QObject(object); |
|
1332 |
QCOMPARE(child->parent(), object); |
|
1333 |
QCOMPARE(child->thread(), (QThread *)0); |
|
1334 |
||
1335 |
#if 0 |
|
1336 |
// We don't support moving children into a parent that has no thread |
|
1337 |
// affinity (yet?). |
|
1338 |
QObject *child2 = new QObject; |
|
1339 |
child2->moveToThread(0); |
|
1340 |
child2->setParent(object); |
|
1341 |
QCOMPARE(child2->parent(), object); |
|
1342 |
QCOMPARE(child2->thread(), (QThread *)0); |
|
1343 |
#endif |
|
1344 |
||
1345 |
delete object; |
|
1346 |
} |
|
1347 |
||
1348 |
void tst_QObject::moveToThread() |
|
1349 |
{ |
|
1350 |
QThread *currentThread = QThread::currentThread(); |
|
1351 |
||
1352 |
{ |
|
1353 |
QObject *object = new QObject; |
|
1354 |
QObject *child = new QObject(object); |
|
1355 |
QCOMPARE(object->thread(), currentThread); |
|
1356 |
QCOMPARE(child->thread(), currentThread); |
|
1357 |
object->moveToThread(0); |
|
1358 |
QCOMPARE(object->thread(), (QThread *)0); |
|
1359 |
QCOMPARE(child->thread(), (QThread *)0); |
|
1360 |
object->moveToThread(currentThread); |
|
1361 |
QCOMPARE(object->thread(), currentThread); |
|
1362 |
QCOMPARE(child->thread(), currentThread); |
|
1363 |
object->moveToThread(0); |
|
1364 |
QCOMPARE(object->thread(), (QThread *)0); |
|
1365 |
QCOMPARE(child->thread(), (QThread *)0); |
|
1366 |
// can delete an object with no thread anywhere |
|
1367 |
delete object; |
|
1368 |
} |
|
1369 |
||
1370 |
{ |
|
1371 |
MoveToThreadThread thread; |
|
1372 |
thread.start(); |
|
1373 |
||
1374 |
QObject *object = new QObject; |
|
1375 |
QObject *child = new QObject(object); |
|
1376 |
QPointer<QObject> opointer = object; |
|
1377 |
QPointer<QObject> cpointer = object; |
|
1378 |
||
1379 |
QCOMPARE(object->thread(), currentThread); |
|
1380 |
QCOMPARE(child->thread(), currentThread); |
|
1381 |
object->moveToThread(&thread); |
|
1382 |
QCOMPARE(object->thread(), (QThread *)&thread); |
|
1383 |
QCOMPARE(child->thread(), (QThread *)&thread); |
|
1384 |
||
1385 |
connect(object, SIGNAL(destroyed()), &thread, SLOT(quit()), Qt::DirectConnection); |
|
1386 |
QMetaObject::invokeMethod(object, "deleteLater", Qt::QueuedConnection); |
|
1387 |
thread.wait(); |
|
1388 |
||
1389 |
QVERIFY(opointer == 0); |
|
1390 |
QVERIFY(cpointer == 0); |
|
1391 |
} |
|
1392 |
||
1393 |
{ |
|
1394 |
// make sure posted events are moved with the object |
|
1395 |
MoveToThreadThread thread; |
|
1396 |
thread.start(); |
|
1397 |
||
1398 |
MoveToThreadObject *object = new MoveToThreadObject; |
|
1399 |
MoveToThreadObject *child = new MoveToThreadObject(object); |
|
1400 |
||
1401 |
connect(object, SIGNAL(theSignal()), &thread, SLOT(quit()), Qt::DirectConnection); |
|
1402 |
QCoreApplication::postEvent(child, new QEvent(QEvent::User)); |
|
1403 |
QCoreApplication::postEvent(object, new QEvent(QEvent::User)); |
|
1404 |
||
1405 |
QCOMPARE(object->thread(), currentThread); |
|
1406 |
QCOMPARE(child->thread(), currentThread); |
|
1407 |
object->moveToThread(&thread); |
|
1408 |
QCOMPARE(object->thread(), (QThread *)&thread); |
|
1409 |
QCOMPARE(child->thread(), (QThread *)&thread); |
|
1410 |
||
1411 |
thread.wait(); |
|
1412 |
||
1413 |
QCOMPARE(object->customEventThread, (QThread *)&thread); |
|
1414 |
QCOMPARE(child->customEventThread, (QThread *)&thread); |
|
1415 |
||
1416 |
thread.start(); |
|
1417 |
connect(object, SIGNAL(destroyed()), &thread, SLOT(quit()), Qt::DirectConnection); |
|
1418 |
QMetaObject::invokeMethod(object, "deleteLater", Qt::QueuedConnection); |
|
1419 |
thread.wait(); |
|
1420 |
} |
|
1421 |
||
1422 |
{ |
|
1423 |
// make sure timers are moved with the object |
|
1424 |
MoveToThreadThread thread; |
|
1425 |
thread.start(); |
|
1426 |
||
1427 |
MoveToThreadObject *object = new MoveToThreadObject; |
|
1428 |
MoveToThreadObject *child = new MoveToThreadObject(object); |
|
1429 |
||
1430 |
connect(object, SIGNAL(theSignal()), &thread, SLOT(quit()), Qt::DirectConnection); |
|
1431 |
||
1432 |
#if defined(Q_OS_SYMBIAN) |
|
1433 |
// Child timer will be registered after parent timer in the new |
|
1434 |
// thread, and 10ms is less than symbian timer resolution, so |
|
1435 |
// child->timerEventThread compare after thread.wait() will |
|
1436 |
// usually fail unless timers are farther apart. |
|
1437 |
child->startTimer(100); |
|
1438 |
object->startTimer(150); |
|
1439 |
#else |
|
1440 |
child->startTimer(90); |
|
1441 |
object->startTimer(100); |
|
1442 |
#endif |
|
1443 |
||
1444 |
QCOMPARE(object->thread(), currentThread); |
|
1445 |
QCOMPARE(child->thread(), currentThread); |
|
1446 |
object->moveToThread(&thread); |
|
1447 |
QCOMPARE(object->thread(), (QThread *)&thread); |
|
1448 |
QCOMPARE(child->thread(), (QThread *)&thread); |
|
1449 |
||
1450 |
thread.wait(); |
|
1451 |
||
1452 |
QCOMPARE(object->timerEventThread, (QThread *)&thread); |
|
1453 |
QCOMPARE(child->timerEventThread, (QThread *)&thread); |
|
1454 |
||
1455 |
thread.start(); |
|
1456 |
connect(object, SIGNAL(destroyed()), &thread, SLOT(quit()), Qt::DirectConnection); |
|
1457 |
QMetaObject::invokeMethod(object, "deleteLater", Qt::QueuedConnection); |
|
1458 |
thread.wait(); |
|
1459 |
} |
|
1460 |
||
1461 |
{ |
|
1462 |
// make sure socket notifiers are moved with the object |
|
1463 |
MoveToThreadThread thread; |
|
1464 |
thread.start(); |
|
1465 |
||
1466 |
QTcpServer server; |
|
1467 |
QVERIFY(server.listen(QHostAddress::LocalHost, 0)); |
|
1468 |
QTcpSocket *socket = new QTcpSocket; |
|
1469 |
MoveToThreadObject *child = new MoveToThreadObject(socket); |
|
1470 |
connect(socket, SIGNAL(disconnected()), child, SLOT(theSlot()), Qt::DirectConnection); |
|
1471 |
connect(child, SIGNAL(theSignal()), &thread, SLOT(quit()), Qt::DirectConnection); |
|
1472 |
||
1473 |
socket->connectToHost(server.serverAddress(), server.serverPort()); |
|
1474 |
||
1475 |
QVERIFY(server.waitForNewConnection(1000)); |
|
1476 |
QTcpSocket *serverSocket = server.nextPendingConnection(); |
|
1477 |
QVERIFY(serverSocket); |
|
1478 |
||
1479 |
socket->waitForConnected(); |
|
1480 |
||
1481 |
QCOMPARE(socket->thread(), currentThread); |
|
1482 |
socket->moveToThread(&thread); |
|
1483 |
QCOMPARE(socket->thread(), (QThread *)&thread); |
|
1484 |
||
1485 |
serverSocket->close(); |
|
1486 |
||
1487 |
QVERIFY(thread.wait(10000)); |
|
1488 |
||
1489 |
QCOMPARE(child->slotThread, (QThread *)&thread); |
|
1490 |
||
1491 |
thread.start(); |
|
1492 |
connect(socket, SIGNAL(destroyed()), &thread, SLOT(quit()), Qt::DirectConnection); |
|
1493 |
QMetaObject::invokeMethod(socket, "deleteLater", Qt::QueuedConnection); |
|
1494 |
thread.wait(); |
|
1495 |
} |
|
1496 |
} |
|
1497 |
||
1498 |
||
1499 |
void tst_QObject::property() |
|
1500 |
{ |
|
1501 |
PropertyObject object; |
|
1502 |
const QMetaObject *mo = object.metaObject(); |
|
1503 |
QMetaProperty property; |
|
1504 |
QVERIFY(mo); |
|
1505 |
||
1506 |
QVERIFY(mo->indexOfProperty("alpha") != -1); |
|
1507 |
property = mo->property(mo->indexOfProperty("alpha")); |
|
1508 |
QVERIFY(property.isEnumType()); |
|
1509 |
QCOMPARE(property.typeName(), "Alpha"); |
|
1510 |
QCOMPARE(property.type(), QVariant::Int); |
|
1511 |
||
1512 |
QVariant var = object.property("alpha"); |
|
1513 |
QVERIFY(!var.isNull()); |
|
1514 |
QCOMPARE(var.toInt(), int(PropertyObject::Alpha0)); |
|
1515 |
object.setAlpha(PropertyObject::Alpha1); |
|
1516 |
QCOMPARE(object.property("alpha").toInt(), int(PropertyObject::Alpha1)); |
|
1517 |
QVERIFY(object.setProperty("alpha", PropertyObject::Alpha2)); |
|
1518 |
QCOMPARE(object.property("alpha").toInt(), int(PropertyObject::Alpha2)); |
|
1519 |
QVERIFY(object.setProperty("alpha", "Alpha1")); |
|
1520 |
QCOMPARE(object.property("alpha").toInt(), int(PropertyObject::Alpha1)); |
|
1521 |
QVERIFY(!object.setProperty("alpha", QVariant())); |
|
1522 |
||
1523 |
QVERIFY(mo->indexOfProperty("number") != -1); |
|
1524 |
QCOMPARE(object.property("number").toInt(), 0); |
|
1525 |
object.setNumber(24); |
|
1526 |
QCOMPARE(object.property("number"), QVariant(24)); |
|
1527 |
QVERIFY(object.setProperty("number", 12)); |
|
1528 |
QCOMPARE(object.property("number"), QVariant(12)); |
|
1529 |
QVERIFY(object.setProperty("number", "42")); |
|
1530 |
QCOMPARE(object.property("number"), QVariant(42)); |
|
1531 |
||
1532 |
QVERIFY(mo->indexOfProperty("string") != -1); |
|
1533 |
QCOMPARE(object.property("string").toString(), QString()); |
|
1534 |
object.setString("String1"); |
|
1535 |
QCOMPARE(object.property("string"), QVariant("String1")); |
|
1536 |
QVERIFY(object.setProperty("string", "String2")); |
|
1537 |
QCOMPARE(object.property("string"), QVariant("String2")); |
|
1538 |
QVERIFY(!object.setProperty("string", QVariant())); |
|
1539 |
||
1540 |
const int idx = mo->indexOfProperty("variant"); |
|
1541 |
QVERIFY(idx != -1); |
|
1542 |
QVERIFY(mo->property(idx).type() == QVariant::LastType); |
|
1543 |
QCOMPARE(object.property("variant"), QVariant()); |
|
1544 |
QVariant variant1(42); |
|
1545 |
QVariant variant2("string"); |
|
1546 |
object.setVariant(variant1); |
|
1547 |
QCOMPARE(object.property("variant"), variant1); |
|
1548 |
QVERIFY(object.setProperty("variant", variant2)); |
|
1549 |
QCOMPARE(object.variant(), QVariant(variant2)); |
|
1550 |
QCOMPARE(object.property("variant"), variant2); |
|
1551 |
QVERIFY(object.setProperty("variant", QVariant())); |
|
1552 |
QCOMPARE(object.property("variant"), QVariant()); |
|
1553 |
||
1554 |
QVERIFY(mo->indexOfProperty("custom") != -1); |
|
1555 |
property = mo->property(mo->indexOfProperty("custom")); |
|
1556 |
QVERIFY(property.isValid()); |
|
1557 |
QVERIFY(property.isWritable()); |
|
1558 |
QVERIFY(!property.isEnumType()); |
|
1559 |
QCOMPARE(property.typeName(), "CustomType*"); |
|
1560 |
QCOMPARE(property.type(), QVariant::UserType); |
|
1561 |
||
1562 |
CustomType *customPointer = 0; |
|
1563 |
QVariant customVariant = object.property("custom"); |
|
1564 |
customPointer = qVariantValue<CustomType *>(customVariant); |
|
1565 |
QCOMPARE(customPointer, object.custom()); |
|
1566 |
||
1567 |
CustomType custom; |
|
1568 |
customPointer = &custom; |
|
1569 |
qVariantSetValue(customVariant, customPointer); |
|
1570 |
||
1571 |
property = mo->property(mo->indexOfProperty("custom")); |
|
1572 |
QVERIFY(property.isWritable()); |
|
1573 |
QCOMPARE(property.typeName(), "CustomType*"); |
|
1574 |
QCOMPARE(property.type(), QVariant::UserType); |
|
1575 |
||
1576 |
QVERIFY(object.setProperty("custom", customVariant)); |
|
1577 |
QCOMPARE(object.custom(), customPointer); |
|
1578 |
||
1579 |
customVariant = object.property("custom"); |
|
1580 |
customPointer = qVariantValue<CustomType *>(customVariant); |
|
1581 |
QCOMPARE(object.custom(), customPointer); |
|
1582 |
||
1583 |
// this enum property has a meta type, but it's not yet registered, so we know this fails |
|
1584 |
QVERIFY(mo->indexOfProperty("priority") != -1); |
|
1585 |
property = mo->property(mo->indexOfProperty("priority")); |
|
1586 |
QVERIFY(property.isEnumType()); |
|
1587 |
QCOMPARE(property.typeName(), "Priority"); |
|
1588 |
QCOMPARE(property.type(), QVariant::Int); |
|
1589 |
||
1590 |
var = object.property("priority"); |
|
1591 |
QVERIFY(!var.isNull()); |
|
1592 |
QCOMPARE(var.toInt(), int(PropertyObject::High)); |
|
1593 |
object.setPriority(PropertyObject::Low); |
|
1594 |
QCOMPARE(object.property("priority").toInt(), int(PropertyObject::Low)); |
|
1595 |
QVERIFY(object.setProperty("priority", PropertyObject::VeryHigh)); |
|
1596 |
QCOMPARE(object.property("priority").toInt(), int(PropertyObject::VeryHigh)); |
|
1597 |
QVERIFY(object.setProperty("priority", "High")); |
|
1598 |
QCOMPARE(object.property("priority").toInt(), int(PropertyObject::High)); |
|
1599 |
QVERIFY(!object.setProperty("priority", QVariant())); |
|
1600 |
||
1601 |
// now it's registered, so it works as expected |
|
1602 |
int priorityMetaTypeId = qRegisterMetaType<PropertyObject::Priority>("PropertyObject::Priority"); |
|
1603 |
||
1604 |
QVERIFY(mo->indexOfProperty("priority") != -1); |
|
1605 |
property = mo->property(mo->indexOfProperty("priority")); |
|
1606 |
QVERIFY(property.isEnumType()); |
|
1607 |
QCOMPARE(property.typeName(), "Priority"); |
|
1608 |
QCOMPARE(property.type(), QVariant::UserType); |
|
1609 |
QCOMPARE(property.userType(), priorityMetaTypeId); |
|
1610 |
||
1611 |
var = object.property("priority"); |
|
1612 |
QVERIFY(!var.isNull()); |
|
1613 |
QVERIFY(qVariantCanConvert<PropertyObject::Priority>(var)); |
|
1614 |
QCOMPARE(qVariantValue<PropertyObject::Priority>(var), PropertyObject::High); |
|
1615 |
object.setPriority(PropertyObject::Low); |
|
1616 |
QCOMPARE(qVariantValue<PropertyObject::Priority>(object.property("priority")), PropertyObject::Low); |
|
1617 |
QVERIFY(object.setProperty("priority", PropertyObject::VeryHigh)); |
|
1618 |
QCOMPARE(qVariantValue<PropertyObject::Priority>(object.property("priority")), PropertyObject::VeryHigh); |
|
1619 |
QVERIFY(object.setProperty("priority", "High")); |
|
1620 |
QCOMPARE(qVariantValue<PropertyObject::Priority>(object.property("priority")), PropertyObject::High); |
|
1621 |
QVERIFY(!object.setProperty("priority", QVariant())); |
|
1622 |
||
1623 |
var = object.property("priority"); |
|
1624 |
QCOMPARE(qVariantValue<PropertyObject::Priority>(var), PropertyObject::High); |
|
1625 |
object.setPriority(PropertyObject::Low); |
|
1626 |
QCOMPARE(qVariantValue<PropertyObject::Priority>(object.property("priority")), PropertyObject::Low); |
|
1627 |
object.setProperty("priority", var); |
|
1628 |
QCOMPARE(qVariantValue<PropertyObject::Priority>(object.property("priority")), PropertyObject::High); |
|
1629 |
} |
|
1630 |
||
1631 |
void tst_QObject::metamethod() |
|
1632 |
{ |
|
1633 |
SenderObject obj; |
|
1634 |
const QMetaObject *mobj = obj.metaObject(); |
|
1635 |
QMetaMethod m; |
|
1636 |
||
1637 |
m = mobj->method(mobj->indexOfMethod("invoke1()")); |
|
1638 |
QVERIFY(QByteArray(m.signature()) == "invoke1()"); |
|
1639 |
QVERIFY(m.methodType() == QMetaMethod::Method); |
|
1640 |
QVERIFY(m.access() == QMetaMethod::Public); |
|
1641 |
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable)); |
|
1642 |
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility)); |
|
1643 |
||
1644 |
m = mobj->method(mobj->indexOfMethod("sinvoke1()")); |
|
1645 |
QVERIFY(QByteArray(m.signature()) == "sinvoke1()"); |
|
1646 |
QVERIFY(m.methodType() == QMetaMethod::Method); |
|
1647 |
QVERIFY(m.access() == QMetaMethod::Public); |
|
1648 |
QVERIFY((m.attributes() & QMetaMethod::Scriptable)); |
|
1649 |
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility)); |
|
1650 |
||
1651 |
m = mobj->method(mobj->indexOfMethod("invoke2()")); |
|
1652 |
QVERIFY(QByteArray(m.signature()) == "invoke2()"); |
|
1653 |
QVERIFY(m.methodType() == QMetaMethod::Method); |
|
1654 |
QVERIFY(m.access() == QMetaMethod::Protected); |
|
1655 |
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable)); |
|
1656 |
QVERIFY((m.attributes() & QMetaMethod::Compatibility)); |
|
1657 |
||
1658 |
m = mobj->method(mobj->indexOfMethod("sinvoke2()")); |
|
1659 |
QVERIFY(QByteArray(m.signature()) == "sinvoke2()"); |
|
1660 |
QVERIFY(m.methodType() == QMetaMethod::Method); |
|
1661 |
QVERIFY(m.access() == QMetaMethod::Protected); |
|
1662 |
QVERIFY((m.attributes() & QMetaMethod::Scriptable)); |
|
1663 |
QVERIFY((m.attributes() & QMetaMethod::Compatibility)); |
|
1664 |
||
1665 |
m = mobj->method(mobj->indexOfMethod("invoke3()")); |
|
1666 |
QVERIFY(QByteArray(m.signature()) == "invoke3()"); |
|
1667 |
QVERIFY(m.methodType() == QMetaMethod::Method); |
|
1668 |
QVERIFY(m.access() == QMetaMethod::Private); |
|
1669 |
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable)); |
|
1670 |
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility)); |
|
1671 |
||
1672 |
m = mobj->method(mobj->indexOfMethod("sinvoke3()")); |
|
1673 |
QVERIFY(QByteArray(m.signature()) == "sinvoke3()"); |
|
1674 |
QVERIFY(m.methodType() == QMetaMethod::Method); |
|
1675 |
QVERIFY(m.access() == QMetaMethod::Private); |
|
1676 |
QVERIFY((m.attributes() & QMetaMethod::Scriptable)); |
|
1677 |
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility)); |
|
1678 |
||
1679 |
m = mobj->method(mobj->indexOfMethod("signal5()")); |
|
1680 |
QVERIFY(QByteArray(m.signature()) == "signal5()"); |
|
1681 |
QVERIFY(m.methodType() == QMetaMethod::Signal); |
|
1682 |
QVERIFY(m.access() == QMetaMethod::Protected); |
|
1683 |
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable)); |
|
1684 |
QVERIFY((m.attributes() & QMetaMethod::Compatibility)); |
|
1685 |
||
1686 |
m = mobj->method(mobj->indexOfMethod("aPublicSlot()")); |
|
1687 |
QVERIFY(QByteArray(m.signature()) == "aPublicSlot()"); |
|
1688 |
QVERIFY(m.methodType() == QMetaMethod::Slot); |
|
1689 |
QVERIFY(m.access() == QMetaMethod::Public); |
|
1690 |
QVERIFY(!(m.attributes() & QMetaMethod::Scriptable)); |
|
1691 |
QVERIFY(!(m.attributes() & QMetaMethod::Compatibility)); |
|
1692 |
||
1693 |
m = mobj->method(mobj->indexOfMethod("invoke1()")); |
|
1694 |
QCOMPARE(m.parameterNames().count(), 0); |
|
1695 |
QCOMPARE(m.parameterTypes().count(), 0); |
|
1696 |
||
1697 |
m = mobj->method(mobj->indexOfMethod("invoke2(int)")); |
|
1698 |
QCOMPARE(m.parameterNames().count(), 1); |
|
1699 |
QCOMPARE(m.parameterTypes().count(), 1); |
|
1700 |
QCOMPARE(m.parameterTypes().at(0), QByteArray("int")); |
|
1701 |
QVERIFY(m.parameterNames().at(0).isEmpty()); |
|
1702 |
||
1703 |
m = mobj->method(mobj->indexOfMethod("invoke3(int,int)")); |
|
1704 |
QCOMPARE(m.parameterNames().count(), 2); |
|
1705 |
QCOMPARE(m.parameterTypes().count(), 2); |
|
1706 |
QCOMPARE(m.parameterTypes().at(0), QByteArray("int")); |
|
1707 |
QCOMPARE(m.parameterNames().at(0), QByteArray("hinz")); |
|
1708 |
QCOMPARE(m.parameterTypes().at(1), QByteArray("int")); |
|
1709 |
QCOMPARE(m.parameterNames().at(1), QByteArray("kunz")); |
|
1710 |
||
1711 |
} |
|
1712 |
||
1713 |
namespace QObjectTest |
|
1714 |
{ |
|
1715 |
class TestObject: public QObject |
|
1716 |
{ |
|
1717 |
Q_OBJECT |
|
1718 |
public: |
|
1719 |
TestObject(): QObject(), i(0) {} |
|
1720 |
void doEmit() { emit aSignal(); } |
|
1721 |
int i; |
|
1722 |
public slots: |
|
1723 |
void aSlot() { ++i; } |
|
1724 |
signals: |
|
1725 |
void aSignal(); |
|
1726 |
}; |
|
1727 |
} |
|
1728 |
||
1729 |
void tst_QObject::namespaces() |
|
1730 |
{ |
|
1731 |
QObjectTest::TestObject obj; |
|
1732 |
||
1733 |
QVERIFY(connect(&obj, SIGNAL(aSignal()), &obj, SLOT(aSlot()))); |
|
1734 |
obj.doEmit(); |
|
1735 |
QCOMPARE(obj.i, 1); |
|
1736 |
} |
|
1737 |
||
1738 |
class SuperObject : public QObject |
|
1739 |
{ |
|
1740 |
Q_OBJECT |
|
1741 |
public: |
|
1742 |
QObject *theSender; |
|
1743 |
SuperObject() |
|
1744 |
{ |
|
1745 |
theSender = 0; |
|
1746 |
} |
|
1747 |
||
1748 |
friend class tst_QObject; |
|
1749 |
||
1750 |
using QObject::sender; |
|
1751 |
||
1752 |
public slots: |
|
1753 |
void rememberSender() |
|
1754 |
{ |
|
1755 |
theSender = sender(); |
|
1756 |
} |
|
1757 |
||
1758 |
void deleteAndRememberSender() |
|
1759 |
{ |
|
1760 |
delete theSender; |
|
1761 |
theSender = sender(); |
|
1762 |
} |
|
1763 |
signals: |
|
1764 |
void theSignal(); |
|
1765 |
||
1766 |
}; |
|
1767 |
||
1768 |
void tst_QObject::sender() |
|
1769 |
{ |
|
1770 |
{ |
|
1771 |
SuperObject sender; |
|
1772 |
SuperObject receiver; |
|
1773 |
connect(&sender, SIGNAL(theSignal()), |
|
1774 |
&receiver, SLOT(rememberSender())); |
|
1775 |
QCOMPARE(receiver.sender(), (QObject *)0); |
|
1776 |
emit sender.theSignal(); |
|
1777 |
QCOMPARE(receiver.theSender, (QObject *)&sender); |
|
1778 |
QCOMPARE(receiver.sender(), (QObject *)0); |
|
1779 |
} |
|
1780 |
||
1781 |
{ |
|
1782 |
SuperObject *sender = new SuperObject; |
|
1783 |
SuperObject *receiver = new SuperObject; |
|
1784 |
connect(sender, SIGNAL(theSignal()), |
|
1785 |
receiver, SLOT(rememberSender()), |
|
1786 |
Qt::BlockingQueuedConnection); |
|
1787 |
||
1788 |
QThread thread; |
|
1789 |
receiver->moveToThread(&thread); |
|
1790 |
connect(sender, SIGNAL(theSignal()), |
|
1791 |
&thread, SLOT(quit()), |
|
1792 |
Qt::DirectConnection); |
|
1793 |
||
1794 |
QCOMPARE(receiver->sender(), (QObject *)0); |
|
1795 |
receiver->theSender = 0; |
|
1796 |
thread.start(); |
|
1797 |
emit sender->theSignal(); |
|
1798 |
QCOMPARE(receiver->theSender, (QObject *) sender); |
|
1799 |
QCOMPARE(receiver->sender(), (QObject *)0); |
|
1800 |
||
1801 |
QVERIFY(thread.wait(10000)); |
|
1802 |
delete receiver; |
|
1803 |
delete sender; |
|
1804 |
} |
|
1805 |
||
1806 |
{ |
|
1807 |
SuperObject *sender = new SuperObject; |
|
1808 |
SuperObject receiver; |
|
1809 |
connect(sender, SIGNAL(theSignal()), |
|
1810 |
&receiver, SLOT(deleteAndRememberSender())); |
|
1811 |
QCOMPARE(receiver.sender(), (QObject *)0); |
|
1812 |
receiver.theSender = sender; |
|
1813 |
emit sender->theSignal(); |
|
1814 |
QCOMPARE(receiver.theSender, (QObject *)0); |
|
1815 |
QCOMPARE(receiver.sender(), (QObject *)0); |
|
1816 |
} |
|
1817 |
||
1818 |
{ |
|
1819 |
SuperObject *sender = new SuperObject; |
|
1820 |
SuperObject *receiver = new SuperObject; |
|
1821 |
connect(sender, SIGNAL(theSignal()), |
|
1822 |
receiver, SLOT(deleteAndRememberSender()), |
|
1823 |
Qt::BlockingQueuedConnection); |
|
1824 |
||
1825 |
QThread thread; |
|
1826 |
receiver->moveToThread(&thread); |
|
1827 |
connect(sender, SIGNAL(destroyed()), |
|
1828 |
&thread, SLOT(quit()), |
|
1829 |
Qt::DirectConnection); |
|
1830 |
||
1831 |
QCOMPARE(receiver->sender(), (QObject *)0); |
|
1832 |
receiver->theSender = sender; |
|
1833 |
thread.start(); |
|
1834 |
emit sender->theSignal(); |
|
1835 |
QCOMPARE(receiver->theSender, (QObject *)0); |
|
1836 |
QCOMPARE(receiver->sender(), (QObject *)0); |
|
1837 |
||
1838 |
QVERIFY(thread.wait(10000)); |
|
1839 |
delete receiver; |
|
1840 |
} |
|
1841 |
} |
|
1842 |
||
1843 |
namespace Foo |
|
1844 |
{ |
|
1845 |
struct Bar |
|
1846 |
{ |
|
1847 |
virtual ~Bar() {} |
|
1848 |
virtual int rtti() const = 0; |
|
1849 |
}; |
|
1850 |
||
1851 |
struct Bleh |
|
1852 |
{ |
|
1853 |
virtual ~Bleh() {} |
|
1854 |
virtual int rtti() const = 0; |
|
1855 |
}; |
|
1856 |
} |
|
1857 |
||
1858 |
QT_BEGIN_NAMESPACE |
|
1859 |
Q_DECLARE_INTERFACE(Foo::Bar, "com.qtest.foobar") |
|
1860 |
QT_END_NAMESPACE |
|
1861 |
||
1862 |
#define Bleh_iid "com.qtest.bleh" |
|
1863 |
QT_BEGIN_NAMESPACE |
|
1864 |
Q_DECLARE_INTERFACE(Foo::Bleh, Bleh_iid) |
|
1865 |
QT_END_NAMESPACE |
|
1866 |
||
1867 |
class FooObject: public QObject, public Foo::Bar |
|
1868 |
{ |
|
1869 |
Q_OBJECT |
|
1870 |
Q_INTERFACES(Foo::Bar) |
|
1871 |
public: |
|
1872 |
int rtti() const { return 42; } |
|
1873 |
}; |
|
1874 |
||
1875 |
class BlehObject : public QObject, public Foo::Bleh |
|
1876 |
{ |
|
1877 |
Q_OBJECT |
|
1878 |
Q_INTERFACES(Foo::Bleh) |
|
1879 |
public: |
|
1880 |
int rtti() const { return 43; } |
|
1881 |
}; |
|
1882 |
||
1883 |
void tst_QObject::declareInterface() |
|
1884 |
{ |
|
1885 |
FooObject obj; |
|
1886 |
||
1887 |
Foo::Bar *bar = qobject_cast<Foo::Bar *>(&obj); |
|
1888 |
QVERIFY(bar); |
|
1889 |
QCOMPARE(bar->rtti(), 42); |
|
1890 |
QCOMPARE(static_cast<Foo::Bar *>(&obj), bar); |
|
1891 |
||
1892 |
BlehObject bleh; |
|
1893 |
||
1894 |
bar = qobject_cast<Foo::Bar *>(&bleh); |
|
1895 |
QVERIFY(!bar); |
|
1896 |
Foo::Bleh *b = qobject_cast<Foo::Bleh *>(&bleh); |
|
1897 |
QCOMPARE(b->rtti(), 43); |
|
1898 |
QCOMPARE(static_cast<Foo::Bleh *>(&bleh), b); |
|
1899 |
||
1900 |
} |
|
1901 |
||
1902 |
class CustomData : public QObjectUserData |
|
1903 |
{ |
|
1904 |
public: |
|
1905 |
int id; |
|
1906 |
}; |
|
1907 |
||
1908 |
void tst_QObject::testUserData() |
|
1909 |
{ |
|
1910 |
const int USER_DATA_COUNT = 100; |
|
1911 |
int user_data_ids[USER_DATA_COUNT]; |
|
1912 |
||
1913 |
// Register a few |
|
1914 |
for (int i=0; i<USER_DATA_COUNT; ++i) { |
|
1915 |
user_data_ids[i] = QObject::registerUserData(); |
|
1916 |
} |
|
1917 |
||
1918 |
// Randomize the table a bit |
|
1919 |
for (int i=0; i<100; ++i) { |
|
1920 |
int p1 = rand() % USER_DATA_COUNT; |
|
1921 |
int p2 = rand() % USER_DATA_COUNT; |
|
1922 |
||
1923 |
int tmp = user_data_ids[p1]; |
|
1924 |
user_data_ids[p1] = user_data_ids[p2]; |
|
1925 |
user_data_ids[p2] = tmp; |
|
1926 |
} |
|
1927 |
||
1928 |
// insert the user data into an object |
|
1929 |
QObject my_test_object; |
|
1930 |
for (int i=0; i<USER_DATA_COUNT; ++i) { |
|
1931 |
CustomData *data = new CustomData; |
|
1932 |
data->id = user_data_ids[i]; |
|
1933 |
my_test_object.setUserData(data->id, data); |
|
1934 |
} |
|
1935 |
||
1936 |
// verify that all ids and positions are matching |
|
1937 |
for (int i=0; i<USER_DATA_COUNT; ++i) { |
|
1938 |
int id = user_data_ids[i]; |
|
1939 |
CustomData *data = static_cast<CustomData *>(my_test_object.userData(id)); |
|
1940 |
QVERIFY(data != 0); |
|
1941 |
QVERIFY(data->id == id); |
|
1942 |
} |
|
1943 |
} |
|
1944 |
||
1945 |
class DestroyedListener : public QObject |
|
1946 |
{ |
|
1947 |
Q_OBJECT |
|
1948 |
public: |
|
1949 |
inline DestroyedListener() : pointerWasZero(false) {} |
|
1950 |
||
1951 |
QPointer<QObject> pointer; |
|
1952 |
bool pointerWasZero; |
|
1953 |
||
1954 |
private slots: |
|
1955 |
inline void otherObjectDestroyed() |
|
1956 |
{ pointerWasZero = pointer.isNull(); } |
|
1957 |
}; |
|
1958 |
||
1959 |
void tst_QObject::qpointerResetBeforeDestroyedSignal() |
|
1960 |
{ |
|
1961 |
QObject *obj = new QObject; |
|
1962 |
DestroyedListener listener; |
|
1963 |
listener.pointer = obj; |
|
1964 |
listener.pointerWasZero = false; |
|
1965 |
connect(obj, SIGNAL(destroyed()), &listener, SLOT(otherObjectDestroyed())); |
|
1966 |
delete obj; |
|
1967 |
QVERIFY(listener.pointerWasZero); |
|
1968 |
QVERIFY(listener.pointer.isNull()); |
|
1969 |
} |
|
1970 |
||
1971 |
class DefaultArguments : public QObject |
|
1972 |
{ |
|
1973 |
Q_OBJECT |
|
1974 |
||
1975 |
public slots: |
|
1976 |
||
1977 |
void theSlot(const QString &s) { result = s; } |
|
1978 |
||
1979 |
signals: |
|
1980 |
void theOriginalSignal(); |
|
1981 |
void theSecondSignal(const QString &s = QString("secondDefault")); |
|
1982 |
||
1983 |
public: |
|
1984 |
||
1985 |
void emitTheOriginalSignal() { emit theOriginalSignal(); } |
|
1986 |
void emitTheSecondSignal() { emit theSecondSignal(); } |
|
1987 |
QString result; |
|
1988 |
}; |
|
1989 |
||
1990 |
void tst_QObject::connectSignalsToSignalsWithDefaultArguments() |
|
1991 |
{ |
|
1992 |
DefaultArguments o; |
|
1993 |
connect(&o, SIGNAL(theOriginalSignal()), &o, SIGNAL(theSecondSignal())); |
|
1994 |
connect(&o, SIGNAL(theSecondSignal(QString)), &o, SLOT(theSlot(QString))); |
|
1995 |
QVERIFY( o.result.isEmpty() ); |
|
1996 |
o.emitTheSecondSignal(); |
|
1997 |
QCOMPARE(o.result, QString("secondDefault")); |
|
1998 |
o.result = "Not called"; |
|
1999 |
o.emitTheOriginalSignal(); |
|
2000 |
QCOMPARE(o.result, QString("secondDefault")); |
|
2001 |
||
2002 |
} |
|
2003 |
||
2004 |
void tst_QObject::receivers() |
|
2005 |
{ |
|
2006 |
class Object : public QObject |
|
2007 |
{ |
|
2008 |
public: |
|
2009 |
int receivers(const char* signal) const |
|
2010 |
{ return QObject::receivers(signal); } |
|
2011 |
}; |
|
2012 |
||
2013 |
Object object; |
|
2014 |
QCOMPARE(object.receivers(SIGNAL(destroyed())), 0); |
|
2015 |
object.connect(&object, SIGNAL(destroyed()), SLOT(deleteLater())); |
|
2016 |
QCOMPARE(object.receivers(SIGNAL(destroyed())), 1); |
|
2017 |
object.connect(&object, SIGNAL(destroyed()), SLOT(deleteLater())); |
|
2018 |
QCOMPARE(object.receivers(SIGNAL(destroyed())), 2); |
|
2019 |
object.disconnect(SIGNAL(destroyed()), &object, SLOT(deleteLater())); |
|
2020 |
QCOMPARE(object.receivers(SIGNAL(destroyed())), 0); |
|
2021 |
} |
|
2022 |
||
2023 |
enum Enum { }; |
|
2024 |
||
2025 |
struct Struct { }; |
|
2026 |
class Class { }; |
|
2027 |
||
2028 |
class NormalizeObject : public QObject |
|
2029 |
{ |
|
2030 |
Q_OBJECT |
|
2031 |
||
2032 |
public: |
|
2033 |
||
2034 |
signals: |
|
2035 |
void uintPointerSignal(uint *); |
|
2036 |
void ulongPointerSignal(ulong *); |
|
2037 |
void constUintPointerSignal(const uint *); |
|
2038 |
void constUlongPointerSignal(const ulong *); |
|
2039 |
||
2040 |
void structSignal(Struct s); |
|
2041 |
void classSignal(Class c); |
|
2042 |
void enumSignal(Enum e); |
|
2043 |
||
2044 |
void structPointerSignal(Struct *s); |
|
2045 |
void classPointerSignal(Class *c); |
|
2046 |
void enumPointerSignal(Enum *e); |
|
2047 |
||
2048 |
void constStructPointerSignal(const Struct *s); |
|
2049 |
void constClassPointerSignal(const Class *c); |
|
2050 |
void constEnumPointerSignal(const Enum *e); |
|
2051 |
||
2052 |
void constStructPointerConstPointerSignal(const Struct * const *s); |
|
2053 |
void constClassPointerConstPointerSignal(const Class * const *c); |
|
2054 |
void constEnumPointerConstPointerSignal(const Enum * const *e); |
|
2055 |
||
2056 |
void unsignedintSignal(unsigned int); |
|
2057 |
void unsignedSignal(unsigned); |
|
2058 |
void unsignedlongSignal(unsigned long); |
|
2059 |
void unsignedlonglongSignal(quint64); |
|
2060 |
void unsignedlongintSignal(unsigned long int); |
|
2061 |
void unsignedshortSignal(unsigned short); |
|
2062 |
void unsignedcharSignal(unsigned char); |
|
2063 |
||
2064 |
public slots: |
|
2065 |
void uintPointerSlot(uint *) { } |
|
2066 |
void ulongPointerSlot(ulong *) { } |
|
2067 |
void constUintPointerSlot(const uint *) { } |
|
2068 |
void constUlongPointerSlot(const ulong *) { } |
|
2069 |
||
2070 |
void structSlot(Struct s) { } |
|
2071 |
void classSlot(Class c) { } |
|
2072 |
void enumSlot(Enum e) { } |
|
2073 |
||
2074 |
void structPointerSlot(Struct *s) { } |
|
2075 |
void classPointerSlot(Class *c) { } |
|
2076 |
void enumPointerSlot(Enum *e) { } |
|
2077 |
||
2078 |
void constStructPointerSlot(const Struct *s) { } |
|
2079 |
void constClassPointerSlot(const Class *c) { } |
|
2080 |
void constEnumPointerSlot(const Enum *e) { } |
|
2081 |
||
2082 |
void constStructPointerConstPointerSlot(const Struct * const *s) { } |
|
2083 |
void constClassPointerConstPointerSlot(const Class * const *c) { } |
|
2084 |
void constEnumPointerConstPointerSlot(const Enum * const *e) { } |
|
2085 |
||
2086 |
void uintSlot(uint) {}; |
|
2087 |
void unsignedintSlot(unsigned int) {}; |
|
2088 |
void unsignedSlot(unsigned) {}; |
|
2089 |
void unsignedlongSlot(unsigned long) {}; |
|
2090 |
void unsignedlonglongSlot(quint64) {}; |
|
2091 |
void unsignedlongintSlot(unsigned long int) {}; |
|
2092 |
void unsignedshortSlot(unsigned short) {}; |
|
2093 |
void unsignedcharSlot(unsigned char) {}; |
|
2094 |
||
2095 |
}; |
|
2096 |
||
2097 |
void tst_QObject::normalize() |
|
2098 |
{ |
|
2099 |
NormalizeObject object; |
|
2100 |
||
2101 |
// unsigned int -> uint, unsigned long -> ulong |
|
2102 |
QVERIFY(object.connect(&object, |
|
2103 |
SIGNAL(uintPointerSignal(uint *)), |
|
2104 |
SLOT(uintPointerSlot(uint *)))); |
|
2105 |
QVERIFY(object.connect(&object, |
|
2106 |
SIGNAL(uintPointerSignal(unsigned int *)), |
|
2107 |
SLOT(uintPointerSlot(uint *)))); |
|
2108 |
QVERIFY(object.connect(&object, |
|
2109 |
SIGNAL(uintPointerSignal(uint *)), |
|
2110 |
SLOT(uintPointerSlot(unsigned int *)))); |
|
2111 |
||
2112 |
QVERIFY(object.connect(&object, |
|
2113 |
SIGNAL(constUintPointerSignal(const uint *)), |
|
2114 |
SLOT(constUintPointerSlot(const uint *)))); |
|
2115 |
QVERIFY(object.connect(&object, |
|
2116 |
SIGNAL(constUintPointerSignal(const unsigned int *)), |
|
2117 |
SLOT(constUintPointerSlot(const uint *)))); |
|
2118 |
QVERIFY(object.connect(&object, |
|
2119 |
SIGNAL(constUintPointerSignal(const uint *)), |
|
2120 |
SLOT(constUintPointerSlot(const unsigned int *)))); |
|
2121 |
||
2122 |
QVERIFY(object.connect(&object, |
|
2123 |
SIGNAL(ulongPointerSignal(ulong *)), |
|
2124 |
SLOT(ulongPointerSlot(ulong *)))); |
|
2125 |
QVERIFY(object.connect(&object, |
|
2126 |
SIGNAL(ulongPointerSignal(unsigned long *)), |
|
2127 |
SLOT(ulongPointerSlot(ulong *)))); |
|
2128 |
QVERIFY(object.connect(&object, |
|
2129 |
SIGNAL(ulongPointerSignal(ulong *)), |
|
2130 |
SLOT(ulongPointerSlot(unsigned long *)))); |
|
2131 |
||
2132 |
QVERIFY(object.connect(&object, |
|
2133 |
SIGNAL(constUlongPointerSignal(const ulong *)), |
|
2134 |
SLOT(constUlongPointerSlot(const ulong *)))); |
|
2135 |
QVERIFY(object.connect(&object, |
|
2136 |
SIGNAL(constUlongPointerSignal(const unsigned long *)), |
|
2137 |
SLOT(constUlongPointerSlot(const ulong *)))); |
|
2138 |
QVERIFY(object.connect(&object, |
|
2139 |
SIGNAL(constUlongPointerSignal(const ulong *)), |
|
2140 |
SLOT(constUlongPointerSlot(const unsigned long *)))); |
|
2141 |
||
2142 |
// struct, class, and enum are optional |
|
2143 |
QVERIFY(object.connect(&object, |
|
2144 |
SIGNAL(structSignal(struct Struct)), |
|
2145 |
SLOT(structSlot(struct Struct)))); |
|
2146 |
QVERIFY(object.connect(&object, |
|
2147 |
SIGNAL(structSignal(Struct)), |
|
2148 |
SLOT(structSlot(struct Struct)))); |
|
2149 |
QVERIFY(object.connect(&object, |
|
2150 |
SIGNAL(structSignal(struct Struct)), |
|
2151 |
SLOT(structSlot(Struct)))); |
|
2152 |
QVERIFY(object.connect(&object, |
|
2153 |
SIGNAL(classSignal(class Class)), |
|
2154 |
SLOT(classSlot(class Class)))); |
|
2155 |
QVERIFY(object.connect(&object, |
|
2156 |
SIGNAL(classSignal(Class)), |
|
2157 |
SLOT(classSlot(class Class)))); |
|
2158 |
QVERIFY(object.connect(&object, |
|
2159 |
SIGNAL(classSignal(class Class)), |
|
2160 |
SLOT(classSlot(Class)))); |
|
2161 |
QVERIFY(object.connect(&object, |
|
2162 |
SIGNAL(enumSignal(enum Enum)), |
|
2163 |
SLOT(enumSlot(enum Enum)))); |
|
2164 |
QVERIFY(object.connect(&object, |
|
2165 |
SIGNAL(enumSignal(Enum)), |
|
2166 |
SLOT(enumSlot(enum Enum)))); |
|
2167 |
QVERIFY(object.connect(&object, |
|
2168 |
SIGNAL(enumSignal(enum Enum)), |
|
2169 |
SLOT(enumSlot(Enum)))); |
|
2170 |
||
2171 |
QVERIFY(object.connect(&object, |
|
2172 |
SIGNAL(structPointerSignal(struct Struct *)), |
|
2173 |
SLOT(structPointerSlot(struct Struct *)))); |
|
2174 |
QVERIFY(object.connect(&object, |
|
2175 |
SIGNAL(structPointerSignal(Struct *)), |
|
2176 |
SLOT(structPointerSlot(struct Struct *)))); |
|
2177 |
QVERIFY(object.connect(&object, |
|
2178 |
SIGNAL(structPointerSignal(struct Struct *)), |
|
2179 |
SLOT(structPointerSlot(Struct *)))); |
|
2180 |
QVERIFY(object.connect(&object, |
|
2181 |
SIGNAL(classPointerSignal(class Class *)), |
|
2182 |
SLOT(classPointerSlot(class Class *)))); |
|
2183 |
QVERIFY(object.connect(&object, |
|
2184 |
SIGNAL(classPointerSignal(Class *)), |
|
2185 |
SLOT(classPointerSlot(class Class *)))); |
|
2186 |
QVERIFY(object.connect(&object, |
|
2187 |
SIGNAL(classPointerSignal(class Class *)), |
|
2188 |
SLOT(classPointerSlot(Class *)))); |
|
2189 |
QVERIFY(object.connect(&object, |
|
2190 |
SIGNAL(enumPointerSignal(enum Enum *)), |
|
2191 |
SLOT(enumPointerSlot(enum Enum *)))); |
|
2192 |
QVERIFY(object.connect(&object, |
|
2193 |
SIGNAL(enumPointerSignal(Enum *)), |
|
2194 |
SLOT(enumPointerSlot(enum Enum *)))); |
|
2195 |
QVERIFY(object.connect(&object, |
|
2196 |
SIGNAL(enumPointerSignal(enum Enum *)), |
|
2197 |
SLOT(enumPointerSlot(Enum *)))); |
|
2198 |
||
2199 |
QVERIFY(object.connect(&object, |
|
2200 |
SIGNAL(constStructPointerSignal(const struct Struct *)), |
|
2201 |
SLOT(constStructPointerSlot(const struct Struct *)))); |
|
2202 |
QVERIFY(object.connect(&object, |
|
2203 |
SIGNAL(constStructPointerSignal(const Struct *)), |
|
2204 |
SLOT(constStructPointerSlot(const struct Struct *)))); |
|
2205 |
QVERIFY(object.connect(&object, |
|
2206 |
SIGNAL(constStructPointerSignal(const struct Struct *)), |
|
2207 |
SLOT(constStructPointerSlot(const Struct *)))); |
|
2208 |
QVERIFY(object.connect(&object, |
|
2209 |
SIGNAL(constClassPointerSignal(const class Class *)), |
|
2210 |
SLOT(constClassPointerSlot(const class Class *)))); |
|
2211 |
QVERIFY(object.connect(&object, |
|
2212 |
SIGNAL(constClassPointerSignal(const Class *)), |
|
2213 |
SLOT(constClassPointerSlot(const class Class *)))); |
|
2214 |
QVERIFY(object.connect(&object, |
|
2215 |
SIGNAL(constClassPointerSignal(const class Class *)), |
|
2216 |
SLOT(constClassPointerSlot(const Class *)))); |
|
2217 |
QVERIFY(object.connect(&object, |
|
2218 |
SIGNAL(constEnumPointerSignal(const enum Enum *)), |
|
2219 |
SLOT(constEnumPointerSlot(const enum Enum *)))); |
|
2220 |
QVERIFY(object.connect(&object, |
|
2221 |
SIGNAL(constEnumPointerSignal(const Enum *)), |
|
2222 |
SLOT(constEnumPointerSlot(const enum Enum *)))); |
|
2223 |
QVERIFY(object.connect(&object, |
|
2224 |
SIGNAL(constEnumPointerSignal(const enum Enum *)), |
|
2225 |
SLOT(constEnumPointerSlot(const Enum *)))); |
|
2226 |
||
2227 |
QVERIFY(object.connect(&object, |
|
2228 |
SIGNAL(constStructPointerSignal(struct Struct const *)), |
|
2229 |
SLOT(constStructPointerSlot(struct Struct const *)))); |
|
2230 |
QVERIFY(object.connect(&object, |
|
2231 |
SIGNAL(constStructPointerSignal(Struct const *)), |
|
2232 |
SLOT(constStructPointerSlot(struct Struct const *)))); |
|
2233 |
QVERIFY(object.connect(&object, |
|
2234 |
SIGNAL(constStructPointerSignal(struct Struct const *)), |
|
2235 |
SLOT(constStructPointerSlot(Struct const *)))); |
|
2236 |
QVERIFY(object.connect(&object, |
|
2237 |
SIGNAL(constClassPointerSignal(class Class const *)), |
|
2238 |
SLOT(constClassPointerSlot(class Class const *)))); |
|
2239 |
QVERIFY(object.connect(&object, |
|
2240 |
SIGNAL(constClassPointerSignal(Class const *)), |
|
2241 |
SLOT(constClassPointerSlot(class Class const *)))); |
|
2242 |
QVERIFY(object.connect(&object, |
|
2243 |
SIGNAL(constClassPointerSignal(class Class const *)), |
|
2244 |
SLOT(constClassPointerSlot(Class const *)))); |
|
2245 |
QVERIFY(object.connect(&object, |
|
2246 |
SIGNAL(constEnumPointerSignal(enum Enum const *)), |
|
2247 |
SLOT(constEnumPointerSlot(enum Enum const *)))); |
|
2248 |
QVERIFY(object.connect(&object, |
|
2249 |
SIGNAL(constEnumPointerSignal(Enum const *)), |
|
2250 |
SLOT(constEnumPointerSlot(enum Enum const *)))); |
|
2251 |
QVERIFY(object.connect(&object, |
|
2252 |
SIGNAL(constEnumPointerSignal(enum Enum const *)), |
|
2253 |
SLOT(constEnumPointerSlot(Enum const *)))); |
|
2254 |
||
2255 |
QVERIFY(object.connect(&object, |
|
2256 |
SIGNAL(constStructPointerConstPointerSignal(const struct Struct * const *)), |
|
2257 |
SLOT(constStructPointerConstPointerSlot(const struct Struct * const *)))); |
|
2258 |
QVERIFY(object.connect(&object, |
|
2259 |
SIGNAL(constStructPointerConstPointerSignal(const Struct * const *)), |
|
2260 |
SLOT(constStructPointerConstPointerSlot(const struct Struct * const *)))); |
|
2261 |
QVERIFY(object.connect(&object, |
|
2262 |
SIGNAL(constStructPointerConstPointerSignal(const struct Struct * const *)), |
|
2263 |
SLOT(constStructPointerConstPointerSlot(const Struct * const *)))); |
|
2264 |
QVERIFY(object.connect(&object, |
|
2265 |
SIGNAL(constClassPointerConstPointerSignal(const class Class * const *)), |
|
2266 |
SLOT(constClassPointerConstPointerSlot(const class Class * const *)))); |
|
2267 |
QVERIFY(object.connect(&object, |
|
2268 |
SIGNAL(constClassPointerConstPointerSignal(const Class * const *)), |
|
2269 |
SLOT(constClassPointerConstPointerSlot(const class Class * const *)))); |
|
2270 |
QVERIFY(object.connect(&object, |
|
2271 |
SIGNAL(constClassPointerConstPointerSignal(const class Class * const *)), |
|
2272 |
SLOT(constClassPointerConstPointerSlot(const Class * const *)))); |
|
2273 |
QVERIFY(object.connect(&object, |
|
2274 |
SIGNAL(constEnumPointerConstPointerSignal(const enum Enum * const *)), |
|
2275 |
SLOT(constEnumPointerConstPointerSlot(const enum Enum * const *)))); |
|
2276 |
QVERIFY(object.connect(&object, |
|
2277 |
SIGNAL(constEnumPointerConstPointerSignal(const Enum * const *)), |
|
2278 |
SLOT(constEnumPointerConstPointerSlot(const enum Enum * const *)))); |
|
2279 |
QVERIFY(object.connect(&object, |
|
2280 |
SIGNAL(constEnumPointerConstPointerSignal(const enum Enum * const *)), |
|
2281 |
SLOT(constEnumPointerConstPointerSlot(const Enum * const *)))); |
|
2282 |
||
2283 |
QVERIFY(object.connect(&object, |
|
2284 |
SIGNAL(constStructPointerConstPointerSignal(struct Struct const * const *)), |
|
2285 |
SLOT(constStructPointerConstPointerSlot(struct Struct const * const *)))); |
|
2286 |
QVERIFY(object.connect(&object, |
|
2287 |
SIGNAL(constStructPointerConstPointerSignal(Struct const * const *)), |
|
2288 |
SLOT(constStructPointerConstPointerSlot(struct Struct const * const *)))); |
|
2289 |
QVERIFY(object.connect(&object, |
|
2290 |
SIGNAL(constStructPointerConstPointerSignal(struct Struct const * const *)), |
|
2291 |
SLOT(constStructPointerConstPointerSlot(Struct const * const *)))); |
|
2292 |
QVERIFY(object.connect(&object, |
|
2293 |
SIGNAL(constClassPointerConstPointerSignal(class Class const * const *)), |
|
2294 |
SLOT(constClassPointerConstPointerSlot(class Class const * const *)))); |
|
2295 |
QVERIFY(object.connect(&object, |
|
2296 |
SIGNAL(constClassPointerConstPointerSignal(Class const * const *)), |
|
2297 |
SLOT(constClassPointerConstPointerSlot(class Class const * const *)))); |
|
2298 |
QVERIFY(object.connect(&object, |
|
2299 |
SIGNAL(constClassPointerConstPointerSignal(class Class const * const *)), |
|
2300 |
SLOT(constClassPointerConstPointerSlot(Class const * const *)))); |
|
2301 |
QVERIFY(object.connect(&object, |
|
2302 |
SIGNAL(constEnumPointerConstPointerSignal(enum Enum const * const *)), |
|
2303 |
SLOT(constEnumPointerConstPointerSlot(enum Enum const * const *)))); |
|
2304 |
QVERIFY(object.connect(&object, |
|
2305 |
SIGNAL(constEnumPointerConstPointerSignal(Enum const * const *)), |
|
2306 |
SLOT(constEnumPointerConstPointerSlot(enum Enum const * const *)))); |
|
2307 |
QVERIFY(object.connect(&object, |
|
2308 |
SIGNAL(constEnumPointerConstPointerSignal(enum Enum const * const *)), |
|
2309 |
SLOT(constEnumPointerConstPointerSlot(Enum const * const *)))); |
|
2310 |
||
2311 |
QVERIFY(object.connect(&object, |
|
2312 |
SIGNAL(unsignedintSignal(unsigned int)), |
|
2313 |
SLOT(unsignedintSlot(unsigned int)))); |
|
2314 |
QVERIFY(object.connect(&object, |
|
2315 |
SIGNAL(unsignedSignal(unsigned)), |
|
2316 |
SLOT(unsignedSlot(unsigned)))); |
|
2317 |
QVERIFY(object.connect(&object, |
|
2318 |
SIGNAL(unsignedSignal(unsigned)), |
|
2319 |
SLOT(uintSlot(uint)))); |
|
2320 |
QVERIFY(object.connect(&object, |
|
2321 |
SIGNAL(unsignedlongSignal(unsigned long)), |
|
2322 |
SLOT(unsignedlongSlot(unsigned long)))); |
|
2323 |
QVERIFY(object.connect(&object, |
|
2324 |
SIGNAL(unsignedlonglongSignal(quint64)), |
|
2325 |
SLOT(unsignedlonglongSlot(quint64)))); |
|
2326 |
QVERIFY(object.connect(&object, |
|
2327 |
SIGNAL(unsignedlongintSignal(unsigned long int)), |
|
2328 |
SLOT(unsignedlongintSlot(unsigned long int)))); |
|
2329 |
QVERIFY(object.connect(&object, |
|
2330 |
SIGNAL(unsignedshortSignal(unsigned short)), |
|
2331 |
SLOT(unsignedshortSlot(unsigned short)))); |
|
2332 |
QVERIFY(object.connect(&object, |
|
2333 |
SIGNAL(unsignedcharSignal(unsigned char)), |
|
2334 |
SLOT(unsignedcharSlot(unsigned char)))); |
|
2335 |
||
2336 |
||
2337 |
} |
|
2338 |
||
2339 |
class SiblingDeleter : public QObject |
|
2340 |
{ |
|
2341 |
public: |
|
2342 |
inline SiblingDeleter(QObject *sibling, QObject *parent) |
|
2343 |
: QObject(parent), sibling(sibling) {} |
|
2344 |
inline virtual ~SiblingDeleter() { delete sibling; } |
|
2345 |
||
2346 |
private: |
|
2347 |
QPointer<QObject> sibling; |
|
2348 |
}; |
|
2349 |
||
2350 |
||
2351 |
void tst_QObject::childDeletesItsSibling() |
|
2352 |
{ |
|
2353 |
QObject *commonParent = new QObject(0); |
|
2354 |
QPointer<QObject> child = new QObject(0); |
|
2355 |
QPointer<QObject> siblingDeleter = new SiblingDeleter(child, commonParent); |
|
2356 |
child->setParent(commonParent); |
|
2357 |
delete commonParent; // don't crash |
|
2358 |
QVERIFY(!child); |
|
2359 |
QVERIFY(!siblingDeleter); |
|
2360 |
} |
|
2361 |
||
2362 |
void tst_QObject::floatProperty() |
|
2363 |
{ |
|
2364 |
PropertyObject obj; |
|
2365 |
const int idx = obj.metaObject()->indexOfProperty("myFloat"); |
|
2366 |
QVERIFY(idx > 0); |
|
2367 |
QMetaProperty prop = obj.metaObject()->property(idx); |
|
2368 |
QVERIFY(prop.isValid()); |
|
2369 |
QVERIFY(prop.type() == uint(QMetaType::type("float"))); |
|
2370 |
QVERIFY(!prop.write(&obj, QVariant("Hello"))); |
|
2371 |
QVERIFY(prop.write(&obj, qVariantFromValue(128.0f))); |
|
2372 |
QVariant v = prop.read(&obj); |
|
2373 |
QVERIFY(int(v.userType()) == QMetaType::Float); |
|
2374 |
QVERIFY(qVariantValue<float>(v) == 128.0f); |
|
2375 |
} |
|
2376 |
||
2377 |
void tst_QObject::qrealProperty() |
|
2378 |
{ |
|
2379 |
PropertyObject obj; |
|
2380 |
const int idx = obj.metaObject()->indexOfProperty("myQReal"); |
|
2381 |
QVERIFY(idx > 0); |
|
2382 |
QMetaProperty prop = obj.metaObject()->property(idx); |
|
2383 |
QVERIFY(prop.isValid()); |
|
2384 |
QVERIFY(prop.type() == uint(QMetaType::type("qreal"))); |
|
2385 |
QVERIFY(!prop.write(&obj, QVariant("Hello"))); |
|
2386 |
||
2387 |
QVERIFY(prop.write(&obj, qVariantFromValue(128.0f))); |
|
2388 |
QVariant v = prop.read(&obj); |
|
2389 |
QCOMPARE(v.userType(), qMetaTypeId<qreal>()); |
|
2390 |
QVERIFY(qVariantValue<qreal>(v) == 128.0); |
|
2391 |
||
2392 |
QVERIFY(prop.write(&obj, qVariantFromValue(double(127)))); |
|
2393 |
v = prop.read(&obj); |
|
2394 |
QCOMPARE(v.userType(), qMetaTypeId<qreal>()); |
|
2395 |
QVERIFY(qVariantValue<qreal>(v) == 127.0); |
|
2396 |
} |
|
2397 |
||
2398 |
class DynamicPropertyObject : public PropertyObject |
|
2399 |
{ |
|
2400 |
public: |
|
2401 |
inline DynamicPropertyObject() {} |
|
2402 |
||
2403 |
inline virtual bool event(QEvent *e) { |
|
2404 |
if (e->type() == QEvent::DynamicPropertyChange) { |
|
2405 |
changedDynamicProperties.append(static_cast<QDynamicPropertyChangeEvent *>(e)->propertyName()); |
|
2406 |
} |
|
2407 |
return QObject::event(e); |
|
2408 |
} |
|
2409 |
||
2410 |
QList<QByteArray> changedDynamicProperties; |
|
2411 |
}; |
|
2412 |
||
2413 |
void tst_QObject::dynamicProperties() |
|
2414 |
{ |
|
2415 |
DynamicPropertyObject obj; |
|
2416 |
||
2417 |
QVERIFY(obj.dynamicPropertyNames().isEmpty()); |
|
2418 |
||
2419 |
QVERIFY(obj.setProperty("number", 42)); |
|
2420 |
QVERIFY(obj.changedDynamicProperties.isEmpty()); |
|
2421 |
QCOMPARE(obj.property("number").toInt(), 42); |
|
2422 |
||
2423 |
QVERIFY(!obj.setProperty("number", "invalid string")); |
|
2424 |
QVERIFY(obj.changedDynamicProperties.isEmpty()); |
|
2425 |
||
2426 |
QVERIFY(!obj.setProperty("myuserproperty", "Hello")); |
|
2427 |
QCOMPARE(obj.changedDynamicProperties.count(), 1); |
|
2428 |
QCOMPARE(obj.changedDynamicProperties.first(), QByteArray("myuserproperty")); |
|
2429 |
obj.changedDynamicProperties.clear(); |
|
2430 |
||
2431 |
QCOMPARE(obj.property("myuserproperty").toString(), QString("Hello")); |
|
2432 |
||
2433 |
QCOMPARE(obj.dynamicPropertyNames().count(), 1); |
|
2434 |
QCOMPARE(obj.dynamicPropertyNames().first(), QByteArray("myuserproperty")); |
|
2435 |
||
2436 |
QVERIFY(!obj.setProperty("myuserproperty", QVariant())); |
|
2437 |
||
2438 |
QCOMPARE(obj.changedDynamicProperties.count(), 1); |
|
2439 |
QCOMPARE(obj.changedDynamicProperties.first(), QByteArray("myuserproperty")); |
|
2440 |
obj.changedDynamicProperties.clear(); |
|
2441 |
||
2442 |
QVERIFY(obj.property("myuserproperty").isNull()); |
|
2443 |
||
2444 |
QVERIFY(obj.dynamicPropertyNames().isEmpty()); |
|
2445 |
} |
|
2446 |
||
2447 |
void tst_QObject::recursiveSignalEmission() |
|
2448 |
{ |
|
2449 |
#if defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) |
|
2450 |
QSKIP("Emulator builds in Symbian do not support launching processes linking to Qt", SkipAll); |
|
2451 |
#elif defined(QT_NO_PROCESS) |
|
2452 |
QSKIP("Test requires QProcess", SkipAll); |
|
2453 |
#else |
|
2454 |
QProcess proc; |
|
2455 |
proc.start("./signalbug"); |
|
2456 |
QVERIFY(proc.waitForFinished()); |
|
2457 |
QVERIFY(proc.exitStatus() == QProcess::NormalExit); |
|
2458 |
QCOMPARE(proc.exitCode(), 0); |
|
2459 |
#endif |
|
2460 |
} |
|
2461 |
||
2462 |
void tst_QObject::blockingQueuedConnection() |
|
2463 |
{ |
|
2464 |
{ |
|
2465 |
SenderObject sender; |
|
2466 |
||
2467 |
MoveToThreadThread thread; |
|
2468 |
ReceiverObject receiver; |
|
2469 |
receiver.moveToThread(&thread); |
|
2470 |
thread.start(); |
|
2471 |
||
2472 |
receiver.connect(&sender, SIGNAL(signal1()), SLOT(slot1()), Qt::BlockingQueuedConnection); |
|
2473 |
sender.emitSignal1(); |
|
2474 |
QVERIFY(receiver.called(1)); |
|
2475 |
||
2476 |
receiver.reset(); |
|
2477 |
QVERIFY(QMetaObject::invokeMethod(&receiver, "slot1", Qt::BlockingQueuedConnection)); |
|
2478 |
QVERIFY(receiver.called(1)); |
|
2479 |
||
2480 |
thread.quit(); |
|
2481 |
QVERIFY(thread.wait()); |
|
2482 |
} |
|
2483 |
} |
|
2484 |
||
2485 |
class EventSpy : public QObject |
|
2486 |
{ |
|
2487 |
Q_OBJECT |
|
2488 |
||
2489 |
public: |
|
2490 |
typedef QList<QPair<QObject *, QEvent::Type> > EventList; |
|
2491 |
||
2492 |
EventSpy(QObject *parent = 0) |
|
2493 |
: QObject(parent) |
|
2494 |
{ } |
|
2495 |
||
2496 |
EventList eventList() |
|
2497 |
{ |
|
2498 |
return events; |
|
2499 |
} |
|
2500 |
||
2501 |
void clear() |
|
2502 |
{ |
|
2503 |
events.clear(); |
|
2504 |
} |
|
2505 |
||
2506 |
bool eventFilter(QObject *object, QEvent *event) |
|
2507 |
{ |
|
2508 |
events.append(qMakePair(object, event->type())); |
|
2509 |
return false; |
|
2510 |
} |
|
2511 |
||
2512 |
private: |
|
2513 |
EventList events; |
|
2514 |
}; |
|
2515 |
||
2516 |
void tst_QObject::compatibilityChildInsertedEvents() |
|
2517 |
{ |
|
2518 |
EventSpy::EventList expected; |
|
2519 |
||
2520 |
{ |
|
2521 |
// no children created, so we expect no events |
|
2522 |
QObject object; |
|
2523 |
EventSpy spy; |
|
2524 |
object.installEventFilter(&spy); |
|
2525 |
||
2526 |
QCoreApplication::postEvent(&object, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
2527 |
||
2528 |
QCoreApplication::processEvents(); |
|
2529 |
||
2530 |
expected = |
|
2531 |
EventSpy::EventList() |
|
2532 |
<< qMakePair(&object, QEvent::Type(QEvent::User + 1)); |
|
2533 |
QCOMPARE(spy.eventList(), expected); |
|
2534 |
} |
|
2535 |
||
2536 |
{ |
|
2537 |
// 2 children, so we expect 2 ChildAdded and 2 ChildInserted events |
|
2538 |
QObject object; |
|
2539 |
EventSpy spy; |
|
2540 |
object.installEventFilter(&spy); |
|
2541 |
||
2542 |
QCoreApplication::postEvent(&object, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
2543 |
||
2544 |
QObject child1(&object); |
|
2545 |
QObject child2; |
|
2546 |
child2.setParent(&object); |
|
2547 |
||
2548 |
QCoreApplication::postEvent(&object, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
2549 |
||
2550 |
expected = |
|
2551 |
EventSpy::EventList() |
|
2552 |
<< qMakePair(&object, QEvent::ChildAdded) |
|
2553 |
<< qMakePair(&object, QEvent::ChildAdded); |
|
2554 |
QCOMPARE(spy.eventList(), expected); |
|
2555 |
spy.clear(); |
|
2556 |
||
2557 |
QCoreApplication::processEvents(); |
|
2558 |
||
2559 |
expected = |
|
2560 |
EventSpy::EventList() |
|
2561 |
#ifdef QT_HAS_QT3SUPPORT |
|
2562 |
<< qMakePair(&object, QEvent::ChildInsertedRequest) |
|
2563 |
<< qMakePair(&object, QEvent::ChildInserted) |
|
2564 |
<< qMakePair(&object, QEvent::ChildInserted) |
|
2565 |
#endif |
|
2566 |
<< qMakePair(&object, QEvent::Type(QEvent::User + 1)) |
|
2567 |
<< qMakePair(&object, QEvent::Type(QEvent::User + 2)); |
|
2568 |
QCOMPARE(spy.eventList(), expected); |
|
2569 |
} |
|
2570 |
||
2571 |
{ |
|
2572 |
// 2 children, but one is reparented away, so we expect: |
|
2573 |
// 2 ChildAdded, 1 ChildRemoved, and 1 ChildInserted |
|
2574 |
QObject object; |
|
2575 |
EventSpy spy; |
|
2576 |
object.installEventFilter(&spy); |
|
2577 |
||
2578 |
QCoreApplication::postEvent(&object, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
2579 |
||
2580 |
QObject child1(&object); |
|
2581 |
QObject child2; |
|
2582 |
child2.setParent(&object); |
|
2583 |
child2.setParent(0); |
|
2584 |
||
2585 |
QCoreApplication::postEvent(&object, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
2586 |
||
2587 |
expected = |
|
2588 |
EventSpy::EventList() |
|
2589 |
<< qMakePair(&object, QEvent::ChildAdded) |
|
2590 |
<< qMakePair(&object, QEvent::ChildAdded) |
|
2591 |
<< qMakePair(&object, QEvent::ChildRemoved); |
|
2592 |
QCOMPARE(spy.eventList(), expected); |
|
2593 |
spy.clear(); |
|
2594 |
||
2595 |
QCoreApplication::processEvents(); |
|
2596 |
||
2597 |
expected = |
|
2598 |
EventSpy::EventList() |
|
2599 |
#ifdef QT_HAS_QT3SUPPORT |
|
2600 |
<< qMakePair(&object, QEvent::ChildInsertedRequest) |
|
2601 |
<< qMakePair(&object, QEvent::ChildInserted) |
|
2602 |
#endif |
|
2603 |
<< qMakePair(&object, QEvent::Type(QEvent::User + 1)) |
|
2604 |
<< qMakePair(&object, QEvent::Type(QEvent::User + 2)); |
|
2605 |
QCOMPARE(spy.eventList(), expected); |
|
2606 |
} |
|
2607 |
} |
|
2608 |
||
2609 |
void tst_QObject::installEventFilter() |
|
2610 |
{ |
|
2611 |
QEvent event(QEvent::User); |
|
2612 |
EventSpy::EventList expected; |
|
2613 |
||
2614 |
QObject object; |
|
2615 |
EventSpy spy; |
|
2616 |
object.installEventFilter(&spy); |
|
2617 |
||
2618 |
// nothing special, should just work |
|
2619 |
QCoreApplication::sendEvent(&object, &event); |
|
2620 |
expected = |
|
2621 |
EventSpy::EventList() |
|
2622 |
<< qMakePair(&object, QEvent::User); |
|
2623 |
QCOMPARE(spy.eventList(), expected); |
|
2624 |
spy.clear(); |
|
2625 |
||
2626 |
// moving the filter causes QCoreApplication to skip the filter |
|
2627 |
spy.moveToThread(0); |
|
2628 |
QTest::ignoreMessage(QtWarningMsg, "QCoreApplication: Object event filter cannot be in a different thread."); |
|
2629 |
QCoreApplication::sendEvent(&object, &event); |
|
2630 |
QVERIFY(spy.eventList().isEmpty()); |
|
2631 |
||
2632 |
// move it back, and the filter works again |
|
2633 |
spy.moveToThread(object.thread()); |
|
2634 |
QCoreApplication::sendEvent(&object, &event); |
|
2635 |
expected = |
|
2636 |
EventSpy::EventList() |
|
2637 |
<< qMakePair(&object, QEvent::User); |
|
2638 |
QCOMPARE(spy.eventList(), expected); |
|
2639 |
spy.clear(); |
|
2640 |
||
2641 |
// cannot install an event filter that lives in a different thread |
|
2642 |
object.removeEventFilter(&spy); |
|
2643 |
spy.moveToThread(0); |
|
2644 |
QTest::ignoreMessage(QtWarningMsg, "QObject::installEventFilter(): Cannot filter events for objects in a different thread."); |
|
2645 |
object.installEventFilter(&spy); |
|
2646 |
QCoreApplication::sendEvent(&object, &event); |
|
2647 |
QVERIFY(spy.eventList().isEmpty()); |
|
2648 |
} |
|
2649 |
||
2650 |
class DeleteObject : public QObject |
|
2651 |
{ |
|
2652 |
Q_OBJECT |
|
2653 |
||
2654 |
public slots: |
|
2655 |
void deleteSelf() |
|
2656 |
{ |
|
2657 |
delete this; |
|
2658 |
} |
|
2659 |
||
2660 |
void relaySignalAndProcessEvents() |
|
2661 |
{ |
|
2662 |
emit relayedSignal(); |
|
2663 |
QCoreApplication::processEvents(); |
|
2664 |
} |
|
2665 |
||
2666 |
signals: |
|
2667 |
void relayedSignal(); |
|
2668 |
}; |
|
2669 |
||
2670 |
void tst_QObject::deleteSelfInSlot() |
|
2671 |
{ |
|
2672 |
{ |
|
2673 |
SenderObject sender; |
|
2674 |
DeleteObject *receiver = new DeleteObject(); |
|
2675 |
receiver->connect(&sender, |
|
2676 |
SIGNAL(signal1()), |
|
2677 |
SLOT(deleteSelf()), |
|
2678 |
Qt::BlockingQueuedConnection); |
|
2679 |
||
2680 |
QThread thread; |
|
2681 |
receiver->moveToThread(&thread); |
|
2682 |
thread.connect(receiver, SIGNAL(destroyed()), SLOT(quit()), Qt::DirectConnection); |
|
2683 |
thread.start(); |
|
2684 |
||
2685 |
QPointer<DeleteObject> p = receiver; |
|
2686 |
sender.emitSignal1(); |
|
2687 |
QVERIFY(p.isNull()); |
|
2688 |
||
2689 |
QVERIFY(thread.wait(10000)); |
|
2690 |
} |
|
2691 |
||
2692 |
{ |
|
2693 |
SenderObject sender; |
|
2694 |
DeleteObject *receiver = new DeleteObject(); |
|
2695 |
receiver->connect(&sender, |
|
2696 |
SIGNAL(signal1()), |
|
2697 |
SLOT(relaySignalAndProcessEvents()), |
|
2698 |
Qt::BlockingQueuedConnection); |
|
2699 |
receiver->connect(receiver, |
|
2700 |
SIGNAL(relayedSignal()), |
|
2701 |
SLOT(deleteSelf()), |
|
2702 |
Qt::QueuedConnection); |
|
2703 |
||
2704 |
QThread thread; |
|
2705 |
receiver->moveToThread(&thread); |
|
2706 |
thread.connect(receiver, SIGNAL(destroyed()), SLOT(quit()), Qt::DirectConnection); |
|
2707 |
thread.start(); |
|
2708 |
||
2709 |
QPointer<DeleteObject> p = receiver; |
|
2710 |
sender.emitSignal1(); |
|
2711 |
QVERIFY(p.isNull()); |
|
2712 |
||
2713 |
QVERIFY(thread.wait(10000)); |
|
2714 |
} |
|
2715 |
} |
|
2716 |
||
2717 |
class DisconnectObject : public QObject |
|
2718 |
{ |
|
2719 |
Q_OBJECT |
|
2720 |
||
2721 |
public slots: |
|
2722 |
void disconnectSelf() |
|
2723 |
{ |
|
2724 |
disconnect(sender(), 0, this, 0); |
|
2725 |
} |
|
2726 |
||
2727 |
void relaySignalAndProcessEvents() |
|
2728 |
{ |
|
2729 |
emit relayedSignal(); |
|
2730 |
QCoreApplication::processEvents(); |
|
2731 |
} |
|
2732 |
||
2733 |
signals: |
|
2734 |
void relayedSignal(); |
|
2735 |
}; |
|
2736 |
||
2737 |
void tst_QObject::disconnectSelfInSlotAndDeleteAfterEmit() |
|
2738 |
{ |
|
2739 |
{ |
|
2740 |
SenderObject sender; |
|
2741 |
DisconnectObject *receiver = new DisconnectObject(); |
|
2742 |
receiver->connect(&sender, SIGNAL(signal1()), SLOT(disconnectSelf())); |
|
2743 |
sender.emitSignal1AfterRecursion(); |
|
2744 |
delete receiver; |
|
2745 |
} |
|
2746 |
||
2747 |
{ |
|
2748 |
SenderObject sender; |
|
2749 |
DisconnectObject *receiver = new DisconnectObject(); |
|
2750 |
receiver->connect(&sender, |
|
2751 |
SIGNAL(signal1()), |
|
2752 |
SLOT(disconnectSelf()), |
|
2753 |
Qt::BlockingQueuedConnection); |
|
2754 |
||
2755 |
QThread thread; |
|
2756 |
receiver->moveToThread(&thread); |
|
2757 |
thread.connect(receiver, SIGNAL(destroyed()), SLOT(quit()), Qt::DirectConnection); |
|
2758 |
thread.start(); |
|
2759 |
||
2760 |
QPointer<DisconnectObject> p = receiver; |
|
2761 |
sender.emitSignal1(); |
|
2762 |
QVERIFY(!p.isNull()); |
|
2763 |
||
2764 |
receiver->deleteLater(); |
|
2765 |
||
2766 |
QVERIFY(thread.wait(10000)); |
|
2767 |
QVERIFY(p.isNull()); |
|
2768 |
} |
|
2769 |
||
2770 |
{ |
|
2771 |
SenderObject sender; |
|
2772 |
DisconnectObject *receiver = new DisconnectObject(); |
|
2773 |
receiver->connect(&sender, |
|
2774 |
SIGNAL(signal1()), |
|
2775 |
SLOT(relaySignalAndProcessEvents()), |
|
2776 |
Qt::BlockingQueuedConnection); |
|
2777 |
receiver->connect(receiver, |
|
2778 |
SIGNAL(relayedSignal()), |
|
2779 |
SLOT(disconnectSelf()), |
|
2780 |
Qt::QueuedConnection); |
|
2781 |
||
2782 |
QThread thread; |
|
2783 |
receiver->moveToThread(&thread); |
|
2784 |
thread.connect(receiver, SIGNAL(destroyed()), SLOT(quit()), Qt::DirectConnection); |
|
2785 |
thread.start(); |
|
2786 |
||
2787 |
QPointer<DisconnectObject> p = receiver; |
|
2788 |
sender.emitSignal1(); |
|
2789 |
QVERIFY(!p.isNull()); |
|
2790 |
||
2791 |
receiver->deleteLater(); |
|
2792 |
||
2793 |
QVERIFY(thread.wait(10000)); |
|
2794 |
QVERIFY(p.isNull()); |
|
2795 |
} |
|
2796 |
} |
|
2797 |
||
2798 |
void tst_QObject::dumpObjectInfo() |
|
2799 |
{ |
|
2800 |
QObject a, b; |
|
2801 |
QObject::connect(&a, SIGNAL(destroyed(QObject *)), &b, SLOT(deleteLater())); |
|
2802 |
a.disconnect(&b); |
|
2803 |
a.dumpObjectInfo(); // should not crash |
|
2804 |
} |
|
2805 |
||
2806 |
class ConnectToSender : public QObject |
|
2807 |
{ Q_OBJECT |
|
2808 |
public slots: |
|
2809 |
void uselessSlot() { count++; } |
|
2810 |
||
2811 |
void harmfullSlot() { |
|
2812 |
//this used to crash |
|
2813 |
connect(sender(), SIGNAL(signal4()), this, SLOT(uselessSlot())); |
|
2814 |
//play a little bit with the memory in order to really get a segfault. |
|
2815 |
connect(sender(), SIGNAL(signal1()), this, SLOT(uselessSlot())); |
|
2816 |
QList<double>() << 45 << 78 << 65 << 121 << 45 << 78 << 12; |
|
2817 |
} |
|
2818 |
public: |
|
2819 |
int count; |
|
2820 |
}; |
|
2821 |
||
2822 |
void tst_QObject::connectToSender() |
|
2823 |
{ |
|
2824 |
SenderObject s; |
|
2825 |
ConnectToSender r; |
|
2826 |
r.count = 0; |
|
2827 |
QObject::connect(&s, SIGNAL(signal1()), &r, SLOT(harmfullSlot())); |
|
2828 |
QObject::connect(&s, SIGNAL(signal1()), &r, SLOT(uselessSlot())); |
|
2829 |
||
2830 |
s.emitSignal1(); |
|
2831 |
||
2832 |
QCOMPARE(r.count, 1); |
|
2833 |
s.emitSignal4(); |
|
2834 |
QCOMPARE(r.count, 2); |
|
2835 |
} |
|
2836 |
||
2837 |
void tst_QObject::qobjectConstCast() |
|
2838 |
{ |
|
2839 |
FooObject obj; |
|
2840 |
||
2841 |
QObject *ptr = &obj; |
|
2842 |
const QObject *cptr = &obj; |
|
2843 |
||
2844 |
QVERIFY(qobject_cast<FooObject *>(ptr)); |
|
2845 |
QVERIFY(qobject_cast<const FooObject *>(cptr)); |
|
2846 |
} |
|
2847 |
||
2848 |
void tst_QObject::uniqConnection() |
|
2849 |
{ |
|
2850 |
SenderObject *s = new SenderObject; |
|
2851 |
ReceiverObject *r1 = new ReceiverObject; |
|
2852 |
ReceiverObject *r2 = new ReceiverObject; |
|
2853 |
r1->reset(); |
|
2854 |
r2->reset(); |
|
2855 |
ReceiverObject::sequence = 0; |
|
2856 |
||
2857 |
QVERIFY( connect( s, SIGNAL( signal1() ), r1, SLOT( slot1() ) , Qt::UniqueConnection) ); |
|
2858 |
QVERIFY( connect( s, SIGNAL( signal1() ), r2, SLOT( slot1() ) , Qt::UniqueConnection) ); |
|
2859 |
QVERIFY( connect( s, SIGNAL( signal1() ), r1, SLOT( slot3() ) , Qt::UniqueConnection) ); |
|
2860 |
QVERIFY( connect( s, SIGNAL( signal3() ), r1, SLOT( slot3() ) , Qt::UniqueConnection) ); |
|
2861 |
||
2862 |
s->emitSignal1(); |
|
2863 |
s->emitSignal2(); |
|
2864 |
s->emitSignal3(); |
|
2865 |
s->emitSignal4(); |
|
2866 |
||
2867 |
QCOMPARE( r1->count_slot1, 1 ); |
|
2868 |
QCOMPARE( r1->count_slot2, 0 ); |
|
2869 |
QCOMPARE( r1->count_slot3, 2 ); |
|
2870 |
QCOMPARE( r1->count_slot4, 0 ); |
|
2871 |
QCOMPARE( r2->count_slot1, 1 ); |
|
2872 |
QCOMPARE( r2->count_slot2, 0 ); |
|
2873 |
QCOMPARE( r2->count_slot3, 0 ); |
|
2874 |
QCOMPARE( r2->count_slot4, 0 ); |
|
2875 |
QCOMPARE( r1->sequence_slot1, 1 ); |
|
2876 |
QCOMPARE( r2->sequence_slot1, 2 ); |
|
2877 |
QCOMPARE( r1->sequence_slot3, 4 ); |
|
2878 |
||
2879 |
r1->reset(); |
|
2880 |
r2->reset(); |
|
2881 |
ReceiverObject::sequence = 0; |
|
2882 |
||
2883 |
QVERIFY( connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) , Qt::UniqueConnection) ); |
|
2884 |
QVERIFY( connect( s, SIGNAL( signal4() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) ); |
|
2885 |
QVERIFY(!connect( s, SIGNAL( signal4() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) ); |
|
2886 |
QVERIFY( connect( s, SIGNAL( signal1() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) ); |
|
2887 |
QVERIFY(!connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) , Qt::UniqueConnection) ); |
|
2888 |
||
2889 |
s->emitSignal4(); |
|
2890 |
QCOMPARE( r1->count_slot4, 1 ); |
|
2891 |
QCOMPARE( r2->count_slot4, 1 ); |
|
2892 |
QCOMPARE( r1->sequence_slot4, 1 ); |
|
2893 |
QCOMPARE( r2->sequence_slot4, 2 ); |
|
2894 |
||
2895 |
r1->reset(); |
|
2896 |
r2->reset(); |
|
2897 |
ReceiverObject::sequence = 0; |
|
2898 |
||
2899 |
connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) ); |
|
2900 |
||
2901 |
s->emitSignal4(); |
|
2902 |
QCOMPARE( r1->count_slot4, 2 ); |
|
2903 |
QCOMPARE( r2->count_slot4, 1 ); |
|
2904 |
QCOMPARE( r1->sequence_slot4, 3 ); |
|
2905 |
QCOMPARE( r2->sequence_slot4, 2 ); |
|
2906 |
||
2907 |
delete s; |
|
2908 |
delete r1; |
|
2909 |
delete r2; |
|
2910 |
} |
|
2911 |
||
2912 |
void tst_QObject::interfaceIid() |
|
2913 |
{ |
|
2914 |
QCOMPARE(QByteArray(qobject_interface_iid<Foo::Bleh *>()), |
|
2915 |
QByteArray(Bleh_iid)); |
|
2916 |
QCOMPARE(QByteArray(qobject_interface_iid<Foo::Bar *>()), |
|
2917 |
QByteArray("com.qtest.foobar")); |
|
2918 |
QCOMPARE(QByteArray(qobject_interface_iid<FooObject *>()), |
|
2919 |
QByteArray()); |
|
2920 |
} |
|
2921 |
||
2922 |
void tst_QObject::deleteQObjectWhenDeletingEvent() |
|
2923 |
{ |
|
2924 |
//this is related to task 259514 |
|
2925 |
//before the fix this used to dead lock when the QObject from the event was destroyed |
|
2926 |
||
2927 |
struct MyEvent : public QEvent |
|
2928 |
{ |
|
2929 |
MyEvent() : QEvent(QEvent::User) { } |
|
2930 |
QObject obj; |
|
2931 |
}; |
|
2932 |
||
2933 |
QObject o; |
|
2934 |
QApplication::postEvent(&o, new MyEvent); |
|
2935 |
QCoreApplication::removePostedEvents(&o); // here you would get a deadlock |
|
2936 |
} |
|
2937 |
||
2938 |
class OverloadObject : public QObject |
|
2939 |
{ |
|
2940 |
friend class tst_QObject; |
|
2941 |
Q_OBJECT |
|
2942 |
signals: |
|
2943 |
void sig(int i, char c, qreal m = 12); |
|
2944 |
void sig(int i, int j = 12); |
|
2945 |
void sig(QObject *o, QObject *p, QObject *q = 0, QObject *r = 0) const; |
|
2946 |
void other(int a = 0); |
|
2947 |
void sig(QObject *o, OverloadObject *p = 0, QObject *q = 0, QObject *r = 0); |
|
2948 |
void sig(double r = 0.5); |
|
2949 |
public slots: |
|
2950 |
void slo(int i, int j = 43) |
|
2951 |
{ |
|
2952 |
s_num += 1; |
|
2953 |
i1_num = i; |
|
2954 |
i2_num = j; |
|
2955 |
} |
|
2956 |
void slo(QObject *o, QObject *p = qApp, QObject *q = qApp, QObject *r = qApp) |
|
2957 |
{ |
|
2958 |
s_num += 10; |
|
2959 |
o1_obj = o; |
|
2960 |
o2_obj = p; |
|
2961 |
o3_obj = q; |
|
2962 |
o4_obj = r; |
|
2963 |
} |
|
2964 |
void slo() |
|
2965 |
{ |
|
2966 |
s_num += 100; |
|
2967 |
} |
|
2968 |
||
2969 |
public: |
|
2970 |
int s_num; |
|
2971 |
int i1_num; |
|
2972 |
int i2_num; |
|
2973 |
QObject *o1_obj; |
|
2974 |
QObject *o2_obj; |
|
2975 |
QObject *o3_obj; |
|
2976 |
QObject *o4_obj; |
|
2977 |
}; |
|
2978 |
||
2979 |
void tst_QObject::overloads() |
|
2980 |
{ |
|
2981 |
OverloadObject obj1; |
|
2982 |
OverloadObject obj2; |
|
2983 |
QObject obj3; |
|
2984 |
obj1.s_num = 0; |
|
2985 |
obj2.s_num = 0; |
|
2986 |
||
2987 |
connect (&obj1, SIGNAL(sig(int)) , &obj1, SLOT(slo(int))); |
|
2988 |
connect (&obj1, SIGNAL(sig(QObject *, QObject *, QObject *)) , &obj1, SLOT(slo(QObject * , QObject *, QObject *))); |
|
2989 |
||
2990 |
connect (&obj1, SIGNAL(sig(QObject *, QObject *, QObject *, QObject *)) , &obj2, SLOT(slo(QObject * , QObject *, QObject *))); |
|
2991 |
connect (&obj1, SIGNAL(sig(QObject *)) , &obj2, SLOT(slo())); |
|
2992 |
connect (&obj1, SIGNAL(sig(int, int)) , &obj2, SLOT(slo(int, int))); |
|
2993 |
||
2994 |
emit obj1.sig(0.5); //connected to nothing |
|
2995 |
emit obj1.sig(1, 'a'); //connected to nothing |
|
2996 |
QCOMPARE(obj1.s_num, 0); |
|
2997 |
QCOMPARE(obj2.s_num, 0); |
|
2998 |
||
2999 |
emit obj1.sig(1); //this signal is connected |
|
3000 |
QCOMPARE(obj1.s_num, 1); |
|
3001 |
QCOMPARE(obj1.i1_num, 1); |
|
3002 |
QCOMPARE(obj1.i2_num, 43); //default argument of the slot |
|
3003 |
||
3004 |
QCOMPARE(obj2.s_num, 1); |
|
3005 |
QCOMPARE(obj2.i1_num, 1); |
|
3006 |
QCOMPARE(obj2.i2_num, 12); //default argument of the signal |
|
3007 |
||
3008 |
||
3009 |
emit obj1.sig(&obj2); //this signal is conencted to obj2 |
|
3010 |
QCOMPARE(obj1.s_num, 1); |
|
3011 |
QCOMPARE(obj2.s_num, 101); |
|
3012 |
emit obj1.sig(&obj2, &obj3); //this signal is connected |
|
3013 |
QCOMPARE(obj1.s_num, 11); |
|
3014 |
QCOMPARE(obj1.o1_obj, &obj2); |
|
3015 |
QCOMPARE(obj1.o2_obj, &obj3); |
|
3016 |
QCOMPARE(obj1.o3_obj, (QObject *)0); //default arg of the signal |
|
3017 |
QCOMPARE(obj1.o4_obj, qApp); //default arg of the slot |
|
3018 |
||
3019 |
QCOMPARE(obj2.s_num, 111); |
|
3020 |
QCOMPARE(obj2.o1_obj, &obj2); |
|
3021 |
QCOMPARE(obj2.o2_obj, &obj3); |
|
3022 |
QCOMPARE(obj2.o3_obj, (QObject *)0); //default arg of the signal |
|
3023 |
QCOMPARE(obj2.o4_obj, qApp); //default arg of the slot |
|
3024 |
} |
|
3025 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3026 |
class ManySignals : public QObject |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3027 |
{ Q_OBJECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3028 |
friend class tst_QObject; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3029 |
signals: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3030 |
void sig00(); void sig01(); void sig02(); void sig03(); void sig04(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3031 |
void sig05(); void sig06(); void sig07(); void sig08(); void sig09(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3032 |
void sig10(); void sig11(); void sig12(); void sig13(); void sig14(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3033 |
void sig15(); void sig16(); void sig17(); void sig18(); void sig19(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3034 |
void sig20(); void sig21(); void sig22(); void sig23(); void sig24(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3035 |
void sig25(); void sig26(); void sig27(); void sig28(); void sig29(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3036 |
void sig30(); void sig31(); void sig32(); void sig33(); void sig34(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3037 |
void sig35(); void sig36(); void sig37(); void sig38(); void sig39(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3038 |
void sig40(); void sig41(); void sig42(); void sig43(); void sig44(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3039 |
void sig45(); void sig46(); void sig47(); void sig48(); void sig49(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3040 |
void sig50(); void sig51(); void sig52(); void sig53(); void sig54(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3041 |
void sig55(); void sig56(); void sig57(); void sig58(); void sig59(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3042 |
void sig60(); void sig61(); void sig62(); void sig63(); void sig64(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3043 |
void sig65(); void sig66(); void sig67(); void sig68(); void sig69(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3044 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3045 |
public slots: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3046 |
void received() { rec++; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3047 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3048 |
int rec; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3049 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3050 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3051 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3052 |
void tst_QObject::isSignalConnected() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3053 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3054 |
ManySignals o; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3055 |
o.rec = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3056 |
#ifdef QT_BUILD_INTERNAL |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3057 |
QObjectPrivate *priv = QObjectPrivate::get(&o); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3058 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("destroyed()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3059 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig00()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3060 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig05()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3061 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig15()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3062 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig29()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3063 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig60()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3064 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig61()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3065 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3066 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3067 |
QObject::connect(&o, SIGNAL(sig00()), &o, SIGNAL(sig69())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3068 |
QObject::connect(&o, SIGNAL(sig34()), &o, SIGNAL(sig03())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3069 |
QObject::connect(&o, SIGNAL(sig69()), &o, SIGNAL(sig34())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3070 |
QObject::connect(&o, SIGNAL(sig03()), &o, SIGNAL(sig18())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3071 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3072 |
#ifdef QT_BUILD_INTERNAL |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3073 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("destroyed()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3074 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig05()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3075 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig15()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3076 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig29()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3077 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3078 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig00()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3079 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig03()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3080 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig34()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3081 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig69()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3082 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig18()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3083 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3084 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3085 |
QObject::connect(&o, SIGNAL(sig18()), &o, SIGNAL(sig29())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3086 |
QObject::connect(&o, SIGNAL(sig29()), &o, SIGNAL(sig62())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3087 |
QObject::connect(&o, SIGNAL(sig62()), &o, SIGNAL(sig28())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3088 |
QObject::connect(&o, SIGNAL(sig28()), &o, SIGNAL(sig27())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3089 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3090 |
#ifdef QT_BUILD_INTERNAL |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3091 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig18()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3092 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig62()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3093 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig28()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3094 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig69()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3095 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig27()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3096 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3097 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3098 |
QCOMPARE(o.rec, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3099 |
emit o.sig01(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3100 |
emit o.sig34(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3101 |
QCOMPARE(o.rec, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3102 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3103 |
QObject::connect(&o, SIGNAL(sig27()), &o, SLOT(received())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3104 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3105 |
#ifdef QT_BUILD_INTERNAL |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3106 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig00()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3107 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig03()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3108 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig34()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3109 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig18()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3110 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig62()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3111 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig28()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3112 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig69()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3113 |
QVERIFY(priv->isSignalConnected(priv->signalIndex("sig27()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3114 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3115 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig04()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3116 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig21()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3117 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig25()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3118 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig55()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3119 |
QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig61()"))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3120 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3121 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3122 |
emit o.sig00(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3123 |
QCOMPARE(o.rec, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3124 |
emit o.sig69(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3125 |
QCOMPARE(o.rec, 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3126 |
emit o.sig36(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3127 |
QCOMPARE(o.rec, 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3128 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3129 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3130 |
void tst_QObject::qMetaObjectConnect() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3131 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3132 |
SenderObject *s = new SenderObject; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3133 |
ReceiverObject *r1 = new ReceiverObject; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3134 |
ReceiverObject *r2 = new ReceiverObject; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3135 |
r1->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3136 |
r2->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3137 |
ReceiverObject::sequence = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3138 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3139 |
int signal1Index = s->metaObject()->indexOfSignal("signal1()"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3140 |
int signal3Index = s->metaObject()->indexOfSignal("signal3()"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3141 |
int slot1Index = r1->metaObject()->indexOfSlot("slot1()"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3142 |
int slot2Index = r1->metaObject()->indexOfSlot("slot2()"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3143 |
int slot3Index = r1->metaObject()->indexOfSlot("slot3()"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3144 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3145 |
QVERIFY(slot1Index > 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3146 |
QVERIFY(slot2Index > 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3147 |
QVERIFY(slot3Index > 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3148 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3149 |
QVERIFY( QMetaObject::connect( s, signal1Index, r1, slot1Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3150 |
QVERIFY( QMetaObject::connect( s, signal3Index, r2, slot3Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3151 |
QVERIFY( QMetaObject::connect( s, -1, r2, slot2Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3152 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3153 |
QCOMPARE( r1->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3154 |
QCOMPARE( r1->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3155 |
QCOMPARE( r1->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3156 |
QCOMPARE( r2->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3157 |
QCOMPARE( r2->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3158 |
QCOMPARE( r2->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3159 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3160 |
s->emitSignal1(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3161 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3162 |
QCOMPARE( r1->count_slot1, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3163 |
QCOMPARE( r1->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3164 |
QCOMPARE( r1->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3165 |
QCOMPARE( r2->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3166 |
QCOMPARE( r2->count_slot2, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3167 |
QCOMPARE( r2->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3168 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3169 |
s->emitSignal2(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3170 |
s->emitSignal3(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3171 |
s->emitSignal4(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3172 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3173 |
QCOMPARE( r1->count_slot1, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3174 |
QCOMPARE( r1->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3175 |
QCOMPARE( r1->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3176 |
QCOMPARE( r2->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3177 |
QCOMPARE( r2->count_slot2, 4 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3178 |
QCOMPARE( r2->count_slot3, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3179 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3180 |
QVERIFY( QMetaObject::disconnect( s, signal1Index, r1, slot1Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3181 |
QVERIFY( QMetaObject::disconnect( s, signal3Index, r2, slot3Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3182 |
QVERIFY( QMetaObject::disconnect( s, -1, r2, slot2Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3183 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3184 |
s->emitSignal1(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3185 |
s->emitSignal2(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3186 |
s->emitSignal3(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3187 |
s->emitSignal4(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3188 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3189 |
QCOMPARE( r1->count_slot1, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3190 |
QCOMPARE( r1->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3191 |
QCOMPARE( r1->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3192 |
QCOMPARE( r2->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3193 |
QCOMPARE( r2->count_slot2, 4 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3194 |
QCOMPARE( r2->count_slot3, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3195 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3196 |
//some "dynamic" signal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3197 |
QVERIFY( QMetaObject::connect( s, s->metaObject()->methodOffset() + 20, r1, slot3Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3198 |
QVERIFY( QMetaObject::connect( s, s->metaObject()->methodOffset() + 35, r2, slot1Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3199 |
QVERIFY( QMetaObject::connect( s, -1, r1, slot2Index) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3200 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3201 |
r1->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3202 |
r2->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3203 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3204 |
void *args[] = { 0 , 0 }; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3205 |
QMetaObject::activate(s, s->metaObject()->methodOffset() + 20, args); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3206 |
QMetaObject::activate(s, s->metaObject()->methodOffset() + 48, args); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3207 |
QCOMPARE( r1->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3208 |
QCOMPARE( r1->count_slot2, 2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3209 |
QCOMPARE( r1->count_slot3, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3210 |
QCOMPARE( r2->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3211 |
QCOMPARE( r2->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3212 |
QCOMPARE( r2->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3213 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3214 |
QMetaObject::activate(s, s->metaObject()->methodOffset() + 35, args); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3215 |
s->emitSignal1(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3216 |
s->emitSignal2(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3217 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3218 |
QCOMPARE( r1->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3219 |
QCOMPARE( r1->count_slot2, 5 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3220 |
QCOMPARE( r1->count_slot3, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3221 |
QCOMPARE( r2->count_slot1, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3222 |
QCOMPARE( r2->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3223 |
QCOMPARE( r2->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3224 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3225 |
delete s; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3226 |
r1->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3227 |
r2->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3228 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3229 |
#define SIGNAL_INDEX(S) obj1.metaObject()->indexOfSignal(QMetaObject::normalizedSignature(#S)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3230 |
OverloadObject obj1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3231 |
QObject obj2, obj3; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3232 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3233 |
QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(int)) , r1, slot1Index); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3234 |
QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(QObject *, QObject *, QObject *)) , r2, slot1Index); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3235 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3236 |
QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(QObject *, QObject *, QObject *, QObject *)) , r1, slot2Index); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3237 |
QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(QObject *)) , r2, slot2Index); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3238 |
QMetaObject::connect(&obj1, SIGNAL_INDEX(sig(int, int)) , r1, slot3Index); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3239 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3240 |
emit obj1.sig(0.5); //connected to nothing |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3241 |
emit obj1.sig(1, 'a'); //connected to nothing |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3242 |
QCOMPARE( r1->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3243 |
QCOMPARE( r1->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3244 |
QCOMPARE( r1->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3245 |
QCOMPARE( r2->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3246 |
QCOMPARE( r2->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3247 |
QCOMPARE( r2->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3248 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3249 |
emit obj1.sig(1); //this signal is connected |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3250 |
emit obj1.sig(&obj2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3251 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3252 |
QCOMPARE( r1->count_slot1, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3253 |
QCOMPARE( r1->count_slot2, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3254 |
QCOMPARE( r1->count_slot3, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3255 |
QCOMPARE( r2->count_slot1, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3256 |
QCOMPARE( r2->count_slot2, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3257 |
QCOMPARE( r2->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3258 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3259 |
emit obj1.sig(&obj2, &obj3); //this signal is connected |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3260 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3261 |
QCOMPARE( r1->count_slot1, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3262 |
QCOMPARE( r1->count_slot2, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3263 |
QCOMPARE( r1->count_slot3, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3264 |
QCOMPARE( r2->count_slot1, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3265 |
QCOMPARE( r2->count_slot2, 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3266 |
QCOMPARE( r2->count_slot3, 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3267 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3268 |
delete r1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3269 |
delete r2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3270 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3271 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3272 |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3273 |
void tst_QObject::qMetaObjectDisconnectOne() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3274 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3275 |
SenderObject *s = new SenderObject; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3276 |
ReceiverObject *r1 = new ReceiverObject; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3277 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3278 |
int signal1Index = s->metaObject()->indexOfSignal("signal1()"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3279 |
int signal3Index = s->metaObject()->indexOfSignal("signal3()"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3280 |
int slot1Index = r1->metaObject()->indexOfSlot("slot1()"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3281 |
int slot2Index = r1->metaObject()->indexOfSlot("slot2()"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3282 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3283 |
QVERIFY(signal1Index > 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3284 |
QVERIFY(signal3Index > 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3285 |
QVERIFY(slot1Index > 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3286 |
QVERIFY(slot2Index > 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3287 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3288 |
QVERIFY( QMetaObject::connect(s, signal1Index, r1, slot1Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3289 |
QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3290 |
QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3291 |
QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3292 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3293 |
r1->reset(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3294 |
QCOMPARE( r1->count_slot1, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3295 |
QCOMPARE( r1->count_slot2, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3296 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3297 |
s->emitSignal1(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3298 |
QCOMPARE( r1->count_slot1, 1 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3299 |
QCOMPARE( r1->count_slot2, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3300 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3301 |
s->emitSignal3(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3302 |
QCOMPARE( r1->count_slot1, 1 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3303 |
QCOMPARE( r1->count_slot2, 3 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3304 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3305 |
r1->reset(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3306 |
QVERIFY( QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3307 |
QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3308 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3309 |
s->emitSignal1(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3310 |
QCOMPARE( r1->count_slot1, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3311 |
QCOMPARE( r1->count_slot2, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3312 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3313 |
s->emitSignal3(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3314 |
QCOMPARE( r1->count_slot1, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3315 |
QCOMPARE( r1->count_slot2, 2 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3316 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3317 |
r1->reset(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3318 |
QVERIFY( false == QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3319 |
QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3320 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3321 |
s->emitSignal1(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3322 |
QCOMPARE( r1->count_slot1, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3323 |
QCOMPARE( r1->count_slot2, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3324 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3325 |
s->emitSignal3(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3326 |
QCOMPARE( r1->count_slot1, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3327 |
QCOMPARE( r1->count_slot2, 1 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3328 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3329 |
r1->reset(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3330 |
QVERIFY( false == QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3331 |
QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3332 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3333 |
s->emitSignal1(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3334 |
QCOMPARE( r1->count_slot1, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3335 |
QCOMPARE( r1->count_slot2, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3336 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3337 |
s->emitSignal3(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3338 |
QCOMPARE( r1->count_slot1, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3339 |
QCOMPARE( r1->count_slot2, 0 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3340 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3341 |
delete s; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3342 |
delete r1; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3343 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3344 |
|
0 | 3345 |
QTEST_MAIN(tst_QObject) |
3346 |
#include "tst_qobject.moc" |