Changeset View
Changeset View
Standalone View
Standalone View
tests/units/akonadi/akonadidatasourcequeriestest.cpp
Show First 20 Lines • Show All 581 Lines • ▼ Show 20 Line(s) | 581 | if (deleteQuery) | |||
---|---|---|---|---|---|
582 | delete queries.take(); | 582 | delete queries.take(); | ||
583 | 583 | | |||
584 | // THEN | 584 | // THEN | ||
585 | QVERIFY(result->data().isEmpty()); | 585 | QVERIFY(result->data().isEmpty()); | ||
586 | TestHelpers::waitForEmptyJobQueue(); | 586 | TestHelpers::waitForEmptyJobQueue(); | ||
587 | QCOMPARE(result->data().size(), 0); | 587 | QCOMPARE(result->data().size(), 0); | ||
588 | } | 588 | } | ||
589 | 589 | | |||
590 | void shouldLookInAllReportedForSelectedSources_data() | | |||
591 | { | | |||
592 | QTest::addColumn<int>("contentTypes"); | | |||
593 | QTest::addColumn<QStringList>("expectedNames"); | | |||
594 | | ||||
595 | auto expectedNames = QStringList(); | | |||
596 | expectedNames << QStringLiteral("42Task » 43Task") << QStringLiteral("44Note » 45Note"); | | |||
597 | QTest::newRow("tasks and notes") << int(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes) << expectedNames; | | |||
598 | | ||||
599 | expectedNames.clear(); | | |||
600 | expectedNames << QStringLiteral("42Task » 43Task"); | | |||
601 | QTest::newRow("tasks") << int(Akonadi::StorageInterface::Tasks) << expectedNames; | | |||
602 | | ||||
603 | expectedNames.clear(); | | |||
604 | expectedNames << QStringLiteral("44Note » 45Note"); | | |||
605 | QTest::newRow("notes") << int(Akonadi::StorageInterface::Notes) << expectedNames; | | |||
606 | } | | |||
607 | | ||||
608 | void shouldLookInAllReportedForSelectedSources() | 590 | void shouldLookInAllReportedForSelectedSources() | ||
609 | { | 591 | { | ||
610 | // GIVEN | 592 | // GIVEN | ||
611 | AkonadiFakeData data; | 593 | AkonadiFakeData data; | ||
612 | 594 | | |||
613 | // Two top level collections, one with tasks, one with notes and two child collections | 595 | // Two top level collections, one with tasks, one with notes and two child collections | ||
614 | data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent().selected(false)); | 596 | data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent().selected(false)); | ||
615 | data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Task")).withParent(42).withTaskContent().selected(true)); | 597 | data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Task")).withParent(42).withTaskContent().selected(true)); | ||
616 | data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44Note")).withRootAsParent().withNoteContent().selected(false)); | 598 | data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44Note")).withRootAsParent().withNoteContent().selected(false)); | ||
617 | data.createCollection(GenCollection().withId(45).withName(QStringLiteral("45Note")).withParent(44).withNoteContent().selected(true)); | 599 | data.createCollection(GenCollection().withId(45).withName(QStringLiteral("45Note")).withParent(44).withNoteContent().selected(true)); | ||
618 | 600 | | |||
619 | // WHEN | 601 | // WHEN | ||
620 | QFETCH(int, contentTypes); | 602 | QScopedPointer<Domain::DataSourceQueries> queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks, | ||
621 | QScopedPointer<Domain::DataSourceQueries> queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::FetchContentTypes(contentTypes), | | |||
622 | Akonadi::StorageInterface::Ptr(data.createStorage()), | 603 | Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
623 | Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | 604 | Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | ||
624 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 605 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | ||
625 | 606 | | |||
626 | Domain::QueryResult<Domain::DataSource::Ptr>::Ptr result = queries->findAllSelected(); | 607 | Domain::QueryResult<Domain::DataSource::Ptr>::Ptr result = queries->findAllSelected(); | ||
627 | result->data(); | 608 | result->data(); | ||
628 | result = queries->findAllSelected(); // Should not cause any problem or wrong data | 609 | result = queries->findAllSelected(); // Should not cause any problem or wrong data | ||
629 | 610 | | |||
630 | // THEN | 611 | // THEN | ||
631 | QVERIFY(result->data().isEmpty()); | 612 | QVERIFY(result->data().isEmpty()); | ||
632 | TestHelpers::waitForEmptyJobQueue(); | 613 | TestHelpers::waitForEmptyJobQueue(); | ||
633 | 614 | | |||
634 | const auto sources = result->data(); | 615 | const auto sources = result->data(); | ||
635 | auto actualNames = QStringList(); | 616 | auto actualNames = QStringList(); | ||
636 | std::transform(sources.constBegin(), sources.constEnd(), | 617 | std::transform(sources.constBegin(), sources.constEnd(), | ||
637 | std::back_inserter(actualNames), | 618 | std::back_inserter(actualNames), | ||
638 | [] (const Domain::DataSource::Ptr &source) { return source->name(); }); | 619 | [] (const Domain::DataSource::Ptr &source) { return source->name(); }); | ||
639 | actualNames.sort(); | 620 | actualNames.sort(); | ||
640 | 621 | | |||
641 | QFETCH(QStringList, expectedNames); | 622 | QCOMPARE(actualNames, QStringList() << QStringLiteral("42Task » 43Task")); | ||
642 | expectedNames.sort(); | | |||
643 | QCOMPARE(actualNames, expectedNames); | | |||
644 | } | 623 | } | ||
645 | 624 | | |||
646 | void shouldReactToCollectionAddsForSelectedSources() | 625 | void shouldReactToCollectionAddsForSelectedSources() | ||
647 | { | 626 | { | ||
648 | // GIVEN | 627 | // GIVEN | ||
649 | AkonadiFakeData data; | 628 | AkonadiFakeData data; | ||
650 | 629 | | |||
651 | QScopedPointer<Domain::DataSourceQueries> queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, | 630 | QScopedPointer<Domain::DataSourceQueries> queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks, | ||
652 | Akonadi::StorageInterface::Ptr(data.createStorage()), | 631 | Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
653 | Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | 632 | Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | ||
654 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 633 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | ||
655 | 634 | | |||
656 | Domain::QueryResult<Domain::DataSource::Ptr>::Ptr result = queries->findAllSelected(); | 635 | Domain::QueryResult<Domain::DataSource::Ptr>::Ptr result = queries->findAllSelected(); | ||
657 | TestHelpers::waitForEmptyJobQueue(); | 636 | TestHelpers::waitForEmptyJobQueue(); | ||
658 | QVERIFY(result->data().isEmpty()); | 637 | QVERIFY(result->data().isEmpty()); | ||
659 | 638 | | |||
660 | // WHEN | 639 | // WHEN | ||
661 | data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent().selected(false)); | 640 | data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent().selected(false)); | ||
662 | data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Task")).withParent(42).withTaskContent().selected(true)); | 641 | data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Task")).withParent(42).withTaskContent().selected(true)); | ||
663 | data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44Note")).withRootAsParent().withNoteContent().selected(false)); | 642 | data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44Note")).withRootAsParent().withNoteContent().selected(false)); | ||
664 | data.createCollection(GenCollection().withId(45).withName(QStringLiteral("45Note")).withParent(44).withNoteContent().selected(true)); | 643 | data.createCollection(GenCollection().withId(45).withName(QStringLiteral("45Note")).withParent(44).withNoteContent().selected(true)); | ||
665 | 644 | | |||
666 | // THEN | 645 | // THEN | ||
667 | QCOMPARE(result->data().size(), 2); | 646 | QCOMPARE(result->data().size(), 1); | ||
668 | QCOMPARE(result->data().at(0)->name(), QStringLiteral("42Task » 43Task")); | 647 | QCOMPARE(result->data().at(0)->name(), QStringLiteral("42Task » 43Task")); | ||
669 | QCOMPARE(result->data().at(1)->name(), QStringLiteral("44Note » 45Note")); | | |||
670 | } | 648 | } | ||
671 | 649 | | |||
672 | void shouldReactToCollectionRemovesForSelectedSources() | 650 | void shouldReactToCollectionRemovesForSelectedSources() | ||
673 | { | 651 | { | ||
674 | // GIVEN | 652 | // GIVEN | ||
675 | AkonadiFakeData data; | 653 | AkonadiFakeData data; | ||
676 | 654 | | |||
677 | // Two top level collections and two child collections | 655 | // Two top level collections and two child collections | ||
678 | data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent().selected(false)); | 656 | data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent().selected(false)); | ||
679 | data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Task")).withParent(42).withTaskContent().selected(true)); | 657 | data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Task")).withParent(42).withTaskContent().selected(true)); | ||
680 | data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44Note")).withRootAsParent().withNoteContent().selected(false)); | 658 | data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44Note")).withRootAsParent().withNoteContent().selected(false)); | ||
681 | data.createCollection(GenCollection().withId(45).withName(QStringLiteral("45Note")).withParent(44).withNoteContent().selected(true)); | 659 | data.createCollection(GenCollection().withId(45).withName(QStringLiteral("45Note")).withParent(44).withNoteContent().selected(true)); | ||
682 | 660 | | |||
683 | QScopedPointer<Domain::DataSourceQueries> queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, | 661 | QScopedPointer<Domain::DataSourceQueries> queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks, | ||
684 | Akonadi::StorageInterface::Ptr(data.createStorage()), | 662 | Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
685 | Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | 663 | Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | ||
686 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 664 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | ||
687 | 665 | | |||
688 | Domain::QueryResult<Domain::DataSource::Ptr>::Ptr result = queries->findAllSelected(); | 666 | Domain::QueryResult<Domain::DataSource::Ptr>::Ptr result = queries->findAllSelected(); | ||
689 | TestHelpers::waitForEmptyJobQueue(); | 667 | TestHelpers::waitForEmptyJobQueue(); | ||
690 | QCOMPARE(result->data().size(), 2); | 668 | QCOMPARE(result->data().size(), 1); | ||
691 | 669 | | |||
692 | // WHEN | 670 | // WHEN | ||
693 | data.removeCollection(Akonadi::Collection(43)); | 671 | data.removeCollection(Akonadi::Collection(43)); | ||
694 | data.removeCollection(Akonadi::Collection(45)); | 672 | data.removeCollection(Akonadi::Collection(45)); | ||
695 | 673 | | |||
696 | // THEN | 674 | // THEN | ||
697 | QCOMPARE(result->data().size(), 0); | 675 | QCOMPARE(result->data().size(), 0); | ||
698 | } | 676 | } | ||
699 | 677 | | |||
700 | void shouldReactToCollectionChangesForSelectedSources() | 678 | void shouldReactToCollectionChangesForSelectedSources() | ||
701 | { | 679 | { | ||
702 | // GIVEN | 680 | // GIVEN | ||
703 | AkonadiFakeData data; | 681 | AkonadiFakeData data; | ||
704 | 682 | | |||
705 | // Two top level collections and one child collection | 683 | // Two top level collections and one child collection | ||
706 | data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent().selected(false)); | 684 | data.createCollection(GenCollection().withId(42).withName(QStringLiteral("42Task")).withRootAsParent().withTaskContent().selected(false)); | ||
707 | data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Task")).withParent(42).withTaskContent().selected(true)); | 685 | data.createCollection(GenCollection().withId(43).withName(QStringLiteral("43Task")).withParent(42).withTaskContent().selected(true)); | ||
708 | data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44Note")).withRootAsParent().withNoteContent().selected(false)); | 686 | data.createCollection(GenCollection().withId(44).withName(QStringLiteral("44Note")).withRootAsParent().withNoteContent().selected(false)); | ||
709 | data.createCollection(GenCollection().withId(45).withName(QStringLiteral("45Note")).withParent(44).withNoteContent().selected(true)); | 687 | data.createCollection(GenCollection().withId(45).withName(QStringLiteral("45Note")).withParent(44).withNoteContent().selected(true)); | ||
710 | 688 | | |||
711 | QScopedPointer<Domain::DataSourceQueries> queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, | 689 | QScopedPointer<Domain::DataSourceQueries> queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks, | ||
712 | Akonadi::StorageInterface::Ptr(data.createStorage()), | 690 | Akonadi::StorageInterface::Ptr(data.createStorage()), | ||
713 | Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | 691 | Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), | ||
714 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | 692 | Akonadi::MonitorInterface::Ptr(data.createMonitor()))); | ||
715 | 693 | | |||
716 | Domain::QueryResult<Domain::DataSource::Ptr>::Ptr result = queries->findAllSelected(); | 694 | Domain::QueryResult<Domain::DataSource::Ptr>::Ptr result = queries->findAllSelected(); | ||
717 | 695 | | |||
718 | bool replaceHandlerCalled = false; | 696 | bool replaceHandlerCalled = false; | ||
719 | result->addPostReplaceHandler([&replaceHandlerCalled](const Domain::DataSource::Ptr &, int) { | 697 | result->addPostReplaceHandler([&replaceHandlerCalled](const Domain::DataSource::Ptr &, int) { | ||
720 | replaceHandlerCalled = true; | 698 | replaceHandlerCalled = true; | ||
721 | }); | 699 | }); | ||
722 | TestHelpers::waitForEmptyJobQueue(); | 700 | TestHelpers::waitForEmptyJobQueue(); | ||
723 | QCOMPARE(result->data().size(), 2); | 701 | QCOMPARE(result->data().size(), 1); | ||
724 | 702 | | |||
725 | // WHEN | 703 | // WHEN | ||
726 | data.modifyCollection(GenCollection(data.collection(43)).withName(QStringLiteral("43TaskBis"))); | 704 | data.modifyCollection(GenCollection(data.collection(43)).withName(QStringLiteral("43TaskBis"))); | ||
727 | data.modifyCollection(GenCollection(data.collection(45)).withName(QStringLiteral("45NoteBis"))); | 705 | data.modifyCollection(GenCollection(data.collection(45)).withName(QStringLiteral("45NoteBis"))); | ||
728 | TestHelpers::waitForEmptyJobQueue(); | 706 | TestHelpers::waitForEmptyJobQueue(); | ||
729 | 707 | | |||
730 | // THEN | 708 | // THEN | ||
731 | QCOMPARE(result->data().size(), 2); | 709 | QCOMPARE(result->data().size(), 1); | ||
732 | QCOMPARE(result->data().at(0)->name(), QStringLiteral("42Task » 43TaskBis")); | 710 | QCOMPARE(result->data().at(0)->name(), QStringLiteral("42Task » 43TaskBis")); | ||
733 | QCOMPARE(result->data().at(1)->name(), QStringLiteral("44Note » 45NoteBis")); | | |||
734 | QVERIFY(replaceHandlerCalled); | 711 | QVERIFY(replaceHandlerCalled); | ||
735 | } | 712 | } | ||
736 | 713 | | |||
737 | void shouldNotCrashDuringFindAllSelectedWhenFetchJobFailedOrEmpty_data() | 714 | void shouldNotCrashDuringFindAllSelectedWhenFetchJobFailedOrEmpty_data() | ||
738 | { | 715 | { | ||
739 | QTest::addColumn<int>("colErrorCode"); | 716 | QTest::addColumn<int>("colErrorCode"); | ||
740 | QTest::addColumn<int>("colFetchBehavior"); | 717 | QTest::addColumn<int>("colFetchBehavior"); | ||
741 | QTest::addColumn<bool>("deleteQuery"); | 718 | QTest::addColumn<bool>("deleteQuery"); | ||
▲ Show 20 Lines • Show All 238 Lines • Show Last 20 Lines |