diff options
Diffstat (limited to 'tests/auto/corelib/text')
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 69166ea4f6..24aa53a024 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -6832,15 +6832,16 @@ void tst_QString::compare_data() QTest::newRow("data8") << upper << lower << -1 << 0; // embedded nulls - // These don't work as of now. It's OK that these don't work since \0 is not a valid unicode - /*QTest::newRow("data10") << QString(QByteArray("\0", 1)) << QString(QByteArray("\0", 1)) << 0 << 0; - QTest::newRow("data11") << QString(QByteArray("\0", 1)) << QString("") << 1 << 1; - QTest::newRow("data12") << QString("") << QString(QByteArray("\0", 1)) << -1 << -1; - QTest::newRow("data13") << QString("ab\0c") << QString(QByteArray("ab\0c", 4)) << 0 << 0; + QByteArray onenull("", 1); + QTest::newRow("data10") << QString(onenull) << QString(onenull) << 0 << 0; + QTest::newRow("data11") << QString(onenull) << QString("") << 1 << 1; + QTest::newRow("data12") << QString("") << QString(onenull) << -1 << -1; + QTest::newRow("data13") << QString::fromLatin1("ab\0c", 4) << QString(QByteArray("ab\0c", 4)) << 0 << 0; QTest::newRow("data14") << QString(QByteArray("ab\0c", 4)) << QString("abc") << -1 << -1; - QTest::newRow("data15") << QString("abc") << QString(QByteArray("ab\0c", 4)) << 1 << 1;*/ + QTest::newRow("data15") << QString("abc") << QString(QByteArray("ab\0c", 4)) << 1 << 1; + QTest::newRow("data16") << QString("abc") << QString(QByteArray("abc", 4)) << -1 << -1; - // All tests below (generated by the 3 for-loops) are meant to excercise the vectorized versions + // All tests below (generated by the 3 for-loops) are meant to exercise the vectorized versions // of ucstrncmp. QString in1, in2; @@ -6913,6 +6914,10 @@ void tst_QString::compare() QByteArray s1_8 = s1.toUtf8(); QByteArray s2_8 = s2.toUtf8(); + QByteArray s1_1 = s1.toLatin1(); + QByteArray s2_1 = s2.toLatin1(); + QLatin1String l1s1(s1_1); + QLatin1String l1s2(s2_1); const QStringView v1(s1); const QStringView v2(s2); @@ -6933,16 +6938,24 @@ void tst_QString::compare() QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseSensitive)), csr); QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseInsensitive)), cir); - if (csr == 0) + if (csr == 0) { QVERIFY(qHash(s1) == qHash(s2)); + QVERIFY(s1 == s2); + QVERIFY(!(s1 != s2)); + } else { + QVERIFY(s1 != s2); + QVERIFY(!(s1 == s2)); + } if (!cir) QCOMPARE(s1.toCaseFolded(), s2.toCaseFolded()); if (isLatin(s2)) { QVERIFY(QtPrivate::isLatin1(s2)); - QCOMPARE(sign(QString::compare(s1, QLatin1String(s2.toLatin1()))), csr); - QCOMPARE(sign(QString::compare(s1, QLatin1String(s2.toLatin1()), Qt::CaseInsensitive)), cir); + QCOMPARE(sign(QString::compare(s1, l1s2)), csr); + QCOMPARE(sign(QString::compare(s1, l1s2, Qt::CaseInsensitive)), cir); + + // ensure it doesn't compare past the explicit size QByteArray l1 = s2.toLatin1(); l1 += "x"; QLatin1String l1str(l1.constData(), l1.size() - 1); @@ -6952,8 +6965,16 @@ void tst_QString::compare() if (isLatin(s1)) { QVERIFY(QtPrivate::isLatin1(s1)); - QCOMPARE(sign(QString::compare(QLatin1String(s1.toLatin1()), s2)), csr); - QCOMPARE(sign(QString::compare(QLatin1String(s1.toLatin1()), s2, Qt::CaseInsensitive)), cir); + QCOMPARE(sign(QString::compare(l1s1, s2)), csr); + QCOMPARE(sign(QString::compare(l1s1, s2, Qt::CaseInsensitive)), cir); + } + + if (isLatin(s1) && isLatin(s2)) { + QCOMPARE(sign(QtPrivate::compareStrings(l1s1, l1s2)), csr); + QCOMPARE(sign(QtPrivate::compareStrings(l1s1, l1s2, Qt::CaseInsensitive)), cir); + QCOMPARE(l1s1 == l1s2, csr == 0); + QCOMPARE(l1s1 < l1s2, csr < 0); + QCOMPARE(l1s1 > l1s2, csr > 0); } } |