mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 14:36:01 +03:00
Add test for date field backend boundaries
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
a4767a108b
commit
ebc3522e79
1 changed files with 41 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue