diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-06-04 14:32:21 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-06-12 00:03:53 +0200 |
commit | e6457d9b600e26419bfdb5eea1acb62cf96b88e3 (patch) | |
tree | ebdc34b9d1a684f0bcc447ce89d27677f1e3fa8a /tests | |
parent | b65159a5ea8db05165b2eaab8e180a12f30063e4 (diff) |
Ensure test using setlocale() doesn't leave it permanently changed
tst_QStringList::sort() wants to use the C locale; but, if it failed,
it left that in force, since it only restored the prior locale on
success. It should also use C.UTF-8, since Qt now wants UTF-8.
Change-Id: If62e3d8da682081bf969075a719d03caebf09233
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp index b9d24f2656..a6fe866797 100644 --- a/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -30,6 +30,7 @@ #include <qlist.h> #include <qregularexpression.h> #include <qstringlist.h> +#include <QScopeGuard> #include <locale.h> @@ -188,7 +189,10 @@ void tst_QStringList::sort() list2 << "BETA" << "Gamma" << "alpha" << "beta" << "epsilon" << "gAmma" << "gamma"; QCOMPARE( list1, list2 ); - char *current_locale = setlocale(LC_ALL, "C"); + const char *const currentLocale = setlocale(LC_ALL, "C.UTF-8"); + if (!currentLocale) + QSKIP("Failed to set C locale, needed for testing"); + const QScopeGuard restore([currentLocale]() { setlocale(LC_ALL, currentLocale); }); QStringList list3, list4; list3 << "alpha" << "beta" << "BETA" << "gamma" << "Gamma" << "gAmma" << "epsilon"; list3.sort(Qt::CaseInsensitive); @@ -201,7 +205,6 @@ void tst_QStringList::sort() QCOMPARE(list4.at(0), QString("alpha")); QVERIFY(list4.indexOf("epsilon") > 0); QVERIFY(list4.indexOf("epsilon") < (list4.count() - 1)); - setlocale(LC_ALL, current_locale); } void tst_QStringList::replaceInStrings() |