diff --git a/autotests/fbrecurring.cpp b/autotests/fbrecurring.cpp index a28619cc1..46c5333a1 100644 --- a/autotests/fbrecurring.cpp +++ b/autotests/fbrecurring.cpp @@ -1,73 +1,73 @@ /* This file is part of the kcalcore library. Copyright (c) 2007 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "icalformat.h" #include "event.h" #include "memorycalendar.h" #include "freebusy.h" #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; using namespace std; int main() { ICalFormat f; MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); Event::Ptr event1 = Event::Ptr(new Event); event1->setSummary(QStringLiteral("A")); event1->setDtStart(QDateTime(QDate(2006, 1, 1), QTime(12, 0, 0))); //event1->setDuration( 60 * 60 ); event1->setDtEnd(QDateTime(QDate(2006, 1, 1), QTime(13, 0, 0))); event1->setAllDay(false); event1->recurrence()->setDaily(1); //event1->recurrence()->setDuration( 2 ); event1->recurrence()->setEndDateTime(QDateTime(QDate(2006, 1, 3), QTime(13, 0, 0))); cout << f.toICalString(event1).toLocal8Bit().data() << endl; cal->addEvent(event1); Event::Ptr event2 = Event::Ptr(new Event); event2->setSummary(QStringLiteral("B")); event2->setDtStart(QDateTime(QDate(2006, 1, 1), QTime(13, 0, 0))); //event2->setDuration( 60 * 60 ); event2->setDtEnd(QDateTime(QDate(2006, 1, 1), QTime(14, 0, 0))); event2->setAllDay(false); event2->recurrence()->setDaily(1); //event2->recurrence()->setDuration( 3 ); event2->recurrence()->setEndDateTime(QDateTime(QDate(2006, 1, 4), QTime(13, 0, 0))); cout << f.toICalString(event2).toLocal8Bit().data() << endl; cal->addEvent(event2); QDateTime start(QDate(2006, 1, 2), QTime(0, 0, 0)); QDateTime end(QDate(2006, 1, 3), QTime(0, 0, 0)); FreeBusy::Ptr freebusy = FreeBusy::Ptr(new FreeBusy(cal->rawEvents(start.date(), end.date()), start, end)); QString result = f.createScheduleMessage(freebusy, iTIPPublish); cout << result.toLocal8Bit().data() << endl; return 0; } diff --git a/autotests/incidencestest.cpp b/autotests/incidencestest.cpp index d2561e1dd..b3e4a59cd 100644 --- a/autotests/incidencestest.cpp +++ b/autotests/incidencestest.cpp @@ -1,91 +1,91 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "icalformat.h" #include "event.h" #include "todo.h" #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; int main(int argc, char **argv) { QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), QStringLiteral("Verbose output"))); QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("testincidence")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); parser.process(app); const bool verbose = parser.isSet(QStringLiteral("verbose")); ICalFormat f; Event::Ptr event1 = Event::Ptr(new Event); event1->setSummary(QStringLiteral("Test Event")); event1->recurrence()->setDaily(2); event1->recurrence()->setDuration(3); QString eventString1 = f.toString(event1.staticCast()); if (verbose) { qDebug() << "EVENT1 START:" << eventString1 << "EVENT1 END"; } event1->setSchedulingID(QStringLiteral("foo")); Incidence::Ptr event2 = Incidence::Ptr(event1->clone()); Q_ASSERT(event1->uid() == event2->uid()); Q_ASSERT(event1->schedulingID() == event2->schedulingID()); QString eventString2 = f.toString(event2.staticCast()); if (verbose) { qDebug() << "EVENT2 START:" << eventString2 << "EVENT2 END"; } if (eventString1 != eventString2) { qDebug() << "Clone Event FAILED."; } else { qDebug() << "Clone Event SUCCEEDED."; } Todo::Ptr todo1 = Todo::Ptr(new Todo); todo1->setSummary(QStringLiteral("Test todo")); QString todoString1 = f.toString(todo1.staticCast()); if (verbose) { qDebug() << "todo1 START:" << todoString1 << "todo1 END"; } Incidence::Ptr todo2 = Incidence::Ptr(todo1->clone()); QString todoString2 = f.toString(todo2); if (verbose) { qDebug() << "todo2 START:" << todoString2 << "todo2 END"; } if (todoString1 != todoString2) { qDebug() << "Clone Todo FAILED."; } else { qDebug() << "Clone Todo SUCCEEDED."; } } diff --git a/autotests/loadcalendar.cpp b/autotests/loadcalendar.cpp index bfe6980d9..2b736e905 100644 --- a/autotests/loadcalendar.cpp +++ b/autotests/loadcalendar.cpp @@ -1,70 +1,70 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filestorage.h" #include "memorycalendar.h" #include #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; int main(int argc, char **argv) { QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), QStringLiteral("Verbose output"))); QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("testincidence")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); parser.process(app); MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage store(cal, QStringLiteral("cal")); if (!store.load()) { qWarning() << "Error storing into memory calendar"; return 1; } Todo::List todoList; // Build dictionary to look up Task object from Todo uid. Each task is a // QListViewItem, and is initially added with the view as the parent. todoList = cal->rawTodos(); if (todoList.isEmpty()) { qWarning() << "Error loading calendar"; return 1; } qDebug() << (*todoList.begin())->uid(); QString result = (*todoList.begin())->customProperty(QByteArray("karm"), QByteArray("totalTaskTime")); qDebug() << result; if (result != QStringLiteral("a,b")) { qDebug() << "The string a,b was expected, but given was" << result; return 1; } else { qDebug() << "Test passed"; } } diff --git a/autotests/readandwrite.cpp b/autotests/readandwrite.cpp index caa4977b4..2a3182963 100644 --- a/autotests/readandwrite.cpp +++ b/autotests/readandwrite.cpp @@ -1,83 +1,83 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filestorage.h" #include "icalformat.h" #include "memorycalendar.h" #include "vcalformat.h" #include #include #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; int main(int argc, char **argv) { qSetGlobalQHashSeed(0); // Disable QHash randomness qputenv("TZ", "GM"); QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), QStringLiteral("Verbose output"))); parser.addPositionalArgument(QStringLiteral("source"), QStringLiteral("Source file to copy.")); parser.addPositionalArgument(QStringLiteral("destination"), QStringLiteral("Destination directory.")); QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("readandwrite")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); parser.process(app); const QStringList parsedArgs = parser.positionalArguments(); if (parsedArgs.count() != 2) { parser.showHelp(); } QString input = parsedArgs[0]; QString output = parsedArgs[1]; QFileInfo outputFileInfo(output); output = outputFileInfo.absoluteFilePath(); qDebug() << "Input file:" << input; qDebug() << "Output file:" << output; if (outputFileInfo.fileName() == QLatin1String("KOrganizer_3.1.ics.ical.out") || outputFileInfo.fileName() == QLatin1String("KOrganizer_3.2.ics.ical.out")) { return 0; } MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage instore(cal, input); if (!instore.load()) { qDebug() << "DAMN"; return 1; } FileStorage outstore(cal, output); if (!outstore.save()) { return 1; } return 0; } diff --git a/autotests/testalarm.cpp b/autotests/testalarm.cpp index 085d390fd..623bec277 100644 --- a/autotests/testalarm.cpp +++ b/autotests/testalarm.cpp @@ -1,125 +1,125 @@ /* This file is part of the kcalcore library. Copyright (C) 2006 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testalarm.h" #include "event.h" #include "alarm.h" #include QTEST_MAIN(AlarmTest) -using namespace KCalCore; +using namespace KCalendarCore; void AlarmTest::testValidity() { Event inc; Alarm alarm(&inc); alarm.setType(Alarm::Email); QVERIFY(alarm.type() == Alarm::Email); } void AlarmTest::testCompare() { Event inc1, inc2; Alarm alarm1(&inc1), alarm2(&inc2); alarm1.setType(Alarm::Email); alarm2.setType(Alarm::Email); alarm1.setMailAddress(Person(QStringLiteral("name"), QStringLiteral("email@foo.com"))); alarm2.setMailAddress(Person(QStringLiteral("name"), QStringLiteral("email@foo.com"))); QVERIFY(alarm1 == alarm2); alarm2.setMailAddress(Person(QStringLiteral("name"), QStringLiteral("email@foo.pt"))); QVERIFY(alarm1 != alarm2); alarm2.setType(Alarm::Display); QVERIFY(alarm1 != alarm2); } void AlarmTest::testAssignment() { Alarm alarm1(nullptr); alarm1.setType(Alarm::Display); Alarm alarm2 = alarm1; QVERIFY(alarm1 == alarm2); Alarm alarm3 = Alarm(alarm1); QVERIFY(alarm2 == alarm3); } void AlarmTest::testSerializer_data() { - QTest::addColumn("alarm"); + QTest::addColumn("alarm"); Alarm::Ptr a1 = Alarm::Ptr(new Alarm(nullptr)); Alarm::Ptr a2 = Alarm::Ptr(new Alarm(nullptr)); Alarm::Ptr a3 = Alarm::Ptr(new Alarm(nullptr)); Alarm::Ptr a4 = Alarm::Ptr(new Alarm(nullptr)); a1->setType(Alarm::Email); a2->setType(Alarm::Procedure); a3->setType(Alarm::Display); a4->setType(Alarm::Audio); a3->setDisplayAlarm(QStringLiteral("foo")); a3->setText(QStringLiteral("foo bar")); a4->setAudioFile(QStringLiteral("file.mp3")); a2->setProgramFile(QStringLiteral("/usr/bin/foo")); a2->setProgramArguments(QStringLiteral("--play")); a1->setMailSubject(QStringLiteral("empty subject")); Person::List persons; persons << Person(QStringLiteral("a"), QStringLiteral("a@a.pt")) << Person(QStringLiteral("b"), QStringLiteral("b@b.pt")); a1->setMailAddresses(persons); a1->setMailAttachment(QStringLiteral("foo attachment")); a1->setMailText(QStringLiteral("mail body")); a1->setTime(QDateTime(QDate(2006, 8, 3), QTime(8, 0, 0), Qt::UTC)); a2->setStartOffset(Duration(7, Duration::Days)); a3->setEndOffset(Duration(1, Duration::Days)); a1->setSnoozeTime(Duration(1, Duration::Seconds)); a1->setRepeatCount(50); a1->setEnabled(true); a2->setEnabled(true); a3->setHasLocationRadius(false); a3->setLocationRadius(100); QTest::newRow("alarm1") << a1; QTest::newRow("alarm2") << a2; QTest::newRow("alarm3") << a3; QTest::newRow("alarm4") << a4; } void AlarmTest::testSerializer() { - QFETCH(KCalCore::Alarm::Ptr, alarm); + QFETCH(KCalendarCore::Alarm::Ptr, alarm); QByteArray array; QDataStream stream(&array, QIODevice::WriteOnly); stream << alarm; // Serialize Alarm::Ptr alarm2 = Alarm::Ptr(new Alarm(nullptr)); //QVERIFY(*alarm != *alarm2); QDataStream stream2(&array, QIODevice::ReadOnly); stream2 >> alarm2; // deserialize QVERIFY(*alarm == *alarm2); } diff --git a/autotests/testattachment.cpp b/autotests/testattachment.cpp index 47d0611f3..7d3723a40 100644 --- a/autotests/testattachment.cpp +++ b/autotests/testattachment.cpp @@ -1,97 +1,97 @@ /* This file is part of the kcalcore library. Copyright (C) 2006 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testattachment.h" #include "event.h" #include "attachment.h" #include QTEST_MAIN(AttachmentTest) -using namespace KCalCore; +using namespace KCalendarCore; void AttachmentTest::testValidity() { Attachment attachment(QStringLiteral("http://www.kde.org")); QCOMPARE(attachment.uri(), QStringLiteral("http://www.kde.org")); QCOMPARE(attachment.data(), QByteArray()); QVERIFY(attachment.decodedData().isEmpty()); QVERIFY(!attachment.isBinary()); attachment.setDecodedData("foo"); QVERIFY(attachment.isBinary()); QCOMPARE(attachment.decodedData(), QByteArray("foo")); QCOMPARE(attachment.data(), QByteArray("Zm9v")); QCOMPARE(attachment.size(), 3U); Attachment attachment2 = Attachment(QByteArray("Zm9v")); QCOMPARE(attachment2.size(), 3U); QCOMPARE(attachment2.decodedData(), QByteArray("foo")); attachment2.setDecodedData("123456"); QCOMPARE(attachment2.size(), 6U); Attachment attachment3(attachment2); QCOMPARE(attachment3.size(), attachment2.size()); QByteArray fred("jkajskldfasjfklasjfaskfaskfasfkasfjdasfkasjf"); Attachment attachment4(fred, QStringLiteral("image/nonsense")); QCOMPARE(fred, attachment4.data()); QVERIFY(attachment4.isBinary()); QByteArray ethel("a9fafafjafkasmfasfasffksjklfjau"); attachment4.setData(ethel); QCOMPARE(ethel, attachment4.data()); Attachment attachment5(QStringLiteral("http://www.kde.org")); Attachment attachment6(QStringLiteral("http://www.kde.org")); QVERIFY(attachment5 == attachment6); attachment5.setUri(QStringLiteral("http://bugs.kde.org")); QVERIFY(attachment5 != attachment6); attachment5.setDecodedData("123456"); attachment6.setDecodedData("123456"); QVERIFY(attachment5 == attachment6); attachment6.setDecodedData("12345"); QVERIFY(attachment5 != attachment6); } void AttachmentTest::testSerializer_data() { - QTest::addColumn("attachment"); + QTest::addColumn("attachment"); Attachment nonInline(QStringLiteral("http://www.kde.org")); Attachment inlineAttachment(QByteArray("foo"), QStringLiteral("image/nonsense")); QTest::newRow("inline") << inlineAttachment; QTest::newRow("not inline") << nonInline; } void AttachmentTest::testSerializer() { - QFETCH(KCalCore::Attachment, attachment); + QFETCH(KCalendarCore::Attachment, attachment); QByteArray array; QDataStream stream(&array, QIODevice::WriteOnly); stream << attachment; // Serialize Attachment attachment2(QStringLiteral("foo")); QVERIFY(attachment != attachment2); QDataStream stream2(&array, QIODevice::ReadOnly); stream2 >> attachment2; // deserialize QVERIFY(attachment == attachment2); } diff --git a/autotests/testattendee.cpp b/autotests/testattendee.cpp index bc4616469..f8acf2503 100644 --- a/autotests/testattendee.cpp +++ b/autotests/testattendee.cpp @@ -1,233 +1,233 @@ /* This file is part of the kcalcore library. Copyright (C) 2006,2008 Allen Winter Copyright (C) 2010 Casey Link Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testattendee.h" #include "attendee.h" #include "person.h" #include #include QTEST_MAIN(AttendeeTest) -using namespace KCalCore; +using namespace KCalendarCore; void AttendeeTest::testValidity() { Attendee attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); attendee.setRole(Attendee::Chair); QVERIFY(attendee.role() == Attendee::Chair); } void AttendeeTest::testType() { Attendee attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); QCOMPARE(attendee.cuType(), Attendee::Individual); QCOMPARE(attendee.cuTypeStr(), QLatin1String("INDIVIDUAL")); attendee.setCuType(attendee.cuTypeStr()); QCOMPARE(attendee.cuType(), Attendee::Individual); attendee.setCuType(QStringLiteral("INVALID")); QCOMPARE(attendee.cuType(), Attendee::Unknown); QCOMPARE(attendee.cuTypeStr(), QLatin1String("UNKNOWN")); attendee.setCuType(QStringLiteral("group")); QCOMPARE(attendee.cuType(), Attendee::Group); QCOMPARE(attendee.cuTypeStr(), QLatin1String("GROUP")); attendee.setCuType(QStringLiteral("resource")); QCOMPARE(attendee.cuType(), Attendee::Resource); QCOMPARE(attendee.cuTypeStr(), QLatin1String("RESOURCE")); attendee.setCuType(QStringLiteral("ROOM")); QCOMPARE(attendee.cuType(), Attendee::Room); QCOMPARE(attendee.cuTypeStr(), QLatin1String("ROOM")); attendee.setCuType(QStringLiteral("UNKNOWN")); QCOMPARE(attendee.cuType(), Attendee::Unknown); QCOMPARE(attendee.cuTypeStr(), QLatin1String("UNKNOWN")); attendee.setCuType(QStringLiteral("X-test")); QCOMPARE(attendee.cuType(), Attendee::Unknown); QCOMPARE(attendee.cuTypeStr(), QLatin1String("X-TEST")); attendee.setCuType(QStringLiteral("IANA-TEST")); QCOMPARE(attendee.cuType(), Attendee::Unknown); QCOMPARE(attendee.cuTypeStr(), QLatin1String("IANA-TEST")); attendee.setCuType(Attendee::Individual); QCOMPARE(attendee.cuType(), Attendee::Individual); attendee.setCuType(Attendee::Group); QCOMPARE(attendee.cuType(), Attendee::Group); attendee.setCuType(Attendee::Resource); QCOMPARE(attendee.cuType(), Attendee::Resource); attendee.setCuType(Attendee::Room); QCOMPARE(attendee.cuType(), Attendee::Room); attendee.setCuType(Attendee::Unknown); QCOMPARE(attendee.cuType(), Attendee::Unknown); } void AttendeeTest::testCompare() { Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); Attendee attendee2(QStringLiteral("wilma"), QStringLiteral("wilma@flintstone.com")); attendee1.setRole(Attendee::ReqParticipant); attendee2.setRole(Attendee::Chair); QVERIFY(!(attendee1 == attendee2)); attendee2.setRole(Attendee::ReqParticipant); QVERIFY(!(attendee1 == attendee2)); QVERIFY(attendee1.name() == QLatin1String("fred")); } void AttendeeTest::testCompareType() { Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); attendee1.setCuType(Attendee::Resource); Attendee attendee2 = attendee1; QCOMPARE(attendee2.cuType(), Attendee::Resource); QVERIFY(attendee1 == attendee2); attendee2.setCuType(Attendee::Individual); QVERIFY(!(attendee1 == attendee2)); } void AttendeeTest::testAssign() { Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); Attendee attendee2 = attendee1; QVERIFY(attendee1 == attendee2); attendee2.setRole(Attendee::NonParticipant); QVERIFY(!(attendee1 == attendee2)); Attendee attendee3(attendee1); QVERIFY(attendee3 == attendee1); } void AttendeeTest::testDataStreamOut() { Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); attendee1.setRSVP(true); attendee1.setRole(Attendee::Chair); attendee1.setUid(QStringLiteral("Shooby Doo Bop")); attendee1.setDelegate(QStringLiteral("I AM THE Delegate")); attendee1.setDelegator(QStringLiteral("AND I AM THE Delegator")); attendee1.setCuType(QStringLiteral("X-SPECIAL")); attendee1.setCustomProperty("name", QStringLiteral("value")); attendee1.setCustomProperty("foo", QStringLiteral("bar")); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << attendee1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); Person person; bool rsvp; QString delegate, delegator, cuType, uid; CustomProperties customProperties; Attendee::Role role; Attendee::PartStat status; uint role_int, status_int; in_stream >> person; QVERIFY(person.name() == attendee1.name()); QVERIFY(person.email() == attendee1.email()); in_stream >> rsvp; QVERIFY(rsvp == attendee1.RSVP()); in_stream >> role_int; role = Attendee::Role(role_int); QVERIFY(role == attendee1.role()); in_stream >> status_int; status = Attendee::PartStat(status_int); QVERIFY(status == attendee1.status()); in_stream >> uid; QVERIFY(uid == attendee1.uid()); in_stream >> delegate; QVERIFY(delegate == attendee1.delegate()); in_stream >> delegator; QVERIFY(delegator == attendee1.delegator()); in_stream >> cuType; QVERIFY(cuType == attendee1.cuTypeStr()); in_stream >> customProperties; QVERIFY(customProperties == attendee1.customProperties()); } void AttendeeTest::testDataStreamIn() { Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); attendee1.setRSVP(true); attendee1.setRole(Attendee::Chair); attendee1.setCuType(QStringLiteral("IANA-FOO")); attendee1.setUid(QStringLiteral("Shooby Doo Bop")); attendee1.setDelegate(QStringLiteral("I AM THE Delegate")); attendee1.setDelegator(QStringLiteral("AND I AM THE Delegator")); attendee1.setCustomProperty("name", QStringLiteral("value")); attendee1.setCustomProperty("foo", QStringLiteral("bar")); QVERIFY(!attendee1.isNull()); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << attendee1; Attendee attendee2; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); in_stream >> attendee2; QVERIFY(!attendee2.isNull()); QVERIFY(attendee2.uid() == attendee1.uid()); QVERIFY(attendee2.RSVP() == attendee1.RSVP()); QVERIFY(attendee2.role() == attendee1.role()); QVERIFY(attendee2.cuTypeStr() == attendee1.cuTypeStr()); QVERIFY(attendee2.status() == attendee1.status()); QVERIFY(attendee2.delegate() == attendee1.delegate()); QVERIFY(attendee2.delegator() == attendee1.delegator()); QVERIFY(attendee2.customProperties() == attendee1.customProperties()); QVERIFY(attendee1 == attendee2); } void AttendeeTest::testUid() { Attendee a(QStringLiteral("me"), QStringLiteral("test@dev.null")); QVERIFY(!a.uid().isEmpty()); a.setUid(QStringLiteral("42")); QCOMPARE(a.uid(), QLatin1String("42")); a.setUid({}); QVERIFY(!a.uid().isEmpty()); } diff --git a/autotests/testcalendarobserver.cpp b/autotests/testcalendarobserver.cpp index 9a301e08c..aa035a7eb 100644 --- a/autotests/testcalendarobserver.cpp +++ b/autotests/testcalendarobserver.cpp @@ -1,137 +1,137 @@ /* This file is part of the kcalcore library. Copyright (C) 2015 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testcalendarobserver.h" #include "filestorage.h" #include "calendar.h" #include "memorycalendar.h" #include #include #include QTEST_MAIN(CalendarObserverTest) -using namespace KCalCore; -Q_DECLARE_METATYPE(KCalCore::Incidence::Ptr) +using namespace KCalendarCore; +Q_DECLARE_METATYPE(KCalendarCore::Incidence::Ptr) Q_DECLARE_METATYPE(const Calendar *) class SimpleObserver : public QObject, public Calendar::CalendarObserver { Q_OBJECT public: SimpleObserver(Calendar *cal, QObject *parent = nullptr) : QObject(parent) , mCal(cal) { } Calendar *mCal = nullptr; Q_SIGNALS: - void incidenceAdded(const KCalCore::Incidence::Ptr &incidence); - void incidenceChanged(const KCalCore::Incidence::Ptr &incidence); - void incidenceAboutToBeDeleted(const KCalCore::Incidence::Ptr &incidence); - void incidenceDeleted(const KCalCore::Incidence::Ptr &incidence, const Calendar *calendar); + void incidenceAdded(const KCalendarCore::Incidence::Ptr &incidence); + void incidenceChanged(const KCalendarCore::Incidence::Ptr &incidence); + void incidenceAboutToBeDeleted(const KCalendarCore::Incidence::Ptr &incidence); + void incidenceDeleted(const KCalendarCore::Incidence::Ptr &incidence, const Calendar *calendar); protected: - void calendarIncidenceAdded(const KCalCore::Incidence::Ptr &incidence) override + void calendarIncidenceAdded(const KCalendarCore::Incidence::Ptr &incidence) override { Q_EMIT incidenceAdded(incidence); } - void calendarIncidenceChanged(const KCalCore::Incidence::Ptr &incidence) override + void calendarIncidenceChanged(const KCalendarCore::Incidence::Ptr &incidence) override { Q_EMIT incidenceChanged(incidence); } - void calendarIncidenceAboutToBeDeleted(const KCalCore::Incidence::Ptr &incidence) override + void calendarIncidenceAboutToBeDeleted(const KCalendarCore::Incidence::Ptr &incidence) override { QVERIFY(mCal->incidences().contains(incidence)); Q_EMIT incidenceAboutToBeDeleted(incidence); } - void calendarIncidenceDeleted(const KCalCore::Incidence::Ptr &incidence, const Calendar *calendar) override + void calendarIncidenceDeleted(const KCalendarCore::Incidence::Ptr &incidence, const Calendar *calendar) override { QCOMPARE(calendar, mCal); QVERIFY(!calendar->incidences().contains(incidence)); Q_EMIT incidenceDeleted(incidence, calendar); } }; void CalendarObserverTest::testAdd() { - qRegisterMetaType(); + qRegisterMetaType(); MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); SimpleObserver ob(cal.data()); QSignalSpy spy(&ob, &SimpleObserver::incidenceAdded); cal->registerObserver(&ob); Event::Ptr event1 = Event::Ptr(new Event()); event1->setUid(QStringLiteral("1")); cal->addEvent(event1); QCOMPARE(spy.count(), 1); QList arguments = spy.takeFirst(); - QCOMPARE(arguments.at(0).value(), static_cast(event1)); + QCOMPARE(arguments.at(0).value(), static_cast(event1)); } void CalendarObserverTest::testChange() { - qRegisterMetaType(); + qRegisterMetaType(); MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); SimpleObserver ob(cal.data()); QSignalSpy spy(&ob, &SimpleObserver::incidenceChanged); cal->registerObserver(&ob); Event::Ptr event1 = Event::Ptr(new Event()); event1->setUid(QStringLiteral("1")); cal->addEvent(event1); QCOMPARE(spy.count(), 0); event1->setDescription(QStringLiteral("desc")); QCOMPARE(spy.count(), 1); QList arguments = spy.takeFirst(); - QCOMPARE(arguments.at(0).value(), static_cast(event1)); + QCOMPARE(arguments.at(0).value(), static_cast(event1)); } void CalendarObserverTest::testDelete() { - qRegisterMetaType(); + qRegisterMetaType(); qRegisterMetaType(); MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); SimpleObserver ob(cal.data()); QSignalSpy spy1(&ob, &SimpleObserver::incidenceAboutToBeDeleted); QSignalSpy spy2(&ob, &SimpleObserver::incidenceDeleted); cal->registerObserver(&ob); Event::Ptr event1 = Event::Ptr(new Event()); event1->setUid(QStringLiteral("1")); cal->addEvent(event1); QCOMPARE(spy1.count(), 0); QCOMPARE(spy2.count(), 0); cal->deleteEvent(event1); QCOMPARE(spy1.count(), 1); QCOMPARE(spy2.count(), 1); QList arguments = spy1.takeFirst(); - QCOMPARE(arguments.at(0).value(), static_cast(event1)); + QCOMPARE(arguments.at(0).value(), static_cast(event1)); arguments = spy2.takeFirst(); - QCOMPARE(arguments.at(0).value(), static_cast(event1)); + QCOMPARE(arguments.at(0).value(), static_cast(event1)); QCOMPARE(arguments.at(1).value(), cal.data()); } #include "testcalendarobserver.moc" diff --git a/autotests/testcalfilter.cpp b/autotests/testcalfilter.cpp index 3860e7d76..db27bfa7d 100644 --- a/autotests/testcalfilter.cpp +++ b/autotests/testcalfilter.cpp @@ -1,49 +1,49 @@ /* This file is part of the kcalcore library. Copyright (c) 2006 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testcalfilter.h" #include "calfilter.h" #include QTEST_MAIN(CalFilterTest) -using namespace KCalCore; +using namespace KCalendarCore; void CalFilterTest::testValidity() { CalFilter f; f.setName(QStringLiteral("testfilter")); QVERIFY(f.name() == QLatin1String("testfilter")); CalFilter g(QStringLiteral("fredfilter")); QVERIFY(g.name() == QLatin1String("fredfilter")); CalFilter f1, f2; QVERIFY(f1 == f2); } void CalFilterTest::testCats() { CalFilter f1, f2; QStringList cats; cats << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c"); f1.setCategoryList(cats); f2.setCategoryList(cats); QVERIFY(f1.categoryList() == f2.categoryList()); } diff --git a/autotests/testcreateddatecompat.cpp b/autotests/testcreateddatecompat.cpp index 738915585..a07b4cd71 100644 --- a/autotests/testcreateddatecompat.cpp +++ b/autotests/testcreateddatecompat.cpp @@ -1,85 +1,85 @@ /* * Copyright (C) 2012 Christian Mollekopf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "testcreateddatecompat.h" #include "icalformat.h" #include "memorycalendar.h" #include #include #include //"X-KDE-ICAL-IMPLEMENTATION-VERSION:1.0\n" const char *const icalFile32 = "BEGIN:VCALENDAR\n" "PRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\n" "VERSION:2.0\n" "BEGIN:VEVENT\n" "DTSTAMP:20031213T204753Z\n" "ORGANIZER:MAILTO:nobody@nowhere\n" "CREATED:20031213T204152Z\n" "UID:uid\n" "SEQUENCE:0\n" "LAST-MODIFIED:20031213T204152Z\n" "SUMMARY:Holladiho\n" "DTSTART:20031213T071500Z\n" "END:VEVENT\n" "END:VCALENDAR\n"; const char *const icalFile33 = "BEGIN:VCALENDAR\n" "PRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\n" "VERSION:2.0\n" "X-KDE-ICAL-IMPLEMENTATION-VERSION:1.0\n" "BEGIN:VEVENT\n" "DTSTAMP:20031213T204753Z\n" "ORGANIZER:MAILTO:nobody@nowhere\n" "CREATED:20031213T204152Z\n" "UID:uid\n" "SEQUENCE:0\n" "LAST-MODIFIED:20031213T204152Z\n" "SUMMARY:Holladiho\n" "DTSTART:20031213T071500Z\n" "END:VEVENT\n" "END:VCALENDAR\n"; void CreatedDateCompatTest::testCompat32() { - KCalCore::MemoryCalendar::Ptr cal(new KCalCore::MemoryCalendar(QTimeZone::utc())); - KCalCore::ICalFormat format; + KCalendarCore::MemoryCalendar::Ptr cal(new KCalendarCore::MemoryCalendar(QTimeZone::utc())); + KCalendarCore::ICalFormat format; QVERIFY(format.fromRawString(cal, QByteArray(icalFile32))); - KCalCore::Event::Ptr event = cal->event(QStringLiteral("uid")); + KCalendarCore::Event::Ptr event = cal->event(QStringLiteral("uid")); QVERIFY(event); QCOMPARE(event->created(), QDateTime(QDate(2003, 12, 13), QTime(20, 47, 53), Qt::UTC)); } void CreatedDateCompatTest::testCompat33() { - KCalCore::MemoryCalendar::Ptr cal(new KCalCore::MemoryCalendar(QTimeZone::utc())); - KCalCore::ICalFormat format; + KCalendarCore::MemoryCalendar::Ptr cal(new KCalendarCore::MemoryCalendar(QTimeZone::utc())); + KCalendarCore::ICalFormat format; QVERIFY(format.fromRawString(cal, QByteArray(icalFile33))); - KCalCore::Event::Ptr event = cal->event(QStringLiteral("uid")); + KCalendarCore::Event::Ptr event = cal->event(QStringLiteral("uid")); QVERIFY(event); QCOMPARE(event->created(), QDateTime(QDate(2003, 12, 13), QTime(20, 41, 52), Qt::UTC)); QVERIFY(!event->customProperties().contains("X-KDE-ICAL-IMPLEMENTATION-VERSION")); } QTEST_MAIN(CreatedDateCompatTest) diff --git a/autotests/testcustomproperties.cpp b/autotests/testcustomproperties.cpp index c881575d4..52426978d 100644 --- a/autotests/testcustomproperties.cpp +++ b/autotests/testcustomproperties.cpp @@ -1,240 +1,240 @@ /* This file is part of the kcalcore library. Copyright (c) 2009 Allen Winter Copyright (C) 2010 Casey Link Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testcustomproperties.h" #include "customproperties.h" #include #include QTEST_MAIN(CustomPropertiesTest) -using namespace KCalCore; +using namespace KCalendarCore; void CustomPropertiesTest::testValidity() { CustomProperties cp; QByteArray app("KORG"); QByteArray key("TEXT"); QByteArray name("X-KDE-KORG-TEXT"); QCOMPARE(cp.customPropertyName(app, key), name); cp.setCustomProperty(app, key, QStringLiteral("rich")); QCOMPARE(cp.customProperty(app, key), QLatin1String("rich")); QCOMPARE(cp.nonKDECustomProperty(name), QLatin1String("rich")); cp.removeCustomProperty(app, key); cp.setCustomProperty(app, key, QStringLiteral("foo")); cp.setCustomProperty(app, key, QStringLiteral("rich")); QCOMPARE(cp.customProperty(app, key), QLatin1String("rich")); key = "X-TEXT"; cp.setNonKDECustomProperty(key, QStringLiteral("rich")); QCOMPARE(cp.nonKDECustomProperty(key), QLatin1String("rich")); cp.removeNonKDECustomProperty(key); cp.setNonKDECustomProperty(key, QStringLiteral("foo")); cp.setNonKDECustomProperty(key, QStringLiteral("rich")); QCOMPARE(cp.nonKDECustomProperty(key), QLatin1String("rich")); } void CustomPropertiesTest::testCompare() { CustomProperties cp1, cp2; QByteArray app("KORG"); QByteArray key("TEXT"); cp1.setCustomProperty(app, key, QStringLiteral("rich")); cp2 = cp1; QVERIFY(cp1 == cp2); CustomProperties cp3; cp3.setCustomProperty(app, key, cp1.customProperty(app, key)); QVERIFY(cp1 == cp3); QVERIFY(cp1.customProperty(app, key) == QLatin1String("rich")); QVERIFY(cp1.customProperty(app, "foo").isEmpty()); QVERIFY(cp1.customProperty(app, QByteArray()).isEmpty()); CustomProperties cp4; QVERIFY(cp4.customProperty(app, key).isEmpty()); QVERIFY(cp4.customProperty(app, "foo").isEmpty()); QVERIFY(cp4.customProperty(app, QByteArray()).isEmpty()); key = "X-TEXT"; cp1.setNonKDECustomProperty(key, QStringLiteral("rich")); cp2 = cp1; QVERIFY(cp1 == cp2); cp3.setNonKDECustomProperty(key, cp1.nonKDECustomProperty(key)); QVERIFY(cp1 == cp3); QVERIFY(cp1.nonKDECustomProperty(key) == QLatin1String("rich")); QVERIFY(cp1.nonKDECustomProperty("foo").isEmpty()); QVERIFY(cp1.nonKDECustomProperty(QByteArray()).isEmpty()); CustomProperties cp5; QVERIFY(cp5.nonKDECustomProperty(key).isEmpty()); QVERIFY(cp5.nonKDECustomProperty("foo").isEmpty()); QVERIFY(cp5.nonKDECustomProperty(QByteArray()).isEmpty()); } void CustomPropertiesTest::testMapValidity() { QMap cpmap; cpmap.insert("X-key1", QStringLiteral("val1")); cpmap.insert("X-key2", QStringLiteral("val2")); cpmap.insert("X-key3", QStringLiteral("val3")); cpmap.insert("X-key4", QStringLiteral("val4")); cpmap.insert("X-key5", QStringLiteral("val5")); CustomProperties cp; cp.setCustomProperties(cpmap); QVERIFY(cp.customProperties().value("X-key3") == QLatin1String("val3")); } void CustomPropertiesTest::testMapCompare() { QMap cpmap; cpmap.insert("X-key1", QStringLiteral("val1")); cpmap.insert("X-key2", QStringLiteral("val2")); cpmap.insert("X-key3", QStringLiteral("val3")); cpmap.insert("X-key4", QStringLiteral("val4")); cpmap.insert("X-key5", QStringLiteral("val5")); CustomProperties cp1, cp2; cp1.setCustomProperties(cpmap); cp1 = cp2; QVERIFY(cp1 == cp2); CustomProperties cp3; cp3.setCustomProperties(cp1.customProperties()); QVERIFY(cp1 == cp3); } void CustomPropertiesTest::testEmpty() { CustomProperties cp; QByteArray app("KORG"); QByteArray key("TEXT"); QString empty; cp.setCustomProperty(app, key, empty); QCOMPARE(cp.customProperty(app, key), empty); cp.removeCustomProperty(app, key); cp.setCustomProperty(app, key, empty); QCOMPARE(cp.customProperty(app, key), empty); key = "X-TEXT"; cp.setNonKDECustomProperty(key, empty); QCOMPARE(cp.nonKDECustomProperty(key), empty); cp.removeNonKDECustomProperty(key); cp.setNonKDECustomProperty(key, empty); QCOMPARE(cp.nonKDECustomProperty(key), empty); } void CustomPropertiesTest::testDataStreamIn() { QMap cpmap; cpmap.insert("X-key1", QStringLiteral("val1")); cpmap.insert("X-key2", QStringLiteral("val2")); cpmap.insert("X-key3", QStringLiteral("val3")); cpmap.insert("X-key4", QStringLiteral("val4")); cpmap.insert("X-key5", QStringLiteral("val5")); CustomProperties cp; cp.setCustomProperties(cpmap); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << cp; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); QMap cpmap2; in_stream >> cpmap2; QVERIFY(cpmap == cpmap2); } void CustomPropertiesTest::testVolatile() { QMap cpmap; cpmap.insert("X-key1", QStringLiteral("val1")); cpmap.insert("X-KDE-VOLATILE-FOO", QStringLiteral("val2")); CustomProperties cp; cp.setCustomProperties(cpmap); QCOMPARE(cp.customProperties().count(), 2); QMap cpmap2; cpmap2.insert("X-key1", QStringLiteral("val1")); CustomProperties cp2; cp2.setCustomProperties(cpmap2); QCOMPARE(cp, cp2); cp.removeCustomProperty("VOLATILE", "FOO"); QCOMPARE(cp.customProperties().count(), 1); cp.setCustomProperty("VOLATILE", "FOO", QStringLiteral("BAR")); QCOMPARE(cp.customProperties().count(), 2); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << cp; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); in_stream >> cp; QCOMPARE(cp.customProperties().count(), 1); } void CustomPropertiesTest::testDataStreamOut() { QMap cpmap; cpmap.insert("X-key1", QStringLiteral("val1")); cpmap.insert("X-key2", QStringLiteral("val2")); cpmap.insert("X-key3", QStringLiteral("val3")); cpmap.insert("X-key4", QStringLiteral("val4")); cpmap.insert("X-key5", QStringLiteral("val5")); CustomProperties cp, cp2; cp.setCustomProperties(cpmap); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << cp; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); in_stream >> cp2; QVERIFY(cp2 == cp); } diff --git a/autotests/testduration.cpp b/autotests/testduration.cpp index dcbbc08cc..7acfe956b 100644 --- a/autotests/testduration.cpp +++ b/autotests/testduration.cpp @@ -1,114 +1,114 @@ /* This file is part of the kcalcore library. Copyright (c) 2006 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testduration.h" #include "duration.h" #include #include QTEST_MAIN(DurationTest) -using namespace KCalCore; +using namespace KCalendarCore; void DurationTest::testValidity() { const QDateTime firstDateTime(QDate(2006, 8, 3), QTime(7, 0, 0), Qt::UTC); Duration d(firstDateTime, QDateTime(QDate(2006, 8, 3), QTime(8, 0, 0), Qt::UTC)); QCOMPARE(d.asSeconds(), 1 * 60 * 60); } void DurationTest::testCompare() { const QDateTime firstDateTime(QDate(2006, 8, 3), QTime(7, 0, 0), Qt::UTC); Duration d1(firstDateTime, QDateTime(QDate(2006, 8, 3), QTime(8, 0, 0), Qt::UTC)); //d1 has 1hr duration Duration d2(2 * 60 * 60); // 2hr duration Duration d1copy(d1); // test copy constructor Duration d1assign = d1; // test operator= QVERIFY(d1 < d2); QVERIFY(d1 != d2); QVERIFY(d1copy == d1); QVERIFY(d1assign == d1); Duration d3(7, Duration::Days); Duration d4(7 * 24 * 60 * 60, Duration::Seconds); QVERIFY(d3 != d4); // cannot compare days durations with seconds durations QVERIFY(d3 > d2); QVERIFY(-d3 < d2); Duration d5 = d1; d5 += d2; // should be 3hrs QVERIFY(d5 > d2); QVERIFY(d2 < d5); Duration d6(3 * 60 * 60); QVERIFY(d6 == d5); QVERIFY((d6 -= (2 * 60 * 60)) == d1); } void DurationTest::testSerializer_data() { - QTest::addColumn("duration"); + QTest::addColumn("duration"); Duration duration1; Duration duration2(7, Duration::Days); Duration duration3(7 * 24 * 60 * 60, Duration::Seconds); const QDateTime firstDateTime(QDate(2006, 8, 3), QTime(7, 0, 0), Qt::UTC); Duration duration4(firstDateTime, QDateTime(QDate(2006, 8, 3), QTime(8, 0, 0), Qt::UTC)); QTest::newRow("duration1") << duration1; QTest::newRow("duration2") << duration2; QTest::newRow("duration3") << duration3; QTest::newRow("duration4") << duration4; } void DurationTest::testSerializer() { - QFETCH(KCalCore::Duration, duration); + QFETCH(KCalendarCore::Duration, duration); QByteArray array; QDataStream stream(&array, QIODevice::WriteOnly); stream << duration; // Serialize Duration duration2; QDataStream stream2(&array, QIODevice::ReadOnly); stream2 >> duration2; // deserialize QVERIFY(duration == duration2); } void DurationTest::testIsNull() { Duration d; QVERIFY(d.isNull()); Duration d2(7, Duration::Days); QVERIFY(!d2.isNull()); } diff --git a/autotests/testevent.cpp b/autotests/testevent.cpp index ff98359a2..199e42c91 100644 --- a/autotests/testevent.cpp +++ b/autotests/testevent.cpp @@ -1,306 +1,306 @@ /* This file is part of the kcalcore library. Copyright (C) 2006,2008 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testevent.h" #include "event.h" #include "todo.h" #include QTEST_MAIN(EventTest) -Q_DECLARE_METATYPE(KCalCore::Incidence::DateTimeRole) +Q_DECLARE_METATYPE(KCalendarCore::Incidence::DateTimeRole) -using namespace KCalCore; +using namespace KCalendarCore; void EventTest::testSetRoles_data() { QTest::addColumn("originalDtStart"); QTest::addColumn("originalDtEnd"); QTest::addColumn("allDayEvent"); - QTest::addColumn("setRole"); + QTest::addColumn("setRole"); QTest::addColumn("dateTimeToSet"); QTest::addColumn("expectedDtStart"); QTest::addColumn("expectedDtEnd"); const QDateTime todayDate(QDate::currentDate(), {}); // all day event const QDateTime todayDateTime = QDateTime::currentDateTimeUtc(); - QTest::newRow("dnd 0 duration") << todayDate << todayDate << true << KCalCore::Incidence::RoleDnD + QTest::newRow("dnd 0 duration") << todayDate << todayDate << true << KCalendarCore::Incidence::RoleDnD << todayDateTime << todayDateTime << todayDateTime.addSecs(3600); } void EventTest::testSetRoles() { QFETCH(QDateTime, originalDtStart); QFETCH(QDateTime, originalDtEnd); QFETCH(bool, allDayEvent); - QFETCH(KCalCore::Incidence::DateTimeRole, setRole); + QFETCH(KCalendarCore::Incidence::DateTimeRole, setRole); QFETCH(QDateTime, dateTimeToSet); QFETCH(QDateTime, expectedDtStart); QFETCH(QDateTime, expectedDtEnd); Event::Ptr event = Event::Ptr(new Event()); event->setDtStart(originalDtStart); event->setDtEnd(originalDtEnd); event->setAllDay(allDayEvent); event->setDateTime(dateTimeToSet, setRole); QCOMPARE(event->dtStart(), expectedDtStart); QCOMPARE(event->dtEnd(), expectedDtEnd); } void EventTest::testValidity() { QDate dt = QDate::currentDate(); Event *event = new Event(); event->setDtStart(QDateTime(dt, {})); event->setDtEnd(QDateTime(dt, {}).addDays(1)); event->setSummary(QStringLiteral("Event1 Summary")); event->setDescription(QStringLiteral("This is a description of the first event")); event->setLocation(QStringLiteral("the place")); QCOMPARE(event->summary(), QStringLiteral("Event1 Summary")); QCOMPARE(event->location(), QStringLiteral("the place")); QCOMPARE(event->type(), Incidence::TypeEvent); } void EventTest::testCompare() { QDate dt = QDate::currentDate(); Event event1; event1.setDtStart(QDateTime(dt, {})); event1.setDtEnd(QDateTime(dt, {}).addDays(1)); event1.setSummary(QStringLiteral("Event1 Summary")); event1.setDescription(QStringLiteral("This is a description of the first event")); event1.setLocation(QStringLiteral("the place")); Event event2; event2.setDtStart(QDateTime(dt, {}).addDays(1)); event2.setDtEnd(QDateTime(dt, {}).addDays(2)); event2.setSummary(QStringLiteral("Event2 Summary")); event2.setDescription(QStringLiteral("This is a description of the second event")); event2.setLocation(QStringLiteral("the other place")); QVERIFY(!(event1 == event2)); QCOMPARE(event1.dtEnd(), event2.dtStart()); QCOMPARE(event2.summary(), QStringLiteral("Event2 Summary")); } void EventTest::testClone() { QDate dt = QDate::currentDate(); Event event1; event1.setDtStart(QDateTime(dt, {})); event1.setDtEnd(QDateTime(dt, {}).addDays(1)); event1.setSummary(QStringLiteral("Event1 Summary")); event1.setDescription(QStringLiteral("This is a description of the first event")); event1.setLocation(QStringLiteral("the place")); Event *event2 = event1.clone(); QCOMPARE(event1.summary(), event2->summary()); QCOMPARE(event1.dtStart(), event2->dtStart()); QCOMPARE(event1.dtEnd(), event2->dtEnd()); QCOMPARE(event1.description(), event2->description()); QCOMPARE(event1.location(), event2->location()); } void EventTest::testCopy() { QDate dt = QDate::currentDate(); Event event1; event1.setDtStart(QDateTime(dt, {})); event1.setDtEnd(QDateTime(dt, {}).addDays(1)); event1.setSummary(QStringLiteral("Event1 Summary")); event1.setDescription(QStringLiteral("This is a description of the first event")); event1.setLocation(QStringLiteral("the place")); event1.setTransparency(Event::Transparent); Event event2 = event1; QCOMPARE(event1.summary(), event2.summary()); QCOMPARE(event1.dtStart(), event2.dtStart()); QCOMPARE(event1.dtEnd(), event2.dtEnd()); QCOMPARE(event1.description(), event2.description()); QCOMPARE(event1.location(), event2.location()); } void EventTest::testCopyIncidence() { QDate dt = QDate::currentDate(); Todo todo; todo.setDtStart(QDateTime(dt, {})); todo.setSummary(QStringLiteral("Event1 Summary")); todo.setDescription(QStringLiteral("This is a description of the first event")); todo.setLocation(QStringLiteral("the place")); Event event(todo); QCOMPARE(event.uid(), todo.uid()); QCOMPARE(event.dtStart(), todo.dtStart()); QCOMPARE(event.summary(), todo.summary()); QCOMPARE(event.description(), todo.description()); QCOMPARE(event.location(), todo.location()); } void EventTest::testAssign() { QDate dt = QDate::currentDate(); Event event1; event1.setDtStart(QDateTime(dt, {})); event1.setDtEnd(QDateTime(dt, {}).addDays(1)); event1.setSummary(QStringLiteral("Event1 Summary")); event1.setDescription(QStringLiteral("This is a description of the first event")); event1.setLocation(QStringLiteral("the place")); event1.setTransparency(Event::Transparent); Event event2 = event1; QCOMPARE(event1, event2); } void EventTest::testSerializer_data() { - QTest::addColumn("event"); + QTest::addColumn("event"); QDateTime today = QDateTime::currentDateTimeUtc(); QDateTime yesterday = today.addDays(-1); Event::Ptr event1 = Event::Ptr(new Event()); Attendee attendee1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); event1->addAttendee(attendee1); event1->setDtStart(yesterday); event1->setDtEnd(today); Event::Ptr event2 = Event::Ptr(new Event()); Attendee attendee2(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); event2->addAttendee(attendee2); event2->setDtStart(yesterday); event2->setDtEnd(today); event2->setAllDay(true); event2->addComment(QStringLiteral("comment1")); event2->setUrl(QUrl(QStringLiteral("http://someurl"))); event2->setCustomProperty("app", "key", QStringLiteral("value")); // Remaining properties tested in testtodo.cpp QTest::newRow("event") << event1; QTest::newRow("event2") << event2; } void EventTest::testSerializer() { - QFETCH(KCalCore::Event::Ptr, event); - IncidenceBase::Ptr incidenceBase = event.staticCast(); + QFETCH(KCalendarCore::Event::Ptr, event); + IncidenceBase::Ptr incidenceBase = event.staticCast(); QByteArray array; QDataStream stream(&array, QIODevice::WriteOnly); stream << incidenceBase; Event::Ptr event2 = Event::Ptr(new Event()); - IncidenceBase::Ptr incidenceBase2 = event2.staticCast(); + IncidenceBase::Ptr incidenceBase2 = event2.staticCast(); QVERIFY(*event != *event2); QDataStream stream2(&array, QIODevice::ReadOnly); stream2 >> incidenceBase2; QCOMPARE(*event, *event2); } void EventTest::testDurationDtEnd() { const QDate dt = QDate::currentDate(); { Event event; event.setDtStart(QDateTime(dt, {})); event.setDtEnd(QDateTime(dt, {}).addDays(1)); QCOMPARE(event.hasEndDate(), true); QCOMPARE(event.hasDuration(), false); } { Event event; event.setDtStart(QDateTime(dt, {})); event.setDuration(Duration(QDateTime(dt, {}), QDateTime(dt, {}).addDays(1))); QCOMPARE(event.hasDuration(), true); QCOMPARE(event.hasEndDate(), false); } } void EventTest::testDtEndChange() { QDate dt = QDate::currentDate(); Event event1; event1.setDtStart(QDateTime(dt, {})); event1.setDtEnd(QDateTime(dt, {}).addDays(1)); event1.resetDirtyFields(); event1.setDtEnd(QDateTime(dt, {}).addDays(1)); QVERIFY(event1.dirtyFields().empty()); event1.setDtEnd(QDateTime(dt, {}).addDays(2)); QCOMPARE(event1.dirtyFields(), QSet() << IncidenceBase::FieldDtEnd); event1.resetDirtyFields(); event1.setDtEnd(QDateTime()); QCOMPARE(event1.dirtyFields(), QSet() << IncidenceBase::FieldDtEnd); event1.resetDirtyFields(); event1.setDtEnd(QDateTime(dt, {}).addDays(2)); QCOMPARE(event1.dirtyFields(), QSet() << IncidenceBase::FieldDtEnd); } void EventTest::testIsMultiDay_data() { QTest::addColumn("start"); QTest::addColumn("end"); QTest::addColumn("isMultiDay"); QTest::newRow("event0") << QDateTime(QDate(2016, 7, 9), QTime(12, 0, 0)) << QDateTime(QDate(2016, 7, 9), QTime(13, 0, 0)) << false; QTest::newRow("event1") << QDateTime(QDate(2016, 7, 9), QTime(12, 0, 0)) << QDateTime(QDate(2016, 7, 10), QTime(0, 0, 0)) << false; QTest::newRow("event2") << QDateTime(QDate(2016, 7, 9), QTime(12, 0, 0)) << QDateTime(QDate(2016, 7, 10), QTime(12, 0, 0)) << true; QTest::newRow("event3") << QDateTime(QDate(2016, 12, 31), QTime(0, 0, 0)) << QDateTime(QDate(2017, 1, 1), QTime(0, 0, 0)) << false; QTest::newRow("event4") << QDateTime(QDate(2016, 12, 31), QTime(0, 0, 1)) << QDateTime(QDate(2017, 1, 1), QTime(0, 0, 1)) << true; QTest::newRow("event5") << QDateTime(QDate(2016, 12, 31), QTime(12, 0, 0)) << QDateTime(QDate(2017, 1, 1), QTime(12, 0, 0)) << true; QTest::newRow("event6") << QDateTime(QDate(2016, 12, 24), QTime(12, 0, 0)) << QDateTime(QDate(2017, 1, 1), QTime(0, 0, 0)) << true; } void EventTest::testIsMultiDay() { QFETCH(QDateTime, start); QFETCH(QDateTime, end); QFETCH(bool, isMultiDay); Event event; event.setDtStart(start); event.setDtEnd(end); QCOMPARE(event.isMultiDay(), isMultiDay); } diff --git a/autotests/testexception.cpp b/autotests/testexception.cpp index 08616f2b2..e7a31ea61 100644 --- a/autotests/testexception.cpp +++ b/autotests/testexception.cpp @@ -1,34 +1,34 @@ /* This file is part of the kcalcore library. Copyright (C) 2006 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testexception.h" #include "exceptions.h" #include QTEST_MAIN(ExceptionTest) -using namespace KCalCore; +using namespace KCalendarCore; void ExceptionTest::testValidity() { Exception ef(Exception::LoadError); QVERIFY(ef.code() == Exception::LoadError); } diff --git a/autotests/testfb.cpp b/autotests/testfb.cpp index 7427b6fec..a652fd70f 100644 --- a/autotests/testfb.cpp +++ b/autotests/testfb.cpp @@ -1,67 +1,67 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "event.h" #include "icalformat.h" #include "freebusy.h" #include #include -using namespace KCalCore; +using namespace KCalendarCore; int main(int, char **) { const QString fbString = QStringLiteral("BEGIN:VCALENDAR\n" "PRODID:-//proko2//freebusy 1.0//EN\n" "METHOD:PUBLISH\n" "VERSION:2.0\n" "BEGIN:VFREEBUSY\n" "ORGANIZER:MAILTO:test3@kdab.net\n" "X-KDE-Foo:bla\n" "DTSTAMP:20071202T152453Z\n" "URL:http://mail.kdab.net/freebusy/test3%40kdab.net.ifb\n" "DTSTART:19700101T000000Z\n" "DTEND:200700101T000000Z\n" "COMMENT:This is a dummy vfreebusy that indicates an empty calendar\n" "FREEBUSY:19700101T000000Z/19700101T000000Z\n" "FREEBUSY;X-UID=bGlia2NhbC0xODk4MjgxNTcuMTAxMA==;X-\n" " SUMMARY=RW1wbG95ZWUgbWVldGluZw==;X-LOCATION=Um9vb\n" " SAyMTM=:20080131T170000Z/20080131T174500Z\n" "END:VFREEBUSY\n" "END:VCALENDAR\n"); ICalFormat format; FreeBusy::Ptr fb = format.parseFreeBusy(fbString); qDebug() << fb->fullBusyPeriods().count() << " " << fb->dtStart().toString(); const FreeBusyPeriod::List l = fb->fullBusyPeriods(); for (FreeBusyPeriod::List::ConstIterator it = l.begin(); it != l.end(); ++it) { qDebug() << (*it).start().toString() << " " << (*it).end().toString() << "+ " << (*it).summary() << ":" << (*it).location(); } typedef QMap FooMap; const FooMap props = fb->customProperties(); for (FooMap::ConstIterator it = props.begin(); it != props.end(); ++it) { qDebug() << it.key() << ": " << it.value(); } } diff --git a/autotests/testfilestorage.cpp b/autotests/testfilestorage.cpp index 4194bfbac..8b8535e35 100644 --- a/autotests/testfilestorage.cpp +++ b/autotests/testfilestorage.cpp @@ -1,166 +1,166 @@ /* This file is part of the kcalcore library. Copyright (C) 2007 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testfilestorage.h" #include "filestorage.h" #include "memorycalendar.h" #include #include QTEST_MAIN(FileStorageTest) -using namespace KCalCore; +using namespace KCalendarCore; void FileStorageTest::testValidity() { MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage fs(cal, QStringLiteral("fred.ics")); QCOMPARE(fs.fileName(), QStringLiteral("fred.ics")); QCOMPARE(fs.calendar().data(), cal.data()); cal->close(); } void FileStorageTest::testSave() { MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage fs(cal, QStringLiteral("fred.ics")); QDate dt = QDate::currentDate(); Event::Ptr event1 = Event::Ptr(new Event()); event1->setUid(QStringLiteral("1")); event1->setDtStart(QDateTime(dt, {})); event1->setDtEnd(QDateTime(dt, {}).addDays(1)); event1->setSummary(QStringLiteral("Event1 Summary")); event1->setDescription(QStringLiteral("This is a description of the first event")); event1->setLocation(QStringLiteral("the place")); cal->addEvent(event1); Event::Ptr event2 = Event::Ptr(new Event()); event2->setUid(QStringLiteral("2")); event2->setDtStart(QDateTime(dt, {}).addDays(1)); event2->setDtEnd(QDateTime(dt, {}).addDays(2)); event2->setSummary(QStringLiteral("Event2 Summary")); event2->setDescription(QStringLiteral("This is a description of the second event")); event2->setLocation(QStringLiteral("the other place")); cal->addEvent(event2); QVERIFY(fs.open()); QVERIFY(fs.save()); QVERIFY(fs.close()); cal->close(); QFile::remove(QStringLiteral("fred.ics")); } void FileStorageTest::testSaveLoadSave() { MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage fs(cal, QStringLiteral("fred.ics")); QDate dt = QDate::currentDate(); Event::Ptr event1 = Event::Ptr(new Event()); event1->setUid(QStringLiteral("1")); event1->setDtStart(QDateTime(dt, {})); event1->setDtEnd(QDateTime(dt, {}).addDays(1)); event1->setSummary(QStringLiteral("Event1 Summary")); event1->setDescription(QStringLiteral("This is a description of the first event")); event1->setLocation(QStringLiteral("the place")); cal->addEvent(event1); Event::Ptr event2 = Event::Ptr(new Event()); event2->setUid(QStringLiteral("2")); event2->setDtStart(QDateTime(dt, {}).addDays(1)); event2->setDtEnd(QDateTime(dt, {}).addDays(2)); event2->setSummary(QStringLiteral("Event2 Summary")); event2->setDescription(QStringLiteral("This is a description of the second event")); event2->setLocation(QStringLiteral("the other place")); cal->addEvent(event2); QVERIFY(fs.open()); QVERIFY(fs.save()); QVERIFY(fs.close()); QVERIFY(fs.open()); QVERIFY(fs.load()); Event::Ptr e = fs.calendar()->incidence(QStringLiteral("1")).staticCast(); QVERIFY(e != nullptr); QVERIFY(fs.close()); QFile::remove(QStringLiteral("fred.ics")); QVERIFY(fs.open()); QVERIFY(fs.save()); QVERIFY(fs.close()); QFile::remove(QStringLiteral("fred.ics")); } void FileStorageTest::testSpecialChars() { const QDate currentDate = QDate::currentDate(); const QString uid(QStringLiteral("12345")); Event::Ptr event = Event::Ptr(new Event()); event->setUid(uid); event->setDtStart(QDateTime(currentDate, {})); event->setDtEnd(QDateTime(currentDate.addDays(1), {})); const QChar latin1_umlaut[] = { 0xFC, QLatin1Char('\0') }; event->setSummary(QString(latin1_umlaut)); // Save to file: MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage fs(cal, QStringLiteral("bart.ics")); cal->addEvent(event); QVERIFY(fs.open()); QVERIFY(fs.save()); QVERIFY(fs.close()); // Load again: MemoryCalendar::Ptr otherCalendar(new MemoryCalendar(QTimeZone::utc())); FileStorage otherFs(otherCalendar, QStringLiteral("bart.ics")); QVERIFY(otherFs.open()); QVERIFY(otherFs.load()); Event::Ptr otherEvent = otherCalendar->incidence(uid).staticCast(); QVERIFY(otherFs.close()); QVERIFY(otherEvent); // Make sure the retrieved incidence is equal to the original one QVERIFY(otherEvent->summary() == event->summary()); QVERIFY(otherEvent->summary().toLatin1().count() == 1 && strcmp(otherEvent->summary().toLatin1().constData(), QString(latin1_umlaut).toLatin1().constData()) == 0); // Make sure bart.ics is in UTF-8 QFile file(QStringLiteral("bart.ics")); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); const QByteArray bytesFromFile = file.readAll(); const QChar utf_umlaut[] = { 0xC3, 0XBC, QLatin1Char('\0') }; QVERIFY(bytesFromFile.contains(QString(utf_umlaut).toLatin1().constData())); QVERIFY(!bytesFromFile.contains(QString(latin1_umlaut).toLatin1().constData())); file.close(); file.remove(); } diff --git a/autotests/testfreebusy.cpp b/autotests/testfreebusy.cpp index f83d8ec5a..e3049771a 100644 --- a/autotests/testfreebusy.cpp +++ b/autotests/testfreebusy.cpp @@ -1,113 +1,113 @@ /* This file is part of the kcalcore library. Copyright (c) 2007-2008 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testfreebusy.h" #include "freebusy.h" #include QTEST_MAIN(FreeBusyTest) -using namespace KCalCore; +using namespace KCalendarCore; void FreeBusyTest::testValidity() { const QDateTime firstDateTime(QDate(2007, 7, 23), QTime(7, 0, 0), Qt::UTC); FreeBusy fb1(firstDateTime, QDateTime(QDate(2007, 7, 23), QTime(8, 0, 0), Qt::UTC)); QCOMPARE(fb1.dtEnd(), QDateTime(QDate(2007, 7, 23), QTime(8, 0, 0), Qt::UTC)); } void FreeBusyTest::testAddSort() { Period::List periods; const QDateTime firstq1DateTime(QDate(2007, 7, 23), QTime(7, 0, 0), Qt::UTC); Period q1(firstq1DateTime, QDateTime(QDate(2007, 7, 23), QTime(8, 0, 0), Qt::UTC)); periods.append(q1); const QDateTime firstq2DateTime(QDate(2007, 8, 23), QTime(7, 0, 0), Qt::UTC); Period q2(firstq2DateTime, QDateTime(QDate(2007, 8, 23), QTime(8, 0, 0), Qt::UTC)); periods.append(q2); const QDateTime firstq3DateTime(QDate(2007, 9, 23), QTime(7, 0, 0), Qt::UTC); Period q3(firstq3DateTime, QDateTime(QDate(2007, 9, 23), QTime(8, 0, 0), Qt::UTC)); periods.append(q3); FreeBusy fb1; fb1.addPeriods(periods); const QDateTime firstfb1DateTime(QDate(2007, 10, 27), QTime(7, 0, 0), Qt::UTC); fb1.addPeriod(firstfb1DateTime, QDateTime(QDate(2007, 10, 27), QTime(8, 0, 0), Qt::UTC)); const QDateTime secondfb1DateTime(QDate(2007, 8, 27), QTime(7, 0, 0), Qt::UTC); fb1.addPeriod(secondfb1DateTime, QDateTime(QDate(2007, 8, 27), QTime(8, 0, 0), Qt::UTC)); const QDateTime thirdfb1DateTime(QDate(2007, 6, 27), QTime(7, 0, 0), Qt::UTC); fb1.addPeriod(thirdfb1DateTime, QDateTime(QDate(2007, 6, 27), QTime(8, 0, 0), Qt::UTC)); Period::List busyPeriods = fb1.busyPeriods(); QVERIFY(!busyPeriods.isEmpty()); QCOMPARE(busyPeriods.last().end(), QDateTime(QDate(2007, 10, 27), QTime(8, 0, 0), Qt::UTC)); } void FreeBusyTest::testAssign() { const QDateTime firstDateTime(QDate(2007, 7, 23), QTime(7, 0, 0), Qt::UTC); FreeBusy fb1(firstDateTime, QDateTime(QDate(2007, 7, 23), QTime(8, 0, 0), Qt::UTC)); FreeBusy fb2 = fb1; QCOMPARE(fb1, fb2); fb1.setDtStart(firstDateTime.addDays(1)); fb2.setDtStart(firstDateTime.addDays(2)); QVERIFY(!(fb1 == fb2)); FreeBusy fb3 = fb2; QCOMPARE(fb3, fb2); QDateTime dt = fb3.dtEnd(); fb3.setDtEnd(dt.addDays(1)); fb2.setDtEnd(dt.addDays(1)); QCOMPARE(fb2, fb3); } void FreeBusyTest::testDataStream() { const QDateTime firstDateTime(QDate(2007, 7, 23), QTime(7, 0, 0), Qt::UTC); FreeBusy::Ptr fb1(new FreeBusy(firstDateTime, QDateTime(QDate(2007, 7, 23), QTime(8, 0, 0), Qt::UTC))); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << fb1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); FreeBusy::Ptr fb2; in_stream >> fb2; QCOMPARE(fb1->dtEnd(), fb2->dtEnd()); QCOMPARE(fb1->busyPeriods(), fb2->busyPeriods()); // QVERIFY( *fb1 == *fb2 ); } diff --git a/autotests/testfreebusyperiod.cpp b/autotests/testfreebusyperiod.cpp index c319b6fd9..bb58618a9 100644 --- a/autotests/testfreebusyperiod.cpp +++ b/autotests/testfreebusyperiod.cpp @@ -1,117 +1,117 @@ /* This file is part of the kcalcore library. Copyright (C) 2010 Casey Link Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testfreebusyperiod.h" #include "freebusyperiod.h" #include QTEST_MAIN(FreeBusyPeriodTest) -using namespace KCalCore; +using namespace KCalendarCore; void FreeBusyPeriodTest::testValidity() { const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC); FreeBusyPeriod p1(p1DateTime, Duration(60)); QString summary = QStringLiteral("I can haz summary?"); QString location = QStringLiteral("The Moon"); p1.setSummary(summary); p1.setLocation(location); QVERIFY(p1.hasDuration()); QCOMPARE(p1.duration().asSeconds(), 60); QVERIFY(p1.start() == QDateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC)); QCOMPARE(p1.summary(), summary); QCOMPARE(p1.location(), location); } void FreeBusyPeriodTest::testAssign() { const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC); FreeBusyPeriod p1(p1DateTime, Duration(60)); FreeBusyPeriod p2; QString summary = QStringLiteral("I can haz summary?"); QString location = QStringLiteral("The Moon"); p1.setSummary(summary); p1.setLocation(location); p2 = p1; QVERIFY(p2.hasDuration()); QVERIFY(p2.duration().asSeconds() == 60); QVERIFY(p2.start() == QDateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC)); QCOMPARE(p1.summary(), summary); QCOMPARE(p1.location(), location); } void FreeBusyPeriodTest::testDataStreamOut() { const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC); FreeBusyPeriod p1(p1DateTime, Duration(60)); p1.setSummary(QStringLiteral("I can haz summary?")); p1.setLocation(QStringLiteral("The Moon")); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << p1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); Period p2; Period periodParent = static_cast(p1); in_stream >> p2; QVERIFY(periodParent == p2); QString summary; in_stream >> summary; QCOMPARE(summary, p1.summary()); QString location; in_stream >> location; QCOMPARE(location, p1.location()); } void FreeBusyPeriodTest::testDataStreamIn() { const QDateTime p1DateTime(QDate(2006, 8, 30)); const Duration duration(24 * 60 * 60); FreeBusyPeriod p1(p1DateTime, duration); p1.setSummary(QStringLiteral("I can haz summary?")); p1.setLocation(QStringLiteral("The Moon")); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << p1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); FreeBusyPeriod p2; in_stream >> p2; QCOMPARE(p2, p1); } diff --git a/autotests/testicalformat.cpp b/autotests/testicalformat.cpp index b8655d22b..e34b70d9c 100644 --- a/autotests/testicalformat.cpp +++ b/autotests/testicalformat.cpp @@ -1,172 +1,172 @@ /* This file is part of the kcalcore library. Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company Author: Sergio Martins This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testicalformat.h" #include "event.h" #include "icalformat.h" #include "memorycalendar.h" #include #include #include QTEST_MAIN(ICalFormatTest) -using namespace KCalCore; +using namespace KCalendarCore; void ICalFormatTest::testCharsets() { ICalFormat format; const QDate currentDate = QDate::currentDate(); Event::Ptr event = Event::Ptr(new Event()); event->setUid(QStringLiteral("12345")); event->setDtStart(QDateTime(currentDate, {})); event->setDtEnd(QDateTime(currentDate.addDays(1), {})); event->setAllDay(true); // ü const QChar latin1_umlaut[] = { 0xFC, QLatin1Char('\0') }; event->setSummary(QString(latin1_umlaut)); // Test if toString( Incidence ) didn't mess charsets const QString serialized = format.toString(event.staticCast()); const QChar utf_umlaut[] = { 0xC3, 0XBC, QLatin1Char('\0') }; QVERIFY(serialized.toUtf8().contains(QString(utf_umlaut).toLatin1().constData())); QVERIFY(!serialized.toUtf8().contains(QString(latin1_umlaut).toLatin1().constData())); QVERIFY(serialized.toLatin1().contains(QString(latin1_umlaut).toLatin1().constData())); QVERIFY(!serialized.toLatin1().contains(QString(utf_umlaut).toLatin1().constData())); // test fromString( QString ) const QString serializedCalendar = QLatin1String("BEGIN:VCALENDAR\nPRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\nVERSION:2.0\n") +serialized +QLatin1String("\nEND:VCALENDAR"); Incidence::Ptr event2 = format.fromString(serializedCalendar); QVERIFY(event->summary() == event2->summary()); QVERIFY(event2->summary().toUtf8() == QByteArray(QString(utf_umlaut).toLatin1().constData())); // test save() MemoryCalendar::Ptr calendar(new MemoryCalendar(QTimeZone::utc())); calendar->addIncidence(event); QVERIFY(format.save(calendar, QLatin1String("hommer.ics"))); // Make sure hommer.ics is in UTF-8 QFile file(QStringLiteral("hommer.ics")); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); const QByteArray bytesFromFile = file.readAll(); QVERIFY(bytesFromFile.contains(QString(utf_umlaut).toLatin1().constData())); QVERIFY(!bytesFromFile.contains(QString(latin1_umlaut).toLatin1().constData())); file.close(); // Test load: MemoryCalendar::Ptr calendar2(new MemoryCalendar(QTimeZone::utc())); QVERIFY(format.load(calendar2, QLatin1String("hommer.ics"))); QVERIFY(calendar2->incidences().count() == 1); // qDebug() << format.toString( event.staticCast() ); // qDebug() << format.toString( calendar2->incidences().at(0) ); Event::Ptr loadedEvent = calendar2->incidences().at(0).staticCast(); QVERIFY(loadedEvent->summary().toUtf8() == QByteArray(QString(utf_umlaut).toLatin1().constData())); QVERIFY(*loadedEvent == *event); // Test fromRawString() MemoryCalendar::Ptr calendar3(new MemoryCalendar(QTimeZone::utc())); QVERIFY(format.fromRawString(calendar3, bytesFromFile)); QVERIFY(calendar3->incidences().count() == 1); QVERIFY(*calendar3->incidences().at(0) == *event); QFile::remove(QStringLiteral("hommer.ics")); } void ICalFormatTest::testVolatileProperties() { // Volatile properties are not written to the serialized data ICalFormat format; const QDate currentDate = QDate::currentDate(); Event::Ptr event = Event::Ptr(new Event()); event->setUid(QStringLiteral("12345")); event->setDtStart(QDateTime(currentDate, {})); event->setDtEnd(QDateTime(currentDate.addDays(1), {})); event->setAllDay(true); event->setCustomProperty("VOLATILE", "FOO", QStringLiteral("BAR")); QString string = format.toICalString(event); Incidence::Ptr incidence = format.fromString(string); QCOMPARE(incidence->uid(), QStringLiteral("12345")); QVERIFY(incidence->customProperties().isEmpty()); } void ICalFormatTest::testCuType() { ICalFormat format; const QDate currentDate = QDate::currentDate(); Event::Ptr event(new Event()); event->setUid(QStringLiteral("12345")); event->setDtStart(QDateTime(currentDate, {})); event->setDtEnd(QDateTime(currentDate.addDays(1), {})); event->setAllDay(true); Attendee attendee(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); attendee.setCuType(Attendee::Resource); event->addAttendee(attendee); const QString serialized = format.toString(event.staticCast()); // test fromString(QString) const QString serializedCalendar = QLatin1String("BEGIN:VCALENDAR\nPRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\nVERSION:2.0\n") +serialized +QLatin1String("\nEND:VCALENDAR"); Incidence::Ptr event2 = format.fromString(serializedCalendar); QVERIFY(event2->attendeeCount() == 1); Attendee attendee2 = event2->attendees()[0]; QVERIFY(attendee2.cuType() == attendee.cuType()); QVERIFY(attendee2.name() == attendee.name()); QVERIFY(attendee2.email() == attendee.email()); } void ICalFormatTest::testAlarm() { ICalFormat format; Event::Ptr event(new Event); event->setDtStart(QDateTime(QDate(2017, 03, 24))); Alarm::Ptr alarm = event->newAlarm(); alarm->setType(Alarm::Display); alarm->setStartOffset(Duration(0)); const QString serialized = QLatin1String("BEGIN:VCALENDAR\nPRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\nVERSION:2.0\n") + format.toString(event.staticCast()) + QLatin1String("\nEND:VCALENDAR"); Incidence::Ptr event2 = format.fromString(serialized); Alarm::Ptr alarm2 = event2->alarms()[0]; QCOMPARE(*alarm, *alarm2); } diff --git a/autotests/testicaltimezones.cpp b/autotests/testicaltimezones.cpp index b4fed5eb8..6e6db68b8 100644 --- a/autotests/testicaltimezones.cpp +++ b/autotests/testicaltimezones.cpp @@ -1,234 +1,234 @@ /* This file is part of the kcalcore library. Copyright (c) 2005-2007 David Jarvie This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testicaltimezones.h" #include "icaltimezones_p.h" #include #include QTEST_MAIN(ICalTimeZonesTest) extern "C" { #include } -using namespace KCalCore; +using namespace KCalendarCore; static icalcomponent *loadCALENDAR(const char *vcal); // First daylight savings time has an end date, takes a break for a year, // and is then replaced by another static const char *VTZ_Western = "BEGIN:VTIMEZONE\r\n" "TZID:Test-Dummy-Western\r\n" "LAST-MODIFIED:19870101T000000Z\r\n" "TZURL:http://tz.reference.net/dummies/western\r\n" "LOCATION:Zedland/Tryburgh\r\n" "X-LIC-LOCATION:Wyland/Tryburgh\r\n" "BEGIN:STANDARD\r\n" "DTSTART:19671029T020000\r\n" "RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\r\n" "TZOFFSETFROM:-0400\r\n" "TZOFFSETTO:-0500\r\n" "TZNAME:WST\r\n" "END:STANDARD\r\n" "BEGIN:DAYLIGHT\r\n" "DTSTART:19870405T020000\r\n" "RRULE:FREQ=YEARLY;UNTIL=19970406T070000Z;BYDAY=1SU;BYMONTH=4\r\n" "TZOFFSETFROM:-0500\r\n" "TZOFFSETTO:-0400\r\n" "TZNAME:WDT1\r\n" "END:DAYLIGHT\r\n" "BEGIN:DAYLIGHT\r\n" "DTSTART:19990425T020000\r\n" "RDATE;VALUE=DATE-TIME:20000430T020000\r\n" "TZOFFSETFROM:-0500\r\n" "TZOFFSETTO:-0400\r\n" "TZNAME:WDT2\r\n" "END:DAYLIGHT\r\n" "END:VTIMEZONE\r\n"; // Standard time only static const char *VTZ_other = "BEGIN:VTIMEZONE\r\n" "TZID:Test-Dummy-Other\r\n" "TZURL:http://tz.reference.net/dummies/other\r\n" "X-LIC-LOCATION:Wyland/Tryburgh\r\n" "BEGIN:STANDARD\r\n" "DTSTART:19500101T000000\r\n" "RDATE;VALUE=DATE-TIME:19500101T000000\r\n" "TZOFFSETFROM:+0000\r\n" "TZOFFSETTO:+0300\r\n" "TZNAME:OST\r\n" "END:STANDARD\r\n" "END:VTIMEZONE\r\n"; static const char *VTZ_other_DST = "BEGIN:VTIMEZONE\r\n" "TZID:Test-Dummy-Other-DST\r\n" "BEGIN:STANDARD\r\n" "DTSTART:19500101T000000\r\n" "RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11\r\n" "TZOFFSETFROM:+0000\r\n" "TZOFFSETTO:+0300\r\n" "TZNAME:OST\r\n" "END:STANDARD\r\n" "BEGIN:DAYLIGHT\r\n" "DTSTART:19500501T000000\r\n" "RRULE:FREQ=YEARLY;BYDAY=3SU;BYMONTH=5\r\n" "TZOFFSETFROM:+0200\r\n" "TZOFFSETTO:+0500\r\n" "TZNAME:DST\r\n" "END:DAYLIGHT\r\n" "END:VTIMEZONE\r\n"; static const char *VTZ_Prague = "BEGIN:VTIMEZONE\r\n" "TZID:Europe/Prague\r\n" "BEGIN:STANDARD\r\n" "TZNAME:CET\r\n" "TZOFFSETFROM:+0000\r\n" "TZOFFSETTO:+0100\r\n" "DTSTART:19781231T230000\r\n" "RDATE;VALUE=DATE-TIME:19781231T230000\r\n" "END:STANDARD\r\n" "BEGIN:DAYLIGHT\r\n" "TZNAME:CEST\r\n" "TZOFFSETFROM:+0100\r\n" "TZOFFSETTO:+0200\r\n" "DTSTART:19810329T020000\r\n" "RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3\r\n" "END:DAYLIGHT\r\n" "BEGIN:DAYLIGHT\r\n" "TZNAME:CEST\r\n" "TZOFFSETFROM:+0100\r\n" "TZOFFSETTO:+0200\r\n" "DTSTART:19790401T020000\r\n" "RDATE;VALUE=DATE-TIME:19790401T020000\r\n" "RDATE;VALUE=DATE-TIME:19800406T020000\r\n" "END:DAYLIGHT\r\n" "BEGIN:STANDARD\r\n" "TZNAME:CET\r\n" "TZOFFSETFROM:+0200\r\n" "TZOFFSETTO:+0100\r\n" "DTSTART:19971026T030000\r\n" "RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\r\n" "END:STANDARD\r\n" "BEGIN:STANDARD\r\n" "TZNAME:CET\r\n" "TZOFFSETFROM:+0200\r\n" "TZOFFSETTO:+0100\r\n" "DTSTART:19790930T030000\r\n" "RRULE:FREQ=YEARLY;UNTIL=19961027T030000;COUNT=17;BYDAY=-1SU;BYMONTH=9\r\n" "RDATE;VALUE=DATE-TIME:19950924T030000\r\n" "END:STANDARD\r\n" "END:VTIMEZONE\r\n"; // CALENDAR component header and footer static const char *calendarHeader = "BEGIN:VCALENDAR\r\n" "PRODID:-//Libkcal//NONSGML ICalTimeZonesTest//EN\r\n" "VERSION:2.0\r\n"; static const char *calendarFooter = "END:CALENDAR\r\n"; /////////////////////////// // ICalTimeZoneSource tests /////////////////////////// void ICalTimeZonesTest::initTestCase() { qputenv("TZ", "Europe/Zurich"); } void ICalTimeZonesTest::parse_data() { QTest::addColumn("vtimezone"); QTest::addColumn("onDate"); QTest::addColumn("origTz"); QTest::addColumn("expTz"); QTest::newRow("dummy-western") << QByteArray(VTZ_Western) << QDateTime{} << QByteArray("Test-Dummy-Western") << QByteArray("America/Toronto"); QTest::newRow("dummy-other") << QByteArray(VTZ_other) << QDateTime{} << QByteArray("Test-Dummy-Other") << QByteArray("UTC+03:00"); QTest::newRow("dummy-other-dst DST") << QByteArray(VTZ_other_DST) << QDateTime({ 2017, 03, 10 }, {}) << QByteArray("Test-Dummy-Other-DST") << QByteArray("UTC+03:00"); QTest::newRow("dummy-other-dst STD") << QByteArray(VTZ_other_DST) << QDateTime({ 2017, 07, 05 }, {}) << QByteArray("Test-Dummy-Other-DST") << QByteArray("UTC+05:00"); QTest::newRow("dummy-other-dst DST after") << QByteArray(VTZ_other_DST) << QDateTime({ 2017, 12, 24 }, {}) << QByteArray("Test-Dummy-Other-DST") << QByteArray("UTC+03:00"); QTest::newRow("iana") << QByteArray() << QDateTime({ 2017, 9, 14 }, {}) << QByteArray("Europe/Zurich") << QByteArray("Europe/Zurich"); } void ICalTimeZonesTest::parse() { QFETCH(QByteArray, vtimezone); QFETCH(QDateTime, onDate); QFETCH(QByteArray, origTz); QFETCH(QByteArray, expTz); QByteArray calText(calendarHeader); calText += vtimezone; calText += calendarFooter; auto vcalendar = loadCALENDAR(calText.constData()); ICalTimeZoneCache timezones; ICalTimeZoneParser parser(&timezones); parser.parse(vcalendar); icalcomponent_free(vcalendar); QCOMPARE(timezones.tzForTime(onDate, origTz).id(), expTz); } void ICalTimeZonesTest::write() { auto vtimezone = ICalTimeZoneParser::vcaltimezoneFromQTimeZone(QTimeZone("Europe/Prague"), QDateTime::currentDateTimeUtc().addYears(-200)); #if defined(USE_ICAL_3) QCOMPARE(vtimezone, QByteArray(VTZ_Prague).replace(";VALUE=DATE-TIME", "")); //krazy:exclude=doublequote_chars #else QCOMPARE(vtimezone, QByteArray(VTZ_Prague)); #endif } icalcomponent *loadCALENDAR(const char *vcal) { icalcomponent *calendar = icalcomponent_new_from_string(const_cast(vcal)); if (calendar) { if (icalcomponent_isa(calendar) == ICAL_VCALENDAR_COMPONENT) { return calendar; } icalcomponent_free(calendar); } return nullptr; } diff --git a/autotests/testincidence.cpp b/autotests/testincidence.cpp index 4f8ab5a4e..5a6eed1b6 100644 --- a/autotests/testincidence.cpp +++ b/autotests/testincidence.cpp @@ -1,284 +1,284 @@ /* This file is part of the kcalcore library. Copyright (C) 2015 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testincidence.h" #include "event.h" #include "utils.h" #include QTEST_MAIN(IncidenceTest) -Q_DECLARE_METATYPE(KCalCore::Incidence::DateTimeRole) +Q_DECLARE_METATYPE(KCalendarCore::Incidence::DateTimeRole) -using namespace KCalCore; +using namespace KCalendarCore; void IncidenceTest::testDtStartChange() { QDate dt = QDate::currentDate(); QTime t = QTime::currentTime(); Event inc; inc.setDtStart(QDateTime(dt, {})); inc.setAllDay(true); inc.recurrence()->setDaily(1); inc.resetDirtyFields(); inc.setDtStart(QDateTime(dt, {})); QVERIFY(inc.dirtyFields().empty()); inc.setDtStart(QDateTime(dt, t)); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldDtStart << IncidenceBase::FieldRecurrence); QCOMPARE(inc.recurrence()->startDateTime().time(), t); inc.resetDirtyFields(); inc.setDtStart(QDateTime(dt, {}).addDays(1)); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldDtStart << IncidenceBase::FieldRecurrence); QCOMPARE(inc.recurrence()->startDateTime(), QDateTime(dt, {}).addDays(1)); inc.resetDirtyFields(); inc.setDtStart(QDateTime()); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldDtStart << IncidenceBase::FieldRecurrence); QCOMPARE(inc.recurrence()->startDateTime(), QDateTime()); inc.resetDirtyFields(); inc.setDtStart(QDateTime(dt, {}).addDays(1)); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldDtStart << IncidenceBase::FieldRecurrence); QCOMPARE(inc.recurrence()->startDateTime(), QDateTime(dt, {}).addDays(1)); } void IncidenceTest::testSummaryChange() { Event inc; inc.setSummary(QStringLiteral("bla"), false); inc.resetDirtyFields(); inc.setSummary(QStringLiteral("bla"), false); QVERIFY(inc.dirtyFields().empty()); inc.setSummary(QStringLiteral("bla2"), false); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldSummary); inc.resetDirtyFields(); inc.setSummary(QStringLiteral("bla2"), true); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldSummary); } void IncidenceTest::testLocationChange() { Event inc; inc.setLocation(QStringLiteral("here"), false); inc.resetDirtyFields(); inc.setLocation(QStringLiteral("here"), false); QVERIFY(inc.dirtyFields().empty()); inc.setLocation(QStringLiteral("there"), false); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldLocation); inc.resetDirtyFields(); inc.setLocation(QStringLiteral("there"), true); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldLocation); } void IncidenceTest::testRecurrenceTypeChange() { QDate dt = QDate::currentDate(); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setDaily(1); inc.resetDirtyFields(); r->setDaily(1); QVERIFY(inc.dirtyFields().empty()); r->setDaily(2); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); inc.resetDirtyFields(); r->setMonthly(2); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); } void IncidenceTest::testRecurrenceEndTimeChange() { QDate dt = QDate::currentDate(); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setDaily(1); r->setEndDateTime(QDateTime(dt, {}).addDays(1)); inc.resetDirtyFields(); r->setEndDateTime(QDateTime(dt, {}).addDays(1)); QVERIFY(inc.dirtyFields().empty()); r->setEndDateTime(QDateTime(dt, {}).addDays(2)); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); } void IncidenceTest::testRecurrenceEndTimeDurationChange() { QDate dt = QDate::currentDate(); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setDaily(1); inc.resetDirtyFields(); QCOMPARE(r->duration(), -1); QVERIFY(!r->endDateTime().isValid()); r->setDuration(5); QVERIFY(r->endDateTime().isValid()); inc.resetDirtyFields(); // duration is set and set enddate to inValid r->setDuration(5); r->setEndDateTime(QDateTime()); QVERIFY(inc.dirtyFields().empty()); // now set valid enddate -> set duration to 0 by sideeffect r->setEndDateTime(QDateTime(dt, {}).addDays(1)); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); QCOMPARE(r->duration(), 0); QCOMPARE(r->endDateTime(), QDateTime(dt, {}).addDays(1)); // with valid endDate, now setDuration and aftward set invalid endDate r->setEndDateTime(QDateTime(dt, {}).addDays(1)); r->setDuration(5); inc.resetDirtyFields(); r->setEndDateTime(QDateTime()); QVERIFY(inc.dirtyFields().empty()); QCOMPARE(r->endDate(), dt.addDays(4)); QCOMPARE(r->duration(), 5); } void IncidenceTest::testRecurrenceDurationChange() { QDate dt = QDate::currentDate(); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setDuration(1); inc.resetDirtyFields(); r->setDuration(1); QVERIFY(inc.dirtyFields().empty()); r->setDuration(2); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); } void IncidenceTest::testRecurrenceExDatesChange() { QDate dt = QDate::currentDate(); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setExDates(DateList() << dt.addDays(1) << dt.addDays(2)); inc.resetDirtyFields(); r->setExDates(DateList() << dt.addDays(2) << dt.addDays(1)); QVERIFY(inc.dirtyFields().empty()); r->setExDates(DateList() << dt.addDays(1)); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); } void IncidenceTest::testRecurrenceMonthlyDate() { QDate dt = QDate::currentDate(); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setMonthly(1); r->setMonthlyDate(QList() << 1 << 2 << 3); inc.resetDirtyFields(); r->setMonthlyDate(QList() << 3 << 1 << 2); QVERIFY(inc.dirtyFields().empty()); r->setMonthlyDate(QList() << 3 << 1); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); } void IncidenceTest::testRecurrenceMonthlyPos() { QDate dt = QDate::currentDate(); RecurrenceRule::WDayPos pos1(1, 2); RecurrenceRule::WDayPos pos2(3, 4); RecurrenceRule::WDayPos pos3(1, 2); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setYearly(1); r->setMonthlyPos(QList() << pos1 << pos2); inc.resetDirtyFields(); //TODO: test sorting r->setMonthlyPos(QList() << pos1 << pos2); QVERIFY(inc.dirtyFields().empty()); r->setMonthlyPos(QList() << pos3); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); } void IncidenceTest::testRecurrenceYearlyDay() { QDate dt = QDate::currentDate(); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setYearly(1); r->setYearlyDay(QList() << 1 << 2 << 3); inc.resetDirtyFields(); r->setYearlyDay(QList() << 3 << 1 << 2); QVERIFY(inc.dirtyFields().empty()); r->setYearlyDay(QList() << 3 << 1); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); } void IncidenceTest::testRecurrenceYearlyMonth() { QDate dt = QDate::currentDate(); Event inc; inc.setDtStart(QDateTime(dt, {})); - KCalCore::Recurrence *r = inc.recurrence(); + KCalendarCore::Recurrence *r = inc.recurrence(); r->setYearly(1); r->setYearlyMonth(QList() << 1 << 2 << 3); inc.resetDirtyFields(); r->setYearlyMonth(QList() << 3 << 1 << 2); QVERIFY(inc.dirtyFields().empty()); r->setYearlyMonth(QList() << 3 << 1); QCOMPARE(inc.dirtyFields(), QSet() << IncidenceBase::FieldRecurrence); } diff --git a/autotests/testincidencegenerator.h b/autotests/testincidencegenerator.h index 63a8d0a47..72903406a 100644 --- a/autotests/testincidencegenerator.h +++ b/autotests/testincidencegenerator.h @@ -1,53 +1,53 @@ /* This file is part of the kcalcore library. Copyright (C) 2004 Till Adam This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TESTINCIDENCEGENERATOR_H #define TESTINCIDENCEGENERATOR_H #include "../event.h" #include "../todo.h" #include "../journal.h" -using namespace KCalCore; +using namespace KCalendarCore; static Event *makeTestEvent() { Event *event = new Event(); event->setSummary("Test Event"); event->recurrence()->setDaily(2); event->recurrence()->setDuration(3); return event; } static Todo *makeTestTodo() { Todo *todo = new Todo(); todo->setSummary("Test Todo"); todo->setPriority(5); return todo; } static Journal *makeTestJournal() { Journal *journal = new Journal(); journal->setSummary("Test Journal"); return journal; } #endif diff --git a/autotests/testincidencerelation.cpp b/autotests/testincidencerelation.cpp index 8fd74a5aa..416817ffc 100644 --- a/autotests/testincidencerelation.cpp +++ b/autotests/testincidencerelation.cpp @@ -1,62 +1,62 @@ /* This file is part of the kcalcore library. Copyright (c) 2009 Thomas McGuire This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testincidencerelation.h" #include "todo.h" #include QTEST_MAIN(IncidenceRelationTest) -using namespace KCalCore; +using namespace KCalendarCore; void IncidenceRelationTest::testRelations() { // Build the following tree: // todo1 // \- todo2 // \- todo3 // Then make todo3 independent: // todo3 // todo1 // \- todo2 Todo::Ptr todo1 = Todo::Ptr(new Todo()); todo1->setSummary(QStringLiteral("todo")); Todo::Ptr todo2 = Todo::Ptr(new Todo()); todo2->setSummary(QStringLiteral("sub-todo")); Todo::Ptr todo3 = Todo::Ptr(new Todo()); todo3->setSummary(QStringLiteral("sub-sub-todo")); todo3->setRelatedTo(todo2->uid()); todo2->setRelatedTo(todo1->uid()); QCOMPARE(todo3->relatedTo(), todo2->uid()); QCOMPARE(todo2->relatedTo(), todo1->uid()); QCOMPARE(todo1->relatedTo(), QString()); todo3->setRelatedTo(QString()); QCOMPARE(todo3->relatedTo(), QString()); QCOMPARE(todo2->relatedTo(), todo1->uid()); QCOMPARE(todo1->relatedTo(), QString()); } diff --git a/autotests/testjournal.cpp b/autotests/testjournal.cpp index b9c1a9eaa..cbf06c96d 100644 --- a/autotests/testjournal.cpp +++ b/autotests/testjournal.cpp @@ -1,133 +1,133 @@ /* This file is part of the kcalcore library. Copyright (C) 2007-2008 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testjournal.h" #include "journal.h" #include QTEST_MAIN(JournalTest) -using namespace KCalCore; +using namespace KCalendarCore; void JournalTest::testValidity() { QDate dt = QDate::currentDate(); Journal *journal = new Journal(); journal->setDtStart(QDateTime(dt, {})); journal->setAllDay(true); journal->setSummary(QStringLiteral("Journal Summary")); journal->setDescription(QStringLiteral("This is a description of my journal")); journal->setLocation(QStringLiteral("the place")); //KDE5: QVERIFY( journal->typeStr() == QStringLiteral( "journal" ) ); QVERIFY(journal->summary() == QLatin1String("Journal Summary")); QVERIFY(journal->location() == QLatin1String("the place")); } void JournalTest::testCompare() { QDate dt = QDate::currentDate(); Journal journal1; journal1.setDtStart(QDateTime(dt, {})); journal1.setAllDay(true); journal1.setSummary(QStringLiteral("Journal Summary")); journal1.setDescription(QStringLiteral("This is a description of my journal")); journal1.setLocation(QStringLiteral("the place")); Journal journal2; journal2.setDtStart(QDateTime(dt, {}).addDays(1)); journal2.setAllDay(true); journal2.setSummary(QStringLiteral("Journal2 Summary")); journal2.setDescription(QStringLiteral("This is a description of another journal")); journal2.setLocation(QStringLiteral("the other place")); QVERIFY(!(journal1 == journal2)); QVERIFY(journal2.summary() == QLatin1String("Journal2 Summary")); } void JournalTest::testClone() { QDate dt = QDate::currentDate(); Journal journal1; journal1.setDtStart(QDateTime(dt, {})); journal1.setAllDay(true); journal1.setSummary(QStringLiteral("Journal1 Summary")); journal1.setDescription(QStringLiteral("This is a description of the first journal")); journal1.setLocation(QStringLiteral("the place")); Journal *journal2 = journal1.clone(); QVERIFY(journal1.summary() == journal2->summary()); QVERIFY(journal1.dtStart() == journal2->dtStart()); QVERIFY(journal1.description() == journal2->description()); QVERIFY(journal1.location() == journal2->location()); } void JournalTest::testRich() { QDate dt = QDate::currentDate(); Journal journal1; journal1.setDtStart(QDateTime(dt, {})); journal1.setAllDay(true); journal1.setSummary(QStringLiteral("Journal1 Summary"), true); journal1.setDescription(QStringLiteral("This is a of the first journal"), true); journal1.setLocation(QStringLiteral("

the place

"), true); QVERIFY(journal1.summaryIsRich()); QVERIFY(journal1.descriptionIsRich()); QVERIFY(journal1.locationIsRich()); } void JournalTest::testAssign() { QDate dt = QDate::currentDate(); Journal journal1; journal1.setDtStart(QDateTime(dt, {})); journal1.setAllDay(true); journal1.setSummary(QStringLiteral("Journal1 Summary")); journal1.setDescription(QStringLiteral("This is a description of the first journal")); journal1.setLocation(QStringLiteral("the place")); Journal journal2 = journal1; QVERIFY(journal1 == journal2); } void JournalTest::testSerializer_data() { - QTest::addColumn("journal"); + QTest::addColumn("journal"); Journal::Ptr journal1 = Journal::Ptr(new Journal()); QTest::newRow("journal") << journal1; } void JournalTest::testSerializer() { - QFETCH(KCalCore::Journal::Ptr, journal); - IncidenceBase::Ptr incidenceBase = journal.staticCast(); + QFETCH(KCalendarCore::Journal::Ptr, journal); + IncidenceBase::Ptr incidenceBase = journal.staticCast(); QByteArray array; QDataStream stream(&array, QIODevice::WriteOnly); stream << incidenceBase; Journal::Ptr journal2 = Journal::Ptr(new Journal()); - IncidenceBase::Ptr incidenceBase2 = journal2.staticCast(); + IncidenceBase::Ptr incidenceBase2 = journal2.staticCast(); QVERIFY(*journal != *journal2); QDataStream stream2(&array, QIODevice::ReadOnly); stream2 >> incidenceBase2; QVERIFY(*journal == *journal2); } diff --git a/autotests/testmemorycalendar.cpp b/autotests/testmemorycalendar.cpp index 1469aff28..122ca1506 100644 --- a/autotests/testmemorycalendar.cpp +++ b/autotests/testmemorycalendar.cpp @@ -1,275 +1,275 @@ /* This file is part of the kcalcore library. Copyright (C) 2006-2007 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testmemorycalendar.h" #include "filestorage.h" #include "memorycalendar.h" #include "utils.h" #include #include #include QTEST_MAIN(MemoryCalendarTest) -using namespace KCalCore; +using namespace KCalendarCore; void MemoryCalendarTest::testValidity() { MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); cal->setProductId(QStringLiteral("fredware calendar")); QVERIFY(cal->productId() == QLatin1String("fredware calendar")); QVERIFY(cal->timeZoneId() == QByteArrayLiteral("UTC")); QVERIFY(cal->timeZone() == QTimeZone::utc()); cal->close(); } void MemoryCalendarTest::testEvents() { MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); cal->setProductId(QStringLiteral("fredware calendar")); QDate dt = QDate::currentDate(); Event::Ptr event1 = Event::Ptr(new Event()); event1->setUid(QStringLiteral("1")); event1->setDtStart(QDateTime(dt, {})); event1->setDtEnd(QDateTime(dt, {}).addDays(1)); event1->setAllDay(true); event1->setSummary(QStringLiteral("Event1 Summary")); event1->setDescription(QStringLiteral("This is a description of the first event")); event1->setLocation(QStringLiteral("the place")); Event::Ptr event2 = Event::Ptr(new Event()); event2->setUid(QStringLiteral("2")); event2->setDtStart(QDateTime(dt, {}).addDays(1)); event2->setDtEnd(QDateTime(dt, {}).addDays(2)); event2->setAllDay(true); event2->setSummary(QStringLiteral("Event2 Summary")); event2->setDescription(QStringLiteral("This is a description of the second event")); event2->setLocation(QStringLiteral("the other place")); QVERIFY(cal->addEvent(event1)); QVERIFY(cal->addEvent(event2)); FileStorage store(cal, QStringLiteral("foo.ics")); QVERIFY(store.save()); cal->close(); QFile::remove(QStringLiteral("foo.ics")); } void MemoryCalendarTest::testIncidences() { MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); cal->setProductId(QStringLiteral("fredware calendar")); QDate dt = QDate::currentDate(); Event::Ptr event1 = Event::Ptr(new Event()); event1->setUid(QStringLiteral("1")); event1->setDtStart(QDateTime(dt, {})); event1->setDtEnd(QDateTime(dt, {}).addDays(1)); event1->setAllDay(true); event1->setSummary(QStringLiteral("Event1 Summary")); event1->setDescription(QStringLiteral("This is a description of the first event")); event1->setLocation(QStringLiteral("the place")); Event::Ptr event2 = Event::Ptr(new Event()); event2->setUid(QStringLiteral("2")); event2->setDtStart(QDateTime(dt, {}).addDays(1)); event2->setDtEnd(QDateTime(dt, {}).addDays(2)); event2->setAllDay(true); event2->setSummary(QStringLiteral("Event2 Summary")); event2->setDescription(QStringLiteral("This is a description of the second event")); event2->setLocation(QStringLiteral("the other place")); QVERIFY(cal->addEvent(event1)); QVERIFY(cal->addEvent(event2)); Todo::Ptr todo1 = Todo::Ptr(new Todo()); todo1->setUid(QStringLiteral("3")); todo1->setDtStart(QDateTime(dt, {}).addDays(1)); todo1->setDtDue(QDateTime(dt, {}).addDays(2)); todo1->setAllDay(true); todo1->setSummary(QStringLiteral("Todo1 Summary")); todo1->setDescription(QStringLiteral("This is a description of a todo")); todo1->setLocation(QStringLiteral("this place")); Todo::Ptr todo2 = Todo::Ptr(new Todo()); todo2->setUid(QStringLiteral("4")); todo2->setDtStart(QDateTime(dt, {}).addDays(1)); todo2->setAllDay(true); todo2->setSummary(QStringLiteral("

Todo2 Summary

"), true); todo2->setDescription(QStringLiteral("This is a description of a todo")); todo2->setLocation(QStringLiteral("this place"), true); QVERIFY(cal->addTodo(todo1)); QVERIFY(cal->addTodo(todo2)); FileStorage store(cal, QStringLiteral("foo.ics")); QVERIFY(store.save()); cal->close(); QVERIFY(store.load()); Todo::Ptr todo = cal->incidence(QStringLiteral("4")).staticCast(); QVERIFY(todo->uid() == QLatin1String("4")); QVERIFY(todo->summaryIsRich()); QVERIFY(todo->locationIsRich()); cal->close(); QFile::remove(QStringLiteral("foo.ics")); } void MemoryCalendarTest::testRelationsCrash() { // Before, there was a crash that occurred only when reloading a calendar in which // the incidences had special relations. // This test tests that scenario, and will crash if it fails. MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage store1(cal, QLatin1Literal(ICALTESTDATADIR) + QLatin1String("test_relations.ics")); QVERIFY(store1.load()); const Todo::List oldTodos = cal->todos(); qDebug() << "Loaded " << oldTodos.count() << " todos into oldTodos."; FileStorage store2(cal, QLatin1String(ICALTESTDATADIR) + QLatin1String("test_relations.ics")); QVERIFY(store2.load()); const Todo::List newTodos = cal->todos(); qDebug() << "Loaded " << newTodos.count() << " into newTodos."; // We can saftely access the old deleted todos here, since they are not really deleted // and are still kept in a map of deleted items somewhere. // // Here we make sure that non of the old items have connections to the new items, and // the other way around. // This doesn't makes sense so i commented it. when you load a calendar the second time // it reuses what it can, so oldTodo == newTodo /* foreach (const Todo::Ptr &oldTodo, oldTodos ) { foreach (const Todo::Ptr &newTodo, newTodos ) { QVERIFY( oldTodo != newTodo ); // Make sure that none of the new todos point to an old, deleted todo QVERIFY( newTodo->relatedTo() != oldTodo ); QVERIFY( !newTodo->relations().contains( oldTodo ) ); // Make sure that none of the old todos point to a new todo QVERIFY( oldTodo->relatedTo() != newTodo ); QVERIFY( !oldTodo->relations().contains( newTodo ) ); } } */ cal->close(); } void MemoryCalendarTest::testRecurrenceExceptions() { MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); cal->setProductId(QStringLiteral("fredware calendar")); QDate dt = QDate::currentDate(); QDateTime start(dt, {}); Event::Ptr event1 = Event::Ptr(new Event()); event1->setUid(QStringLiteral("1")); event1->setDtStart(start); event1->setDtEnd(start.addDays(1)); event1->setSummary(QStringLiteral("Event1 Summary")); event1->recurrence()->setDaily(1); event1->recurrence()->setDuration(3); QVERIFY(cal->addEvent(event1)); const QDateTime recurrenceId = event1->dtStart().addDays(1); Event::Ptr exception1 = cal->createException(event1, recurrenceId).staticCast(); QCOMPARE(exception1->recurrenceId(), recurrenceId); QCOMPARE(exception1->uid(), event1->uid()); exception1->setSummary(QStringLiteral("exception")); QVERIFY(exception1); QVERIFY(cal->addEvent(exception1)); QCOMPARE(cal->event(event1->uid()), event1); QCOMPARE(cal->event(event1->uid(), recurrenceId), exception1); const Event::List incidences = cal->rawEvents(start.date(), start.addDays(3).date(), start.timeZone()); //Contains incidence and exception QCOMPARE(incidences.size(), 2); //Returns only exceptions for an event const Event::List exceptions = cal->eventInstances(event1); QCOMPARE(exceptions.size(), 1); QCOMPARE(exceptions.first()->uid(), event1->uid()); QCOMPARE(exceptions.first()->summary(), exception1->summary()); } void MemoryCalendarTest::testChangeRecurId() { // When we change the recurring id, internal hashtables should be updated. MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); QDateTime start(QDate::currentDate(), {}); // Add main event Event::Ptr event1 = Event::Ptr(new Event()); const QString uid = QStringLiteral("1"); event1->setUid(uid); event1->setDtStart(start); event1->setDtEnd(start.addDays(1)); event1->setAllDay(true); event1->setSummary(QStringLiteral("Event1 Summary")); event1->recurrence()->setDaily(1); event1->recurrence()->setDuration(3); QVERIFY(cal->addEvent(event1)); // Add exception event: const QDateTime recurrenceId = event1->dtStart().addDays(1); Event::Ptr exception1 = cal->createException(event1, recurrenceId).staticCast(); QCOMPARE(exception1->recurrenceId(), recurrenceId); QCOMPARE(exception1->uid(), event1->uid()); exception1->setSummary(QStringLiteral("exception")); QVERIFY(exception1); QVERIFY(cal->addEvent(exception1)); const QString oldIdentifier = exception1->instanceIdentifier(); Incidence::Ptr foo = cal->instance(oldIdentifier); QVERIFY(foo && foo->hasRecurrenceId()); // Now change the recurring id! exception1->setRecurrenceId(start.addDays(2)); const QString newIdentifier = exception1->instanceIdentifier(); QVERIFY(oldIdentifier != newIdentifier); foo = cal->instance(oldIdentifier); QVERIFY(!foo); foo = cal->instance(newIdentifier); QVERIFY(foo); // Test hashing Incidence::List incidences = cal->incidences(); QVERIFY(incidences.count() == 2); QDateTime newRecId = start.addDays(2); Incidence::Ptr main = cal->incidence(uid); Incidence::Ptr exception = cal->incidence(uid, newRecId); Incidence::Ptr noException = cal->incidence(uid, recurrenceId); QVERIFY(!noException); QVERIFY(main); QVERIFY(exception); QVERIFY(exception->recurrenceId() == newRecId); QVERIFY(exception->summary() == QLatin1String("exception")); QVERIFY(main->summary() == event1->summary()); } diff --git a/autotests/testoccurrenceiterator.cpp b/autotests/testoccurrenceiterator.cpp index 417cbd097..85bbb7e68 100644 --- a/autotests/testoccurrenceiterator.cpp +++ b/autotests/testoccurrenceiterator.cpp @@ -1,298 +1,298 @@ /* * Copyright (C) 2012 Christian Mollekopf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "testoccurrenceiterator.h" #include "occurrenceiterator.h" #include "memorycalendar.h" #include "calfilter.h" #include #include #include QTEST_MAIN(TestOccurrenceIterator) void TestOccurrenceIterator::testIterationWithExceptions() { - KCalCore::MemoryCalendar calendar(QTimeZone::utc()); + KCalendarCore::MemoryCalendar calendar(QTimeZone::utc()); QDateTime start(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); QDateTime end(QDate(2013, 03, 10), QTime(11, 0, 0), Qt::UTC); QDateTime recurrenceId(QDate(2013, 03, 11), QTime(10, 0, 0), Qt::UTC); QDateTime exceptionStart(QDate(2013, 03, 11), QTime(12, 0, 0), Qt::UTC); QDateTime exceptionEnd(QDate(2013, 03, 11), QTime(13, 0, 0), Qt::UTC); QDateTime actualEnd(QDate(2013, 03, 12), QTime(11, 0, 0), Qt::UTC); - KCalCore::Event::Ptr event1(new KCalCore::Event()); + KCalendarCore::Event::Ptr event1(new KCalendarCore::Event()); event1->setUid(QStringLiteral("event1")); event1->setSummary(QStringLiteral("event1")); event1->setDtStart(start); event1->setDtEnd(end); event1->recurrence()->setDaily(1); calendar.addEvent(event1); - KCalCore::Event::Ptr exception(new KCalCore::Event()); + KCalendarCore::Event::Ptr exception(new KCalendarCore::Event()); exception->setUid(event1->uid()); exception->setSummary(QStringLiteral("exception")); exception->setRecurrenceId(recurrenceId); exception->setDtStart(exceptionStart); exception->setDtEnd(exceptionEnd); calendar.addEvent(exception); int occurrence = 0; - KCalCore::OccurrenceIterator rIt(calendar, start, actualEnd); + KCalendarCore::OccurrenceIterator rIt(calendar, start, actualEnd); while (rIt.hasNext()) { rIt.next(); occurrence++; if (occurrence == 1) { QCOMPARE(rIt.occurrenceStartDate(), start); QCOMPARE(rIt.incidence()->summary(), event1->summary()); } if (occurrence == 2) { QCOMPARE(rIt.occurrenceStartDate(), exceptionStart); QCOMPARE(rIt.incidence()->summary(), exception->summary()); } if (occurrence == 3) { QCOMPARE(rIt.occurrenceStartDate(), start.addDays(2)); QCOMPARE(rIt.incidence()->summary(), event1->summary()); } // qDebug() << occurrence; // qDebug() << "occurrence: " << rIt.occurrenceStartDate().toString(); // qDebug() << "uid: " << rIt.incidence()->uid(); // qDebug() << "summary: " << rIt.incidence()->summary(); // qDebug() << "start: " << rIt.incidence()->dtStart().toString(); // qDebug(); } QCOMPARE(occurrence, 3); } void TestOccurrenceIterator::testEventsAndTodos() { - KCalCore::MemoryCalendar calendar(QTimeZone::utc()); + KCalendarCore::MemoryCalendar calendar(QTimeZone::utc()); QDateTime start(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); QDateTime actualEnd(QDate(2013, 03, 13), QTime(11, 0, 0), Qt::UTC); - KCalCore::Event::Ptr event(new KCalCore::Event()); + KCalendarCore::Event::Ptr event(new KCalendarCore::Event()); event->setUid(QStringLiteral("event")); event->setDtStart(start); event->recurrence()->setDaily(1); event->recurrence()->setDuration(2); calendar.addEvent(event); - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtStart(start); todo->recurrence()->setDaily(1); todo->recurrence()->setDuration(2); calendar.addTodo(todo); - KCalCore::OccurrenceIterator rIt(calendar, start, actualEnd); + KCalendarCore::OccurrenceIterator rIt(calendar, start, actualEnd); QList expectedTodoOccurrences; expectedTodoOccurrences << start << start.addDays(1); QList expectedEventOccurrences; expectedEventOccurrences << start << start.addDays(1); while (rIt.hasNext()) { rIt.next(); qDebug() << rIt.occurrenceStartDate().toString(); - if (rIt.incidence()->type() == KCalCore::Incidence::TypeTodo) { + if (rIt.incidence()->type() == KCalendarCore::Incidence::TypeTodo) { QCOMPARE(expectedTodoOccurrences.removeAll(rIt.occurrenceStartDate()), 1); } else { QCOMPARE(expectedEventOccurrences.removeAll(rIt.occurrenceStartDate()), 1); } } QCOMPARE(expectedTodoOccurrences.size(), 0); QCOMPARE(expectedEventOccurrences.size(), 0); } void TestOccurrenceIterator::testFilterCompletedTodos() { - KCalCore::MemoryCalendar calendar(QTimeZone::utc()); - calendar.filter()->setCriteria(KCalCore::CalFilter::HideCompletedTodos); + KCalendarCore::MemoryCalendar calendar(QTimeZone::utc()); + calendar.filter()->setCriteria(KCalendarCore::CalFilter::HideCompletedTodos); QDateTime start(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); QDateTime actualEnd(QDate(2013, 03, 13), QTime(11, 0, 0), Qt::UTC); - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtDue(start); todo->setDtStart(start); todo->recurrence()->setDaily(1); todo->recurrence()->setDuration(2); // Yes, recurring todos are weird... setting this says that all occurrences // until this one have been completed, and thus should be skipped. // that's what kontact did, so it's what we test now. todo->setDtRecurrence(start.addDays(2)); calendar.addTodo(todo); - KCalCore::OccurrenceIterator rIt(calendar, start, actualEnd); + KCalendarCore::OccurrenceIterator rIt(calendar, start, actualEnd); QVERIFY(!rIt.hasNext()); } void TestOccurrenceIterator::testAllDayEvents() { - KCalCore::MemoryCalendar calendar(QTimeZone::utc()); + KCalendarCore::MemoryCalendar calendar(QTimeZone::utc()); QDateTime start(QDate(2013, 03, 10), QTime(), Qt::UTC); QDateTime actualEnd(QDate(2013, 03, 13), QTime(11, 0, 0), Qt::UTC); - KCalCore::Event::Ptr event(new KCalCore::Event()); + KCalendarCore::Event::Ptr event(new KCalendarCore::Event()); event->setUid(QStringLiteral("event")); event->setDtStart(start); event->setAllDay(true); event->recurrence()->setDaily(1); event->recurrence()->setDuration(2); calendar.addEvent(event); - KCalCore::OccurrenceIterator rIt(calendar, start, actualEnd); + KCalendarCore::OccurrenceIterator rIt(calendar, start, actualEnd); QList expectedEventOccurrences; expectedEventOccurrences << start << start.addDays(1); while (rIt.hasNext()) { rIt.next(); qDebug() << rIt.occurrenceStartDate().toString(); QCOMPARE(expectedEventOccurrences.removeAll(rIt.occurrenceStartDate()), 1); } QCOMPARE(expectedEventOccurrences.size(), 0); } void TestOccurrenceIterator::testWithExceptionThisAndFuture() { - KCalCore::MemoryCalendar calendar(QTimeZone::utc()); + KCalendarCore::MemoryCalendar calendar(QTimeZone::utc()); QDateTime start(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); QDateTime end(QDate(2013, 03, 10), QTime(11, 0, 0), Qt::UTC); QDateTime recurrenceId1(QDate(2013, 03, 11), QTime(10, 0, 0), Qt::UTC); QDateTime exceptionStart1(QDate(2013, 03, 11), QTime(12, 0, 0), Qt::UTC); QDateTime exceptionEnd1(QDate(2013, 03, 11), QTime(13, 0, 0), Qt::UTC); QDateTime recurrenceId2(QDate(2013, 03, 13), QTime(10, 0, 0), Qt::UTC); QDateTime exceptionStart2(QDate(2013, 03, 13), QTime(14, 0, 0), Qt::UTC); QDateTime exceptionEnd2(QDate(2013, 03, 13), QTime(15, 0, 0), Qt::UTC); QDateTime actualEnd(QDate(2013, 03, 14), QTime(11, 0, 0), Qt::UTC); - KCalCore::Event::Ptr event1(new KCalCore::Event()); + KCalendarCore::Event::Ptr event1(new KCalendarCore::Event()); event1->setUid(QStringLiteral("event1")); event1->setSummary(QStringLiteral("event1")); event1->setDtStart(start); event1->setDtEnd(end); event1->recurrence()->setDaily(1); calendar.addEvent(event1); - KCalCore::Event::Ptr exception1(new KCalCore::Event()); + KCalendarCore::Event::Ptr exception1(new KCalendarCore::Event()); exception1->setUid(event1->uid()); exception1->setSummary(QStringLiteral("exception1")); exception1->setRecurrenceId(recurrenceId1); exception1->setThisAndFuture(true); exception1->setDtStart(exceptionStart1); exception1->setDtEnd(exceptionEnd1); calendar.addEvent(exception1); - KCalCore::Event::Ptr exception2(new KCalCore::Event()); + KCalendarCore::Event::Ptr exception2(new KCalendarCore::Event()); exception2->setUid(event1->uid()); exception2->setSummary(QStringLiteral("exception2")); exception2->setRecurrenceId(recurrenceId2); exception2->setDtStart(exceptionStart2); exception2->setDtEnd(exceptionEnd2); calendar.addEvent(exception2); int occurrence = 0; - KCalCore::OccurrenceIterator rIt(calendar, start, actualEnd); + KCalendarCore::OccurrenceIterator rIt(calendar, start, actualEnd); while (rIt.hasNext()) { rIt.next(); occurrence++; // qDebug() << occurrence; // qDebug() << "occurrence: " << rIt.occurrenceStartDate().toString(); // qDebug() << "uid: " << rIt.incidence()->uid(); // qDebug() << "summary: " << rIt.incidence()->summary(); // qDebug() << "start: " << rIt.incidence()->dtStart().toString(); // qDebug(); QCOMPARE(rIt.recurrenceId(), start.addDays(occurrence - 1)); if (occurrence == 1) { QCOMPARE(rIt.occurrenceStartDate(), start); QCOMPARE(rIt.incidence()->summary(), event1->summary()); } if (occurrence == 2) { QCOMPARE(rIt.occurrenceStartDate(), exceptionStart1); QCOMPARE(rIt.incidence()->summary(), exception1->summary()); } if (occurrence == 3) { QCOMPARE(rIt.occurrenceStartDate(), exceptionStart1.addDays(1)); QCOMPARE(rIt.incidence()->summary(), exception1->summary()); } if (occurrence == 4) { QCOMPARE(rIt.occurrenceStartDate(), exceptionStart2); QCOMPARE(rIt.incidence()->summary(), exception2->summary()); } if (occurrence == 5) { QCOMPARE(rIt.occurrenceStartDate(), exceptionStart1.addDays(3)); QCOMPARE(rIt.incidence()->summary(), exception1->summary()); } } QCOMPARE(occurrence, 5); } void TestOccurrenceIterator::testSubDailyRecurrences() { - KCalCore::MemoryCalendar calendar(QTimeZone::utc()); + KCalendarCore::MemoryCalendar calendar(QTimeZone::utc()); QDateTime start(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); QDateTime actualEnd(QDate(2013, 03, 10), QTime(13, 0, 0), Qt::UTC); - KCalCore::Event::Ptr event(new KCalCore::Event()); + KCalendarCore::Event::Ptr event(new KCalendarCore::Event()); event->setUid(QStringLiteral("event")); event->setDtStart(start); event->recurrence()->setHourly(1); event->recurrence()->setDuration(2); calendar.addEvent(event); - KCalCore::OccurrenceIterator rIt(calendar, start, actualEnd); + KCalendarCore::OccurrenceIterator rIt(calendar, start, actualEnd); QList expectedEventOccurrences; expectedEventOccurrences << start << start.addSecs(60 * 60); while (rIt.hasNext()) { rIt.next(); qDebug() << rIt.occurrenceStartDate().toString(); QCOMPARE(expectedEventOccurrences.removeAll(rIt.occurrenceStartDate()), 1); } QCOMPARE(expectedEventOccurrences.size(), 0); } void TestOccurrenceIterator::testJournals() { - KCalCore::MemoryCalendar calendar(QTimeZone::utc()); + KCalendarCore::MemoryCalendar calendar(QTimeZone::utc()); const QDateTime today = QDateTime::currentDateTimeUtc(); const QDateTime yesterday = today.addDays(-1); const QDateTime tomorrow = today.addDays(1); - KCalCore::Journal::Ptr journal(new KCalCore::Journal()); + KCalendarCore::Journal::Ptr journal(new KCalendarCore::Journal()); journal->setUid(QStringLiteral("journal")); journal->setDtStart(today); calendar.addJournal(journal); - KCalCore::OccurrenceIterator rIt(calendar, yesterday, tomorrow); + KCalendarCore::OccurrenceIterator rIt(calendar, yesterday, tomorrow); QVERIFY(rIt.hasNext()); rIt.next(); QCOMPARE(rIt.occurrenceStartDate(), today); QVERIFY(!rIt.hasNext()); - KCalCore::OccurrenceIterator rIt2(calendar, tomorrow, tomorrow.addDays(1)); + KCalendarCore::OccurrenceIterator rIt2(calendar, tomorrow, tomorrow.addDays(1)); QVERIFY(!rIt2.hasNext()); } diff --git a/autotests/testperiod.cpp b/autotests/testperiod.cpp index 609186ce7..36e7825af 100644 --- a/autotests/testperiod.cpp +++ b/autotests/testperiod.cpp @@ -1,130 +1,130 @@ /* This file is part of the kcalcore library. Copyright (c) 2006 Narayan Newton Copyright (C) 2010 Casey Link Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testperiod.h" #include "period.h" #include "utils.h" #include QTEST_MAIN(PeriodTest) -using namespace KCalCore; +using namespace KCalendarCore; void PeriodTest::testValidity() { const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC); Period p1(p1DateTime, Duration(60)); Period p2; QVERIFY(p1.hasDuration()); QCOMPARE(p1.duration().asSeconds(), 60); QVERIFY(p1.start() == QDateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC)); p2 = p1; QVERIFY(p2.hasDuration()); QVERIFY(p2.duration().asSeconds() == 60); QVERIFY(p2.start() == QDateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC)); const QDateTime p3DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC); Period p3(p3DateTime, Duration(24 * 60 * 60)); QVERIFY(p3.hasDuration()); QVERIFY(p3.duration().asSeconds() == 24 * 60 * 60); QVERIFY(p3.start() == QDateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC)); } void PeriodTest::testCompare() { const QDateTime p1DateTime(QDate(2006, 8, 30), {}); Period p1(p1DateTime, Duration(24 * 60 * 60)); const QDateTime p2DateTime(QDate(2006, 8, 29), {}); Period p2(p2DateTime, Duration(23 * 60 * 60)); const QDateTime p3DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC); Period p3(p3DateTime, Duration(24 * 60 * 60)); Period p1copy(p1); // test copy constructor Period p1assign = p1; // test operator= Period p3copy(p3); Period p3assign = p3; QVERIFY(p2 < p1); QVERIFY(!(p1 == p2)); QVERIFY(p1copy == p1); QVERIFY(p1assign == p1); QVERIFY(p3copy == p3); QVERIFY(p3assign == p3); } void PeriodTest::testDataStreamOut() { const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC); const Duration duration(24 * 60 * 60); Period p1(p1DateTime, duration); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << p1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); QDateTime begin; deserializeKDateTimeAsQDateTime(in_stream, begin); // There is no way to serialize KDateTime as of KDE4.5 // and the to/fromString methods do not perform a perfect reconstruction // of a datetime QVERIFY(begin == p1.start()); QDateTime end; deserializeKDateTimeAsQDateTime(in_stream, end); QVERIFY(end == p1.end()); bool dailyduration; in_stream >> dailyduration; QVERIFY(dailyduration == duration.isDaily()); bool hasduration; in_stream >> hasduration; QVERIFY(hasduration == p1.hasDuration()); } void PeriodTest::testDataStreamIn() { const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC); const Duration duration(24 * 60 * 60); Period p1(p1DateTime, duration); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << p1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); Period p2; in_stream >> p2; QVERIFY(p1 == p2); } diff --git a/autotests/testperson.cpp b/autotests/testperson.cpp index c93d16515..3b69b54e0 100644 --- a/autotests/testperson.cpp +++ b/autotests/testperson.cpp @@ -1,111 +1,111 @@ /* This file is part of the kcalcore library. Copyright (C) 2006-2009 Allen Winter Copyright (C) 2010 Casey Link Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testperson.h" #include "person.h" #include #include QTEST_MAIN(PersonTest) -using namespace KCalCore; +using namespace KCalendarCore; void PersonTest::testValidity() { Person person(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); QVERIFY(person.name() == QLatin1String("fred")); } void PersonTest::testCompare() { Person person1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); Person person2(QStringLiteral("wilma"), QStringLiteral("wilma@flintstone.com")); Person person3 = Person::fromFullName(QStringLiteral("fred ")); Person person1copy(person1); // test copy constructor Person person1assign = person1; // test operator= QVERIFY(!(person1 == person2)); QVERIFY(person1 == person3); QVERIFY(person1 == person1copy); QVERIFY(person1 == person1assign); QVERIFY(person1.name() == QLatin1String("fred")); QVERIFY(person2.email() == QLatin1String("wilma@flintstone.com")); QVERIFY(person3.name() == QLatin1String("fred")); QVERIFY(person3.email() == QLatin1String("fred@flintstone.com")); } void PersonTest::testStringify() { Person person1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); Person person2(QStringLiteral("wilma"), QStringLiteral("wilma@flintstone.com")); QVERIFY(person1.fullName() == QLatin1String("fred ")); QVERIFY(person2.fullName() == QLatin1String("wilma ")); person1.setName(QLatin1String("")); QVERIFY(person1.fullName() == QLatin1String("fred@flintstone.com")); person1.setEmail(QString()); QVERIFY(person1.fullName().isEmpty()); } void PersonTest::testDataStreamIn() { Person person1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << person1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); QString name, email; int count; in_stream >> name; QVERIFY(name == QLatin1String("fred")); in_stream >> email; QVERIFY(email == QLatin1String("fred@flintstone.com")); in_stream >> count; QCOMPARE(count, 0); } void PersonTest::testDataStreamOut() { Person person1(QStringLiteral("fred"), QStringLiteral("fred@flintstone.com")); QByteArray byteArray; QDataStream out_stream(&byteArray, QIODevice::WriteOnly); out_stream << person1; QDataStream in_stream(&byteArray, QIODevice::ReadOnly); Person person2; in_stream >> person2; QVERIFY(person2.name() == person1.name()); QVERIFY(person2.email() == person1.email()); } diff --git a/autotests/testreadrecurrenceid.cpp b/autotests/testreadrecurrenceid.cpp index 8710f75b1..b0755270f 100644 --- a/autotests/testreadrecurrenceid.cpp +++ b/autotests/testreadrecurrenceid.cpp @@ -1,87 +1,87 @@ /* * Copyright (C) 2012 Christian Mollekopf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "testreadrecurrenceid.h" #include "memorycalendar.h" #include "icalformat.h" #include "exceptions.h" #include #include #include QTEST_MAIN(TestReadRecurrenceId) void TestReadRecurrenceId::testReadSingleException() { - KCalCore::ICalFormat format; + KCalendarCore::ICalFormat format; QFile file(QLatin1String(ICALTESTDATADIR) + QLatin1String("test_recurrenceid_single.ics")); QVERIFY(file.open(QIODevice::ReadOnly)); // qDebug() << file.readAll(); - KCalCore::Incidence::Ptr i = format.fromString(QString::fromUtf8(file.readAll())); + KCalendarCore::Incidence::Ptr i = format.fromString(QString::fromUtf8(file.readAll())); if (!i) { qWarning() << "Failed to parse incidence!"; if (format.exception()) { qWarning() << format.exception()->arguments(); } } QVERIFY(i); QVERIFY(i->hasRecurrenceId()); } void TestReadRecurrenceId::testReadSingleExceptionWithThisAndFuture() { - KCalCore::ICalFormat format; + KCalendarCore::ICalFormat format; QFile file(QLatin1String(ICALTESTDATADIR) + QLatin1String("test_recurrenceid_thisandfuture.ics")); QVERIFY(file.open(QIODevice::ReadOnly)); - KCalCore::Incidence::Ptr i = format.fromString(QString::fromUtf8(file.readAll())); + KCalendarCore::Incidence::Ptr i = format.fromString(QString::fromUtf8(file.readAll())); QVERIFY(i); QVERIFY(i->hasRecurrenceId()); QVERIFY(i->thisAndFuture()); } void TestReadRecurrenceId::testReadWriteSingleExceptionWithThisAndFuture() { - KCalCore::MemoryCalendar::Ptr cal(new KCalCore::MemoryCalendar(QTimeZone::utc())); - KCalCore::ICalFormat format; - KCalCore::Incidence::Ptr inc(new KCalCore::Event); + KCalendarCore::MemoryCalendar::Ptr cal(new KCalendarCore::MemoryCalendar(QTimeZone::utc())); + KCalendarCore::ICalFormat format; + KCalendarCore::Incidence::Ptr inc(new KCalendarCore::Event); QTimeZone tz("Europe/Berlin"); QDateTime startDate(QDate(2015, 1, 2), QTime(3, 4, 5), tz); inc->setDtStart(startDate); inc->setRecurrenceId(startDate); inc->setThisAndFuture(true); cal->addIncidence(inc); const QString result = format.toString(cal, QString()); qDebug() << result; - KCalCore::Incidence::Ptr i = format.fromString(result); + KCalendarCore::Incidence::Ptr i = format.fromString(result); QVERIFY(i); QVERIFY(i->hasRecurrenceId()); QVERIFY(i->thisAndFuture()); QCOMPARE(i->recurrenceId(), startDate); } void TestReadRecurrenceId::testReadExceptionWithMainEvent() { - KCalCore::MemoryCalendar::Ptr calendar(new KCalCore::MemoryCalendar(QTimeZone::utc())); - KCalCore::ICalFormat format; + KCalendarCore::MemoryCalendar::Ptr calendar(new KCalendarCore::MemoryCalendar(QTimeZone::utc())); + KCalendarCore::ICalFormat format; QFile file(QLatin1String(ICALTESTDATADIR) + QLatin1String("test_recurrenceid.ics")); QVERIFY(file.open(QIODevice::ReadOnly)); format.fromString(calendar, QString::fromUtf8(file.readAll())); QCOMPARE(calendar->rawEvents().size(), 2); } diff --git a/autotests/testrecurprevious.cpp b/autotests/testrecurprevious.cpp index e95b91209..15859dd60 100644 --- a/autotests/testrecurprevious.cpp +++ b/autotests/testrecurprevious.cpp @@ -1,158 +1,158 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher Copyright (C) 2005 Reinhold Kainhofer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filestorage.h" #include "memorycalendar.h" #include "utils.h" #include #include #include #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; static QString dumpTime(const QDateTime &dt, const QTimeZone &viewZone); int main(int argc, char **argv) { qputenv("TZ", "GMT"); QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), QStringLiteral("Verbose output"))); parser.addPositionalArgument(QStringLiteral("input"), QStringLiteral("Name of input file")); parser.addPositionalArgument(QStringLiteral("output"), QStringLiteral("optional name of output file for the recurrence dates")); QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("testrecurrencenew")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); parser.process(app); QStringList parsedArgs = parser.positionalArguments(); if (parsedArgs.isEmpty()) { parser.showHelp(); } QString input = parsedArgs[0]; qDebug() << "Input file:" << input; QTextStream *outstream = nullptr; outstream = nullptr; QString fn(QLatin1String("")); if (parsedArgs.count() > 1) { fn = parsedArgs[1]; qDebug() << "We have a file name given:" << fn; } QFile outfile(fn); if (!fn.isEmpty() && outfile.open(QIODevice::WriteOnly)) { qDebug() << "Opened output file!!!"; outstream = new QTextStream(&outfile); } MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); QTimeZone viewZone; FileStorage store(cal, input); if (!store.load()) { return 1; } QString tz = cal->nonKDECustomProperty("X-LibKCal-Testsuite-OutTZ"); if (!tz.isEmpty()) { viewZone = QTimeZone(tz.toUtf8()); } qDebug() << viewZone.id(); Incidence::List inc = cal->incidences(); for (Incidence::List::Iterator it = inc.begin(); it != inc.end(); ++it) { Incidence::Ptr incidence = *it; qDebug() << "*+*+*+*+*+*+*+*+*+*"; qDebug() << " ->" << incidence->summary() << "<-"; incidence->recurrence()->dump(); QDateTime dt = incidence->recurrence()->endDateTime(); int i = 0; if (outstream) { if (!dt.isValid()) { if (viewZone.isValid()) { dt = QDateTime(QDate(2011, 1, 1), QTime(0, 0, 1), viewZone); } else { dt = QDateTime(QDate(2011, 1, 1), QTime(0, 0, 1)); } } else { dt = dt.addYears(2); } qDebug() << "-------------------------------------------"; qDebug() << " *~*~*~*~ Starting with date:" << dumpTime(dt, viewZone); // Output to file for testing purposes while (dt.isValid() && i < 500) { ++i; dt = incidence->recurrence()->getPreviousDateTime(dt); if (dt.isValid()) { (*outstream) << dumpTime(dt, viewZone) << endl; } } } else { if (!dt.isValid()) { dt = QDateTime(QDate(2005, 7, 31), QTime(23, 59, 59), Qt::UTC); } else { dt = dt.addYears(2); } incidence->recurrence()->dump(); qDebug() << "-------------------------------------------"; qDebug() << " *~*~*~*~ Starting with date:" << dumpTime(dt, viewZone); // Output to konsole while (dt.isValid() && i < 50) { ++i; qDebug() << "-------------------------------------------"; dt = incidence->recurrence()->getPreviousDateTime(dt); if (dt.isValid()) { qDebug() << " *~*~*~*~ Previous date is:" << dumpTime(dt, viewZone); } } } } delete outstream; outfile.close(); return 0; } QString dumpTime(const QDateTime &dt, const QTimeZone &viewZone) { if (!dt.isValid()) { return QString(); } const QDateTime vdt = viewZone.isValid() ? dt.toTimeZone(viewZone) : dt; QString format = QStringLiteral("yyyy-MM-ddThh:mm:ss t"); if (viewZone.isValid()) { format += QStringLiteral(" '%1'").arg(QString::fromUtf8(viewZone.id())); } return vdt.toString(format); } diff --git a/autotests/testrecurrence.cpp b/autotests/testrecurrence.cpp index 4092bfc9e..1a91bcd17 100644 --- a/autotests/testrecurrence.cpp +++ b/autotests/testrecurrence.cpp @@ -1,141 +1,141 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher Copyright (C) 2005 Reinhold Kainhofer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filestorage.h" #include "memorycalendar.h" #include #include #include #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; static QString dumpTime(const QDateTime &dt, const QTimeZone &viewZone); int main(int argc, char **argv) { qputenv("TZ", "GMT"); QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), QStringLiteral("Verbose output"))); parser.addPositionalArgument(QStringLiteral("input"), QStringLiteral("Name of input file")); parser.addPositionalArgument(QStringLiteral("output"), QStringLiteral("optional name of output file for the recurrence dates")); QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("testrecurrencenew")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); parser.process(app); const QStringList parsedArgs = parser.positionalArguments(); if (parsedArgs.isEmpty()) { parser.showHelp(); } QString input = parsedArgs[0]; qDebug() << "Input file:" << input; QTextStream *outstream = nullptr; QString fn; if (parsedArgs.count() > 1) { fn = parsedArgs[1]; qDebug() << "We have a file name given:" << fn; } QFile outfile(fn); if (!fn.isEmpty() && outfile.open(QIODevice::WriteOnly)) { qDebug() << "Opened output file!!!"; outstream = new QTextStream(&outfile); } MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); QTimeZone viewZone; FileStorage store(cal, input); if (!store.load()) { return 1; } QString tz = cal->nonKDECustomProperty("X-LibKCal-Testsuite-OutTZ"); if (!tz.isEmpty()) { viewZone = QTimeZone(tz.toUtf8()); } Incidence::List inc = cal->incidences(); for (Incidence::List::Iterator it = inc.begin(); it != inc.end(); ++it) { Incidence::Ptr incidence = *it; qDebug() << "*+*+*+*+*+*+*+*+*+*"; qDebug() << " ->" << incidence->summary() << "<-"; incidence->recurrence()->dump(); QDateTime dt; if (incidence->allDay()) { dt = incidence->dtStart().addDays(-1); } else { dt = incidence->dtStart().addSecs(-1); } int i = 0; if (outstream) { // Output to file for testing purposes while (dt.isValid() && i < 500) { ++i; dt = incidence->recurrence()->getNextDateTime(dt); if (dt.isValid()) { (*outstream) << dumpTime(dt, viewZone) << endl; } } } else { incidence->recurrence()->dump(); // Output to konsole while (dt.isValid() && i < 10) { ++i; qDebug() << "-------------------------------------------"; dt = incidence->recurrence()->getNextDateTime(dt); if (dt.isValid()) { qDebug() << " *~*~*~*~ Next date is:" << dumpTime(dt, viewZone); } } } } delete outstream; outfile.close(); return 0; } QString dumpTime(const QDateTime &dt, const QTimeZone &viewZone) { if (!dt.isValid()) { return QString(); } const QDateTime vdt = viewZone.isValid() ? dt.toTimeZone(viewZone) : dt; QString format = QStringLiteral("yyyy-MM-ddThh:mm:ss t"); if (viewZone.isValid()) { format += QStringLiteral(" '%1'").arg(QString::fromUtf8(viewZone.id())); } else if (vdt.timeZone().isValid()) { format += QStringLiteral(" '%1'").arg(QString::fromUtf8(vdt.timeZone().id())); } return vdt.toString(format); } diff --git a/autotests/testrecurrenceexception.cpp b/autotests/testrecurrenceexception.cpp index 9121ae38e..d866da97c 100644 --- a/autotests/testrecurrenceexception.cpp +++ b/autotests/testrecurrenceexception.cpp @@ -1,45 +1,45 @@ /* * Copyright (C) 2013 Christian Mollekopf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "testrecurrenceexception.h" #include "memorycalendar.h" #include QTEST_MAIN(TestRecurrenceException) void TestRecurrenceException::testCreateTodoException() { const QDateTime dtstart(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); const QDateTime dtdue(QDate(2013, 03, 10), QTime(11, 0, 0), Qt::UTC); const QDateTime recurrenceId(QDateTime(dtstart).addDays(1)); - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtStart(dtstart); todo->setDtDue(dtdue); todo->recurrence()->setDaily(1); todo->recurrence()->setDuration(3); - const KCalCore::Todo::Ptr exception - = KCalCore::MemoryCalendar::createException(todo, recurrenceId, false).staticCast(); + const KCalendarCore::Todo::Ptr exception + = KCalendarCore::MemoryCalendar::createException(todo, recurrenceId, false).staticCast(); QCOMPARE(exception->dtStart(), recurrenceId); QCOMPARE(exception->dtDue(), QDateTime(dtdue).addDays(1)); //FIXME should be done on clearing the recurrence, but we can't due to BC. //Probably not that important as long as dtRecurrence is ignored if the todo is not recurring //QCOMPARE(exception->dtRecurrence(), QDateTime()); //TODO dtCompleted } diff --git a/autotests/testrecurrencetype.cpp b/autotests/testrecurrencetype.cpp index f1564ac7f..3a4dfcd06 100644 --- a/autotests/testrecurrencetype.cpp +++ b/autotests/testrecurrencetype.cpp @@ -1,137 +1,137 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher Copyright (C) 2005 Reinhold Kainhofer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filestorage.h" #include "memorycalendar.h" #include #include #include #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; static QString dumpTime(const QDateTime &dt, const QTimeZone &viewZone); int main(int argc, char **argv) { QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), QStringLiteral("Verbose output"))); parser.addPositionalArgument(QStringLiteral("input"), QStringLiteral("Name of input file")); parser.addPositionalArgument(QStringLiteral("output"), QStringLiteral("optional name of output file for the recurrence dates")); QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("testrecurrencenew")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); parser.process(app); const QStringList parsedArgs = parser.positionalArguments(); if (parsedArgs.isEmpty()) { parser.showHelp(); } QString input = parsedArgs[0]; qDebug() << "Input file:" << input; QTextStream *outstream = nullptr; QString fn; if (parsedArgs.count() > 1) { fn = parsedArgs[1]; qDebug() << "We have a file name given:" << fn; } QFile outfile(fn); if (!fn.isEmpty() && outfile.open(QIODevice::WriteOnly)) { qDebug() << "Opened output file!!!"; outstream = new QTextStream(&outfile); } MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); QTimeZone viewZone; FileStorage store(cal, input); if (!store.load()) { return 1; } QString tz = cal->nonKDECustomProperty("X-LibKCal-Testsuite-OutTZ"); if (!tz.isEmpty()) { viewZone = QTimeZone(tz.toUtf8()); } Incidence::List inc = cal->incidences(); for (Incidence::List::Iterator it = inc.begin(); it != inc.end(); ++it) { Incidence::Ptr incidence = *it; qDebug() << "*+*+*+*+*+*+*+*+*+*"; qDebug() << " ->" << incidence->summary() << "<-"; incidence->recurrence()->dump(); QDateTime dt; if (incidence->allDay()) { dt = incidence->dtStart().addDays(-1); } else { dt = incidence->dtStart().addSecs(-1); } int i = 0; if (outstream) { // Output to file for testing purposes while (dt.isValid() && i < 500) { ++i; dt = incidence->recurrence()->getNextDateTime(dt); if (dt.isValid()) { (*outstream) << dumpTime(dt, viewZone) << endl; } } } else { incidence->recurrence()->dump(); // Output to konsole while (dt.isValid() && i < 10) { ++i; qDebug() << "-------------------------------------------"; dt = incidence->recurrence()->getNextDateTime(dt); if (dt.isValid()) { qDebug() << " *~*~*~*~ Next date is:" << dumpTime(dt, viewZone); } } } } delete outstream; outfile.close(); return 0; } QString dumpTime(const QDateTime &dt, const QTimeZone &viewZone) { if (!dt.isValid()) { return QString(); } QDateTime vdt = viewZone.isValid() ? dt.toTimeZone(viewZone) : dt; QString format = QStringLiteral("yyyy-MM-ddThh:mm:ss t"); if (viewZone.isValid()) { format += QStringLiteral(" '%1'").arg(QString::fromUtf8(viewZone.id())); } return vdt.toString(format); } diff --git a/autotests/testrecurson.cpp b/autotests/testrecurson.cpp index 9937f7b01..c27f3a265 100644 --- a/autotests/testrecurson.cpp +++ b/autotests/testrecurson.cpp @@ -1,120 +1,120 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher Copyright (C) 2005 Reinhold Kainhofer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filestorage.h" #include "memorycalendar.h" #include "utils.h" #include #include #include #include #include #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; int main(int argc, char **argv) { qputenv("TZ", "GMT"); QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), QStringLiteral("Verbose output"))); parser.addPositionalArgument(QStringLiteral("input"), QStringLiteral("Name of input file")); parser.addPositionalArgument(QStringLiteral("output"), QStringLiteral("optional name of output file for the recurrence dates")); QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("testrecurson")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); parser.process(app); const QStringList parsedArgs = parser.positionalArguments(); if (parsedArgs.isEmpty()) { parser.showHelp(); } QString input = parsedArgs[0]; QTextStream *outstream = nullptr; QString fn; if (parsedArgs.count() > 1) { fn = parsedArgs[1]; // qDebug() << "We have a file name given:" << fn; } QFile outfile(fn); if (!fn.isEmpty() && outfile.open(QIODevice::WriteOnly)) { // qDebug() << "Opened output file!!!"; outstream = new QTextStream(&outfile); } MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage store(cal, input); if (!store.load()) { return 1; } QString tz = cal->nonKDECustomProperty("X-LibKCal-Testsuite-OutTZ"); const auto viewZone = tz.isEmpty() ? cal->timeZone() : QTimeZone(tz.toUtf8()); Incidence::List inc = cal->incidences(); for (Incidence::List::Iterator it = inc.begin(); it != inc.end(); ++it) { Incidence::Ptr incidence = *it; // qDebug() << " ->" << incidence->summary() << "<-"; // incidence->recurrence()->dump(); QDate dt(1996, 7, 1); if (outstream) { // Output to file for testing purposes int nr = 0; while (dt.year() <= 2020 && nr <= 500) { if (incidence->recursOn(dt, viewZone)) { (*outstream) << dt.toString(Qt::ISODate) << endl; nr++; } dt = dt.addDays(1); } } else { dt = QDate(2005, 1, 1); while (dt.year() < 2007) { if (incidence->recursOn(dt, viewZone)) { qDebug() << dt.toString(Qt::ISODate); } dt = dt.addDays(1); } } } delete outstream; outfile.close(); return 0; } diff --git a/autotests/testrecurtodo.cpp b/autotests/testrecurtodo.cpp index 590d38837..5ee709fd6 100644 --- a/autotests/testrecurtodo.cpp +++ b/autotests/testrecurtodo.cpp @@ -1,263 +1,263 @@ /* This file is part of the kcalcore library. Copyright (c) 2011 Sérgio Martins This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testrecurtodo.h" #include "todo.h" #include "utils.h" #include #include QTEST_MAIN(RecurTodoTest) -using namespace KCalCore; +using namespace KCalendarCore; void RecurTodoTest::testAllDay() { qputenv("TZ", "GMT"); const QDate currentDate = QDate::currentDate(); const QDateTime currentUtcDateTime = QDateTime::currentDateTimeUtc(); const QDate dueDate(QDate::currentDate()); Todo *todo = new Todo(); todo->setDtStart(QDateTime(dueDate.addDays(-1), {})); todo->setDtDue(QDateTime(dueDate, {})); todo->setSummary(QStringLiteral("All day event")); todo->setAllDay(true); QCOMPARE(todo->dtStart().daysTo(todo->dtDue()), 1); Recurrence *recurrence = todo->recurrence(); recurrence->unsetRecurs(); recurrence->setDaily(1); QCOMPARE(todo->dtDue(), QDateTime(dueDate, {})); todo->setCompleted(currentUtcDateTime); QVERIFY(todo->recurs()); QVERIFY(todo->percentComplete() == 0); const QDate newStartDate = todo->dtStart().date(); const QDate newDueDate = todo->dtDue().date(); QCOMPARE(newStartDate, currentDate); QCOMPARE(newStartDate.daysTo(newDueDate), 1); todo->setCompleted(currentUtcDateTime); QCOMPARE(newDueDate, currentDate.addDays(1)); QCOMPARE(todo->dtDue(true /*first ocurrence*/).date(), dueDate); } void RecurTodoTest::testRecurrenceStart() { qputenv("TZ", "GMT"); const QDateTime currentDateTime = QDateTime::currentDateTime(); const QDate currentDate = currentDateTime.date(); const QTime currentTimeWithMS = currentDateTime.time(); const QDate fourDaysAgo(currentDate.addDays(-4)); const QDate treeDaysAgo(currentDate.addDays(-3)); const QTime currentTime(currentTimeWithMS.hour(), currentTimeWithMS.minute(), currentTimeWithMS.second()); Todo *todo = new Todo(); Recurrence *recurrence = todo->recurrence(); recurrence->unsetRecurs(); recurrence->setDaily(1); todo->setDtStart(QDateTime(fourDaysAgo, currentTime)); const QDateTime originalDtDue(treeDaysAgo, currentTime); todo->setDtDue(originalDtDue); todo->setSummary(QStringLiteral("Not an all day event")); QVERIFY(!todo->allDay()); QVERIFY(recurrence->startDateTime().isValid()); } void RecurTodoTest::testNonAllDay() { qputenv("TZ", "GMT"); const QDateTime currentDateTime = QDateTime::currentDateTime(); const QDate currentDate = currentDateTime.date(); const QTime currentTimeWithMS = currentDateTime.time(); const QDate fourDaysAgo(currentDate.addDays(-4)); const QDate treeDaysAgo(currentDate.addDays(-3)); const QTime currentTime(currentTimeWithMS.hour(), currentTimeWithMS.minute(), currentTimeWithMS.second()); Todo *todo = new Todo(); todo->setDtStart(QDateTime(fourDaysAgo, currentTime)); const QDateTime originalDtDue(treeDaysAgo, currentTime); todo->setDtDue(originalDtDue); todo->setSummary(QStringLiteral("Not an all day event")); QVERIFY(!todo->allDay()); Recurrence *recurrence = todo->recurrence(); recurrence->unsetRecurs(); recurrence->setDaily(1); QVERIFY(recurrence->startDateTime().isValid()); QCOMPARE(todo->dtDue(), originalDtDue); todo->setCompleted(QDateTime::currentDateTimeUtc()); QVERIFY(todo->recurs()); QVERIFY(todo->percentComplete() == 0); const bool equal = todo->dtStart() == QDateTime(currentDate, currentTime, todo->dtStart().timeZone()).addDays(1); if (!equal) { qDebug() << "Test Failed. dtDue = " << todo->dtDue().toString() << "OriginalDtDue:" << originalDtDue.toString() << "QDateTime:" << QDateTime(currentDate, currentTime, todo->dtDue().timeZone()).addDays(1).toString(); } QVERIFY(equal); todo->setCompleted(QDateTime::currentDateTimeUtc()); QCOMPARE(todo->dtStart(), QDateTime(currentDate, currentTime, todo->dtStart().timeZone()).addDays(2)); QCOMPARE(todo->dtDue(true /*first ocurrence*/), QDateTime(treeDaysAgo, currentTime)); } void RecurTodoTest::testIsAllDay() { - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtStart(QDateTime(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC)); todo->setDtDue(QDateTime(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC)); todo->recurrence()->setDaily(1); todo->recurrence()->setDuration(2); QCOMPARE(todo->allDay(), false); QCOMPARE(todo->recurrence()->allDay(), false); - KCalCore::Todo::Ptr allDay(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr allDay(new KCalendarCore::Todo()); allDay->setUid(QStringLiteral("todo")); allDay->setDtStart(QDateTime(QDate(2013, 03, 10), {}, Qt::UTC)); allDay->setDtDue(QDateTime(QDate(2013, 03, 10), {}, Qt::UTC)); allDay->setAllDay(true); allDay->recurrence()->setDaily(1); allDay->recurrence()->setDuration(2); QCOMPARE(allDay->allDay(), true); QCOMPARE(allDay->recurrence()->allDay(), true); } void RecurTodoTest::testHasDueDate() { - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtStart(QDateTime(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC)); todo->recurrence()->setDaily(1); todo->recurrence()->setDuration(2); QVERIFY(!todo->hasDueDate()); } void RecurTodoTest::testRecurTodo_data() { QTest::addColumn("dtstart"); QTest::addColumn("dtdue"); // Can't use QDateTime::currentDateTimeUtc() due to milliseconds mismatching const QDateTime today = QDateTime::fromSecsSinceEpoch(QDateTime::currentSecsSinceEpoch(), Qt::UTC); const QDateTime tomorrow = today.addDays(1); const QDateTime invalid; QTest::newRow("valid dtstart") << today << invalid; QTest::newRow("valid dtstart and dtdue") << today << tomorrow; QTest::newRow("valid dtdue") << invalid << today; } void RecurTodoTest::testRecurTodo() { QFETCH(QDateTime, dtstart); QFETCH(QDateTime, dtdue); - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtStart(dtstart); todo->setDtDue(dtdue); todo->recurrence()->setDaily(1); const bool legacyMode = !dtstart.isValid(); QCOMPARE(todo->percentComplete(), 0); // Recur it todo->setCompleted(QDateTime::currentDateTimeUtc()); QCOMPARE(todo->percentComplete(), 0); if (legacyMode) { QVERIFY(todo->dtDue().isValid()); QVERIFY(!todo->dtStart().isValid()); QCOMPARE(todo->dtDue(), dtdue.addDays(1)); QCOMPARE(todo->dtDue(/**first=*/ true), dtdue); } else { QVERIFY(todo->dtStart().isValid()); QVERIFY(!(todo->dtDue().isValid() ^ dtdue.isValid())); QCOMPARE(todo->dtStart(), dtstart.addDays(1)); if (dtdue.isValid()) { const int delta = dtstart.daysTo(dtdue); QCOMPARE(todo->dtStart().daysTo(todo->dtDue()), delta); } QCOMPARE(todo->dtStart(/**first=*/ true), dtstart); } } void RecurTodoTest::testDtStart() { QDateTime start(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtStart(start); todo->recurrence()->setDaily(1); todo->recurrence()->setDuration(2); QCOMPARE(todo->dtStart(), start); - KCalCore::Todo::Ptr todoWithDue(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todoWithDue(new KCalendarCore::Todo()); todoWithDue->setUid(QStringLiteral("todoWithDue")); todoWithDue->setDtStart(start); todoWithDue->setDtDue(QDateTime(start).addSecs(60)); todoWithDue->recurrence()->setDaily(1); todoWithDue->recurrence()->setDuration(2); QCOMPARE(todoWithDue->dtStart(), start); } void RecurTodoTest::testRecurrenceBasedOnDtStart() { const QDateTime dtstart(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); const QDateTime dtdue(QDate(2013, 03, 10), QTime(11, 0, 0), Qt::UTC); - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtStart(dtstart); todo->setDtDue(dtdue); todo->recurrence()->setDaily(1); todo->recurrence()->setDuration(3); QCOMPARE(todo->recurrence()->getNextDateTime(dtstart), dtstart.addDays(1)); QCOMPARE(todo->recurrence()->getNextDateTime(dtstart.addDays(1)), dtstart.addDays(2)); QCOMPARE(todo->recurrence()->getNextDateTime(dtstart.addDays(2)), QDateTime()); } //For backwards compatibility only void RecurTodoTest::testRecurrenceBasedOnDue() { const QDateTime dtdue(QDate(2013, 03, 10), QTime(11, 0, 0), Qt::UTC); - KCalCore::Todo::Ptr todo(new KCalCore::Todo()); + KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo()); todo->setUid(QStringLiteral("todo")); todo->setDtDue(dtdue); todo->recurrence()->setDaily(1); todo->recurrence()->setDuration(3); QCOMPARE(todo->recurrence()->getNextDateTime(dtdue), dtdue.addDays(1)); QCOMPARE(todo->recurrence()->getNextDateTime(dtdue.addDays(1)), dtdue.addDays(2)); QCOMPARE(todo->recurrence()->getNextDateTime(dtdue.addDays(2)), QDateTime()); } diff --git a/autotests/testtimesininterval.cpp b/autotests/testtimesininterval.cpp index e83d1977a..a0d50c9af 100644 --- a/autotests/testtimesininterval.cpp +++ b/autotests/testtimesininterval.cpp @@ -1,158 +1,158 @@ /* This file is part of the kcalcore library. Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company Author: Sergio Martins This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testtimesininterval.h" #include "event.h" #include "utils.h" #include #include QTEST_MAIN(TimesInIntervalTest) -using namespace KCalCore; +using namespace KCalendarCore; void TimesInIntervalTest::test() { const QDateTime currentDate(QDate::currentDate(), {}); Event *event = new Event(); event->setDtStart(currentDate); event->setDtEnd(currentDate.addDays(1)); event->setAllDay(true); event->setSummary(QStringLiteral("Event1 Summary")); event->recurrence()->setDaily(1); //------------------------------------------------------------------------------------------------ // Just to warm up QVERIFY(event->recurs()); QVERIFY(event->recursAt(currentDate)); //------------------------------------------------------------------------------------------------ // Daily recurrence that never stops. // Should return numDaysInInterval+1 occurrences const int numDaysInInterval = 7; QDateTime start(currentDate); QDateTime end(start.addDays(numDaysInInterval)); start.setTime(QTime(0, 0, 0)); end.setTime(QTime(23, 59, 59)); auto dateList = event->recurrence()->timesInInterval(start, end); QVERIFY(dateList.count() == numDaysInInterval + 1); //------------------------------------------------------------------------------------------------ // start == end == first day of the recurrence, should only return 1 occurrence end = start; end.setTime(QTime(23, 59, 59)); dateList = event->recurrence()->timesInInterval(start, end); QVERIFY(dateList.count() == 1); //------------------------------------------------------------------------------------------------ // Test daily recurrence that only lasts X days const int recurrenceDuration = 3; event->recurrence()->setDuration(recurrenceDuration); end = start.addDays(100); dateList = event->recurrence()->timesInInterval(start, end); QVERIFY(dateList.count() == recurrenceDuration); //------------------------------------------------------------------------------------------------ // Test daily recurrence that only lasts X days, and give start == end == last day of // recurrence. Previous versions of kcal had a bug and didn't return an occurrence start = start.addDays(recurrenceDuration - 1); end = start; start.setTime(QTime(0, 0, 0)); end.setTime(QTime(23, 59, 59)); dateList = event->recurrence()->timesInInterval(start, end); QVERIFY(dateList.count() == 1); //------------------------------------------------------------------------------------------------ } //Test that interval start and end are inclusive void TimesInIntervalTest::testSubDailyRecurrenceIntervalInclusive() { const QDateTime start(QDate(2013, 03, 10), QTime(10, 0, 0), Qt::UTC); const QDateTime end(QDate(2013, 03, 10), QTime(11, 0, 0), Qt::UTC); - KCalCore::Event::Ptr event(new KCalCore::Event()); + KCalendarCore::Event::Ptr event(new KCalendarCore::Event()); event->setUid(QStringLiteral("event")); event->setDtStart(start); event->recurrence()->setHourly(1); event->recurrence()->setDuration(2); QList expectedEventOccurrences; expectedEventOccurrences << start << start.addSecs(60 * 60); const auto timesInInterval = event->recurrence()->timesInInterval(start, end); // qDebug() << "timesInInterval " << timesInInterval; for (const auto &dt : timesInInterval) { // qDebug() << dt; QCOMPARE(expectedEventOccurrences.removeAll(dt), 1); } QCOMPARE(expectedEventOccurrences.size(), 0); } //Test that the recurrence dtStart is used for calculation and not the interval start date void TimesInIntervalTest::testSubDailyRecurrence2() { const QDateTime start(QDate(2013, 03, 10), QTime(10, 2, 3), Qt::UTC); const QDateTime end(QDate(2013, 03, 10), QTime(13, 4, 5), Qt::UTC); - KCalCore::Event::Ptr event(new KCalCore::Event()); + KCalendarCore::Event::Ptr event(new KCalendarCore::Event()); event->setUid(QStringLiteral("event")); event->setDtStart(start); event->recurrence()->setHourly(1); event->recurrence()->setDuration(2); QList expectedEventOccurrences; expectedEventOccurrences << start << start.addSecs(60 * 60); const auto timesInInterval = event->recurrence()->timesInInterval(start.addSecs(-20), end.addSecs(20)); // qDebug() << "timesInInterval " << timesInInterval; for (const auto &dt : timesInInterval) { // qDebug() << dt; QCOMPARE(expectedEventOccurrences.removeAll(dt), 1); } QCOMPARE(expectedEventOccurrences.size(), 0); } void TimesInIntervalTest::testSubDailyRecurrenceIntervalLimits() { const QDateTime start(QDate(2013, 03, 10), QTime(10, 2, 3), Qt::UTC); const QDateTime end(QDate(2013, 03, 10), QTime(12, 2, 3), Qt::UTC); - KCalCore::Event::Ptr event(new KCalCore::Event()); + KCalendarCore::Event::Ptr event(new KCalendarCore::Event()); event->setUid(QStringLiteral("event")); event->setDtStart(start); event->recurrence()->setHourly(1); event->recurrence()->setDuration(3); QList expectedEventOccurrences; expectedEventOccurrences << start.addSecs(60 * 60); const auto timesInInterval = event->recurrence()->timesInInterval(start.addSecs(1), end.addSecs(-1)); // qDebug() << "timesInInterval " << timesInInterval; for (const auto &dt : timesInInterval) { // qDebug() << dt; QCOMPARE(expectedEventOccurrences.removeAll(dt), 1); } QCOMPARE(expectedEventOccurrences.size(), 0); } diff --git a/autotests/testtodo.cpp b/autotests/testtodo.cpp index 20b2bf1eb..da2924644 100644 --- a/autotests/testtodo.cpp +++ b/autotests/testtodo.cpp @@ -1,287 +1,287 @@ /* This file is part of the kcalcore library. Copyright (C) 2006,2008 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testtodo.h" #include "todo.h" #include "event.h" #include "attachment.h" #include "utils.h" #include QTEST_MAIN(TodoTest) -using namespace KCalCore; +using namespace KCalendarCore; void TodoTest::initTestCase() { qputenv("TZ", "GMT"); } void TodoTest::testValidity() { QDate dt = QDate::currentDate(); Todo *todo = new Todo(); todo->setDtStart(QDateTime(dt, {})); todo->setDtDue(QDateTime(dt, {}).addDays(1)); todo->setSummary(QStringLiteral("To-do1 Summary")); todo->setDescription(QStringLiteral("This is a description of the first to-do")); todo->setLocation(QStringLiteral("the place")); todo->setPercentComplete(5); QCOMPARE(todo->summary(), QStringLiteral("To-do1 Summary")); QCOMPARE(todo->location(), QStringLiteral("the place")); QCOMPARE(todo->percentComplete(), 5); } void TodoTest::testCompare() { QDate dt = QDate::currentDate(); Todo todo1; todo1.setDtStart(QDateTime(dt, {})); todo1.setDtDue(QDateTime(dt, {}).addDays(1)); todo1.setSummary(QStringLiteral("To-do1 Summary")); todo1.setDescription(QStringLiteral("This is a description of the first to-do")); todo1.setLocation(QStringLiteral("the place")); todo1.setCompleted(true); Todo todo2; todo2.setDtStart(QDateTime(dt, {}).addDays(1)); todo2.setDtDue(QDateTime(dt, {}).addDays(2)); todo2.setSummary(QStringLiteral("To-do2 Summary")); todo2.setDescription(QStringLiteral("This is a description of the second to-do")); todo2.setLocation(QStringLiteral("the other place")); todo2.setCompleted(false); QVERIFY(!(todo1 == todo2)); QCOMPARE(todo1.dtDue(), todo2.dtStart()); QCOMPARE(todo2.summary(), QStringLiteral("To-do2 Summary")); QVERIFY(!(todo1.isCompleted() == todo2.isCompleted())); } void TodoTest::testClone() { QDate dt = QDate::currentDate(); Todo todo1; todo1.setDtStart(QDateTime(dt, {})); todo1.setDtDue(QDateTime(dt, {}).addDays(1)); todo1.setSummary(QStringLiteral("Todo1 Summary")); todo1.setDescription(QStringLiteral("This is a description of the first todo")); todo1.setLocation(QStringLiteral("the place")); Todo *todo2 = todo1.clone(); QCOMPARE(todo1.summary(), todo2->summary()); QCOMPARE(todo1.dtStart(), todo2->dtStart()); QCOMPARE(todo1.dtDue(), todo2->dtDue()); QCOMPARE(todo1.description(), todo2->description()); QCOMPARE(todo1.location(), todo2->location()); QCOMPARE(todo1.isCompleted(), todo2->isCompleted()); } void TodoTest::testCopyIncidence() { QDate dt = QDate::currentDate(); Event event; event.setDtStart(QDateTime(dt, {})); event.setSummary(QStringLiteral("Event1 Summary")); event.setDescription(QStringLiteral("This is a description of the first event")); event.setLocation(QStringLiteral("the place")); Todo todo(event); QCOMPARE(todo.uid(), event.uid()); QCOMPARE(todo.dtStart(), event.dtStart()); QCOMPARE(todo.summary(), event.summary()); QCOMPARE(todo.description(), event.description()); QCOMPARE(todo.location(), event.location()); } void TodoTest::testAssign() { QDate dt = QDate::currentDate(); Todo todo1; todo1.setDtStart(QDateTime(dt, {})); todo1.setDtDue(QDateTime(dt, {}).addDays(1)); todo1.setSummary(QStringLiteral("Todo1 Summary")); todo1.setDescription(QStringLiteral("This is a description of the first todo")); todo1.setLocation(QStringLiteral("the place")); Todo todo2 = todo1; QVERIFY(todo1 == todo2); } void TodoTest::testSetCompleted() { Todo todo1, todo2, todo3; todo1.setSummary(QStringLiteral("Todo Summary")); todo2.setSummary(QStringLiteral("Todo Summary")); todo3.setSummary(QStringLiteral("Todo Summary")); QDateTime today = QDateTime::currentDateTimeUtc(); // due yesterday QDateTime originalDueDate = today.addDays(-1); todo1.setDtStart(originalDueDate); todo1.setDtDue(originalDueDate); todo1.recurrence()->setDaily(1); todo1.setCompleted(today); todo2.setCompleted(true); todo3.setStatus(Incidence::StatusCompleted); QVERIFY(originalDueDate != todo1.dtDue()); QVERIFY(!todo1.isCompleted()); QVERIFY(todo2.isCompleted()); QCOMPARE(todo2.status(), Incidence::StatusCompleted); QVERIFY(todo3.isCompleted()); todo2.setCompleted(false); QVERIFY(!todo2.isCompleted()); } void TodoTest::testStatus() { QDateTime today = QDateTime::currentDateTimeUtc(); QDateTime yesterday = today.addDays(-1); Todo todo1; todo1.setAllDay(true); todo1.setDtStart(yesterday); todo1.setDtDue(today); todo1.setPercentComplete(50); QVERIFY(todo1.isInProgress(false)); QVERIFY(!todo1.isNotStarted(false)); QVERIFY(!todo1.isOverdue()); todo1.setPercentComplete(100); QVERIFY(todo1.isCompleted()); Todo todo2 = todo1; todo2.setPercentComplete(33); todo2.setDtDue(QDateTime()); QVERIFY(todo2.isOpenEnded()); } void TodoTest::testSerializer_data() { - QTest::addColumn("todo"); + QTest::addColumn("todo"); QDateTime today = QDateTime::currentDateTimeUtc(); QDateTime yesterday = today.addDays(-1); Todo::Ptr todo1 = Todo::Ptr(new Todo()); Todo::Ptr todo2 = Todo::Ptr(new Todo()); Todo::Ptr todo3 = Todo::Ptr(new Todo()); Todo::Ptr todo4 = Todo::Ptr(new Todo()); Todo::Ptr todo5 = Todo::Ptr(new Todo()); Todo::Ptr todo6 = Todo::Ptr(new Todo()); todo1->setSummary(QStringLiteral("Summary"), false); todo1->setDescription(QStringLiteral("description"), false); todo1->setCreated(yesterday); todo1->setRevision(50); todo1->setDtDue(yesterday); todo1->setDtStart(today); todo1->setPercentComplete(50); todo1->setLocation(QStringLiteral("location"), false); todo2->setDescription(QStringLiteral("description"), true); todo2->setSummary(QStringLiteral("Summary2"), true); todo2->setLocation(QStringLiteral("location"), true); todo2->setDtDue(yesterday); todo2->setPercentComplete(100); todo3->setDtStart(today); todo3->setPercentComplete(100); todo3->setCategories(QStringList() << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c") << QStringLiteral("d")); todo3->setResources(QStringList() << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c") << QStringLiteral("d")); todo3->setPriority(5); QVERIFY(!todo4->dirtyFields().contains(IncidenceBase::FieldRecurrence)); todo4->recurrence()->setDaily(1); QVERIFY(todo4->dirtyFields().contains(IncidenceBase::FieldRecurrence)); Attachment attachment(QStringLiteral("http://www.kde.org")); todo4->addAttachment(attachment); todo5->recurrence()->setDaily(1); todo5->setCompleted(today); todo5->setStatus(Incidence::StatusDraft); todo5->setSecrecy(Incidence::SecrecyPrivate); todo5->setRelatedTo(QStringLiteral("uid1"), Incidence::RelTypeParent); todo5->setHasGeo(true); todo5->setGeoLatitude(40); todo5->setGeoLongitude(40); todo5->setOrganizer(QStringLiteral("organizer@mail.com")); todo6->recurrence()->setDaily(1); todo6->setCompleted(today); todo6->setRecurrenceId(yesterday); todo6->setStatus(Incidence::StatusDraft); todo6->setSecrecy(Incidence::SecrecyPrivate); todo6->setRelatedTo(QStringLiteral("uid1"), Incidence::RelTypeParent); todo6->setHasGeo(true); todo6->setGeoLatitude(40); todo6->setGeoLongitude(40); todo6->setUid(QStringLiteral("uid22")); todo6->setLastModified(today); todo6->addContact(QStringLiteral("addContact")); // Remaining properties tested in testevent.cpp QTest::newRow("todo1") << todo1; QTest::newRow("todo2") << todo2; QTest::newRow("todo3") << todo3; QTest::newRow("todo4") << todo4; QTest::newRow("todo5") << todo5; QTest::newRow("todo6") << todo6; } void TodoTest::testSerializer() { - QFETCH(KCalCore::Todo::Ptr, todo); - IncidenceBase::Ptr incidenceBase = todo.staticCast(); + QFETCH(KCalendarCore::Todo::Ptr, todo); + IncidenceBase::Ptr incidenceBase = todo.staticCast(); QByteArray array; QDataStream stream(&array, QIODevice::WriteOnly); stream << incidenceBase; Todo::Ptr todo2 = Todo::Ptr(new Todo()); - IncidenceBase::Ptr incidenceBase2 = todo2.staticCast(); + IncidenceBase::Ptr incidenceBase2 = todo2.staticCast(); QVERIFY(*todo != *todo2); QDataStream stream2(&array, QIODevice::ReadOnly); stream2 >> incidenceBase2; QVERIFY(*todo == *todo2); } void TodoTest::testRoles() { const QDateTime today = QDateTime::currentDateTimeUtc(); const QDateTime yesterday = today.addDays(-1); Todo todo; todo.setDtStart(today.addDays(-1)); todo.setDtDue(today); QCOMPARE(todo.dateTime(Incidence::RoleDisplayStart), today); QCOMPARE(todo.dateTime(Incidence::RoleDisplayEnd), today); todo.setDtDue(QDateTime()); QCOMPARE(todo.dateTime(Incidence::RoleDisplayStart), yesterday); QCOMPARE(todo.dateTime(Incidence::RoleDisplayEnd), yesterday); } diff --git a/autotests/testtostring.cpp b/autotests/testtostring.cpp index 6c549d68c..0c7e520f6 100644 --- a/autotests/testtostring.cpp +++ b/autotests/testtostring.cpp @@ -1,47 +1,47 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "event.h" #include "icalformat.h" #include #include -using namespace KCalCore; +using namespace KCalendarCore; int main(int, char **) { // std::cout << "Hello World!" << std::endl; Event::Ptr ev = Event::Ptr(new Event); ev->setSummary(QStringLiteral("Griazi")); ICalFormat iformat; QString icalstr = iformat.toICalString(ev); qDebug() << icalstr; Incidence::Ptr ev2 = iformat.fromString(icalstr); qDebug() << "Event reread!"; if (ev2) { qDebug() << iformat.toICalString(ev2); } else { qDebug() << "Could not read incidence"; } } diff --git a/autotests/testvcalexport.cpp b/autotests/testvcalexport.cpp index df3b7e4d2..db3caac54 100644 --- a/autotests/testvcalexport.cpp +++ b/autotests/testvcalexport.cpp @@ -1,75 +1,75 @@ /* This file is part of the kcalcore library. Copyright (c) 2003 Cornelius Schumacher Copyright (C) 2005 Reinhold Kainhofer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filestorage.h" #include "memorycalendar.h" #include "vcalformat.h" #include #include #include #include #include -using namespace KCalCore; +using namespace KCalendarCore; int main(int argc, char **argv) { QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("verbose"), QStringLiteral("Verbose output"))); parser.addPositionalArgument(QStringLiteral("input"), QStringLiteral("Name of input file")); parser.addPositionalArgument(QStringLiteral("output"), QStringLiteral("Name of output file")); QCoreApplication app(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("testvcalexport")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); parser.process(app); const QStringList parsedArgs = parser.positionalArguments(); if (parsedArgs.count() != 2) { parser.showHelp(); } QString input = parsedArgs[0]; QString output = parsedArgs[1]; QFileInfo outputFileInfo(output); output = outputFileInfo.absoluteFilePath(); qDebug() << "Input file:" << input; qDebug() << "Output file:" << output; MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); FileStorage instore(cal, input); if (!instore.load()) { return 1; } FileStorage outstore(cal, output, new VCalFormat); if (!outstore.save()) { return 1; } return 0; }