summaryrefslogtreecommitdiffstats
path: root/tests/auto/qdate
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qdate')
-rw-r--r--tests/auto/qdate/tst_qdate.cpp50
1 files changed, 42 insertions, 8 deletions
diff --git a/tests/auto/qdate/tst_qdate.cpp b/tests/auto/qdate/tst_qdate.cpp
index 7223291..60772eb 100644
--- a/tests/auto/qdate/tst_qdate.cpp
+++ b/tests/auto/qdate/tst_qdate.cpp
@@ -99,6 +99,7 @@ private slots:
void standaloneShortMonthName() const;
void longMonthName() const;
void standaloneLongMonthName() const;
+ void roundtrip() const;
};
Q_DECLARE_METATYPE(QDate)
@@ -668,17 +669,18 @@ void tst_QDate::toString_format()
void tst_QDate::isLeapYear()
{
- QVERIFY(QDate::isLeapYear(-4444));
- QVERIFY(!QDate::isLeapYear(-4443));
- QVERIFY(QDate::isLeapYear(-8));
- QVERIFY(!QDate::isLeapYear(-7));
- QVERIFY(QDate::isLeapYear(-4));
+ QVERIFY(QDate::isLeapYear(-4445));
+ QVERIFY(!QDate::isLeapYear(-4444));
+ QVERIFY(!QDate::isLeapYear(-6));
+ QVERIFY(QDate::isLeapYear(-5));
+ QVERIFY(!QDate::isLeapYear(-4));
QVERIFY(!QDate::isLeapYear(-3));
QVERIFY(!QDate::isLeapYear(-2));
- QVERIFY(!QDate::isLeapYear(-1));
- QVERIFY(!QDate::isLeapYear(1));
- QVERIFY(!QDate::isLeapYear(1));
+ QVERIFY(QDate::isLeapYear(-1));
+ QVERIFY(!QDate::isLeapYear(0)); // Doesn't exist
QVERIFY(!QDate::isLeapYear(1));
+ QVERIFY(!QDate::isLeapYear(2));
+ QVERIFY(!QDate::isLeapYear(3));
QVERIFY(QDate::isLeapYear(4));
QVERIFY(!QDate::isLeapYear(7));
QVERIFY(QDate::isLeapYear(8));
@@ -910,5 +912,37 @@ void tst_QDate::standaloneLongMonthName() const
}
}
+void tst_QDate::roundtrip() const
+{
+ // Test round trip, this exercises setDate(), isValid(), isLeapYear(),
+ // year(), month(), day(), julianDayFromDate(), and getDateFromJulianDay()
+ // to ensure they are internally consistent (but doesn't guarantee correct)
+
+ // Test Julian round trip in both BC and AD
+ QDate testDate;
+ QDate loopDate = QDate::fromJulianDay(1684899); // 1 Jan 100 BC
+ while ( loopDate.toJulianDay() <= 1757948 ) { // 31 Dec 100 AD
+ testDate.setDate( loopDate.year(), loopDate.month(), loopDate.day() );
+ QCOMPARE( loopDate.toJulianDay(), testDate.toJulianDay() );
+ loopDate = loopDate.addDays(1);
+ }
+
+ // Test Julian and Gregorian round trip during changeover period
+ loopDate = QDate::fromJulianDay(2298153); // 1 Jan 1580 AD
+ while ( loopDate.toJulianDay() <= 2300334 ) { // 31 Dec 1585 AD
+ testDate.setDate( loopDate.year(), loopDate.month(), loopDate.day() );
+ QCOMPARE( loopDate.toJulianDay(), testDate.toJulianDay() );
+ loopDate = loopDate.addDays(1);
+ }
+
+ // Test Gregorian round trip during current useful period
+ loopDate = QDate::fromJulianDay(2378497); // 1 Jan 1900 AD
+ while ( loopDate.toJulianDay() <= 2488433 ) { // 31 Dec 2100 AD
+ testDate.setDate( loopDate.year(), loopDate.month(), loopDate.day() );
+ QCOMPARE( loopDate.toJulianDay(), testDate.toJulianDay() );
+ loopDate = loopDate.addDays(1);
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QDate)
#include "tst_qdate.moc"