summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2024-01-09 19:19:29 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2024-02-02 08:26:14 +0100
commitb0cb4a80e5419fb65304d60c59798eaeb5032c22 (patch)
tree4b41915682be2f4635b8affa2569665a6edd64d0
parent5d451d514cc35402b04288372483223d6c893c47 (diff)
Modernize comparisons in tst_QLocale
QCOMPARE() can report enum values by name just fine, no need to laboriously convert them to strings. While comparing all tags in one go did allow a more comprehensive report, it's enough to know we failed; this is testing cross-platform code, so a debugger can tell us all those extra details if we get a failure. Testing qHash() doesn't distinguish equal things is fairly low value; at least avoid duplicating the construction of the reference value. Replace a bunch of other QVERIFY()s with the new cousins of QCOMPARE() for ordered and different comparisons. In the process, mark some of the QLocale objects as const. Change-Id: Ic93b8ed60c6f2cc846fbba428983778896d61291 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp57
1 files changed, 23 insertions, 34 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index f39b9ebd6d..9b0ee827ca 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -392,9 +392,9 @@ void tst_QLocale::defaulted_ctor()
#define TEST_CTOR(req_lang, req_country, exp_lang, exp_country) \
do { \
- QLocale l(QLocale::req_lang, QLocale::req_country); \
- QCOMPARE((int)l.language(), (int)exp_lang); \
- QCOMPARE((int)l.territory(), (int)exp_country); \
+ const QLocale l(QLocale::req_lang, QLocale::req_country); \
+ QCOMPARE(l.language(), exp_lang); \
+ QCOMPARE(l.territory(), exp_country); \
} while (false)
TEST_CTOR(AnyLanguage, AnyTerritory, default_lang, default_country);
@@ -478,15 +478,12 @@ void tst_QLocale::defaulted_ctor()
#undef TEST_CTOR
#define TEST_CTOR(req_lc, exp_lang, exp_country) \
do { \
- QLocale l(req_lc); \
- QVERIFY2(l.language() == QLocale::exp_lang \
- && l.territory() == QLocale::exp_country, \
- QString("requested: \"" + QString(req_lc) + "\", got: " \
- + QLocale::languageToString(l.language()) \
- + QLatin1Char('/') \
- + QLocale::territoryToString(l.territory())).toUtf8().constData()); \
- QCOMPARE(l, QLocale(QLocale::exp_lang, QLocale::exp_country)); \
- QCOMPARE(qHash(l), qHash(QLocale(QLocale::exp_lang, QLocale::exp_country))); \
+ const QLocale l(req_lc); \
+ QCOMPARE(l.language(), QLocale::exp_lang); \
+ QCOMPARE(l.territory(), QLocale::exp_country); \
+ const QLocale m(QLocale::exp_lang, QLocale::exp_country); \
+ QCOMPARE(l, m); \
+ QCOMPARE(qHash(l), qHash(m)); \
} while (false)
QLocale::setDefault(QLocale(QLocale::C));
@@ -541,14 +538,10 @@ void tst_QLocale::defaulted_ctor()
#undef TEST_CTOR
#define TEST_CTOR(req_lc, exp_lang, exp_script, exp_country) \
do { \
- QLocale l(req_lc); \
- QVERIFY2(l.language() == QLocale::exp_lang \
- && l.script() == QLocale::exp_script \
- && l.territory() == QLocale::exp_country, \
- QString("requested: \"" + QString(req_lc) + "\", got: " \
- + QLocale::languageToString(l.language()) \
- + QLatin1Char('/') + QLocale::scriptToString(l.script()) \
- + QLatin1Char('/') + QLocale::territoryToString(l.territory())).toUtf8().constData()); \
+ const QLocale l(req_lc); \
+ QCOMPARE(l.language(), QLocale::exp_lang); \
+ QCOMPARE(l.script(), QLocale::exp_script); \
+ QCOMPARE(l.territory(), QLocale::exp_country); \
} while (false)
TEST_CTOR("zh_CN", Chinese, SimplifiedHanScript, China);
@@ -731,13 +724,9 @@ void tst_QLocale::legacyNames()
#define TEST_CTOR(req_lc, exp_lang, exp_country) \
do { \
- QLocale l(req_lc); \
- QVERIFY2(l.language() == QLocale::exp_lang \
- && l.territory() == QLocale::exp_country, \
- QString("requested: \"" + QString(req_lc) + "\", got: " \
- + QLocale::languageToString(l.language()) \
- + QLatin1Char('/') \
- + QLocale::territoryToString(l.territory())).toUtf8().constData()); \
+ const QLocale l(req_lc); \
+ QCOMPARE(l.language(), QLocale::exp_lang); \
+ QCOMPARE(l.territory(), QLocale::exp_country); \
} while (false)
TEST_CTOR("mo_MD", Romanian, Moldova);
@@ -1055,7 +1044,7 @@ void tst_QLocale::stringToDouble()
QCOMPARE(d, num);
if (std::isfinite(num)) {
double diff = d > num ? d - num : num - d;
- QVERIFY(diff <= MY_DOUBLE_EPSILON);
+ QCOMPARE_LE(diff, MY_DOUBLE_EPSILON);
}
}
@@ -1066,7 +1055,7 @@ void tst_QLocale::stringToDouble()
QCOMPARE(d, num);
if (std::isfinite(num)) {
double diff = d > num ? d - num : num - d;
- QVERIFY(diff <= MY_DOUBLE_EPSILON);
+ QCOMPARE_LE(diff, MY_DOUBLE_EPSILON);
}
}
#undef MY_DOUBLE_EPSILON
@@ -1163,7 +1152,7 @@ void tst_QLocale::stringToFloat()
QCOMPARE(f, fnum);
if (std::isfinite(fnum)) {
float diff = f > fnum ? f - fnum : fnum - f;
- QVERIFY(diff <= MY_FLOAT_EPSILON);
+ QCOMPARE_LE(diff, MY_FLOAT_EPSILON);
}
}
@@ -1174,7 +1163,7 @@ void tst_QLocale::stringToFloat()
QCOMPARE(f, fnum);
if (std::isfinite(fnum)) {
float diff = f > fnum ? f - fnum : fnum - f;
- QVERIFY(diff <= MY_FLOAT_EPSILON);
+ QCOMPARE_LE(diff, MY_FLOAT_EPSILON);
}
}
#undef MY_FLOAT_EPSILON
@@ -2722,7 +2711,7 @@ void tst_QLocale::macDefaultLocale()
|| locale.groupSeparator() == QStringView(u"\xA0") // no-breaking space
|| locale.groupSeparator() == QStringView(u"'")
|| locale.groupSeparator().isEmpty());
- QVERIFY(locale.decimalPoint() != locale.groupSeparator());
+ QCOMPARE_NE(locale.decimalPoint(), locale.groupSeparator());
// make sure we are using the system to parse them
QCOMPARE(locale.toString(1234.56), systemLocaleFormatNumber(QString("1,234.56")));
@@ -3099,7 +3088,7 @@ void tst_QLocale::testNames()
if (language != QLocale::C) {
const int idx = name.indexOf(QLatin1Char('_'));
- QVERIFY(idx != -1);
+ QCOMPARE_NE(idx, -1);
const QString lang = name.left(idx);
QCOMPARE(QLocale(lang).language(), language);
@@ -3395,7 +3384,7 @@ void tst_QLocale::monthName()
QCOMPARE(ru.monthName(1, QLocale::NarrowFormat), QString::fromUtf8("\320\257"));
const auto sys = QLocale::system();
if (sys.language() == QLocale::Russian) // QTBUG-92018
- QVERIFY(sys.monthName(3) != sys.standaloneMonthName(3));
+ QCOMPARE_NE(sys.monthName(3), sys.standaloneMonthName(3));
const QLocale ir("ga_IE");
QCOMPARE(ir.monthName(1, QLocale::ShortFormat), QLatin1String("Ean"));