diff options
-rw-r--r-- | common/clientapi.cpp | 41 | ||||
-rw-r--r-- | common/clientapi.h | 11 | ||||
-rw-r--r-- | common/commands/notification.fbs | 1 | ||||
-rw-r--r-- | common/genericresource.cpp | 19 | ||||
-rw-r--r-- | common/genericresource.h | 2 | ||||
-rw-r--r-- | common/listener.cpp | 21 | ||||
-rw-r--r-- | common/listener.h | 2 | ||||
-rw-r--r-- | common/notification.h | 1 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 27 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 10 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.h | 2 | ||||
-rw-r--r-- | tests/clientapitest.cpp | 1 | ||||
-rw-r--r-- | tests/inspectiontest.cpp | 25 |
13 files changed, 138 insertions, 25 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp index deab962..40257bb 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp | |||
@@ -298,13 +298,50 @@ KAsync::Job<void> Resources::inspect(const Inspection &inspectionCommand) | |||
298 | Trace() << "Sending inspection " << resource; | 298 | Trace() << "Sending inspection " << resource; |
299 | auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(resource); | 299 | auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(resource); |
300 | resourceAccess->open(); | 300 | resourceAccess->open(); |
301 | auto notifier = QSharedPointer<Akonadi2::Notifier>::create(resourceAccess); | ||
301 | auto id = QUuid::createUuid().toByteArray(); | 302 | auto id = QUuid::createUuid().toByteArray(); |
302 | return resourceAccess->sendInspectionCommand(id, ApplicationDomain::getTypeName<DomainType>(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue) | 303 | return resourceAccess->sendInspectionCommand(id, ApplicationDomain::getTypeName<DomainType>(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue) |
303 | .template then<void>([resourceAccess]() { | 304 | .template then<void>([resourceAccess, notifier, id](KAsync::Future<void> &future) { |
304 | //TODO wait for inspection notification | 305 | notifier->registerHandler([&future, id](const ResourceNotification ¬ification) { |
306 | if (notification.id == id) { | ||
307 | if (notification.code) { | ||
308 | future.setError(-1, "Inspection returned an error: " + notification.message); | ||
309 | } else { | ||
310 | future.setFinished(); | ||
311 | } | ||
312 | } | ||
313 | }); | ||
305 | }); | 314 | }); |
306 | } | 315 | } |
307 | 316 | ||
317 | class Akonadi2::Notifier::Private { | ||
318 | public: | ||
319 | Private() | ||
320 | : context(new QObject) | ||
321 | { | ||
322 | |||
323 | } | ||
324 | QList<QSharedPointer<ResourceAccess> > resourceAccess; | ||
325 | QList<std::function<void(const ResourceNotification &)> > handler; | ||
326 | QSharedPointer<QObject> context; | ||
327 | }; | ||
328 | |||
329 | Notifier::Notifier(const QSharedPointer<ResourceAccess> &resourceAccess) | ||
330 | : d(new Akonadi2::Notifier::Private) | ||
331 | { | ||
332 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const ResourceNotification ¬ification) { | ||
333 | for (const auto &handler : d->handler) { | ||
334 | handler(notification); | ||
335 | } | ||
336 | }); | ||
337 | d->resourceAccess << resourceAccess; | ||
338 | } | ||
339 | |||
340 | void Notifier::registerHandler(std::function<void(const ResourceNotification &)> handler) | ||
341 | { | ||
342 | d->handler << handler; | ||
343 | } | ||
344 | |||
308 | #define REGISTER_TYPE(T) template KAsync::Job<void> Store::remove<T>(const T &domainObject); \ | 345 | #define REGISTER_TYPE(T) template KAsync::Job<void> Store::remove<T>(const T &domainObject); \ |
309 | template KAsync::Job<void> Store::create<T>(const T &domainObject); \ | 346 | template KAsync::Job<void> Store::create<T>(const T &domainObject); \ |
310 | template KAsync::Job<void> Store::modify<T>(const T &domainObject); \ | 347 | template KAsync::Job<void> Store::modify<T>(const T &domainObject); \ |
diff --git a/common/clientapi.h b/common/clientapi.h index d496715..5ed99e0 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -31,6 +31,8 @@ | |||
31 | class QAbstractItemModel; | 31 | class QAbstractItemModel; |
32 | 32 | ||
33 | namespace Akonadi2 { | 33 | namespace Akonadi2 { |
34 | class ResourceAccess; | ||
35 | class ResourceNotification; | ||
34 | 36 | ||
35 | /** | 37 | /** |
36 | * Store interface used in the client API. | 38 | * Store interface used in the client API. |
@@ -136,6 +138,15 @@ namespace Resources { | |||
136 | KAsync::Job<void> inspect(const Inspection &inspectionCommand); | 138 | KAsync::Job<void> inspect(const Inspection &inspectionCommand); |
137 | } | 139 | } |
138 | 140 | ||
141 | class Notifier { | ||
142 | public: | ||
143 | Notifier(const QSharedPointer<ResourceAccess> &resourceAccess); | ||
144 | void registerHandler(std::function<void(const ResourceNotification &)>); | ||
145 | |||
146 | private: | ||
147 | class Private; | ||
148 | QScopedPointer<Private> d; | ||
149 | }; | ||
139 | 150 | ||
140 | } | 151 | } |
141 | 152 | ||
diff --git a/common/commands/notification.fbs b/common/commands/notification.fbs index eb00986..5c810cf 100644 --- a/common/commands/notification.fbs +++ b/common/commands/notification.fbs | |||
@@ -5,6 +5,7 @@ enum NotificationCode : byte { Success = 0, Failure = 1, UserCode } | |||
5 | 5 | ||
6 | table Notification { | 6 | table Notification { |
7 | type: NotificationType = Status; | 7 | type: NotificationType = Status; |
8 | identifier: string; //An identifier that links back to the something related to the notification (e.g. an entity id or a command id) | ||
8 | message: string; | 9 | message: string; |
9 | code: int = 0; //Of type NotificationCode | 10 | code: int = 0; //Of type NotificationCode |
10 | } | 11 | } |
diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 90fc763..892c3db 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp | |||
@@ -301,6 +301,7 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c | |||
301 | if (Akonadi2::Commands::VerifyInspectionBuffer(verifier)) { | 301 | if (Akonadi2::Commands::VerifyInspectionBuffer(verifier)) { |
302 | auto buffer = Akonadi2::Commands::GetInspection(command); | 302 | auto buffer = Akonadi2::Commands::GetInspection(command); |
303 | int inspectionType = buffer->type(); | 303 | int inspectionType = buffer->type(); |
304 | QByteArray inspectionId = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->id()->Data()), buffer->id()->size()); | ||
304 | QByteArray entityId = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->entityId()->Data()), buffer->entityId()->size()); | 305 | QByteArray entityId = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->entityId()->Data()), buffer->entityId()->size()); |
305 | QByteArray domainType = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->domainType()->Data()), buffer->domainType()->size()); | 306 | QByteArray domainType = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->domainType()->Data()), buffer->domainType()->size()); |
306 | QByteArray property = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->property()->Data()), buffer->property()->size()); | 307 | QByteArray property = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->property()->Data()), buffer->property()->size()); |
@@ -308,7 +309,21 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c | |||
308 | QDataStream s(expectedValueString); | 309 | QDataStream s(expectedValueString); |
309 | QVariant expectedValue; | 310 | QVariant expectedValue; |
310 | s >> expectedValue; | 311 | s >> expectedValue; |
311 | return inspect(inspectionType, domainType, entityId, property, expectedValue); | 312 | inspect(inspectionType, inspectionId, domainType, entityId, property, expectedValue).then<void>([=]() { |
313 | Akonadi2::ResourceNotification n; | ||
314 | n.type = Akonadi2::NotificationType_Inspection; | ||
315 | n.id = inspectionId; | ||
316 | n.code = Akonadi2::NotificationCode_Success; | ||
317 | emit notify(n); | ||
318 | }, [=](int code, const QString &message) { | ||
319 | Akonadi2::ResourceNotification n; | ||
320 | n.type = Akonadi2::NotificationType_Inspection; | ||
321 | n.message = message; | ||
322 | n.id = inspectionId; | ||
323 | n.code = Akonadi2::NotificationCode_Failure; | ||
324 | emit notify(n); | ||
325 | }).exec(); | ||
326 | return KAsync::null<void>(); | ||
312 | } | 327 | } |
313 | return KAsync::error<void>(-1, "Invalid inspection command."); | 328 | return KAsync::error<void>(-1, "Invalid inspection command."); |
314 | }); | 329 | }); |
@@ -334,7 +349,7 @@ GenericResource::~GenericResource() | |||
334 | delete mSourceChangeReplay; | 349 | delete mSourceChangeReplay; |
335 | } | 350 | } |
336 | 351 | ||
337 | KAsync::Job<void> GenericResource::inspect(int inspectionType, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | 352 | KAsync::Job<void> GenericResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) |
338 | { | 353 | { |
339 | Warning() << "Inspection not implemented"; | 354 | Warning() << "Inspection not implemented"; |
340 | return KAsync::null<void>(); | 355 | return KAsync::null<void>(); |
diff --git a/common/genericresource.h b/common/genericresource.h index 90b7c29..d71061c 100644 --- a/common/genericresource.h +++ b/common/genericresource.h | |||
@@ -48,7 +48,7 @@ public: | |||
48 | virtual KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore); | 48 | virtual KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore); |
49 | virtual KAsync::Job<void> processAllMessages() Q_DECL_OVERRIDE; | 49 | virtual KAsync::Job<void> processAllMessages() Q_DECL_OVERRIDE; |
50 | virtual void setLowerBoundRevision(qint64 revision) Q_DECL_OVERRIDE; | 50 | virtual void setLowerBoundRevision(qint64 revision) Q_DECL_OVERRIDE; |
51 | virtual KAsync::Job<void> inspect(int inspectionType, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue); | 51 | virtual KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue); |
52 | 52 | ||
53 | int error() const; | 53 | int error() const; |
54 | 54 | ||
diff --git a/common/listener.cpp b/common/listener.cpp index 5d55202..bb0a130 100644 --- a/common/listener.cpp +++ b/common/listener.cpp | |||
@@ -386,6 +386,25 @@ void Listener::updateClientsWithRevision(qint64 revision) | |||
386 | m_fbb.Clear(); | 386 | m_fbb.Clear(); |
387 | } | 387 | } |
388 | 388 | ||
389 | void Listener::notify(const Akonadi2::ResourceNotification ¬ification) | ||
390 | { | ||
391 | auto messageString = m_fbb.CreateString(notification.message.toUtf8().constData(), notification.message.toUtf8().size()); | ||
392 | auto idString = m_fbb.CreateString(notification.id.constData(), notification.id.size()); | ||
393 | Akonadi2::NotificationBuilder builder(m_fbb); | ||
394 | builder.add_type(static_cast<Akonadi2::NotificationType>(notification.type)); | ||
395 | builder.add_code(notification.code); | ||
396 | builder.add_identifier(idString); | ||
397 | builder.add_message(messageString); | ||
398 | auto command = builder.Finish(); | ||
399 | Akonadi2::FinishNotificationBuffer(m_fbb, command); | ||
400 | for (Client &client : m_connections) { | ||
401 | if (client.socket && client.socket->isOpen()) { | ||
402 | Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::NotificationCommand, m_fbb); | ||
403 | } | ||
404 | } | ||
405 | m_fbb.Clear(); | ||
406 | } | ||
407 | |||
389 | Akonadi2::Resource *Listener::loadResource() | 408 | Akonadi2::Resource *Listener::loadResource() |
390 | { | 409 | { |
391 | if (!m_resource) { | 410 | if (!m_resource) { |
@@ -395,6 +414,8 @@ Akonadi2::Resource *Listener::loadResource() | |||
395 | Trace() << QString("\tResource: %1").arg((qlonglong)m_resource); | 414 | Trace() << QString("\tResource: %1").arg((qlonglong)m_resource); |
396 | connect(m_resource, &Akonadi2::Resource::revisionUpdated, | 415 | connect(m_resource, &Akonadi2::Resource::revisionUpdated, |
397 | this, &Listener::refreshRevision); | 416 | this, &Listener::refreshRevision); |
417 | connect(m_resource, &Akonadi2::Resource::notify, | ||
418 | this, &Listener::notify); | ||
398 | } else { | 419 | } else { |
399 | ErrorMsg() << "Failed to load resource " << m_resourceName; | 420 | ErrorMsg() << "Failed to load resource " << m_resourceName; |
400 | m_resource = new Akonadi2::Resource; | 421 | m_resource = new Akonadi2::Resource; |
diff --git a/common/listener.h b/common/listener.h index 3db1937..2dfd91a 100644 --- a/common/listener.h +++ b/common/listener.h | |||
@@ -28,6 +28,7 @@ | |||
28 | namespace Akonadi2 | 28 | namespace Akonadi2 |
29 | { | 29 | { |
30 | class Resource; | 30 | class Resource; |
31 | class ResourceNotification; | ||
31 | } | 32 | } |
32 | 33 | ||
33 | class QTimer; | 34 | class QTimer; |
@@ -76,6 +77,7 @@ private Q_SLOTS: | |||
76 | void onDataAvailable(); | 77 | void onDataAvailable(); |
77 | void processClientBuffers(); | 78 | void processClientBuffers(); |
78 | void refreshRevision(qint64); | 79 | void refreshRevision(qint64); |
80 | void notify(const Akonadi2::ResourceNotification &); | ||
79 | void quit(); | 81 | void quit(); |
80 | 82 | ||
81 | private: | 83 | private: |
diff --git a/common/notification.h b/common/notification.h index 8ffc24c..c83e579 100644 --- a/common/notification.h +++ b/common/notification.h | |||
@@ -32,6 +32,7 @@ namespace Akonadi2 | |||
32 | class AKONADI2COMMON_EXPORT ResourceNotification | 32 | class AKONADI2COMMON_EXPORT ResourceNotification |
33 | { | 33 | { |
34 | public: | 34 | public: |
35 | QByteArray id; | ||
35 | int type; | 36 | int type; |
36 | QString message; | 37 | QString message; |
37 | int code; | 38 | int code; |
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 65e9a8c..483d83f 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -46,6 +46,16 @@ | |||
46 | #undef Log | 46 | #undef Log |
47 | #define Log(IDENTIFIER) Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") | 47 | #define Log(IDENTIFIER) Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") |
48 | 48 | ||
49 | static void queuedInvoke(const std::function<void()> &f) | ||
50 | { | ||
51 | QTimer *timer = new QTimer; | ||
52 | QObject::connect(timer, &QTimer::timeout, [=]() { | ||
53 | f(); | ||
54 | delete timer; | ||
55 | }); | ||
56 | timer->start(0); | ||
57 | } | ||
58 | |||
49 | namespace Akonadi2 | 59 | namespace Akonadi2 |
50 | { | 60 | { |
51 | 61 | ||
@@ -534,6 +544,23 @@ bool ResourceAccess::processMessageBuffer() | |||
534 | Log(d->resourceInstanceIdentifier) << "Received shutdown notification."; | 544 | Log(d->resourceInstanceIdentifier) << "Received shutdown notification."; |
535 | close(); | 545 | close(); |
536 | break; | 546 | break; |
547 | case Akonadi2::NotificationType::NotificationType_Inspection: { | ||
548 | Log(d->resourceInstanceIdentifier) << "Received inspection notification."; | ||
549 | ResourceNotification n; | ||
550 | if (buffer->identifier()) { | ||
551 | n.id = QByteArray::fromRawData(reinterpret_cast<char const *>(buffer->identifier()->Data()), buffer->identifier()->size()); | ||
552 | } | ||
553 | if (buffer->message()) { | ||
554 | n.message = QByteArray::fromRawData(reinterpret_cast<char const *>(buffer->message()->Data()), buffer->message()->size()); | ||
555 | } | ||
556 | n.type = buffer->type(); | ||
557 | n.code = buffer->code(); | ||
558 | //The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first | ||
559 | queuedInvoke([=]() { | ||
560 | emit notification(n); | ||
561 | }); | ||
562 | } | ||
563 | break; | ||
537 | default: | 564 | default: |
538 | Warning() << "Received unknown notification: " << buffer->type(); | 565 | Warning() << "Received unknown notification: " << buffer->type(); |
539 | break; | 566 | break; |
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 27d5f17..c43b5e6 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -134,21 +134,17 @@ void DummyResource::removeFromDisk(const QByteArray &instanceIdentifier) | |||
134 | Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); | 134 | Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); |
135 | } | 135 | } |
136 | 136 | ||
137 | KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | 137 | KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) |
138 | { | 138 | { |
139 | 139 | ||
140 | Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; | 140 | Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; |
141 | if (property == "testInspection") { | 141 | if (property == "testInspection") { |
142 | Akonadi2::ResourceNotification n; | ||
143 | n.type = Akonadi2::NotificationType_Inspection; | ||
144 | if (expectedValue.toBool()) { | 142 | if (expectedValue.toBool()) { |
145 | //Success | 143 | //Success |
146 | n.code = 0; | 144 | return KAsync::null<void>(); |
147 | emit notify(n); | ||
148 | } else { | 145 | } else { |
149 | //Failure | 146 | //Failure |
150 | n.code = 1; | 147 | return KAsync::error<void>(1, "Failed."); |
151 | emit notify(n); | ||
152 | } | 148 | } |
153 | } | 149 | } |
154 | return KAsync::null<void>(); | 150 | return KAsync::null<void>(); |
diff --git a/examples/dummyresource/resourcefactory.h b/examples/dummyresource/resourcefactory.h index 3f67187..634829e 100644 --- a/examples/dummyresource/resourcefactory.h +++ b/examples/dummyresource/resourcefactory.h | |||
@@ -40,7 +40,7 @@ public: | |||
40 | KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; | 40 | KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; |
41 | using GenericResource::synchronizeWithSource; | 41 | using GenericResource::synchronizeWithSource; |
42 | static void removeFromDisk(const QByteArray &instanceIdentifier); | 42 | static void removeFromDisk(const QByteArray &instanceIdentifier); |
43 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; | 43 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; |
44 | private: | 44 | private: |
45 | KAsync::Job<void> replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; | 45 | KAsync::Job<void> replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; |
46 | Akonadi2::ApplicationDomain::Event::Ptr createEvent(const QByteArray &rid, const QMap<QString, QVariant> &data, Akonadi2::Storage::Transaction &); | 46 | Akonadi2::ApplicationDomain::Event::Ptr createEvent(const QByteArray &rid, const QMap<QString, QVariant> &data, Akonadi2::Storage::Transaction &); |
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 5942849..86150ee 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp | |||
@@ -33,6 +33,7 @@ public: | |||
33 | KAsync::Job<void> create(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; | 33 | KAsync::Job<void> create(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; |
34 | KAsync::Job<void> modify(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; | 34 | KAsync::Job<void> modify(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; |
35 | KAsync::Job<void> remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; | 35 | KAsync::Job<void> remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; |
36 | KAsync::Job<void> inspect(const Akonadi2::Inspection &) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; | ||
36 | QPair<KAsync::Job<void>, typename Akonadi2::ResultEmitter<typename T::Ptr>::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE | 37 | QPair<KAsync::Job<void>, typename Akonadi2::ResultEmitter<typename T::Ptr>::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE |
37 | { | 38 | { |
38 | auto resultProvider = new Akonadi2::ResultProvider<typename T::Ptr>(); | 39 | auto resultProvider = new Akonadi2::ResultProvider<typename T::Ptr>(); |
diff --git a/tests/inspectiontest.cpp b/tests/inspectiontest.cpp index e332844..29cce6c 100644 --- a/tests/inspectiontest.cpp +++ b/tests/inspectiontest.cpp | |||
@@ -4,11 +4,7 @@ | |||
4 | 4 | ||
5 | #include "dummyresource/resourcefactory.h" | 5 | #include "dummyresource/resourcefactory.h" |
6 | #include "clientapi.h" | 6 | #include "clientapi.h" |
7 | #include "commands.h" | ||
8 | #include "entitybuffer.h" | ||
9 | #include "resourceconfig.h" | 7 | #include "resourceconfig.h" |
10 | #include "modelresult.h" | ||
11 | #include "pipeline.h" | ||
12 | #include "log.h" | 8 | #include "log.h" |
13 | 9 | ||
14 | /** | 10 | /** |
@@ -38,25 +34,30 @@ private Q_SLOTS: | |||
38 | Akonadi2::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); | 34 | Akonadi2::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); |
39 | } | 35 | } |
40 | 36 | ||
41 | void init() | 37 | void testInspection_data() |
42 | { | 38 | { |
43 | qDebug(); | 39 | QTest::addColumn<bool>("success"); |
44 | qDebug() << "-----------------------------------------"; | 40 | QTest::newRow("success") << true; |
45 | qDebug(); | 41 | QTest::newRow("fail") << false; |
46 | } | 42 | } |
47 | 43 | ||
48 | void testMarkMailAsRead() | 44 | void testInspection() |
49 | { | 45 | { |
46 | QFETCH(bool, success); | ||
50 | using namespace Akonadi2; | 47 | using namespace Akonadi2; |
51 | using namespace Akonadi2::ApplicationDomain; | 48 | using namespace Akonadi2::ApplicationDomain; |
52 | 49 | ||
53 | Mail mail(QByteArray("org.kde.dummy.instance1"), QByteArray("identifier"), 0, QSharedPointer<MemoryBufferAdaptor::MemoryBufferAdaptor>::create()); | 50 | Mail mail(QByteArray("org.kde.dummy.instance1"), QByteArray("identifier"), 0, QSharedPointer<MemoryBufferAdaptor::MemoryBufferAdaptor>::create()); |
54 | 51 | ||
55 | auto inspectionCommand = Resources::Inspection::PropertyInspection(mail, "unread", true); | 52 | //testInspection is a magic property that the dummyresource supports |
53 | auto inspectionCommand = Resources::Inspection::PropertyInspection(mail, "testInspection", success); | ||
56 | auto result = Resources::inspect<Mail>(inspectionCommand).exec(); | 54 | auto result = Resources::inspect<Mail>(inspectionCommand).exec(); |
57 | result.waitForFinished(); | 55 | result.waitForFinished(); |
58 | QVERIFY(!result.errorCode()); | 56 | if (success) { |
59 | Akonadi2::Store::flushMessageQueue(QByteArrayList() << QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); | 57 | QVERIFY(!result.errorCode()); |
58 | } else { | ||
59 | QVERIFY(result.errorCode()); | ||
60 | } | ||
60 | } | 61 | } |
61 | }; | 62 | }; |
62 | 63 | ||