summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstring
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-04-25 22:47:39 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2021-04-27 14:12:34 +0200
commite6f7202e34f407a316d1c96a6b3a55f24dd068d8 (patch)
tree7c23d074530f22482caa1b7c3ddd2563f220179d /tests/auto/corelib/text/qstring
parentdbb001eb1b3c8208ecaf2cf6ff34a859222a1b53 (diff)
Add more tests for QList/QString/QBA
The major part is stability tests for QList operations, Also added std::shared_ptr to the Custom type. shared_ptr accesses the memory which does not directly belong to QList, so using it inside a passed-to-qlist type is beneficial (e.g. ASan could catch extra issues) Basic prepend-aware cases added to QString/QBA tests Task-number: QTBUG-93019 Change-Id: I50e742bdf10ea9de2de66539a7dbb9abc4352f82 Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit adb41bbe00b2b853d4dd26cd9ee77ae5ed541576) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qstring')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 57885f596d..963ab2aa1a 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -2418,6 +2418,36 @@ void tst_QString::insert_special_cases()
QCOMPARE(a.insert(1, QLatin1String("BCD")), QString("ABCDEF"));
QCOMPARE(a.insert(3, QLatin1String("-")), QString("ABC-DEF"));
QCOMPARE(a.insert(a.size() + 1, QLatin1String("XYZ")), QString("ABC-DEF XYZ"));
+
+ {
+ a = "one";
+ a.prepend(u'a');
+ QString b(a.data_ptr()->freeSpaceAtEnd(), u'b');
+ QCOMPARE(a.insert(a.size() + 1, QLatin1String(b.toLatin1())), QString("aone ") + b);
+ }
+
+ {
+ a = "onetwothree";
+ while (a.size() - 1)
+ a.remove(0, 1);
+ QString b(a.data_ptr()->freeSpaceAtEnd() + 1, u'b');
+ QCOMPARE(a.insert(a.size() + 1, QLatin1String(b.toLatin1())), QString("e ") + b);
+ }
+
+ {
+ a = "one";
+ a.prepend(u'a');
+ QString b(a.data_ptr()->freeSpaceAtEnd(), u'b');
+ QCOMPARE(a.insert(a.size() + 1, b), QString("aone ") + b);
+ }
+
+ {
+ a = "onetwothree";
+ while (a.size() - 1)
+ a.remove(0, 1);
+ QString b(a.data_ptr()->freeSpaceAtEnd() + 1, u'b');
+ QCOMPARE(a.insert(a.size() + 1, b), QString("e ") + b);
+ }
}
void tst_QString::append_data(bool emptyIsNoop)
@@ -2477,6 +2507,49 @@ void tst_QString::append_special_cases()
a.append(QLatin1String("BC"));
QCOMPARE(a, QLatin1String("ABC"));
}
+
+ {
+ QString a = "one";
+ a.prepend(u'a');
+ QString b(a.data_ptr()->freeSpaceAtEnd(), u'b');
+ QCOMPARE(a.append(QLatin1String(b.toLatin1())), QString("aone") + b);
+ }
+
+ {
+ QString a = "onetwothree";
+ while (a.size() - 1)
+ a.remove(0, 1);
+ QString b(a.data_ptr()->freeSpaceAtEnd(), u'b');
+ QCOMPARE(a.append(QLatin1String(b.toLatin1())), QString("e") + b);
+ }
+
+ {
+ QString a = "one";
+ a.prepend(u'a');
+ QString b(a.data_ptr()->freeSpaceAtEnd(), u'b');
+ QCOMPARE(a.append(b), QString("aone") + b);
+ }
+
+ {
+ QString a = "onetwothree";
+ while (a.size() - 1)
+ a.remove(0, 1);
+ QString b(a.data_ptr()->freeSpaceAtEnd() + 1, u'b');
+ QCOMPARE(a.append(b), QString("e") + b);
+ }
+
+ {
+ QString a = "one";
+ a.prepend(u'a');
+ QCOMPARE(a.append(u'b'), QString("aoneb"));
+ }
+
+ {
+ QString a = "onetwothree";
+ while (a.size() - 1)
+ a.remove(0, 1);
+ QCOMPARE(a.append(u'b'), QString("eb"));
+ }
}
void tst_QString::append_bytearray_special_cases_data()