diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-27 23:00:23 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-27 23:22:10 +0200 |
commit | 7bd184460952932a237dc6f8bea7a8cd220afadf (patch) | |
tree | dd520096627edd9c7c06d7d1a52b30bb0876be22 /tests/genericfacadetest.cpp | |
parent | 60514ebd866c8c49e90e501198588e2806c5fe7b (diff) | |
download | sink-7bd184460952932a237dc6f8bea7a8cd220afadf.tar.gz sink-7bd184460952932a237dc6f8bea7a8cd220afadf.zip |
Abstracted the storage so the facade can be tested.
Diffstat (limited to 'tests/genericfacadetest.cpp')
-rw-r--r-- | tests/genericfacadetest.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp new file mode 100644 index 0000000..fa086d1 --- /dev/null +++ b/tests/genericfacadetest.cpp | |||
@@ -0,0 +1,80 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | |||
5 | #include <common/facade.h> | ||
6 | #include <common/domainadaptor.h> | ||
7 | #include <common/resultprovider.h> | ||
8 | #include <common/synclistresult.h> | ||
9 | |||
10 | //Replace with something different | ||
11 | #include "event_generated.h" | ||
12 | |||
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 void read(const Akonadi2::Query &query, const QPair<qint64, qint64> &revisionRange, 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 | } | ||
34 | |||
35 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults; | ||
36 | }; | ||
37 | |||
38 | class TestResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> | ||
39 | { | ||
40 | public: | ||
41 | TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<EntityStorage<Akonadi2::ApplicationDomain::Event> > storage) | ||
42 | : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), storage) | ||
43 | { | ||
44 | |||
45 | } | ||
46 | virtual ~TestResourceFacade() | ||
47 | { | ||
48 | |||
49 | } | ||
50 | }; | ||
51 | |||
52 | class GenericFacadeTest : public QObject | ||
53 | { | ||
54 | Q_OBJECT | ||
55 | private Q_SLOTS: | ||
56 | |||
57 | void testLoad() | ||
58 | { | ||
59 | Akonadi2::Query query; | ||
60 | query.liveQuery = false; | ||
61 | auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create(); | ||
62 | |||
63 | auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create()); | ||
64 | storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); | ||
65 | TestResourceFacade facade("identifier", storage); | ||
66 | |||
67 | async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(resultSet->emitter()); | ||
68 | |||
69 | facade.load(query, resultSet).exec().waitForFinished(); | ||
70 | resultSet->initialResultSetComplete(); | ||
71 | |||
72 | //We have to wait for the events that deliver the results to be processed by the eventloop | ||
73 | result.exec(); | ||
74 | |||
75 | QCOMPARE(result.size(), 1); | ||
76 | } | ||
77 | }; | ||
78 | |||
79 | QTEST_MAIN(GenericFacadeTest) | ||
80 | #include "genericfacadetest.moc" | ||