Changeset View
Changeset View
Standalone View
Standalone View
tests/units/akonadi/akonadilivequeryhelperstest.cpp
Show First 20 Lines • Show All 370 Lines • ▼ Show 20 Line(s) | 306 | { | |||
---|---|---|---|---|---|
371 | result.clear(); | 371 | result.clear(); | ||
372 | std::transform(items.constBegin(), items.constEnd(), | 372 | std::transform(items.constBegin(), items.constEnd(), | ||
373 | std::back_inserter(result), | 373 | std::back_inserter(result), | ||
374 | titleFromItem); | 374 | titleFromItem); | ||
375 | result.sort(); | 375 | result.sort(); | ||
376 | QCOMPARE(result, expected); | 376 | QCOMPARE(result, expected); | ||
377 | } | 377 | } | ||
378 | 378 | | |||
379 | void shouldFetchItemsByCollection_data() | ||||
380 | { | ||||
381 | QTest::addColumn<Akonadi::Collection>("collection"); | ||||
382 | | ||||
383 | QTest::newRow("first collection") << Akonadi::Collection(42); | ||||
384 | QTest::newRow("second collection") << Akonadi::Collection(43); | ||||
385 | } | ||||
386 | | ||||
387 | void shouldFetchItemsByCollection() | ||||
388 | { | ||||
389 | // GIVEN | ||||
390 | auto data = AkonadiFakeData(); | ||||
391 | auto helpers = createHelpers(data); | ||||
392 | | ||||
393 | // Two top level collections with tasks | ||||
394 | data.createCollection(GenCollection().withId(42).withRootAsParent().withName(QStringLiteral("42")).withTaskContent()); | ||||
395 | data.createCollection(GenCollection().withId(43).withRootAsParent().withName(QStringLiteral("43")).withTaskContent()); | ||||
396 | | ||||
397 | // Two items in each collection | ||||
398 | data.createItem(GenTodo().withId(42).withParent(42).withTitle(QStringLiteral("42"))); | ||||
399 | data.createItem(GenTodo().withId(43).withParent(42).withTitle(QStringLiteral("43"))); | ||||
400 | data.createItem(GenTodo().withId(44).withParent(43).withTitle(QStringLiteral("44"))); | ||||
401 | data.createItem(GenTodo().withId(45).withParent(43).withTitle(QStringLiteral("45"))); | ||||
402 | | ||||
403 | // The list which will be filled by the fetch function | ||||
404 | auto items = Akonadi::Item::List(); | ||||
405 | auto add = [&items] (const Akonadi::Item &item) { | ||||
406 | items.append(item); | ||||
407 | }; | ||||
408 | | ||||
409 | // WHEN | ||||
410 | QFETCH(Akonadi::Collection, collection); | ||||
411 | auto fetch = helpers->fetchItems(collection); | ||||
412 | fetch(add); | ||||
413 | TestHelpers::waitForEmptyJobQueue(); | ||||
414 | | ||||
415 | auto result = QStringList(); | ||||
416 | std::transform(items.constBegin(), items.constEnd(), | ||||
417 | std::back_inserter(result), | ||||
418 | titleFromItem); | ||||
419 | result.sort(); | ||||
420 | | ||||
421 | // THEN | ||||
422 | auto expected = QStringList(); | ||||
423 | | ||||
424 | switch (collection.id()) { | ||||
425 | case 42: | ||||
426 | expected << QStringLiteral("42") << QStringLiteral("43"); | ||||
427 | break; | ||||
428 | case 43: | ||||
429 | expected << QStringLiteral("44") << QStringLiteral("45"); | ||||
430 | break; | ||||
431 | } | ||||
432 | QVERIFY(!expected.isEmpty()); | ||||
433 | | ||||
434 | expected.sort(); | ||||
435 | QCOMPARE(result, expected); | ||||
436 | | ||||
437 | // WHEN (should not crash when the helpers object is deleted) | ||||
438 | helpers.clear(); | ||||
439 | items.clear(); | ||||
440 | fetch(add); | ||||
441 | TestHelpers::waitForEmptyJobQueue(); | ||||
442 | | ||||
443 | // THEN | ||||
444 | result.clear(); | ||||
445 | std::transform(items.constBegin(), items.constEnd(), | ||||
446 | std::back_inserter(result), | ||||
447 | titleFromItem); | ||||
448 | result.sort(); | ||||
449 | QCOMPARE(result, expected); | ||||
450 | } | ||||
451 | | ||||
379 | void shouldFetchItemsByTag_data() | 452 | void shouldFetchItemsByTag_data() | ||
380 | { | 453 | { | ||
381 | QTest::addColumn<Akonadi::Tag>("tag"); | 454 | QTest::addColumn<Akonadi::Tag>("tag"); | ||
382 | 455 | | |||
383 | QTest::newRow("first tag") << Akonadi::Tag(42); | 456 | QTest::newRow("first tag") << Akonadi::Tag(42); | ||
384 | QTest::newRow("second tag") << Akonadi::Tag(43); | 457 | QTest::newRow("second tag") << Akonadi::Tag(43); | ||
385 | } | 458 | } | ||
386 | 459 | | |||
▲ Show 20 Lines • Show All 202 Lines • Show Last 20 Lines |