summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-08-14 09:05:42 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-08-14 09:06:31 +0200
commit5c23199d4e8ff21661dfa5aacc13149178e78cab (patch)
tree322aee61581d7c85f1ccb65e47d1e79eba1ba6c9 /tests/auto/corelib/kernel/qobject/tst_qobject.cpp
parent252bad7c589e03d3e12df02354b00a84d8e3159a (diff)
parentc8d9b17367cfdcb034d11f8a168ca4ae3993e7c3 (diff)
Merge remote-tracking branch 'origin/stable' into dev
Conflicts: configure mkspecs/macx-xcode/Info.plist.app mkspecs/macx-xcode/Info.plist.lib qmake/doc/qmake.qdocconf src/corelib/global/qglobal.h tests/auto/other/exceptionsafety/exceptionsafety.pro tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp Change-Id: I3c769a4a82dc2e99a12c69123fbf17613fd2ac2a
Diffstat (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp58
1 files changed, 51 insertions, 7 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 9bf28430b0..8d1ea3b510 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -5727,27 +5727,44 @@ void tst_QObject::connectFunctorOverloads()
#endif
}
+class GetSenderObject : public QObject
+{
+ Q_OBJECT
+public:
+ QObject *accessSender() { return sender(); }
+
+public Q_SLOTS:
+ void triggerSignal() { Q_EMIT aSignal(); }
+
+Q_SIGNALS:
+ void aSignal();
+};
+
static int countedStructObjectsCount = 0;
struct CountedStruct
{
- CountedStruct() { ++countedStructObjectsCount; }
- CountedStruct(const CountedStruct &) { ++countedStructObjectsCount; }
+ CountedStruct() : sender(Q_NULLPTR) { ++countedStructObjectsCount; }
+ CountedStruct(GetSenderObject *sender) : sender(sender) { ++countedStructObjectsCount; }
+ CountedStruct(const CountedStruct &o) : sender(o.sender) { ++countedStructObjectsCount; }
CountedStruct &operator=(const CountedStruct &) { return *this; }
- ~CountedStruct() { --countedStructObjectsCount; }
- void operator()() const {}
+ // accessSender here allows us to check if there's a deadlock
+ ~CountedStruct() { --countedStructObjectsCount; if (sender != Q_NULLPTR) (void)sender->accessSender(); }
+ void operator()() const { }
+
+ GetSenderObject *sender;
};
void tst_QObject::disconnectDoesNotLeakFunctor()
{
QCOMPARE(countedStructObjectsCount, 0);
{
+ GetSenderObject obj;
QMetaObject::Connection c;
{
- CountedStruct s;
+ CountedStruct s(&obj);
QCOMPARE(countedStructObjectsCount, 1);
- QTimer timer;
- c = connect(&timer, &QTimer::timeout, s);
+ c = connect(&obj, &GetSenderObject::aSignal, s);
QVERIFY(c);
QCOMPARE(countedStructObjectsCount, 2);
QVERIFY(QObject::disconnect(c));
@@ -5798,6 +5815,33 @@ void tst_QObject::disconnectDoesNotLeakFunctor()
}
QCOMPARE(countedStructObjectsCount, 0);
{
+ QTimer *timer = new QTimer;
+ QEventLoop e;
+
+ connect(timer, &QTimer::timeout, CountedStruct());
+ QCOMPARE(countedStructObjectsCount, 1); // only one instance, in Qt internals
+ timer->deleteLater();
+ connect(timer, &QObject::destroyed, &e, &QEventLoop::quit, Qt::QueuedConnection);
+ e.exec();
+ QCOMPARE(countedStructObjectsCount, 0); // functor being destroyed
+ }
+ QCOMPARE(countedStructObjectsCount, 0);
+ {
+ GetSenderObject obj;
+
+ connect(&obj, &GetSenderObject::aSignal, CountedStruct(&obj));
+ QCOMPARE(countedStructObjectsCount, 1);
+ }
+ QCOMPARE(countedStructObjectsCount, 0);
+ {
+ GetSenderObject obj;
+
+ connect(&obj, &GetSenderObject::aSignal, CountedStruct(&obj));
+ QCOMPARE(countedStructObjectsCount, 1);
+ QObject::disconnect(&obj, &GetSenderObject::aSignal, 0, 0);
+ }
+ QCOMPARE(countedStructObjectsCount, 0);
+ {
#if defined(Q_COMPILER_LAMBDA)
CountedStruct s;
QCOMPARE(countedStructObjectsCount, 1);