diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2016-07-19 19:51:41 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2016-07-19 20:14:40 +0200 |
commit | 782ebeada125e3d8a293c7806e34cc737c30ddda (patch) | |
tree | 5516ad24a7532d650289758abd5e92a35bc2240e /tests/auto/corelib | |
parent | 091df96fb8da356dc9de81dc390f55e66d4d7c01 (diff) | |
parent | 62cbb434579a56871f0917bc306d592055381c00 (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
qmake/library/qmakebuiltins.cpp
qmake/library/qmakeevaluator.cpp
qmake/library/qmakeevaluator.h
qmake/project.h
QMakeEvaluator:
* evaluateConditional(): one side changed return type, the other
changed a parameter type.
* split_value_list(): one side changed a parameter adjacent to where ...
* expandVariableReferences(): ... the other killed one overload and
changed the survivor
src/corelib/io/qlockfile_unix.cpp
One side changed a #if condition, the other moved NETBSD's part of
what it controlled.
src/corelib/tools/qdatetime.cpp
One side fixed a reachable Q_UNREACHABLE in toMSecsSinceEpoch(), the
other moved it from the private class to the public one, in the midst
of the "short date-time" optimization, which confused diff entirely.
One side changed a QStringLiteral to QLatin1String, the other rewrote
adjoining code.
src/network/kernel/qauthenticator.cpp
Both rewrote a line, equivalently; kept the dev version.
src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h
One side changed #if-ery that the other removed.
tools/configure/configureapp.cpp
One side added a check to -target parsing; the other killed -target.
tests/auto/testlib/selftests/expected_cmptest.lightxml
tests/auto/testlib/selftests/expected_cmptest.teamcity
tests/auto/testlib/selftests/expected_cmptest.txt
tests/auto/testlib/selftests/expected_cmptest.xml
tests/auto/testlib/selftests/expected_cmptest.xunitxml
Regenerated using generate_expected_output.py
I note that quite a few other expected_* come out changed, now.
There was no git-conflict in
src/widgets/kernel/qformlayout.cpp
but it didn't compile; one side removed some unused methods; the other
found uses for one of them. Put FixedColumnMatrix<>::removeRow(int)
back for its new user.
Change-Id: I8cc2a71add48c0a848e13cfc47b5a7754e8ca584
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp | 77 | ||||
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 162 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp | 16 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qpair/tst_qpair.cpp | 30 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp | 8 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 69 |
6 files changed, 285 insertions, 77 deletions
diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index 4a5aead17a..de6884d454 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -1197,10 +1197,11 @@ static QTime qTimeData(int index) case 57: return QTime(23, 59, 59, 99); case 58: return QTime(23, 59, 59, 100); case 59: return QTime(23, 59, 59, 999); + case 60: return QTime(); } return QTime(0, 0, 0); } -#define MAX_QTIME_DATA 60 +#define MAX_QTIME_DATA 61 void tst_QDataStream::stream_QTime_data() { @@ -2786,10 +2787,11 @@ void tst_QDataStream::status_QHash_QMap() MAP_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, StringHash()); } -#define LIST_TEST(byteArray, expectedStatus, expectedList) \ +#define LIST_TEST(byteArray, initialStatus, expectedStatus, expectedList) \ { \ QByteArray ba = byteArray; \ QDataStream stream(&ba, QIODevice::ReadOnly); \ + stream.setStatus(initialStatus); \ stream >> list; \ QCOMPARE((int)stream.status(), (int)expectedStatus); \ QCOMPARE(list.size(), expectedList.size()); \ @@ -2801,6 +2803,7 @@ void tst_QDataStream::status_QHash_QMap() expectedLinkedList << expectedList.at(i); \ QByteArray ba = byteArray; \ QDataStream stream(&ba, QIODevice::ReadOnly); \ + stream.setStatus(initialStatus); \ stream >> linkedList; \ QCOMPARE((int)stream.status(), (int)expectedStatus); \ QCOMPARE(linkedList.size(), expectedLinkedList.size()); \ @@ -2812,6 +2815,7 @@ void tst_QDataStream::status_QHash_QMap() expectedVector << expectedList.at(i); \ QByteArray ba = byteArray; \ QDataStream stream(&ba, QIODevice::ReadOnly); \ + stream.setStatus(initialStatus); \ stream >> vector; \ QCOMPARE((int)stream.status(), (int)expectedStatus); \ QCOMPARE(vector.size(), expectedVector.size()); \ @@ -2827,8 +2831,49 @@ void tst_QDataStream::status_QLinkedList_QList_QVector() List list; Vector vector; - LIST_TEST(QByteArray(), QDataStream::ReadPastEnd, List()); - LIST_TEST(QByteArray("\x00\x00\x00\x00", 4), QDataStream::Ok, List()); + // ok + { + List listWithEmptyString; + listWithEmptyString.append(""); + + List someList; + someList.append("J"); + someList.append("MN"); + + LIST_TEST(QByteArray("\x00\x00\x00\x00", 4), QDataStream::Ok, QDataStream::Ok, List()); + LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00", 8), QDataStream::Ok, QDataStream::Ok, listWithEmptyString); + LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x02\x00J" + "\x00\x00\x00\x04\x00M\x00N", 18), QDataStream::Ok, QDataStream::Ok, someList); + } + + // past end + { + LIST_TEST(QByteArray(), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LIST_TEST(QByteArray("\x00", 1), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LIST_TEST(QByteArray("\x00\x00", 2), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LIST_TEST(QByteArray("\x00\x00\x00", 3), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LIST_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + for (int i = 4; i < 12; ++i) { + LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", i), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + } + } + + // corrupt data + { + LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::Ok, QDataStream::ReadCorruptData, List()); + LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x01\x00J" + "\x00\x00\x00\x02\x00M\x00N", 18), QDataStream::Ok, QDataStream::ReadCorruptData, List()); + } + + // test the previously latched error status is not affected by reading + { + List listWithEmptyString; + listWithEmptyString.append(""); + + LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, listWithEmptyString); + LIST_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::ReadCorruptData, QDataStream::ReadCorruptData, List()); + LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, List()); + } } void tst_QDataStream::streamToAndFromQByteArray() @@ -3061,6 +3106,30 @@ void tst_QDataStream::compatibility_Qt3() QCOMPARE(in_palette.brush(QPalette::Button).style(), Qt::NoBrush); QCOMPARE(in_palette.color(QPalette::Light), QColor(Qt::green)); } + // QTime() was serialized to (0, 0, 0, 0) in Qt3, not (0xFF, 0xFF, 0xFF, 0xFF) + // This is because in Qt3 a null time was valid, and there was no support for deserializing a value of -1. + { + QByteArray stream; + { + QDataStream out(&stream, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_3_3); + out << QTime(); + } + QTime in_time; + { + QDataStream in(stream); + in.setVersion(QDataStream::Qt_3_3); + in >> in_time; + } + QVERIFY(in_time.isNull()); + + quint32 rawValue; + QDataStream in(stream); + in.setVersion(QDataStream::Qt_3_3); + in >> rawValue; + QCOMPARE(rawValue, quint32(0)); + } + } void tst_QDataStream::compatibility_Qt2() diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 73672f3572..e982660bef 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -120,7 +120,8 @@ private slots: void isValid(); void schemeValidator_data(); void schemeValidator(); - void invalidSchemeValidator(); + void setScheme_data(); + void setScheme(); void strictParser_data(); void strictParser(); void tolerantParser(); @@ -2077,87 +2078,114 @@ void tst_QUrl::isValid() void tst_QUrl::schemeValidator_data() { - QTest::addColumn<QByteArray>("encodedUrl"); + QTest::addColumn<QString>("input"); QTest::addColumn<bool>("result"); - QTest::addColumn<QString>("toString"); - - QTest::newRow("empty") << QByteArray() << false << QString(); - - // ftp - QTest::newRow("ftp:") << QByteArray("ftp:") << true << QString("ftp:"); - QTest::newRow("ftp://ftp.qt-project.org") - << QByteArray("ftp://ftp.qt-project.org") - << true << QString("ftp://ftp.qt-project.org"); - QTest::newRow("ftp://ftp.qt-project.org/") - << QByteArray("ftp://ftp.qt-project.org/") - << true << QString("ftp://ftp.qt-project.org/"); - QTest::newRow("ftp:/index.html") - << QByteArray("ftp:/index.html") - << false << QString(); - - // mailto - QTest::newRow("mailto:") << QByteArray("mailto:") << true << QString("mailto:"); - QTest::newRow("mailto://smtp.trolltech.com/ole@bull.name") - << QByteArray("mailto://smtp.trolltech.com/ole@bull.name") << false << QString(); - QTest::newRow("mailto:") << QByteArray("mailto:") << true << QString("mailto:"); - QTest::newRow("mailto:ole@bull.name") - << QByteArray("mailto:ole@bull.name") << true << QString("mailto:ole@bull.name"); + QTest::addColumn<QString>("scheme"); - // file - QTest::newRow("file:") << QByteArray("file:/etc/passwd") << true << QString("file:///etc/passwd"); + // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) + + QTest::newRow("empty") << QString() << false << QString(); + + // uncontroversial ones + QTest::newRow("ftp") << "ftp://ftp.example.com/" << true << "ftp"; + QTest::newRow("http") << "http://www.example.com/" << true << "http"; + QTest::newRow("mailto") << "mailto:smith@example.com" << true << "mailto"; + QTest::newRow("file-1slash") << "file:/etc/passwd" << true << "file"; + QTest::newRow("file-2slashes") << "file://server/etc/passwd" << true << "file"; + QTest::newRow("file-3slashes") << "file:///etc/passwd" << true << "file"; + + QTest::newRow("mailto+subject") << "mailto:smith@example.com?subject=Hello%20World" << true << "mailto"; + QTest::newRow("mailto+host") << "mailto://smtp.example.com/smith@example.com" << true << "mailto"; + + // valid, but unexpected + QTest::newRow("ftp-nohost") << "ftp:/etc/passwd" << true << "ftp"; + QTest::newRow("http-nohost") << "http:/etc/passwd" << true << "http"; + QTest::newRow("mailto-nomail") << "mailto://smtp.example.com" << true << "mailto"; + + // schemes with numbers + QTest::newRow("digits") << "proto2://" << true << "proto2"; + + // schemes with dots, dashes, and pluses + QTest::newRow("svn+ssh") << "svn+ssh://svn.example.com" << true << "svn+ssh"; + QTest::newRow("withdash") << "svn-ssh://svn.example.com" << true << "svn-ssh"; + QTest::newRow("withdots") << "org.qt-project://qt-project.org" << true << "org.qt-project"; + + // lowercasing + QTest::newRow("FTP") << "FTP://ftp.example.com/" << true << "ftp"; + QTest::newRow("HTTP") << "HTTP://www.example.com/" << true << "http"; + QTest::newRow("MAILTO") << "MAILTO:smith@example.com" << true << "mailto"; + QTest::newRow("FILE") << "FILE:/etc/passwd" << true << "file"; + QTest::newRow("SVN+SSH") << "SVN+SSH://svn.example.com" << true << "svn+ssh"; + QTest::newRow("WITHDASH") << "SVN-SSH://svn.example.com" << true << "svn-ssh"; + QTest::newRow("WITHDOTS") << "ORG.QT-PROJECT://qt-project.org" << true << "org.qt-project"; + + // invalid entries + QTest::newRow("start-digit") << "1http://example.com" << false << "1http"; + QTest::newRow("start-plus") << "+ssh://user@example.com" << false << "+ssh"; + QTest::newRow("start-dot") << ".org.example:///" << false << ".org.example"; + QTest::newRow("with-space") << "a b://" << false << "a b"; + QTest::newRow("with-non-ascii") << "\304\245\305\243\305\245\321\200://example.com" << false << "\304\245\305\243\305\245\321\200"; + QTest::newRow("with-control1") << "http\1://example.com" << false << "http\1"; + QTest::newRow("with-control127") << "http\177://example.com" << false << "http\177"; + QTest::newRow("with-null") << QString::fromLatin1("http\0://example.com", 19) << false << QString::fromLatin1("http\0", 5); + + QTest::newRow("percent-encoded") << "%68%74%%74%70://example.com" << false << "%68%74%%74%70"; + + static const char controls[] = "!\"$&'()*,;<=>[\\]^_`{|}~"; + for (size_t i = 0; i < sizeof(controls) - 1; ++i) + QTest::newRow(("with-" + QByteArray(1, controls[i])).constData()) + << QString("pre%1post://example.com/").arg(QLatin1Char(controls[i])) + << false << QString("pre%1post").arg(QLatin1Char(controls[i])); } void tst_QUrl::schemeValidator() { - QFETCH(QByteArray, encodedUrl); + QFETCH(QString, input); QFETCH(bool, result); - QFETCH(QString, toString); - QUrl url = QUrl::fromEncoded(encodedUrl); - QEXPECT_FAIL("ftp:/index.html", "high-level URL validation not reimplemented yet", Abort); - QEXPECT_FAIL("mailto://smtp.trolltech.com/ole@bull.name", "high-level URL validation not reimplemented yet", Abort); + QUrl url(input); QCOMPARE(url.isValid(), result); - if (!result) - QVERIFY(url.toString().isEmpty()); -} + if (result) { + QFETCH(QString, scheme); + QCOMPARE(url.scheme(), scheme); -void tst_QUrl::invalidSchemeValidator() -{ - // test that if scheme does not start with an ALPHA, QUrl::isValid() returns false - { - QUrl url("1http://qt-project.org"); - QVERIFY(url.scheme().isEmpty()); - QVERIFY(url.path().startsWith("1http")); - } - { - QUrl url("http://qt-project.org"); - url.setScheme("111http://qt-project.org"); - QCOMPARE(url.isValid(), false); - QVERIFY(url.toString().isEmpty()); - } - // non-ALPHA character at other positions in the scheme are ok - { - QUrl url("ht111tp://qt-project.org", QUrl::StrictMode); + // reconstruct with just the scheme: + url.setUrl(scheme + ':'); QVERIFY(url.isValid()); - QCOMPARE(url.scheme(), QString("ht111tp")); - QVERIFY(!url.toString().isEmpty()); - } - { - QUrl url("http://qt-project.org"); - url.setScheme("ht123tp://qt-project.org"); - QVERIFY(!url.isValid()); + QCOMPARE(url.scheme(), scheme); + } else { QVERIFY(url.toString().isEmpty()); - url.setScheme("http"); - QVERIFY(url.isValid()); - QVERIFY(!url.toString().isEmpty()); - } - { - QUrl url = QUrl::fromEncoded("ht321tp://qt-project.org", QUrl::StrictMode); - QVERIFY(url.isValid()); - QVERIFY(!url.toString().isEmpty()); } } +void tst_QUrl::setScheme_data() +{ + schemeValidator_data(); + + // a couple more which wouldn't work in parsing a full URL + QTest::newRow("with-slash") << QString() << false << "http/"; + QTest::newRow("with-question") << QString() << false << "http?"; + QTest::newRow("with-hash") << QString() << false << "http#"; +} + +void tst_QUrl::setScheme() +{ + QFETCH(QString, scheme); + QFETCH(bool, result); + QString expectedScheme; + if (result) + expectedScheme = scheme; + + QUrl url; + url.setScheme(scheme); + QCOMPARE(url.isValid(), result); + QCOMPARE(url.scheme(), expectedScheme); + + url.setScheme(scheme.toUpper()); + QCOMPARE(url.isValid(), result); + QCOMPARE(url.scheme(), expectedScheme); +} + void tst_QUrl::strictParser_data() { QTest::addColumn<QString>("input"); diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 7cdee891bb..1a70ac5e75 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -40,6 +40,8 @@ class tst_QHashFunctions : public QObject Q_OBJECT private Q_SLOTS: void qhash(); + void qhash_of_empty_and_null_qstring(); + void qhash_of_empty_and_null_qbytearray(); void fp_qhash_of_zero_is_zero(); void qthash_data(); void qthash(); @@ -128,6 +130,20 @@ void tst_QHashFunctions::qhash() } } +void tst_QHashFunctions::qhash_of_empty_and_null_qstring() +{ + QString null, empty(""); + QCOMPARE(null, empty); + QCOMPARE(qHash(null), qHash(empty)); +} + +void tst_QHashFunctions::qhash_of_empty_and_null_qbytearray() +{ + QByteArray null, empty(""); + QCOMPARE(null, empty); + QCOMPARE(qHash(null), qHash(empty)); +} + void tst_QHashFunctions::fp_qhash_of_zero_is_zero() { QCOMPARE(qHash(-0.0f), 0U); diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp index fb0986d05b..1d5f7536c8 100644 --- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp +++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp @@ -35,6 +35,7 @@ class tst_QPair : public QObject { Q_OBJECT private Q_SLOTS: + void pairOfReferences(); void testConstexpr(); void testConversions(); void taskQTBUG_48780_pairContainingCArray(); @@ -91,6 +92,35 @@ Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isDummy ); Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isPointer); +void tst_QPair::pairOfReferences() +{ + int i = 0; + QString s; + + QPair<int&, QString&> p(i, s); + + p.first = 1; + QCOMPARE(i, 1); + + i = 2; + QCOMPARE(p.first, 2); + + p.second = QLatin1String("Hello"); + QCOMPARE(s, QLatin1String("Hello")); + + s = QLatin1String("olleH"); + QCOMPARE(p.second, QLatin1String("olleH")); + + QPair<int&, QString&> q = p; + q.first = 3; + QCOMPARE(i, 3); + QCOMPARE(p.first, 3); + + q.second = QLatin1String("World"); + QCOMPARE(s, QLatin1String("World")); + QCOMPARE(p.second, QLatin1String("World")); +} + void tst_QPair::testConstexpr() { Q_CONSTEXPR QPair<int, double> pID = qMakePair(0, 0.0); diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp index 7bd732379d..c212589f59 100644 --- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp +++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp @@ -206,9 +206,9 @@ void tst_QRingBuffer::free() ringBuffer.append(QByteArray("01234", 5)); ringBuffer.free(1); - QCOMPARE(ringBuffer.size(), Q_INT64_C(4095 + 2048 + 5)); + QCOMPARE(ringBuffer.size(), Q_INT64_C(4095) + 2048 + 5); ringBuffer.free(4096); - QCOMPARE(ringBuffer.size(), Q_INT64_C(2047 + 5)); + QCOMPARE(ringBuffer.size(), Q_INT64_C(2047) + 5); ringBuffer.free(48); ringBuffer.free(2000); QCOMPARE(ringBuffer.size(), Q_INT64_C(4)); @@ -268,9 +268,9 @@ void tst_QRingBuffer::chop() ringBuffer.reserve(4096); ringBuffer.chop(1); - QCOMPARE(ringBuffer.size(), Q_INT64_C(5 + 2048 + 4095)); + QCOMPARE(ringBuffer.size(), Q_INT64_C(5) + 2048 + 4095); ringBuffer.chop(4096); - QCOMPARE(ringBuffer.size(), Q_INT64_C(5 + 2047)); + QCOMPARE(ringBuffer.size(), Q_INT64_C(5) + 2047); ringBuffer.chop(48); ringBuffer.chop(2000); QCOMPARE(ringBuffer.size(), Q_INT64_C(4)); diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 641ca0d25e..6df9ad7cdf 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -352,7 +352,7 @@ private slots: void replace_qchar_qstring(); void replace_uint_uint_data(); void replace_uint_uint(); - void replace_uint_uint_extra(); + void replace_extra(); void replace_string_data(); void replace_string(); void replace_regexp_data(); @@ -475,6 +475,8 @@ private slots: void sprintfS(); void fill(); void truncate(); + void chop_data(); + void chop(); void constructor(); void constructorQByteArray_data(); void constructorQByteArray(); @@ -1211,6 +1213,31 @@ void tst_QString::truncate() } +void tst_QString::chop_data() +{ + QTest::addColumn<QString>("input"); + QTest::addColumn<int>("count" ); + QTest::addColumn<QString>("result"); + + const QString original("abcd"); + + QTest::newRow("data0") << original << 1 << QString("abc"); + QTest::newRow("data1") << original << 0 << original; + QTest::newRow("data2") << original << -1 << original; + QTest::newRow("data3") << original << original.size() << QString(); + QTest::newRow("data4") << original << 1000 << QString(); +} + +void tst_QString::chop() +{ + QFETCH(QString, input); + QFETCH(int, count); + QFETCH(QString, result); + + input.chop(count); + QCOMPARE(input, result); +} + void tst_QString::fill() { QString e; @@ -2776,7 +2803,7 @@ void tst_QString::replace_uint_uint() } } -void tst_QString::replace_uint_uint_extra() +void tst_QString::replace_extra() { /* This test is designed to be extremely slow if QString::replace() doesn't optimize the case @@ -2813,6 +2840,44 @@ void tst_QString::replace_uint_uint_extra() QString str5("abcdefghij"); str5.replace(8, 10, str5); QCOMPARE(str5, QString("abcdefghabcdefghij")); + + // Replacements using only part of the string modified: + QString str6("abcdefghij"); + str6.replace(1, 8, str6.constData() + 3, 3); + QCOMPARE(str6, QString("adefj")); + + QString str7("abcdefghibcdefghij"); + str7.replace(str7.constData() + 1, 6, str7.constData() + 2, 3); + QCOMPARE(str7, QString("acdehicdehij")); + + const int many = 1024; + /* + QS::replace(const QChar *, int, const QChar *, int, Qt::CaseSensitivity) + does its replacements in batches of many (please keep in sync with any + changes to batch size), which lead to misbehaviour if ether QChar * array + was part of the data being modified. + */ + QString str8("abcdefg"), ans8("acdeg"); + { + // Make str8 and ans8 repeat themselves many + 1 times: + int i = many; + QString big(str8), small(ans8); + while (i && !(i & 1)) { // Exploit many being a power of 2: + big += big; + small += small; + i >>= 1; + } + while (i-- > 0) { + str8 += big; + ans8 += small; + } + } + str8.replace(str8.constData() + 1, 5, str8.constData() + 2, 3); + // Pre-test the bit where the diff happens, so it gets displayed: + QCOMPARE(str8.mid((many - 3) * 5), ans8.mid((many - 3) * 5)); + // Also check the full values match, of course: + QCOMPARE(str8.size(), ans8.size()); + QCOMPARE(str8, ans8); } void tst_QString::replace_string() |