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/createObject.qml38
-rw-r--r--tests/auto/qml/qqmlcomponent/data/createQmlObject.qml32
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp93
3 files changed, 135 insertions, 28 deletions
diff --git a/tests/auto/qml/qqmlcomponent/data/createObject.qml b/tests/auto/qml/qqmlcomponent/data/createObject.qml
index da5db8e8e6..afd9e71229 100644
--- a/tests/auto/qml/qqmlcomponent/data/createObject.qml
+++ b/tests/auto/qml/qqmlcomponent/data/createObject.qml
@@ -1,13 +1,35 @@
import QtQuick 2.0
+import QtQuick.Window 2.0
-Item{
- id: root
- property QtObject qobject : null
- property QtObject declarativeitem : null
- Component{id: a; QtObject{} }
- Component{id: b; Item{} }
+Item {
+ property QtObject qtobjectParent: QtObject { }
+ property QtObject itemParent: Item { }
+ property QtObject windowParent: Window { }
+
+ property QtObject qtobject_qtobject : null
+ property QtObject qtobject_item : null
+ property QtObject qtobject_window : null
+
+ property QtObject item_qtobject : null
+ property QtObject item_item : null
+ property QtObject item_window : null
+
+ property QtObject window_qtobject : null
+ property QtObject window_item : null
+ property QtObject window_window : null
+
+ Component { id: a; QtObject{} }
+ Component { id: b; Item{} }
+ Component { id: c; Window{} }
Component.onCompleted: {
- root.qobject = a.createObject(root);
- root.declarativeitem = b.createObject(root);
+ qtobject_qtobject = a.createObject(qtobjectParent);
+ qtobject_item = b.createObject(qtobjectParent);
+ qtobject_window = c.createObject(qtobjectParent);
+ item_qtobject = a.createObject(itemParent);
+ item_item = b.createObject(itemParent);
+ item_window = c.createObject(itemParent);
+ window_qtobject = a.createObject(windowParent);
+ window_item = b.createObject(windowParent);
+ window_window = c.createObject(windowParent);
}
}
diff --git a/tests/auto/qml/qqmlcomponent/data/createQmlObject.qml b/tests/auto/qml/qqmlcomponent/data/createQmlObject.qml
new file mode 100644
index 0000000000..282ab509f0
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/createQmlObject.qml
@@ -0,0 +1,32 @@
+import QtQuick 2.0
+import QtQuick.Window 2.0
+
+Item {
+ property QtObject qtobjectParent: QtObject { }
+ property QtObject itemParent: Item { }
+ property QtObject windowParent: Window { }
+
+ property QtObject qtobject_qtobject : null
+ property QtObject qtobject_item : null
+ property QtObject qtobject_window : null
+
+ property QtObject item_qtobject : null
+ property QtObject item_item : null
+ property QtObject item_window : null
+
+ property QtObject window_qtobject : null
+ property QtObject window_item : null
+ property QtObject window_window : null
+
+ Component.onCompleted: {
+ qtobject_qtobject = Qt.createQmlObject("import QtQuick 2.0; QtObject{}", qtobjectParent);
+ qtobject_item = Qt.createQmlObject("import QtQuick 2.0; Item{}", qtobjectParent);
+ qtobject_window = Qt.createQmlObject("import QtQuick.Window 2.0; Window{}", qtobjectParent);
+ item_qtobject = Qt.createQmlObject("import QtQuick 2.0; QtObject{}", itemParent);
+ item_item = Qt.createQmlObject("import QtQuick 2.0; Item{}", itemParent);
+ item_window = Qt.createQmlObject("import QtQuick.Window 2.0; Window{}", itemParent);
+ window_qtobject = Qt.createQmlObject("import QtQuick 2.0; QtObject{}", windowParent);
+ window_item = Qt.createQmlObject("import QtQuick 2.0; Item{}", windowParent);
+ window_window = Qt.createQmlObject("import QtQuick.Window 2.0; Window{}", windowParent);
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index 1e02eb8376..bb159d5931 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
@@ -10,9 +10,9 @@
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -23,8 +23,8 @@
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
@@ -103,7 +103,8 @@ private slots:
void null();
void loadEmptyUrl();
void qmlCreateWindow();
- void qmlCreateObject();
+ void qmlCreateObjectAutoParent_data();
+ void qmlCreateObjectAutoParent();
void qmlCreateObjectWithProperties();
void qmlIncubateObject();
void qmlCreateParentReference();
@@ -170,21 +171,73 @@ void tst_qqmlcomponent::qmlCreateWindow()
QVERIFY(window);
}
-void tst_qqmlcomponent::qmlCreateObject()
+void tst_qqmlcomponent::qmlCreateObjectAutoParent_data()
{
- QQmlEngine engine;
- QQmlComponent component(&engine, testFileUrl("createObject.qml"));
- QObject *object = component.create();
- QVERIFY(object != 0);
+ QTest::addColumn<QString>("testFile");
- QObject *testObject1 = object->property("qobject").value<QObject*>();
- QVERIFY(testObject1);
- QVERIFY(testObject1->parent() == object);
+ QTest::newRow("createObject") << QStringLiteral("createObject.qml");
+ QTest::newRow("createQmlObject") << QStringLiteral("createQmlObject.qml");
+}
- QObject *testObject2 = object->property("declarativeitem").value<QObject*>();
- QVERIFY(testObject2);
- QVERIFY(testObject2->parent() == object);
- QCOMPARE(testObject2->metaObject()->className(), "QQuickItem");
+
+void tst_qqmlcomponent::qmlCreateObjectAutoParent()
+{
+ QFETCH(QString, testFile);
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl(testFile));
+ QQuickItem *root = qobject_cast<QQuickItem *>(component.create());
+ QVERIFY(root);
+ QObject *qtobjectParent = root->property("qtobjectParent").value<QObject*>();
+ QQuickItem *itemParent = qobject_cast<QQuickItem *>(root->property("itemParent").value<QObject*>());
+ QQuickWindow *windowParent = qobject_cast<QQuickWindow *>(root->property("windowParent").value<QObject*>());
+ QVERIFY(qtobjectParent);
+ QVERIFY(itemParent);
+ QVERIFY(windowParent);
+
+ QObject *qtobject_qtobject = root->property("qtobject_qtobject").value<QObject*>();
+ QObject *qtobject_item = root->property("qtobject_item").value<QObject*>();
+ QObject *qtobject_window = root->property("qtobject_window").value<QObject*>();
+ QObject *item_qtobject = root->property("item_qtobject").value<QObject*>();
+ QObject *item_item = root->property("item_item").value<QObject*>();
+ QObject *item_window = root->property("item_window").value<QObject*>();
+ QObject *window_qtobject = root->property("window_qtobject").value<QObject*>();
+ QObject *window_item = root->property("window_item").value<QObject*>();
+ QObject *window_window = root->property("window_window").value<QObject*>();
+
+ QVERIFY(qtobject_qtobject);
+ QVERIFY(qtobject_item);
+ QVERIFY(qtobject_window);
+ QVERIFY(item_qtobject);
+ QVERIFY(item_item);
+ QVERIFY(item_window);
+ QVERIFY(window_qtobject);
+ QVERIFY(window_item);
+ QVERIFY(window_window);
+
+ QCOMPARE(qtobject_item->metaObject()->className(), "QQuickItem");
+ QCOMPARE(qtobject_window->metaObject()->className(), "QQuickWindow");
+ QCOMPARE(item_item->metaObject()->className(), "QQuickItem");
+ QCOMPARE(item_window->metaObject()->className(), "QQuickWindow");
+ QCOMPARE(window_item->metaObject()->className(), "QQuickItem");
+ QCOMPARE(window_window->metaObject()->className(), "QQuickWindow");
+
+ QCOMPARE(qtobject_qtobject->parent(), qtobjectParent);
+ QCOMPARE(qtobject_item->parent(), qtobjectParent);
+ QCOMPARE(qtobject_window->parent(), qtobjectParent);
+ QCOMPARE(item_qtobject->parent(), itemParent);
+ QCOMPARE(item_item->parent(), itemParent);
+ QCOMPARE(item_window->parent(), itemParent);
+ QCOMPARE(window_qtobject->parent(), windowParent);
+ QCOMPARE(window_item->parent(), windowParent);
+ QCOMPARE(window_window->parent(), windowParent);
+
+ QCOMPARE(qobject_cast<QQuickItem *>(qtobject_item)->parentItem(), (QQuickItem *)0);
+ QCOMPARE(qobject_cast<QQuickWindow *>(qtobject_window)->transientParent(), (QQuickWindow *)0);
+ QCOMPARE(qobject_cast<QQuickItem *>(item_item)->parentItem(), itemParent);
+ QCOMPARE(qobject_cast<QQuickWindow *>(item_window)->transientParent(), itemParent->window());
+ QCOMPARE(qobject_cast<QQuickItem *>(window_item)->parentItem(), windowParent->contentItem());
+ QCOMPARE(qobject_cast<QQuickWindow *>(window_window)->transientParent(), windowParent);
}
void tst_qqmlcomponent::qmlCreateObjectWithProperties()