summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qbytedatabuffer
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qbytedatabuffer')
-rw-r--r--tests/auto/corelib/text/qbytedatabuffer/CMakeLists.txt19
-rw-r--r--tests/auto/corelib/text/qbytedatabuffer/qbytedatabuffer.pro4
-rw-r--r--tests/auto/corelib/text/qbytedatabuffer/tst_qbytedatabuffer.cpp99
3 files changed, 90 insertions, 32 deletions
diff --git a/tests/auto/corelib/text/qbytedatabuffer/CMakeLists.txt b/tests/auto/corelib/text/qbytedatabuffer/CMakeLists.txt
new file mode 100644
index 0000000000..bfcfb6bc98
--- /dev/null
+++ b/tests/auto/corelib/text/qbytedatabuffer/CMakeLists.txt
@@ -0,0 +1,19 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## tst_qbytedatabuffer Test:
+#####################################################################
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qbytedatabuffer LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qbytedatabuffer
+ SOURCES
+ tst_qbytedatabuffer.cpp
+ LIBRARIES
+ Qt::CorePrivate
+)
diff --git a/tests/auto/corelib/text/qbytedatabuffer/qbytedatabuffer.pro b/tests/auto/corelib/text/qbytedatabuffer/qbytedatabuffer.pro
deleted file mode 100644
index e23018f96a..0000000000
--- a/tests/auto/corelib/text/qbytedatabuffer/qbytedatabuffer.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TARGET = tst_qbytedatabuffer
-CONFIG += testcase
-QT = core-private testlib
-SOURCES += tst_qbytedatabuffer.cpp
diff --git a/tests/auto/corelib/text/qbytedatabuffer/tst_qbytedatabuffer.cpp b/tests/auto/corelib/text/qbytedatabuffer/tst_qbytedatabuffer.cpp
index 59f4d153e6..27482f6486 100644
--- a/tests/auto/corelib/text/qbytedatabuffer/tst_qbytedatabuffer.cpp
+++ b/tests/auto/corelib/text/qbytedatabuffer/tst_qbytedatabuffer.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <private/qbytedata_p.h>
@@ -38,10 +13,12 @@ private Q_SLOTS:
void canReadLine();
void positionHandling();
void appendBuffer();
+ void moveAppendBuffer();
void readCompleteBuffer_data();
void readCompleteBuffer();
void readPartialBuffer_data();
void readPartialBuffer();
+ void readPointer();
private:
void readBuffer(int size, int readSize);
};
@@ -91,7 +68,8 @@ void tst_QByteDataBuffer::positionHandling()
void tst_QByteDataBuffer::appendBuffer()
{
QByteDataBuffer buf;
- buf.append(QByteArray("\1\2\3"));
+ QByteArray local("\1\2\3");
+ buf.append(local);
buf.getChar();
QByteDataBuffer tmp;
@@ -99,6 +77,17 @@ void tst_QByteDataBuffer::appendBuffer()
QCOMPARE(tmp.readAll(), buf.readAll());
}
+void tst_QByteDataBuffer::moveAppendBuffer()
+{
+ QByteDataBuffer buf;
+ buf.append(QByteArray("hello world"));
+ QCOMPARE(buf.getChar(), 'h');
+
+ QByteDataBuffer tmp;
+ tmp.append(std::move(buf));
+ QCOMPARE(tmp.readAll(), "ello world");
+}
+
static QByteArray makeByteArray(int size)
{
QByteArray array;
@@ -157,5 +146,59 @@ void tst_QByteDataBuffer::readPartialBuffer()
readBuffer(size, QIODEVICE_BUFFERSIZE);
}
+void tst_QByteDataBuffer::readPointer()
+{
+ QByteDataBuffer buffer;
+
+ auto view = buffer.readPointer();
+ QCOMPARE(view.size(), 0);
+ QCOMPARE(view, "");
+
+ buffer.append("Hello");
+ buffer.append("World");
+
+ qint64 initialSize = buffer.byteAmount();
+ view = buffer.readPointer();
+
+ QCOMPARE(initialSize, buffer.byteAmount());
+ QCOMPARE(view.size(), 5);
+ QCOMPARE(view, "Hello");
+
+ buffer.advanceReadPointer(2);
+ view = buffer.readPointer();
+
+ QCOMPARE(initialSize - 2, buffer.byteAmount());
+ QCOMPARE(view.size(), 3);
+ QCOMPARE(view, "llo");
+
+ buffer.advanceReadPointer(3);
+ view = buffer.readPointer();
+
+ QCOMPARE(initialSize - 5, buffer.byteAmount());
+ QCOMPARE(view.size(), 5);
+ QCOMPARE(view, "World");
+
+ buffer.advanceReadPointer(5);
+ view = buffer.readPointer();
+
+ QVERIFY(buffer.isEmpty());
+ QCOMPARE(view.size(), 0);
+ QCOMPARE(view, "");
+
+ // Advance past the current view's size
+ buffer.append("Hello");
+ buffer.append("World");
+
+ buffer.advanceReadPointer(6);
+ view = buffer.readPointer();
+ QCOMPARE(view, "orld");
+ QCOMPARE(buffer.byteAmount(), 4);
+
+ // Advance past the end of all contained data
+ buffer.advanceReadPointer(6);
+ view = buffer.readPointer();
+ QCOMPARE(view, "");
+}
+
QTEST_MAIN(tst_QByteDataBuffer)
#include "tst_qbytedatabuffer.moc"