diff -r ef0373b55136 -r 758a864f9613 tests/auto/collections/tst_collections.cpp --- a/tests/auto/collections/tst_collections.cpp Fri Sep 17 08:34:18 2010 +0300 +++ b/tests/auto/collections/tst_collections.cpp Mon Oct 04 01:19:32 2010 +0300 @@ -165,6 +165,7 @@ void containerTypedefs(); void forwardDeclared(); void alignment(); + void QTBUG13079_collectionInsideCollection(); }; struct LargeStatic { @@ -3589,5 +3590,133 @@ } #endif +#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS + +template class C> +struct QTBUG13079_Node { + C children; + QString s; + + ~QTBUG13079_Node() { + children.begin(); //play with memory + } +}; +template class C> void QTBUG13079_collectionInsideCollectionImpl() +{ + C > nodeList; + nodeList << QTBUG13079_Node(); + nodeList.first().s = "parent"; + nodeList.first().children << QTBUG13079_Node(); + 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(); +} + +template class C> +struct QTBUG13079_NodeAssoc { + C children; + QString s; + + ~QTBUG13079_NodeAssoc() { + children.begin(); //play with memory + } +}; +template class C> void QTBUG13079_collectionInsideCollectionAssocImpl() +{ + C > nodeMap; + nodeMap[18] = QTBUG13079_NodeAssoc(); + nodeMap[18].s = "parent"; + nodeMap[18].children[12] = QTBUG13079_NodeAssoc(); + 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(); +} + + +static quint32 qHash(const QTBUG13079_Node &) +{ + return 0; +} + +bool operator==(const QTBUG13079_Node &a, const QTBUG13079_Node &b) +{ + return a.s == b.s && a.children == b.children; +} + +template class C> +struct QTBUG13079_NodePtr : QSharedData { + C child; + QTBUG13079_NodePtr *next; + QString s; + + QTBUG13079_NodePtr() : next(0) {} + ~QTBUG13079_NodePtr() { + next = child.data(); //play with memory + } +}; +template class C> void QTBUG13079_collectionInsidePtrImpl() +{ + typedef C > Ptr; + { + Ptr nodePtr; + nodePtr = Ptr(new QTBUG13079_NodePtr()); + nodePtr->s = "parent"; + nodePtr->child = Ptr(new QTBUG13079_NodePtr()); + 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()); + nodePtr->s = "parent"; + nodePtr->next = new QTBUG13079_NodePtr(); + 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(); + QTBUG13079_collectionInsideCollectionImpl(); + QTBUG13079_collectionInsideCollectionImpl(); + QTBUG13079_collectionInsideCollectionImpl(); + QTBUG13079_collectionInsideCollectionImpl(); + + { + QSet > nodeSet; + nodeSet << QTBUG13079_Node(); + nodeSet = nodeSet.begin()->children; + QCOMPARE(nodeSet.count(), 0); + } + + QTBUG13079_collectionInsideCollectionAssocImpl(); + QTBUG13079_collectionInsideCollectionAssocImpl(); + + QTBUG13079_collectionInsidePtrImpl(); + QTBUG13079_collectionInsidePtrImpl(); + QTBUG13079_collectionInsidePtrImpl(); +#endif +} + QTEST_APPLESS_MAIN(tst_Collections) #include "tst_collections.moc"