summaryrefslogtreecommitdiff
path: root/tests/auto/collections/tst_collections.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-08-25 18:00:47 +0200
committerOlivier Goffart <olivier.goffart@nokia.com>2010-08-25 18:00:47 +0200
commit913ea0d5cdee3a182a811db2bb9440aee679ae08 (patch)
tree79708faf5c379948eb5aa2f84cb24488a9cb0c4f /tests/auto/collections/tst_collections.cpp
parent5c45c66b1743645b77826ad61508a79eadd48414 (diff)
parentd9dd68c4400c3ca590ea425d6f3d070ea6094099 (diff)
downloadqt4-tools-913ea0d5cdee3a182a811db2bb9440aee679ae08.tar.gz
Merge remote branch 'origin/4.7' into qt-master-from-4.7
Conflicts: qmake/generators/win32/msbuild_objectmodel.cpp src/declarative/qml/qdeclarativexmlhttprequest.cpp src/opengl/opengl.pro src/opengl/qgl_p.h src/plugins/bearer/connman/qconnmanservice_linux.cpp tests/auto/qpainter/tst_qpainter.cpp tools/assistant/tools/assistant/helpviewer_qwv.h tools/assistant/tools/assistant/openpageswidget.h
Diffstat (limited to 'tests/auto/collections/tst_collections.cpp')
-rw-r--r--tests/auto/collections/tst_collections.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/tests/auto/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp
index 4ecd3926e4..0adceee651 100644
--- a/tests/auto/collections/tst_collections.cpp
+++ b/tests/auto/collections/tst_collections.cpp
@@ -165,6 +165,7 @@ private slots:
void containerTypedefs();
void forwardDeclared();
void alignment();
+ void QTBUG13079_collectionInsideCollection();
};
struct LargeStatic {
@@ -3578,5 +3579,133 @@ void tst_Collections::alignment()
}
#endif
+#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
+
+template<template<class> class C>
+struct QTBUG13079_Node {
+ C<QTBUG13079_Node> children;
+ QString s;
+
+ ~QTBUG13079_Node() {
+ children.begin(); //play with memory
+ }
+};
+template<template<class> class C> void QTBUG13079_collectionInsideCollectionImpl()
+{
+ C<QTBUG13079_Node<C> > nodeList;
+ nodeList << QTBUG13079_Node<C>();
+ nodeList.first().s = "parent";
+ nodeList.first().children << QTBUG13079_Node<C>();
+ nodeList.first().children.first().s = "child";
+
+ nodeList = nodeList.first().children;
+ QCOMPARE(nodeList.first().s, QString::fromLatin1("child"));
+
+ nodeList = nodeList.first().children;
+ QCOMPARE(nodeList.count(), 0);
+ nodeList << QTBUG13079_Node<C>();
+}
+
+template<template<class, class> class C>
+struct QTBUG13079_NodeAssoc {
+ C<int, QTBUG13079_NodeAssoc> children;
+ QString s;
+
+ ~QTBUG13079_NodeAssoc() {
+ children.begin(); //play with memory
+ }
+};
+template<template<class, class> class C> void QTBUG13079_collectionInsideCollectionAssocImpl()
+{
+ C<int, QTBUG13079_NodeAssoc<C> > nodeMap;
+ nodeMap[18] = QTBUG13079_NodeAssoc<C>();
+ nodeMap[18].s = "parent";
+ nodeMap[18].children[12] = QTBUG13079_NodeAssoc<C>();
+ nodeMap[18].children[12].s = "child";
+
+ nodeMap = nodeMap[18].children;
+ QCOMPARE(nodeMap[12].s, QString::fromLatin1("child"));
+
+ nodeMap = nodeMap[12].children;
+ QCOMPARE(nodeMap.count(), 0);
+ nodeMap[42] = QTBUG13079_NodeAssoc<C>();
+}
+
+
+static quint32 qHash(const QTBUG13079_Node<QSet> &)
+{
+ return 0;
+}
+
+bool operator==(const QTBUG13079_Node<QSet> &a, const QTBUG13079_Node<QSet> &b)
+{
+ return a.s == b.s && a.children == b.children;
+}
+
+template<template<class> class C>
+struct QTBUG13079_NodePtr : QSharedData {
+ C<QTBUG13079_NodePtr> child;
+ QTBUG13079_NodePtr *next;
+ QString s;
+
+ QTBUG13079_NodePtr() : next(0) {}
+ ~QTBUG13079_NodePtr() {
+ next = child.data(); //play with memory
+ }
+};
+template<template<class> class C> void QTBUG13079_collectionInsidePtrImpl()
+{
+ typedef C<QTBUG13079_NodePtr<C> > Ptr;
+ {
+ Ptr nodePtr;
+ nodePtr = Ptr(new QTBUG13079_NodePtr<C>());
+ nodePtr->s = "parent";
+ nodePtr->child = Ptr(new QTBUG13079_NodePtr<C>());
+ nodePtr->child->s = "child";
+ nodePtr = nodePtr->child;
+ QCOMPARE(nodePtr->s, QString::fromLatin1("child"));
+ nodePtr = nodePtr->child;
+ QVERIFY(!nodePtr);
+ }
+ {
+ Ptr nodePtr;
+ nodePtr = Ptr(new QTBUG13079_NodePtr<C>());
+ nodePtr->s = "parent";
+ nodePtr->next = new QTBUG13079_NodePtr<C>();
+ nodePtr->next->s = "next";
+ nodePtr = Ptr(nodePtr->next);
+ QCOMPARE(nodePtr->s, QString::fromLatin1("next"));
+ nodePtr = Ptr(nodePtr->next);
+ QVERIFY(!nodePtr);
+ }
+}
+
+#endif
+
+void tst_Collections::QTBUG13079_collectionInsideCollection()
+{
+#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
+ QTBUG13079_collectionInsideCollectionImpl<QVector>();
+ QTBUG13079_collectionInsideCollectionImpl<QStack>();
+ QTBUG13079_collectionInsideCollectionImpl<QList>();
+ QTBUG13079_collectionInsideCollectionImpl<QLinkedList>();
+ QTBUG13079_collectionInsideCollectionImpl<QQueue>();
+
+ {
+ QSet<QTBUG13079_Node<QSet> > nodeSet;
+ nodeSet << QTBUG13079_Node<QSet>();
+ nodeSet = nodeSet.begin()->children;
+ QCOMPARE(nodeSet.count(), 0);
+ }
+
+ QTBUG13079_collectionInsideCollectionAssocImpl<QMap>();
+ QTBUG13079_collectionInsideCollectionAssocImpl<QHash>();
+
+ QTBUG13079_collectionInsidePtrImpl<QSharedPointer>();
+ QTBUG13079_collectionInsidePtrImpl<QExplicitlySharedDataPointer>();
+ QTBUG13079_collectionInsidePtrImpl<QSharedDataPointer>();
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_Collections)
#include "tst_collections.moc"