diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2019-06-26 12:48:21 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2019-07-02 09:49:36 +0200 |
commit | 8c8eae279d57ff73b69620f5710b8290d6268051 (patch) | |
tree | 691fd40336447f6c5874e350a19f86810709a3af /tests/auto/corelib/time | |
parent | c34242c679aaea6ee1badf6c1e5f274f925f5f50 (diff) |
Remove usages of deprecated APIs from QDateTime
- Replaced the usages of:
* QDateTime::toTime_t() -> QDateTime::toSecsSinceEpoch().
* QDateTime::fromTime_t() -> QDateTime::fromSecsSinceEpoch().
* QDate::shortDayName() -> QLocale::system().dayName().
* QTime by QElapsedTimer, where the deprecated methods of QTime
were used.
- Modified the tests for the deprecated methods to be enabled only
when the corresponding methods are enabled: when the deprecated
APIs are disabled, the tests will be also disabled, and the
compilation won't be broken.
Task-number: QTBUG-76491
Change-Id: I4d565db2329e580c567aae511696eb1efe120843
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/corelib/time')
-rw-r--r-- | tests/auto/corelib/time/qdate/tst_qdate.cpp | 4 | ||||
-rw-r--r-- | tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 36 |
2 files changed, 35 insertions, 5 deletions
diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 0ef494b229..73384c35f4 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -91,7 +91,7 @@ private slots: void negativeYear() const; void printNegativeYear() const; void roundtripGermanLocale() const; -#if QT_CONFIG(textdate) +#if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) void shortDayName() const; void standaloneShortDayName() const; void longDayName() const; @@ -1473,7 +1473,7 @@ void tst_QDate::roundtripGermanLocale() const theDateTime.fromString(theDateTime.toString(Qt::TextDate), Qt::TextDate); } -#if QT_CONFIG(textdate) +#if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) QT_WARNING_PUSH // the methods tested here are all deprecated QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 609b58cf85..ac1b903aa1 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -61,6 +61,10 @@ private slots: void timeSpec(); void toSecsSinceEpoch_data(); void toSecsSinceEpoch(); +#if QT_DEPRECATED_SINCE(5, 8) + void toTime_t_data(); + void toTime_t(); +#endif void daylightSavingsTimeChange_data(); void daylightSavingsTimeChange(); void springForward_data(); @@ -1690,6 +1694,34 @@ void tst_QDateTime::toSecsSinceEpoch() QDateTime datetime = dt( dateTimeStr ); qint64 asSecsSinceEpoch = datetime.toSecsSinceEpoch(); + QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000); + + QDateTime datetime2 = QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch); + QCOMPARE(datetime, datetime2); +} + +#if QT_DEPRECATED_SINCE(5, 8) +void tst_QDateTime::toTime_t_data() +{ + QTest::addColumn<QString>("dateTimeStr"); + QTest::addColumn<bool>("res"); + + QTest::newRow( "data1" ) << str( 1800, 1, 1, 12, 0, 0 ) << false; + QTest::newRow( "data2" ) << str( 1969, 1, 1, 12, 0, 0 ) << false; + QTest::newRow( "data3" ) << str( 2002, 1, 1, 12, 0, 0 ) << true; + QTest::newRow( "data4" ) << str( 2002, 6, 1, 12, 0, 0 ) << true; + QTest::newRow( "data5" ) << QString("INVALID") << false; + QTest::newRow( "data6" ) << str( 2038, 1, 1, 12, 0, 0 ) << true; + QTest::newRow( "data7" ) << str( 2063, 4, 5, 12, 0, 0 ) << true; // the day of First Contact + QTest::newRow( "data8" ) << str( 2107, 1, 1, 12, 0, 0 ) + << bool( sizeof(uint) > 32 && sizeof(time_t) > 32 ); +} + +void tst_QDateTime::toTime_t() +{ + QFETCH( QString, dateTimeStr ); + QDateTime datetime = dt( dateTimeStr ); + uint asTime_t = datetime.toTime_t(); QFETCH( bool, res ); if (res) { @@ -1697,15 +1729,13 @@ void tst_QDateTime::toSecsSinceEpoch() } else { QVERIFY( asTime_t == (uint)-1 ); } - QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000); if ( asTime_t != (uint) -1 ) { QDateTime datetime2 = QDateTime::fromTime_t( asTime_t ); QCOMPARE(datetime, datetime2); } - QDateTime datetime2 = QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch); - QCOMPARE(datetime, datetime2); } +#endif void tst_QDateTime::daylightSavingsTimeChange_data() { |