Changeset View
Changeset View
Standalone View
Standalone View
autotests/libs/etmpopulationtest.cpp
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Line(s) | |||||
134 | private Q_SLOTS: | 134 | private Q_SLOTS: | ||
135 | void initTestCase(); | 135 | void initTestCase(); | ||
136 | void testMonitoringCollectionsPreset(); | 136 | void testMonitoringCollectionsPreset(); | ||
137 | void testMonitoringCollections(); | 137 | void testMonitoringCollections(); | ||
138 | void testFullPopulation(); | 138 | void testFullPopulation(); | ||
139 | void testAddMonitoringCollections(); | 139 | void testAddMonitoringCollections(); | ||
140 | void testRemoveMonitoringCollections(); | 140 | void testRemoveMonitoringCollections(); | ||
141 | void testDisplayFilter(); | 141 | void testDisplayFilter(); | ||
142 | void testReferenceCollection(); | | |||
143 | void testLoadingOfHiddenCollection(); | 142 | void testLoadingOfHiddenCollection(); | ||
144 | void testSwitchFromReferenceToEnabled(); | | |||
145 | 143 | | |||
146 | private: | 144 | private: | ||
147 | Collection res; | 145 | Collection res; | ||
148 | QString mainCollectionName; | 146 | QString mainCollectionName; | ||
149 | Collection monitorCol; | 147 | Collection monitorCol; | ||
150 | Collection col1; | 148 | Collection col1; | ||
151 | Collection col2; | 149 | Collection col2; | ||
152 | Collection col3; | 150 | Collection col3; | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 298 | { | |||
314 | QVERIFY(getIndex(QStringLiteral("col3"), model).isValid()); | 312 | QVERIFY(getIndex(QStringLiteral("col3"), model).isValid()); | ||
315 | QVERIFY(getIndex(QStringLiteral("col4"), model).isValid()); | 313 | QVERIFY(getIndex(QStringLiteral("col4"), model).isValid()); | ||
316 | QVERIFY(!getIndex(QStringLiteral("col5"), model).isValid()); | 314 | QVERIFY(!getIndex(QStringLiteral("col5"), model).isValid()); | ||
317 | 315 | | |||
318 | Akonadi::CollectionDeleteJob *deleteJob = new Akonadi::CollectionDeleteJob(col5); | 316 | Akonadi::CollectionDeleteJob *deleteJob = new Akonadi::CollectionDeleteJob(col5); | ||
319 | AKVERIFYEXEC(deleteJob); | 317 | AKVERIFYEXEC(deleteJob); | ||
320 | } | 318 | } | ||
321 | 319 | | |||
322 | void EtmPopulationTest::testReferenceCollection() | | |||
323 | { | | |||
324 | Collection col5 = createCollection(QStringLiteral("col5"), monitorCol, false); | | |||
325 | QVERIFY(col5.isValid()); | | |||
326 | | ||||
327 | ChangeRecorder *changeRecorder = new ChangeRecorder(this); | | |||
328 | InspectableETM *model = new InspectableETM(changeRecorder, this); | | |||
329 | model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation); | | |||
330 | model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive); | | |||
331 | model->setListFilter(Akonadi::CollectionFetchScope::Display); | | |||
332 | | ||||
333 | QTRY_VERIFY(model->isFullyPopulated()); | | |||
334 | QVERIFY(!getIndex(QStringLiteral("col5"), model).isValid()); | | |||
335 | //Check that this random other collection is actually available | | |||
336 | QVERIFY(getIndex(QStringLiteral("col1"), model).isValid()); | | |||
337 | | ||||
338 | ModelSignalSpy spy(*model); | | |||
339 | | ||||
340 | //Reference the collection and it should appear in the model | | |||
341 | model->setCollectionReferenced(col5, true); | | |||
342 | | ||||
343 | QTRY_VERIFY(getIndex(QStringLiteral("col5"), model).isValid()); | | |||
344 | QTRY_VERIFY(getIndex(QStringLiteral("col5"), model).data(Akonadi::EntityTreeModel::IsPopulatedRole).toBool()); | | |||
345 | //Check that this random other collection is still available | | |||
346 | QVERIFY(getIndex(QStringLiteral("col1"), model).isValid()); | | |||
347 | //Verify the etms collection has been updated accordingly | | |||
348 | QTRY_VERIFY(getIndex(QStringLiteral("col5"), model).data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>().referenced()); | | |||
349 | | ||||
350 | //Ensure all signals have been delivered to the spy | | |||
351 | QTest::qWait(0); | | |||
352 | QCOMPARE(spy.mSignals.count(QStringLiteral("rowsInserted")), 1); | | |||
353 | //Signals for data-changed signal from the referencing | | |||
354 | QCOMPARE(spy.mSignals.count(QStringLiteral("dataChanged")), 2); | | |||
355 | | ||||
356 | //Dereference the collection and it should disappear again | | |||
357 | model->setCollectionReferenced(col5, false); | | |||
358 | QTRY_VERIFY(!getIndex(QStringLiteral("col5"), model).isValid()); | | |||
359 | //Check that this random other collection is still available | | |||
360 | QVERIFY(getIndex(QStringLiteral("col1"), model).isValid()); | | |||
361 | | ||||
362 | Akonadi::CollectionDeleteJob *deleteJob = new Akonadi::CollectionDeleteJob(col5); | | |||
363 | AKVERIFYEXEC(deleteJob); | | |||
364 | } | | |||
365 | | ||||
366 | /* | 320 | /* | ||
367 | * Col5 and it's ancestors should be included although the ancestors don't match the mimetype filter. | 321 | * Col5 and it's ancestors should be included although the ancestors don't match the mimetype filter. | ||
368 | */ | 322 | */ | ||
369 | void EtmPopulationTest::testLoadingOfHiddenCollection() | 323 | void EtmPopulationTest::testLoadingOfHiddenCollection() | ||
370 | { | 324 | { | ||
371 | Collection col5 = createCollection(QStringLiteral("col5"), monitorCol, false, QStringList() << QStringLiteral("application/test")); | 325 | Collection col5 = createCollection(QStringLiteral("col5"), monitorCol, false, QStringList() << QStringLiteral("application/test")); | ||
372 | QVERIFY(col5.isValid()); | 326 | QVERIFY(col5.isValid()); | ||
373 | 327 | | |||
374 | ChangeRecorder *changeRecorder = new ChangeRecorder(this); | 328 | ChangeRecorder *changeRecorder = new ChangeRecorder(this); | ||
375 | changeRecorder->setMimeTypeMonitored(QStringLiteral("application/test"), true); | 329 | changeRecorder->setMimeTypeMonitored(QStringLiteral("application/test"), true); | ||
376 | InspectableETM *model = new InspectableETM(changeRecorder, this); | 330 | InspectableETM *model = new InspectableETM(changeRecorder, this); | ||
377 | model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation); | 331 | model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation); | ||
378 | model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive); | 332 | model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive); | ||
379 | 333 | | |||
380 | QTRY_VERIFY(model->isCollectionTreeFetched()); | 334 | QTRY_VERIFY(model->isCollectionTreeFetched()); | ||
381 | QVERIFY(getIndex(QStringLiteral("col5"), model).isValid()); | 335 | QVERIFY(getIndex(QStringLiteral("col5"), model).isValid()); | ||
382 | 336 | | |||
383 | Akonadi::CollectionDeleteJob *deleteJob = new Akonadi::CollectionDeleteJob(col5); | 337 | Akonadi::CollectionDeleteJob *deleteJob = new Akonadi::CollectionDeleteJob(col5); | ||
384 | AKVERIFYEXEC(deleteJob); | 338 | AKVERIFYEXEC(deleteJob); | ||
385 | } | 339 | } | ||
386 | 340 | | |||
387 | void EtmPopulationTest::testSwitchFromReferenceToEnabled() | | |||
388 | { | | |||
389 | Collection col5 = createCollection(QStringLiteral("col5"), monitorCol, false, QStringList() << QStringLiteral("application/test") << Collection::mimeType()); | | |||
390 | QVERIFY(col5.isValid()); | | |||
391 | Collection col6 = createCollection(QStringLiteral("col6"), col5, true, QStringList() << QStringLiteral("application/test")); | | |||
392 | QVERIFY(col6.isValid()); | | |||
393 | | ||||
394 | ChangeRecorder *changeRecorder = new ChangeRecorder(this); | | |||
395 | InspectableETM *model = new InspectableETM(changeRecorder, this); | | |||
396 | model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation); | | |||
397 | model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive); | | |||
398 | model->setListFilter(Akonadi::CollectionFetchScope::Display); | | |||
399 | QTRY_VERIFY(model->isFullyPopulated()); | | |||
400 | model->setCollectionReferenced(col5, true); | | |||
401 | QTRY_VERIFY(getIndex(QStringLiteral("col5"), model).data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>().referenced()); | | |||
402 | | ||||
403 | //Dereference and enable the collection | | |||
404 | col5.setEnabled(true); | | |||
405 | model->setCollectionReferenced(col5, false); | | |||
406 | | ||||
407 | //Index and child should stay in model since both are enabled | | |||
408 | QVERIFY(getIndex(QStringLiteral("col5"), model).isValid()); | | |||
409 | QVERIFY(getIndex(QStringLiteral("col6"), model).isValid()); | | |||
410 | | ||||
411 | Akonadi::CollectionDeleteJob *deleteJob = new Akonadi::CollectionDeleteJob(col5); | | |||
412 | AKVERIFYEXEC(deleteJob); | | |||
413 | } | | |||
414 | | ||||
415 | #include "etmpopulationtest.moc" | 341 | #include "etmpopulationtest.moc" | ||
416 | 342 | | |||
417 | QTEST_AKONADIMAIN(EtmPopulationTest) | 343 | QTEST_AKONADIMAIN(EtmPopulationTest) | ||
418 | 344 | |