Skip to content

Commit

Permalink
Add test for date field backend boundaries
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Sep 12, 2023
1 parent d1d26d6 commit d491268
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/testdatefieldbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,47 @@ private slots:
QCOMPARE(backend.dateMsecs(), currentDateMSecs);
QCOMPARE(backend.dateString(), currentDateString);
}

void testDateBoundaries()
{
Quick::DateFieldBackend backend;
const auto minDate = QDate::currentDate().addDays(-5);
const auto maxDate = QDate::currentDate().addDays(5);
const auto minDateMs = minDate.startOfDay(Qt::UTC).toMSecsSinceEpoch();
const auto maxDateMs = maxDate.startOfDay(Qt::UTC).toMSecsSinceEpoch();
const auto invalidMinDate = minDate.addDays(-1);
const auto invalidMaxDate = maxDate.addDays(1);

// Set by QDate
backend.setMinimumDate(minDate);
backend.setMaximumDate(maxDate);

QCOMPARE(backend.minimumDate(), minDate);
QCOMPARE(backend.maximumDate(), maxDate);
QCOMPARE(backend.minimumDateMsecs(), minDateMs);
QCOMPARE(backend.maximumDateMsecs(), maxDateMs);

// Reset and try when setting by MSecs
backend.setMinimumDate({});
backend.setMaximumDate({});
backend.setMinimumDateMsecs(minDateMs);
backend.setMaximumDateMsecs(maxDateMs);

QCOMPARE(backend.minimumDate(), minDate);
QCOMPARE(backend.maximumDate(), maxDate);
QCOMPARE(backend.minimumDateMsecs(), minDateMs);
QCOMPARE(backend.maximumDateMsecs(), maxDateMs);

// Since we default to the current date, the date should be valid
QVERIFY(backend.validDate());

// Now try with invalid dates
backend.setDate(invalidMinDate);
QVERIFY(!backend.validDate());

backend.setDate(invalidMaxDate);
QVERIFY(!backend.validDate());
}
};

QTEST_MAIN(TestDateFieldBackend)
Expand Down

0 comments on commit d491268

Please sign in to comment.