summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qcollator/tst_qcollator.cpp')
-rw-r--r--tests/auto/corelib/tools/qcollator/tst_qcollator.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
index 2d65d3433f..72f88a235d 100644
--- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
+++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
@@ -93,7 +93,7 @@ void tst_QCollator::compare_data()
QTest::addColumn<int>("caseInsensitiveResult");
QTest::addColumn<bool>("numericMode");
QTest::addColumn<bool>("ignorePunctuation");
- QTest::addColumn<int>("punctuationResult");
+ QTest::addColumn<int>("punctuationResult"); // Test ignores punctuation *and case*
/*
It's hard to test English, because it's treated differently
@@ -169,8 +169,12 @@ void tst_QCollator::compare_data()
QTest::newRow("french6") << QString("fr_FR") << QString("Test 9") << QString("Test_19") << -1 << -1 << true << true << -1;
QTest::newRow("french7") << QString("fr_FR") << QString("test_19") << QString("test 19") << 1 << 1 << true << false << 1;
QTest::newRow("french8") << QString("fr_FR") << QString("test.19") << QString("test,19") << 1 << 1 << true << true << 0;
-}
+ // C locale: case sensitive [A-Z] < [a-z] but case insensitive [Aa] < [Bb] <...< [Zz]
+ const QString C = QStringLiteral("C");
+ QTest::newRow("C:ABBA:AaaA") << C << QStringLiteral("ABBA") << QStringLiteral("AaaA") << -1 << 1 << false << false << 1;
+ QTest::newRow("C:AZa:aAZ") << C << QStringLiteral("AZa") << QStringLiteral("aAZ") << -1 << 1 << false << false << 1;
+}
void tst_QCollator::compare()
{
@@ -184,6 +188,10 @@ void tst_QCollator::compare()
QFETCH(int, punctuationResult);
QCollator collator(locale);
+ // Need to canonicalize sign to -1, 0 or 1, as .compare() can produce any -ve for <, any +ve for >.
+ auto asSign = [](int compared) {
+ return compared < 0 ? -1 : compared > 0 ? 1 : 0;
+ };
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
if (collator.locale() != QLocale())
@@ -193,12 +201,12 @@ void tst_QCollator::compare()
if (numericMode)
collator.setNumericMode(true);
- QCOMPARE(collator.compare(s1, s2), result);
+ QCOMPARE(asSign(collator.compare(s1, s2)), result);
collator.setCaseSensitivity(Qt::CaseInsensitive);
- QCOMPARE(collator.compare(s1, s2), caseInsensitiveResult);
+ QCOMPARE(asSign(collator.compare(s1, s2)), caseInsensitiveResult);
#if !QT_CONFIG(iconv)
collator.setIgnorePunctuation(ignorePunctuation);
- QCOMPARE(collator.compare(s1, s2), punctuationResult);
+ QCOMPARE(asSign(collator.compare(s1, s2)), punctuationResult);
#endif
}