From 10d19014fe2c9c02f2bc3e19732cbe340e316076 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 10 Nov 2015 12:05:39 +0100 Subject: A result model The result model drives the data retrieval and provides the interace for consumers --- tests/CMakeLists.txt | 2 + tests/clientapitest.cpp | 117 ++++++++++++++++++++++++++++++++++++++---------- tests/querytest.cpp | 100 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+), 23 deletions(-) create mode 100644 tests/querytest.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5629cdb..9ed5a76 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,8 +45,10 @@ auto_tests ( genericfacadetest resourcecommunicationtest pipelinetest + querytest ) target_link_libraries(dummyresourcetest akonadi2_resource_dummy) target_link_libraries(dummyresourcebenchmark akonadi2_resource_dummy) +target_link_libraries(querytest akonadi2_resource_dummy) diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 665d29b..5bfad4b 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -6,28 +6,45 @@ #include "facade.h" #include "synclistresult.h" #include "resourceconfig.h" +#include "modelresult.h" +#include "resultprovider.h" -class DummyResourceFacade : public Akonadi2::StoreFacade +template +class DummyResourceFacade : public Akonadi2::StoreFacade { public: + static std::shared_ptr > registerFacade() + { + auto facade = std::make_shared >(); + Akonadi2::FacadeFactory::instance().registerFacade >("dummyresource", + [facade](const QByteArray &instanceIdentifier) { + return facade; + } + ); + return facade; + } ~DummyResourceFacade(){}; - KAsync::Job create(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; - KAsync::Job modify(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; - KAsync::Job remove(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; - KAsync::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE + KAsync::Job create(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; + KAsync::Job modify(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; + KAsync::Job remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; + KAsync::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE { capturedResultProvider = resultProvider; return KAsync::start([this, resultProvider, query]() { for (const auto &res : results) { - resultProvider->add(res); + qDebug() << "Parent filter " << query.propertyFilter.value("parent").toByteArray() << res->identifier(); + if (!query.propertyFilter.contains("parent") || query.propertyFilter.value("parent").toByteArray() == res->getProperty("parent").toByteArray()) { + resultProvider->add(res); + } } }); } - QList results; - QWeakPointer > capturedResultProvider; + QList results; + QWeakPointer > capturedResultProvider; }; + /** * Test of the client api implementation. * @@ -38,17 +55,6 @@ class ClientAPITest : public QObject Q_OBJECT private Q_SLOTS: - static std::shared_ptr registerDummyFacade() - { - auto facade = std::make_shared(); - Akonadi2::FacadeFactory::instance().registerFacade("dummyresource", - [facade](const QByteArray &instanceIdentifier) { - return facade; - } - ); - return facade; - } - void initTestCase() { Akonadi2::FacadeFactory::instance().resetFactory(); @@ -57,8 +63,8 @@ private Q_SLOTS: void testLoad() { - auto facade = registerDummyFacade(); - facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer()); + auto facade = DummyResourceFacade::registerFacade(); + facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); Akonadi2::Query query; @@ -73,8 +79,8 @@ private Q_SLOTS: //The query provider is supposed to delete itself void testQueryLifetime() { - auto facade = registerDummyFacade(); - facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer()); + auto facade = DummyResourceFacade::registerFacade(); + facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); Akonadi2::Query query; @@ -119,6 +125,71 @@ private Q_SLOTS: } } + void testModelSingle() + { + auto facade = DummyResourceFacade::registerFacade(); + facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); + + Akonadi2::Query query; + query.resources << "dummyresource.instance1"; + query.liveQuery = false; + + auto model = new ModelResult(query, QList() << "summary" << "uid"); + model->fetchMore(QModelIndex()); + QTRY_COMPARE(model->rowCount(), 1); + } + + void testModelNested() + { + auto facade = DummyResourceFacade::registerFacade(); + auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); + subfolder->setProperty("parent", "id"); + facade->results << folder << subfolder; + ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); + + //Test + Akonadi2::Query query; + query.resources << "dummyresource.instance1"; + query.liveQuery = false; + + auto model = new ModelResult(query, QList() << "summary" << "uid"); + model->fetchMore(QModelIndex()); + QTRY_COMPARE(model->rowCount(), 1); + model->fetchMore(model->index(0, 0)); + QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); + } + + // void testModelNestedLive() + // { + // auto facade = DummyResourceFacade::registerFacade(); + // auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + // auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); + // subfolder->setProperty("parent", "id"); + // facade->results << folder << subfolder; + // ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); + // + // //Test + // Akonadi2::Query query; + // query.resources << "dummyresource.instance1"; + // query.liveQuery = true + // + // auto model = new ModelResult(query, QList() << "summary" << "uid"); + // model->fetchMore(QModelIndex()); + // QTRY_COMPARE(model->rowCount(), 1); + // model->fetchMore(model->index(0, 0)); + // QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); + // + // auto resultProvider = facade->capturedResultProvider.toStrongRef(); + // + // //A modification can also be a move + // // resultProvider->modify(); + // + // // resultProvider->remove(); + // } + + }; QTEST_MAIN(ClientAPITest) diff --git a/tests/querytest.cpp b/tests/querytest.cpp new file mode 100644 index 0000000..9f4b3bb --- /dev/null +++ b/tests/querytest.cpp @@ -0,0 +1,100 @@ +#include + +#include + +#include "dummyresource/resourcefactory.h" +#include "clientapi.h" +#include "synclistresult.h" +#include "commands.h" +#include "resourceconfig.h" +#include "log.h" +#include "modelresult.h" + +/** + * Test of the query system using the dummy resource. + * + * This test requires the dummy resource installed. + */ +class QueryTest : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void initTestCase() + { + Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); + auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + QVERIFY(factory); + DummyResource::removeFromDisk("org.kde.dummy.instance1"); + ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); + } + + void cleanup() + { + Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + DummyResource::removeFromDisk("org.kde.dummy.instance1"); + auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + QVERIFY(factory); + } + + void init() + { + qDebug(); + qDebug() << "-----------------------------------------"; + qDebug(); + } + + void testSingle() + { + //Setup + { + Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + Akonadi2::Store::create(mail).exec().waitForFinished(); + } + + //Test + Akonadi2::Query query; + query.resources << "org.kde.dummy.instance1"; + query.syncOnDemand = false; + query.processAll = true; + + auto model = new ModelResult(query, QList() << "summary" << "uid"); + model->fetchMore(QModelIndex()); + QTRY_COMPARE(model->rowCount(), 1); + } + + // void testTree() + // { + // //Setup + // { + // Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); + // Akonadi2::Store::create(folder).exec().waitForFinished(); + // + // Akonadi2::Query query; + // query.resources << "org.kde.dummy.instance1"; + // query.syncOnDemand = false; + // query.processAll = true; + // + // auto model = new ModelResult(query, QList() << "summary" << "uid"); + // QTRY_COMPARE(model->rowCount(), 1); + // + // auto folderEntity = model->index(0, 0).data(ModelResult::DomainObjectRole).value(); + // + // Akonadi2::ApplicationDomain::Folder subfolder("org.kde.dummy.instance1"); + // subfolder.setProperty("parent", folderEntity.identifier()); + // Akonadi2::Store::create(subfolder).exec().waitForFinished(); + // } + // + // //Test + // Akonadi2::Query query; + // query.resources << "org.kde.dummy.instance1"; + // query.syncOnDemand = false; + // query.processAll = true; + // + // auto model = new ModelResult(query, QList() << "summary" << "uid"); + // QTRY_COMPARE(model->rowCount(), 1); + // QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); + // } +}; + +QTEST_MAIN(QueryTest) +#include "querytest.moc" -- cgit v1.2.3 From 09aafbd1373b5d1152ac7a453a140a7f76c2e90e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 13 Nov 2015 19:34:47 +0100 Subject: It's starting to work --- tests/clientapitest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 5bfad4b..2b3cc46 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -27,7 +27,7 @@ public: KAsync::Job create(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; KAsync::Job modify(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; KAsync::Job remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; - KAsync::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE + KAsync::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE { capturedResultProvider = resultProvider; return KAsync::start([this, resultProvider, query]() { @@ -41,7 +41,7 @@ public: } QList results; - QWeakPointer > capturedResultProvider; + QWeakPointer > capturedResultProvider; }; -- cgit v1.2.3 From 75c231f0758603120ec562af772b48b5f6ac0e24 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 13 Nov 2015 23:31:41 +0100 Subject: DummyResourceTest and QueryTest are passing sync has been removed from the query code and is now a separate step --- tests/dummyresourcetest.cpp | 24 ++++++++++++++++++++++++ tests/querytest.cpp | 24 +++++++++++++++++++++++- tests/testimplementations.h | 4 ++-- 3 files changed, 49 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index d027266..3b90e6c 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -64,6 +64,9 @@ private Q_SLOTS: query.syncOnDemand = false; query.processAll = true; + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + query.propertyFilter.insert("uid", "testuid"); async::SyncListResult result(Akonadi2::Store::load(query)); result.exec(); @@ -88,6 +91,9 @@ private Q_SLOTS: query.syncOnDemand = false; query.processAll = true; + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + query.propertyFilter.insert("uid", "testuid"); async::SyncListResult result(Akonadi2::Store::load(query)); result.exec(); @@ -114,6 +120,9 @@ private Q_SLOTS: query.syncOnDemand = false; query.processAll = true; + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + query.propertyFilter.insert("summary", "summaryValue2"); async::SyncListResult result(Akonadi2::Store::load(query)); result.exec(); @@ -145,6 +154,9 @@ private Q_SLOTS: query.syncOnDemand = true; query.processAll = true; + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + async::SyncListResult result(Akonadi2::Store::load(query)); result.exec(); QVERIFY(!result.isEmpty()); @@ -160,6 +172,9 @@ private Q_SLOTS: query.syncOnDemand = true; query.processAll = true; + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + async::SyncListResult result(Akonadi2::Store::load(query)); result.exec(); QVERIFY(!result.isEmpty()); @@ -182,6 +197,9 @@ private Q_SLOTS: query.processAll = true; query.propertyFilter.insert("uid", "testuid"); + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + //Test create Akonadi2::ApplicationDomain::Event event2; { @@ -198,6 +216,9 @@ private Q_SLOTS: event2.setProperty("summary", "summaryValue2"); Akonadi2::Store::modify(event2).exec().waitForFinished(); + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + //Test modify { async::SyncListResult result(Akonadi2::Store::load(query)); @@ -210,6 +231,9 @@ private Q_SLOTS: Akonadi2::Store::remove(event2).exec().waitForFinished(); + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + //Test remove { async::SyncListResult result(Akonadi2::Store::load(query)); diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 9f4b3bb..47d977b 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -57,11 +57,33 @@ private Q_SLOTS: query.syncOnDemand = false; query.processAll = true; - auto model = new ModelResult(query, QList() << "summary" << "uid"); + auto model = Akonadi2::Store::loadModel(query); model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); } + void testSingleWithDelay() + { + //Setup + { + Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + Akonadi2::Store::create(mail).exec().waitForFinished(); + } + + //Test + Akonadi2::Query query; + query.resources << "org.kde.dummy.instance1"; + query.syncOnDemand = false; + query.processAll = true; + query.liveQuery = true; + + auto model = Akonadi2::Store::loadModel(query); + QTest::qWait(200); + model->fetchMore(QModelIndex()); + QVERIFY(model->rowCount() < 2); + QTRY_COMPARE(model->rowCount(), 1); + } + // void testTree() // { // //Setup diff --git a/tests/testimplementations.h b/tests/testimplementations.h index eee78b0..1436c68 100644 --- a/tests/testimplementations.h +++ b/tests/testimplementations.h @@ -85,8 +85,8 @@ public Q_SLOTS: class TestResourceFacade : public Akonadi2::GenericFacade { public: - TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer > storage, const QSharedPointer resourceAccess) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create(), storage, resourceAccess) + TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer resourceAccess) + : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create(), resourceAccess) { } -- cgit v1.2.3 From 25b08ded08e7b581215a4e89f43c4a1509c13f4a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 14 Nov 2015 00:06:40 +0100 Subject: Query test adjustments --- tests/querytest.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 47d977b..e4f1d0d 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -55,8 +55,10 @@ private Q_SLOTS: Akonadi2::Query query; query.resources << "org.kde.dummy.instance1"; query.syncOnDemand = false; - query.processAll = true; + query.processAll = false; + query.liveQuery = true; + //We fetch before the data is available and rely on the live query mechanism to deliver the actual data auto model = Akonadi2::Store::loadModel(query); model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); @@ -75,10 +77,14 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; query.syncOnDemand = false; query.processAll = true; - query.liveQuery = true; + query.liveQuery = false; + //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data auto model = Akonadi2::Store::loadModel(query); - QTest::qWait(200); + + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + model->fetchMore(QModelIndex()); QVERIFY(model->rowCount() < 2); QTRY_COMPARE(model->rowCount(), 1); -- cgit v1.2.3 From ec902175d53d371b03d8e754d917e196cd15aafa Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 15 Nov 2015 09:46:27 +0100 Subject: Fixed clientapitest --- tests/clientapitest.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 2b3cc46..2ce64d3 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -30,14 +30,15 @@ public: KAsync::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE { capturedResultProvider = resultProvider; - return KAsync::start([this, resultProvider, query]() { - for (const auto &res : results) { + resultProvider->setFetcher([query, resultProvider, this](const QByteArray &) { + for (const auto &res : results) { qDebug() << "Parent filter " << query.propertyFilter.value("parent").toByteArray() << res->identifier(); if (!query.propertyFilter.contains("parent") || query.propertyFilter.value("parent").toByteArray() == res->getProperty("parent").toByteArray()) { resultProvider->add(res); } } }); + return KAsync::null(); } QList results; @@ -135,7 +136,7 @@ private Q_SLOTS: query.resources << "dummyresource.instance1"; query.liveQuery = false; - auto model = new ModelResult(query, QList() << "summary" << "uid"); + auto model = Akonadi2::Store::loadModel(query); model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); } @@ -154,7 +155,7 @@ private Q_SLOTS: query.resources << "dummyresource.instance1"; query.liveQuery = false; - auto model = new ModelResult(query, QList() << "summary" << "uid"); + auto model = Akonadi2::Store::loadModel(query); model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); model->fetchMore(model->index(0, 0)); -- cgit v1.2.3 From d4b10a3de396eebc6c815093e9e1725ece270e9e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 15 Nov 2015 11:09:31 +0100 Subject: Working folder tree query --- tests/querytest.cpp | 98 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index e4f1d0d..677dbac 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -90,38 +90,72 @@ private Q_SLOTS: QTRY_COMPARE(model->rowCount(), 1); } - // void testTree() - // { - // //Setup - // { - // Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); - // Akonadi2::Store::create(folder).exec().waitForFinished(); - // - // Akonadi2::Query query; - // query.resources << "org.kde.dummy.instance1"; - // query.syncOnDemand = false; - // query.processAll = true; - // - // auto model = new ModelResult(query, QList() << "summary" << "uid"); - // QTRY_COMPARE(model->rowCount(), 1); - // - // auto folderEntity = model->index(0, 0).data(ModelResult::DomainObjectRole).value(); - // - // Akonadi2::ApplicationDomain::Folder subfolder("org.kde.dummy.instance1"); - // subfolder.setProperty("parent", folderEntity.identifier()); - // Akonadi2::Store::create(subfolder).exec().waitForFinished(); - // } - // - // //Test - // Akonadi2::Query query; - // query.resources << "org.kde.dummy.instance1"; - // query.syncOnDemand = false; - // query.processAll = true; - // - // auto model = new ModelResult(query, QList() << "summary" << "uid"); - // QTRY_COMPARE(model->rowCount(), 1); - // QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); - // } + void testFolder() + { + //Setup + { + Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); + Akonadi2::Store::create(folder).exec().waitForFinished(); + } + + //Test + Akonadi2::Query query; + query.resources << "org.kde.dummy.instance1"; + query.syncOnDemand = false; + query.processAll = false; + query.liveQuery = true; + + //We fetch before the data is available and rely on the live query mechanism to deliver the actual data + auto model = Akonadi2::Store::loadModel(query); + model->fetchMore(QModelIndex()); + QTRY_COMPARE(model->rowCount(), 1); + auto folderEntity = model->index(0, 0).data(ModelResult::DomainObjectRole).value(); + QVERIFY(!folderEntity->identifier().isEmpty()); + } + + void testFolderTree() + { + //Setup + { + Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); + Akonadi2::Store::create(folder).exec().waitForFinished(); + + Akonadi2::Query query; + query.resources << "org.kde.dummy.instance1"; + query.syncOnDemand = false; + query.processAll = true; + + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + + auto model = Akonadi2::Store::loadModel(query); + model->fetchMore(QModelIndex()); + QTRY_COMPARE(model->rowCount(), 1); + + auto folderEntity = model->index(0, 0).data(ModelResult::DomainObjectRole).value(); + QVERIFY(!folderEntity->identifier().isEmpty()); + + Akonadi2::ApplicationDomain::Folder subfolder("org.kde.dummy.instance1"); + subfolder.setProperty("parent", folderEntity->identifier()); + Akonadi2::Store::create(subfolder).exec().waitForFinished(); + } + + //Test + Akonadi2::Query query; + query.resources << "org.kde.dummy.instance1"; + query.syncOnDemand = false; + query.processAll = true; + + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + + //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data + auto model = Akonadi2::Store::loadModel(query); + model->fetchMore(QModelIndex()); + QTRY_COMPARE(model->rowCount(), 1); + model->fetchMore(model->index(0, 0)); + QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); + } }; QTEST_MAIN(QueryTest) -- cgit v1.2.3 From 972f3a4e96876e4c36162a11062e40863d88a2a1 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 15 Nov 2015 12:46:26 +0100 Subject: Cleanup --- tests/genericfacadebenchmark.cpp | 3 +-- tests/genericfacadetest.cpp | 39 ++++++++++++++++++--------------------- tests/testimplementations.h | 26 -------------------------- 3 files changed, 19 insertions(+), 49 deletions(-) (limited to 'tests') diff --git a/tests/genericfacadebenchmark.cpp b/tests/genericfacadebenchmark.cpp index 29c91d7..94d6f41 100644 --- a/tests/genericfacadebenchmark.cpp +++ b/tests/genericfacadebenchmark.cpp @@ -56,8 +56,7 @@ private Q_SLOTS: QBENCHMARK { auto resultSet = QSharedPointer >::create(); auto resourceAccess = QSharedPointer::create(); - auto storage = QSharedPointer >::create("identifier"); - TestResourceFacade facade(identifier, storage, resourceAccess); + TestResourceFacade facade(identifier, resourceAccess); async::SyncListResult result(resultSet->emitter()); diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp index 67320c3..9e7500f 100644 --- a/tests/genericfacadetest.cpp +++ b/tests/genericfacadetest.cpp @@ -17,6 +17,7 @@ * Test for the generic facade implementation. * * This test doesn't use the actual storage and thus only tests the update logic of the facade. + * //FIXME this now uses the actual storage */ class GenericFacadeTest : public QObject { @@ -34,10 +35,9 @@ private Q_SLOTS: query.liveQuery = false; auto resultSet = QSharedPointer >::create(); - auto storage = QSharedPointer::create("identifier"); auto resourceAccess = QSharedPointer::create(); - storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); - TestResourceFacade facade("identifier", storage, resourceAccess); + // storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); + TestResourceFacade facade("identifier", resourceAccess); async::SyncListResult result(resultSet->emitter()); @@ -56,10 +56,9 @@ private Q_SLOTS: query.liveQuery = true; auto resultSet = QSharedPointer >::create(); - auto storage = QSharedPointer::create("identifier"); auto resourceAccess = QSharedPointer::create(); - storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); - TestResourceFacade facade("identifier", storage, resourceAccess); + // storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); + TestResourceFacade facade("identifier", resourceAccess); async::SyncListResult result(resultSet->emitter()); @@ -70,9 +69,9 @@ private Q_SLOTS: QCOMPARE(result.size(), 1); //Enter a second result - storage->mResults.clear(); - storage->mResults << QSharedPointer::create("resource", "id2", 0, QSharedPointer()); - storage->mLatestRevision = 2; + // storage->mResults.clear(); + // storage->mResults << QSharedPointer::create("resource", "id2", 0, QSharedPointer()); + // storage->mLatestRevision = 2; resourceAccess->emit revisionChanged(2); //Hack to get event loop in synclistresult to abort again @@ -88,12 +87,11 @@ private Q_SLOTS: query.liveQuery = true; auto resultSet = QSharedPointer >::create(); - auto storage = QSharedPointer::create("identifier"); auto resourceAccess = QSharedPointer::create(); auto entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); entity->setProperty("test", "test1"); - storage->mResults << entity; - TestResourceFacade facade("identifier", storage, resourceAccess); + // storage->mResults << entity; + TestResourceFacade facade("identifier", resourceAccess); async::SyncListResult result(resultSet->emitter()); @@ -104,11 +102,11 @@ private Q_SLOTS: QCOMPARE(result.size(), 1); //Modify the entity again - storage->mResults.clear(); + // storage->mResults.clear(); entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); entity->setProperty("test", "test2"); - storage->mModifications << entity; - storage->mLatestRevision = 2; + // storage->mModifications << entity; + // storage->mLatestRevision = 2; resourceAccess->emit revisionChanged(2); //Hack to get event loop in synclistresult to abort again @@ -125,11 +123,10 @@ private Q_SLOTS: query.liveQuery = true; auto resultSet = QSharedPointer >::create(); - auto storage = QSharedPointer::create("identifier"); auto resourceAccess = QSharedPointer::create(); auto entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer()); - storage->mResults << entity; - TestResourceFacade facade("identifier", storage, resourceAccess); + // storage->mResults << entity; + TestResourceFacade facade("identifier", resourceAccess); async::SyncListResult result(resultSet->emitter()); @@ -140,9 +137,9 @@ private Q_SLOTS: QCOMPARE(result.size(), 1); //Remove the entity again - storage->mResults.clear(); - storage->mRemovals << entity; - storage->mLatestRevision = 2; + // storage->mResults.clear(); + // storage->mRemovals << entity; + // storage->mLatestRevision = 2; resourceAccess->emit revisionChanged(2); //Hack to get event loop in synclistresult to abort again diff --git a/tests/testimplementations.h b/tests/testimplementations.h index 1436c68..c371456 100644 --- a/tests/testimplementations.h +++ b/tests/testimplementations.h @@ -21,13 +21,11 @@ #include -#include #include #include #include #include #include -#include #include //Replace with something different @@ -44,30 +42,6 @@ public: virtual ~TestEventAdaptorFactory() {}; }; -class TestEntityStorage : public EntityStorage -{ -public: - using EntityStorage::EntityStorage; - virtual qint64 read(const Akonadi2::Query &query, qint64 oldRevision, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE - { - for (const auto &res : mResults) { - resultProvider->add(res); - } - for (const auto &res : mModifications) { - resultProvider->modify(res); - } - for (const auto &res : mRemovals) { - resultProvider->remove(res); - } - return mLatestRevision; - } - - QList mResults; - QList mModifications; - QList mRemovals; - qint64 mLatestRevision; -}; - class TestResourceAccess : public Akonadi2::ResourceAccessInterface { Q_OBJECT -- cgit v1.2.3 From 0f24357d01bd8a278f03793db863d3f71ac37ef2 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 18 Nov 2015 00:51:55 +0100 Subject: Don't use a smart pointer for the result provider We're not doing any lifetime management anyways. --- tests/clientapitest.cpp | 12 ++++++------ tests/genericfacadebenchmark.cpp | 2 +- tests/genericfacadetest.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 2ce64d3..9202e29 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -27,14 +27,14 @@ public: KAsync::Job create(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; KAsync::Job modify(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; KAsync::Job remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; - KAsync::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE + KAsync::Job load(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface &resultProvider) Q_DECL_OVERRIDE { - capturedResultProvider = resultProvider; - resultProvider->setFetcher([query, resultProvider, this](const QByteArray &) { + capturedResultProvider = &resultProvider; + resultProvider.setFetcher([query, &resultProvider, this](const QByteArray &) { for (const auto &res : results) { qDebug() << "Parent filter " << query.propertyFilter.value("parent").toByteArray() << res->identifier(); if (!query.propertyFilter.contains("parent") || query.propertyFilter.value("parent").toByteArray() == res->getProperty("parent").toByteArray()) { - resultProvider->add(res); + resultProvider.add(res); } } }); @@ -42,7 +42,7 @@ public: } QList results; - QWeakPointer > capturedResultProvider; + Akonadi2::ResultProviderInterface *capturedResultProvider; }; @@ -94,7 +94,7 @@ private Q_SLOTS: QCOMPARE(result.size(), 1); } //It's running in a separate thread, so we have to wait for a moment until the query provider deletes itself. - QTRY_VERIFY(!facade->capturedResultProvider); + // QTRY_VERIFY(!facade->capturedResultProvider); } //TODO: This test doesn't belong to this testsuite diff --git a/tests/genericfacadebenchmark.cpp b/tests/genericfacadebenchmark.cpp index 94d6f41..8b00666 100644 --- a/tests/genericfacadebenchmark.cpp +++ b/tests/genericfacadebenchmark.cpp @@ -60,7 +60,7 @@ private Q_SLOTS: async::SyncListResult result(resultSet->emitter()); - facade.load(query, resultSet).exec().waitForFinished(); + facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); //We have to wait for the events that deliver the results to be processed by the eventloop diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp index 9e7500f..bb95f4e 100644 --- a/tests/genericfacadetest.cpp +++ b/tests/genericfacadetest.cpp @@ -41,7 +41,7 @@ private Q_SLOTS: async::SyncListResult result(resultSet->emitter()); - facade.load(query, resultSet).exec().waitForFinished(); + facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); //We have to wait for the events that deliver the results to be processed by the eventloop @@ -62,7 +62,7 @@ private Q_SLOTS: async::SyncListResult result(resultSet->emitter()); - facade.load(query, resultSet).exec().waitForFinished(); + facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); result.exec(); @@ -95,7 +95,7 @@ private Q_SLOTS: async::SyncListResult result(resultSet->emitter()); - facade.load(query, resultSet).exec().waitForFinished(); + facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); result.exec(); @@ -130,7 +130,7 @@ private Q_SLOTS: async::SyncListResult result(resultSet->emitter()); - facade.load(query, resultSet).exec().waitForFinished(); + facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); result.exec(); -- cgit v1.2.3 From c4a6746e4420b580fe35cc89783de4dbc3205ac6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 19 Nov 2015 18:14:09 +0100 Subject: The parent is always an object, so we might as well make that explicit --- tests/clientapitest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 9202e29..ce11221 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -30,7 +30,7 @@ public: KAsync::Job load(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface &resultProvider) Q_DECL_OVERRIDE { capturedResultProvider = &resultProvider; - resultProvider.setFetcher([query, &resultProvider, this](const QByteArray &) { + resultProvider.setFetcher([query, &resultProvider, this](const typename T::Ptr &) { for (const auto &res : results) { qDebug() << "Parent filter " << query.propertyFilter.value("parent").toByteArray() << res->identifier(); if (!query.propertyFilter.contains("parent") || query.propertyFilter.value("parent").toByteArray() == res->getProperty("parent").toByteArray()) { -- cgit v1.2.3 From 0b967e06a1a50c1f540b941d381680cdf3ac4706 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 21 Nov 2015 02:29:35 +0100 Subject: Fixed build --- tests/clientapitest.cpp | 1 + tests/genericfacadebenchmark.cpp | 1 + tests/pipelinetest.cpp | 1 + 3 files changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index ce11221..4883b5e 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -8,6 +8,7 @@ #include "resourceconfig.h" #include "modelresult.h" #include "resultprovider.h" +#include "facadefactory.h" template class DummyResourceFacade : public Akonadi2::StoreFacade diff --git a/tests/genericfacadebenchmark.cpp b/tests/genericfacadebenchmark.cpp index 8b00666..703acd1 100644 --- a/tests/genericfacadebenchmark.cpp +++ b/tests/genericfacadebenchmark.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "event_generated.h" diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 47090a8..2ede69d 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -19,6 +19,7 @@ #include "pipeline.h" #include "log.h" #include "domainadaptor.h" +#include "definitions.h" static void removeFromDisk(const QString &name) { -- cgit v1.2.3 From 9ad96df6cd1526de32bff2b4f98491dd8318f760 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 24 Nov 2015 23:00:45 +0100 Subject: Use Query::parentProperty to express tree queries That way we don't have to hardcode the parent property, and we can use the property to express non-tree queries as well. --- tests/querytest.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 677dbac..fdfb609 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -145,6 +145,7 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; query.syncOnDemand = false; query.processAll = true; + query.parentProperty = "parent"; //Ensure all local data is processed Akonadi2::Store::synchronize(query).exec().waitForFinished(); -- cgit v1.2.3 From e4a4d72fd206fc2d5c1095b39b2839e53cd114bb Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 25 Nov 2015 00:37:42 +0100 Subject: Optimize findLast This just gave a 700% boost to query performance from ~2k to 14k reads per second... --- tests/storagetest.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index bef8755..d950961 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -376,6 +376,7 @@ private Q_SLOTS: db.write("sub1","value1"); db.write("sub2","value2"); db.write("wub3","value3"); + db.write("wub4","value4"); QByteArray result; db.findLatest("sub", [&](const QByteArray &key, const QByteArray &value) { result = value; @@ -384,6 +385,35 @@ private Q_SLOTS: QCOMPARE(result, QByteArray("value2")); } + void testFindLatestInSingle() + { + Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); + auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + auto db = transaction.openDatabase("test", nullptr, false); + db.write("sub2","value2"); + QByteArray result; + db.findLatest("sub", [&](const QByteArray &key, const QByteArray &value) { + result = value; + }); + + QCOMPARE(result, QByteArray("value2")); + } + + void testFindLast() + { + Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); + auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + auto db = transaction.openDatabase("test", nullptr, false); + db.write("sub2","value2"); + db.write("wub3","value3"); + QByteArray result; + db.findLatest("wub", [&](const QByteArray &key, const QByteArray &value) { + result = value; + }); + + QCOMPARE(result, QByteArray("value3")); + } + void testRecordRevision() { Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); -- cgit v1.2.3 From 13af56e436f49df32d3b2f6f223cf1dec2eabaac Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 26 Nov 2015 14:29:46 +0100 Subject: Use the new model api in the benchmark and split tests up. This way it's possible to i.e. repeatedly only run the reading part. --- tests/dummyresourcebenchmark.cpp | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 242ac76..609b8dc 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp @@ -10,6 +10,7 @@ #include "synclistresult.h" #include "pipeline.h" #include "log.h" +#include "resourceconfig.h" #include "event_generated.h" #include "entity_generated.h" @@ -24,18 +25,20 @@ class DummyResourceBenchmark : public QObject { Q_OBJECT +private: + int num; private Q_SLOTS: void initTestCase() { Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); - DummyResource::removeFromDisk("org.kde.dummy.instance1"); + ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); + num = 5000; } void cleanup() { - DummyResource::removeFromDisk("org.kde.dummy.instance1"); } static KAsync::Job waitForCompletion(QList > &futures) @@ -68,11 +71,12 @@ private Q_SLOTS: }); } - void testWriteToFacadeAndQueryByUid() + void testWriteToFacade() { + DummyResource::removeFromDisk("org.kde.dummy.instance1"); + QTime time; time.start(); - int num = 100; QList > waitCondition; for (int i = 0; i < num; i++) { Akonadi2::ApplicationDomain::Event event("org.kde.dummy.instance1"); @@ -90,13 +94,17 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; query.syncOnDemand = false; query.processAll = true; - - query.propertyFilter.insert("uid", "nonexistantuid"); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); + Akonadi2::Store::synchronize(query).exec().waitForFinished(); } auto allProcessedTime = time.elapsed(); + qDebug() << "Append to messagequeue " << appendTime; + qDebug() << "All processed: " << allProcessedTime << "/sec " << num*1000/allProcessedTime; + } + void testQueryByUid() + { + QTime time; + time.start(); //Measure query { time.start(); @@ -106,20 +114,18 @@ private Q_SLOTS: query.processAll = false; query.propertyFilter.insert("uid", "testuid"); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), num); + auto model = Akonadi2::Store::loadModel(query); + model->fetchMore(QModelIndex()); + QTRY_COMPARE(model->rowCount(QModelIndex()), num); } - qDebug() << "Append to messagequeue " << appendTime; - qDebug() << "All processed: " << allProcessedTime << "/sec " << num*1000/allProcessedTime; qDebug() << "Query Time: " << time.elapsed() << "/sec " << num*1000/time.elapsed(); } void testWriteInProcess() { + DummyResource::removeFromDisk("org.kde.dummy.instance1"); QTime time; time.start(); - int num = 100; auto pipeline = QSharedPointer::create("org.kde.dummy.instance1"); DummyResource resource("org.kde.dummy.instance1", pipeline); @@ -191,6 +197,12 @@ private Q_SLOTS: Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); } } + + //This allows to run individual parts without doing a cleanup, but still cleaning up normally + void testCleanupForCompleteTest() + { + DummyResource::removeFromDisk("org.kde.dummy.instance1"); + } }; QTEST_MAIN(DummyResourceBenchmark) -- cgit v1.2.3 From 5b41b26a349967acf2197f9f9228526193fd826e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 27 Nov 2015 17:30:04 +0100 Subject: Introduced a QueryRunner object The QueryRunner object lives for the duration of the query (so just for the initial query for non-live queries, and for the lifetime of the result model for live queries). It's supposed to handle all the threading internally and decouple the lifetime of the facade. --- tests/CMakeLists.txt | 12 +++--- tests/clientapitest.cpp | 86 ++++++++++++++++++++++++---------------- tests/dummyresourcebenchmark.cpp | 2 - 3 files changed, 57 insertions(+), 43 deletions(-) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ed5a76..b26797c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,25 +30,25 @@ endmacro(auto_tests) manual_tests ( storagebenchmark dummyresourcebenchmark - genericresourcebenchmark - genericfacadebenchmark +# genericresourcebenchmark +# genericfacadebenchmark ) auto_tests ( clientapitest storagetest - dummyresourcetest + # dummyresourcetest domainadaptortest messagequeuetest indextest - genericresourcetest - genericfacadetest + # genericresourcetest + # genericfacadetest resourcecommunicationtest pipelinetest querytest ) -target_link_libraries(dummyresourcetest akonadi2_resource_dummy) +# target_link_libraries(dummyresourcetest akonadi2_resource_dummy) target_link_libraries(dummyresourcebenchmark akonadi2_resource_dummy) target_link_libraries(querytest akonadi2_resource_dummy) diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 4883b5e..d76fac8 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -4,7 +4,6 @@ #include "clientapi.h" #include "facade.h" -#include "synclistresult.h" #include "resourceconfig.h" #include "modelresult.h" #include "resultprovider.h" @@ -28,22 +27,35 @@ public: KAsync::Job create(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; KAsync::Job modify(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; KAsync::Job remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; - KAsync::Job load(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface &resultProvider) Q_DECL_OVERRIDE + QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE { - capturedResultProvider = &resultProvider; - resultProvider.setFetcher([query, &resultProvider, this](const typename T::Ptr &) { - for (const auto &res : results) { + // capturedResultProvider = &resultProvider; + Trace() << "lkjsdflkjsdfljsdfljsdlfj"; + + auto resultProvider = new Akonadi2::ResultProvider(); + resultProvider->onDone([resultProvider]() { + Trace() << "Result provider is done"; + delete resultProvider; + }); + //We have to do it this way, otherwise we're not setting the fetcher right + auto emitter = resultProvider->emitter(); + + resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &) { + Trace() << "Running the fetcher"; + for (const auto &res : results) { qDebug() << "Parent filter " << query.propertyFilter.value("parent").toByteArray() << res->identifier(); if (!query.propertyFilter.contains("parent") || query.propertyFilter.value("parent").toByteArray() == res->getProperty("parent").toByteArray()) { - resultProvider.add(res); + resultProvider->add(res); } } }); - return KAsync::null(); + auto job = KAsync::start([query, resultProvider]() { + }); + return qMakePair(job, emitter); } QList results; - Akonadi2::ResultProviderInterface *capturedResultProvider; + // Akonadi2::ResultProviderInterface *capturedResultProvider; }; @@ -61,24 +73,25 @@ private Q_SLOTS: { Akonadi2::FacadeFactory::instance().resetFactory(); ResourceConfig::clear(); + Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); } - void testLoad() - { - auto facade = DummyResourceFacade::registerFacade(); - facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); - ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); - - Akonadi2::Query query; - query.resources << "dummyresource.instance1"; - query.liveQuery = false; - - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 1); - } - - //The query provider is supposed to delete itself + // void testLoad() + // { + // auto facade = DummyResourceFacade::registerFacade(); + // facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + // ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); + // + // Akonadi2::Query query; + // query.resources << "dummyresource.instance1"; + // query.liveQuery = false; + // + // async::SyncListResult result(Akonadi2::Store::load(query)); + // result.exec(); + // QCOMPARE(result.size(), 1); + // } + // + // //The query provider is supposed to delete itself void testQueryLifetime() { auto facade = DummyResourceFacade::registerFacade(); @@ -90,12 +103,12 @@ private Q_SLOTS: query.liveQuery = true; { - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 1); + auto model = Akonadi2::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); } //It's running in a separate thread, so we have to wait for a moment until the query provider deletes itself. // QTRY_VERIFY(!facade->capturedResultProvider); + QTest::qWait(300); } //TODO: This test doesn't belong to this testsuite @@ -112,18 +125,22 @@ private Q_SLOTS: { Akonadi2::Query query; query.propertyFilter.insert("type", "dummyresource"); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 1); + // async::SyncListResult result(Akonadi2::Store::load(query)); + auto model = Akonadi2::Store::loadModel(query); + // result.exec(); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); } Akonadi2::Store::remove(res).exec().waitForFinished(); { Akonadi2::Query query; query.propertyFilter.insert("type", "dummyresource"); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 0); + // async::SyncListResult result(Akonadi2::Store::load(query)); + auto model = Akonadi2::Store::loadModel(query); + // result.exec(); + // QCOMPARE(result.size(), 0); + // QTRY_COMPARE(result.size(), 0); + QTRY_COMPARE(model->rowCount(QModelIndex()), 0); } } @@ -138,7 +155,6 @@ private Q_SLOTS: query.liveQuery = false; auto model = Akonadi2::Store::loadModel(query); - model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); } @@ -155,9 +171,9 @@ private Q_SLOTS: Akonadi2::Query query; query.resources << "dummyresource.instance1"; query.liveQuery = false; + query.parentProperty = "parent"; auto model = Akonadi2::Store::loadModel(query); - model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); model->fetchMore(model->index(0, 0)); QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 609b8dc..6eaf065 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp @@ -7,7 +7,6 @@ #include "clientapi.h" #include "commands.h" #include "entitybuffer.h" -#include "synclistresult.h" #include "pipeline.h" #include "log.h" #include "resourceconfig.h" @@ -115,7 +114,6 @@ private Q_SLOTS: query.propertyFilter.insert("uid", "testuid"); auto model = Akonadi2::Store::loadModel(query); - model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(QModelIndex()), num); } qDebug() << "Query Time: " << time.elapsed() << "/sec " << num*1000/time.elapsed(); -- cgit v1.2.3 From 088d8a40c195ce6dcb91556a17f69d26e5586a3e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 28 Nov 2015 12:48:43 +0100 Subject: Removed most uses of SyncListResult and brought back the dummyresourcetest --- tests/CMakeLists.txt | 4 +- tests/clientapitest.cpp | 90 +++++++++++++++++++++------------------------ tests/dummyresourcetest.cpp | 81 ++++++++++++++++++++-------------------- tests/pipelinetest.cpp | 1 - tests/querytest.cpp | 2 - tests/testimplementations.h | 1 - 6 files changed, 85 insertions(+), 94 deletions(-) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b26797c..11fe415 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,7 +37,7 @@ manual_tests ( auto_tests ( clientapitest storagetest - # dummyresourcetest + dummyresourcetest domainadaptortest messagequeuetest indextest @@ -48,7 +48,7 @@ auto_tests ( querytest ) -# target_link_libraries(dummyresourcetest akonadi2_resource_dummy) +target_link_libraries(dummyresourcetest akonadi2_resource_dummy) target_link_libraries(dummyresourcebenchmark akonadi2_resource_dummy) target_link_libraries(querytest akonadi2_resource_dummy) diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index d76fac8..e97b2a4 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -76,21 +76,20 @@ private Q_SLOTS: Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); } - // void testLoad() - // { - // auto facade = DummyResourceFacade::registerFacade(); - // facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); - // ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); - // - // Akonadi2::Query query; - // query.resources << "dummyresource.instance1"; - // query.liveQuery = false; - // - // async::SyncListResult result(Akonadi2::Store::load(query)); - // result.exec(); - // QCOMPARE(result.size(), 1); - // } - // + void testLoad() + { + auto facade = DummyResourceFacade::registerFacade(); + facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); + + Akonadi2::Query query; + query.resources << "dummyresource.instance1"; + query.liveQuery = false; + + auto model = Akonadi2::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + } + // //The query provider is supposed to delete itself void testQueryLifetime() { @@ -125,9 +124,7 @@ private Q_SLOTS: { Akonadi2::Query query; query.propertyFilter.insert("type", "dummyresource"); - // async::SyncListResult result(Akonadi2::Store::load(query)); auto model = Akonadi2::Store::loadModel(query); - // result.exec(); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); } @@ -135,11 +132,8 @@ private Q_SLOTS: { Akonadi2::Query query; query.propertyFilter.insert("type", "dummyresource"); - // async::SyncListResult result(Akonadi2::Store::load(query)); auto model = Akonadi2::Store::loadModel(query); - // result.exec(); - // QCOMPARE(result.size(), 0); - // QTRY_COMPARE(result.size(), 0); + //TODO ensure the initial query completed QTRY_COMPARE(model->rowCount(QModelIndex()), 0); } } @@ -179,33 +173,33 @@ private Q_SLOTS: QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); } - // void testModelNestedLive() - // { - // auto facade = DummyResourceFacade::registerFacade(); - // auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); - // auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); - // subfolder->setProperty("parent", "id"); - // facade->results << folder << subfolder; - // ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); - // - // //Test - // Akonadi2::Query query; - // query.resources << "dummyresource.instance1"; - // query.liveQuery = true - // - // auto model = new ModelResult(query, QList() << "summary" << "uid"); - // model->fetchMore(QModelIndex()); - // QTRY_COMPARE(model->rowCount(), 1); - // model->fetchMore(model->index(0, 0)); - // QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); - // - // auto resultProvider = facade->capturedResultProvider.toStrongRef(); - // - // //A modification can also be a move - // // resultProvider->modify(); - // - // // resultProvider->remove(); - // } + void testModelNestedLive() + { + auto facade = DummyResourceFacade::registerFacade(); + auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); + subfolder->setProperty("parent", "id"); + facade->results << folder << subfolder; + ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); + + //Test + Akonadi2::Query query; + query.resources << "dummyresource.instance1"; + query.liveQuery = true; + query.parentProperty = "parent"; + + auto model = Akonadi2::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(), 1); + model->fetchMore(model->index(0, 0)); + QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); + + // auto resultProvider = facade->capturedResultProvider.toStrongRef(); + + //A modification can also be a move + // resultProvider->modify(); + + // resultProvider->remove(); + } }; diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 3b90e6c..d2fcda7 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -4,10 +4,10 @@ #include "dummyresource/resourcefactory.h" #include "clientapi.h" -#include "synclistresult.h" #include "commands.h" #include "entitybuffer.h" #include "resourceconfig.h" +#include "modelresult.h" #include "pipeline.h" #include "log.h" @@ -68,10 +68,9 @@ private Q_SLOTS: Akonadi2::Store::synchronize(query).exec().waitForFinished(); query.propertyFilter.insert("uid", "testuid"); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 1); - auto value = result.first(); + auto model = Akonadi2::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); } @@ -95,10 +94,11 @@ private Q_SLOTS: Akonadi2::Store::synchronize(query).exec().waitForFinished(); query.propertyFilter.insert("uid", "testuid"); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 1); - auto value = result.first(); + + auto model = Akonadi2::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + qDebug() << value->getProperty("uid").toByteArray(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); } @@ -124,10 +124,11 @@ private Q_SLOTS: Akonadi2::Store::synchronize(query).exec().waitForFinished(); query.propertyFilter.insert("summary", "summaryValue2"); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 1); - auto value = result.first(); + + auto model = Akonadi2::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + qDebug() << value->getProperty("uid").toByteArray(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid2")); } @@ -157,10 +158,10 @@ private Q_SLOTS: //Ensure all local data is processed Akonadi2::Store::synchronize(query).exec().waitForFinished(); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QVERIFY(!result.isEmpty()); - auto value = result.first(); + auto model = Akonadi2::Store::loadModel(query); + QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + QVERIFY(!value->getProperty("summary").toString().isEmpty()); qDebug() << value->getProperty("summary").toString(); } @@ -175,10 +176,10 @@ private Q_SLOTS: //Ensure all local data is processed Akonadi2::Store::synchronize(query).exec().waitForFinished(); - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QVERIFY(!result.isEmpty()); - auto value = result.first(); + auto model = Akonadi2::Store::loadModel(query); + QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + QVERIFY(!value->getProperty("subject").toString().isEmpty()); qDebug() << value->getProperty("subject").toString(); } @@ -203,10 +204,10 @@ private Q_SLOTS: //Test create Akonadi2::ApplicationDomain::Event event2; { - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 1); - auto value = result.first(); + auto model = Akonadi2::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); event2 = *value; @@ -221,10 +222,10 @@ private Q_SLOTS: //Test modify { - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QCOMPARE(result.size(), 1); - auto value = result.first(); + auto model = Akonadi2::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); } @@ -236,9 +237,9 @@ private Q_SLOTS: //Test remove { - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); - QTRY_COMPARE(result.size(), 0); + auto model = Akonadi2::Store::loadModel(query); + //TODO ensure the initial query is done + QTRY_COMPARE(model->rowCount(QModelIndex()), 0); } } @@ -252,9 +253,8 @@ private Q_SLOTS: query.liveQuery = true; query.propertyFilter.insert("uid", "testuid"); - - async::SyncListResult result(Akonadi2::Store::load(query)); - result.exec(); + auto model = Akonadi2::Store::loadModel(query); + //TODO ensure the initial query is done Akonadi2::ApplicationDomain::Event event("org.kde.dummy.instance1"); event.setProperty("uid", "testuid"); @@ -265,8 +265,8 @@ private Q_SLOTS: //Test create Akonadi2::ApplicationDomain::Event event2; { - QTRY_COMPARE(result.size(), 1); - auto value = result.first(); + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); event2 = *value; @@ -278,8 +278,9 @@ private Q_SLOTS: //Test modify { - QTRY_COMPARE(result.size(), 1); - auto value = result.first(); + //TODO wait for a change signal + QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); } @@ -288,7 +289,7 @@ private Q_SLOTS: //Test remove { - QTRY_COMPARE(result.size(), 0); + QTRY_COMPARE(model->rowCount(QModelIndex()), 0); } } diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 2ede69d..f0fd1a4 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -12,7 +12,6 @@ #include "deleteentity_generated.h" #include "dummyresource/resourcefactory.h" #include "clientapi.h" -#include "synclistresult.h" #include "commands.h" #include "entitybuffer.h" #include "resourceconfig.h" diff --git a/tests/querytest.cpp b/tests/querytest.cpp index fdfb609..e354272 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -4,7 +4,6 @@ #include "dummyresource/resourcefactory.h" #include "clientapi.h" -#include "synclistresult.h" #include "commands.h" #include "resourceconfig.h" #include "log.h" @@ -129,7 +128,6 @@ private Q_SLOTS: Akonadi2::Store::synchronize(query).exec().waitForFinished(); auto model = Akonadi2::Store::loadModel(query); - model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); auto folderEntity = model->index(0, 0).data(ModelResult::DomainObjectRole).value(); diff --git a/tests/testimplementations.h b/tests/testimplementations.h index c371456..a47a775 100644 --- a/tests/testimplementations.h +++ b/tests/testimplementations.h @@ -23,7 +23,6 @@ #include #include -#include #include #include #include -- cgit v1.2.3 From 887abffb3f712acaa23eae174d5890f337fe43cb Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 28 Nov 2015 16:20:38 +0100 Subject: Cleanup --- tests/dummyresourcetest.cpp | 18 +++++++++--------- tests/querytest.cpp | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index d2fcda7..20c725f 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -70,7 +70,7 @@ private Q_SLOTS: query.propertyFilter.insert("uid", "testuid"); auto model = Akonadi2::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); } @@ -97,7 +97,7 @@ private Q_SLOTS: auto model = Akonadi2::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); qDebug() << value->getProperty("uid").toByteArray(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); @@ -127,7 +127,7 @@ private Q_SLOTS: auto model = Akonadi2::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); qDebug() << value->getProperty("uid").toByteArray(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid2")); @@ -160,7 +160,7 @@ private Q_SLOTS: auto model = Akonadi2::Store::loadModel(query); QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); QVERIFY(!value->getProperty("summary").toString().isEmpty()); qDebug() << value->getProperty("summary").toString(); @@ -178,7 +178,7 @@ private Q_SLOTS: auto model = Akonadi2::Store::loadModel(query); QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); QVERIFY(!value->getProperty("subject").toString().isEmpty()); qDebug() << value->getProperty("subject").toString(); @@ -206,7 +206,7 @@ private Q_SLOTS: { auto model = Akonadi2::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); @@ -224,7 +224,7 @@ private Q_SLOTS: { auto model = Akonadi2::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); @@ -266,7 +266,7 @@ private Q_SLOTS: Akonadi2::ApplicationDomain::Event event2; { QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); event2 = *value; @@ -280,7 +280,7 @@ private Q_SLOTS: { //TODO wait for a change signal QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(ModelResult::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); } diff --git a/tests/querytest.cpp b/tests/querytest.cpp index e354272..669bf58 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -108,7 +108,7 @@ private Q_SLOTS: auto model = Akonadi2::Store::loadModel(query); model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); - auto folderEntity = model->index(0, 0).data(ModelResult::DomainObjectRole).value(); + auto folderEntity = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); } @@ -130,7 +130,7 @@ private Q_SLOTS: auto model = Akonadi2::Store::loadModel(query); QTRY_COMPARE(model->rowCount(), 1); - auto folderEntity = model->index(0, 0).data(ModelResult::DomainObjectRole).value(); + auto folderEntity = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); Akonadi2::ApplicationDomain::Folder subfolder("org.kde.dummy.instance1"); -- cgit v1.2.3 From f715898a1b6781e2860727942ce510f324a23c71 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Nov 2015 10:32:41 +0100 Subject: Test model signals --- tests/clientapitest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index e97b2a4..bd1cccd 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -173,6 +173,28 @@ private Q_SLOTS: QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); } + void testModelSignals() + { + auto facade = DummyResourceFacade::registerFacade(); + auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); + subfolder->setProperty("parent", "id"); + facade->results << folder << subfolder; + ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); + + //Test + Akonadi2::Query query; + query.resources << "dummyresource.instance1"; + query.liveQuery = false; + query.parentProperty = "parent"; + + auto model = Akonadi2::Store::loadModel(query); + QSignalSpy spy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); + QVERIFY(spy.isValid()); + model->fetchMore(model->index(0, 0)); + QTRY_VERIFY(spy.count() >= 1); + } + void testModelNestedLive() { auto facade = DummyResourceFacade::registerFacade(); -- cgit v1.2.3 From 32a6d2f881bb6d12a4ab685b7bb3fb10c3bdf72c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Nov 2015 11:41:09 +0100 Subject: Use the ChildrenFetchedRole --- tests/clientapitest.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index bd1cccd..5d8cd9f 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -30,7 +30,6 @@ public: QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE { // capturedResultProvider = &resultProvider; - Trace() << "lkjsdflkjsdfljsdfljsdlfj"; auto resultProvider = new Akonadi2::ResultProvider(); resultProvider->onDone([resultProvider]() { @@ -40,7 +39,7 @@ public: //We have to do it this way, otherwise we're not setting the fetcher right auto emitter = resultProvider->emitter(); - resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &) { + resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &parent) { Trace() << "Running the fetcher"; for (const auto &res : results) { qDebug() << "Parent filter " << query.propertyFilter.value("parent").toByteArray() << res->identifier(); @@ -48,6 +47,7 @@ public: resultProvider->add(res); } } + resultProvider->initialResultSetComplete(parent); }); auto job = KAsync::start([query, resultProvider]() { }); @@ -87,7 +87,8 @@ private Q_SLOTS: query.liveQuery = false; auto model = Akonadi2::Store::loadModel(query); - QTRY_COMPARE(model->rowCount(QModelIndex()), 1); + QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(QModelIndex()), 1); } // //The query provider is supposed to delete itself @@ -168,9 +169,11 @@ private Q_SLOTS: query.parentProperty = "parent"; auto model = Akonadi2::Store::loadModel(query); - QTRY_COMPARE(model->rowCount(), 1); + QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 1); model->fetchMore(model->index(0, 0)); - QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); + QTRY_VERIFY(model->data(model->index(0, 0), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(model->index(0, 0)), 1); } void testModelSignals() -- cgit v1.2.3 From 0c744f0f14836ee70ca675135a9ca4cef080baa3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Nov 2015 15:58:56 +0100 Subject: Test modifications --- tests/clientapitest.cpp | 62 ++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 5d8cd9f..8f956ab 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -29,8 +29,6 @@ public: KAsync::Job remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE { - // capturedResultProvider = &resultProvider; - auto resultProvider = new Akonadi2::ResultProvider(); resultProvider->onDone([resultProvider]() { Trace() << "Result provider is done"; @@ -51,11 +49,12 @@ public: }); auto job = KAsync::start([query, resultProvider]() { }); + mResultProvider = resultProvider; return qMakePair(job, emitter); } QList results; - // Akonadi2::ResultProviderInterface *capturedResultProvider; + Akonadi2::ResultProviderInterface *mResultProvider; }; @@ -91,26 +90,6 @@ private Q_SLOTS: QCOMPARE(model->rowCount(QModelIndex()), 1); } - // //The query provider is supposed to delete itself - void testQueryLifetime() - { - auto facade = DummyResourceFacade::registerFacade(); - facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); - ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); - - Akonadi2::Query query; - query.resources << "dummyresource.instance1"; - query.liveQuery = true; - - { - auto model = Akonadi2::Store::loadModel(query); - QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - } - //It's running in a separate thread, so we have to wait for a moment until the query provider deletes itself. - // QTRY_VERIFY(!facade->capturedResultProvider); - QTest::qWait(300); - } - //TODO: This test doesn't belong to this testsuite void resourceManagement() { @@ -134,8 +113,8 @@ private Q_SLOTS: Akonadi2::Query query; query.propertyFilter.insert("type", "dummyresource"); auto model = Akonadi2::Store::loadModel(query); - //TODO ensure the initial query completed - QTRY_COMPARE(model->rowCount(QModelIndex()), 0); + QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(QModelIndex()), 0); } } @@ -218,12 +197,37 @@ private Q_SLOTS: model->fetchMore(model->index(0, 0)); QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); - // auto resultProvider = facade->capturedResultProvider.toStrongRef(); + auto resultProvider = facade->mResultProvider; + + //Test new toplevel folder + { + QSignalSpy rowsInsertedSpy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); + auto folder2 = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); + resultProvider->add(folder2); + QTRY_COMPARE(model->rowCount(), 2); + QTRY_COMPARE(rowsInsertedSpy.count(), 1); + QCOMPARE(rowsInsertedSpy.at(0).at(0).value(), QModelIndex()); + } - //A modification can also be a move - // resultProvider->modify(); + //Test changed name + { + QSignalSpy dataChanged(model.data(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector &))); + folder->setProperty("subject", "modifiedSubject"); + resultProvider->modify(folder); + QTRY_COMPARE(model->rowCount(), 2); + QTRY_COMPARE(dataChanged.count(), 1); + } + + //Test removal + { + QSignalSpy rowsRemovedSpy(model.data(), SIGNAL(rowsRemoved(const QModelIndex &, int, int))); + folder->setProperty("subject", "modifiedSubject"); + resultProvider->remove(subfolder); + QTRY_COMPARE(model->rowCount(model->index(0, 0)), 0); + QTRY_COMPARE(rowsRemovedSpy.count(), 1); + } - // resultProvider->remove(); + //TODO: A modification can also be a move } -- cgit v1.2.3