summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-12 17:04:26 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-16 00:01:41 +0100
commit81bf3e68b9edb6fc8635ab5520f86df9c8d6ef04 (patch)
tree9a111d74c4891cf7c7c88614e1a247d2a5bad5b4 /tests/auto/corelib/tools
parent758a830f7ef23ebea542bc6dad4490b29e22bab8 (diff)
Make QRingBuffer a move-only type
There's no sense in copying a ring buffer. Moving is enough. This marks an important step on the way to preventing accidental copies of ring buffer content, because the 'QList buffers' member can now no longer be implicitly shared. While the compiler will still emit the code for detach()ing, it will now never be executed. Pick-to: 6.3 Change-Id: I968bfe3e50c46720ed4baca55c99c1f9c518f653 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
index 3b922de0ca..6efa39f4f5 100644
--- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
+++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
@@ -38,6 +38,7 @@ class tst_QRingBuffer : public QObject
private slots:
void constructing();
void usingInVector();
+ void usingInVarLengthArray();
void readPointerAtPositionWriteRead();
void readPointerAtPositionEmptyRead();
void readPointerAtPositionWithHead();
@@ -83,10 +84,20 @@ void tst_QRingBuffer::constructing()
void tst_QRingBuffer::usingInVector()
{
QRingBuffer ringBuffer;
- QList<QRingBuffer> buffers;
+ std::vector<QRingBuffer> buffers;
ringBuffer.reserve(5);
- buffers.append(ringBuffer);
+ buffers.push_back(std::move(ringBuffer));
+ QCOMPARE(buffers[0].size(), Q_INT64_C(5));
+}
+
+void tst_QRingBuffer::usingInVarLengthArray()
+{
+ QRingBuffer ringBuffer;
+ QVarLengthArray<QRingBuffer, 42> buffers;
+
+ ringBuffer.reserve(5);
+ buffers.push_back(std::move(ringBuffer));
QCOMPARE(buffers[0].size(), Q_INT64_C(5));
}