diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-01-11 06:28:49 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-01-20 01:11:20 (GMT) |
commit | 5f92bc9dd9f05f4824711b03406bdbe222ff73e9 (patch) | |
tree | fbea025f0f1c3d5a86039db69307acfcdf0a0fe5 /tests/auto | |
parent | 68af2fdbb25f8b77a7f314d19d1a0cc50b114e37 (diff) | |
download | Qt-5f92bc9dd9f05f4824711b03406bdbe222ff73e9.zip Qt-5f92bc9dd9f05f4824711b03406bdbe222ff73e9.tar.gz Qt-5f92bc9dd9f05f4824711b03406bdbe222ff73e9.tar.bz2 |
QMetaObject::disconnectOne()
Adds a disconnectOne() method that allows a single signal/slot connection
to be disconnected, as required by QTBUG-6781.
Reviewed-by: Warwick Allison
Reviewed-by: Olivier Goffart
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qobject/tst_qobject.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp index d342581..4fa6aaa 100644 --- a/tests/auto/qobject/tst_qobject.cpp +++ b/tests/auto/qobject/tst_qobject.cpp @@ -127,6 +127,7 @@ private slots: void overloads(); void isSignalConnected(); void qMetaObjectConnect(); + void qMetaObjectDisconnectOne(); protected: }; @@ -3269,5 +3270,77 @@ void tst_QObject::qMetaObjectConnect() } +void tst_QObject::qMetaObjectDisconnectOne() +{ + SenderObject *s = new SenderObject; + ReceiverObject *r1 = new ReceiverObject; + + int signal1Index = s->metaObject()->indexOfSignal("signal1()"); + int signal3Index = s->metaObject()->indexOfSignal("signal3()"); + int slot1Index = r1->metaObject()->indexOfSlot("slot1()"); + int slot2Index = r1->metaObject()->indexOfSlot("slot2()"); + + QVERIFY(signal1Index > 0); + QVERIFY(signal3Index > 0); + QVERIFY(slot1Index > 0); + QVERIFY(slot2Index > 0); + + QVERIFY( QMetaObject::connect(s, signal1Index, r1, slot1Index) ); + QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) ); + QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) ); + QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) ); + + r1->reset(); + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 0 ); + + s->emitSignal1(); + QCOMPARE( r1->count_slot1, 1 ); + QCOMPARE( r1->count_slot2, 0 ); + + s->emitSignal3(); + QCOMPARE( r1->count_slot1, 1 ); + QCOMPARE( r1->count_slot2, 3 ); + + r1->reset(); + QVERIFY( QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) ); + QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) ); + + s->emitSignal1(); + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 0 ); + + s->emitSignal3(); + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 2 ); + + r1->reset(); + QVERIFY( false == QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) ); + QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) ); + + s->emitSignal1(); + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 0 ); + + s->emitSignal3(); + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 1 ); + + r1->reset(); + QVERIFY( false == QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) ); + QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) ); + + s->emitSignal1(); + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 0 ); + + s->emitSignal3(); + QCOMPARE( r1->count_slot1, 0 ); + QCOMPARE( r1->count_slot2, 0 ); + + delete s; + delete r1; +} + QTEST_MAIN(tst_QObject) #include "tst_qobject.moc" |