97 void standaloneLongDayName() const; |
97 void standaloneLongDayName() const; |
98 void shortMonthName() const; |
98 void shortMonthName() const; |
99 void standaloneShortMonthName() const; |
99 void standaloneShortMonthName() const; |
100 void longMonthName() const; |
100 void longMonthName() const; |
101 void standaloneLongMonthName() const; |
101 void standaloneLongMonthName() const; |
|
102 void roundtrip() const; |
102 }; |
103 }; |
103 |
104 |
104 Q_DECLARE_METATYPE(QDate) |
105 Q_DECLARE_METATYPE(QDate) |
105 |
106 |
106 tst_QDate::tst_QDate() |
107 tst_QDate::tst_QDate() |
666 QCOMPARE( t.toString( format ), str ); |
667 QCOMPARE( t.toString( format ), str ); |
667 } |
668 } |
668 |
669 |
669 void tst_QDate::isLeapYear() |
670 void tst_QDate::isLeapYear() |
670 { |
671 { |
671 QVERIFY(QDate::isLeapYear(-4444)); |
672 QVERIFY(QDate::isLeapYear(-4445)); |
672 QVERIFY(!QDate::isLeapYear(-4443)); |
673 QVERIFY(!QDate::isLeapYear(-4444)); |
673 QVERIFY(QDate::isLeapYear(-8)); |
674 QVERIFY(!QDate::isLeapYear(-6)); |
674 QVERIFY(!QDate::isLeapYear(-7)); |
675 QVERIFY(QDate::isLeapYear(-5)); |
675 QVERIFY(QDate::isLeapYear(-4)); |
676 QVERIFY(!QDate::isLeapYear(-4)); |
676 QVERIFY(!QDate::isLeapYear(-3)); |
677 QVERIFY(!QDate::isLeapYear(-3)); |
677 QVERIFY(!QDate::isLeapYear(-2)); |
678 QVERIFY(!QDate::isLeapYear(-2)); |
678 QVERIFY(!QDate::isLeapYear(-1)); |
679 QVERIFY(QDate::isLeapYear(-1)); |
|
680 QVERIFY(!QDate::isLeapYear(0)); // Doesn't exist |
679 QVERIFY(!QDate::isLeapYear(1)); |
681 QVERIFY(!QDate::isLeapYear(1)); |
680 QVERIFY(!QDate::isLeapYear(1)); |
682 QVERIFY(!QDate::isLeapYear(2)); |
681 QVERIFY(!QDate::isLeapYear(1)); |
683 QVERIFY(!QDate::isLeapYear(3)); |
682 QVERIFY(QDate::isLeapYear(4)); |
684 QVERIFY(QDate::isLeapYear(4)); |
683 QVERIFY(!QDate::isLeapYear(7)); |
685 QVERIFY(!QDate::isLeapYear(7)); |
684 QVERIFY(QDate::isLeapYear(8)); |
686 QVERIFY(QDate::isLeapYear(8)); |
685 QVERIFY(QDate::isLeapYear(100)); |
687 QVERIFY(QDate::isLeapYear(100)); |
686 QVERIFY(QDate::isLeapYear(400)); |
688 QVERIFY(QDate::isLeapYear(400)); |
908 for(int i = 1; i <= 12; ++i) { |
910 for(int i = 1; i <= 12; ++i) { |
909 QCOMPARE(QDate::longMonthName(i, QDate::StandaloneFormat), locale.standaloneMonthName(i, QLocale::LongFormat)); |
911 QCOMPARE(QDate::longMonthName(i, QDate::StandaloneFormat), locale.standaloneMonthName(i, QLocale::LongFormat)); |
910 } |
912 } |
911 } |
913 } |
912 |
914 |
|
915 void tst_QDate::roundtrip() const |
|
916 { |
|
917 // Test round trip, this exercises setDate(), isValid(), isLeapYear(), |
|
918 // year(), month(), day(), julianDayFromDate(), and getDateFromJulianDay() |
|
919 // to ensure they are internally consistent (but doesn't guarantee correct) |
|
920 |
|
921 // Test Julian round trip in both BC and AD |
|
922 QDate testDate; |
|
923 QDate loopDate = QDate::fromJulianDay(1684899); // 1 Jan 100 BC |
|
924 while ( loopDate.toJulianDay() <= 1757948 ) { // 31 Dec 100 AD |
|
925 testDate.setDate( loopDate.year(), loopDate.month(), loopDate.day() ); |
|
926 QCOMPARE( loopDate.toJulianDay(), testDate.toJulianDay() ); |
|
927 loopDate = loopDate.addDays(1); |
|
928 } |
|
929 |
|
930 // Test Julian and Gregorian round trip during changeover period |
|
931 loopDate = QDate::fromJulianDay(2298153); // 1 Jan 1580 AD |
|
932 while ( loopDate.toJulianDay() <= 2300334 ) { // 31 Dec 1585 AD |
|
933 testDate.setDate( loopDate.year(), loopDate.month(), loopDate.day() ); |
|
934 QCOMPARE( loopDate.toJulianDay(), testDate.toJulianDay() ); |
|
935 loopDate = loopDate.addDays(1); |
|
936 } |
|
937 |
|
938 // Test Gregorian round trip during current useful period |
|
939 loopDate = QDate::fromJulianDay(2378497); // 1 Jan 1900 AD |
|
940 while ( loopDate.toJulianDay() <= 2488433 ) { // 31 Dec 2100 AD |
|
941 testDate.setDate( loopDate.year(), loopDate.month(), loopDate.day() ); |
|
942 QCOMPARE( loopDate.toJulianDay(), testDate.toJulianDay() ); |
|
943 loopDate = loopDate.addDays(1); |
|
944 } |
|
945 } |
|
946 |
913 QTEST_APPLESS_MAIN(tst_QDate) |
947 QTEST_APPLESS_MAIN(tst_QDate) |
914 #include "tst_qdate.moc" |
948 #include "tst_qdate.moc" |