summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qlist
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-03-24 12:53:27 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-05 05:23:07 +0200
commitf1540a2966ce911e9a5d5754e53f6026e3c26d22 (patch)
tree91c60cfa43392dac8152179434099471c4e69bca /tests/auto/corelib/tools/qlist
parent3e930baa98b4382b76aea5ed6ffdcfb60cdce2d4 (diff)
Fix capacity reservation for shared QByteArray
We can squeeze, but not by discarding elements. Make sure the size of the object stays intact after changing the reserved capacity. I've also added unit tests for other containers, just to be sure. Task-number: QTBUG-37750 Change-Id: I5135b095943b7589423c51cebcb52af792468e61 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'tests/auto/corelib/tools/qlist')
-rw-r--r--tests/auto/corelib/tools/qlist/tst_qlist.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
index 2c9bf9d4c9..d77cc4a37c 100644
--- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp
+++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
@@ -278,6 +278,8 @@ private slots:
void setSharableComplex() const;
void eraseValidIteratorsOnSharedList() const;
void insertWithValidIteratorsOnSharedList() const;
+
+ void reserve() const;
private:
template<typename T> void length() const;
template<typename T> void append() const;
@@ -1669,5 +1671,31 @@ void tst_QList::insertWithValidIteratorsOnSharedList() const
QCOMPARE(a.at(1), 15);
}
+void tst_QList::reserve() const
+{
+ // Note:
+ // This test depends on QList's current behavior that ints are stored in the array itself.
+ // This test would not work for QList<Complex>.
+ int capacity = 100;
+ QList<int> list;
+ list.reserve(capacity);
+ list << 0;
+ int *data = &list[0];
+
+ for (int i = 1; i < capacity; i++) {
+ list << i;
+ QCOMPARE(&list.at(0), data);
+ }
+
+ QList<int> copy = list;
+ list.reserve(capacity / 2);
+ QCOMPARE(list.size(), capacity); // we didn't shrink the size!
+
+ copy = list;
+ list.reserve(capacity * 2);
+ QCOMPARE(list.size(), capacity);
+ QVERIFY(&list.at(0) != data);
+}
+
QTEST_APPLESS_MAIN(tst_QList)
#include "tst_qlist.moc"