summaryrefslogtreecommitdiffstats
path: root/tests/genericfacadetest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-10-09 18:51:04 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-10-10 10:40:01 +0200
commit6f1d3437b3bdd3ccde1243ceddf19f0c0fb5afda (patch)
tree0c90df67eac827d5166158c1f7055d00cf39425d /tests/genericfacadetest.cpp
parent4f1ec5deaf3205e4d71dcb0ff35a29cfbb2c8ec1 (diff)
downloadsink-6f1d3437b3bdd3ccde1243ceddf19f0c0fb5afda.tar.gz
sink-6f1d3437b3bdd3ccde1243ceddf19f0c0fb5afda.zip
Modification and removal in results
Now we just need to ensure that equality is tested using the ApplicationDomainType::identifier
Diffstat (limited to 'tests/genericfacadetest.cpp')
-rw-r--r--tests/genericfacadetest.cpp79
1 files changed, 78 insertions, 1 deletions
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp
index f21de70..e9c1a94 100644
--- a/tests/genericfacadetest.cpp
+++ b/tests/genericfacadetest.cpp
@@ -30,10 +30,18 @@ public:
30 for (const auto &res : mResults) { 30 for (const auto &res : mResults) {
31 resultProvider->add(res); 31 resultProvider->add(res);
32 } 32 }
33 for (const auto &res : mModifications) {
34 resultProvider->modify(res);
35 }
36 for (const auto &res : mRemovals) {
37 resultProvider->remove(res);
38 }
33 return mLatestRevision; 39 return mLatestRevision;
34 } 40 }
35 41
36 QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults; 42 QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults;
43 QList<Akonadi2::ApplicationDomain::Event::Ptr> mModifications;
44 QList<Akonadi2::ApplicationDomain::Event::Ptr> mRemovals;
37 qint64 mLatestRevision; 45 qint64 mLatestRevision;
38}; 46};
39 47
@@ -126,9 +134,78 @@ private Q_SLOTS:
126 resultSet->initialResultSetComplete(); 134 resultSet->initialResultSetComplete();
127 result.exec(); 135 result.exec();
128 136
129 // QTRY_COMPARE(result.size(), 2);
130 QCOMPARE(result.size(), 2); 137 QCOMPARE(result.size(), 2);
131 } 138 }
139
140 void testLiveQueryModify()
141 {
142 Akonadi2::Query query;
143 query.liveQuery = true;
144
145 auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create();
146 auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create(), "bufferType");
147 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
148 auto entity = QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create());
149 entity->setProperty("test", "test1");
150 storage->mResults << entity;
151 TestResourceFacade facade("identifier", storage, resourceAccess);
152
153 async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(resultSet->emitter());
154
155 facade.load(query, resultSet).exec().waitForFinished();
156 resultSet->initialResultSetComplete();
157
158 result.exec();
159 QCOMPARE(result.size(), 1);
160
161 //Modify the entity again
162 storage->mResults.clear();
163 entity = QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create());
164 entity->setProperty("test", "test2");
165 storage->mModifications << entity;
166 storage->mLatestRevision = 2;
167 resourceAccess->emit revisionChanged(2);
168
169 //Hack to get event loop in synclistresult to abort again
170 resultSet->initialResultSetComplete();
171 result.exec();
172
173 QCOMPARE(result.size(), 1);
174 QCOMPARE(result.first()->getProperty("test").toByteArray(), QByteArray("test2"));
175 }
176
177 void testLiveQueryRemove()
178 {
179 Akonadi2::Query query;
180 query.liveQuery = true;
181
182 auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create();
183 auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create(), "bufferType");
184 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
185 auto entity = QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>());
186 storage->mResults << entity;
187 TestResourceFacade facade("identifier", storage, resourceAccess);
188
189 async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(resultSet->emitter());
190
191 facade.load(query, resultSet).exec().waitForFinished();
192 resultSet->initialResultSetComplete();
193
194 result.exec();
195 QCOMPARE(result.size(), 1);
196
197 //Remove the entity again
198 storage->mResults.clear();
199 storage->mRemovals << entity;
200 storage->mLatestRevision = 2;
201 resourceAccess->emit revisionChanged(2);
202
203 //Hack to get event loop in synclistresult to abort again
204 resultSet->initialResultSetComplete();
205 result.exec();
206
207 QCOMPARE(result.size(), 0);
208 }
132}; 209};
133 210
134QTEST_MAIN(GenericFacadeTest) 211QTEST_MAIN(GenericFacadeTest)