From adb41bbe00b2b853d4dd26cd9ee77ae5ed541576 Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Sun, 25 Apr 2021 22:47:39 +0200 Subject: 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 Pick-to: dev 6.0 6.1 Change-Id: I50e742bdf10ea9de2de66539a7dbb9abc4352f82 Reviewed-by: Lars Knoll --- tests/auto/corelib/text/qstring/tst_qstring.cpp | 73 +++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'tests/auto/corelib/text/qstring/tst_qstring.cpp') diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 79c4fa4ab0..c962496980 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -2419,6 +2419,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) @@ -2478,6 +2508,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() -- cgit v1.2.3