diff options
Diffstat (limited to 'tests/querytest.cpp')
-rw-r--r-- | tests/querytest.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index d72dc7d..ab2a7e5 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -12,6 +12,8 @@ | |||
12 | #include "test.h" | 12 | #include "test.h" |
13 | #include "testutils.h" | 13 | #include "testutils.h" |
14 | 14 | ||
15 | using namespace Sink::ApplicationDomain; | ||
16 | |||
15 | /** | 17 | /** |
16 | * Test of the query system using the dummy resource. | 18 | * Test of the query system using the dummy resource. |
17 | * | 19 | * |
@@ -97,6 +99,46 @@ private slots: | |||
97 | QCOMPARE(model->rowCount(), 1); | 99 | QCOMPARE(model->rowCount(), 1); |
98 | } | 100 | } |
99 | 101 | ||
102 | void testFilter() | ||
103 | { | ||
104 | // Setup | ||
105 | { | ||
106 | Mail mail("sink.dummy.instance1"); | ||
107 | mail.setUid("test1"); | ||
108 | mail.setFolder("folder1"); | ||
109 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | ||
110 | } | ||
111 | { | ||
112 | Mail mail("sink.dummy.instance1"); | ||
113 | mail.setUid("test2"); | ||
114 | mail.setFolder("folder2"); | ||
115 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | ||
116 | } | ||
117 | |||
118 | // Test | ||
119 | Sink::Query query; | ||
120 | query.resources << "sink.dummy.instance1"; | ||
121 | query.liveQuery = true; | ||
122 | query.filter<Mail::Folder>("folder1"); | ||
123 | |||
124 | // We fetch before the data is available and rely on the live query mechanism to deliver the actual data | ||
125 | auto model = Sink::Store::loadModel<Mail>(query); | ||
126 | QTRY_COMPARE(model->rowCount(), 1); | ||
127 | |||
128 | auto mail = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>(); | ||
129 | { | ||
130 | mail->setFolder("folder2"); | ||
131 | Sink::Store::modify<Mail>(*mail).exec().waitForFinished(); | ||
132 | } | ||
133 | QTRY_COMPARE(model->rowCount(), 0); | ||
134 | |||
135 | { | ||
136 | mail->setFolder("folder1"); | ||
137 | Sink::Store::modify<Mail>(*mail).exec().waitForFinished(); | ||
138 | } | ||
139 | QTRY_COMPARE(model->rowCount(), 1); | ||
140 | } | ||
141 | |||
100 | void testById() | 142 | void testById() |
101 | { | 143 | { |
102 | QByteArray id; | 144 | QByteArray id; |
@@ -200,6 +242,13 @@ private slots: | |||
200 | Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); | 242 | Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); |
201 | } | 243 | } |
202 | 244 | ||
245 | { | ||
246 | Sink::ApplicationDomain::Mail mail("sink.dummy.instance1"); | ||
247 | mail.setProperty("uid", "test2"); | ||
248 | mail.setProperty("sender", "doe@example.org"); | ||
249 | Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); | ||
250 | } | ||
251 | |||
203 | // Test | 252 | // Test |
204 | Sink::Query query; | 253 | Sink::Query query; |
205 | query.resources << "sink.dummy.instance1"; | 254 | query.resources << "sink.dummy.instance1"; |
@@ -256,6 +305,61 @@ private slots: | |||
256 | QCOMPARE(model->rowCount(), 1); | 305 | QCOMPARE(model->rowCount(), 1); |
257 | } | 306 | } |
258 | 307 | ||
308 | /* | ||
309 | * Filter by two properties to make sure that we also use a non-index based filter. | ||
310 | */ | ||
311 | void testMailByUidAndFolder() | ||
312 | { | ||
313 | // Setup | ||
314 | Folder::Ptr folderEntity; | ||
315 | { | ||
316 | Folder folder("sink.dummy.instance1"); | ||
317 | Sink::Store::create<Folder>(folder).exec().waitForFinished(); | ||
318 | |||
319 | Sink::Query query; | ||
320 | query.resources << "sink.dummy.instance1"; | ||
321 | |||
322 | // Ensure all local data is processed | ||
323 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
324 | |||
325 | auto model = Sink::Store::loadModel<Folder>(query); | ||
326 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
327 | QCOMPARE(model->rowCount(), 1); | ||
328 | |||
329 | folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Folder::Ptr>(); | ||
330 | QVERIFY(!folderEntity->identifier().isEmpty()); | ||
331 | |||
332 | Mail mail("sink.dummy.instance1"); | ||
333 | mail.setProperty("uid", "test1"); | ||
334 | mail.setProperty("folder", folderEntity->identifier()); | ||
335 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | ||
336 | |||
337 | Mail mail1("sink.dummy.instance1"); | ||
338 | mail1.setProperty("uid", "test1"); | ||
339 | mail1.setProperty("folder", "foobar"); | ||
340 | Sink::Store::create<Mail>(mail1).exec().waitForFinished(); | ||
341 | |||
342 | Mail mail2("sink.dummy.instance1"); | ||
343 | mail2.setProperty("uid", "test2"); | ||
344 | mail2.setProperty("folder", folderEntity->identifier()); | ||
345 | Sink::Store::create<Mail>(mail2).exec().waitForFinished(); | ||
346 | } | ||
347 | |||
348 | // Test | ||
349 | Sink::Query query; | ||
350 | query.resources << "sink.dummy.instance1"; | ||
351 | query.filter<Mail::Folder>(*folderEntity); | ||
352 | query.filter<Mail::Uid>("test1"); | ||
353 | |||
354 | // Ensure all local data is processed | ||
355 | Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
356 | |||
357 | // We fetch before the data is available and rely on the live query mechanism to deliver the actual data | ||
358 | auto model = Sink::Store::loadModel<Mail>(query); | ||
359 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
360 | QCOMPARE(model->rowCount(), 1); | ||
361 | } | ||
362 | |||
259 | void testMailByFolderSortedByDate() | 363 | void testMailByFolderSortedByDate() |
260 | { | 364 | { |
261 | // Setup | 365 | // Setup |