diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2022-10-24 23:58:14 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2022-11-03 14:22:51 +0200 |
commit | f41089ba3da174279d168a4649dad52e8d90cd90 (patch) | |
tree | 720421ad73ff0fe33440ec7bbd32fb412330ab38 /tests | |
parent | dcfab7e28ee9bbdf09138a321e1f8db2b770d4b7 (diff) |
QString: don't detach in remove(pos, len)
- If this string isn't shared, don't call detach, instead use ->erase() as
needed
- If this string is shared, create a new string, and copy all elements
except the ones that would be removed, see task for details
Update unittest to test both code paths.
Task-number: QTBUG-106181
Change-Id: I4c73ff17a6fa89ddcf6966f9c5bf789753f6d39e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 80bc6c9208..0462d0689d 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -3318,13 +3318,23 @@ void tst_QString::remove_uint_uint() QFETCH( int, index ); QFETCH( int, len ); QFETCH( QString, after ); + QFETCH(QString, result); - if ( after.size() == 0 ) { - QString s1 = string; - s1.remove( (uint) index, (uint) len ); - QTEST( s1, "result" ); - } else - QCOMPARE( 0, 0 ); // shut Qt Test + // For the replace() unitests? + if ( after.size() != 0 ) { + return; + } + + // Test when isShared() is true + QString s1 = string; + s1.remove((qsizetype)index, (qsizetype)len); + QCOMPARE(s1, result); + + QString s2 = string; + // Test when isShared() is false + s2.detach(); + s2.remove((qsizetype)index, (qsizetype)len); + QCOMPARE(s2, result); } void tst_QString::remove_string() |