summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-04-04 15:20:51 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-04-06 10:44:40 +0000
commita00a1d8806cfbf17e04b88d1b4ff4a9cf5b6294a (patch)
tree393f227915629c65ca4d63230b0b6f45f2acf341 /tests/auto/corelib
parent2fb7c94f63ce783c7f36149791fe72e053933ece (diff)
QByteArray/QVarLengthArray: add missing resize(n, v) overloads
QList and QString had them, so add them to QByteArray and QVarLengthArray, too. In the QVLA case, we need to jump though a hoop or two to avoid having to duplicate all the reallocation logic. Nothing a few template tricks cannot solve. [ChangeLog][QtCore][QByteArray] Added resize(n, ch) overload. [ChangeLog][QtCore][QVarLengthArray] Added resize(n, v) overload. Fixes: QTBUG-102270 Change-Id: I0d281ae5b574f440f682e4a62427b434dcf5b687 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp18
-rw-r--r--tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp23
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
index 78b6f4d506..1de223d1e7 100644
--- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
@@ -125,6 +125,7 @@ private slots:
void reserve();
void reserveExtended_data();
void reserveExtended();
+ void resize();
void movablity_data();
void movablity();
void literals();
@@ -2091,6 +2092,23 @@ void tst_QByteArray::reserveExtended()
QCOMPARE(array.capacity(), array.size());
}
+void tst_QByteArray::resize()
+{
+ QByteArray ba;
+ ba.resize(15);
+ QCOMPARE(ba.size(), qsizetype(15));
+ ba.resize(10);
+ QCOMPARE(ba.size(), 10);
+ ba.resize(0);
+ QCOMPARE(ba.size(), 0);
+ ba.resize(5, 'a');
+ QCOMPARE(ba.size(), 5);
+ QCOMPARE(ba, "aaaaa");
+ ba.resize(10, 'b');
+ QCOMPARE(ba.size(), 10);
+ QCOMPARE(ba, "aaaaabbbbb");
+}
+
void tst_QByteArray::movablity_data()
{
QTest::addColumn<QByteArray>("array");
diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
index 26fe1167d5..dabf9dd7f4 100644
--- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
+++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
@@ -347,6 +347,17 @@ private Q_SLOTS:
private:
template <typename Container>
+ void resize_impl() const;
+
+private Q_SLOTS:
+ void resize_std_vector() { resize_impl<std::vector<int>>(); }
+ void resize_QList() { resize_impl<QList<qintptr>>(); }
+ void resize_QVarLengthArray() { resize_impl<QVarLengthArray<int>>(); }
+ void resize_QString() { resize_impl<QString>(); }
+ void resize_QByteArray() { resize_impl<QByteArray>(); }
+
+private:
+ template <typename Container>
void front_back_impl() const;
private Q_SLOTS:
@@ -730,6 +741,18 @@ template <typename T> T clean(T &&t) { return std::forward<T>(t); }
inline char clean(QLatin1Char ch) { return ch.toLatin1(); }
template <typename Container>
+void tst_ContainerApiSymmetry::resize_impl() const
+{
+ using V = typename Container::value_type;
+ using S = typename Container::size_type;
+ auto c = make<Container>(3);
+ QCOMPARE(c.size(), S(3));
+ c.resize(4, V(5));
+ QCOMPARE(c.size(), S(4));
+ QCOMPARE(c.back(), V(5));
+}
+
+template <typename Container>
void tst_ContainerApiSymmetry::front_back_impl() const
{
using V = typename Container::value_type;