Commit f84e6a9a authored by Adriaan de Groot's avatar Adriaan de Groot 💬

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.
parent e3282dfb
...@@ -15,13 +15,26 @@ QTEST_MAIN(RecurTodoTest) ...@@ -15,13 +15,26 @@ QTEST_MAIN(RecurTodoTest)
using namespace KCalendarCore; 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() void RecurTodoTest::testAllDay()
{ {
qputenv("TZ", "GMT"); setTimeZone("UTC");
const QDate currentDate = QDate::currentDate(); const QDate currentDate = QDate::currentDate();
const QDateTime currentUtcDateTime = QDateTime::currentDateTimeUtc(); const QDateTime currentUtcDateTime = QDateTime::currentDateTimeUtc();
const QDate dueDate(QDate::currentDate()); const QDate dueDate(QDate::currentDate());
QCOMPARE(currentDate, dueDate);
QCOMPARE(currentDate, currentUtcDateTime.date());
Todo *todo = new Todo(); Todo *todo = new Todo();
todo->setDtStart(QDateTime(dueDate.addDays(-1), {})); todo->setDtStart(QDateTime(dueDate.addDays(-1), {}));
todo->setDtDue(QDateTime(dueDate, {})); todo->setDtDue(QDateTime(dueDate, {}));
...@@ -29,14 +42,17 @@ void RecurTodoTest::testAllDay() ...@@ -29,14 +42,17 @@ void RecurTodoTest::testAllDay()
todo->setAllDay(true); todo->setAllDay(true);
QCOMPARE(todo->dtStart().daysTo(todo->dtDue()), 1); QCOMPARE(todo->dtStart().daysTo(todo->dtDue()), 1);
QVERIFY(!todo->recurs());
Recurrence *recurrence = todo->recurrence(); Recurrence *recurrence = todo->recurrence();
recurrence->unsetRecurs(); recurrence->unsetRecurs();
recurrence->setDaily(1); recurrence->setDaily(1);
QCOMPARE(todo->dtDue(), QDateTime(dueDate, {})); QCOMPARE(todo->dtDue(), QDateTime(dueDate, {}));
QCOMPARE(todo->percentComplete(), 0);
QVERIFY(todo->recurs()); // Previously it did not recur
todo->setCompleted(currentUtcDateTime); todo->setCompleted(currentUtcDateTime);
QVERIFY(todo->recurs()); QVERIFY(todo->recurs());
QVERIFY(todo->percentComplete() == 0); QCOMPARE(todo->percentComplete(), 0); // It is still not done
const QDate newStartDate = todo->dtStart().date(); const QDate newStartDate = todo->dtStart().date();
const QDate newDueDate = todo->dtDue().date(); const QDate newDueDate = todo->dtDue().date();
QCOMPARE(newStartDate, currentDate); QCOMPARE(newStartDate, currentDate);
...@@ -50,7 +66,7 @@ void RecurTodoTest::testAllDay() ...@@ -50,7 +66,7 @@ void RecurTodoTest::testAllDay()
void RecurTodoTest::testRecurrenceStart() void RecurTodoTest::testRecurrenceStart()
{ {
qputenv("TZ", "GMT"); setTimeZone("UTC");
const QDateTime currentDateTime = QDateTime::currentDateTime(); const QDateTime currentDateTime = QDateTime::currentDateTime();
const QDate currentDate = currentDateTime.date(); const QDate currentDate = currentDateTime.date();
const QTime currentTimeWithMS = currentDateTime.time(); const QTime currentTimeWithMS = currentDateTime.time();
...@@ -73,7 +89,7 @@ void RecurTodoTest::testRecurrenceStart() ...@@ -73,7 +89,7 @@ void RecurTodoTest::testRecurrenceStart()
void RecurTodoTest::testNonAllDay() void RecurTodoTest::testNonAllDay()
{ {
qputenv("TZ", "GMT"); setTimeZone("UTC");
const QDateTime currentDateTime = QDateTime::currentDateTime(); const QDateTime currentDateTime = QDateTime::currentDateTime();
const QDate currentDate = currentDateTime.date(); const QDate currentDate = currentDateTime.date();
const QTime currentTimeWithMS = currentDateTime.time(); const QTime currentTimeWithMS = currentDateTime.time();
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
class RecurTodoTest : public QObject class RecurTodoTest : public QObject
{ {
Q_OBJECT Q_OBJECT
private:
void setTimeZone(const char* zonename);
private Q_SLOTS: private Q_SLOTS:
void testAllDay(); void testAllDay();
void testNonAllDay(); void testNonAllDay();
......
...@@ -17,7 +17,7 @@ using namespace KCalendarCore; ...@@ -17,7 +17,7 @@ using namespace KCalendarCore;
void TodoTest::initTestCase() void TodoTest::initTestCase()
{ {
qputenv("TZ", "GMT"); qputenv("TZ", "UTC");
} }
void TodoTest::testValidity() void TodoTest::testValidity()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment