From 877536f67416da2b5c742ad4705168788a67f333 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 13 Sep 2023 00:42:39 +0800 Subject: [PATCH] Check that signals were correctly emitted in testDateBoundaries Signed-off-by: Claudio Cambra --- test/testdatefieldbackend.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/testdatefieldbackend.cpp b/test/testdatefieldbackend.cpp index 918d633dec6a7..776c61e1032da 100644 --- a/test/testdatefieldbackend.cpp +++ b/test/testdatefieldbackend.cpp @@ -43,6 +43,13 @@ private slots: void testDateBoundaries() { Quick::DateFieldBackend backend; + + QSignalSpy minimumDateChangedSpy(&backend, &Quick::DateFieldBackend::minimumDateChanged); + QSignalSpy maximumDateChangedSpy(&backend, &Quick::DateFieldBackend::maximumDateChanged); + QSignalSpy minimumDateMsecsChangedSpy(&backend, &Quick::DateFieldBackend::minimumDateMsecsChanged); + QSignalSpy maximumDateMsecsChangedSpy(&backend, &Quick::DateFieldBackend::maximumDateMsecsChanged); + QSignalSpy validDateChangedSpy(&backend, &Quick::DateFieldBackend::validDateChanged); + const auto minDate = QDate::currentDate().addDays(-5); const auto maxDate = QDate::currentDate().addDays(5); const auto minDateMs = minDate.startOfDay(Qt::UTC).toMSecsSinceEpoch(); @@ -59,6 +66,12 @@ private slots: QCOMPARE(backend.minimumDateMsecs(), minDateMs); QCOMPARE(backend.maximumDateMsecs(), maxDateMs); + QCOMPARE(minimumDateChangedSpy.count(), 1); + QCOMPARE(maximumDateChangedSpy.count(), 1); + QCOMPARE(minimumDateMsecsChangedSpy.count(), 1); + QCOMPARE(maximumDateMsecsChangedSpy.count(), 1); + QCOMPARE(validDateChangedSpy.count(), 2); // Changes per each min/max date set + // Reset and try when setting by MSecs backend.setMinimumDate({}); backend.setMaximumDate({}); @@ -70,15 +83,23 @@ private slots: QCOMPARE(backend.minimumDateMsecs(), minDateMs); QCOMPARE(backend.maximumDateMsecs(), maxDateMs); + QCOMPARE(minimumDateChangedSpy.count(), 3); + QCOMPARE(maximumDateChangedSpy.count(), 3); + QCOMPARE(minimumDateMsecsChangedSpy.count(), 3); + QCOMPARE(maximumDateMsecsChangedSpy.count(), 3); + QCOMPARE(validDateChangedSpy.count(), 6); + // 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()); + QCOMPARE(validDateChangedSpy.count(), 7); backend.setDate(invalidMaxDate); QVERIFY(!backend.validDate()); + QCOMPARE(validDateChangedSpy.count(), 8); } };