3587 { |
3588 { |
3588 QSKIP("Compiler doesn't support necessary extension keywords", SkipAll); |
3589 QSKIP("Compiler doesn't support necessary extension keywords", SkipAll); |
3589 } |
3590 } |
3590 #endif |
3591 #endif |
3591 |
3592 |
|
3593 #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS |
|
3594 |
|
3595 template<template<class> class C> |
|
3596 struct QTBUG13079_Node { |
|
3597 C<QTBUG13079_Node> children; |
|
3598 QString s; |
|
3599 |
|
3600 ~QTBUG13079_Node() { |
|
3601 children.begin(); //play with memory |
|
3602 } |
|
3603 }; |
|
3604 template<template<class> class C> void QTBUG13079_collectionInsideCollectionImpl() |
|
3605 { |
|
3606 C<QTBUG13079_Node<C> > nodeList; |
|
3607 nodeList << QTBUG13079_Node<C>(); |
|
3608 nodeList.first().s = "parent"; |
|
3609 nodeList.first().children << QTBUG13079_Node<C>(); |
|
3610 nodeList.first().children.first().s = "child"; |
|
3611 |
|
3612 nodeList = nodeList.first().children; |
|
3613 QCOMPARE(nodeList.first().s, QString::fromLatin1("child")); |
|
3614 |
|
3615 nodeList = nodeList.first().children; |
|
3616 QCOMPARE(nodeList.count(), 0); |
|
3617 nodeList << QTBUG13079_Node<C>(); |
|
3618 } |
|
3619 |
|
3620 template<template<class, class> class C> |
|
3621 struct QTBUG13079_NodeAssoc { |
|
3622 C<int, QTBUG13079_NodeAssoc> children; |
|
3623 QString s; |
|
3624 |
|
3625 ~QTBUG13079_NodeAssoc() { |
|
3626 children.begin(); //play with memory |
|
3627 } |
|
3628 }; |
|
3629 template<template<class, class> class C> void QTBUG13079_collectionInsideCollectionAssocImpl() |
|
3630 { |
|
3631 C<int, QTBUG13079_NodeAssoc<C> > nodeMap; |
|
3632 nodeMap[18] = QTBUG13079_NodeAssoc<C>(); |
|
3633 nodeMap[18].s = "parent"; |
|
3634 nodeMap[18].children[12] = QTBUG13079_NodeAssoc<C>(); |
|
3635 nodeMap[18].children[12].s = "child"; |
|
3636 |
|
3637 nodeMap = nodeMap[18].children; |
|
3638 QCOMPARE(nodeMap[12].s, QString::fromLatin1("child")); |
|
3639 |
|
3640 nodeMap = nodeMap[12].children; |
|
3641 QCOMPARE(nodeMap.count(), 0); |
|
3642 nodeMap[42] = QTBUG13079_NodeAssoc<C>(); |
|
3643 } |
|
3644 |
|
3645 |
|
3646 static quint32 qHash(const QTBUG13079_Node<QSet> &) |
|
3647 { |
|
3648 return 0; |
|
3649 } |
|
3650 |
|
3651 bool operator==(const QTBUG13079_Node<QSet> &a, const QTBUG13079_Node<QSet> &b) |
|
3652 { |
|
3653 return a.s == b.s && a.children == b.children; |
|
3654 } |
|
3655 |
|
3656 template<template<class> class C> |
|
3657 struct QTBUG13079_NodePtr : QSharedData { |
|
3658 C<QTBUG13079_NodePtr> child; |
|
3659 QTBUG13079_NodePtr *next; |
|
3660 QString s; |
|
3661 |
|
3662 QTBUG13079_NodePtr() : next(0) {} |
|
3663 ~QTBUG13079_NodePtr() { |
|
3664 next = child.data(); //play with memory |
|
3665 } |
|
3666 }; |
|
3667 template<template<class> class C> void QTBUG13079_collectionInsidePtrImpl() |
|
3668 { |
|
3669 typedef C<QTBUG13079_NodePtr<C> > Ptr; |
|
3670 { |
|
3671 Ptr nodePtr; |
|
3672 nodePtr = Ptr(new QTBUG13079_NodePtr<C>()); |
|
3673 nodePtr->s = "parent"; |
|
3674 nodePtr->child = Ptr(new QTBUG13079_NodePtr<C>()); |
|
3675 nodePtr->child->s = "child"; |
|
3676 nodePtr = nodePtr->child; |
|
3677 QCOMPARE(nodePtr->s, QString::fromLatin1("child")); |
|
3678 nodePtr = nodePtr->child; |
|
3679 QVERIFY(!nodePtr); |
|
3680 } |
|
3681 { |
|
3682 Ptr nodePtr; |
|
3683 nodePtr = Ptr(new QTBUG13079_NodePtr<C>()); |
|
3684 nodePtr->s = "parent"; |
|
3685 nodePtr->next = new QTBUG13079_NodePtr<C>(); |
|
3686 nodePtr->next->s = "next"; |
|
3687 nodePtr = Ptr(nodePtr->next); |
|
3688 QCOMPARE(nodePtr->s, QString::fromLatin1("next")); |
|
3689 nodePtr = Ptr(nodePtr->next); |
|
3690 QVERIFY(!nodePtr); |
|
3691 } |
|
3692 } |
|
3693 |
|
3694 #endif |
|
3695 |
|
3696 void tst_Collections::QTBUG13079_collectionInsideCollection() |
|
3697 { |
|
3698 #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS |
|
3699 QTBUG13079_collectionInsideCollectionImpl<QVector>(); |
|
3700 QTBUG13079_collectionInsideCollectionImpl<QStack>(); |
|
3701 QTBUG13079_collectionInsideCollectionImpl<QList>(); |
|
3702 QTBUG13079_collectionInsideCollectionImpl<QLinkedList>(); |
|
3703 QTBUG13079_collectionInsideCollectionImpl<QQueue>(); |
|
3704 |
|
3705 { |
|
3706 QSet<QTBUG13079_Node<QSet> > nodeSet; |
|
3707 nodeSet << QTBUG13079_Node<QSet>(); |
|
3708 nodeSet = nodeSet.begin()->children; |
|
3709 QCOMPARE(nodeSet.count(), 0); |
|
3710 } |
|
3711 |
|
3712 QTBUG13079_collectionInsideCollectionAssocImpl<QMap>(); |
|
3713 QTBUG13079_collectionInsideCollectionAssocImpl<QHash>(); |
|
3714 |
|
3715 QTBUG13079_collectionInsidePtrImpl<QSharedPointer>(); |
|
3716 QTBUG13079_collectionInsidePtrImpl<QExplicitlySharedDataPointer>(); |
|
3717 QTBUG13079_collectionInsidePtrImpl<QSharedDataPointer>(); |
|
3718 #endif |
|
3719 } |
|
3720 |
3592 QTEST_APPLESS_MAIN(tst_Collections) |
3721 QTEST_APPLESS_MAIN(tst_Collections) |
3593 #include "tst_collections.moc" |
3722 #include "tst_collections.moc" |