diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-06 09:58:34 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-06 09:58:34 +0200 |
commit | abc90b737074d93f73490a77e1eb1e1666dac375 (patch) | |
tree | 2c79c2996401e7732d94ba3d0b623c8290484f9f | |
parent | a9f3692a0bceb796d10952307f87fdb77abadbf7 (diff) | |
download | sink-abc90b737074d93f73490a77e1eb1e1666dac375.tar.gz sink-abc90b737074d93f73490a77e1eb1e1666dac375.zip |
Test the resource status
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 13 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.h | 1 | ||||
-rw-r--r-- | tests/resourceconfigtest.cpp | 31 |
3 files changed, 45 insertions, 0 deletions
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 2bd52cc..21a76ad 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "entitybuffer.h" | 23 | #include "entitybuffer.h" |
24 | #include "pipeline.h" | 24 | #include "pipeline.h" |
25 | #include "dummycalendar_generated.h" | 25 | #include "dummycalendar_generated.h" |
26 | #include "notification_generated.h" | ||
26 | #include "mail_generated.h" | 27 | #include "mail_generated.h" |
27 | #include "createentity_generated.h" | 28 | #include "createentity_generated.h" |
28 | #include "domainadaptor.h" | 29 | #include "domainadaptor.h" |
@@ -144,6 +145,18 @@ DummyResource::~DummyResource() | |||
144 | 145 | ||
145 | } | 146 | } |
146 | 147 | ||
148 | KAsync::Job<void> DummyResource::synchronizeWithSource() | ||
149 | { | ||
150 | Trace() << "Synchronize with source and sending a notification about it"; | ||
151 | Sink::Notification n; | ||
152 | n.id = "connected"; | ||
153 | n.type = Sink::Notification::Status; | ||
154 | n.message = "We're connected"; | ||
155 | n.code = Sink::ApplicationDomain::ConnectedStatus; | ||
156 | emit notify(n); | ||
157 | return GenericResource::synchronizeWithSource(); | ||
158 | } | ||
159 | |||
147 | KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | 160 | KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) |
148 | { | 161 | { |
149 | 162 | ||
diff --git a/examples/dummyresource/resourcefactory.h b/examples/dummyresource/resourcefactory.h index 1c51b00..a7d0281 100644 --- a/examples/dummyresource/resourcefactory.h +++ b/examples/dummyresource/resourcefactory.h | |||
@@ -35,6 +35,7 @@ public: | |||
35 | DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::Pipeline> &pipeline = QSharedPointer<Sink::Pipeline>()); | 35 | DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::Pipeline> &pipeline = QSharedPointer<Sink::Pipeline>()); |
36 | virtual ~DummyResource(); | 36 | virtual ~DummyResource(); |
37 | 37 | ||
38 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE; | ||
38 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; | 39 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; |
39 | }; | 40 | }; |
40 | 41 | ||
diff --git a/tests/resourceconfigtest.cpp b/tests/resourceconfigtest.cpp index bebff50..42f8b70 100644 --- a/tests/resourceconfigtest.cpp +++ b/tests/resourceconfigtest.cpp | |||
@@ -8,6 +8,8 @@ | |||
8 | #include "modelresult.h" | 8 | #include "modelresult.h" |
9 | #include "resultprovider.h" | 9 | #include "resultprovider.h" |
10 | #include "facadefactory.h" | 10 | #include "facadefactory.h" |
11 | #include "test.h" | ||
12 | #include "testutils.h" | ||
11 | 13 | ||
12 | /** | 14 | /** |
13 | * Test of the resource configuration. | 15 | * Test of the resource configuration. |
@@ -19,6 +21,7 @@ private slots: | |||
19 | 21 | ||
20 | void initTestCase() | 22 | void initTestCase() |
21 | { | 23 | { |
24 | Sink::Test::initTest(); | ||
22 | Sink::FacadeFactory::instance().resetFactory(); | 25 | Sink::FacadeFactory::instance().resetFactory(); |
23 | ResourceConfig::clear(); | 26 | ResourceConfig::clear(); |
24 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); | 27 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); |
@@ -72,6 +75,34 @@ private slots: | |||
72 | Sink::Store::remove(res).exec().waitForFinished(); | 75 | Sink::Store::remove(res).exec().waitForFinished(); |
73 | } | 76 | } |
74 | 77 | ||
78 | void testLoadResourceStatus() | ||
79 | { | ||
80 | ResourceConfig::clear(); | ||
81 | Sink::FacadeFactory::instance().registerStaticFacades(); | ||
82 | |||
83 | Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
84 | res.setProperty("identifier", "dummyresource.identifier1"); | ||
85 | res.setProperty("type", "org.kde.dummy"); | ||
86 | res.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << "foo")); | ||
87 | |||
88 | Sink::Store::create(res).exec().waitForFinished(); | ||
89 | { | ||
90 | Sink::Query query; | ||
91 | query.liveQuery = true; | ||
92 | query.request<Sink::ApplicationDomain::SinkResource::Status>(); | ||
93 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(Sink::Query::CapabilityFilter("foo")); | ||
94 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | ||
95 | auto resource = model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkResource::Ptr>(); | ||
96 | QCOMPARE(resource->getStatus(), static_cast<int>(Sink::ApplicationDomain::OfflineStatus)); | ||
97 | |||
98 | //Synchronize to connect | ||
99 | VERIFYEXEC(Sink::Store::synchronize(query)); | ||
100 | QTRY_COMPARE(model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkResource::Ptr>()->getStatus(), static_cast<int>(Sink::ApplicationDomain::ConnectedStatus)); | ||
101 | } | ||
102 | |||
103 | VERIFYEXEC(Sink::Store::remove(res)); | ||
104 | } | ||
105 | |||
75 | }; | 106 | }; |
76 | 107 | ||
77 | QTEST_MAIN(ResourceConfigTest) | 108 | QTEST_MAIN(ResourceConfigTest) |