From afe656a428129d52675f9fecc11af330fea1d4c4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 2 Aug 2018 19:49:50 +0200 Subject: Carddav changereplay --- examples/carddavresource/tests/CMakeLists.txt | 2 +- examples/carddavresource/tests/carddavtest.cpp | 48 ++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) (limited to 'examples/carddavresource/tests') diff --git a/examples/carddavresource/tests/CMakeLists.txt b/examples/carddavresource/tests/CMakeLists.txt index e7e8c18..e59665e 100644 --- a/examples/carddavresource/tests/CMakeLists.txt +++ b/examples/carddavresource/tests/CMakeLists.txt @@ -6,4 +6,4 @@ include(SinkTest) auto_tests ( carddavtest ) -target_link_libraries(carddavtest sink_resource_carddav) +target_link_libraries(carddavtest sink_resource_carddav KF5::Contacts) diff --git a/examples/carddavresource/tests/carddavtest.cpp b/examples/carddavresource/tests/carddavtest.cpp index 6e7cf01..b0f41d1 100644 --- a/examples/carddavresource/tests/carddavtest.cpp +++ b/examples/carddavresource/tests/carddavtest.cpp @@ -12,10 +12,12 @@ #include #include #include +#include +#include -using Sink::ApplicationDomain::Calendar; -using Sink::ApplicationDomain::Event; +using Sink::ApplicationDomain::Addressbook; +using Sink::ApplicationDomain::Contact; using Sink::ApplicationDomain::SinkResource; class CardDavTest : public QObject @@ -109,6 +111,48 @@ private slots: QCOMPARE(contacts.size(), 2); } } + + void testSyncAddressbooks() + { + Sink::SyncScope scope; + scope.setType(); + scope.resourceFilter(mResourceInstanceIdentifier); + + VERIFYEXEC(Sink::Store::synchronize(scope)); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); + const auto addressbooks = Sink::Store::read(Sink::Query().resourceFilter(mResourceInstanceIdentifier)); + QCOMPARE(addressbooks.size(), 1); + } + + void testAddContact() + { + Sink::SyncScope scope; + scope.setType(); + scope.resourceFilter(mResourceInstanceIdentifier); + + VERIFYEXEC(Sink::Store::synchronize(scope)); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); + + auto addressbooks = Sink::Store::read(Sink::Query().resourceFilter(mResourceInstanceIdentifier)); + QVERIFY(!addressbooks.isEmpty()); + + KContacts::Addressee addressee; + addressee.setGivenName("John"); + addressee.setFamilyName("Doe"); + addressee.setFormattedName("John Doe"); + KContacts::VCardConverter converter; + const auto vcard = converter.createVCard(addressee, KContacts::VCardConverter::v3_0); + + Contact contact(mResourceInstanceIdentifier); + contact.setVcard(vcard); + contact.setAddressbook(addressbooks.first()); + + VERIFYEXEC(Sink::Store::create(contact)); + VERIFYEXEC(Sink::ResourceControl::flushReplayQueue(mResourceInstanceIdentifier)); + + auto contacts = Sink::Store::read({}); + QVERIFY(!contacts.isEmpty()); + } }; QTEST_MAIN(CardDavTest) -- cgit v1.2.3