diff options
Diffstat (limited to 'tests/clientapitest.cpp')
-rw-r--r-- | tests/clientapitest.cpp | 62 |
1 files changed, 33 insertions, 29 deletions
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: | |||
29 | KAsync::Job<void> remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; | 29 | KAsync::Job<void> remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; |
30 | QPair<KAsync::Job<void>, typename Akonadi2::ResultEmitter<typename T::Ptr>::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE | 30 | QPair<KAsync::Job<void>, typename Akonadi2::ResultEmitter<typename T::Ptr>::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE |
31 | { | 31 | { |
32 | // capturedResultProvider = &resultProvider; | ||
33 | |||
34 | auto resultProvider = new Akonadi2::ResultProvider<typename T::Ptr>(); | 32 | auto resultProvider = new Akonadi2::ResultProvider<typename T::Ptr>(); |
35 | resultProvider->onDone([resultProvider]() { | 33 | resultProvider->onDone([resultProvider]() { |
36 | Trace() << "Result provider is done"; | 34 | Trace() << "Result provider is done"; |
@@ -51,11 +49,12 @@ public: | |||
51 | }); | 49 | }); |
52 | auto job = KAsync::start<void>([query, resultProvider]() { | 50 | auto job = KAsync::start<void>([query, resultProvider]() { |
53 | }); | 51 | }); |
52 | mResultProvider = resultProvider; | ||
54 | return qMakePair(job, emitter); | 53 | return qMakePair(job, emitter); |
55 | } | 54 | } |
56 | 55 | ||
57 | QList<typename T::Ptr> results; | 56 | QList<typename T::Ptr> results; |
58 | // Akonadi2::ResultProviderInterface<typename T::Ptr> *capturedResultProvider; | 57 | Akonadi2::ResultProviderInterface<typename T::Ptr> *mResultProvider; |
59 | }; | 58 | }; |
60 | 59 | ||
61 | 60 | ||
@@ -91,26 +90,6 @@ private Q_SLOTS: | |||
91 | QCOMPARE(model->rowCount(QModelIndex()), 1); | 90 | QCOMPARE(model->rowCount(QModelIndex()), 1); |
92 | } | 91 | } |
93 | 92 | ||
94 | // //The query provider is supposed to delete itself | ||
95 | void testQueryLifetime() | ||
96 | { | ||
97 | auto facade = DummyResourceFacade<Akonadi2::ApplicationDomain::Event>::registerFacade(); | ||
98 | facade->results << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id", 0, QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
99 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); | ||
100 | |||
101 | Akonadi2::Query query; | ||
102 | query.resources << "dummyresource.instance1"; | ||
103 | query.liveQuery = true; | ||
104 | |||
105 | { | ||
106 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query); | ||
107 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | ||
108 | } | ||
109 | //It's running in a separate thread, so we have to wait for a moment until the query provider deletes itself. | ||
110 | // QTRY_VERIFY(!facade->capturedResultProvider); | ||
111 | QTest::qWait(300); | ||
112 | } | ||
113 | |||
114 | //TODO: This test doesn't belong to this testsuite | 93 | //TODO: This test doesn't belong to this testsuite |
115 | void resourceManagement() | 94 | void resourceManagement() |
116 | { | 95 | { |
@@ -134,8 +113,8 @@ private Q_SLOTS: | |||
134 | Akonadi2::Query query; | 113 | Akonadi2::Query query; |
135 | query.propertyFilter.insert("type", "dummyresource"); | 114 | query.propertyFilter.insert("type", "dummyresource"); |
136 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::AkonadiResource>(query); | 115 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::AkonadiResource>(query); |
137 | //TODO ensure the initial query completed | 116 | QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); |
138 | QTRY_COMPARE(model->rowCount(QModelIndex()), 0); | 117 | QCOMPARE(model->rowCount(QModelIndex()), 0); |
139 | } | 118 | } |
140 | } | 119 | } |
141 | 120 | ||
@@ -218,12 +197,37 @@ private Q_SLOTS: | |||
218 | model->fetchMore(model->index(0, 0)); | 197 | model->fetchMore(model->index(0, 0)); |
219 | QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); | 198 | QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); |
220 | 199 | ||
221 | // auto resultProvider = facade->capturedResultProvider.toStrongRef(); | 200 | auto resultProvider = facade->mResultProvider; |
201 | |||
202 | //Test new toplevel folder | ||
203 | { | ||
204 | QSignalSpy rowsInsertedSpy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); | ||
205 | auto folder2 = QSharedPointer<Akonadi2::ApplicationDomain::Folder>::create("resource", "id2", 0, QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
206 | resultProvider->add(folder2); | ||
207 | QTRY_COMPARE(model->rowCount(), 2); | ||
208 | QTRY_COMPARE(rowsInsertedSpy.count(), 1); | ||
209 | QCOMPARE(rowsInsertedSpy.at(0).at(0).value<QModelIndex>(), QModelIndex()); | ||
210 | } | ||
222 | 211 | ||
223 | //A modification can also be a move | 212 | //Test changed name |
224 | // resultProvider->modify(); | 213 | { |
214 | QSignalSpy dataChanged(model.data(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &))); | ||
215 | folder->setProperty("subject", "modifiedSubject"); | ||
216 | resultProvider->modify(folder); | ||
217 | QTRY_COMPARE(model->rowCount(), 2); | ||
218 | QTRY_COMPARE(dataChanged.count(), 1); | ||
219 | } | ||
220 | |||
221 | //Test removal | ||
222 | { | ||
223 | QSignalSpy rowsRemovedSpy(model.data(), SIGNAL(rowsRemoved(const QModelIndex &, int, int))); | ||
224 | folder->setProperty("subject", "modifiedSubject"); | ||
225 | resultProvider->remove(subfolder); | ||
226 | QTRY_COMPARE(model->rowCount(model->index(0, 0)), 0); | ||
227 | QTRY_COMPARE(rowsRemovedSpy.count(), 1); | ||
228 | } | ||
225 | 229 | ||
226 | // resultProvider->remove(); | 230 | //TODO: A modification can also be a move |
227 | } | 231 | } |
228 | 232 | ||
229 | 233 | ||