summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qcollator/tst_qcollator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qcollator/tst_qcollator.cpp')
-rw-r--r--tests/auto/corelib/text/qcollator/tst_qcollator.cpp71
1 files changed, 33 insertions, 38 deletions
diff --git a/tests/auto/corelib/text/qcollator/tst_qcollator.cpp b/tests/auto/corelib/text/qcollator/tst_qcollator.cpp
index d1345906a9..b6da8a3899 100644
--- a/tests/auto/corelib/text/qcollator/tst_qcollator.cpp
+++ b/tests/auto/corelib/text/qcollator/tst_qcollator.cpp
@@ -1,38 +1,15 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qlocale.h>
#include <qcollator.h>
#include <private/qglobal_p.h>
+#include <QScopeGuard>
#include <cstring>
+#include <iostream>
class tst_QCollator : public QObject
{
@@ -75,8 +52,8 @@ void tst_QCollator::basics()
QCOMPARE(c3.locale(), de_AT);
// posix implementation supports only C and default locale,
- // so update it for Android build
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+ // so update it for Android and INTEGRITY builds
+#if !QT_CONFIG(icu) && !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
c3.setLocale(QLocale());
#endif
QCollatorSortKey key1 = c3.sortKey("test");
@@ -110,8 +87,8 @@ void tst_QCollator::moveSemantics()
// test QCollatorSortKey move assignment
// posix implementation supports only C and default locale,
- // so update it for Android build
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+ // so update it for Android and INTEGRITY builds
+#if !QT_CONFIG(icu) && !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
c1.setLocale(QLocale());
#endif
QCollatorSortKey key1 = c1.sortKey("1");
@@ -276,22 +253,33 @@ void tst_QCollator::compare()
QFETCH(int, punctuationResult);
QCollator collator((QLocale(locale)));
+
+ // AFTER the QCollator initialization
+ auto localechanger = qScopeGuard([original = QLocale()] {
+ QLocale::setDefault(original); // reset back to what it was
+ });
+ QLocale::setDefault(QLocale(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())
- QSKIP("Posix implementation of collation only supports default locale");
+#if defined(Q_OS_WASM)
+ if (strcmp(QTest::currentDataTag(), "english5") == 0
+ || strcmp(QTest::currentDataTag(), "english8") == 0)
+ QSKIP("Some en-us locale tests have issues on WASM");
+#endif // Q_OS_WASM
+#if !QT_CONFIG(icu) && !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
+ if (collator.locale() != QLocale::c() && collator.locale() != QLocale::system().collation())
+ QSKIP("POSIX implementation of collation only supports C and system collation locales");
#endif
if (numericMode)
collator.setNumericMode(true);
- int keyCompareResult = result;
- int keyCompareCaseInsensitiveResult = caseInsensitiveResult;
- int keyComparePunctuationResultResult = punctuationResult;
+ [[maybe_unused]] int keyCompareResult = result;
+ [[maybe_unused]] int keyCompareCaseInsensitiveResult = caseInsensitiveResult;
+ [[maybe_unused]] int keyComparePunctuationResultResult = punctuationResult;
// trying to deal with special behavior of different OS-dependent collators
if (collator.locale() == QLocale("C")) {
@@ -310,10 +298,17 @@ void tst_QCollator::compare()
// NOTE: currently QCollatorSortKey::compare is not working
// properly without icu: see QTBUG-88704 for details
QCOMPARE(asSign(collator.compare(s1, s2)), result);
+ if (!numericMode)
+ QCOMPARE(asSign(QCollator::defaultCompare(s1, s2)), result);
#if QT_CONFIG(icu)
auto key1 = collator.sortKey(s1);
auto key2 = collator.sortKey(s2);
QCOMPARE(asSign(key1.compare(key2)), keyCompareResult);
+
+ key1 = QCollator::defaultSortKey(s1);
+ key2 = QCollator::defaultSortKey(s2);
+ if (!numericMode)
+ QCOMPARE(asSign(key1.compare(key2)), keyCompareResult);
#endif
collator.setCaseSensitivity(Qt::CaseInsensitive);
QCOMPARE(asSign(collator.compare(s1, s2)), caseInsensitiveResult);