Improve QDate, QTime, QDateTime auto tests.

Add more test data, merging operator!= tests in with operator==
to take advantage of added data.

Change-Id: If0426a3d01b8800cb7363385dbf3bcb21af5ed8f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mitch Curtis 2012-06-28 15:42:51 +02:00 committed by Qt by Nokia
parent e70e9f8239
commit b6e26b5b19
3 changed files with 110 additions and 43 deletions

View File

@ -73,8 +73,8 @@ private slots:
void addYears_data();
void addYears();
void daysTo();
void operator_eq_eq_data();
void operator_eq_eq();
void operator_not_eq();
void operator_lt();
void operator_gt();
void operator_lt_eq();
@ -671,32 +671,47 @@ void tst_QDate::daysTo()
QCOMPARE(zeroDate.daysTo(minDate), minJd);
}
void tst_QDate::operator_eq_eq()
void tst_QDate::operator_eq_eq_data()
{
QDate d1(2000,1,2);
QDate d2(2000,1,2);
QVERIFY( d1 == d2 );
QTest::addColumn<QDate>("d1");
QTest::addColumn<QDate>("d2");
QTest::addColumn<bool>("expectEqual");
d1 = QDate(2001,12,5);
d2 = QDate(2001,12,5);
QVERIFY( d1 == d2 );
QTest::newRow("data0") << QDate(2000,1,2) << QDate(2000,1,2) << true;
QTest::newRow("data1") << QDate(2001,12,5) << QDate(2001,12,5) << true;
QTest::newRow("data2") << QDate(2001,12,5) << QDate(2001,12,5) << true;
QTest::newRow("data3") << QDate(2001,12,5) << QDate(2002,12,5) << false;
d2 = QDate(2002,12,5);
QVERIFY( !(d1 == d2) );
QDate date1(1900, 1, 1);
QDate date2 = date1.addDays(1);
QDate date3 = date1.addDays(-1);
QDate date4 = date1.addMonths(1);
QDate date5 = date1.addMonths(-1);
QDate date6 = date1.addYears(1);
QDate date7 = date1.addYears(-1);
QTest::newRow("data4") << date2 << date3 << false;
QTest::newRow("data5") << date4 << date5 << false;
QTest::newRow("data6") << date6 << date7 << false;
QTest::newRow("data7") << date1 << date2 << false;
QTest::newRow("data8") << date1 << date3 << false;
QTest::newRow("data9") << date1 << date4 << false;
QTest::newRow("data10") << date1 << date5 << false;
QTest::newRow("data11") << date1 << date6 << false;
QTest::newRow("data12") << date1 << date7 << false;
}
void tst_QDate::operator_not_eq()
void tst_QDate::operator_eq_eq()
{
QDate d1(2000,1,2);
QDate d2(2000,1,2);
QVERIFY( !(d1 != d2) );
QFETCH(QDate, d1);
QFETCH(QDate, d2);
QFETCH(bool, expectEqual);
d1 = QDate(2001,12,5);
d2 = QDate(2001,12,5);
QVERIFY( !(d1 != d2) );
bool equal = d1 == d2;
QCOMPARE(equal, expectEqual);
bool notEqual = d1 != d2;
QCOMPARE(notEqual, !expectEqual);
d2 = QDate(2002,12,5);
QVERIFY( d1 != d2 );
}
void tst_QDate::operator_lt()

View File

