diff options
Diffstat (limited to 'tests/querytest.cpp')
-rw-r--r-- | tests/querytest.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 16376b9..50fc67f 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -259,6 +259,69 @@ private Q_SLOTS: | |||
259 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | 259 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); |
260 | QCOMPARE(model->rowCount(), 1); | 260 | QCOMPARE(model->rowCount(), 1); |
261 | } | 261 | } |
262 | |||
263 | void testMailByFolderSortedByDate() | ||
264 | { | ||
265 | //Setup | ||
266 | Sink::ApplicationDomain::Folder::Ptr folderEntity; | ||
267 | { | ||
268 | Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); | ||
269 | Sink::Store::create<Sink::ApplicationDomain::Folder>(folder).exec().waitForFinished(); | ||
270 | |||
271 | Sink::Query query; | ||
272 | query.resources << "org.kde.dummy.instance1"; | ||
273 | |||
274 | //Ensure all local data is processed | ||
275 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
276 | |||
277 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); | ||
278 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
279 | QCOMPARE(model->rowCount(), 1); | ||
280 | |||
281 | folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>(); | ||
282 | QVERIFY(!folderEntity->identifier().isEmpty()); | ||
283 | |||
284 | const auto date = QDateTime(QDate(2015, 7, 7), QTime(12, 0)); | ||
285 | { | ||
286 | Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); | ||
287 | mail.setProperty("uid", "testSecond"); | ||
288 | mail.setProperty("folder", folderEntity->identifier()); | ||
289 | mail.setProperty("date", date.addDays(-1)); | ||
290 | Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); | ||
291 | } | ||
292 | { | ||
293 | Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); | ||
294 | mail.setProperty("uid", "testLatest"); | ||
295 | mail.setProperty("folder", folderEntity->identifier()); | ||
296 | mail.setProperty("date", date); | ||
297 | Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); | ||
298 | } | ||
299 | { | ||
300 | Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); | ||
301 | mail.setProperty("uid", "testLast"); | ||
302 | mail.setProperty("folder", folderEntity->identifier()); | ||
303 | mail.setProperty("date", date.addDays(-2)); | ||
304 | Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); | ||
305 | } | ||
306 | } | ||
307 | |||
308 | //Test | ||
309 | Sink::Query query; | ||
310 | query.resources << "org.kde.dummy.instance1"; | ||
311 | query.propertyFilter.insert("folder", folderEntity->identifier()); | ||
312 | query.sortProperty = "date"; | ||
313 | query.limit = 1; | ||
314 | |||
315 | //Ensure all local data is processed | ||
316 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
317 | |||
318 | //We fetch before the data is available and rely on the live query mechanism to deliver the actual data | ||
319 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); | ||
320 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
321 | //The model is not sorted, but the limited set is sorted, so we can only test for the latest result. | ||
322 | QCOMPARE(model->rowCount(), 1); | ||
323 | QCOMPARE(model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->getProperty("uid").toByteArray(), QByteArray("testLatest")); | ||
324 | } | ||
262 | }; | 325 | }; |
263 | 326 | ||
264 | QTEST_MAIN(QueryTest) | 327 | QTEST_MAIN(QueryTest) |