From e0be3ab28ed5ce028555ed7ef2f25d2964dc81a5 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 9 Jan 2020 11:40:50 +0100 Subject: Combine negativeYear() and printNegativeYear() They overlapped and the latter had duplicated code, so make them into a single data-driven test. At the same time, replace the '-' at the start of the expected string with QLocale::negativeSign(), since the test fails otherwise when LC_NUMERIC=nb_NO on Linux (Debian/testing). Change-Id: I051c75abff16b2e6f8278fcb152b6bde14c71f9a Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdate/tst_qdate.cpp | 39 +++++++++++++---------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index dd2cb3eea8..567209dcf6 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -88,7 +88,7 @@ private slots: void toStringDateFormat(); void isLeapYear(); void yearsZeroToNinetyNine(); - void negativeYear() const; + void printNegativeYear_data() const; void printNegativeYear() const; void roundtripGermanLocale() const; #if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) @@ -1458,33 +1458,28 @@ void tst_QDate::yearsZeroToNinetyNine() } } - -void tst_QDate::negativeYear() const +void tst_QDate::printNegativeYear_data() const { - QDate y(-20, 3, 4); - QVERIFY(y.isValid()); - QCOMPARE(y.year(), -20); + QTest::addColumn("year"); + QTest::addColumn("expect"); + QTest::newRow("millennium") << -1000 << QStringLiteral("-1000"); + QTest::newRow("century") << -500 << QStringLiteral("-0500"); + QTest::newRow("decade") << -20 << QStringLiteral("-0020"); + QTest::newRow("year") << -7 << QStringLiteral("-0007"); } void tst_QDate::printNegativeYear() const { - { - QDate date(-500, 3, 4); - QVERIFY(date.isValid()); - QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0500")); - } - - { - QDate date(-10, 3, 4); - QVERIFY(date.isValid()); - QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0010")); - } + QFETCH(int, year); + QFETCH(QString, expect); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + expect.replace(QLatin1Char('-'), QLocale().negativeSign()); +#endif - { - QDate date(-2, 3, 4); - QVERIFY(date.isValid()); - QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0002")); - } + QDate date(year, 3, 4); + QVERIFY(date.isValid()); + QCOMPARE(date.year(), year); + QCOMPARE(date.toString(QLatin1String("yyyy")), expect); } void tst_QDate::roundtripGermanLocale() const -- cgit v1.2.3