diff options
Diffstat (limited to 'tests/querytest.cpp')
-rw-r--r-- | tests/querytest.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 0844d72..1584c48 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -1182,6 +1182,78 @@ private slots: | |||
1182 | QCOMPARE(mail->getProperty("folders").toList().size(), 2); | 1182 | QCOMPARE(mail->getProperty("folders").toList().size(), 2); |
1183 | } | 1183 | } |
1184 | } | 1184 | } |
1185 | |||
1186 | /* | ||
1187 | * This test is here to ensure we don't crash if we call removeFromDisk with a running query. | ||
1188 | */ | ||
1189 | void testRemoveFromDiskWithRunningQuery() | ||
1190 | { | ||
1191 | { | ||
1192 | // Setup | ||
1193 | Folder::Ptr folderEntity; | ||
1194 | const auto date = QDateTime(QDate(2015, 7, 7), QTime(12, 0)); | ||
1195 | { | ||
1196 | Folder folder("sink.dummy.instance1"); | ||
1197 | Sink::Store::create<Folder>(folder).exec().waitForFinished(); | ||
1198 | |||
1199 | Sink::Query query; | ||
1200 | query.resourceFilter("sink.dummy.instance1"); | ||
1201 | |||
1202 | // Ensure all local data is processed | ||
1203 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); | ||
1204 | |||
1205 | auto model = Sink::Store::loadModel<Folder>(query); | ||
1206 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
1207 | QCOMPARE(model->rowCount(), 1); | ||
1208 | |||
1209 | folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Folder::Ptr>(); | ||
1210 | QVERIFY(!folderEntity->identifier().isEmpty()); | ||
1211 | |||
1212 | { | ||
1213 | Mail mail("sink.dummy.instance1"); | ||
1214 | mail.setExtractedMessageId("testSecond"); | ||
1215 | mail.setFolder(folderEntity->identifier()); | ||
1216 | mail.setExtractedDate(date.addDays(-1)); | ||
1217 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | ||
1218 | } | ||
1219 | { | ||
1220 | Mail mail("sink.dummy.instance1"); | ||
1221 | mail.setExtractedMessageId("testLatest"); | ||
1222 | mail.setFolder(folderEntity->identifier()); | ||
1223 | mail.setExtractedDate(date); | ||
1224 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | ||
1225 | } | ||
1226 | { | ||
1227 | Mail mail("sink.dummy.instance1"); | ||
1228 | mail.setExtractedMessageId("testLast"); | ||
1229 | mail.setFolder(folderEntity->identifier()); | ||
1230 | mail.setExtractedDate(date.addDays(-2)); | ||
1231 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | ||
1232 | } | ||
1233 | } | ||
1234 | |||
1235 | // Test | ||
1236 | Sink::Query query; | ||
1237 | query.resourceFilter("sink.dummy.instance1"); | ||
1238 | query.filter<Mail::Folder>(*folderEntity); | ||
1239 | query.sort<Mail::Date>(); | ||
1240 | query.limit(1); | ||
1241 | query.setFlags(Query::LiveQuery); | ||
1242 | query.reduce<ApplicationDomain::Mail::ThreadId>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()) | ||
1243 | .count("count") | ||
1244 | .collect<ApplicationDomain::Mail::Unread>("unreadCollected") | ||
1245 | .collect<ApplicationDomain::Mail::Important>("importantCollected"); | ||
1246 | |||
1247 | // Ensure all local data is processed | ||
1248 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); | ||
1249 | |||
1250 | auto model = Sink::Store::loadModel<Mail>(query); | ||
1251 | } | ||
1252 | |||
1253 | //FIXME: this will result in a crash in the above still running query. | ||
1254 | VERIFYEXEC(Sink::Store::removeDataFromDisk(QByteArray("sink.dummy.instance1"))); | ||
1255 | } | ||
1256 | |||
1185 | }; | 1257 | }; |
1186 | 1258 | ||
1187 | QTEST_MAIN(QueryTest) | 1259 | QTEST_MAIN(QueryTest) |