summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 63d06497ce..471d73e512 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -149,6 +149,7 @@ private slots:
void connectBase();
void connectWarnings();
void qmlConnect();
+ void qmlConnectToQObjectReceiver();
void exceptions();
void noDeclarativeParentChangedOnDestruction();
void deleteLaterInAboutToBlockHandler();
@@ -157,6 +158,7 @@ private slots:
void nullReceiver();
void functorReferencesConnection();
void disconnectDisconnects();
+ void declarativeData();
};
struct QObjectCreatedOnShutdown
@@ -3023,6 +3025,16 @@ void tst_QObject::recursiveSignalEmission()
QSKIP("No qprocess support", SkipAll);
#else
QProcess proc;
+
+ // Add the executable's directory to path so that we can find the test helper next to it
+ // in a cross-platform way. We must do this because the CWD is not pointing to this directory
+ // in debug-and-release builds.
+ QByteArray pathEnv = qgetenv("PATH");
+ qputenv("PATH",
+ pathEnv + QDir::listSeparator().toLatin1()
+ + QCoreApplication::applicationDirPath().toLocal8Bit());
+ auto restore = qScopeGuard([&] { qputenv("PATH", pathEnv); });
+
// signalbug helper app should always be next to this test binary
const QString path = QStringLiteral("signalbug_helper");
proc.start(path);
@@ -6783,6 +6795,33 @@ void tst_QObject::qmlConnect()
#endif
}
+void tst_QObject::qmlConnectToQObjectReceiver()
+{
+#ifdef QT_BUILD_INTERNAL
+ SenderObject sender;
+ QScopedPointer<QObject> receiver(new QObject);
+ QmlReceiver *slotObject = new QmlReceiver;
+ slotObject->magic = slotObject;
+ slotObject->ref(); // extra ref so that slot object is not implicitly deleted
+
+ QVERIFY(QObjectPrivate::connect(&sender, sender.metaObject()->indexOfSignal("signal1()"),
+ receiver.get(), slotObject, Qt::AutoConnection));
+
+ QCOMPARE(slotObject->callCount, 0);
+ sender.emitSignal1();
+ QCOMPARE(slotObject->callCount, 1);
+
+ receiver.reset(); // this should disconnect the slotObject
+
+ sender.emitSignal1();
+ QCOMPARE(slotObject->callCount, 1);
+
+ slotObject->destroyIfLastRef();
+#else
+ QSKIP("Needs QT_BUILD_INTERNAL");
+#endif
+}
+
#ifndef QT_NO_EXCEPTIONS
class ObjectException : public std::exception { };
@@ -7651,5 +7690,77 @@ void tst_QObject::disconnectDisconnects()
Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro<tst_QObject>::Value);
Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value);
+#ifdef QT_BUILD_INTERNAL
+/*
+ Since QObjectPrivate stores the declarativeData pointer in a union with the pointer
+ to the currently destroyed child, calls to the QtDeclarative handlers need to be
+ correctly guarded. QTBUG-105286
+*/
+namespace QtDeclarative {
+static QAbstractDeclarativeData *theData;
+
+static void destroyed(QAbstractDeclarativeData *data, QObject *)
+{
+ QCOMPARE(data, theData);
+}
+static void signalEmitted(QAbstractDeclarativeData *data, QObject *, int, void **)
+{
+ QCOMPARE(data, theData);
+}
+// we can't use QCOMPARE in the next two functions, as they don't return void
+static int receivers(QAbstractDeclarativeData *data, const QObject *, int)
+{
+ QTest::qCompare(data, theData, "data", "theData", __FILE__, __LINE__);
+ return 0;
+}
+static bool isSignalConnected(QAbstractDeclarativeData *data, const QObject *, int)
+{
+ QTest::qCompare(data, theData, "data", "theData", __FILE__, __LINE__);
+ return true;
+}
+
+class Object : public QObject
+{
+ Q_OBJECT
+public:
+ using QObject::QObject;
+ ~Object()
+ {
+ if (Object *p = static_cast<Object *>(parent()))
+ p->emitSignal();
+ }
+
+ void emitSignal()
+ {
+ emit theSignal();
+ }
+
+signals:
+ void theSignal();
+};
+
+}
+#endif
+
+void tst_QObject::declarativeData()
+{
+#ifdef QT_BUILD_INTERNAL
+ QAbstractDeclarativeData::destroyed = QtDeclarative::destroyed;
+ QAbstractDeclarativeData::signalEmitted = QtDeclarative::signalEmitted;
+ QAbstractDeclarativeData::receivers = QtDeclarative::receivers;
+ QAbstractDeclarativeData::isSignalConnected = QtDeclarative::isSignalConnected;
+
+ QtDeclarative::Object p;
+ QObjectPrivate *priv = QObjectPrivate::get(&p);
+ priv->declarativeData = QtDeclarative::theData = new QAbstractDeclarativeData;
+
+ connect(&p, &QtDeclarative::Object::theSignal, &p, []{
+ });
+
+ QtDeclarative::Object *child = new QtDeclarative::Object;
+ child->setParent(&p);
+#endif
+}
+
QTEST_MAIN(tst_QObject)
#include "tst_qobject.moc"