tests/auto/qobject/tst_qobject.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 8 3f74d0d4af4c
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the test suite of the Qt Toolkit.
     7 ** This file is part of the test suite of the Qt Toolkit.
     8 **
     8 **
   125     void interfaceIid();
   125     void interfaceIid();
   126     void deleteQObjectWhenDeletingEvent();
   126     void deleteQObjectWhenDeletingEvent();
   127     void overloads();
   127     void overloads();
   128     void isSignalConnected();
   128     void isSignalConnected();
   129     void qMetaObjectConnect();
   129     void qMetaObjectConnect();
       
   130     void qMetaObjectDisconnectOne();
   130 protected:
   131 protected:
   131 };
   132 };
   132 
   133 
   133 tst_QObject::tst_QObject()
   134 tst_QObject::tst_QObject()
   134 {
   135 {
  3267     delete r1;
  3268     delete r1;
  3268     delete r2;
  3269     delete r2;
  3269 
  3270 
  3270 }
  3271 }
  3271 
  3272 
       
  3273 void tst_QObject::qMetaObjectDisconnectOne()
       
  3274 {
       
  3275     SenderObject *s = new SenderObject;
       
  3276     ReceiverObject *r1 = new ReceiverObject;
       
  3277 
       
  3278     int signal1Index = s->metaObject()->indexOfSignal("signal1()");
       
  3279     int signal3Index = s->metaObject()->indexOfSignal("signal3()");
       
  3280     int slot1Index = r1->metaObject()->indexOfSlot("slot1()");
       
  3281     int slot2Index = r1->metaObject()->indexOfSlot("slot2()");
       
  3282 
       
  3283     QVERIFY(signal1Index > 0);
       
  3284     QVERIFY(signal3Index > 0);
       
  3285     QVERIFY(slot1Index > 0);
       
  3286     QVERIFY(slot2Index > 0);
       
  3287 
       
  3288     QVERIFY( QMetaObject::connect(s, signal1Index, r1, slot1Index) );
       
  3289     QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) );
       
  3290     QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) );
       
  3291     QVERIFY( QMetaObject::connect(s, signal3Index, r1, slot2Index) );
       
  3292 
       
  3293     r1->reset();
       
  3294     QCOMPARE( r1->count_slot1, 0 );
       
  3295     QCOMPARE( r1->count_slot2, 0 );
       
  3296 
       
  3297     s->emitSignal1();
       
  3298     QCOMPARE( r1->count_slot1, 1 );
       
  3299     QCOMPARE( r1->count_slot2, 0 );
       
  3300 
       
  3301     s->emitSignal3();
       
  3302     QCOMPARE( r1->count_slot1, 1 );
       
  3303     QCOMPARE( r1->count_slot2, 3 );
       
  3304 
       
  3305     r1->reset();
       
  3306     QVERIFY( QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) );
       
  3307     QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) );
       
  3308 
       
  3309     s->emitSignal1();
       
  3310     QCOMPARE( r1->count_slot1, 0 );
       
  3311     QCOMPARE( r1->count_slot2, 0 );
       
  3312 
       
  3313     s->emitSignal3();
       
  3314     QCOMPARE( r1->count_slot1, 0 );
       
  3315     QCOMPARE( r1->count_slot2, 2 );
       
  3316 
       
  3317     r1->reset();
       
  3318     QVERIFY( false == QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) );
       
  3319     QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) );
       
  3320 
       
  3321     s->emitSignal1();
       
  3322     QCOMPARE( r1->count_slot1, 0 );
       
  3323     QCOMPARE( r1->count_slot2, 0 );
       
  3324 
       
  3325     s->emitSignal3();
       
  3326     QCOMPARE( r1->count_slot1, 0 );
       
  3327     QCOMPARE( r1->count_slot2, 1 );
       
  3328 
       
  3329     r1->reset();
       
  3330     QVERIFY( false == QMetaObject::disconnectOne(s, signal1Index, r1, slot1Index) );
       
  3331     QVERIFY( QMetaObject::disconnectOne(s, signal3Index, r1, slot2Index) );
       
  3332 
       
  3333     s->emitSignal1();
       
  3334     QCOMPARE( r1->count_slot1, 0 );
       
  3335     QCOMPARE( r1->count_slot2, 0 );
       
  3336 
       
  3337     s->emitSignal3();
       
  3338     QCOMPARE( r1->count_slot1, 0 );
       
  3339     QCOMPARE( r1->count_slot2, 0 );
       
  3340 
       
  3341     delete s;
       
  3342     delete r1;
       
  3343 }
       
  3344 
  3272 QTEST_MAIN(tst_QObject)
  3345 QTEST_MAIN(tst_QObject)
  3273 #include "tst_qobject.moc"
  3346 #include "tst_qobject.moc"