From 8310533975fc3cafd796ca3b1266d6777137b2d0 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 16 Oct 2012 12:05:06 +0200 Subject: [PATCH] Improve QTime test coverage. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: If47de3dc047ac4f8a4a1498cf225e03bbbf4110e Reviewed-by: Mitch Curtis Reviewed-by: Jędrzej Nowacki Reviewed-by: Jon Severinsson --- src/corelib/tools/qdatetime.cpp | 2 +- tests/auto/corelib/tools/qtime/tst_qtime.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 7561847..7845273 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -1804,7 +1804,7 @@ QTime fromStringImpl(const QString &s, Qt::DateFormat f, bool &isMidnight24) if (s.size() == 5) { // Do not need to specify seconds if using ISO format. return QTime(hour, minute, 0, 0); - } else if ((s.size() > 6 && s[5] == QLatin1Char(',')) || s[5] == QLatin1Char('.')) { + } else if ((s.size() > 6) && (s[5] == QLatin1Char(',') || s[5] == QLatin1Char('.'))) { // Possibly specifying fraction of a minute. // We only want 5 digits worth of fraction of minute. This follows the existing diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp index a1a31d7..bfb8b4c 100644 --- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp @@ -192,6 +192,8 @@ void tst_QTime::addMSecs_data() QTest::newRow( "Data17_2") << QTime(0,0,0,0) << -5 << QTime(23,59,59,995); QTest::newRow( "Data17_3") << QTime(0,0,0,1) << -6 << QTime(23,59,59,995); QTest::newRow( "Data17_4") << QTime(0,0,0,2) << -7 << QTime(23,59,59,995); + + QTest::newRow( "Data18_0" ) << invalidTime() << 1 << invalidTime(); } void tst_QTime::addMSecs() @@ -574,6 +576,9 @@ void tst_QTime::fromStringDateFormat_data() QTest::newRow("TextDate - data1") << QString("10:12:34") << Qt::TextDate << QTime(10,12,34,0); QTest::newRow("TextDate - data2") << QString("19:03:54.998601") << Qt::TextDate << QTime(19, 3, 54, 999); QTest::newRow("TextDate - data3") << QString("19:03:54.999601") << Qt::TextDate << QTime(19, 3, 54, 999); + QTest::newRow("TextDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::TextDate << invalidTime(); + QTest::newRow("TextDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::TextDate << invalidTime(); + QTest::newRow("TextDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::TextDate << QTime(23, 1, 1, 0); QTest::newRow("IsoDate - valid, start of day, omit seconds") << QString::fromLatin1("00:00") << Qt::ISODate << QTime(0, 0, 0); QTest::newRow("IsoDate - valid, omit seconds") << QString::fromLatin1("22:21") << Qt::ISODate << QTime(22, 21, 0); @@ -585,11 +590,17 @@ void tst_QTime::fromStringDateFormat_data() QTest::newRow("IsoDate - invalid, too many minutes") << QString::fromLatin1("10:70") << Qt::ISODate << invalidTime(); // This is a valid time if it happens on June 30 or December 31 (leap seconds). QTest::newRow("IsoDate - invalid, too many seconds") << QString::fromLatin1("23:59:60") << Qt::ISODate << invalidTime(); + QTest::newRow("IsoDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::ISODate << invalidTime(); + QTest::newRow("IsoDate - invalid, not enough minutes") << QString::fromLatin1("23:0") << Qt::ISODate << invalidTime(); + QTest::newRow("IsoDate - invalid, minute fraction") << QString::fromLatin1("23:00,XX") << Qt::ISODate << invalidTime(); + QTest::newRow("IsoDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::ISODate << invalidTime(); + QTest::newRow("IsoDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::ISODate << QTime(23, 1, 1, 0); QTest::newRow("IsoDate - data0") << QString("00:00:00") << Qt::ISODate << QTime(0,0,0,0); QTest::newRow("IsoDate - data1") << QString("10:12:34") << Qt::ISODate << QTime(10,12,34,0); QTest::newRow("IsoDate - data2") << QString("19:03:54.998601") << Qt::ISODate << QTime(19, 3, 54, 999); QTest::newRow("IsoDate - data3") << QString("19:03:54.999601") << Qt::ISODate << QTime(19, 3, 54, 999); + QTest::newRow("IsoDate - minute fraction midnight") << QString("24:00,0") << Qt::ISODate << QTime(0, 0, 0, 0); } void tst_QTime::fromStringDateFormat() -- 2.7.4