summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2019-06-26 12:48:21 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2019-07-02 09:49:36 +0200
commit8c8eae279d57ff73b69620f5710b8290d6268051 (patch)
tree691fd40336447f6c5874e350a19f86810709a3af /tests
parentc34242c679aaea6ee1badf6c1e5f274f925f5f50 (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')
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp2
-rw-r--r--tests/auto/corelib/time/qdate/tst_qdate.cpp4
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp36
-rw-r--r--tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp2
-rw-r--r--tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp2
5 files changed, 38 insertions, 8 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index 0944ec252e..16e81cdd77 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -1261,7 +1261,7 @@ void tst_QFileInfo::fakeFileTimes_data()
QTest::newRow("early") << QDateTime(QDate(1901, 12, 14), QTime(12, 0));
// QTBUG-12006 claims XP handled this (2010-Mar-26 8:46:10) wrong due to an MS API bug:
- QTest::newRow("XP-bug") << QDateTime::fromTime_t(1269593170);
+ QTest::newRow("XP-bug") << QDateTime::fromSecsSinceEpoch(1269593170);
}
void tst_QFileInfo::fakeFileTimes()
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()
{
diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
index 06db0e8546..d1bf63bf8a 100644
--- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
@@ -172,7 +172,7 @@ ResultSet testRun(ContainerType &container, Algorithm &algorithm, int millisecs)
{
TestInt::lessThanRefCount = 0;
int count = 0;
- QTime t;
+ QElapsedTimer t;
t.start();
while(t.elapsed() < millisecs) {
++count;
diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
index c6f6900def..cd045e476c 100644
--- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
+++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
@@ -3454,7 +3454,7 @@ void tst_QDateTimeEdit::timeSpec()
}
QVERIFY(edit.minimumTime() != min.time());
QVERIFY(edit.minimumDateTime().timeSpec() != min.timeSpec());
- QCOMPARE(edit.minimumDateTime().toTime_t(), min.toTime_t());
+ QCOMPARE(edit.minimumDateTime().toSecsSinceEpoch(), min.toSecsSinceEpoch());
} else {
QSKIP("Not tested in the GMT timezone");
}