aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcomponent
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlcomponent')
-rw-r--r--tests/auto/qml/qqmlcomponent/data/onDestructionCount.qml16
-rw-r--r--tests/auto/qml/qqmlcomponent/data/onDestructionLookup.qml25
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp43
3 files changed, 84 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcomponent/data/onDestructionCount.qml b/tests/auto/qml/qqmlcomponent/data/onDestructionCount.qml
new file mode 100644
index 0000000000..3938acf6a5
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/onDestructionCount.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.0
+
+Item {
+ Component {
+ id: internalComponent
+
+ Item {
+ Component.onDestruction: console.warn('Component.onDestruction')
+ }
+ }
+
+ Component.onCompleted: {
+ internalComponent.createObject()
+ gc()
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/onDestructionLookup.qml b/tests/auto/qml/qqmlcomponent/data/onDestructionLookup.qml
new file mode 100644
index 0000000000..a49a86e1f3
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/onDestructionLookup.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+
+ property bool success: false
+
+ Component {
+ id: internalComponent
+
+ Item {
+ id: internalRoot
+
+ property string foo: ''
+
+ Component.onCompleted: { internalRoot.foo = 'bar' }
+ Component.onDestruction: { root.success = (internalRoot.foo == 'bar') }
+ }
+ }
+
+ Component.onCompleted: {
+ internalComponent.createObject()
+ gc()
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index b534d0c788..bf76ed962b 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -112,6 +112,8 @@ private slots:
void async();
void asyncHierarchy();
void componentUrlCanonicalization();
+ void onDestructionLookup();
+ void onDestructionCount();
private:
QQmlEngine engine;
@@ -366,6 +368,47 @@ void tst_qqmlcomponent::componentUrlCanonicalization()
}
}
+void tst_qqmlcomponent::onDestructionLookup()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("onDestructionLookup.qml"));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(object != 0);
+ QVERIFY(object->property("success").toBool());
+}
+
+void tst_qqmlcomponent::onDestructionCount()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("onDestructionCount.qml"));
+
+ QLatin1String warning("Component.onDestruction");
+
+ {
+ // Warning should be emitted during create()
+ QTest::ignoreMessage(QtWarningMsg, warning.data());
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(object != 0);
+ }
+
+ // Warning should not be emitted any further
+ QCOMPARE(engine.outputWarningsToStandardError(), true);
+
+ warnings.clear();
+ QtMsgHandler old = qInstallMsgHandler(msgHandler);
+
+ QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::processEvents();
+
+ qInstallMsgHandler(old);
+
+ engine.setOutputWarningsToStandardError(false);
+ QCOMPARE(engine.outputWarningsToStandardError(), false);
+
+ QCOMPARE(warnings.count(), 0);
+}
+
QTEST_MAIN(tst_qqmlcomponent)
#include "tst_qqmlcomponent.moc"