From f1540a2966ce911e9a5d5754e53f6026e3c26d22 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 24 Mar 2014 12:53:27 -0700 Subject: Fix capacity reservation for shared QByteArray MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/auto/corelib/tools/qbytearray') diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index b06741b23e..6e183f3212 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -1855,6 +1855,21 @@ void tst_QByteArray::reserve() QVERIFY(data == qba.data()); } + qba.resize(capacity); + + QByteArray copy = qba; + qba.reserve(capacity / 2); + QCOMPARE(qba.size(), capacity); // we didn't shrink the size! + QCOMPARE(qba.capacity(), capacity); + QCOMPARE(copy.capacity(), capacity); + + copy = qba; + qba.reserve(capacity * 2); + QCOMPARE(qba.size(), capacity); + QCOMPARE(qba.capacity(), capacity * 2); + QCOMPARE(copy.capacity(), capacity); + QVERIFY(qba.constData() != data); + QByteArray nil1, nil2; nil1.reserve(0); nil2.squeeze(); -- cgit v1.2.3