diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qobject/tst_qobject.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp index 5035139..67a9c46 100644 --- a/tests/auto/qobject/tst_qobject.cpp +++ b/tests/auto/qobject/tst_qobject.cpp @@ -60,6 +60,10 @@ #include <QProcess> #include "qobject.h" +#ifdef QT_BUILD_INTERNAL +#include <private/qobject_p.h> +#endif + #include <math.h> @@ -121,6 +125,7 @@ private slots: void interfaceIid(); void deleteQObjectWhenDeletingEvent(); void overloads(); + void isSignalConnected(); protected: }; @@ -3016,5 +3021,109 @@ void tst_QObject::overloads() QCOMPARE(obj2.o4_obj, qApp); //default arg of the slot } +class ManySignals : public QObject +{ Q_OBJECT + friend class tst_QObject; +signals: + void sig00(); void sig01(); void sig02(); void sig03(); void sig04(); + void sig05(); void sig06(); void sig07(); void sig08(); void sig09(); + void sig10(); void sig11(); void sig12(); void sig13(); void sig14(); + void sig15(); void sig16(); void sig17(); void sig18(); void sig19(); + void sig20(); void sig21(); void sig22(); void sig23(); void sig24(); + void sig25(); void sig26(); void sig27(); void sig28(); void sig29(); + void sig30(); void sig31(); void sig32(); void sig33(); void sig34(); + void sig35(); void sig36(); void sig37(); void sig38(); void sig39(); + void sig40(); void sig41(); void sig42(); void sig43(); void sig44(); + void sig45(); void sig46(); void sig47(); void sig48(); void sig49(); + void sig50(); void sig51(); void sig52(); void sig53(); void sig54(); + void sig55(); void sig56(); void sig57(); void sig58(); void sig59(); + void sig60(); void sig61(); void sig62(); void sig63(); void sig64(); + void sig65(); void sig66(); void sig67(); void sig68(); void sig69(); + +public slots: + void received() { rec++; } +public: + int rec; +}; + + +void tst_QObject::isSignalConnected() +{ + ManySignals o; + o.rec = 0; +#ifdef QT_BUILD_INTERNAL + QObjectPrivate *priv = QObjectPrivate::get(&o); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("destroyed()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig00()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig05()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig15()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig29()"))); + if (sizeof(void *) >= 8) { //on 32bit isSignalConnected only works with the first 32 signals + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig60()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig61()"))); + } +#endif + + QObject::connect(&o, SIGNAL(sig00()), &o, SIGNAL(sig69())); + QObject::connect(&o, SIGNAL(sig34()), &o, SIGNAL(sig03())); + QObject::connect(&o, SIGNAL(sig69()), &o, SIGNAL(sig34())); + QObject::connect(&o, SIGNAL(sig03()), &o, SIGNAL(sig18())); + +#ifdef QT_BUILD_INTERNAL + QVERIFY(!priv->isSignalConnected(priv->signalIndex("destroyed()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig05()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig15()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig29()"))); + + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig00()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig03()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig34()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig69()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig18()"))); +#endif + + QObject::connect(&o, SIGNAL(sig18()), &o, SIGNAL(sig29())); + QObject::connect(&o, SIGNAL(sig29()), &o, SIGNAL(sig62())); + QObject::connect(&o, SIGNAL(sig62()), &o, SIGNAL(sig28())); + QObject::connect(&o, SIGNAL(sig28()), &o, SIGNAL(sig27())); + +#ifdef QT_BUILD_INTERNAL + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig18()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig62()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig28()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig69()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig27()"))); +#endif + + QCOMPARE(o.rec, 0); + emit o.sig01(); + emit o.sig34(); + QCOMPARE(o.rec, 0); + + QObject::connect(&o, SIGNAL(sig27()), &o, SLOT(received())); + +#ifdef QT_BUILD_INTERNAL + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig00()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig03()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig34()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig18()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig62()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig28()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig69()"))); + QVERIFY(priv->isSignalConnected(priv->signalIndex("sig27()"))); + + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig04()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig21()"))); + QVERIFY(!priv->isSignalConnected(priv->signalIndex("sig25()"))); +#endif + + emit o.sig00(); + QCOMPARE(o.rec, 1); + emit o.sig69(); + QCOMPARE(o.rec, 2); + emit o.sig36(); + QCOMPARE(o.rec, 2); +} + QTEST_MAIN(tst_QObject) #include "tst_qobject.moc" |