diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qdatetime/tst_qdatetime.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qdatetime/tst_qdatetime.cpp b/tests/auto/qdatetime/tst_qdatetime.cpp index f8836a6..d612911 100644 --- a/tests/auto/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/qdatetime/tst_qdatetime.cpp @@ -85,6 +85,8 @@ private slots: void setTime_t(); void setMSecsSinceEpoch_data(); void setMSecsSinceEpoch(); + void toString_isoDate_data(); + void toString_isoDate(); void toString_enumformat(); void toString_strformat_data(); void toString_strformat(); @@ -506,6 +508,36 @@ void tst_QDateTime::setMSecsSinceEpoch() QCOMPARE(dt, reference.addMSecs(msecs)); } +void tst_QDateTime::toString_isoDate_data() +{ + QTest::addColumn<QDateTime>("dt"); + QTest::addColumn<QString>("formatted"); + + QTest::newRow("localtime") + << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34)) + << QString("1978-11-09T13:28:34"); + QTest::newRow("UTC") + << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), Qt::UTC) + << QString("1978-11-09T13:28:34Z"); + QDateTime dt(QDate(1978, 11, 9), QTime(13, 28, 34)); + dt.setUtcOffset(19800); + QTest::newRow("positive OffsetFromUTC") + << dt + << QString("1978-11-09T13:28:34+05:30"); + dt.setUtcOffset(-7200); + QTest::newRow("negative OffsetFromUTC") + << dt + << QString("1978-11-09T13:28:34-02:00"); +} + +void tst_QDateTime::toString_isoDate() +{ + QFETCH(QDateTime, dt); + QFETCH(QString, formatted); + + QCOMPARE(dt.toString(Qt::ISODate), formatted); +} + void tst_QDateTime::toString_enumformat() { QDateTime dt1(QDate(1995, 5, 20), QTime(12, 34, 56)); |