summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-01-21 08:42:05 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-21 11:12:11 +0100
commit9eba69d7f914e4823e94699c5653df5ad279eb46 (patch)
tree343c45808fa78ac10e8c1011aea1cf12715cb057
parent909dbb92eb8ae607142e4316c01058090faaf1c7 (diff)
downloadqtbase-9eba69d7f914e4823e94699c5653df5ad279eb46.tar.gz
qtbase-9eba69d7f914e4823e94699c5653df5ad279eb46.tar.bz2
qtbase-9eba69d7f914e4823e94699c5653df5ad279eb46.zip
Fix a bug in some QString comparison operators
Some comparison operators comparing to const char * where not implemented correctly. Task-number: QTBUG-34024 Change-Id: Idbdc64c8ed93e88d9f2b2f55213bc785b33cb543 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
-rw-r--r--src/corelib/tools/qstring.h8
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp56
2 files changed, 60 insertions, 4 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 0a0a609728..9778d42c1d 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -1029,13 +1029,13 @@ inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QString &s2)
inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) != 0; }
inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QString &s2)
-{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) < 0; }
-inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) > 0; }
+inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QString &s2)
+{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) < 0; }
inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QString &s2)
-{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; }
-inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QString &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; }
+inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QString &s2)
+{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; }
inline QT_ASCII_CAST_WARN bool operator==(const char *s1, QLatin1String s2)
{ return QString::fromUtf8(s1) == s2; }
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 48874781c0..12fe5259d9 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -4419,6 +4419,62 @@ void tst_QString::operator_smaller()
// operator< is not locale-aware (or shouldn't be)
QVERIFY( foo < QString("\xc3\xa9") );
QVERIFY( foo < "\xc3\xa9" );
+
+ QVERIFY(QString("a") < QString("b"));
+ QVERIFY(QString("a") <= QString("b"));
+ QVERIFY(QString("a") <= QString("a"));
+ QVERIFY(QString("a") == QString("a"));
+ QVERIFY(QString("a") >= QString("a"));
+ QVERIFY(QString("b") >= QString("a"));
+ QVERIFY(QString("b") > QString("a"));
+
+ QVERIFY("a" < QString("b"));
+ QVERIFY("a" <= QString("b"));
+ QVERIFY("a" <= QString("a"));
+ QVERIFY("a" == QString("a"));
+ QVERIFY("a" >= QString("a"));
+ QVERIFY("b" >= QString("a"));
+ QVERIFY("b" > QString("a"));
+
+ QVERIFY(QString("a") < "b");
+ QVERIFY(QString("a") <= "b");
+ QVERIFY(QString("a") <= "a");
+ QVERIFY(QString("a") == "a");
+ QVERIFY(QString("a") >= "a");
+ QVERIFY(QString("b") >= "a");
+ QVERIFY(QString("b") > "a");
+
+ QVERIFY(QLatin1String("a") < QString("b"));
+ QVERIFY(QLatin1String("a") <= QString("b"));
+ QVERIFY(QLatin1String("a") <= QString("a"));
+ QVERIFY(QLatin1String("a") == QString("a"));
+ QVERIFY(QLatin1String("a") >= QString("a"));
+ QVERIFY(QLatin1String("b") >= QString("a"));
+ QVERIFY(QLatin1String("b") > QString("a"));
+
+ QVERIFY(QString("a") < QLatin1String("b"));
+ QVERIFY(QString("a") <= QLatin1String("b"));
+ QVERIFY(QString("a") <= QLatin1String("a"));
+ QVERIFY(QString("a") == QLatin1String("a"));
+ QVERIFY(QString("a") >= QLatin1String("a"));
+ QVERIFY(QString("b") >= QLatin1String("a"));
+ QVERIFY(QString("b") > QLatin1String("a"));
+
+ QVERIFY("a" < QLatin1String("b"));
+ QVERIFY("a" <= QLatin1String("b"));
+ QVERIFY("a" <= QLatin1String("a"));
+ QVERIFY("a" == QLatin1String("a"));
+ QVERIFY("a" >= QLatin1String("a"));
+ QVERIFY("b" >= QLatin1String("a"));
+ QVERIFY("b" > QLatin1String("a"));
+
+ QVERIFY(QLatin1String("a") < "b");
+ QVERIFY(QLatin1String("a") <= "b");
+ QVERIFY(QLatin1String("a") <= "a");
+ QVERIFY(QLatin1String("a") == "a");
+ QVERIFY(QLatin1String("a") >= "a");
+ QVERIFY(QLatin1String("b") >= "a");
+ QVERIFY(QLatin1String("b") > "a");
}
void tst_QString::integer_conversion_data()