diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2020-11-09 15:49:28 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2020-11-11 01:00:39 +0100 |
commit | bbadd1b5c1c7000bf4004ba34b3194864e688982 (patch) | |
tree | 20f2721193818611de99dbd31c453a69cd039b3b /tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp | |
parent | 059ca16aa0d3e8b89702df3e95bb32d7071bd957 (diff) |
Add QByteArray::insert(qsizetype, const QByteArray &)
For consistency with append and prepend we should have an overload for
insert() as well. This also enables insert() to be used with
QStringBuilder, i.e. qba.insert(2, qba2 + "abc").
Because simply adding a const QByteArray & overload causes ambiguity
with QByteArrayView we also add a const char * overload.
Add some extra test-cases. Two for QByteArrayView since it's not
directly tested anymore. One for inserting self directly.
Change-Id: Ieb43a6a7d1afbb498bc89c690908d7f0faa94687
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp')
-rw-r--r-- | tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index cf70a7bbaa..7f9bff844f 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -946,6 +946,18 @@ void tst_QByteArray::insert() ba = "ab"; QCOMPARE(ba.insert(1, "\0X\0", 3), QByteArray::fromRawData("a\0X\0b", 5)); QCOMPARE(ba.size(), 5); + + ba = "Hello World"; + QCOMPARE(ba.insert(5, QByteArrayView(",")), QByteArray("Hello, World")); + QCOMPARE(ba.size(), 12); + + ba = "one"; + QCOMPARE(ba.insert(1, ba), QByteArray("oonene")); + QCOMPARE(ba.size(), 6); + + ba = "one"; + QCOMPARE(ba.insert(1, QByteArrayView(ba)), QByteArray("oonene")); + QCOMPARE(ba.size(), 6); } void tst_QByteArray::insertExtended_data() |