summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2022-11-20 14:49:04 +0200
committerAhmad Samir <a.samirh78@gmail.com>2023-01-30 23:52:42 +0200
commit26f8ea1224e43bef9ba3f121c6d5d8e19a8756fc (patch)
treefdddf4deaf7e51bd0825118bd2a9bdc1389ac104 /tests
parent482a75fef9643220366029862dbf636a88bccb82 (diff)
QString: don't detach in replace(QChar, QChar, case)
If the string is shared, instead of detaching, create a new string and copy the characters from this string, replacing the ones matching "before" with "after", to the new string. Change-Id: I2c33690230d40f3121e60e242666460559258b7b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 2e733fc49b..2ea3e2e6e9 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -764,7 +764,14 @@ void tst_QString::replace_qchar_qchar()
QFETCH(Qt::CaseSensitivity, cs);
QFETCH(QString, expected);
- QCOMPARE(src.replace(before, after, cs), expected);
+ QString str = src;
+ // Test when string is shared
+ QCOMPARE(str.replace(before, after, cs), expected);
+
+ str = src;
+ // Test when it's not shared
+ str.detach();
+ QCOMPARE(str.replace(before, after, cs), expected);
}
void tst_QString::replace_qchar_qstring_data()