summaryrefslogtreecommitdiffstats
path: root/tests/querytest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/querytest.cpp')
-rw-r--r--tests/querytest.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/querytest.cpp b/tests/querytest.cpp
index 328448f..b358621 100644
--- a/tests/querytest.cpp
+++ b/tests/querytest.cpp
@@ -1,6 +1,7 @@
1#include <QtTest> 1#include <QtTest>
2 2
3#include <QString> 3#include <QString>
4#include <QSignalSpy>
4 5
5#include "resource.h" 6#include "resource.h"
6#include "store.h" 7#include "store.h"
@@ -786,6 +787,12 @@ private slots:
786 auto model = Sink::Store::loadModel<Mail>(query); 787 auto model = Sink::Store::loadModel<Mail>(query);
787 QTRY_COMPARE(model->rowCount(), 1); 788 QTRY_COMPARE(model->rowCount(), 1);
788 789
790 QSignalSpy insertedSpy(model.data(), &QAbstractItemModel::rowsInserted);
791 QSignalSpy removedSpy(model.data(), &QAbstractItemModel::rowsRemoved);
792 QSignalSpy changedSpy(model.data(), &QAbstractItemModel::dataChanged);
793 QSignalSpy layoutChangedSpy(model.data(), &QAbstractItemModel::layoutChanged);
794 QSignalSpy resetSpy(model.data(), &QAbstractItemModel::modelReset);
795
789 //The leader should change to mail2 after the modification 796 //The leader should change to mail2 after the modification
790 { 797 {
791 auto mail2 = Mail::createEntity<Mail>("sink.dummy.instance1"); 798 auto mail2 = Mail::createEntity<Mail>("sink.dummy.instance1");
@@ -802,6 +809,13 @@ private slots:
802 QTRY_COMPARE(mail->getMessageId(), QByteArray{"mail2"}); 809 QTRY_COMPARE(mail->getMessageId(), QByteArray{"mail2"});
803 QCOMPARE(mail->getProperty("count").toInt(), 2); 810 QCOMPARE(mail->getProperty("count").toInt(), 2);
804 QCOMPARE(mail->getProperty("folders").toList().size(), 2); 811 QCOMPARE(mail->getProperty("folders").toList().size(), 2);
812
813 //This should eventually be just one modification instead of remove + add (See datastorequery reduce component)
814 QCOMPARE(insertedSpy.size(), 1);
815 QCOMPARE(removedSpy.size(), 1);
816 QCOMPARE(changedSpy.size(), 0);
817 QCOMPARE(layoutChangedSpy.size(), 0);
818 QCOMPARE(resetSpy.size(), 0);
805 } 819 }
806 820
807 void testBloom() 821 void testBloom()
@@ -875,12 +889,28 @@ private slots:
875 auto model = Sink::Store::loadModel<Mail>(query); 889 auto model = Sink::Store::loadModel<Mail>(query);
876 QTRY_COMPARE(model->rowCount(), 1); 890 QTRY_COMPARE(model->rowCount(), 1);
877 891
892 QSignalSpy insertedSpy(model.data(), &QAbstractItemModel::rowsInserted);
893 QSignalSpy removedSpy(model.data(), &QAbstractItemModel::rowsRemoved);
894 QSignalSpy changedSpy(model.data(), &QAbstractItemModel::dataChanged);
895 QSignalSpy layoutChangedSpy(model.data(), &QAbstractItemModel::layoutChanged);
896 QSignalSpy resetSpy(model.data(), &QAbstractItemModel::modelReset);
897
898 //This modification should make it through
899 {
900 //This should not trigger an entity already in model warning
901 mail1.setUnread(false);
902 VERIFYEXEC(Sink::Store::modify(mail1));
903 }
904
905 //This mail should make it through
878 { 906 {
879 auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); 907 auto mail = Mail::createEntity<Mail>("sink.dummy.instance1");
880 mail.setExtractedMessageId("mail2"); 908 mail.setExtractedMessageId("mail2");
881 mail.setFolder(folder1); 909 mail.setFolder(folder1);
882 VERIFYEXEC(Sink::Store::create(mail)); 910 VERIFYEXEC(Sink::Store::create(mail));
883 } 911 }
912
913 //This mail shouldn't make it through
884 { 914 {
885 auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); 915 auto mail = Mail::createEntity<Mail>("sink.dummy.instance1");
886 mail.setExtractedMessageId("mail3"); 916 mail.setExtractedMessageId("mail3");
@@ -892,6 +922,14 @@ private slots:
892 QTRY_COMPARE(model->rowCount(), 2); 922 QTRY_COMPARE(model->rowCount(), 2);
893 QTest::qWait(100); 923 QTest::qWait(100);
894 QCOMPARE(model->rowCount(), 2); 924 QCOMPARE(model->rowCount(), 2);
925
926 //From mail2
927 QCOMPARE(insertedSpy.size(), 1);
928 QCOMPARE(removedSpy.size(), 0);
929 //From the modification
930 QCOMPARE(changedSpy.size(), 1);
931 QCOMPARE(layoutChangedSpy.size(), 0);
932 QCOMPARE(resetSpy.size(), 0);
895 } 933 }
896}; 934};
897 935