tst_QByteArray: check replace() doesn't replace the terminating \0
It doesn't. Pick-to: 6.5 5.15 Change-Id: Ica3fb2b8a65d0f9d14490ecdcce72eba82258916 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit fff69288781bf946ad645fd781ad51ab48ebcbdc) (cherry picked from commit 8e2c6a590429892d9fecf9a0ccc7c6a00d6c7b6d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>bb10
parent
e393bf24d9
commit
40b45176b9
|
|
@ -76,6 +76,7 @@ private slots:
|
|||
void replaceWithSpecifiedLength();
|
||||
void replaceWithEmptyNeedleInsertsBeforeEachChar_data();
|
||||
void replaceWithEmptyNeedleInsertsBeforeEachChar();
|
||||
void replaceDoesNotReplaceTheTerminatingNull();
|
||||
|
||||
void number();
|
||||
void number_double_data();
|
||||
|
|
@ -1601,6 +1602,23 @@ void tst_QByteArray::replaceWithEmptyNeedleInsertsBeforeEachChar()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QByteArray::replaceDoesNotReplaceTheTerminatingNull()
|
||||
{
|
||||
// Try really hard to replace the implicit terminating '\0' byte:
|
||||
constexpr char content[] = "Hello, World!";
|
||||
#define CHECK(...) do { \
|
||||
QByteArray ba(content); \
|
||||
QCOMPARE(std::as_const(ba).data()[ba.size()], '\0'); \
|
||||
ba.replace(__VA_ARGS__); \
|
||||
QCOMPARE(ba, content); \
|
||||
QCOMPARE(std::as_const(ba).data()[ba.size()], '\0'); \
|
||||
} while (false)
|
||||
CHECK('\0', 'a');
|
||||
CHECK(QByteArrayView{"!", 2}, // including \0, matches end of `ba`
|
||||
QByteArrayView{"!!"});
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
void tst_QByteArray::number()
|
||||
{
|
||||
QCOMPARE(QByteArray::number(quint64(0)), QByteArray("0"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue