summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-11-29 11:24:49 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-11-29 20:04:38 +0000
commit8568a6386c1691e296e288021d7fd6316695cfbb (patch)
tree067d7a50c8c49c8a3250c11c4bf467dd19661aa3 /tests
parentccaeffe5655cba23b4f708ec575e34f03cf08a1c (diff)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
index 6d844c1844..9ded894472 100644
--- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
@@ -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");