summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-02-17 00:54:04 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-02-21 18:46:35 +0000
commitcbdf40c4292aa4fc4038d4c12880b16c60b58d9e (patch)
tree331514d4be3eb8a593c02a235cadaeb88c864439 /tests
parent152e927d0883df98eef622b9631a26cdec4fdf7e (diff)
QVarLengthArray: fix appending an already-contained item
Like the lvalue QVector::append() overload, when we reallocate, we need to take a copy of the function's argument because the reference will get stale upon reallocation. Add a test. [ChangeLog][QtCore][QVarLengthArray] Fixed a bug involving appending an item already in the container to the container again. Change-Id: I06eeed6cb383dd5924e47a302bb3d1666d04c8e8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 0e3d6fe4f69955bf98e23a382caf5251e2b47ea0)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index 82f78b2b0b..466b7a3ac4 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -82,8 +82,21 @@ struct Foo
void tst_QVarLengthArray::append()
{
- QVarLengthArray<QString> v;
- v.append(QString("hello"));
+ QVarLengthArray<QString, 2> v;
+ v.append(QString("1"));
+ v.append(v.front());
+ QCOMPARE(v.capacity(), 2);
+ // transition from prealloc to heap:
+ v.append(v.front());
+ QVERIFY(v.capacity() > 2);
+ QCOMPARE(v.front(), v.back());
+ while (v.size() < v.capacity())
+ v.push_back(v[0]);
+ QCOMPARE(v.back(), v.front());
+ QCOMPARE(v.size(), v.capacity());
+ // transition from heap to larger heap:
+ v.push_back(v.front());
+ QCOMPARE(v.back(), v.front());
QVarLengthArray<int> v2; // rocket!
v2.append(5);