@ -104,6 +104,7 @@ private slots:
void secsTo();
void msecsTo_data();
void msecsTo();
void operator_eqeq_data();
void operator_eqeq();
void currentDateTime();
void currentDateTimeUtc();
@ -1145,10 +1146,54 @@ void tst_QDateTime::daylightSavingsTimeChange()
QCOMPARE(dt.time(), QTime(0, 0, 1));
}
void tst_QDateTime::operator_eqeq_data()
{
QTest::addColumn<QDateTime>("dt1");
QTest::addColumn<QDateTime>("dt2");
QTest::addColumn<bool>("expectEqual");
QTest::addColumn<bool>("checkEuro");
QDateTime dateTime1(QDate(2012, 6, 20), QTime(14, 33, 2, 500));
QDateTime dateTime1a = dateTime1.addMSecs(1);
QDateTime dateTime2(QDate(2012, 20, 6), QTime(14, 33, 2, 500));
QDateTime dateTime2a = dateTime2.addMSecs(-1);
QDateTime dateTime3(QDate(1970, 1, 1), QTime(0, 0, 0, 0), Qt::UTC);
QDateTime dateTime3a = dateTime3.addDays(1);
QDateTime dateTime3b = dateTime3.addDays(-1);
// Ensure that different times may be equal when considering timezone.
QDateTime dateTime3c(dateTime3.addSecs(3600));
dateTime3c.setUtcOffset(3600);
QDateTime dateTime3d(dateTime3.addSecs(-3600));
dateTime3d.setUtcOffset(-3600);
// Convert from UTC to local.
QDateTime dateTime3e(dateTime3.date(), dateTime3.time());
QTest::newRow("data0") << dateTime1 << dateTime1 << true << false;
QTest::newRow("data1") << dateTime2 << dateTime2 << true << false;
QTest::newRow("data2") << dateTime1a << dateTime1a << true << false;
QTest::newRow("data3") << dateTime1 << dateTime2 << false << false;
QTest::newRow("data4") << dateTime1 << dateTime1a << false << false;
QTest::newRow("data5") << dateTime2 << dateTime2a << false << false;
QTest::newRow("data6") << dateTime2 << dateTime3 << false << false;
QTest::newRow("data7") << dateTime3 << dateTime3a << false << false;
QTest::newRow("data8") << dateTime3 << dateTime3b << false << false;
QTest::newRow("data9") << dateTime3a << dateTime3b << false << false;
QTest::newRow("data10") << dateTime3 << dateTime3c << true << false;
QTest::newRow("data11") << dateTime3 << dateTime3d << true << false;
QTest::newRow("data12") << dateTime3c << dateTime3d << true << false;
QTest::newRow("data13") << dateTime3 << dateTime3e << false << false;
if (europeanTimeZone) {
QTest::newRow("data14") << QDateTime(QDate(2004, 1, 2), QTime(2, 2, 3), Qt::LocalTime)
<< QDateTime(QDate(2004, 1, 2), QTime(1, 2, 3), Qt::UTC) << true << true;
}
}
void tst_QDateTime::operator_eqeq()
{
QDateTime dt1(QDate(2004, 1, 2), QTime(2, 2, 3), Qt::LocalTime);
QDateTime dt2(QDate(2004, 1, 2), QTime(1, 2, 3), Qt::UTC);
QFETCH(QDateTime, dt1);
QFETCH(QDateTime, dt2);
QFETCH(bool, expectEqual);
QFETCH(bool, checkEuro);
QVERIFY(dt1 == dt1);
QVERIFY(!(dt1 != dt1));
@ -1161,7 +1206,12 @@ void tst_QDateTime::operator_eqeq()
QVERIFY(dt1.toUTC() == dt1.toUTC());
if (europeanTimeZone) {
bool equal = dt1 == dt2;
QCOMPARE(equal, expectEqual);
bool notEqual = dt1 != dt2;
QCOMPARE(notEqual, !expectEqual);
if (checkEuro) {
QVERIFY(dt1.toUTC() == dt2);
QVERIFY(dt1 == dt2.toLocalTime());
}

View File

@ -60,8 +60,8 @@ private slots:
void addMSecs();
void addSecs_data();
void addSecs();
void operator_eq_eq_data();
void operator_eq_eq();
void operator_not_eq();
void operator_lt();
void operator_gt();
void operator_lt_eq();
@ -340,34 +340,36 @@ void tst_QTime::msecsTo()
QCOMPARE( t1.msecsTo( t2 ), delta );
}
void tst_QTime::operator_eq_eq()
void tst_QTime::operator_eq_eq_data()
{
QTime t1(0,0,0,0);
QTime t2(0,0,0,0);
QVERIFY( t1 == t2 );
QTest::addColumn<QTime>("t1");
QTest::addColumn<QTime>("t2");
QTest::addColumn<bool>("expectEqual");
t1 = QTime(12,34,56,20);
t2 = QTime(12,34,56,20);
QVERIFY( t1 == t2 );
QTime time1(0, 0, 0, 0);
QTime time2 = time1.addMSecs(1);
QTime time3 = time1.addMSecs(-1);
QTime time4(23, 59, 59, 999);
t1 = QTime(01,34,56,20);
t2 = QTime(13,34,56,20);
QVERIFY( !(t1 == t2) );
QTest::newRow("data0") << time1 << time2 << false;
QTest::newRow("data1") << time2 << time3 << false;
QTest::newRow("data2") << time4 << time1 << false;
QTest::newRow("data3") << time1 << time1 << true;
QTest::newRow("data4") << QTime(12,34,56,20) << QTime(12,34,56,20) << true;
QTest::newRow("data5") << QTime(01,34,56,20) << QTime(13,34,56,20) << false;
}
void tst_QTime::operator_not_eq()
void tst_QTime::operator_eq_eq()
{
QTime t1(0,0,0,0);
QTime t2(0,0,0,0);
QVERIFY( !(t1 != t2) );
QFETCH(QTime, t1);
QFETCH(QTime, t2);
QFETCH(bool, expectEqual);
t1 = QTime(12,34,56,20);
t2 = QTime(12,34,56,20);
QVERIFY( !(t1 != t2) );
bool equal = t1 == t2;
QCOMPARE(equal, expectEqual);
bool notEqual = t1 != t2;
QCOMPARE(notEqual, !expectEqual);
t1 = QTime(01,34,56,20);
t2 = QTime(13,34,56,20);
QVERIFY( t1 != t2 );
}
void tst_QTime::operator_lt()