diff options
Diffstat (limited to 'tests/teststore.cpp')
-rw-r--r-- | tests/teststore.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/teststore.cpp b/tests/teststore.cpp index c69588ef..ad494d52 100644 --- a/tests/teststore.cpp +++ b/tests/teststore.cpp | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <KCalCore/Event> | 27 | #include <KCalCore/Event> |
28 | #include <KCalCore/ICalFormat> | 28 | #include <KCalCore/ICalFormat> |
29 | #include <KContacts/VCardConverter> | ||
29 | 30 | ||
30 | #include <QDebug> | 31 | #include <QDebug> |
31 | #include <QUuid> | 32 | #include <QUuid> |
@@ -186,6 +187,46 @@ static void createCalendar(const QVariantMap &object) | |||
186 | [calendarId](const QVariantMap &object) { createEvent(object, calendarId); }); | 187 | [calendarId](const QVariantMap &object) { createEvent(object, calendarId); }); |
187 | } | 188 | } |
188 | 189 | ||
190 | static void createContact(const QVariantMap &object, const QByteArray &addressbookId = {}) | ||
191 | { | ||
192 | using Sink::ApplicationDomain::ApplicationDomainType; | ||
193 | using Sink::ApplicationDomain::Contact; | ||
194 | |||
195 | QString uid; | ||
196 | if (object.contains("uid")) { | ||
197 | uid = object["uid"].toString(); | ||
198 | } else { | ||
199 | uid = QUuid::createUuid().toString(); | ||
200 | } | ||
201 | |||
202 | auto sinkContact = ApplicationDomainType::createEntity<Contact>(object["resource"].toByteArray()); | ||
203 | |||
204 | KContacts::Addressee addressee; | ||
205 | addressee.setUid(uid); | ||
206 | addressee.setGivenName(object["givenname"].toString()); | ||
207 | addressee.setFamilyName(object["familyname"].toString()); | ||
208 | |||
209 | KContacts::VCardConverter converter; | ||
210 | |||
211 | auto contact = ApplicationDomainType::createEntity<Contact>(object["resource"].toByteArray()); | ||
212 | contact.setVcard(converter.createVCard(addressee, KContacts::VCardConverter::v3_0)); | ||
213 | contact.setAddressbook(addressbookId); | ||
214 | |||
215 | Sink::Store::create(contact).exec().waitForFinished(); | ||
216 | } | ||
217 | |||
218 | static void createAddressbook(const QVariantMap &object) | ||
219 | { | ||
220 | using namespace Sink::ApplicationDomain; | ||
221 | auto addressbook = ApplicationDomainType::createEntity<Addressbook>(object["resource"].toByteArray()); | ||
222 | addressbook.setName(object["name"].toString()); | ||
223 | Sink::Store::create(addressbook).exec().waitForFinished(); | ||
224 | |||
225 | iterateOverObjects(object.value("contacts").toList(), [=](const QVariantMap &object) { | ||
226 | createContact(object, addressbook.identifier()); | ||
227 | }); | ||
228 | } | ||
229 | |||
189 | void TestStore::setup(const QVariantMap &map) | 230 | void TestStore::setup(const QVariantMap &map) |
190 | { | 231 | { |
191 | using namespace Sink::ApplicationDomain; | 232 | using namespace Sink::ApplicationDomain; |
@@ -215,6 +256,9 @@ void TestStore::setup(const QVariantMap &map) | |||
215 | } else if (object["type"] == "caldav") { | 256 | } else if (object["type"] == "caldav") { |
216 | resource.setResourceType("sink.caldav"); | 257 | resource.setResourceType("sink.caldav"); |
217 | resource.setProperty("testmode", true); | 258 | resource.setProperty("testmode", true); |
259 | } else if (object["type"] == "carddav") { | ||
260 | resource.setResourceType("sink.carddav"); | ||
261 | resource.setProperty("testmode", true); | ||
218 | } else { | 262 | } else { |
219 | Q_ASSERT(false); | 263 | Q_ASSERT(false); |
220 | } | 264 | } |
@@ -239,6 +283,7 @@ void TestStore::setup(const QVariantMap &map) | |||
239 | }); | 283 | }); |
240 | 284 | ||
241 | iterateOverObjects(map.value("calendars").toList(), createCalendar); | 285 | iterateOverObjects(map.value("calendars").toList(), createCalendar); |
286 | iterateOverObjects(map.value("addressbooks").toList(), createAddressbook); | ||
242 | 287 | ||
243 | Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); | 288 | Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); |
244 | } | 289 | } |