Check that QStringView::split() w/rvalue QRegularExpression returns valid data

This test currently passes in Qt 6, but fails in Qt 5.15, thus the
QT_VERSION check.

Pick-to: 6.2 5.15
Task-number: QTBUG-98653
Change-Id: I3c7b9bc7ef74f605ff63768b38c473296274d0de
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Marc Mutz 2021-11-29 11:24:49 +01:00
parent ccaeffe565
commit 8568a6386c
1 changed files with 29 additions and 0 deletions

View File

@ -89,6 +89,7 @@ private slots:
void threadSafety_data();
void threadSafety();
void returnsViewsIntoOriginalString();
void wildcard_data();
void wildcard();
void testInvalidWildcard_data();
@ -2432,6 +2433,34 @@ void tst_QRegularExpression::threadSafety()
}
}
void tst_QRegularExpression::returnsViewsIntoOriginalString()
{
// https://bugreports.qt.io/browse/QTBUG-98653
auto to_void = [](const auto *p) -> const void* { return p; };
// GIVEN
// a QString with dynamically-allocated data:
const QString string = QLatin1String("A\nA\nB\nB\n\nC\nC"); // NOT QStringLiteral!
const auto stringDataAddress = to_void(string.data());
// and a view over said QString:
QStringView view(string);
const auto viewDataAddress = to_void(view.data());
QCOMPARE(stringDataAddress, viewDataAddress);
// WHEN
// we call view.split() with a temporary QRegularExpression object
const auto split = view.split(QRegularExpression( "(\r\n|\n|\r)" ), Qt::KeepEmptyParts);
// THEN
// the returned views should point into the underlying string:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QEXPECT_FAIL("", "QTBUG-98653", Continue);
#endif
QCOMPARE(to_void(split.front().data()), stringDataAddress);
}
void tst_QRegularExpression::wildcard_data()
{
QTest::addColumn<QString>("pattern");