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/querytest.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/querytest.cpp (limited to 'tests/querytest.cpp') 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 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/querytest.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests/querytest.cpp') 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 -- 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/querytest.cpp') 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 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/querytest.cpp') 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 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/querytest.cpp') 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 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/querytest.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/querytest.cpp') 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(); -- 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/querytest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/querytest.cpp') 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