diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-08-23 11:44:12 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-08-23 15:22:31 (GMT) |
commit | a2f83283a64460ca26530321f8eb64f3ddfe4c8b (patch) | |
tree | c06929f2751f839245bd434b42fbe9fe8de43ee6 /tests/auto/collections | |
parent | d405aa6510514ce02b312994db55c305bde60285 (diff) | |
download | Qt-a2f83283a64460ca26530321f8eb64f3ddfe4c8b.zip Qt-a2f83283a64460ca26530321f8eb64f3ddfe4c8b.tar.gz Qt-a2f83283a64460ca26530321f8eb64f3ddfe4c8b.tar.bz2 |
Fix assignment of a container included in the container itself
Task-number: QTBUG-13079
Reviewed-by: Joao
Diffstat (limited to 'tests/auto/collections')
-rw-r--r-- | tests/auto/collections/tst_collections.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/auto/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp index d092c34..8617e02 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 { @@ -3589,5 +3590,91 @@ 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; +} + +#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>(); +#endif +} + QTEST_APPLESS_MAIN(tst_Collections) #include "tst_collections.moc" |