diff options
Diffstat (limited to 'common/test/clientapitest.cpp')
-rw-r--r-- | common/test/clientapitest.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/common/test/clientapitest.cpp b/common/test/clientapitest.cpp new file mode 100644 index 0000000..2d1c238 --- /dev/null +++ b/common/test/clientapitest.cpp | |||
@@ -0,0 +1,48 @@ | |||
1 | #include <QtTest> | ||
2 | #include <QDebug> | ||
3 | #include <functional> | ||
4 | |||
5 | #include "../clientapi.h" | ||
6 | |||
7 | class DummyResourceFacade : public Akonadi2::StoreFacade<Akonadi2::Domain::Event> | ||
8 | { | ||
9 | public: | ||
10 | ~DummyResourceFacade(){}; | ||
11 | virtual void create(const Akonadi2::Domain::Event &domainObject){}; | ||
12 | virtual void modify(const Akonadi2::Domain::Event &domainObject){}; | ||
13 | virtual void remove(const Akonadi2::Domain::Event &domainObject){}; | ||
14 | virtual void load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback) | ||
15 | { | ||
16 | qDebug() << "load called"; | ||
17 | for(const auto &result : results) { | ||
18 | resultCallback(result); | ||
19 | } | ||
20 | } | ||
21 | |||
22 | QList<Akonadi2::Domain::Event::Ptr> results; | ||
23 | }; | ||
24 | |||
25 | class ClientAPITest : public QObject | ||
26 | { | ||
27 | Q_OBJECT | ||
28 | private Q_SLOTS: | ||
29 | |||
30 | void testLoad() | ||
31 | { | ||
32 | DummyResourceFacade facade; | ||
33 | facade.results << QSharedPointer<Akonadi2::Domain::Event>::create("resource", "id", 0); | ||
34 | |||
35 | Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::Domain::Event, DummyResourceFacade>("dummyresource", [facade](){ return new DummyResourceFacade(facade); }); | ||
36 | |||
37 | Akonadi2::Query query; | ||
38 | query.resources << "dummyresource"; | ||
39 | |||
40 | async::SyncListResult<Akonadi2::Domain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::Domain::Event>(query)); | ||
41 | result.exec(); | ||
42 | QCOMPARE(result.size(), 1); | ||
43 | } | ||
44 | |||
45 | }; | ||
46 | |||
47 | QTEST_MAIN(ClientAPITest) | ||
48 | #include "clientapitest.moc" | ||