From 0c744f0f14836ee70ca675135a9ca4cef080baa3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Nov 2015 15:58:56 +0100 Subject: Test modifications --- tests/clientapitest.cpp | 62 ++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 5d8cd9f..8f956ab 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -29,8 +29,6 @@ public: KAsync::Job remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE { - // capturedResultProvider = &resultProvider; - auto resultProvider = new Akonadi2::ResultProvider(); resultProvider->onDone([resultProvider]() { Trace() << "Result provider is done"; @@ -51,11 +49,12 @@ public: }); auto job = KAsync::start([query, resultProvider]() { }); + mResultProvider = resultProvider; return qMakePair(job, emitter); } QList results; - // Akonadi2::ResultProviderInterface *capturedResultProvider; + Akonadi2::ResultProviderInterface *mResultProvider; }; @@ -91,26 +90,6 @@ private Q_SLOTS: QCOMPARE(model->rowCount(QModelIndex()), 1); } - // //The query provider is supposed to delete itself - void testQueryLifetime() - { - auto facade = DummyResourceFacade::registerFacade(); - facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); - ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); - - Akonadi2::Query query; - query.resources << "dummyresource.instance1"; - query.liveQuery = true; - - { - auto model = Akonadi2::Store::loadModel(query); - QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - } - //It's running in a separate thread, so we have to wait for a moment until the query provider deletes itself. - // QTRY_VERIFY(!facade->capturedResultProvider); - QTest::qWait(300); - } - //TODO: This test doesn't belong to this testsuite void resourceManagement() { @@ -134,8 +113,8 @@ private Q_SLOTS: Akonadi2::Query query; query.propertyFilter.insert("type", "dummyresource"); auto model = Akonadi2::Store::loadModel(query); - //TODO ensure the initial query completed - QTRY_COMPARE(model->rowCount(QModelIndex()), 0); + QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(QModelIndex()), 0); } } @@ -218,12 +197,37 @@ private Q_SLOTS: model->fetchMore(model->index(0, 0)); QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); - // auto resultProvider = facade->capturedResultProvider.toStrongRef(); + auto resultProvider = facade->mResultProvider; + + //Test new toplevel folder + { + QSignalSpy rowsInsertedSpy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); + auto folder2 = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); + resultProvider->add(folder2); + QTRY_COMPARE(model->rowCount(), 2); + QTRY_COMPARE(rowsInsertedSpy.count(), 1); + QCOMPARE(rowsInsertedSpy.at(0).at(0).value(), QModelIndex()); + } - //A modification can also be a move - // resultProvider->modify(); + //Test changed name + { + QSignalSpy dataChanged(model.data(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector &))); + folder->setProperty("subject", "modifiedSubject"); + resultProvider->modify(folder); + QTRY_COMPARE(model->rowCount(), 2); + QTRY_COMPARE(dataChanged.count(), 1); + } + + //Test removal + { + QSignalSpy rowsRemovedSpy(model.data(), SIGNAL(rowsRemoved(const QModelIndex &, int, int))); + folder->setProperty("subject", "modifiedSubject"); + resultProvider->remove(subfolder); + QTRY_COMPARE(model->rowCount(model->index(0, 0)), 0); + QTRY_COMPARE(rowsRemovedSpy.count(), 1); + } - // resultProvider->remove(); + //TODO: A modification can also be a move } -- cgit v1.2.3