summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstring/tst_qstring.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-06-03 09:03:14 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-06-03 09:28:19 (GMT)
commitcd003bfcf9a05967893099e8948ba3d8f281aa7d (patch)
treec9e5afc64bf1d33bbf6121f64c03ba20fc2ecdf8 /tests/auto/qstring/tst_qstring.cpp
parent9ecba4c0c963272bbbac627a6742153b5f6f361f (diff)
downloadQt-cd003bfcf9a05967893099e8948ba3d8f281aa7d.zip
Qt-cd003bfcf9a05967893099e8948ba3d8f281aa7d.tar.gz
Qt-cd003bfcf9a05967893099e8948ba3d8f281aa7d.tar.bz2
QString: Fix severals bugs when comparing with QStringRef
the internal ucstricmp and ucstrcmp contains different bugs if the strings are not 0-terminated, as it is with QStringRef. - in ucstricmp, even if the pointer are the same, the lenght could be different - we used to deference the 'end' pointer, that would be 0 if the string ends with 0, but we cannot do that in the general case Task-number: QTBUG-10404 Reviewed-by: Denis
Diffstat (limited to 'tests/auto/qstring/tst_qstring.cpp')
-rw-r--r--tests/auto/qstring/tst_qstring.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index 1bea4b7..c887936 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -207,6 +207,7 @@ private slots:
void repeated() const;
void repeated_data() const;
void task262677remove();
+ void QTBUG10404_compareRef();
};
typedef QList<int> IntList;
@@ -4828,6 +4829,38 @@ void tst_QString::task262677remove()
QVERIFY(driveName == QLatin1String("V:"));
}
+void tst_QString::QTBUG10404_compareRef()
+{
+ QString a = "ABCDEFGH";
+
+ QCOMPARE(QStringRef(&a, 1, 2).compare(QLatin1String("BC")), 0);
+ QVERIFY(QStringRef(&a, 1, 2).compare(QLatin1String("BCD")) < 0);
+ QCOMPARE(QStringRef(&a, 1, 2).compare(QLatin1String("Bc"), Qt::CaseInsensitive), 0);
+ QVERIFY(QStringRef(&a, 1, 2).compare(QLatin1String("bCD"), Qt::CaseInsensitive) < 0);
+
+ QCOMPARE(QStringRef(&a, 1, 2).compare(QString::fromLatin1("BC")), 0);
+ QVERIFY(QStringRef(&a, 1, 2).compare(QString::fromLatin1("BCD")) < 0);
+ QCOMPARE(QStringRef(&a, 1, 2).compare(QString::fromLatin1("Bc"), Qt::CaseInsensitive), 0);
+ QVERIFY(QStringRef(&a, 1, 2).compare(QString::fromLatin1("bCD"), Qt::CaseInsensitive) < 0);
+
+ QCOMPARE(QString::fromLatin1("BC").compare(QStringRef(&a, 1, 2)), 0);
+ QVERIFY(QString::fromLatin1("BCD").compare(QStringRef(&a, 1, 2)) > 0);
+ QCOMPARE(QString::fromLatin1("Bc").compare(QStringRef(&a, 1, 2), Qt::CaseInsensitive), 0);
+ QVERIFY(QString::fromLatin1("bCD").compare(QStringRef(&a, 1, 2), Qt::CaseInsensitive) > 0);
+
+ QCOMPARE(QStringRef(&a, 1, 2).compare(QStringRef(&a, 1, 2)), 0);
+ QVERIFY(QStringRef(&a, 1, 2).compare(QStringRef(&a, 1, 3)) < 0);
+ QCOMPARE(QStringRef(&a, 1, 2).compare(QStringRef(&a, 1, 2), Qt::CaseInsensitive), 0);
+ QVERIFY(QStringRef(&a, 1, 2).compare(QStringRef(&a, 1, 3), Qt::CaseInsensitive) < 0);
+
+ QString a2 = "ABCDEFGh";
+ QCOMPARE(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 2)), 0);
+ QVERIFY(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 3)) < 0);
+ QCOMPARE(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 2), Qt::CaseInsensitive), 0);
+ QVERIFY(QStringRef(&a2, 1, 2).compare(QStringRef(&a, 1, 3), Qt::CaseInsensitive) < 0);
+}
+
+
QTEST_APPLESS_MAIN(tst_QString)