tst_QByteArray: check replace() doesn't replace the terminating \0
It doesn't. Pick-to: 6.8 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)
This commit is contained in:
parent
c653cf1171
commit
8e2c6a5904
@ -78,6 +78,7 @@ private slots:
|
|||||||
void replaceWithSpecifiedLength();
|
void replaceWithSpecifiedLength();
|
||||||
void replaceWithEmptyNeedleInsertsBeforeEachChar_data();
|
void replaceWithEmptyNeedleInsertsBeforeEachChar_data();
|
||||||
void replaceWithEmptyNeedleInsertsBeforeEachChar();
|
void replaceWithEmptyNeedleInsertsBeforeEachChar();
|
||||||
|
void replaceDoesNotReplaceTheTerminatingNull();
|
||||||
|
|
||||||
void number();
|
void number();
|
||||||
void number_double_data();
|
void number_double_data();
|
||||||
@ -1608,6 +1609,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()
|
void tst_QByteArray::number()
|
||||||
{
|
{
|
||||||
QCOMPARE(QByteArray::number(quint64(0)), QByteArray("0"));
|
QCOMPARE(QByteArray::number(quint64(0)), QByteArray("0"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user