diff options
-rw-r--r-- | tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/genericfacadebenchmark.cpp | 39 | ||||
-rw-r--r-- | tests/genericfacadetest.cpp | 64 | ||||
-rw-r--r-- | tests/genericresourcebenchmark.cpp | 27 | ||||
-rw-r--r-- | tests/genericresourcetest.cpp | 17 | ||||
-rw-r--r-- | tests/pipelinetest.cpp | 13 | ||||
-rw-r--r-- | tests/testimplementations.cpp | 23 | ||||
-rw-r--r-- | tests/testimplementations.h | 111 |
8 files changed, 146 insertions, 152 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b2201ff..5629cdb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -10,7 +10,7 @@ include_directories( | |||
10 | 10 | ||
11 | macro(manual_tests) | 11 | macro(manual_tests) |
12 | foreach(_testname ${ARGN}) | 12 | foreach(_testname ${ARGN}) |
13 | add_executable(${_testname} ${_testname}.cpp) | 13 | add_executable(${_testname} ${_testname}.cpp testimplementations.cpp) |
14 | generate_flatbuffers(${_testname} calendar) | 14 | generate_flatbuffers(${_testname} calendar) |
15 | qt5_use_modules(${_testname} Core Test Concurrent) | 15 | qt5_use_modules(${_testname} Core Test Concurrent) |
16 | target_link_libraries(${_testname} akonadi2common libhawd) | 16 | target_link_libraries(${_testname} akonadi2common libhawd) |
@@ -19,7 +19,7 @@ endmacro(manual_tests) | |||
19 | 19 | ||
20 | macro(auto_tests) | 20 | macro(auto_tests) |
21 | foreach(_testname ${ARGN}) | 21 | foreach(_testname ${ARGN}) |
22 | add_executable(${_testname} ${_testname}.cpp) | 22 | add_executable(${_testname} ${_testname}.cpp testimplementations.cpp) |
23 | generate_flatbuffers(${_testname} calendar) | 23 | generate_flatbuffers(${_testname} calendar) |
24 | add_test(${_testname} ${_testname}) | 24 | add_test(${_testname} ${_testname}) |
25 | qt5_use_modules(${_testname} Core Test Concurrent) | 25 | qt5_use_modules(${_testname} Core Test Concurrent) |
diff --git a/tests/genericfacadebenchmark.cpp b/tests/genericfacadebenchmark.cpp index 7cd6c75..3e98fce 100644 --- a/tests/genericfacadebenchmark.cpp +++ b/tests/genericfacadebenchmark.cpp | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | #include <QString> | 3 | #include <QString> |
4 | 4 | ||
5 | #include "testimplementations.h" | ||
6 | |||
5 | #include <common/facade.h> | 7 | #include <common/facade.h> |
6 | #include <common/domainadaptor.h> | 8 | #include <common/domainadaptor.h> |
7 | #include <common/resultprovider.h> | 9 | #include <common/resultprovider.h> |
@@ -9,44 +11,7 @@ | |||
9 | 11 | ||
10 | #include "event_generated.h" | 12 | #include "event_generated.h" |
11 | 13 | ||
12 | class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder> | ||
13 | { | ||
14 | public: | ||
15 | TestEventAdaptorFactory() | ||
16 | : DomainTypeAdaptorFactory() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | virtual ~TestEventAdaptorFactory() {}; | ||
21 | }; | ||
22 | |||
23 | class TestResourceAccess : public Akonadi2::ResourceAccessInterface | ||
24 | { | ||
25 | Q_OBJECT | ||
26 | public: | ||
27 | virtual ~TestResourceAccess() {}; | ||
28 | KAsync::Job<void> sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
29 | KAsync::Job<void> sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
30 | KAsync::Job<void> synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
31 | |||
32 | public Q_SLOTS: | ||
33 | void open() Q_DECL_OVERRIDE {} | ||
34 | void close() Q_DECL_OVERRIDE {} | ||
35 | }; | ||
36 | |||
37 | class TestResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> | ||
38 | { | ||
39 | public: | ||
40 | TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<EntityStorage<Akonadi2::ApplicationDomain::Event> > storage, const QSharedPointer<Akonadi2::ResourceAccessInterface> resourceAccess) | ||
41 | : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), storage, resourceAccess) | ||
42 | { | ||
43 | 14 | ||
44 | } | ||
45 | virtual ~TestResourceFacade() | ||
46 | { | ||
47 | |||
48 | } | ||
49 | }; | ||
50 | 15 | ||
51 | class GenericFacadeBenchmark : public QObject | 16 | class GenericFacadeBenchmark : public QObject |
52 | { | 17 | { |
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp index e9c1a94..ae6a685 100644 --- a/tests/genericfacadetest.cpp +++ b/tests/genericfacadetest.cpp | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | #include <QString> | 3 | #include <QString> |
4 | 4 | ||
5 | #include "testimplementations.h" | ||
6 | |||
5 | #include <common/facade.h> | 7 | #include <common/facade.h> |
6 | #include <common/domainadaptor.h> | 8 | #include <common/domainadaptor.h> |
7 | #include <common/resultprovider.h> | 9 | #include <common/resultprovider.h> |
@@ -10,68 +12,6 @@ | |||
10 | //Replace with something different | 12 | //Replace with something different |
11 | #include "event_generated.h" | 13 | #include "event_generated.h" |
12 | 14 | ||
13 | class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder> | ||
14 | { | ||
15 | public: | ||
16 | TestEventAdaptorFactory() | ||
17 | : DomainTypeAdaptorFactory() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | virtual ~TestEventAdaptorFactory() {}; | ||
22 | }; | ||
23 | |||
24 | class TestEntityStorage : public EntityStorage<Akonadi2::ApplicationDomain::Event> | ||
25 | { | ||
26 | public: | ||
27 | using EntityStorage::EntityStorage; | ||
28 | virtual qint64 read(const Akonadi2::Query &query, qint64 oldRevision, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider) Q_DECL_OVERRIDE | ||
29 | { | ||
30 | for (const auto &res : mResults) { | ||
31 | resultProvider->add(res); | ||
32 | } | ||
33 | for (const auto &res : mModifications) { | ||
34 | resultProvider->modify(res); | ||
35 | } | ||
36 | for (const auto &res : mRemovals) { | ||
37 | resultProvider->remove(res); | ||
38 | } | ||
39 | return mLatestRevision; | ||
40 | } | ||
41 | |||
42 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults; | ||
43 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mModifications; | ||
44 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mRemovals; | ||
45 | qint64 mLatestRevision; | ||
46 | }; | ||
47 | |||
48 | class TestResourceAccess : public Akonadi2::ResourceAccessInterface | ||
49 | { | ||
50 | Q_OBJECT | ||
51 | public: | ||
52 | virtual ~TestResourceAccess() {}; | ||
53 | KAsync::Job<void> sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
54 | KAsync::Job<void> sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
55 | KAsync::Job<void> synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
56 | |||
57 | public Q_SLOTS: | ||
58 | void open() Q_DECL_OVERRIDE {} | ||
59 | void close() Q_DECL_OVERRIDE {} | ||
60 | }; | ||
61 | |||
62 | class TestResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> | ||
63 | { | ||
64 | public: | ||
65 | TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<EntityStorage<Akonadi2::ApplicationDomain::Event> > storage, const QSharedPointer<Akonadi2::ResourceAccessInterface> resourceAccess) | ||
66 | : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), storage, resourceAccess) | ||
67 | { | ||
68 | |||
69 | } | ||
70 | virtual ~TestResourceFacade() | ||
71 | { | ||
72 | |||
73 | } | ||
74 | }; | ||
75 | 15 | ||
76 | class GenericFacadeTest : public QObject | 16 | class GenericFacadeTest : public QObject |
77 | { | 17 | { |
diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp index 50d0c67..1776c81 100644 --- a/tests/genericresourcebenchmark.cpp +++ b/tests/genericresourcebenchmark.cpp | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | #include <QString> | 3 | #include <QString> |
4 | 4 | ||
5 | #include "testimplementations.h" | ||
6 | |||
5 | #include "event_generated.h" | 7 | #include "event_generated.h" |
6 | #include "createentity_generated.h" | 8 | #include "createentity_generated.h" |
7 | #include "commands.h" | 9 | #include "commands.h" |
@@ -15,31 +17,6 @@ | |||
15 | #include "hawd/dataset.h" | 17 | #include "hawd/dataset.h" |
16 | #include "hawd/formatter.h" | 18 | #include "hawd/formatter.h" |
17 | 19 | ||
18 | class TestResource : public Akonadi2::GenericResource | ||
19 | { | ||
20 | public: | ||
21 | TestResource(const QByteArray &instanceIdentifier, QSharedPointer<Akonadi2::Pipeline> pipeline) | ||
22 | : Akonadi2::GenericResource(instanceIdentifier, pipeline) | ||
23 | { | ||
24 | } | ||
25 | |||
26 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | ||
27 | { | ||
28 | return KAsync::null<void>(); | ||
29 | } | ||
30 | }; | ||
31 | |||
32 | class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder> | ||
33 | { | ||
34 | public: | ||
35 | TestEventAdaptorFactory() | ||
36 | : DomainTypeAdaptorFactory() | ||
37 | { | ||
38 | } | ||
39 | |||
40 | virtual ~TestEventAdaptorFactory() {}; | ||
41 | }; | ||
42 | |||
43 | 20 | ||
44 | static void removeFromDisk(const QString &name) | 21 | static void removeFromDisk(const QString &name) |
45 | { | 22 | { |
diff --git a/tests/genericresourcetest.cpp b/tests/genericresourcetest.cpp index fa6da22..60b1dab 100644 --- a/tests/genericresourcetest.cpp +++ b/tests/genericresourcetest.cpp | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | #include <QString> | 3 | #include <QString> |
4 | 4 | ||
5 | #include "testimplementations.h" | ||
6 | |||
5 | #include "event_generated.h" | 7 | #include "event_generated.h" |
6 | #include "entity_generated.h" | 8 | #include "entity_generated.h" |
7 | #include "metadata_generated.h" | 9 | #include "metadata_generated.h" |
@@ -12,21 +14,6 @@ | |||
12 | #include "genericresource.h" | 14 | #include "genericresource.h" |
13 | #include "definitions.h" | 15 | #include "definitions.h" |
14 | 16 | ||
15 | class TestResource : public Akonadi2::GenericResource | ||
16 | { | ||
17 | public: | ||
18 | TestResource(const QByteArray &instanceIdentifier, QSharedPointer<Akonadi2::Pipeline> pipeline) | ||
19 | : Akonadi2::GenericResource(instanceIdentifier, pipeline) | ||
20 | { | ||
21 | } | ||
22 | |||
23 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | ||
24 | { | ||
25 | return KAsync::null<void>(); | ||
26 | } | ||
27 | }; | ||
28 | |||
29 | |||
30 | static void removeFromDisk(const QString &name) | 17 | static void removeFromDisk(const QString &name) |
31 | { | 18 | { |
32 | Akonadi2::Storage store(Akonadi2::storageLocation(), name, Akonadi2::Storage::ReadWrite); | 19 | Akonadi2::Storage store(Akonadi2::storageLocation(), name, Akonadi2::Storage::ReadWrite); |
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 4cff511..9aa7024 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | #include <QString> | 3 | #include <QString> |
4 | 4 | ||
5 | #include "testimplementations.h" | ||
6 | |||
5 | #include "event_generated.h" | 7 | #include "event_generated.h" |
6 | #include "entity_generated.h" | 8 | #include "entity_generated.h" |
7 | #include "metadata_generated.h" | 9 | #include "metadata_generated.h" |
@@ -18,17 +20,6 @@ | |||
18 | #include "log.h" | 20 | #include "log.h" |
19 | #include "domainadaptor.h" | 21 | #include "domainadaptor.h" |
20 | 22 | ||
21 | class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder> | ||
22 | { | ||
23 | public: | ||
24 | TestEventAdaptorFactory() | ||
25 | : DomainTypeAdaptorFactory() | ||
26 | { | ||
27 | } | ||
28 | |||
29 | virtual ~TestEventAdaptorFactory() {}; | ||
30 | }; | ||
31 | |||
32 | static void removeFromDisk(const QString &name) | 23 | static void removeFromDisk(const QString &name) |
33 | { | 24 | { |
34 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), name, Akonadi2::Storage::ReadWrite); | 25 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), name, Akonadi2::Storage::ReadWrite); |
diff --git a/tests/testimplementations.cpp b/tests/testimplementations.cpp new file mode 100644 index 0000000..1040956 --- /dev/null +++ b/tests/testimplementations.cpp | |||
@@ -0,0 +1,23 @@ | |||
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 | |||
21 | #include "testimplementations.h" | ||
22 | |||
23 | #include "testimplementations.moc" | ||
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 | }; | ||