diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-20 15:50:52 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-20 15:50:52 +0200 |
commit | 7a456d8a8687d7a960c0f8c4bfb18eed3754404c (patch) | |
tree | fd3e77c5ff6885fcf5a1dd7e1722197904b6ec65 | |
parent | 43c4cd555e4a265d3e484dfeea0aa05da0977cd0 (diff) | |
download | sink-7a456d8a8687d7a960c0f8c4bfb18eed3754404c.tar.gz sink-7a456d8a8687d7a960c0f8c4bfb18eed3754404c.zip |
Test & fix live query removals
-rw-r--r-- | common/entitystorage.cpp | 3 | ||||
-rw-r--r-- | tests/dummyresourcetest.cpp | 50 |
2 files changed, 52 insertions, 1 deletions
diff --git a/common/entitystorage.cpp b/common/entitystorage.cpp index 63017dd..5d4df9f 100644 --- a/common/entitystorage.cpp +++ b/common/entitystorage.cpp | |||
@@ -27,7 +27,8 @@ ResultSet EntityStorageBase::filteredSet(const ResultSet &resultSet, const std:: | |||
27 | std::function<bool(std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &, Akonadi2::Operation)>)> generator = [this, resultSetPtr, &transaction, filter, initialQuery](std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &, Akonadi2::Operation)> callback) -> bool { | 27 | std::function<bool(std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &, Akonadi2::Operation)>)> generator = [this, resultSetPtr, &transaction, filter, initialQuery](std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &, Akonadi2::Operation)> callback) -> bool { |
28 | while (resultSetPtr->next()) { | 28 | while (resultSetPtr->next()) { |
29 | readEntity(transaction, resultSetPtr->id(), [this, filter, callback, initialQuery](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject, Akonadi2::Operation operation) { | 29 | readEntity(transaction, resultSetPtr->id(), [this, filter, callback, initialQuery](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject, Akonadi2::Operation operation) { |
30 | if (filter(domainObject)) { | 30 | //Always remove removals, they probably don't match due to non-available properties |
31 | if (filter(domainObject) || operation == Akonadi2::Operation_Removal) { | ||
31 | if (initialQuery) { | 32 | if (initialQuery) { |
32 | //We're not interested in removals during the initial query | 33 | //We're not interested in removals during the initial query |
33 | if (operation != Akonadi2::Operation_Removal) { | 34 | if (operation != Akonadi2::Operation_Removal) { |
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 93a6a9c..731f013 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp | |||
@@ -225,6 +225,56 @@ private Q_SLOTS: | |||
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | void testWriteModifyDeleteLive() | ||
229 | { | ||
230 | |||
231 | Akonadi2::Query query; | ||
232 | query.resources << "org.kde.dummy.instance1"; | ||
233 | query.syncOnDemand = false; | ||
234 | query.processAll = true; | ||
235 | query.liveQuery = true; | ||
236 | query.propertyFilter.insert("uid", "testuid"); | ||
237 | |||
238 | |||
239 | async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query)); | ||
240 | result.exec(); | ||
241 | |||
242 | Akonadi2::ApplicationDomain::Event event; | ||
243 | event.setProperty("uid", "testuid"); | ||
244 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | ||
245 | event.setProperty("summary", "summaryValue"); | ||
246 | Akonadi2::Store::create<Akonadi2::ApplicationDomain::Event>(event, "org.kde.dummy.instance1").exec().waitForFinished(); | ||
247 | |||
248 | //Test create | ||
249 | Akonadi2::ApplicationDomain::Event event2; | ||
250 | { | ||
251 | QTRY_COMPARE(result.size(), 1); | ||
252 | auto value = result.first(); | ||
253 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); | ||
254 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); | ||
255 | event2 = *value; | ||
256 | } | ||
257 | |||
258 | event2.setProperty("uid", "testuid"); | ||
259 | event2.setProperty("summary", "summaryValue2"); | ||
260 | Akonadi2::Store::modify<Akonadi2::ApplicationDomain::Event>(event2, "org.kde.dummy.instance1").exec().waitForFinished(); | ||
261 | |||
262 | //Test modify | ||
263 | { | ||
264 | QTRY_COMPARE(result.size(), 1); | ||
265 | auto value = result.first(); | ||
266 | QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); | ||
267 | QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); | ||
268 | } | ||
269 | |||
270 | Akonadi2::Store::remove<Akonadi2::ApplicationDomain::Event>(event2, "org.kde.dummy.instance1").exec().waitForFinished(); | ||
271 | |||
272 | //Test remove | ||
273 | { | ||
274 | QTRY_COMPARE(result.size(), 0); | ||
275 | } | ||
276 | } | ||
277 | |||
228 | }; | 278 | }; |
229 | 279 | ||
230 | QTEST_MAIN(DummyResourceTest) | 280 | QTEST_MAIN(DummyResourceTest) |