aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index a45efc793c..787bac1520 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -3862,6 +3862,64 @@ void tst_qqmlecmascript::scriptConnect()
QScopedPointer<QObject> root { component.create() };
QVERIFY2(root, qPrintable(component.errorString()));
}
+
+ {
+ QQmlComponent component(&engine, testFileUrl("scriptConnect.8.qml"));
+
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ QVERIFY(obj.data() != nullptr);
+
+ QCOMPARE(obj.data()->property("count"), 0);
+
+ QMetaObject::invokeMethod(obj.data(), "someSignal");
+ QCOMPARE(obj.data()->property("count"), 1);
+
+ QMetaObject::invokeMethod(obj.data(), "itemDestroy");
+ QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
+ QCoreApplication::processEvents();
+
+ QMetaObject::invokeMethod(obj.data(), "someSignal");
+ QCOMPARE(obj.data()->property("count"), 1);
+ }
+
+ {
+ QQmlComponent component(&engine, testFileUrl("scriptConnect.9.qml"));
+
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ QVERIFY(obj.data() != nullptr);
+
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
+
+ QCOMPARE(object->property("a"), 0);
+
+ QMetaObject::invokeMethod(object, "someSignal");
+ QCOMPARE(object->property("a"), 1);
+
+ QMetaObject::invokeMethod(object, "destroyObj", Qt::DirectConnection);
+ QApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
+ QApplication::processEvents();
+
+ QMetaObject::invokeMethod(object, "someSignal");
+
+ QCOMPARE(object->property("a"), 1);
+ }
+
+ {
+ QQmlComponent component(&engine, testFileUrl("scriptConnectSingleton.qml"));
+
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ QVERIFY(obj.data() != nullptr);
+
+ QMetaObject::invokeMethod(obj.data(), "mySignal", Qt::DirectConnection);
+ QCOMPARE(obj.data()->property("a").toInt(), 1);
+ engine.clearSingletons();
+ QMetaObject::invokeMethod(obj.data(), "mySignal", Qt::DirectConnection);
+ QCOMPARE(obj.data()->property("a").toInt(), 1);
+
+ }
}
void tst_qqmlecmascript::scriptDisconnect()
@@ -3942,6 +4000,60 @@ void tst_qqmlecmascript::scriptDisconnect()
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->property("test").toInt(), 3);
}
+
+ {
+ QQmlComponent component(&engine, testFileUrl("scriptDisconnect.5.qml"));
+
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ QVERIFY(obj.data() != nullptr);
+
+ QCOMPARE(obj.data()->property("count"), 0);
+
+ QMetaObject::invokeMethod(obj.data(), "someSignal");
+ QCOMPARE(obj.data()->property("count"), 1);
+
+ QMetaObject::invokeMethod(obj.data(), "disconnectSignal");
+
+ QMetaObject::invokeMethod(obj.data(), "someSignal");
+ QCOMPARE(obj.data()->property("count"), 1);
+ }
+
+ {
+ QQmlComponent component(&engine, testFileUrl("scriptConnect.9.qml"));
+
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ QVERIFY(obj.data() != nullptr);
+
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(obj.data());
+
+ QCOMPARE(object->property("a"), 0);
+
+ QMetaObject::invokeMethod(object, "someSignal");
+ QCOMPARE(object->property("a"), 1);
+
+ QMetaObject::invokeMethod(object, "disconnectSignal", Qt::DirectConnection);
+
+ QMetaObject::invokeMethod(object, "someSignal");
+
+ QCOMPARE(object->property("a"), 1);
+ }
+
+ {
+ QQmlComponent component(&engine, testFileUrl("scriptConnectSingleton.qml"));
+
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+ QVERIFY(obj.data() != nullptr);
+
+ QMetaObject::invokeMethod(obj.data(), "mySignal", Qt::DirectConnection);
+ QCOMPARE(obj.data()->property("a").toInt(), 1);
+
+ QMetaObject::invokeMethod(obj.data(), "disconnectSingleton", Qt::DirectConnection);
+ QMetaObject::invokeMethod(obj.data(), "mySignal", Qt::DirectConnection);
+ QCOMPARE(obj.data()->property("a").toInt(), 1);
+ }
}
class OwnershipObject : public QObject