Changeset View
Changeset View
Standalone View
Standalone View
tests/testlib/akonadifakestorage.cpp
Show First 20 Lines • Show All 280 Lines • ▼ Show 20 Line(s) | |||||
281 | 281 | | |||
282 | KJob *AkonadiFakeStorage::createTransaction() | 282 | KJob *AkonadiFakeStorage::createTransaction() | ||
283 | { | 283 | { | ||
284 | auto job = new AkonadiFakeTransaction; | 284 | auto job = new AkonadiFakeTransaction; | ||
285 | Utils::JobHandler::install(job, noop); | 285 | Utils::JobHandler::install(job, noop); | ||
286 | return job; | 286 | return job; | ||
287 | } | 287 | } | ||
288 | 288 | | |||
289 | KJob *AkonadiFakeStorage::createTag(Akonadi::Tag tag) | | |||
290 | { | | |||
291 | Q_ASSERT(!tag.isValid()); | | |||
292 | | ||||
293 | auto job = new FakeJob; | | |||
294 | if (!m_data->tag(tag.id()).isValid()) { | | |||
295 | Utils::JobHandler::install(job, [=] () mutable { | | |||
296 | tag.setId(m_data->maxTagId() + 1); | | |||
297 | m_data->createTag(tag); | | |||
298 | }); | | |||
299 | } else { | | |||
300 | job->setExpectedError(1, QStringLiteral("The tag already exists")); | | |||
301 | Utils::JobHandler::install(job, noop); | | |||
302 | } | | |||
303 | return job; | | |||
304 | } | | |||
305 | | ||||
306 | KJob *AkonadiFakeStorage::updateTag(Akonadi::Tag tag) | | |||
307 | { | | |||
308 | auto job = new FakeJob; | | |||
309 | if (m_data->tag(tag.id()).isValid()) { | | |||
310 | Utils::JobHandler::install(job, [=] { | | |||
311 | m_data->modifyTag(tag); | | |||
312 | }); | | |||
313 | } else { | | |||
314 | job->setExpectedError(1, QStringLiteral("The tag doesn't exist")); | | |||
315 | Utils::JobHandler::install(job, noop); | | |||
316 | } | | |||
317 | return job; | | |||
318 | } | | |||
319 | | ||||
320 | KJob *AkonadiFakeStorage::removeTag(Akonadi::Tag tag) | | |||
321 | { | | |||
322 | auto job = new FakeJob; | | |||
323 | if (m_data->tag(tag.id()).isValid()) { | | |||
324 | Utils::JobHandler::install(job, [=] { | | |||
325 | m_data->removeTag(tag); | | |||
326 | }); | | |||
327 | } else { | | |||
328 | job->setExpectedError(1, QStringLiteral("The tag doesn't exist")); | | |||
329 | Utils::JobHandler::install(job, noop); | | |||
330 | } | | |||
331 | return job; | | |||
332 | } | | |||
333 | | ||||
334 | Akonadi::CollectionFetchJobInterface *AkonadiFakeStorage::fetchCollections(Akonadi::Collection collection, | 289 | Akonadi::CollectionFetchJobInterface *AkonadiFakeStorage::fetchCollections(Akonadi::Collection collection, | ||
335 | Akonadi::StorageInterface::FetchDepth depth) | 290 | Akonadi::StorageInterface::FetchDepth depth) | ||
336 | { | 291 | { | ||
337 | auto job = new AkonadiFakeCollectionFetchJob; | 292 | auto job = new AkonadiFakeCollectionFetchJob; | ||
338 | auto children = Akonadi::Collection::List(); | 293 | auto children = Akonadi::Collection::List(); | ||
339 | 294 | | |||
340 | switch (depth) { | 295 | switch (depth) { | ||
341 | case Base: | 296 | case Base: | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 357 | if (behavior == AkonadiFakeStorageBehavior::NormalFetch) | |||
403 | job->setItems(Akonadi::Item::List() << fullItem); | 358 | job->setItems(Akonadi::Item::List() << fullItem); | ||
404 | job->setExpectedError(m_data->storageBehavior().fetchItemErrorCode(item.id())); | 359 | job->setExpectedError(m_data->storageBehavior().fetchItemErrorCode(item.id())); | ||
405 | Utils::JobHandler::install(job, noop); | 360 | Utils::JobHandler::install(job, noop); | ||
406 | return job; | 361 | return job; | ||
407 | } | 362 | } | ||
408 | 363 | | |||
409 | Akonadi::ItemFetchJobInterface *AkonadiFakeStorage::fetchTagItems(Akonadi::Tag tag) | 364 | Akonadi::ItemFetchJobInterface *AkonadiFakeStorage::fetchTagItems(Akonadi::Tag tag) | ||
410 | { | 365 | { | ||
411 | auto items = m_data->tagItems(findId(tag)); | 366 | Akonadi::Item::List items; // TODO PORT = m_data->contextItems(findId(tag)); | ||
412 | std::transform(items.begin(), items.end(), | 367 | std::transform(items.begin(), items.end(), | ||
413 | items.begin(), | 368 | items.begin(), | ||
414 | [this] (const Akonadi::Item &item) { | 369 | [this] (const Akonadi::Item &item) { | ||
415 | auto collection = m_data->reconstructAncestors(item.parentCollection()); | 370 | auto collection = m_data->reconstructAncestors(item.parentCollection()); | ||
416 | auto result = item; | 371 | auto result = item; | ||
417 | result.setParentCollection(collection); | 372 | result.setParentCollection(collection); | ||
418 | // Force payload detach | 373 | // Force payload detach | ||
419 | result.setPayloadFromData(result.payloadData()); | 374 | result.setPayloadFromData(result.payloadData()); | ||
420 | return result; | 375 | return result; | ||
421 | }); | 376 | }); | ||
422 | 377 | | |||
423 | auto job = new AkonadiFakeItemFetchJob; | 378 | auto job = new AkonadiFakeItemFetchJob; | ||
424 | const auto behavior = m_data->storageBehavior().fetchTagItemsBehavior(tag.id()); | 379 | const auto behavior = m_data->storageBehavior().fetchTagItemsBehavior(tag.id()); | ||
425 | if (behavior == AkonadiFakeStorageBehavior::NormalFetch) | 380 | if (behavior == AkonadiFakeStorageBehavior::NormalFetch) | ||
426 | job->setItems(items); | 381 | job->setItems(items); | ||
427 | job->setExpectedError(m_data->storageBehavior().fetchTagItemsErrorCode(tag.id())); | 382 | job->setExpectedError(m_data->storageBehavior().fetchTagItemsErrorCode(tag.id())); | ||
428 | Utils::JobHandler::install(job, noop); | 383 | Utils::JobHandler::install(job, noop); | ||
429 | return job; | 384 | return job; | ||
430 | } | 385 | } | ||
431 | 386 | | |||
432 | Akonadi::TagFetchJobInterface *AkonadiFakeStorage::fetchTags() | 387 | Akonadi::TagFetchJobInterface *AkonadiFakeStorage::fetchTags() | ||
433 | { | 388 | { | ||
434 | auto job = new AkonadiFakeTagFetchJob; | 389 | auto job = new AkonadiFakeTagFetchJob; | ||
435 | const auto behavior = m_data->storageBehavior().fetchTagsBehavior(); | 390 | const auto behavior = m_data->storageBehavior().fetchTagsBehavior(); | ||
436 | if (behavior == AkonadiFakeStorageBehavior::NormalFetch) | 391 | //if (behavior == AkonadiFakeStorageBehavior::NormalFetch) | ||
437 | job->setTags(m_data->tags()); | 392 | // TODO PORT job->setTags(m_data->contexts()); | ||
438 | job->setExpectedError(m_data->storageBehavior().fetchTagsErrorCode()); | 393 | job->setExpectedError(m_data->storageBehavior().fetchTagsErrorCode()); | ||
439 | Utils::JobHandler::install(job, noop); | 394 | Utils::JobHandler::install(job, noop); | ||
440 | return job; | 395 | return job; | ||
441 | } | 396 | } | ||
442 | 397 | | |||
443 | Akonadi::Tag::Id AkonadiFakeStorage::findId(const Akonadi::Tag &tag) | | |||
444 | { | | |||
445 | if (tag.isValid() || tag.gid().isEmpty()) | | |||
446 | return tag.id(); | | |||
447 | | ||||
448 | const auto gid = tag.gid(); | | |||
449 | auto tags = m_data->tags(); | | |||
450 | auto result = std::find_if(tags.constBegin(), tags.constEnd(), | | |||
451 | [gid] (const Akonadi::Tag &tag) { | | |||
452 | return tag.gid() == gid; | | |||
453 | }); | | |||
454 | return (result != tags.constEnd()) ? result->id() : tag.id(); | | |||
455 | } | | |||
456 | | ||||
457 | Akonadi::Collection::Id AkonadiFakeStorage::findId(const Akonadi::Collection &collection) | 398 | Akonadi::Collection::Id AkonadiFakeStorage::findId(const Akonadi::Collection &collection) | ||
458 | { | 399 | { | ||
459 | if (collection.isValid() || collection.remoteId().isEmpty()) | 400 | if (collection.isValid() || collection.remoteId().isEmpty()) | ||
460 | return collection.id(); | 401 | return collection.id(); | ||
461 | 402 | | |||
462 | const auto remoteId = collection.remoteId(); | 403 | const auto remoteId = collection.remoteId(); | ||
463 | auto collections = m_data->collections(); | 404 | auto collections = m_data->collections(); | ||
464 | auto result = std::find_if(collections.constBegin(), collections.constEnd(), | 405 | auto result = std::find_if(collections.constBegin(), collections.constEnd(), | ||
Show All 35 Lines |