File indexing completed on 2024-11-24 04:44:10
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "contact.h" 0010 0011 #include <KCalendarCore/Event> 0012 #include <KCalendarCore/Journal> 0013 #include <KCalendarCore/Recurrence> 0014 #include <KCalendarCore/Todo> 0015 #include <QTest> 0016 0017 #include <kolabformat.h> 0018 0019 Q_DECLARE_METATYPE(Kolab::Duration) 0020 Q_DECLARE_METATYPE(Kolab::cDateTime) 0021 Q_DECLARE_METATYPE(std::vector<Kolab::cDateTime>) 0022 Q_DECLARE_METATYPE(Kolab::Event) 0023 Q_DECLARE_METATYPE(std::vector<Kolab::Event>) 0024 Q_DECLARE_METATYPE(Kolab::Todo) 0025 Q_DECLARE_METATYPE(Kolab::Journal) 0026 Q_DECLARE_METATYPE(Kolab::Contact) 0027 Q_DECLARE_METATYPE(Kolab::Period) 0028 Q_DECLARE_METATYPE(std::vector<Kolab::FreebusyPeriod>) 0029 0030 Q_DECLARE_METATYPE(KCalendarCore::Event) 0031 Q_DECLARE_METATYPE(KCalendarCore::Todo) 0032 Q_DECLARE_METATYPE(KCalendarCore::Journal) 0033 0034 namespace QTest 0035 { 0036 template<> 0037 char *toString(const Kolab::cDateTime &dt) 0038 { 0039 QByteArray ba = "Kolab::cDateTime("; 0040 ba += QByteArray::number(dt.year()) + ", " + QByteArray::number(dt.month()) + ", " + QByteArray::number(dt.day()) + ", "; 0041 ba += QByteArray::number(dt.hour()) + ", " + QByteArray::number(dt.minute()) + ", " + QByteArray::number(dt.second()) + ", "; 0042 ba += QByteArray(dt.isUTC() ? QByteArray("UTC") : QByteArray("TZ: " + QByteArray::fromStdString(dt.timezone()))); 0043 ba += ")"; 0044 return qstrdup(ba.data()); 0045 } 0046 0047 template<> 0048 char *toString(const KCalendarCore::Attendee &at) 0049 { 0050 QByteArray ba = "Attendee("; 0051 ba += at.name().toLatin1() + ", "; 0052 ba += at.email().toLatin1() + ", "; 0053 ba += QByteArray::number(at.role()) + ", "; 0054 ba += QByteArray::number(at.status()) + ", "; 0055 ba += QByteArray::number(at.RSVP()) + ", "; 0056 ba += at.delegate().toLatin1() + ", "; 0057 ba += at.delegator().toLatin1() + ", "; 0058 ba += at.uid().toLatin1() + ", "; 0059 ba += ")"; 0060 return qstrdup(ba.data()); 0061 } 0062 0063 template<> 0064 char *toString(const QList<int> &l) 0065 { 0066 QByteArray ba = "QList<int>("; 0067 for (int i : l) { 0068 ba += QByteArray::number(i) + ", "; 0069 } 0070 ba += ")"; 0071 return qstrdup(ba.data()); 0072 } 0073 0074 template<> 0075 char *toString(const QList<KCalendarCore::RecurrenceRule::WDayPos> &l) 0076 { 0077 QByteArray ba = "QList<int>("; 0078 for (const KCalendarCore::RecurrenceRule::WDayPos &i : l) { 0079 ba += QByteArray::number(i.pos()) + " "; 0080 ba += QByteArray::number(i.day()) + ", "; 0081 } 0082 ba += ")"; 0083 return qstrdup(ba.data()); 0084 } 0085 0086 template<> 0087 char *toString(const KCalendarCore::DateList &l) 0088 { 0089 QByteArray ba = "KCalendarCore::DateList("; 0090 for (const QDate &i : l) { 0091 ba += i.toString().toLatin1(); 0092 } 0093 ba += ")"; 0094 return qstrdup(ba.data()); 0095 } 0096 0097 template<> 0098 char *toString(const KCalendarCore::DateTimeList &l) 0099 { 0100 QByteArray ba = "KCalendarCore::DateTimeList("; 0101 for (const QDateTime &i : l) { 0102 ba += toString(i); 0103 } 0104 ba += ")"; 0105 return qstrdup(ba.data()); 0106 } 0107 0108 template<> 0109 char *toString(const KCalendarCore::Recurrence &at) 0110 { 0111 // at.dump(); 0112 KCalendarCore::RecurrenceRule *r = at.defaultRRule(); 0113 QByteArray ba; 0114 if (!r) { 0115 ba += "Recurrence( )"; 0116 } else { 0117 Q_ASSERT(r); 0118 Q_ASSERT(at.rRules().size() == 1); 0119 0120 ba += "Recurrence("; 0121 ba += QByteArray::number(r->recurrenceType()) + "\n"; 0122 ba += QByteArray::number(r->frequency()) + "\n"; 0123 ba += QByteArray::number(r->duration()) + "\n"; 0124 ba += QByteArray(toString(r->startDt())) + "\n"; 0125 ba += QByteArray(toString(r->endDt())) + "\n"; 0126 ba += QByteArray(toString(r->bySeconds())) + "\n"; 0127 ba += QByteArray(toString(r->byMinutes())) + "\n"; 0128 ba += QByteArray(toString(r->byHours())) + "\n"; 0129 ba += QByteArray(toString(r->byDays())) + "\n"; 0130 ba += QByteArray(toString(r->byMonthDays())) + "\n"; 0131 ba += QByteArray(toString(r->byYearDays())) + "\n"; 0132 ba += QByteArray(toString(r->byMonths())) + "\n"; 0133 ba += ")\n"; 0134 ba += QByteArray(toString(at.exDates())) + "\n"; 0135 ba += QByteArray(toString(at.exDateTimes())) + "\n"; 0136 ba += QByteArray(toString(at.rDates())) + "\n"; 0137 ba += QByteArray(toString(at.rDateTimes())) + "\n"; 0138 } 0139 return qstrdup(ba.data()); 0140 } 0141 0142 template<> 0143 char *toString(const Kolab::RecurrenceRule &at) 0144 { 0145 QByteArray ba; 0146 ba += "KolabRecurrenceRule("; 0147 ba += QByteArray::number(at.weekStart()) + "\n"; 0148 ba += QByteArray::number(at.frequency()) + "\n"; 0149 ba += QByteArray::number(at.interval()) + "\n"; 0150 ba += QByteArray::number(at.count()) + "\n"; 0151 ba += QByteArray(toString(at.end())) + "\n"; 0152 ba += QByteArray(toString(at.bysecond())) + "\n"; 0153 ba += QByteArray(toString(at.byminute())) + "\n"; 0154 ba += QByteArray(toString(at.byhour())) + "\n"; 0155 ba += QByteArray(toString(at.byday())) + "\n"; 0156 ba += QByteArray(toString(at.bymonthday())) + "\n"; 0157 ba += QByteArray(toString(at.byyearday())) + "\n"; 0158 ba += QByteArray(toString(at.byweekno())) + "\n"; 0159 ba += QByteArray(toString(at.bymonth())) + "\n"; 0160 ba += ")"; 0161 return qstrdup(ba.data()); 0162 } 0163 0164 template<> 0165 char *toString(const KCalendarCore::Duration &d) 0166 { 0167 QByteArray ba; 0168 ba += "KCalendarCore::Duration("; 0169 ba += QByteArray::number(d.isDaily()) + ", "; 0170 ba += QByteArray::number(d.value()) + " "; 0171 ba += ")"; 0172 return qstrdup(ba.data()); 0173 } 0174 0175 template<> 0176 char *toString(const Kolab::ContactReference &a) 0177 { 0178 QByteArray ba = "Kolab::ContactReference("; 0179 ba += QByteArray::fromStdString(a.email()) + ", "; 0180 ba += QByteArray::fromStdString(a.name()) + ", "; 0181 ba += QByteArray::fromStdString(a.uid()); 0182 ba += ")"; 0183 return qstrdup(ba.data()); 0184 } 0185 0186 template<> 0187 char *toString(const std::vector<Kolab::ContactReference> &v) 0188 { 0189 QByteArray ba = "vector<Kolab::ContactReference>("; 0190 for (std::size_t i = 0; i < v.size(); i++) { 0191 ba += QByteArray(toString(v.at(i))) + "\n"; 0192 } 0193 ba += ")"; 0194 return qstrdup(ba.data()); 0195 } 0196 0197 template<> 0198 char *toString(const Kolab::Attendee &a) 0199 { 0200 QByteArray ba = "Kolab::Attendee("; 0201 ba += QByteArray::fromStdString(a.contact().email()) + "\n"; 0202 ba += QByteArray::fromStdString(a.contact().name()) + "\n"; 0203 ba += QByteArray::number(a.partStat()) + "\n"; 0204 ba += QByteArray::number(a.role()) + "\n"; 0205 ba += QByteArray::number(a.rsvp()) + "\n"; 0206 ba += QByteArray::fromStdString(a.contact().uid()) + "\n"; 0207 ba += QByteArray(toString(a.delegatedTo())) + "\n"; 0208 ba += QByteArray(toString(a.delegatedFrom())) + "\n"; 0209 ba += QByteArray::number(a.cutype()) + "\n"; 0210 ba += ")"; 0211 return qstrdup(ba.data()); 0212 } 0213 0214 template<> 0215 char *toString(const std::vector<Kolab::Attendee> &v) 0216 { 0217 QByteArray ba = "vector<Kolab::Attendee>("; 0218 for (std::size_t i = 0; i < v.size(); i++) { 0219 ba += QByteArray(toString(v.at(i))) + "\n"; 0220 ba += QByteArray("#######################") + "\n"; 0221 } 0222 ba += ")"; 0223 return qstrdup(ba.data()); 0224 } 0225 0226 template<> 0227 char *toString(const Kolab::CustomProperty &a) 0228 { 0229 QByteArray ba = "Kolab::CustomProperty("; 0230 ba += QByteArray::fromStdString(a.identifier) + ", "; 0231 ba += QByteArray::fromStdString(a.value); 0232 ba += ")"; 0233 return qstrdup(ba.data()); 0234 } 0235 0236 template<> 0237 char *toString(const std::vector<Kolab::CustomProperty> &v) 0238 { 0239 QByteArray ba = "vector<Kolab::CustomProperty>("; 0240 for (std::size_t i = 0; i < v.size(); i++) { 0241 ba += QByteArray(toString(v.at(i))) + "\n"; 0242 } 0243 ba += ")"; 0244 return qstrdup(ba.data()); 0245 } 0246 0247 template<> 0248 char *toString(const Kolab::Period &p) 0249 { 0250 QByteArray ba = "Kolab::Period("; 0251 ba += QByteArray(toString(p.start)) + "\n"; 0252 ba += QByteArray(toString(p.end)) + "\n"; 0253 ba += ")"; 0254 return qstrdup(ba.data()); 0255 } 0256 0257 template<> 0258 char *toString(const std::vector<Kolab::Period> &v) 0259 { 0260 QByteArray ba = "vector<Kolab::Period>("; 0261 for (std::size_t i = 0; i < v.size(); i++) { 0262 ba += QByteArray(toString(v.at(i))) + "\n"; 0263 } 0264 ba += ")"; 0265 return qstrdup(ba.data()); 0266 } 0267 0268 template<> 0269 char *toString(const Kolab::FreebusyPeriod &p) 0270 { 0271 QByteArray ba = "Kolab::FreebusyPeriod("; 0272 ba += QByteArray::number(p.type()) + "\n"; 0273 ba += QByteArray::fromStdString(p.eventUid()) + "\n"; 0274 ba += QByteArray::fromStdString(p.eventLocation()) + "\n"; 0275 ba += QByteArray::fromStdString(p.eventSummary()) + "\n"; 0276 ba += QByteArray(toString(p.periods())) + "\n"; 0277 ba += ")"; 0278 return qstrdup(ba.data()); 0279 } 0280 0281 template<> 0282 char *toString(const Kolab::Duration &p) 0283 { 0284 QByteArray ba = "Kolab::Duration"; 0285 ba += p.isNegative() ? "-" : "+"; 0286 ba += "("; 0287 ba += QByteArray::number(p.weeks()) + ", "; 0288 ba += QByteArray::number(p.days()) + ", "; 0289 ba += QByteArray::number(p.hours()) + ", "; 0290 ba += QByteArray::number(p.minutes()) + ", "; 0291 ba += QByteArray::number(p.seconds()); 0292 ba += ")"; 0293 return qstrdup(ba.data()); 0294 } 0295 }