diff options
Diffstat (limited to 'examples/carddavresource/tests/carddavtest.cpp')
-rw-r--r-- | examples/carddavresource/tests/carddavtest.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
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 @@ | |||
12 | #include <KDAV2/DavItemCreateJob> | 12 | #include <KDAV2/DavItemCreateJob> |
13 | #include <KDAV2/DavCollectionsFetchJob> | 13 | #include <KDAV2/DavCollectionsFetchJob> |
14 | #include <KDAV2/DavCollection> | 14 | #include <KDAV2/DavCollection> |
15 | #include <KContacts/Addressee> | ||
16 | #include <KContacts/VCardConverter> | ||
15 | 17 | ||
16 | 18 | ||
17 | using Sink::ApplicationDomain::Calendar; | 19 | using Sink::ApplicationDomain::Addressbook; |
18 | using Sink::ApplicationDomain::Event; | 20 | using Sink::ApplicationDomain::Contact; |
19 | using Sink::ApplicationDomain::SinkResource; | 21 | using Sink::ApplicationDomain::SinkResource; |
20 | 22 | ||
21 | class CardDavTest : public QObject | 23 | class CardDavTest : public QObject |
@@ -109,6 +111,48 @@ private slots: | |||
109 | QCOMPARE(contacts.size(), 2); | 111 | QCOMPARE(contacts.size(), 2); |
110 | } | 112 | } |
111 | } | 113 | } |
114 | |||
115 | void testSyncAddressbooks() | ||
116 | { | ||
117 | Sink::SyncScope scope; | ||
118 | scope.setType<Addressbook>(); | ||
119 | scope.resourceFilter(mResourceInstanceIdentifier); | ||
120 | |||
121 | VERIFYEXEC(Sink::Store::synchronize(scope)); | ||
122 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); | ||
123 | const auto addressbooks = Sink::Store::read<Addressbook>(Sink::Query().resourceFilter(mResourceInstanceIdentifier)); | ||
124 | QCOMPARE(addressbooks.size(), 1); | ||
125 | } | ||
126 | |||
127 | void testAddContact() | ||
128 | { | ||
129 | Sink::SyncScope scope; | ||
130 | scope.setType<Addressbook>(); | ||
131 | scope.resourceFilter(mResourceInstanceIdentifier); | ||
132 | |||
133 | VERIFYEXEC(Sink::Store::synchronize(scope)); | ||
134 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); | ||
135 | |||
136 | auto addressbooks = Sink::Store::read<Addressbook>(Sink::Query().resourceFilter(mResourceInstanceIdentifier)); | ||
137 | QVERIFY(!addressbooks.isEmpty()); | ||
138 | |||
139 | KContacts::Addressee addressee; | ||
140 | addressee.setGivenName("John"); | ||
141 | addressee.setFamilyName("Doe"); | ||
142 | addressee.setFormattedName("John Doe"); | ||
143 | KContacts::VCardConverter converter; | ||
144 | const auto vcard = converter.createVCard(addressee, KContacts::VCardConverter::v3_0); | ||
145 | |||
146 | Contact contact(mResourceInstanceIdentifier); | ||
147 | contact.setVcard(vcard); | ||
148 | contact.setAddressbook(addressbooks.first()); | ||
149 | |||
150 | VERIFYEXEC(Sink::Store::create(contact)); | ||
151 | VERIFYEXEC(Sink::ResourceControl::flushReplayQueue(mResourceInstanceIdentifier)); | ||
152 | |||
153 | auto contacts = Sink::Store::read<Contact>({}); | ||
154 | QVERIFY(!contacts.isEmpty()); | ||
155 | } | ||
112 | }; | 156 | }; |
113 | 157 | ||
114 | QTEST_MAIN(CardDavTest) | 158 | QTEST_MAIN(CardDavTest) |