diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-02-27 14:30:21 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-03-02 14:16:00 +0000 |
commit | 4cd3d57b247d64d23d775d16a2b2fb3eb8d9de21 (patch) | |
tree | 317d111c93d10446f9f37399f8e24bdebbee52f4 | |
parent | 7da13272dfcd18b762ef6fdc46ad75825aed7953 (diff) |
tst_qvarlengtharray: add test for QVLA(n) ctor
Also add one for types that are neither copy- nor move-constructible.
In contrast to resize(n), the QVLA(n) ctor worked for such types, so
make sure it stays that way.
Manual conflict resolutions:
- QCOMPARE_GE() is 6.4+, use QVERIFY( >= ) instead.
Change-Id: If54fbc9dd6a4808175c4bcb0ffb492b33c879746
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit e7c792ba7179c4c81fb2e26f66031ec81234b0d7)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 578d6e7ab0..e9dd40f822 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -65,12 +65,29 @@ public: { return !operator==(lhs, rhs); } }; +class NonCopyable +{ + Q_DISABLE_COPY(NonCopyable) + int n; +public: + NonCopyable() : n(0) {} + explicit NonCopyable(int n) : n(n) {} + + friend bool operator==(const NonCopyable &lhs, const NonCopyable &rhs) noexcept + { return lhs.n == rhs.n; } + friend bool operator!=(const NonCopyable &lhs, const NonCopyable &rhs) noexcept + { return !operator==(lhs, rhs); } +}; + class tst_QVarLengthArray : public QObject { Q_OBJECT private slots: void defaultConstructor_int() { defaultConstructor<int>(); } void defaultConstructor_QString() { defaultConstructor<QString>(); } + void sizeConstructor_int() { sizeConstructor<int>(); } + void sizeConstructor_QString() { sizeConstructor<QString>(); } + void sizeConstructor_NonCopyable() { sizeConstructor<NonCopyable>(); } void append(); void prepend(); void insertToEmpty(); @@ -118,6 +135,8 @@ private slots: private: template <typename T> void defaultConstructor(); + template <typename T> + void sizeConstructor(); template <qsizetype N, typename T> void move(T t1, T t2); template <qsizetype N> @@ -147,6 +166,31 @@ void tst_QVarLengthArray::defaultConstructor() } } +template <typename T> +void tst_QVarLengthArray::sizeConstructor() +{ + { + QVarLengthArray<T, 123> vla(0); + QCOMPARE(vla.size(), 0); + QVERIFY(vla.empty()); + QVERIFY(vla.isEmpty()); + QCOMPARE(vla.begin(), vla.end()); + QCOMPARE(vla.capacity(), 123); + } + { + QVarLengthArray<T, 124> vla(124); + QCOMPARE(vla.size(), 124); + QVERIFY(!vla.empty()); + QCOMPARE(vla.capacity(), 124); + } + { + QVarLengthArray<T, 124> vla(125); + QCOMPARE(vla.size(), 125); + QVERIFY(!vla.empty()); + QVERIFY(vla.capacity() >= 125); + } +} + void tst_QVarLengthArray::append() { QVarLengthArray<QString, 2> v; |