From f84e6a9a38013c785d7b3e7f068c540ca4e36060 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 9 Jul 2020 20:44:10 +0000 Subject: [PATCH] Fix unittests on FreeBSD. - The "short form" timezone "GMT" does not always exist on FreeBSD. Use short form "UTC" instead. - While here, add a little test that the named timezone is valid. - Make tests a little more explicit as to what they're testing. --- autotests/testrecurtodo.cpp | 24 ++++++++++++++++++++---- autotests/testrecurtodo.h | 2 ++ autotests/testtodo.cpp | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/autotests/testrecurtodo.cpp b/autotests/testrecurtodo.cpp index 103241d35..9270c0c21 100644 --- a/autotests/testrecurtodo.cpp +++ b/autotests/testrecurtodo.cpp @@ -15,13 +15,26 @@ QTEST_MAIN(RecurTodoTest) using namespace KCalendarCore; +void RecurTodoTest::setTimeZone(const char* zonename) +{ + QVERIFY(QTimeZone(zonename).isValid()); + qputenv("TZ", zonename); + const QDateTime currentDateTime = QDateTime::currentDateTime(); + QVERIFY(currentDateTime.timeZone().isValid()); + QCOMPARE(currentDateTime.timeZoneAbbreviation(), QString::fromLatin1(zonename)); +} + + void RecurTodoTest::testAllDay() { - qputenv("TZ", "GMT"); + setTimeZone("UTC"); const QDate currentDate = QDate::currentDate(); const QDateTime currentUtcDateTime = QDateTime::currentDateTimeUtc(); const QDate dueDate(QDate::currentDate()); + QCOMPARE(currentDate, dueDate); + QCOMPARE(currentDate, currentUtcDateTime.date()); + Todo *todo = new Todo(); todo->setDtStart(QDateTime(dueDate.addDays(-1), {})); todo->setDtDue(QDateTime(dueDate, {})); @@ -29,14 +42,17 @@ void RecurTodoTest::testAllDay() todo->setAllDay(true); QCOMPARE(todo->dtStart().daysTo(todo->dtDue()), 1); + QVERIFY(!todo->recurs()); Recurrence *recurrence = todo->recurrence(); recurrence->unsetRecurs(); recurrence->setDaily(1); QCOMPARE(todo->dtDue(), QDateTime(dueDate, {})); + QCOMPARE(todo->percentComplete(), 0); + QVERIFY(todo->recurs()); // Previously it did not recur todo->setCompleted(currentUtcDateTime); QVERIFY(todo->recurs()); - QVERIFY(todo->percentComplete() == 0); + QCOMPARE(todo->percentComplete(), 0); // It is still not done const QDate newStartDate = todo->dtStart().date(); const QDate newDueDate = todo->dtDue().date(); QCOMPARE(newStartDate, currentDate); @@ -50,7 +66,7 @@ void RecurTodoTest::testAllDay() void RecurTodoTest::testRecurrenceStart() { - qputenv("TZ", "GMT"); + setTimeZone("UTC"); const QDateTime currentDateTime = QDateTime::currentDateTime(); const QDate currentDate = currentDateTime.date(); const QTime currentTimeWithMS = currentDateTime.time(); @@ -73,7 +89,7 @@ void RecurTodoTest::testRecurrenceStart() void RecurTodoTest::testNonAllDay() { - qputenv("TZ", "GMT"); + setTimeZone("UTC"); const QDateTime currentDateTime = QDateTime::currentDateTime(); const QDate currentDate = currentDateTime.date(); const QTime currentTimeWithMS = currentDateTime.time(); diff --git a/autotests/testrecurtodo.h b/autotests/testrecurtodo.h index 9374f06a7..7e44670f8 100644 --- a/autotests/testrecurtodo.h +++ b/autotests/testrecurtodo.h @@ -14,6 +14,8 @@ class RecurTodoTest : public QObject { Q_OBJECT +private: + void setTimeZone(const char* zonename); private Q_SLOTS: void testAllDay(); void testNonAllDay(); diff --git a/autotests/testtodo.cpp b/autotests/testtodo.cpp index 99ae9cdaa..1684a7c8a 100644 --- a/autotests/testtodo.cpp +++ b/autotests/testtodo.cpp @@ -17,7 +17,7 @@ using namespace KCalendarCore; void TodoTest::initTestCase() { - qputenv("TZ", "GMT"); + qputenv("TZ", "UTC"); } void TodoTest::testValidity() -- GitLab