summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-11-16 14:29:42 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2018-11-23 10:04:46 +0000
commit108c9015b960fccd79efc6de4459dbf05f6ced54 (patch)
tree9be7d754c03706665b6be503d7ecbf57504bfdc0 /tests
parent6dcc13d4024ed5fd56610c44140aed72e0248a8e (diff)
Implement transient locale as instantiating a class
A couple of QLocale tests were using setlocale twice to provide a transient locale tweak in tests; however, if the test in between fails, that can leave the program running in the "transient" locale after. So implement a proper class whose destructor ensures the transient is tidied away. Also change the locale in use by one of these transient changes: it purported to be checking things didn't depend on locale, but was using the same local as most of the test-cases for its test. Change-Id: I0d954edcc96019a8c2eb12b7a7c568e8b87a41d5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index b7cb8a1bdc..4803451399 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -153,6 +153,16 @@ private:
QString m_decimal, m_thousand, m_sdate, m_ldate, m_time;
QString m_sysapp;
bool europeanTimeZone;
+
+ 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)) {}
+ ~TransientLocale() { setlocale(m_category, m_prior); }
+ };
};
tst_QLocale::tst_QLocale()
@@ -806,10 +816,12 @@ void tst_QLocale::stringToDouble()
double d = locale.toDouble(num_str, &ok);
QCOMPARE(ok, good);
- char *currentLocale = setlocale(LC_ALL, "de_DE");
- QCOMPARE(locale.toDouble(num_str, &ok), d); // make sure result is independent of locale
- QCOMPARE(ok, good);
- setlocale(LC_ALL, currentLocale);
+ {
+ // Make sure result is independent of locale:
+ TransientLocale ignoreme(LC_ALL, "ar_SA");
+ QCOMPARE(locale.toDouble(num_str, &ok), d);
+ QCOMPARE(ok, good);
+ }
if (ok) {
double diff = d - num;
@@ -939,9 +951,8 @@ void tst_QLocale::doubleToString()
const QLocale locale(locale_name);
QCOMPARE(locale.toString(num, mode, precision), num_str);
- char *currentLocale = setlocale(LC_ALL, "de_DE");
+ TransientLocale ignoreme(LC_ALL, "de_DE");
QCOMPARE(locale.toString(num, mode, precision), num_str);
- setlocale(LC_ALL, currentLocale);
}
void tst_QLocale::strtod_data()