From b0c1e07d648caf585d2be12cf3d18eb42b86f721 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 7 Feb 2017 13:10:38 +0100 Subject: Add tests for QCollatorSortKey There weren't any, at all. Testing on the CI showed that the implementation is broken on macOS, and, to a lesser extent, on Windows, so blacklist the failing tests until the implementation can be fixed. No need to hold back testing the other implementations. Task-number: QTBUG-58737 Change-Id: I9ae16ab778dbe2e95a6ca5e0bae00df4bad65cb2 Reviewed-by: Edward Welbourne --- tests/auto/corelib/tools/qcollator/BLACKLIST | 18 ++++++++++++++ .../auto/corelib/tools/qcollator/tst_qcollator.cpp | 28 ++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/auto/corelib/tools/qcollator/BLACKLIST diff --git a/tests/auto/corelib/tools/qcollator/BLACKLIST b/tests/auto/corelib/tools/qcollator/BLACKLIST new file mode 100644 index 0000000000..09b69e0108 --- /dev/null +++ b/tests/auto/corelib/tools/qcollator/BLACKLIST @@ -0,0 +1,18 @@ +[compare:swedish5] +osx +[compare:norwegian4] +osx +[compare:german6] +osx +windows +[compare:german7] +osx +windows +[compare:german8] +osx +[compare:german9] +osx +[compare:german10] +osx +[compare:french5] +osx diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp index d09910fd5c..ead0992f92 100644 --- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp +++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp @@ -33,6 +33,11 @@ #include +Q_CONSTEXPR inline int sign(int i) Q_DECL_NOTHROW +{ return i < 0 ? -1 : i > 0 ? 1 : 0; } + +#define QCOMPARE_SIGN(x, y) QCOMPARE(sign(x), sign(y)) + class tst_QCollator : public QObject { Q_OBJECT @@ -173,9 +178,28 @@ void tst_QCollator::compare() if (numericMode) collator.setNumericMode(true); - QCOMPARE(collator.compare(s1, s2), result); + QCOMPARE_SIGN(collator.compare(s1, s2), result); + { + const auto s1sk = collator.sortKey(s1); + const auto s2sk = collator.sortKey(s2); + + QCOMPARE_SIGN(s1sk.compare(s2sk), result); +#define CHECK(op) QCOMPARE(s1sk op s2sk, result op 0) + CHECK(<); +#undef CHECK + } + collator.setCaseSensitivity(Qt::CaseInsensitive); - QCOMPARE(collator.compare(s1, s2), caseInsensitiveResult); + QCOMPARE_SIGN(collator.compare(s1, s2), caseInsensitiveResult); + { + const auto s1sk = collator.sortKey(s1); + const auto s2sk = collator.sortKey(s2); + + QCOMPARE_SIGN(s1sk.compare(s2sk), caseInsensitiveResult); +#define CHECK(op) QCOMPARE(s1sk op s2sk, caseInsensitiveResult op 0) + CHECK(<); +#undef CHECK + } } -- cgit v1.2.3