File indexing completed on 2024-11-24 04:44:09
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #include "kcalconversiontest.h" 0008 #include "contact.h" 0009 0010 #include <KCalendarCore/Recurrence> 0011 #include <KContacts/Addressee> 0012 #include <QTest> 0013 #include <kolabcontact.h> 0014 0015 #include "conversion/kabcconversion.h" 0016 #include "conversion/kcalconversion.cpp" 0017 #include "conversion/kcalconversion.h" 0018 #include "testhelpers.h" 0019 0020 using namespace Kolab::Conversion; 0021 0022 template<typename T> 0023 void comparePointerVectors(const QList<T> &list, const QList<T> &other) 0024 { 0025 QCOMPARE(list.size(), other.size()); 0026 for (int i = 0; i < list.size(); i++) { 0027 QCOMPARE(*list.at(i), *other.at(i)); 0028 } 0029 } 0030 0031 void compareAttendeesVectors(const KCalendarCore::Attendee::List &list, const KCalendarCore::Attendee::List &other) 0032 { 0033 QCOMPARE(list.size(), other.size()); 0034 for (int i = 0; i < list.size(); i++) { 0035 KCalendarCore::Attendee at1 = list.at(i); 0036 at1.setUid(QString()); 0037 KCalendarCore::Attendee at2 = other.at(i); 0038 at2.setUid(QString()); 0039 QCOMPARE(at1, at2); 0040 } 0041 } 0042 0043 void KCalConversionTest::initTestCase() 0044 { 0045 } 0046 0047 void KCalConversionTest::testDate_data() 0048 { 0049 QTest::addColumn<Kolab::cDateTime>("input"); 0050 QTest::addColumn<QDateTime>("result"); 0051 0052 QTest::newRow("datetime with tz") << Kolab::cDateTime("Europe/Zurich", 2006, 1, 8, 12, 0, 0) 0053 << QDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), QTimeZone("Europe/Zurich")); 0054 QTest::newRow("floating datetime") << Kolab::cDateTime(2006, 1, 8, 12, 0, 0, false) << QDateTime(QDate(2006, 1, 8), QTime(12, 0, 0)); 0055 QTest::newRow("utc datetime") << Kolab::cDateTime(2006, 1, 8, 12, 0, 0, true) << QDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), Qt::UTC); 0056 QTest::newRow("date only") << Kolab::cDateTime(2006, 1, 8) << QDateTime(QDate(2006, 1, 8), {}); 0057 } 0058 0059 void KCalConversionTest::testDate() 0060 { 0061 QFETCH(Kolab::cDateTime, input); 0062 QFETCH(QDateTime, result); 0063 0064 const QDateTime &r = Kolab::Conversion::toDate(input); 0065 QCOMPARE(r, result); 0066 0067 const Kolab::cDateTime &r2 = Kolab::Conversion::fromDate(result, input.isDateOnly()); 0068 QCOMPARE(r2, input); 0069 } 0070 0071 void KCalConversionTest::testDuration_data() 0072 { 0073 QTest::addColumn<Kolab::Duration>("input"); 0074 QTest::addColumn<KCalendarCore::Duration>("result"); 0075 QTest::addColumn<Kolab::Duration>("fromResult"); 0076 0077 QTest::newRow("seconds") << Kolab::Duration(0, 0, 0, 30, false) << KCalendarCore::Duration(30, KCalendarCore::Duration::Seconds) 0078 << Kolab::Duration(0, 0, 0, 30, false); 0079 QTest::newRow("minutes") << Kolab::Duration(0, 0, 1, 30, false) << KCalendarCore::Duration(90, KCalendarCore::Duration::Seconds) 0080 << Kolab::Duration(0, 0, 0, 90, false); 0081 QTest::newRow("hours") << Kolab::Duration(0, 1, 1, 30, false) << KCalendarCore::Duration(60 * 60 + 90, KCalendarCore::Duration::Seconds) 0082 << Kolab::Duration(0, 0, 0, 60 * 60 + 90, false); 0083 QTest::newRow("days") << Kolab::Duration(1, 1, 1, 30, false) << KCalendarCore::Duration(24 * 60 * 60 + 60 * 60 + 90, KCalendarCore::Duration::Seconds) 0084 << Kolab::Duration(0, 0, 0, 24 * 60 * 60 + 60 * 60 + 90, false); 0085 QTest::newRow("daysonly") << Kolab::Duration(30, 0, 0, 0, false) << KCalendarCore::Duration(30, KCalendarCore::Duration::Days) 0086 << Kolab::Duration(30, 0, 0, 0, false); 0087 QTest::newRow("weeks") << Kolab::Duration(30, false) << KCalendarCore::Duration(30 * 7, KCalendarCore::Duration::Days) 0088 << Kolab::Duration(30 * 7, 0, 0, 0, false); 0089 } 0090 0091 void KCalConversionTest::testDuration() 0092 { 0093 QFETCH(Kolab::Duration, input); 0094 QFETCH(KCalendarCore::Duration, result); 0095 QFETCH(Kolab::Duration, fromResult); 0096 0097 const KCalendarCore::Duration &r = Kolab::Conversion::toDuration(input); 0098 QCOMPARE(r, result); 0099 0100 const Kolab::Duration &r2 = Kolab::Conversion::fromDuration(result); 0101 QCOMPARE(r2, fromResult); 0102 } 0103 0104 void KCalConversionTest::testDateTZ_data() 0105 { 0106 QTest::addColumn<Kolab::cDateTime>("input"); 0107 QTest::addColumn<QDateTime>("result"); 0108 0109 QTest::newRow("berlin") << Kolab::cDateTime("Europe/Berlin", 2006, 1, 8, 12, 0, 0) 0110 << QDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), QTimeZone("Europe/Berlin")); 0111 } 0112 0113 void KCalConversionTest::testDateTZ() 0114 { 0115 QFETCH(Kolab::cDateTime, input); 0116 QFETCH(QDateTime, result); 0117 0118 const QDateTime &r = Kolab::Conversion::toDate(input); 0119 QCOMPARE(QString::fromUtf8(result.timeZone().id()), QString::fromStdString(input.timezone())); 0120 QCOMPARE(r.timeZone().offsetFromUtc(QDateTime::currentDateTimeUtc()), result.timeZone().offsetFromUtc(QDateTime::currentDateTimeUtc())); 0121 0122 const Kolab::cDateTime &r2 = Kolab::Conversion::fromDate(result, input.isDateOnly()); 0123 QCOMPARE(QString::fromStdString(r2.timezone()), QString::fromUtf8(result.timeZone().id())); 0124 } 0125 0126 void KCalConversionTest::testConversion_data() 0127 { 0128 QTest::addColumn<KCalendarCore::Event>("kcal"); 0129 QTest::addColumn<Kolab::Event>("kolab"); 0130 0131 Kolab::cDateTime date(2011, 2, 2, 12, 11, 10, true); 0132 Kolab::cDateTime date2(2011, 2, 2, 12, 12, 10, true); 0133 Kolab::cDateTime date3(2012, 2, 2, 12, 12, 10, true); 0134 std::vector<int> intVector; 0135 intVector.push_back(1); 0136 intVector.push_back(-3); 0137 intVector.push_back(2); 0138 std::vector<std::string> stringVector; 0139 stringVector.emplace_back("cat1"); 0140 stringVector.emplace_back("cat2"); 0141 stringVector.emplace_back("parent/child"); 0142 0143 { 0144 KCalendarCore::Event kcal; 0145 kcal.setUid(QStringLiteral("uid")); 0146 kcal.setCreated(toDate(date)); 0147 kcal.setLastModified(toDate(date)); 0148 kcal.setRevision(3); 0149 kcal.setSecrecy(KCalendarCore::Incidence::SecrecyConfidential); 0150 kcal.setCategories(toStringList(stringVector)); 0151 kcal.setDtStart(toDate(date)); 0152 kcal.setDtEnd(toDate(date2)); 0153 kcal.setAllDay(date.isDateOnly()); 0154 kcal.setTransparency(KCalendarCore::Event::Transparent); 0155 0156 kcal.setRecurrenceId(toDate(date2)); // TODO THISANDFUTURE 0157 kcal.recurrence()->setDaily(3); 0158 kcal.recurrence()->setDuration(5); 0159 kcal.recurrence()->addRDateTime(toDate(date2)); 0160 kcal.recurrence()->addRDate(toDate(date2).date()); 0161 kcal.recurrence()->addExDateTime(toDate(date3)); 0162 kcal.recurrence()->addExDate(toDate(date3).date()); 0163 0164 KCalendarCore::RecurrenceRule *rr = kcal.recurrence()->defaultRRule(true); 0165 QList<int> intList(intVector.cbegin(), intVector.cend()); 0166 rr->setBySeconds(intList); 0167 rr->setByMinutes(intList); 0168 rr->setByHours(intList); 0169 rr->setByDays(QList<KCalendarCore::RecurrenceRule::WDayPos>() 0170 << KCalendarCore::RecurrenceRule::WDayPos(3, 1) << KCalendarCore::RecurrenceRule::WDayPos(5, 4)); 0171 rr->setByMonthDays(intList); 0172 rr->setByYearDays(intList); 0173 rr->setByMonths(intList); 0174 rr->setByWeekNumbers(intList); 0175 0176 kcal.setSummary(QStringLiteral("summary")); 0177 kcal.setDescription(QStringLiteral("description")); 0178 kcal.setPriority(3); 0179 kcal.setStatus(KCalendarCore::Incidence::StatusConfirmed); 0180 kcal.setLocation(QStringLiteral("location")); 0181 kcal.setOrganizer(KCalendarCore::Person(QStringLiteral("organizer"), QStringLiteral("organizer@email"))); 0182 // Url 0183 kcal.setNonKDECustomProperty("X-KOLAB-URL", QStringLiteral("http://test.org")); 0184 KCalendarCore::Attendee att(QStringLiteral("attendee"), 0185 QStringLiteral("attendee@email"), 0186 false, 0187 KCalendarCore::Attendee::NeedsAction, 0188 KCalendarCore::Attendee::ReqParticipant); 0189 att.setDelegate(QStringLiteral("mailto:delegatee<delegatee@email>")); 0190 att.setDelegator(QStringLiteral("mailto:delegator<delegator@email>")); 0191 kcal.addAttendee(att); 0192 kcal.addAttachment(KCalendarCore::Attachment(QStringLiteral("uri"), QStringLiteral("mimetype/mime"))); 0193 KCalendarCore::Alarm::Ptr alarm = KCalendarCore::Alarm::Ptr(new KCalendarCore::Alarm(&kcal)); 0194 KCalendarCore::Person::List addressees; 0195 addressees.append(KCalendarCore::Person(QStringLiteral("name"), QStringLiteral("email@email"))); 0196 alarm->setEmailAlarm(QStringLiteral("subject"), QStringLiteral("text"), addressees, QStringList()); // No support for attachments 0197 kcal.addAlarm(alarm); 0198 // TODO alarms 0199 0200 kcal.setNonKDECustomProperty("X-KOLAB-key1", QStringLiteral("value1")); 0201 kcal.setNonKDECustomProperty("X-KOLAB-key2", QStringLiteral("value2")); 0202 kcal.setCustomProperty("SOMEOTHERAPP", "key2", QStringLiteral("value2")); 0203 Q_ASSERT(kcal.nonKDECustomProperty("X-KOLAB-key1") == QLatin1StringView("value1")); 0204 0205 Kolab::Event kolab; 0206 kolab.setUid("uid"); 0207 kolab.setCreated(date); 0208 kolab.setLastModified(date); 0209 kolab.setSequence(3); 0210 kolab.setClassification(Kolab::ClassConfidential); 0211 kolab.setCategories(stringVector); 0212 kolab.setStart(date); 0213 kolab.setEnd(date2); 0214 kolab.setTransparency(true); 0215 0216 Kolab::RecurrenceRule rrule; 0217 rrule.setInterval(3); 0218 rrule.setFrequency(Kolab::RecurrenceRule::Daily); 0219 rrule.setCount(5); 0220 rrule.setBysecond(intVector); 0221 rrule.setByminute(intVector); 0222 rrule.setByhour(intVector); 0223 rrule.setByday(std::vector<Kolab::DayPos>() << Kolab::DayPos(3, Kolab::Monday) << Kolab::DayPos(5, Kolab::Thursday)); 0224 rrule.setBymonthday(intVector); 0225 rrule.setByyearday(intVector); 0226 rrule.setByweekno(intVector); 0227 rrule.setBymonth(intVector); 0228 0229 kolab.setRecurrenceRule(rrule); 0230 kolab.setRecurrenceID(date2, true); 0231 kolab.setRecurrenceDates(std::vector<Kolab::cDateTime>() << date2 << Kolab::cDateTime(date2.year(), date2.month(), date2.day())); 0232 kolab.setExceptionDates(std::vector<Kolab::cDateTime>() << date3 << Kolab::cDateTime(date3.year(), date3.month(), date3.day())); 0233 0234 kolab.setSummary("summary"); 0235 kolab.setDescription("description"); 0236 kolab.setPriority(3); 0237 kolab.setStatus(Kolab::StatusConfirmed); 0238 kolab.setLocation("location"); 0239 kolab.setOrganizer(Kolab::ContactReference(Kolab::ContactReference::EmailReference, "organizer@email", "organizer")); // TODO uid 0240 kolab.setUrl("http://test.org"); 0241 0242 Kolab::Attendee a(Kolab::ContactReference(Kolab::ContactReference::EmailReference, "attendee@email", "attendee")); // TODO uid 0243 a.setDelegatedTo(std::vector<Kolab::ContactReference>() 0244 << Kolab::ContactReference(Kolab::ContactReference::EmailReference, "delegatee@email", "delegatee")); 0245 a.setDelegatedFrom(std::vector<Kolab::ContactReference>() 0246 << Kolab::ContactReference(Kolab::ContactReference::EmailReference, "delegator@email", "delegator")); 0247 a.setCutype(Kolab::CutypeIndividual); 0248 kolab.setAttendees(std::vector<Kolab::Attendee>() << a); 0249 0250 Kolab::Attachment attach; 0251 attach.setUri("uri", "mimetype/mime"); 0252 kolab.setAttachments(std::vector<Kolab::Attachment>() << attach); 0253 0254 // std::vector<std::string> receipents; 0255 // receipents.push_back("email@email"); 0256 // Kolab::Alarm alarm2("summary", "description", receipents); 0257 // kolab.setAlarms(std::vector<Kolab::Alarm>() << alarm2); 0258 0259 // The sorting is random, just sort them here how we think they should arrive so we don't have to sort during compare (due to laziness). 0260 std::vector<Kolab::CustomProperty> customproperties; 0261 customproperties.emplace_back("X-KDE-SOMEOTHERAPP-key2", "value2"); 0262 customproperties.emplace_back("key1", "value1"); 0263 customproperties.emplace_back("key2", "value2"); 0264 0265 kolab.setCustomProperties(customproperties); 0266 0267 QTest::newRow("with endDate and recurrence duration") << kcal << kolab; 0268 } 0269 { 0270 KCalendarCore::Event kcal; 0271 kcal.setUid(QStringLiteral("uid")); 0272 kcal.setCreated(toDate(date)); 0273 kcal.setLastModified(toDate(date)); 0274 kcal.setRevision(3); 0275 kcal.setDtStart(toDate(date)); 0276 kcal.setAllDay(date.isDateOnly()); 0277 kcal.setDuration(KCalendarCore::Duration(toDate(date), toDate(date2))); 0278 kcal.recurrence()->setDaily(3); 0279 kcal.recurrence()->setEndDateTime(toDate(date3)); 0280 0281 Kolab::Event kolab; 0282 kolab.setUid("uid"); 0283 kolab.setCreated(date); 0284 kolab.setLastModified(date); 0285 kolab.setSequence(3); 0286 kolab.setStart(date); 0287 kolab.setDuration(Kolab::Duration(0, 0, 1, 0)); 0288 Kolab::RecurrenceRule rrule; 0289 rrule.setInterval(3); 0290 rrule.setFrequency(Kolab::RecurrenceRule::Daily); 0291 rrule.setEnd(date3); 0292 kolab.setRecurrenceRule(rrule); 0293 0294 QTest::newRow("with duration and recurrence endDate") << kcal << kolab; 0295 } 0296 { 0297 Kolab::cDateTime start(2011, 1, 1); 0298 Kolab::cDateTime end(2011, 1, 3); 0299 0300 KCalendarCore::Event kcal; 0301 kcal.setUid(QStringLiteral("uid")); 0302 kcal.setCreated(toDate(date)); 0303 kcal.setLastModified(toDate(date)); 0304 kcal.setDtStart(toDate(start)); 0305 kcal.setDtEnd(toDate(end)); 0306 kcal.setAllDay(start.isDateOnly()); 0307 kcal.recurrence()->setDaily(3); 0308 kcal.recurrence()->setEndDateTime(toDate(end)); 0309 0310 Kolab::Event kolab; 0311 kolab.setUid("uid"); 0312 kolab.setCreated(date); 0313 kolab.setLastModified(date); 0314 kolab.setStart(start); 0315 kolab.setEnd(end); 0316 Kolab::RecurrenceRule rrule; 0317 rrule.setInterval(3); 0318 rrule.setFrequency(Kolab::RecurrenceRule::Daily); 0319 rrule.setEnd(end); 0320 kolab.setRecurrenceRule(rrule); 0321 0322 QTest::newRow("date only dates") << kcal << kolab; 0323 } 0324 { 0325 KCalendarCore::Event kcal; 0326 kcal.setUid(QStringLiteral("uid")); 0327 kcal.setCreated(toDate(date)); 0328 kcal.setLastModified(toDate(date)); 0329 kcal.setDtStart(toDate(date)); 0330 kcal.setAllDay(date.isDateOnly()); 0331 kcal.setSummary(QStringLiteral("äöü%@$£é¤¼²°€Š�")); 0332 0333 Kolab::Event kolab; 0334 kolab.setUid("uid"); 0335 kolab.setCreated(date); 0336 kolab.setLastModified(date); 0337 kolab.setStart(date); 0338 kolab.setSummary(std::string(QStringLiteral("äöü%@$£é¤¼²°€Š�").toUtf8().constData())); 0339 0340 QTest::newRow("latin1+Unicode") << kcal << kolab; 0341 } 0342 } 0343 0344 void KCalConversionTest::testConversion() 0345 { 0346 QFETCH(KCalendarCore::Event, kcal); 0347 QFETCH(Kolab::Event, kolab); 0348 0349 KCalendarCore::Event::Ptr e = toKCalendarCore(kolab); 0350 const Kolab::Event &b = fromKCalendarCore(kcal); 0351 0352 QCOMPARE(e->uid(), kcal.uid()); 0353 QCOMPARE(e->created(), kcal.created()); 0354 QCOMPARE(e->lastModified(), kcal.lastModified()); 0355 QCOMPARE(e->revision(), kcal.revision()); 0356 QCOMPARE(e->secrecy(), kcal.secrecy()); 0357 QCOMPARE(e->categories(), kcal.categories()); 0358 QCOMPARE(e->dtStart(), kcal.dtStart()); 0359 QCOMPARE(e->dtEnd(), kcal.dtEnd()); 0360 QCOMPARE(e->duration(), kcal.duration()); 0361 QCOMPARE(e->transparency(), kcal.transparency()); 0362 QCOMPARE(*e->recurrence(), *kcal.recurrence()); 0363 QCOMPARE(e->recurrenceId(), kcal.recurrenceId()); 0364 QCOMPARE(e->recurrenceType(), kcal.recurrenceType()); 0365 QCOMPARE(e->summary(), kcal.summary()); 0366 QCOMPARE(e->description(), kcal.description()); 0367 QCOMPARE(e->priority(), kcal.priority()); 0368 QCOMPARE(e->status(), kcal.status()); 0369 QCOMPARE(e->location(), kcal.location()); 0370 QCOMPARE(e->organizer().name(), kcal.organizer().name()); 0371 QCOMPARE(e->organizer().email(), kcal.organizer().email()); 0372 QCOMPARE(e->nonKDECustomProperty("X-KOLAB-URL"), kcal.nonKDECustomProperty("X-KOLAB-URL")); 0373 // otherwise we'd break the customProperties comparison 0374 e->removeNonKDECustomProperty("X-KOLAB-URL"); 0375 kcal.removeNonKDECustomProperty("X-KOLAB-URL"); 0376 compareAttendeesVectors(e->attendees(), kcal.attendees()); 0377 QCOMPARE(e->attachments(), kcal.attachments()); 0378 0379 // QCOMPARE(e->alarms(), kcal.alarms()); //TODO 0380 QCOMPARE(e->customProperties(), kcal.customProperties()); 0381 0382 // QBENCHMARK { 0383 // toKCalendarCore(kolab); 0384 // } 0385 0386 QCOMPARE(b.uid(), kolab.uid()); 0387 QCOMPARE(b.created(), kolab.created()); 0388 QCOMPARE(b.lastModified(), kolab.lastModified()); 0389 QCOMPARE(b.sequence(), kolab.sequence()); 0390 QCOMPARE(b.classification(), kolab.classification()); 0391 QCOMPARE(b.categories(), kolab.categories()); 0392 QCOMPARE(b.start(), kolab.start()); 0393 QCOMPARE(b.end(), kolab.end()); 0394 QCOMPARE(b.duration(), kolab.duration()); 0395 QCOMPARE(b.transparency(), kolab.transparency()); 0396 0397 QCOMPARE(b.recurrenceRule(), kolab.recurrenceRule()); 0398 QCOMPARE(b.recurrenceID(), kolab.recurrenceID()); 0399 QCOMPARE(b.recurrenceDates(), kolab.recurrenceDates()); 0400 QCOMPARE(b.exceptionDates(), kolab.exceptionDates()); 0401 0402 QCOMPARE(b.summary(), kolab.summary()); 0403 QCOMPARE(b.description(), kolab.description()); 0404 QCOMPARE(b.status(), kolab.status()); 0405 QCOMPARE(b.location(), kolab.location()); 0406 QCOMPARE(b.organizer(), kolab.organizer()); 0407 QCOMPARE(b.url(), kolab.url()); 0408 QCOMPARE(b.attendees(), kolab.attendees()); 0409 QCOMPARE(b.attachments(), kolab.attachments()); 0410 QCOMPARE(b.customProperties(), kolab.customProperties()); 0411 } 0412 0413 void KCalConversionTest::testTodoConversion_data() 0414 { 0415 QTest::addColumn<KCalendarCore::Todo>("kcal"); 0416 QTest::addColumn<Kolab::Todo>("kolab"); 0417 0418 Kolab::cDateTime date(2011, 2, 2, 12, 11, 10, true); 0419 Kolab::cDateTime date2(2011, 2, 2, 12, 12, 10, true); 0420 0421 { 0422 KCalendarCore::Todo kcal; 0423 kcal.setUid(QStringLiteral("uid")); 0424 kcal.setDtStart(toDate(date)); 0425 kcal.setDtDue(toDate(date2)); 0426 kcal.setAllDay(date.isDateOnly()); 0427 kcal.setRelatedTo(QStringLiteral("uid2"), KCalendarCore::Incidence::RelTypeParent); 0428 0429 Kolab::Todo kolab; 0430 kolab.setUid("uid"); 0431 kolab.setStart(date); 0432 kolab.setDue(date2); 0433 std::vector<std::string> relateds; 0434 relateds.emplace_back("uid2"); 0435 kolab.setRelatedTo(relateds); 0436 0437 QTest::newRow("todo") << kcal << kolab; 0438 } 0439 } 0440 0441 void KCalConversionTest::testTodoConversion() 0442 { 0443 QFETCH(KCalendarCore::Todo, kcal); 0444 QFETCH(Kolab::Todo, kolab); 0445 0446 const KCalendarCore::Todo::Ptr e = toKCalendarCore(kolab); 0447 0448 QCOMPARE(e->uid(), kcal.uid()); 0449 QCOMPARE(e->dtStart(), kcal.dtStart()); 0450 QCOMPARE(e->dtDue(), kcal.dtDue()); 0451 QCOMPARE(e->relatedTo(KCalendarCore::Incidence::RelTypeParent), kcal.relatedTo(KCalendarCore::Incidence::RelTypeParent)); 0452 0453 const Kolab::Todo &b = fromKCalendarCore(kcal); 0454 QCOMPARE(b.uid(), kolab.uid()); 0455 QCOMPARE(b.start(), kolab.start()); 0456 QCOMPARE(b.due(), kolab.due()); 0457 QCOMPARE(b.relatedTo(), kolab.relatedTo()); 0458 } 0459 0460 void KCalConversionTest::testJournalConversion_data() 0461 { 0462 QTest::addColumn<KCalendarCore::Journal>("kcal"); 0463 QTest::addColumn<Kolab::Journal>("kolab"); 0464 0465 Kolab::cDateTime date(2011, 2, 2, 12, 11, 10, true); 0466 Kolab::cDateTime date2(2011, 2, 2, 12, 12, 10, true); 0467 0468 { 0469 KCalendarCore::Journal kcal; 0470 kcal.setUid(QStringLiteral("uid")); 0471 kcal.setDtStart(toDate(date)); 0472 kcal.setSummary(QStringLiteral("summary")); 0473 0474 Kolab::Journal kolab; 0475 kolab.setUid("uid"); 0476 kolab.setStart(date); 0477 kolab.setSummary("summary"); 0478 0479 QTest::newRow("journal") << kcal << kolab; 0480 } 0481 } 0482 0483 void KCalConversionTest::testJournalConversion() 0484 { 0485 QFETCH(KCalendarCore::Journal, kcal); 0486 QFETCH(Kolab::Journal, kolab); 0487 0488 const KCalendarCore::Journal::Ptr e = toKCalendarCore(kolab); 0489 0490 QCOMPARE(e->uid(), kcal.uid()); 0491 QCOMPARE(e->dtStart(), kcal.dtStart()); 0492 QCOMPARE(e->summary(), kcal.summary()); 0493 0494 const Kolab::Journal &b = fromKCalendarCore(kcal); 0495 QCOMPARE(b.uid(), kolab.uid()); 0496 QCOMPARE(b.start(), kolab.start()); 0497 QCOMPARE(b.summary(), kolab.summary()); 0498 } 0499 0500 void KCalConversionTest::testContactConversion_data() 0501 { 0502 QTest::addColumn<KContacts::Addressee>("kcal"); 0503 QTest::addColumn<Kolab::Contact>("kolab"); 0504 0505 { 0506 KContacts::Addressee kcal; 0507 kcal.setUid(QStringLiteral("uid")); 0508 kcal.setFormattedName(QStringLiteral("name")); 0509 0510 Kolab::Contact kolab; 0511 kolab.setUid("uid"); 0512 kolab.setName("name"); 0513 0514 QTest::newRow("basic") << kcal << kolab; 0515 } 0516 { 0517 KContacts::Addressee kcal; 0518 kcal.setUid(QStringLiteral("uid")); 0519 kcal.setFormattedName(QStringLiteral("name")); 0520 kcal.setBirthday(QDate(2012, 2, 2).startOfDay()); 0521 0522 // Because QDateTime doesn't know date-only values we always end up with a date-time 0523 Kolab::Contact kolab; 0524 kolab.setUid("uid"); 0525 kolab.setName("name"); 0526 kolab.setBDay(Kolab::cDateTime(2012, 2, 2, 0, 0, 0)); 0527 0528 QTest::newRow("bday") << kcal << kolab; 0529 } 0530 { 0531 KContacts::Addressee kcal; 0532 kcal.setUid(QStringLiteral("uid")); 0533 // The first address is always the preferred 0534 kcal.setEmails(QStringList() << QStringLiteral("email1@example.org") << QStringLiteral("email2@example.org")); 0535 kcal.insertCustom(QStringLiteral("KOLAB"), QStringLiteral("EmailTypesemail1@example.org"), QStringLiteral("home,work")); 0536 0537 Kolab::Contact kolab; 0538 kolab.setUid("uid"); 0539 0540 Kolab::Email email1("email1@example.org", Kolab::Email::Work | Kolab::Email::Home); 0541 Kolab::Email email2("email2@example.org"); 0542 0543 std::vector<Kolab::Email> emails; 0544 emails.push_back(email1); 0545 emails.push_back(email2); 0546 kolab.setEmailAddresses(emails, 0); 0547 0548 QTest::newRow("emailTypesAndPreference") << kcal << kolab; 0549 } 0550 } 0551 0552 void KCalConversionTest::testContactConversion() 0553 { 0554 QFETCH(KContacts::Addressee, kcal); 0555 QFETCH(Kolab::Contact, kolab); 0556 0557 const KContacts::Addressee &e = toKABC(kolab); 0558 0559 QCOMPARE(e.uid(), kcal.uid()); 0560 QCOMPARE(e.formattedName(), kcal.formattedName()); 0561 QCOMPARE(e.emails(), kcal.emails()); 0562 QCOMPARE(e.preferredEmail(), kcal.preferredEmail()); 0563 const auto mails{e.emails()}; 0564 for (const QString &mail : mails) { 0565 QCOMPARE(e.custom(QLatin1StringView("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(mail)), 0566 kcal.custom(QLatin1StringView("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(mail))); 0567 } 0568 QCOMPARE(e.birthday(), kcal.birthday()); 0569 0570 const Kolab::Contact &b = fromKABC(kcal); 0571 QCOMPARE(b.uid(), kolab.uid()); 0572 QCOMPARE(b.name(), kolab.name()); 0573 QCOMPARE(b.emailAddresses(), kolab.emailAddresses()); 0574 QCOMPARE(b.emailAddressPreferredIndex(), kolab.emailAddressPreferredIndex()); 0575 QCOMPARE(b.bDay(), kolab.bDay()); 0576 } 0577 0578 // void KCalConversionTest::BenchmarkRoundtripKCAL() 0579 // { 0580 // const Kolab::Event &event = Kolab::readEvent(TEST_DATA_PATH "/testfiles/icalEvent.xml", true); 0581 // std::string result = Kolab::writeEvent(event); 0582 // QBENCHMARK { 0583 // Kolab::Conversion::toKCalendarCore(Kolab::readEvent(result, false)); 0584 // } 0585 // } 0586 0587 QTEST_MAIN(KCalConversionTest) 0588 0589 #include "moc_kcalconversiontest.cpp"