diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-08 13:18:19 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-08 13:18:19 +0100 |
commit | ae4b64b198a143240aa5dd1e202e5016abfdae71 (patch) | |
tree | 5d9d58a512ebc60c44637d11c9424f67a02887e8 /tests | |
parent | f425c2070131161dc11bcf70e35f8d1848cadb65 (diff) | |
download | sink-ae4b64b198a143240aa5dd1e202e5016abfdae71.tar.gz sink-ae4b64b198a143240aa5dd1e202e5016abfdae71.zip |
Wrap references in a Reerence type.
This allows us to make sure that references are not taken out of
context (the resource).
Because we need to use the type-specific accessors more we also ran into
a problem that we cannot "downcast" a reference with the change
recording still working, for that we have the cast<T>() operator now.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/clientapitest.cpp | 6 | ||||
-rw-r--r-- | tests/domainadaptortest.cpp | 2 | ||||
-rw-r--r-- | tests/mailquerybenchmark.cpp | 10 | ||||
-rw-r--r-- | tests/pipelinebenchmark.cpp | 8 | ||||
-rw-r--r-- | tests/querytest.cpp | 60 |
5 files changed, 38 insertions, 48 deletions
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 4a33d17..4afe328 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp | |||
@@ -148,7 +148,7 @@ private slots: | |||
148 | auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); | 148 | auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); |
149 | auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 149 | auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
150 | auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 150 | auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
151 | subfolder->setProperty("parent", "id"); | 151 | subfolder->setParent("id"); |
152 | facade->results << folder << subfolder; | 152 | facade->results << folder << subfolder; |
153 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); | 153 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); |
154 | 154 | ||
@@ -170,7 +170,7 @@ private slots: | |||
170 | auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); | 170 | auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); |
171 | auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 171 | auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
172 | auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 172 | auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
173 | subfolder->setProperty("parent", "id"); | 173 | subfolder->setParent("id"); |
174 | facade->results << folder << subfolder; | 174 | facade->results << folder << subfolder; |
175 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); | 175 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); |
176 | 176 | ||
@@ -192,7 +192,7 @@ private slots: | |||
192 | auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("dummyresource.instance1", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 192 | auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("dummyresource.instance1", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
193 | auto subfolder = | 193 | auto subfolder = |
194 | QSharedPointer<Sink::ApplicationDomain::Folder>::create("dummyresource.instance1", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 194 | QSharedPointer<Sink::ApplicationDomain::Folder>::create("dummyresource.instance1", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
195 | subfolder->setProperty("parent", "id"); | 195 | subfolder->setParent("id"); |
196 | facade->results << folder << subfolder; | 196 | facade->results << folder << subfolder; |
197 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); | 197 | ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); |
198 | 198 | ||
diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index 4fd04db..a17152e 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp | |||
@@ -110,6 +110,7 @@ private slots: | |||
110 | Sink::ApplicationDomain::Mail mail; | 110 | Sink::ApplicationDomain::Mail mail; |
111 | mail.setExtractedSubject("summary"); | 111 | mail.setExtractedSubject("summary"); |
112 | mail.setMimeMessage("foobar"); | 112 | mail.setMimeMessage("foobar"); |
113 | mail.setFolder("folder"); | ||
113 | 114 | ||
114 | flatbuffers::FlatBufferBuilder metadataFbb; | 115 | flatbuffers::FlatBufferBuilder metadataFbb; |
115 | auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); | 116 | auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); |
@@ -134,6 +135,7 @@ private slots: | |||
134 | Sink::ApplicationDomain::Mail readMail{QByteArray{}, QByteArray{}, 0, adaptor}; | 135 | Sink::ApplicationDomain::Mail readMail{QByteArray{}, QByteArray{}, 0, adaptor}; |
135 | QCOMPARE(readMail.getSubject(), mail.getSubject()); | 136 | QCOMPARE(readMail.getSubject(), mail.getSubject()); |
136 | QCOMPARE(readMail.getMimeMessage(), mail.getMimeMessage()); | 137 | QCOMPARE(readMail.getMimeMessage(), mail.getMimeMessage()); |
138 | QCOMPARE(readMail.getFolder(), mail.getFolder()); | ||
137 | } | 139 | } |
138 | 140 | ||
139 | } | 141 | } |
diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index 702239d..0e2f6fa 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp | |||
@@ -69,11 +69,11 @@ class MailQueryBenchmark : public QObject | |||
69 | const auto date = QDateTime::currentDateTimeUtc(); | 69 | const auto date = QDateTime::currentDateTimeUtc(); |
70 | for (int i = 0; i < count; i++) { | 70 | for (int i = 0; i < count; i++) { |
71 | auto domainObject = Mail::Ptr::create(); | 71 | auto domainObject = Mail::Ptr::create(); |
72 | domainObject->setProperty("uid", "uid"); | 72 | domainObject->setUid("uid"); |
73 | domainObject->setProperty("subject", QString("subject%1").arg(i)); | 73 | domainObject->setExtractedSubject(QString("subject%1").arg(i)); |
74 | domainObject->setProperty("date", date.addSecs(count)); | 74 | domainObject->setExtractedDate(date.addSecs(count)); |
75 | domainObject->setProperty("folder", "folder1"); | 75 | domainObject->setFolder("folder1"); |
76 | // domainObject->setProperty("attachment", attachment); | 76 | // domainObject->setAttachment(attachment); |
77 | const auto command = createCommand<Mail>(*domainObject, *domainTypeAdaptorFactory); | 77 | const auto command = createCommand<Mail>(*domainObject, *domainTypeAdaptorFactory); |
78 | pipeline->newEntity(command.data(), command.size()); | 78 | pipeline->newEntity(command.data(), command.size()); |
79 | } | 79 | } |
diff --git a/tests/pipelinebenchmark.cpp b/tests/pipelinebenchmark.cpp index 2e614ef..341c733 100644 --- a/tests/pipelinebenchmark.cpp +++ b/tests/pipelinebenchmark.cpp | |||
@@ -73,10 +73,10 @@ class PipelineBenchmark : public QObject | |||
73 | const auto date = QDateTime::currentDateTimeUtc(); | 73 | const auto date = QDateTime::currentDateTimeUtc(); |
74 | for (int i = 0; i < count; i++) { | 74 | for (int i = 0; i < count; i++) { |
75 | auto domainObject = Sink::ApplicationDomain::Mail::Ptr::create(); | 75 | auto domainObject = Sink::ApplicationDomain::Mail::Ptr::create(); |
76 | domainObject->setProperty("uid", "uid"); | 76 | domainObject->setUid("uid"); |
77 | domainObject->setProperty("subject", QString("subject%1").arg(i)); | 77 | domainObject->setExtractedSubject(QString("subject%1").arg(i)); |
78 | domainObject->setProperty("date", date.addSecs(count)); | 78 | domainObject->setExtractedDate(date.addSecs(count)); |
79 | domainObject->setProperty("folder", "folder1"); | 79 | domainObject->setFolder("folder1"); |
80 | // domainObject->setProperty("attachment", attachment); | 80 | // domainObject->setProperty("attachment", attachment); |
81 | const auto command = createCommand<Sink::ApplicationDomain::Mail>(*domainObject, *domainTypeAdaptorFactory); | 81 | const auto command = createCommand<Sink::ApplicationDomain::Mail>(*domainObject, *domainTypeAdaptorFactory); |
82 | pipeline->newEntity(command.data(), command.size()); | 82 | pipeline->newEntity(command.data(), command.size()); |
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 2eb1239..574e68d 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -228,25 +228,13 @@ private slots: | |||
228 | { | 228 | { |
229 | // Setup | 229 | // Setup |
230 | { | 230 | { |
231 | Folder folder("sink.dummy.instance1"); | 231 | auto folder = ApplicationDomainType::createEntity<Folder>("sink.dummy.instance1"); |
232 | Sink::Store::create<Folder>(folder).exec().waitForFinished(); | 232 | VERIFYEXEC(Sink::Store::create<Folder>(folder)); |
233 | 233 | auto subfolder = ApplicationDomainType::createEntity<Folder>("sink.dummy.instance1"); | |
234 | Sink::Query query; | 234 | subfolder.setParent(folder.identifier()); |
235 | query.resourceFilter("sink.dummy.instance1"); | 235 | VERIFYEXEC(Sink::Store::create<Folder>(subfolder)); |
236 | |||
237 | // Ensure all local data is processed | 236 | // Ensure all local data is processed |
238 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); | 237 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); |
239 | |||
240 | auto model = Sink::Store::loadModel<Folder>(query); | ||
241 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
242 | QCOMPARE(model->rowCount(), 1); | ||
243 | |||
244 | auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Folder::Ptr>(); | ||
245 | QVERIFY(!folderEntity->identifier().isEmpty()); | ||
246 | |||
247 | Folder subfolder("sink.dummy.instance1"); | ||
248 | subfolder.setProperty("parent", folderEntity->identifier()); | ||
249 | Sink::Store::create<Folder>(subfolder).exec().waitForFinished(); | ||
250 | } | 238 | } |
251 | 239 | ||
252 | // Test | 240 | // Test |
@@ -271,14 +259,14 @@ private slots: | |||
271 | // Setup | 259 | // Setup |
272 | { | 260 | { |
273 | Mail mail("sink.dummy.instance1"); | 261 | Mail mail("sink.dummy.instance1"); |
274 | mail.setProperty("uid", "test1"); | 262 | mail.setUid("test1"); |
275 | mail.setProperty("sender", "doe@example.org"); | 263 | mail.setProperty("sender", "doe@example.org"); |
276 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | 264 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); |
277 | } | 265 | } |
278 | 266 | ||
279 | { | 267 | { |
280 | Mail mail("sink.dummy.instance1"); | 268 | Mail mail("sink.dummy.instance1"); |
281 | mail.setProperty("uid", "test2"); | 269 | mail.setUid("test2"); |
282 | mail.setProperty("sender", "doe@example.org"); | 270 | mail.setProperty("sender", "doe@example.org"); |
283 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | 271 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); |
284 | } | 272 | } |
@@ -319,8 +307,8 @@ private slots: | |||
319 | QVERIFY(!folderEntity->identifier().isEmpty()); | 307 | QVERIFY(!folderEntity->identifier().isEmpty()); |
320 | 308 | ||
321 | Mail mail("sink.dummy.instance1"); | 309 | Mail mail("sink.dummy.instance1"); |
322 | mail.setProperty("uid", "test1"); | 310 | mail.setUid("test1"); |
323 | mail.setProperty("folder", folderEntity->identifier()); | 311 | mail.setFolder(folderEntity->identifier()); |
324 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | 312 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); |
325 | } | 313 | } |
326 | 314 | ||
@@ -363,18 +351,18 @@ private slots: | |||
363 | QVERIFY(!folderEntity->identifier().isEmpty()); | 351 | QVERIFY(!folderEntity->identifier().isEmpty()); |
364 | 352 | ||
365 | Mail mail("sink.dummy.instance1"); | 353 | Mail mail("sink.dummy.instance1"); |
366 | mail.setProperty("uid", "test1"); | 354 | mail.setUid("test1"); |
367 | mail.setProperty("folder", folderEntity->identifier()); | 355 | mail.setFolder(folderEntity->identifier()); |
368 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | 356 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); |
369 | 357 | ||
370 | Mail mail1("sink.dummy.instance1"); | 358 | Mail mail1("sink.dummy.instance1"); |
371 | mail1.setProperty("uid", "test1"); | 359 | mail1.setUid("test1"); |
372 | mail1.setProperty("folder", "foobar"); | 360 | mail1.setFolder("foobar"); |
373 | Sink::Store::create<Mail>(mail1).exec().waitForFinished(); | 361 | Sink::Store::create<Mail>(mail1).exec().waitForFinished(); |
374 | 362 | ||
375 | Mail mail2("sink.dummy.instance1"); | 363 | Mail mail2("sink.dummy.instance1"); |
376 | mail2.setProperty("uid", "test2"); | 364 | mail2.setUid("test2"); |
377 | mail2.setProperty("folder", folderEntity->identifier()); | 365 | mail2.setFolder(folderEntity->identifier()); |
378 | Sink::Store::create<Mail>(mail2).exec().waitForFinished(); | 366 | Sink::Store::create<Mail>(mail2).exec().waitForFinished(); |
379 | } | 367 | } |
380 | 368 | ||
@@ -417,23 +405,23 @@ private slots: | |||
417 | const auto date = QDateTime(QDate(2015, 7, 7), QTime(12, 0)); | 405 | const auto date = QDateTime(QDate(2015, 7, 7), QTime(12, 0)); |
418 | { | 406 | { |
419 | Mail mail("sink.dummy.instance1"); | 407 | Mail mail("sink.dummy.instance1"); |
420 | mail.setProperty("uid", "testSecond"); | 408 | mail.setUid("testSecond"); |
421 | mail.setProperty("folder", folderEntity->identifier()); | 409 | mail.setFolder(folderEntity->identifier()); |
422 | mail.setProperty("date", date.addDays(-1)); | 410 | mail.setExtractedDate(date.addDays(-1)); |
423 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | 411 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); |
424 | } | 412 | } |
425 | { | 413 | { |
426 | Mail mail("sink.dummy.instance1"); | 414 | Mail mail("sink.dummy.instance1"); |
427 | mail.setProperty("uid", "testLatest"); | 415 | mail.setUid("testLatest"); |
428 | mail.setProperty("folder", folderEntity->identifier()); | 416 | mail.setFolder(folderEntity->identifier()); |
429 | mail.setProperty("date", date); | 417 | mail.setExtractedDate(date); |
430 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | 418 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); |
431 | } | 419 | } |
432 | { | 420 | { |
433 | Mail mail("sink.dummy.instance1"); | 421 | Mail mail("sink.dummy.instance1"); |
434 | mail.setProperty("uid", "testLast"); | 422 | mail.setUid("testLast"); |
435 | mail.setProperty("folder", folderEntity->identifier()); | 423 | mail.setFolder(folderEntity->identifier()); |
436 | mail.setProperty("date", date.addDays(-2)); | 424 | mail.setExtractedDate(date.addDays(-2)); |
437 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); | 425 | Sink::Store::create<Mail>(mail).exec().waitForFinished(); |
438 | } | 426 | } |
439 | } | 427 | } |