Changeset View
Changeset View
Standalone View
Standalone View
tests/units/akonadi/akonadicachingstoragetest.cpp
Show First 20 Lines • Show All 366 Lines • ▼ Show 20 Line(s) | 316 | { | |||
---|---|---|---|---|---|
367 | { | 367 | { | ||
368 | const auto itemFetchIds = [job, toItemIds]{ | 368 | const auto itemFetchIds = [job, toItemIds]{ | ||
369 | return toItemIds(job->items()); | 369 | return toItemIds(job->items()); | ||
370 | }(); | 370 | }(); | ||
371 | QCOMPARE(itemFetchIds, expectedIds); | 371 | QCOMPARE(itemFetchIds, expectedIds); | ||
372 | QVERIFY(cache->item(44).isValid()); | 372 | QVERIFY(cache->item(44).isValid()); | ||
373 | } | 373 | } | ||
374 | } | 374 | } | ||
375 | | ||||
376 | void shouldCacheTags() | ||||
377 | { | ||||
378 | // GIVEN | ||||
379 | AkonadiFakeData data; | ||||
380 | | ||||
381 | data.createTag(GenTag().withId(42).withName(QStringLiteral("42Plain")).asPlain()); | ||||
382 | data.createTag(GenTag().withId(43).withName(QStringLiteral("43Context")).asContext()); | ||||
383 | data.createTag(GenTag().withId(44).withName(QStringLiteral("44Plain")).asPlain()); | ||||
384 | | ||||
385 | auto cache = Akonadi::Cache::Ptr::create(Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | ||||
386 | Akonadi::MonitorInterface::Ptr(data.createMonitor())); | ||||
387 | Akonadi::CachingStorage storage(cache, Akonadi::StorageInterface::Ptr(data.createStorage())); | ||||
388 | | ||||
389 | // WHEN | ||||
390 | auto job = storage.fetchTags(); | ||||
391 | QVERIFY2(job->kjob()->exec(), job->kjob()->errorString().toUtf8().constData()); | ||||
392 | | ||||
393 | // THEN | ||||
394 | const auto toTagNames = [](const Akonadi::Tag::List &tags) { | ||||
395 | auto res = QStringList(); | ||||
396 | std::transform(tags.cbegin(), tags.cend(), | ||||
397 | std::back_inserter(res), | ||||
398 | std::mem_fn(&Akonadi::Tag::name)); | ||||
399 | res.sort(); | ||||
400 | return res; | ||||
401 | }; | ||||
402 | | ||||
403 | auto expectedNames = QStringList() << "42Plain" << "43Context" << "44Plain"; | ||||
404 | | ||||
405 | { | ||||
406 | const auto tagFetchNames = [job, toTagNames]{ | ||||
407 | return toTagNames(job->tags()); | ||||
408 | }(); | ||||
409 | QCOMPARE(tagFetchNames, expectedNames); | ||||
410 | | ||||
411 | const auto tagCachedNames = [cache, toTagNames]{ | ||||
412 | const auto tags = cache->tags(); | ||||
413 | return toTagNames(tags); | ||||
414 | }(); | ||||
415 | QCOMPARE(tagCachedNames, expectedNames); | ||||
416 | } | ||||
417 | | ||||
418 | // WHEN (second time shouldn't hit the original storage) | ||||
419 | data.storageBehavior().setFetchTagsBehavior(AkonadiFakeStorageBehavior::EmptyFetch); | ||||
420 | data.storageBehavior().setFetchTagsErrorCode(128); | ||||
421 | job = storage.fetchTags(); | ||||
422 | QVERIFY2(job->kjob()->exec(), job->kjob()->errorString().toUtf8().constData()); | ||||
423 | | ||||
424 | { | ||||
425 | const auto tagFetchNames = [job, toTagNames]{ | ||||
426 | return toTagNames(job->tags()); | ||||
427 | }(); | ||||
428 | QCOMPARE(tagFetchNames, expectedNames); | ||||
429 | | ||||
430 | const auto tagCachedNames = [cache, toTagNames]{ | ||||
431 | const auto tags = cache->tags(); | ||||
432 | return toTagNames(tags); | ||||
433 | }(); | ||||
434 | QCOMPARE(tagCachedNames, expectedNames); | ||||
435 | } | ||||
436 | } | ||||
375 | }; | 437 | }; | ||
376 | 438 | | |||
377 | ZANSHIN_TEST_MAIN(AkonadiCachingStorageTest) | 439 | ZANSHIN_TEST_MAIN(AkonadiCachingStorageTest) | ||
378 | 440 | | |||
379 | #include "akonadicachingstoragetest.moc" | 441 | #include "akonadicachingstoragetest.moc" |