diff options
Diffstat (limited to 'tests/querytest.cpp')
-rw-r--r-- | tests/querytest.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
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: | |||
954 | QCOMPARE(resetSpy.size(), 0); | 954 | QCOMPARE(resetSpy.size(), 0); |
955 | } | 955 | } |
956 | 956 | ||
957 | void testFilteredReductionUpdate() | ||
958 | { | ||
959 | // Setup | ||
960 | auto folder1 = Folder::createEntity<Folder>("sink.dummy.instance1"); | ||
961 | VERIFYEXEC(Sink::Store::create<Folder>(folder1)); | ||
962 | |||
963 | auto folder2 = Folder::createEntity<Folder>("sink.dummy.instance1"); | ||
964 | VERIFYEXEC(Sink::Store::create<Folder>(folder2)); | ||
965 | |||
966 | // Ensure all local data is processed | ||
967 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
968 | |||
969 | Query query; | ||
970 | query.setId("testFilteredReductionUpdate"); | ||
971 | query.setFlags(Query::LiveQuery); | ||
972 | query.filter<Mail::Folder>(folder1); | ||
973 | query.reduce<Mail::Folder>(Query::Reduce::Selector::max<Mail::Date>()).count("count").collect<Mail::Folder>("folders"); | ||
974 | query.sort<Mail::Date>(); | ||
975 | |||
976 | auto model = Sink::Store::loadModel<Mail>(query); | ||
977 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
978 | QCOMPARE(model->rowCount(), 0); | ||
979 | |||
980 | QSignalSpy insertedSpy(model.data(), &QAbstractItemModel::rowsInserted); | ||
981 | QSignalSpy removedSpy(model.data(), &QAbstractItemModel::rowsRemoved); | ||
982 | QSignalSpy changedSpy(model.data(), &QAbstractItemModel::dataChanged); | ||
983 | QSignalSpy layoutChangedSpy(model.data(), &QAbstractItemModel::layoutChanged); | ||
984 | QSignalSpy resetSpy(model.data(), &QAbstractItemModel::modelReset); | ||
985 | |||
986 | //Ensure we don't end up with a mail in the thread that was filtered | ||
987 | //This tests the case of an otherwise emtpy thread on purpose. | ||
988 | { | ||
989 | auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); | ||
990 | mail.setExtractedMessageId("filtered"); | ||
991 | mail.setFolder(folder2); | ||
992 | mail.setExtractedDate(QDateTime{QDate{2017, 2, 3}, QTime{11, 0, 0}}); | ||
993 | VERIFYEXEC(Sink::Store::create(mail)); | ||
994 | } | ||
995 | |||
996 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
997 | QCOMPARE(model->rowCount(), 0); | ||
998 | |||
999 | //Ensure the non-filtered still get through. | ||
1000 | { | ||
1001 | auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); | ||
1002 | mail.setExtractedMessageId("not-filtered"); | ||
1003 | mail.setFolder(folder1); | ||
1004 | mail.setExtractedDate(QDateTime{QDate{2017, 2, 3}, QTime{11, 0, 0}}); | ||
1005 | VERIFYEXEC(Sink::Store::create(mail)); | ||
1006 | } | ||
1007 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
1008 | QTRY_COMPARE(model->rowCount(), 1); | ||
1009 | } | ||
1010 | |||
957 | void testBloom() | 1011 | void testBloom() |
958 | { | 1012 | { |
959 | // Setup | 1013 | // Setup |