Skip to content

Commit

Permalink
Remove a duplicate inclusion of qlocale_data_p.h
Browse files Browse the repository at this point in the history
In tst_qlocale.cpp there was a #include that caused the static data
tables to be duplicated, violating ODR. All it actually needed was the
ability to iterate all rows of the locale_data[] table, so export a
method to do that from QLocaleData and have the test run that instead
of pulling in a second copy of the tables.

Pick-to: 6.8 6.5 6.2
Task-number: QTBUG-128930
Change-Id: Ie5ebdf508a622eeca93f8785bc09b086502aa0e2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
ediosyncratic committed Sep 23, 2024
1 parent 58ddd0a commit 96c0765
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/corelib/text/qlocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/corelib/text/qlocale_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 11 additions & 7 deletions tests/auto/corelib/text/qlocale/tst_qlocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3060,10 +3060,9 @@ void tst_QLocale::negativeNumbers()
QT_TEST_EQUALITY_OPS(egypt, farsi, false);
}

#ifdef QT_BUILD_INTERNAL
#include <private/qlocale_p.h>
#include <private/qlocale_data_p.h>

static const int locale_data_count = sizeof(locale_data)/sizeof(locale_data[0]);
#endif

void tst_QLocale::testNames_data()
{
Expand All @@ -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()
Expand Down

0 comments on commit 96c0765

Please sign in to comment.