diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-01-12 09:01:52 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-01-12 11:07:56 +0100 |
commit | 6b8c0a50585bb637c5cd33ca8ffde0cb9c4e3664 (patch) | |
tree | 12647726671357a571e2b371b0e33199efb08156 /tests/auto/corelib | |
parent | 66d94ea30be9c4c8cc81a52134022eb662bedd77 (diff) | |
parent | ca7f1d2197f78ec3332cfd86ab9921730b6d4f23 (diff) | |
download | qtbase-6b8c0a50585bb637c5cd33ca8ffde0cb9c4e3664.tar.gz |
Merge remote-tracking branch 'origin/5.6' into dev
Change-Id: I5839bded07e23af65ced9491c4f50242f964dd31
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 7 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qdate/tst_qdate.cpp | 41 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 46 |
3 files changed, 67 insertions, 27 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 846f560214..bbca60a80e 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -1736,12 +1736,16 @@ void tst_QVariant::compareNumbers_data() const QTest::newRow("float3") << qVariantFromValue(0.f) << qVariantFromValue(-1.f) << +1; QTest::newRow("float4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.f) << -1; QTest::newRow("float5") << qVariantFromValue(0.f) << qVariantFromValue(-float(qInf())) << +1; + QTest::newRow("float6") << qVariantFromValue(-float(qInf())) << qVariantFromValue(-float(qInf())) << 0; + QTest::newRow("float7") << qVariantFromValue(float(qInf())) << qVariantFromValue(float(qInf())) << 0; QTest::newRow("double1") << qVariantFromValue(0.) << qVariantFromValue(0.) << 0; QTest::newRow("double2") << qVariantFromValue(-1.) << qVariantFromValue(0.) << -1; QTest::newRow("double3") << qVariantFromValue(0.) << qVariantFromValue(-1.) << +1; QTest::newRow("double4") << qVariantFromValue(-qInf()) << qVariantFromValue(0.) << -1; QTest::newRow("double5") << qVariantFromValue(0.) << qVariantFromValue(-qInf()) << +1; + QTest::newRow("double6") << qVariantFromValue(-double(qInf())) << qVariantFromValue(-qInf()) << 0; + QTest::newRow("double7") << qVariantFromValue(qInf()) << qVariantFromValue(qInf()) << 0; // mixed comparisons // fp + fp @@ -1750,6 +1754,8 @@ void tst_QVariant::compareNumbers_data() const QTest::newRow("float+double3") << qVariantFromValue(0.f) << qVariantFromValue(-1.) << +1; QTest::newRow("float+double4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.) << -1; QTest::newRow("float+double5") << qVariantFromValue(0.f) << qVariantFromValue(-qInf()) << +1; + QTest::newRow("float+double6") << qVariantFromValue(-float(qInf())) << qVariantFromValue(qInf()) << 0; + QTest::newRow("float+double7") << qVariantFromValue(float(qInf())) << qVariantFromValue(qInf()) << 0; // fp + int QTest::newRow("float+int1") << qVariantFromValue(0.f) << qVariantFromValue(0) << 0; @@ -1760,6 +1766,7 @@ void tst_QVariant::compareNumbers_data() const QTest::newRow("double+int3") << qVariantFromValue(0.) << qVariantFromValue(-1) << +1; QTest::newRow("float+int4") << qVariantFromValue(1.5f) << qVariantFromValue(1) << +1; QTest::newRow("double+int4") << qVariantFromValue(1.5) << qVariantFromValue(1) << +1; + QTest::newRow("double+int5") << qVariantFromValue(qInf()) << qVariantFromValue(1) << +1; // fp + uint QTest::newRow("float+uint1") << qVariantFromValue(0.f) << qVariantFromValue(0U) << 0; diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp index 27988e5b5b..ba7586c3db 100644 --- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp @@ -392,16 +392,37 @@ void tst_QDate::weekNumber_data() QTest::addColumn<int>("month"); QTest::addColumn<int>("day"); - //next we fill it with data - QTest::newRow( "data0" ) << 10 << 2002 << 2002 << 3 << 8; - QTest::newRow( "data1" ) << 10 << 2002 << 2002 << 3 << 8; - QTest::newRow( "data2" ) << 52 << 1999 << 2000 << 1 << 1; - QTest::newRow( "data3" ) << 52 << 1999 << 1999 << 12 << 31; - QTest::newRow( "data4" ) << 1 << 2001 << 2001 << 1 << 1; - QTest::newRow( "data5" ) << 53 << 1998 << 1998 << 12 << 31; - QTest::newRow( "data6" ) << 1 << 1985 << 1984 << 12 << 31; - QTest::newRow( "data7" ) << 52 << 2006 << 2006 << 12 << 31; - QTest::newRow( "data8" ) << 53 << 2004 << 2005 << 1 << 1; + enum { Thursday = 4 }; + bool wasLastYearLong = false; // 1999 was not a long (53-week) year + bool isLongYear; + + // full 400-year cycle for Jan 1, 4 and Dec 28, 31 + for (int yr = 2000; yr < 2400; ++yr, wasLastYearLong = isLongYear) { + QByteArray yrstr = QByteArray::number(yr); + int wday = QDate(yr, 1, 1).dayOfWeek(); + + // the year is 53-week long if Jan 1 is Thursday or, if it's a leap year, a Wednesday + isLongYear = (wday == Thursday) || (QDate::isLeapYear(yr) && wday == Thursday - 1); + + // Jan 4 is always on week 1 + QTest::newRow(yrstr + "-01-04") << 1 << yr << yr << 1 << 4; + + // Dec 28 is always on the last week + QTest::newRow(yrstr + "-12-28") << (52 + isLongYear) << yr << yr << 12 << 28; + + // Jan 1 is on either on week 1 or on the last week of the previous year + QTest::newRow(yrstr + "-01-01") + << (wday <= Thursday ? 1 : 52 + wasLastYearLong) + << (wday <= Thursday ? yr : yr - 1) + << yr << 1 << 1; + + // Dec 31 is either on the last week or week 1 of the next year + wday = QDate(yr, 12, 31).dayOfWeek(); + QTest::newRow(yrstr + "-12-31") + << (wday >= Thursday ? 52 + isLongYear : 1) + << (wday >= Thursday ? yr : yr + 1) + << yr << 12 << 31; + } } void tst_QDate::weekNumber() diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 906129d1af..0088820b41 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -68,6 +68,7 @@ private slots: void timeSpec(); void toTime_t_data(); void toTime_t(); + void daylightSavingsTimeChange_data(); void daylightSavingsTimeChange(); void springForward_data(); void springForward(); @@ -1563,36 +1564,47 @@ void tst_QDateTime::toTime_t() } } +void tst_QDateTime::daylightSavingsTimeChange_data() +{ + QTest::addColumn<QDate>("inDST"); + QTest::addColumn<QDate>("outDST"); + QTest::newRow("Autumn") << QDate(2006, 8, 1) << QDate(2006, 12, 1); + QTest::newRow("Spring") << QDate(2006, 5, 1) << QDate(2006, 2, 1); +} + void tst_QDateTime::daylightSavingsTimeChange() { - // This is a regression test for an old bug where starting with a date in - // DST and then moving to a date outside it (or vice-versa) caused 1-hour - // jumps in time when addSecs() was called. + // This has grown from a regression test for an old bug where starting with + // a date in DST and then moving to a date outside it (or vice-versa) caused + // 1-hour jumps in time when addSecs() was called. // // The bug was caused by QDateTime knowing more than it lets show. // Internally, if it knows, QDateTime stores a flag indicating if the time is // DST or not. If it doesn't, it sets to "LocalUnknown". The problem happened // because some functions did not reset the flag when moving in or out of DST. - // WARNING: This test only works if there's a Daylight Savings Time change - // in the current locale between 2006-11-06 and 2006-10-16 - // This is true for Central European Time + // WARNING: This only tests anything if there's a Daylight Savings Time change + // in the current locale between inDST and outDST. + // This is true for Central European Time and may be elsewhere. - if (!europeanTimeZone) - QSKIP("Not tested with timezone other than Central European (CET/CEST)"); + QFETCH(QDate, inDST); + QFETCH(QDate, outDST); - QDateTime dt = QDateTime(QDate(2006, 11, 6), QTime(0, 0, 0), Qt::LocalTime); - dt.setDate(QDate(2006, 10, 16)); + // First with simple construction + QDateTime dt = QDateTime(outDST, QTime(0, 0, 0), Qt::LocalTime); + int outDSTsecs = dt.toTime_t(); + + dt.setDate(inDST); dt = dt.addSecs(1); - QCOMPARE(dt.date(), QDate(2006, 10, 16)); - QCOMPARE(dt.time(), QTime(0, 0, 1)); + QCOMPARE(dt, QDateTime(inDST, QTime(0, 0, 1))); // now using fromTime_t - dt = QDateTime::fromTime_t(1162767600); // 2006-11-06 00:00:00 +0100 - dt.setDate(QDate(2006, 10, 16)); - dt = dt.addSecs (1); - QCOMPARE(dt.date(), QDate(2006, 10, 16)); - QCOMPARE(dt.time(), QTime(0, 0, 1)); + dt = QDateTime::fromTime_t(outDSTsecs); + QCOMPARE(dt, QDateTime(outDST, QTime(0, 0, 0))); + + dt.setDate(inDST); + dt = dt.addSecs(60); + QCOMPARE(dt, QDateTime(inDST, QTime(0, 1, 0))); } void tst_QDateTime::springForward_data() |