aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-07-29 12:49:37 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-07-29 12:49:37 +0200
commit8b88e37bf79a53eb0cb34226aacb25ad9b01d7cf (patch)
tree6087ee08b55f69f9c4981d9026d3162f2ee50c31 /tests
parent61edb86ed4cc0ac31d77d3793936fa1e8476b504 (diff)
parent7ceca6ac0535a957e9f87f789119c288f6d93837 (diff)
Merge remote-tracking branch 'origin/5.3' into dev
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.cpp60
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h45
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp28
-rw-r--r--tests/auto/qmltest/listview/tst_listview.qml41
4 files changed, 174 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp
index 56e733a423..c4e6709958 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.cpp
+++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp
@@ -338,6 +338,62 @@ static QObject *create_singletonWithEnum(QQmlEngine *, QJSEngine *)
return new SingletonWithEnum;
}
+QObjectContainer::QObjectContainer()
+ : widgetParent(0)
+ , gcOnAppend(false)
+{}
+
+QQmlListProperty<QObject> QObjectContainer::data()
+{
+ return QQmlListProperty<QObject>(this, 0, children_append, children_count, children_at, children_clear);
+}
+
+void QObjectContainer::children_append(QQmlListProperty<QObject> *prop, QObject *o)
+{
+ QObjectContainer *that = static_cast<QObjectContainer*>(prop->object);
+ that->dataChildren.append(o);
+ QObject::connect(o, SIGNAL(destroyed(QObject*)), prop->object, SLOT(childDestroyed(QObject*)));
+
+ if (that->gcOnAppend) {
+ QQmlEngine *engine = qmlEngine(that);
+ engine->collectGarbage();
+ QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::processEvents();
+ }
+}
+
+int QObjectContainer::children_count(QQmlListProperty<QObject> *prop)
+{
+ return static_cast<QObjectContainer*>(prop->object)->dataChildren.count();
+}
+
+QObject *QObjectContainer::children_at(QQmlListProperty<QObject> *prop, int index)
+{
+ return static_cast<QObjectContainer*>(prop->object)->dataChildren.at(index);
+}
+
+void QObjectContainer::children_clear(QQmlListProperty<QObject> *prop)
+{
+ QObjectContainer *that = static_cast<QObjectContainer*>(prop->object);
+ foreach (QObject *c, that->dataChildren)
+ QObject::disconnect(c, SIGNAL(destroyed(QObject*)), that, SLOT(childDestroyed(QObject*)));
+ that->dataChildren.clear();
+}
+
+void QObjectContainer::childDestroyed(QObject *child) {
+ dataChildren.removeAll(child);
+}
+
+void FloatingQObject::classBegin()
+{
+ setParent(0);
+}
+
+void FloatingQObject::componentComplete()
+{
+ Q_ASSERT(!parent());
+}
+
void registerTypes()
{
qmlRegisterType<MyQmlObject>("Qt.test", 1,0, "MyQmlObjectAlias");
@@ -422,6 +478,10 @@ void registerTypes()
qmlRegisterSingletonType<testImportOrderApi>("Qt.test.importOrderApi2",1,0,"Data",testImportOrder_api2);
qmlRegisterSingletonType<SingletonWithEnum>("Qt.test.singletonWithEnum", 1, 0, "SingletonWithEnum", create_singletonWithEnum);
+
+ qmlRegisterType<QObjectContainer>("Qt.test", 1, 0, "QObjectContainer");
+ qmlRegisterType<QObjectContainerWithGCOnAppend>("Qt.test", 1, 0, "QObjectContainerWithGCOnAppend");
+ qmlRegisterType<FloatingQObject>("Qt.test", 1, 0, "FloatingQObject");
}
#include "testtypes.moc"
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index 928d594f62..d5a1220f23 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -1661,6 +1661,51 @@ public:
};
};
+// Like QtObject, but with default property
+class QObjectContainer : public QObject
+{
+ Q_OBJECT
+ Q_CLASSINFO("DefaultProperty", "data")
+ Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false)
+public:
+ QObjectContainer();
+
+ QQmlListProperty<QObject> data();
+
+ static void children_append(QQmlListProperty<QObject> *prop, QObject *o);
+ static int children_count(QQmlListProperty<QObject> *prop);
+ static QObject *children_at(QQmlListProperty<QObject> *prop, int index);
+ static void children_clear(QQmlListProperty<QObject> *prop);
+
+ QList<QObject*> dataChildren;
+ QWidget *widgetParent;
+ bool gcOnAppend;
+
+protected slots:
+ void childDestroyed(QObject *child);
+};
+
+class QObjectContainerWithGCOnAppend : public QObjectContainer
+{
+ Q_OBJECT
+public:
+ QObjectContainerWithGCOnAppend()
+ {
+ gcOnAppend = true;
+ }
+};
+
+class FloatingQObject : public QObject, public QQmlParserStatus
+{
+ Q_OBJECT
+ Q_INTERFACES(QQmlParserStatus)
+public:
+ FloatingQObject() {}
+
+ virtual void classBegin();
+ virtual void componentComplete();
+};
+
void registerTypes();
#endif // TESTTYPES_H
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index d068584797..6b37163b40 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -324,6 +324,7 @@ private slots:
void varPropertyAccessOnObjectWithInvalidContext();
void importedScriptsAccessOnObjectWithInvalidContext();
void contextObjectOnLazyBindings();
+ void garbageCollectionDuringCreation();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -7637,6 +7638,33 @@ void tst_qqmlecmascript::contextObjectOnLazyBindings()
QCOMPARE(subObject->property("testValue").toInt(), int(42));
}
+void tst_qqmlecmascript::garbageCollectionDuringCreation()
+{
+ QQmlComponent component(&engine);
+ component.setData("import Qt.test 1.0\n"
+ "QObjectContainerWithGCOnAppend {\n"
+ " objectName: \"root\"\n"
+ " FloatingQObject {\n"
+ " objectName: \"parentLessChild\"\n"
+ " property var blah;\n" // Ensure we have JS wrapper
+ " }\n"
+ "}\n",
+ QUrl());
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ QObjectContainer *container = qobject_cast<QObjectContainer*>(object.data());
+ QCOMPARE(container->dataChildren.count(), 1);
+
+ QObject *child = container->dataChildren.first();
+ QQmlData *ddata = QQmlData::get(child);
+ QVERIFY(!ddata->jsWrapper.isNullOrUndefined());
+
+ gc(engine);
+ QCOMPARE(container->dataChildren.count(), 0);
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"
diff --git a/tests/auto/qmltest/listview/tst_listview.qml b/tests/auto/qmltest/listview/tst_listview.qml
index 03be57909f..069b62a726 100644
--- a/tests/auto/qmltest/listview/tst_listview.qml
+++ b/tests/auto/qmltest/listview/tst_listview.qml
@@ -108,6 +108,33 @@ Item {
property int createdDelegates: 0
}
+ ListView
+ {
+ id: listInteractiveCurrentIndexEnforce
+ width: 600
+ height: 600
+
+ snapMode: ListView.SnapOneItem
+ orientation: ListView.Horizontal
+ interactive: !currentItem.moving
+ highlightRangeMode: ListView.StrictlyEnforceRange
+
+ model: 4
+
+ focus: true
+ Keys.onPressed: if (event.key == Qt.Key_K) currentIndex = currentIndex + 1;
+
+ delegate: Flickable {
+ width: 600
+ height: 600
+ contentWidth: 600
+ contentHeight: 1200
+
+ MouseArea { anchors.fill: parent }
+ Rectangle { anchors.fill: parent; color: index == 0 ? "red" : index == 1 ? "green" : index == 2 ? "blue" : "white" }
+ }
+ }
+
Component {
id: delegateModelAfterCreateComponent
Rectangle {
@@ -272,5 +299,19 @@ Item {
listViewDelegateModelAfterCreate.model = 40;
verify(listViewDelegateModelAfterCreate.createdDelegates > 0);
}
+
+ function test_listInteractiveCurrentIndexEnforce() {
+ mousePress(listInteractiveCurrentIndexEnforce, 10, 50);
+ mouseMove(listInteractiveCurrentIndexEnforce, 10, 40);
+ mouseMove(listInteractiveCurrentIndexEnforce, 10, 30);
+ mouseMove(listInteractiveCurrentIndexEnforce, 10, 20);
+ mouseMove(listInteractiveCurrentIndexEnforce, 10, 10);
+ compare(listInteractiveCurrentIndexEnforce.interactive, false);
+ mouseRelease(listInteractiveCurrentIndexEnforce, 10, 10);
+ tryCompare(listInteractiveCurrentIndexEnforce, "interactive", true);
+ keyClick("k");
+ compare(listInteractiveCurrentIndexEnforce.currentIndex, 1);
+ tryCompare(listInteractiveCurrentIndexEnforce, "contentX", listInteractiveCurrentIndexEnforce.width);
+ }
}
}