From 057329c24c00047c8c3e1502a9a8dfa9a4169481 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 23 Jun 2020 12:40:55 +0200 Subject: Make feature datetimeparser depend on feature datestring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No client of QDateTimeParser actually uses it unless datestring was enabled, nor is it any use without datestring. Various methods conditioned on datestring are broken unless datetimeparser is enabled. We can't condition public API on datetimeparser, as it's a private feature, but client code can condition use of it on the private feature. All string-to-date/time conversions that use a string format (this includes all locale-specific formats) depend on feature datetimeparser. Change #if-ery (or add it) in all client (including test) code to test the right feature. Tidied up some code in the process. Killed some already-redundant textdate #if-ery. Renamed a test whose name claimed it involved locale, which it doesn't, in the course of #if-ing it. This simplifies the condition for feature datetimeedit (which overtly depended on textdate, redundantly since it depends on datestring which depends on textdate; its dependence on datetimeparser now makes its dependency on datestring also redundant). It also removes the need for assorted datestring checks in QDateTimeParser itself. Change-Id: I5dfe3a977042134b2cfb16cbcc795070634e7adf Reviewed-by: MÃ¥rten Nordheim --- tests/auto/corelib/time/qdate/tst_qdate.cpp | 16 +++++- .../auto/corelib/time/qdatetime/tst_qdatetime.cpp | 60 ++++++++++++---------- tests/auto/corelib/time/qtime/CMakeLists.txt | 2 + tests/auto/corelib/time/qtime/qtime.pro | 2 +- tests/auto/corelib/time/qtime/tst_qtime.cpp | 9 ++++ 5 files changed, 59 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 743cac4d3c..6c7283709c 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -78,19 +78,25 @@ private Q_SLOTS: void operator_gt_eq(); void operator_insert_extract_data(); void operator_insert_extract(); +#if QT_CONFIG(datestring) void fromStringDateFormat_data(); void fromStringDateFormat(); +# if QT_CONFIG(datetimeparser) void fromStringFormat_data(); void fromStringFormat(); +# endif void toStringFormat_data(); void toStringFormat(); void toStringDateFormat_data(); void toStringDateFormat(); +#endif void isLeapYear(); void yearsZeroToNinetyNine(); void printNegativeYear_data() const; void printNegativeYear() const; - void roundtripGermanLocale() const; +#if QT_CONFIG(datestring) + void roundtripString() const; +#endif void roundtrip() const; void qdebug() const; private: @@ -1089,6 +1095,7 @@ void tst_QDate::operator_insert_extract() QCOMPARE(deserialised, date); } +#if QT_CONFIG(datetimeparser) void tst_QDate::fromStringDateFormat_data() { QTest::addColumn("dateStr"); @@ -1295,7 +1302,9 @@ void tst_QDate::fromStringFormat() QDate dt = QDate::fromString(string, format); QCOMPARE(dt, expected); } +#endif // datetimeparser +#if QT_CONFIG(datestring) void tst_QDate::toStringFormat_data() { QTest::addColumn("t"); @@ -1342,6 +1351,7 @@ void tst_QDate::toStringDateFormat() QCOMPARE(date.toString(format), expectedStr); } +#endif // datestring void tst_QDate::isLeapYear() { @@ -1448,7 +1458,8 @@ void tst_QDate::printNegativeYear() const QCOMPARE(date.toString(QLatin1String("yyyy")), expect); } -void tst_QDate::roundtripGermanLocale() const +#if QT_CONFIG(datestring) +void tst_QDate::roundtripString() const { /* This code path should not result in warnings. */ const QDate theDate(QDate::currentDate()); @@ -1457,6 +1468,7 @@ void tst_QDate::roundtripGermanLocale() const const QDateTime theDateTime(QDateTime::currentDateTime()); theDateTime.fromString(theDateTime.toString(Qt::TextDate), Qt::TextDate); } +#endif void tst_QDate::roundtrip() const { diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 32d3b08376..877f29a094 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -72,18 +72,18 @@ private Q_SLOTS: void fromSecsSinceEpoch(); void fromMSecsSinceEpoch_data(); void fromMSecsSinceEpoch(); +#if QT_CONFIG(datestring) void toString_isoDate_data(); void toString_isoDate(); void toString_isoDate_extra(); -#if QT_CONFIG(datestring) void toString_textDate_data(); void toString_textDate(); void toString_textDate_extra(); -#endif void toString_rfcDate_data(); void toString_rfcDate(); void toString_enumformat(); void toString_strformat(); +#endif void addDays(); void addMonths(); void addMonths_data(); @@ -111,12 +111,16 @@ private Q_SLOTS: void currentDateTime(); void currentDateTimeUtc(); void currentDateTimeUtc2(); +#if QT_CONFIG(datestring) void fromStringDateFormat_data(); void fromStringDateFormat(); +# if QT_CONFIG(datetimeparser) void fromStringStringFormat_data(); void fromStringStringFormat(); void fromStringStringFormat_localTimeZone_data(); void fromStringStringFormat_localTimeZone(); +# endif +#endif void offsetFromUtc(); void setOffsetFromUtc(); @@ -130,7 +134,7 @@ private Q_SLOTS: void fewDigitsInYear() const; void printNegativeYear() const; -#if QT_CONFIG(textdate) +#if QT_CONFIG(datetimeparser) void roundtripTextDate() const; #endif void utcOffsetLessThan() const; @@ -280,13 +284,13 @@ QString tst_QDateTime::str( int y, int month, int d, int h, int min, int s ) return QDateTime( QDate(y, month, d), QTime(h, min, s) ).toString( Qt::ISODate ); } -QDateTime tst_QDateTime::dt( const QString& str ) +QDateTime tst_QDateTime::dt(const QString &text) { - if ( str == "INVALID" ) { - return QDateTime(); - } else { - return QDateTime::fromString( str, Qt::ISODate ); - } +#if QT_CONFIG(datestring) + if (text != "INVALID") + return QDateTime::fromString(text, Qt::ISODate); +#endif + return QDateTime(); } void tst_QDateTime::ctor() @@ -801,6 +805,7 @@ void tst_QDateTime::fromSecsSinceEpoch() #endif // timezone } +#if QT_CONFIG(datestring) // depends on, so implies, textdate void tst_QDateTime::toString_isoDate_data() { QTest::addColumn("datetime"); @@ -883,7 +888,6 @@ void tst_QDateTime::toString_isoDate_extra() #endif // timezone } -#if QT_CONFIG(datestring) // depends on textdate void tst_QDateTime::toString_textDate_data() { QTest::addColumn("datetime"); @@ -914,12 +918,14 @@ void tst_QDateTime::toString_textDate() QString result = datetime.toString(Qt::TextDate); QCOMPARE(result, expected); +#if QT_CONFIG(datetimeparser) QDateTime resultDatetime = QDateTime::fromString(result, Qt::TextDate); QCOMPARE(resultDatetime, datetime); QCOMPARE(resultDatetime.date(), datetime.date()); QCOMPARE(resultDatetime.time(), datetime.time()); QCOMPARE(resultDatetime.timeSpec(), datetime.timeSpec()); QCOMPARE(resultDatetime.offsetFromUtc(), datetime.offsetFromUtc()); +#endif } void tst_QDateTime::toString_textDate_extra() @@ -976,7 +982,6 @@ void tst_QDateTime::toString_textDate_extra() dt = QDateTime::fromMSecsSinceEpoch(0, Qt::UTC); QVERIFY(endsWithGmt(dt)); } -#endif // datestring void tst_QDateTime::toString_rfcDate_data() { @@ -1025,15 +1030,25 @@ void tst_QDateTime::toString_enumformat() { QDateTime dt1(QDate(1995, 5, 20), QTime(12, 34, 56)); -#if QT_CONFIG(textdate) QString str1 = dt1.toString(Qt::TextDate); QVERIFY(!str1.isEmpty()); // It's locale-dependent everywhere -#endif QString str2 = dt1.toString(Qt::ISODate); QCOMPARE(str2, QString("1995-05-20T12:34:56")); } +void tst_QDateTime::toString_strformat() +{ + // Most tests are in QLocale, just test that the api works. + QDate testDate(2013, 1, 1); + QTime testTime(1, 2, 3); + QDateTime testDateTime(testDate, testTime, Qt::UTC); + QCOMPARE(testDate.toString("yyyy-MM-dd"), QString("2013-01-01")); + QCOMPARE(testTime.toString("hh:mm:ss"), QString("01:02:03")); + QCOMPARE(testDateTime.toString("yyyy-MM-dd hh:mm:ss t"), QString("2013-01-01 01:02:03 UTC")); +} +#endif // datestring + void tst_QDateTime::addDays() { for (int pass = 0; pass < 2; ++pass) { @@ -2089,24 +2104,13 @@ void tst_QDateTime::operator_insert_extract() } } -void tst_QDateTime::toString_strformat() -{ - // Most tests are in QLocale, just test that the api works. - QDate testDate(2013, 1, 1); - QTime testTime(1, 2, 3); - QDateTime testDateTime(testDate, testTime, Qt::UTC); - QCOMPARE(testDate.toString("yyyy-MM-dd"), QString("2013-01-01")); - QCOMPARE(testTime.toString("hh:mm:ss"), QString("01:02:03")); - QCOMPARE(testDateTime.toString("yyyy-MM-dd hh:mm:ss t"), QString("2013-01-01 01:02:03 UTC")); -} - +#if QT_CONFIG(datestring) void tst_QDateTime::fromStringDateFormat_data() { QTest::addColumn("dateTimeStr"); QTest::addColumn("dateFormat"); QTest::addColumn("expected"); -#if QT_CONFIG(textdate) // Test Qt::TextDate format. QTest::newRow("text date") << QString::fromLatin1("Tue Jun 17 08:00:10 2003") << Qt::TextDate << QDateTime(QDate(2003, 6, 17), QTime(8, 0, 10, 0), Qt::LocalTime); @@ -2186,7 +2190,6 @@ void tst_QDateTime::fromStringDateFormat_data() << QStringLiteral("Sun 1. Dec 13:02:00 1974") << Qt::TextDate << ref; QTest::newRow("month:day") << QStringLiteral("Sun Dec 1 13:02:00 1974") << Qt::TextDate << ref; -#endif // textdate // Test Qt::ISODate format. QTest::newRow("trailing space") // QTBUG-80445 @@ -2453,6 +2456,7 @@ void tst_QDateTime::fromStringDateFormat() QCOMPARE(dateTime, expected); } +# if QT_CONFIG(datetimeparser) void tst_QDateTime::fromStringStringFormat_data() { QTest::addColumn("string"); @@ -2688,6 +2692,8 @@ void tst_QDateTime::fromStringStringFormat_localTimeZone() TimeZoneRollback useZone(localTimeZone); // enforce test's time zone fromStringStringFormat(); // call basic fromStringStringFormat test } +# endif // datetimeparser +#endif // datestring void tst_QDateTime::offsetFromUtc() { @@ -2999,7 +3005,7 @@ void tst_QDateTime::printNegativeYear() const } } -#if QT_CONFIG(textdate) +#if QT_CONFIG(datetimeparser) void tst_QDateTime::roundtripTextDate() const { /* This code path should not result in warnings. */ diff --git a/tests/auto/corelib/time/qtime/CMakeLists.txt b/tests/auto/corelib/time/qtime/CMakeLists.txt index d62858b6d0..0bd4b611e0 100644 --- a/tests/auto/corelib/time/qtime/CMakeLists.txt +++ b/tests/auto/corelib/time/qtime/CMakeLists.txt @@ -10,4 +10,6 @@ add_qt_test(tst_qtime DEFINES QT_NO_FOREACH QT_NO_KEYWORDS + PUBLIC_LIBRARIES + Qt::CorePrivate ) diff --git a/tests/auto/corelib/time/qtime/qtime.pro b/tests/auto/corelib/time/qtime/qtime.pro index 7d2df93cb0..f9daacf5d1 100644 --- a/tests/auto/corelib/time/qtime/qtime.pro +++ b/tests/auto/corelib/time/qtime/qtime.pro @@ -1,5 +1,5 @@ CONFIG += testcase TARGET = tst_qtime -QT = core testlib +QT = core-private testlib SOURCES = tst_qtime.cpp DEFINES += QT_NO_KEYWORDS QT_NO_FOREACH diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp index 764b2b8351..eaa90971f2 100644 --- a/tests/auto/corelib/time/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include #include #include "qdatetime.h" #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -57,14 +58,18 @@ private Q_SLOTS: void operator_gt(); void operator_lt_eq(); void operator_gt_eq(); +#if QT_CONFIG(datestring) +# if QT_CONFIG(datetimeparser) void fromStringFormat_data(); void fromStringFormat(); +# endif void fromStringDateFormat_data(); void fromStringDateFormat(); void toStringDateFormat_data(); void toStringDateFormat(); void toStringFormat_data(); void toStringFormat(); +#endif void msecsSinceStartOfDay_data(); void msecsSinceStartOfDay(); @@ -530,6 +535,8 @@ void tst_QTime::operator_gt_eq() QVERIFY( t1 >= t2 ); } +#if QT_CONFIG(datestring) +# if QT_CONFIG(datetimeparser) void tst_QTime::fromStringFormat_data() { QTest::addColumn("string"); @@ -562,6 +569,7 @@ void tst_QTime::fromStringFormat() QTime dt = QTime::fromString(string, format); QCOMPARE(dt, expected); } +# endif // datetimeparser void tst_QTime::fromStringDateFormat_data() { @@ -750,6 +758,7 @@ void tst_QTime::toStringFormat() QCOMPARE( t.toString( format ), str ); } +#endif // datestring void tst_QTime::msecsSinceStartOfDay_data() { -- cgit v1.2.3