From 7189433c0a55cee16ec54e8af767a4f6b1d614e9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 15 Feb 2016 13:42:36 +0100 Subject: Ensure we correctly sort by date. --- tests/querytest.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'tests') 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: QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); } + + void testMailByFolderSortedByDate() + { + //Setup + Sink::ApplicationDomain::Folder::Ptr folderEntity; + { + Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); + + Sink::Query query; + query.resources << "org.kde.dummy.instance1"; + + //Ensure all local data is processed + Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 1); + + folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); + QVERIFY(!folderEntity->identifier().isEmpty()); + + const auto date = QDateTime(QDate(2015, 7, 7), QTime(12, 0)); + { + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + mail.setProperty("uid", "testSecond"); + mail.setProperty("folder", folderEntity->identifier()); + mail.setProperty("date", date.addDays(-1)); + Sink::Store::create(mail).exec().waitForFinished(); + } + { + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + mail.setProperty("uid", "testLatest"); + mail.setProperty("folder", folderEntity->identifier()); + mail.setProperty("date", date); + Sink::Store::create(mail).exec().waitForFinished(); + } + { + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + mail.setProperty("uid", "testLast"); + mail.setProperty("folder", folderEntity->identifier()); + mail.setProperty("date", date.addDays(-2)); + Sink::Store::create(mail).exec().waitForFinished(); + } + } + + //Test + Sink::Query query; + query.resources << "org.kde.dummy.instance1"; + query.propertyFilter.insert("folder", folderEntity->identifier()); + query.sortProperty = "date"; + query.limit = 1; + + //Ensure all local data is processed + Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + //We fetch before the data is available and rely on the live query mechanism to deliver the actual data + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + //The model is not sorted, but the limited set is sorted, so we can only test for the latest result. + QCOMPARE(model->rowCount(), 1); + QCOMPARE(model->index(0, 0).data(Sink::Store::DomainObjectRole).value()->getProperty("uid").toByteArray(), QByteArray("testLatest")); + } }; QTEST_MAIN(QueryTest) -- cgit v1.2.3