diff options
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 60 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 12 |
2 files changed, 6 insertions, 66 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 31f9bd9d33..d68af22585 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -39,12 +39,12 @@ # include <qprocess.h> #endif #include <float.h> -#include <locale.h> #include <qlocale.h> #include <private/qlocale_p.h> #include <private/qlocale_tools_p.h> #include <qnumeric.h> +#include "../../../../shared/localechange.h" #if defined(Q_OS_LINUX) && !defined(__UCLIBC__) # define QT_USE_FENV @@ -176,58 +176,7 @@ private: bool europeanTimeZone; void toReal_data(); - class TransientLocale - { - const int m_category; - const char *const m_prior; -#if !defined(QT_NO_SYSTEMLOCALE) && defined(Q_OS_UNIX) \ - && (!defined(Q_OS_DARWIN) || defined(Q_OS_NACL)) -#define TRANSIENT_ENV - // Unix system locale consults environment variables, so we need to set - // the appropriate one, too. - const QByteArray m_envVar, m_envPrior; - const bool m_envSet; - static QByteArray categoryToEnv(int category) - { - switch (category) { -#define CASE(cat) case cat: return #cat - CASE(LC_ALL); CASE(LC_NUMERIC); CASE(LC_TIME); CASE(LC_MONETARY); - CASE(LC_MESSAGES); CASE(LC_MEASUREMENT); CASE(LC_COLLATE); -#undef CASE - // Nothing in our code pays attention to any other LC_* - default: - Q_UNREACHABLE(); - qFatal("You need to add a case for this category"); - } - } -#endif // TRANSIENT_ENV - public: - TransientLocale(int category, const char *locale) - : m_category(category), - m_prior(setlocale(category, locale)) -#ifdef TRANSIENT_ENV - , m_envVar(categoryToEnv(category)), - m_envPrior(qgetenv(m_envVar.constData())), - m_envSet(qputenv(m_envVar.constData(), locale)) -#endif - { - QSystemLocale dummy; // to provoke a refresh of the system locale - } - ~TransientLocale() - { -#ifdef TRANSIENT_ENV - if (m_envSet) { - if (m_envPrior.isEmpty()) - qunsetenv(m_envVar.constData()); - else - qputenv(m_envVar.constData(), m_envPrior); - } -#endif - setlocale(m_category, m_prior); - QSystemLocale dummy; // to provoke a refresh of the system locale - } -#undef TRANSIENT_ENV - }; + using TransientLocale = QTestLocaleChange::TransientLocale; }; tst_QLocale::tst_QLocale() @@ -2242,7 +2191,7 @@ public: setWinLocaleInfo(LOCALE_SNATIVEDIGITS, m_digits); setWinLocaleInfo(LOCALE_IDIGITSUBSTITUTION, m_subst); - QSystemLocale dummy; // to provoke a refresh of the system locale + QTestLocaleChange::resetSystemLocale(); } QString m_decimal, m_thousand, m_sdate, m_ldate, m_stime, m_ltime, m_digits, m_subst; @@ -2268,8 +2217,7 @@ void tst_QLocale::windowsDefaultLocale() setWinLocaleInfo(LOCALE_IDIGITSUBSTITUTION, u"2"); // NB: when adding to the system things being set, be sure to update RestoreLocaleHelper, too. - QSystemLocale dummy; // to provoke a refresh of the system locale - QLocale locale = QLocale::system(); + QLocale locale = QTestLocaleChange::resetSystemLocale(); // Make sure we are seeing the system's format strings QCOMPARE(locale.zeroDigit(), QStringView(u"\u3007")); diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index a377834025..f6e7563774 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -60,6 +60,7 @@ #include <ctype.h> #include "../shared/test_number_shared.h" +#include "../../../../shared/localechange.h" #define CREATE_VIEW(string) \ const QString padded = QLatin1Char(' ') + string + QLatin1Char(' '); \ @@ -329,16 +330,7 @@ class tst_QString : public QObject void insert_impl() const { insert_impl<ArgType, QString &(QString::*)(qsizetype, const ArgType&)>(); } void insert_data(bool emptyIsNoop = false); - class TransientLocale - { - const int m_category; - const char *const m_prior; - public: - TransientLocale(int category, const char *locale) - : m_category(category), m_prior(setlocale(category, locale)) {} - bool isValid() const { return !!m_prior; } - ~TransientLocale() { if (m_prior) setlocale(m_category, m_prior); } - }; + using TransientLocale = QTestLocaleChange::TransientLocale; class TransientDefaultLocale { |