From 93c9ebb5d0654626cb8bf2e6b00a5845b210f82c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 17 May 2018 15:16:29 +0200 Subject: Fixed a readEntity call with empty uid Filtered entites are still passed through as removal, but if there is no other value for the reduction, the reduction result is empty. --- tests/querytest.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tests/querytest.cpp') diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 26564b5..fa016a2 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -954,6 +954,60 @@ private slots: QCOMPARE(resetSpy.size(), 0); } + void testFilteredReductionUpdate() + { + // Setup + auto folder1 = Folder::createEntity("sink.dummy.instance1"); + VERIFYEXEC(Sink::Store::create(folder1)); + + auto folder2 = Folder::createEntity("sink.dummy.instance1"); + VERIFYEXEC(Sink::Store::create(folder2)); + + // Ensure all local data is processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + + Query query; + query.setId("testFilteredReductionUpdate"); + query.setFlags(Query::LiveQuery); + query.filter(folder1); + query.reduce(Query::Reduce::Selector::max()).count("count").collect("folders"); + query.sort(); + + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 0); + + QSignalSpy insertedSpy(model.data(), &QAbstractItemModel::rowsInserted); + QSignalSpy removedSpy(model.data(), &QAbstractItemModel::rowsRemoved); + QSignalSpy changedSpy(model.data(), &QAbstractItemModel::dataChanged); + QSignalSpy layoutChangedSpy(model.data(), &QAbstractItemModel::layoutChanged); + QSignalSpy resetSpy(model.data(), &QAbstractItemModel::modelReset); + + //Ensure we don't end up with a mail in the thread that was filtered + //This tests the case of an otherwise emtpy thread on purpose. + { + auto mail = Mail::createEntity("sink.dummy.instance1"); + mail.setExtractedMessageId("filtered"); + mail.setFolder(folder2); + mail.setExtractedDate(QDateTime{QDate{2017, 2, 3}, QTime{11, 0, 0}}); + VERIFYEXEC(Sink::Store::create(mail)); + } + + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + QCOMPARE(model->rowCount(), 0); + + //Ensure the non-filtered still get through. + { + auto mail = Mail::createEntity("sink.dummy.instance1"); + mail.setExtractedMessageId("not-filtered"); + mail.setFolder(folder1); + mail.setExtractedDate(QDateTime{QDate{2017, 2, 3}, QTime{11, 0, 0}}); + VERIFYEXEC(Sink::Store::create(mail)); + } + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + QTRY_COMPARE(model->rowCount(), 1); + } + void testBloom() { // Setup -- cgit v1.2.3