diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-02-08 19:02:01 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-02-20 08:48:46 +0000 |
commit | 3cdf8debd1f8bd9d3ebe598e36b99548db8b6bc7 (patch) | |
tree | 0d6f5370cc4a800e90c0a87a4641d9c676cfa741 /tests/auto/corelib/tools/qtime | |
parent | 567abeaa04db2c30f0d9a5cb95e11d295ad88784 (diff) |
Make sure to use C locale during time tests that assume it
Some format and parse tests for time and date-time depended on locale
but had test data for the C locale (so fail if the test-environment
has, e.g., LANG=de_DE@utf8). So impose the C locale (until Qt 6).
The date-time test did *some* attempts at fixing for locale, but
failed to handle am/pm; and we do have "### Qt 6" comments in
Q(Date|Time)+::fromString indicating that we intend to switch these
methods to use the C locale by default (which shall fix this once and
for all). So rip out the incomplete localization now and test we work
properly at least when the locale used *is* C. Add a comment to the
matching QDate test to rip out its (presently adequate) matching code
once we do get to Qt 6 and make fromString() use the C locale.
QDateTimeParser uses systemLocale(), which is initialized the first
time it gets accessed; so we need to frob the locale *early*; doing so
in the test-class constructor is about as early as we conveniently
can; and seems to work (while doing it in individual tests does not).
(There is no point rolling back at the end; the QSystemLocale global
has been set up by then, so the roll-back would merely leave the
global out of sync with setlocale() and the environment.)
Task-number: QTBUG-58728
Change-Id: Ifa6778a80276050a099387a6dab15a1096be7561
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/corelib/tools/qtime')
-rw-r--r-- | tests/auto/corelib/tools/qtime/tst_qtime.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp index 059e1e519b..71bf39fc4e 100644 --- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp @@ -28,10 +28,26 @@ #include <QtTest/QtTest> #include "qdatetime.h" +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +# include <locale.h> +#endif class tst_QTime : public QObject { Q_OBJECT + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +public: + tst_QTime() + { + // Some tests depend on C locale - BF&I it with belt *and* braces: + qputenv("LC_ALL", "C"); + setlocale(LC_ALL, "C"); + // Need to instantiate as early as possible, before anything accesses + // the QSystemLocale singleton; once it exists, there's no changing it. + } +#endif // remove for ### Qt 6 + private slots: void msecsTo_data(); void msecsTo(); |