From 52ad48c8bd755a2fde249296d6017853538f478f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 23 Sep 2016 01:35:13 +0200 Subject: A new query system --- tests/querytest.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'tests') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index d72dc7d..ab2a7e5 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -12,6 +12,8 @@ #include "test.h" #include "testutils.h" +using namespace Sink::ApplicationDomain; + /** * Test of the query system using the dummy resource. * @@ -97,6 +99,46 @@ private slots: QCOMPARE(model->rowCount(), 1); } + void testFilter() + { + // Setup + { + Mail mail("sink.dummy.instance1"); + mail.setUid("test1"); + mail.setFolder("folder1"); + Sink::Store::create(mail).exec().waitForFinished(); + } + { + Mail mail("sink.dummy.instance1"); + mail.setUid("test2"); + mail.setFolder("folder2"); + Sink::Store::create(mail).exec().waitForFinished(); + } + + // Test + Sink::Query query; + query.resources << "sink.dummy.instance1"; + query.liveQuery = true; + query.filter("folder1"); + + // We fetch before the data is available and rely on the live query mechanism to deliver the actual data + auto model = Sink::Store::loadModel(query); + QTRY_COMPARE(model->rowCount(), 1); + + auto mail = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); + { + mail->setFolder("folder2"); + Sink::Store::modify(*mail).exec().waitForFinished(); + } + QTRY_COMPARE(model->rowCount(), 0); + + { + mail->setFolder("folder1"); + Sink::Store::modify(*mail).exec().waitForFinished(); + } + QTRY_COMPARE(model->rowCount(), 1); + } + void testById() { QByteArray id; @@ -200,6 +242,13 @@ private slots: Sink::Store::create(mail).exec().waitForFinished(); } + { + Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); + mail.setProperty("uid", "test2"); + mail.setProperty("sender", "doe@example.org"); + Sink::Store::create(mail).exec().waitForFinished(); + } + // Test Sink::Query query; query.resources << "sink.dummy.instance1"; @@ -256,6 +305,61 @@ private slots: QCOMPARE(model->rowCount(), 1); } + /* + * Filter by two properties to make sure that we also use a non-index based filter. + */ + void testMailByUidAndFolder() + { + // Setup + Folder::Ptr folderEntity; + { + Folder folder("sink.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); + + Sink::Query query; + query.resources << "sink.dummy.instance1"; + + // Ensure all local data is processed + Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 1); + + folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); + QVERIFY(!folderEntity->identifier().isEmpty()); + + Mail mail("sink.dummy.instance1"); + mail.setProperty("uid", "test1"); + mail.setProperty("folder", folderEntity->identifier()); + Sink::Store::create(mail).exec().waitForFinished(); + + Mail mail1("sink.dummy.instance1"); + mail1.setProperty("uid", "test1"); + mail1.setProperty("folder", "foobar"); + Sink::Store::create(mail1).exec().waitForFinished(); + + Mail mail2("sink.dummy.instance1"); + mail2.setProperty("uid", "test2"); + mail2.setProperty("folder", folderEntity->identifier()); + Sink::Store::create(mail2).exec().waitForFinished(); + } + + // Test + Sink::Query query; + query.resources << "sink.dummy.instance1"; + query.filter(*folderEntity); + query.filter("test1"); + + // Ensure all local data is processed + Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + // We fetch before the data is available and rely on the live query mechanism to deliver the actual data + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 1); + } + void testMailByFolderSortedByDate() { // Setup -- cgit v1.2.3