diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 42ae07b2586..8a8409825f2 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -500,6 +500,14 @@ static qsizetype findLocaleIndexById(QLocaleId localeId) noexcept } static constexpr qsizetype locale_data_size = q20::ssize(locale_data) - 1; // trailing guard +bool QLocaleData::allLocaleDataRows(bool (*check)(qsizetype, const QLocaleData &)) +{ + for (qsizetype index = 0; index < locale_data_size; ++index) { + if (!(*check)(index, locale_data[index])) + return false; + } + return true; +} #if QT_CONFIG(timezone) && QT_CONFIG(timezone_locale) && !QT_CONFIG(icu) namespace QtTimeZoneLocale { diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index a255038c1a2..33bb02e9e94 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -246,6 +246,8 @@ struct QLocaleData // data, e.g. calendar locales, as well as the main CLDR-derived data. [[nodiscard]] static qsizetype findLocaleIndex(QLocaleId localeId) noexcept; [[nodiscard]] static const QLocaleData *c() noexcept; + [[nodiscard]] Q_AUTOTEST_EXPORT + static bool allLocaleDataRows(bool (*check)(qsizetype, const QLocaleData &)); enum DoubleForm { DFExponent = 0, diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index f9846a22e37..4cc45fa5743 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -3060,10 +3060,9 @@ void tst_QLocale::negativeNumbers() QT_TEST_EQUALITY_OPS(egypt, farsi, false); } +#ifdef QT_BUILD_INTERNAL #include -#include - -static const int locale_data_count = sizeof(locale_data)/sizeof(locale_data[0]); +#endif void tst_QLocale::testNames_data() { @@ -3072,16 +3071,21 @@ void tst_QLocale::testNames_data() QLocale::setDefault(QLocale(QLocale::C)); // Ensures predictable fall-backs - for (int i = 0; i < locale_data_count; ++i) { - const QLocaleData &item = locale_data[i]; +#ifdef QT_BUILD_INTERNAL + bool ok = QLocaleData::allLocaleDataRows([](qsizetype index, const QLocaleData &item) { const QByteArray lang = QLocale::languageToString(QLocale::Language(item.m_language_id)).toUtf8(); const QByteArray land = QLocale::territoryToString(QLocale::Territory(item.m_territory_id)).toUtf8(); - QTest::addRow("data_%d (%s/%s)", i, lang.constData(), land.constData()) + QTest::addRow("data_%d (%s/%s)", int(index), lang.constData(), land.constData()) << QLocale::Language(item.m_language_id) << QLocale::Territory(item.m_territory_id); - } + return true; + }); + QVERIFY(ok); +#else + QSKIP("Only internal builds can access the data to set up this test"); +#endif // QT_BUILD_INTERNAL } void tst_QLocale::testNames()