qt6-bb10/tests/auto/corelib/text
Edward Welbourne 2e9d33e534 Use correct index for QLocale::system()'s static
Nothing prevents client code from calling QLocale::setDefault() before
we ever instantiate QLocale::system() - aside from some quirks that
mean setDefault(), currently, does instantiate QLocale::system() to
force initialization of defaultLocalePrivate - so using defaultIndex()
could set the system QLocalePrivate instance's index incorrectly.

In any case, even if the index is initially set correctly, a
subsequent change to the system locale would change the correct index;
and nothing outside QLocale::system() has access to the instance that
would then be remembering an out-of-date index.

Actually tripping over that inconsistency took some deviousness, but
was possible. The index is (currently) only used for month name
lookups and those special-case, for the Roman-derived calendars, the
system locale, to only use the index if the system locale offers no
name for a month. Meanwhile, updateSystemPrivate() uses the fallback
locale's index for its look-up of which CLDR data to copy into the
fallback QLocaleData for the system locale.

None the less, a non-Roman calendar's lookup will go via the index to
get at the CLDR data for that calendar, thereby exposing the system
locale's index to use; and, sure enough, a setDefault() could lead
that to produce wrong answers.

In QLocale::system() there's a cached QLocalePrivate, whose index we
need to ensure stays in sync with the active system locale. So pass
its &m_index to systemData(), which will now (when passed this) ensure
it's up to date. Since we always have called systemData(), to ensure
it is up to date, we can skip that update in the initialization of the
cached private and use m_index = -1 to let systemData() know when it's
in the initial call, thereby making the static cache constinit.

Amended a test to what proved the issue was present.

Change-Id: I8d7ab5830cf0bbb9265c2af2a1edc9396ddef79f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-07-31 17:16:14 +02:00
..
qanystringview QAnyStringView: add QDebug stream operator 2023-07-06 02:18:38 +00:00
qbytearray QByteArray: add trimmed() unittest 2023-07-22 20:48:05 +03:00
qbytearray_large CI: Enable tests under corelib/text for Wasm platform 2023-07-10 14:53:34 +02:00
qbytearrayapisymmetry CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qbytearraylist CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qbytearraymatcher CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qbytearrayview String-like containers: add implicit conversions towards std:: string views 2023-07-13 16:19:06 +02:00
qbytedatabuffer CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qchar CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qcollator CI: Enable tests under corelib/text for Wasm platform 2023-07-10 14:53:34 +02:00
qlatin1stringmatcher CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qlatin1stringview CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qlocale Use correct index for QLocale::system()'s static 2023-07-31 17:16:14 +02:00
qregularexpression CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qstring QString: use _data based testing for trimmed 2023-07-22 20:48:00 +03:00
qstring_no_cast_from_bytearray CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qstringapisymmetry CI: Enable tests under corelib/text for Wasm platform 2023-07-10 14:53:34 +02:00
qstringbuilder QStringBuilder: test more concatenation variants 2023-07-24 01:04:55 +03:00
qstringconverter Provide QStringConverter equivalent of QTextCodec::availableCodecs 2023-07-18 09:38:38 +03:00
qstringiterator CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qstringlist CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qstringmatcher CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qstringtokenizer CI: Enable tests under corelib/text for Wasm platform 2023-07-10 14:53:34 +02:00
qstringview String-like containers: add implicit conversions towards std:: string views 2023-07-13 16:19:06 +02:00
qtextboundaryfinder CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
qunicodetools CMake: Make corelib tests standalone projects 2023-07-05 15:09:32 +02:00
shared Provide optTitle for a NumberDoubleTestData testcase that needs it 2022-10-11 11:21:38 +02:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00