diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-04-25 22:47:39 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2021-04-26 17:07:49 +0200 |
commit | adb41bbe00b2b853d4dd26cd9ee77ae5ed541576 (patch) | |
tree | 0883b7a07b725533e904046dcda2148c74823875 /tests/auto/corelib/text/qstring | |
parent | 5e76c2acff2c70f2893306b16aeba230f3d6114a (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
Pick-to: dev 6.0 6.1
Change-Id: I50e742bdf10ea9de2de66539a7dbb9abc4352f82
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qstring')
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 73 |
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 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() |