summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2012-10-12 12:20:40 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-28 19:22:05 +0100
commitab59a7ef09d56e59f9496ac59d88ba05db61e298 (patch)
tree26e325f15d46275fdd2fc617d059d7afb2c767bb /tests/auto
parentb997481fcbdf574cd71f51c8c7af3c652f36a9aa (diff)
Add private API to connect to slots in QObjectPrivate
Change-Id: I16ffbf91ff4c6e9fca6fe7984800d2c24e70701b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index c3ecf419e0..0521c2277c 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -141,6 +141,7 @@ private slots:
void returnValue2_data();
void returnValue2();
void connectVirtualSlots();
+ void connectPrivateSlots();
void connectFunctorArgDifference();
void disconnectDoesNotLeakFunctor();
};
@@ -5565,6 +5566,72 @@ void tst_QObject::connectVirtualSlots()
*/
}
+#ifndef QT_BUILD_INTERNAL
+void tst_QObject::connectPrivateSlots()
+{QSKIP("Needs QT_BUILD_INTERNAL");}
+#else
+class ConnectToPrivateSlotPrivate;
+
+class ConnectToPrivateSlot :public QObject {
+ Q_OBJECT
+public:
+ ConnectToPrivateSlot();
+ void test(SenderObject *obj1) ;
+ Q_DECLARE_PRIVATE(ConnectToPrivateSlot)
+};
+
+class ConnectToPrivateSlotPrivate : public QObjectPrivate {
+public:
+ Q_DECLARE_PUBLIC(ConnectToPrivateSlot)
+ int receivedCount;
+ QVariant receivedValue;
+
+ void thisIsAPrivateSlot() {
+ receivedCount++;
+ };
+
+ void thisIsAPrivateSlotWithArg(const QVariant &v) {
+ receivedCount++;
+ receivedValue = v;
+ };
+};
+
+ConnectToPrivateSlot::ConnectToPrivateSlot(): QObject(*new ConnectToPrivateSlotPrivate) {}
+
+void ConnectToPrivateSlot::test(SenderObject* obj1) {
+ Q_D(ConnectToPrivateSlot);
+ d->receivedCount = 0;
+ QVERIFY(QObjectPrivate::connect(obj1, &SenderObject::signal1, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot));
+ QVERIFY(QObjectPrivate::connect(obj1, &SenderObject::signal7, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlotWithArg));
+ QCOMPARE(d->receivedCount, 0);
+ obj1->signal1();
+ QCOMPARE(d->receivedCount, 1);
+ QCOMPARE(d->receivedValue, QVariant());
+ obj1->signal7(666, QLatin1Literal("_"));
+ QCOMPARE(d->receivedCount, 2);
+ QCOMPARE(d->receivedValue, QVariant(666));
+ QVERIFY(QObjectPrivate::connect(obj1, &SenderObject::signal2, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot, Qt::UniqueConnection));
+ QVERIFY(!QObjectPrivate::connect(obj1, &SenderObject::signal2, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot, Qt::UniqueConnection));
+ obj1->signal2();
+ QCOMPARE(d->receivedCount, 3);
+ QVERIFY(QObjectPrivate::disconnect(obj1, &SenderObject::signal2, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot));
+ obj1->signal2();
+ QCOMPARE(d->receivedCount, 3);
+ QVERIFY(!QObjectPrivate::disconnect(obj1, &SenderObject::signal2, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot));
+}
+
+void tst_QObject::connectPrivateSlots()
+{
+ SenderObject sender;
+ {
+ ConnectToPrivateSlot o;
+ o.test(&sender);
+ }
+ sender.signal7(777, QLatin1String("check that deleting the object properly disconnected"));
+ sender.signal1();
+}
+#endif
+
struct SlotFunctor
{
void operator()() {}