1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
/*
* SPDX-FileCopyrightText: 2020 Glen Ditchfield <GJDitchfield@acm.org>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "testdateserialization.h"
#include "icalformat.h"
#include "memorycalendar.h"
#include <QDebug>
#include <QTest>
QTEST_MAIN(TestDateSerialization)
using namespace KCalendarCore;
// Check that serialization and deserialization of a minimal recurring todo
// preserves the start and due dates of the todo and its first occurrence.
// See bug 345498.
void TestDateSerialization::testNewRecurringTodo()
{
QDateTime startDate = QDate(2015, 3, 24).startOfDay();
QDateTime dueDate { startDate.addDays(1) };
Todo::Ptr todo(new Todo);
todo->setDtStart(startDate);
todo->setDtDue(dueDate, true);
todo->setAllDay(true);
todo->recurrence()->setMonthly(1);
MemoryCalendar::Ptr cal { new MemoryCalendar(QTimeZone::utc()) };
cal->addIncidence(todo);
ICalFormat format;
const QString result = format.toString(cal, QString());
Incidence::Ptr i = format.fromString(result);
QVERIFY(i);
QVERIFY(i->type() == IncidenceBase::IncidenceType::TypeTodo);
Todo::Ptr newTodo = i.staticCast<Todo>();
QCOMPARE(newTodo->dtStart(true), startDate);
QCOMPARE(newTodo->dtStart(false), startDate);
QCOMPARE(newTodo->dtDue(true), dueDate);
QCOMPARE(newTodo->dtDue(false), dueDate);
}
// Check that serialization and deserialization of a minimal recurring todo
// that has been completed once preserves the start and due dates of the todo
// and correctly calculates the start and due dates of the next occurrence.
// See bug 345565.
void TestDateSerialization::testTodoCompletedOnce()
{
QDateTime startDate = QDate::currentDate().startOfDay();
QDateTime dueDate { startDate.addDays(1) };
Todo::Ptr todo(new Todo);
todo->setDtStart(startDate);
todo->setDtDue(dueDate, true);
todo->setAllDay(true);
todo->recurrence()->setMonthly(1);
MemoryCalendar::Ptr cal { new MemoryCalendar(QTimeZone::utc()) };
cal->addIncidence(todo);
ICalFormat format;
QString result = format.toString(cal, QString());
Incidence::Ptr i = format.fromString(result);
QVERIFY(i);
QVERIFY(i->type() == IncidenceBase::IncidenceType::TypeTodo);
todo = i.staticCast<Todo>();
todo->setCompleted(dueDate);
cal = MemoryCalendar::Ptr {new MemoryCalendar(QTimeZone::utc()) };
cal->addIncidence(todo);
result = format.toString(cal, QString());
QCOMPARE(todo->dtStart(true), startDate);
QCOMPARE(todo->dtStart(false), startDate.addMonths(1));
QCOMPARE(todo->dtDue(true), dueDate);
QCOMPARE(todo->dtDue(false), dueDate.addMonths(1));
}
|