diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-13 00:04:05 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-13 00:04:05 +0200 |
commit | 2eb3810b66de3130f3e650627380c28a96acded7 (patch) | |
tree | 947716efcdfc0be52958e8659defbc19db9e6b6d /tests/testimplementations.h | |
parent | 1b39c149e1fe8705f7fcbd8840de85414c652dc1 (diff) | |
download | sink-2eb3810b66de3130f3e650627380c28a96acded7.tar.gz sink-2eb3810b66de3130f3e650627380c28a96acded7.zip |
Moved test implementations to central location.
Diffstat (limited to 'tests/testimplementations.h')
-rw-r--r-- | tests/testimplementations.h | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/testimplementations.h b/tests/testimplementations.h new file mode 100644 index 0000000..eee78b0 --- /dev/null +++ b/tests/testimplementations.h | |||
@@ -0,0 +1,111 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | #pragma once | ||
21 | |||
22 | #include <Async/Async> | ||
23 | |||
24 | #include <common/entitystorage.h> | ||
25 | #include <common/domainadaptor.h> | ||
26 | #include <common/resultprovider.h> | ||
27 | #include <common/synclistresult.h> | ||
28 | #include <common/resourceaccess.h> | ||
29 | #include <common/facade.h> | ||
30 | #include <common/entitystorage.h> | ||
31 | #include <common/genericresource.h> | ||
32 | |||
33 | //Replace with something different | ||
34 | #include "event_generated.h" | ||
35 | |||
36 | class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder> | ||
37 | { | ||
38 | public: | ||
39 | TestEventAdaptorFactory() | ||
40 | : DomainTypeAdaptorFactory() | ||
41 | { | ||
42 | } | ||
43 | |||
44 | virtual ~TestEventAdaptorFactory() {}; | ||
45 | }; | ||
46 | |||
47 | class TestEntityStorage : public EntityStorage<Akonadi2::ApplicationDomain::Event> | ||
48 | { | ||
49 | public: | ||
50 | using EntityStorage::EntityStorage; | ||
51 | virtual qint64 read(const Akonadi2::Query &query, qint64 oldRevision, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider) Q_DECL_OVERRIDE | ||
52 | { | ||
53 | for (const auto &res : mResults) { | ||
54 | resultProvider->add(res); | ||
55 | } | ||
56 | for (const auto &res : mModifications) { | ||
57 | resultProvider->modify(res); | ||
58 | } | ||
59 | for (const auto &res : mRemovals) { | ||
60 | resultProvider->remove(res); | ||
61 | } | ||
62 | return mLatestRevision; | ||
63 | } | ||
64 | |||
65 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults; | ||
66 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mModifications; | ||
67 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mRemovals; | ||
68 | qint64 mLatestRevision; | ||
69 | }; | ||
70 | |||
71 | class TestResourceAccess : public Akonadi2::ResourceAccessInterface | ||
72 | { | ||
73 | Q_OBJECT | ||
74 | public: | ||
75 | virtual ~TestResourceAccess() {}; | ||
76 | KAsync::Job<void> sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
77 | KAsync::Job<void> sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
78 | KAsync::Job<void> synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
79 | |||
80 | public Q_SLOTS: | ||
81 | void open() Q_DECL_OVERRIDE {} | ||
82 | void close() Q_DECL_OVERRIDE {} | ||
83 | }; | ||
84 | |||
85 | class TestResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> | ||
86 | { | ||
87 | public: | ||
88 | TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<EntityStorage<Akonadi2::ApplicationDomain::Event> > storage, const QSharedPointer<Akonadi2::ResourceAccessInterface> resourceAccess) | ||
89 | : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), storage, resourceAccess) | ||
90 | { | ||
91 | |||
92 | } | ||
93 | virtual ~TestResourceFacade() | ||
94 | { | ||
95 | |||
96 | } | ||
97 | }; | ||
98 | |||
99 | class TestResource : public Akonadi2::GenericResource | ||
100 | { | ||
101 | public: | ||
102 | TestResource(const QByteArray &instanceIdentifier, QSharedPointer<Akonadi2::Pipeline> pipeline) | ||
103 | : Akonadi2::GenericResource(instanceIdentifier, pipeline) | ||
104 | { | ||
105 | } | ||
106 | |||
107 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | ||
108 | { | ||
109 | return KAsync::null<void>(); | ||
110 | } | ||
111 | }; | ||