diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-28 16:50:39 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-28 16:50:39 +0200 |
commit | e22776a57bd12621358ad7cd98dac3261f2a70db (patch) | |
tree | c6fa0cef56931b042c3837826219353c31429422 /tests/genericfacadetest.cpp | |
parent | a547d10f3d36e7c820d913d22798ca051c6e3df3 (diff) | |
download | sink-e22776a57bd12621358ad7cd98dac3261f2a70db.tar.gz sink-e22776a57bd12621358ad7cd98dac3261f2a70db.zip |
Test life queries in the generic facade
Diffstat (limited to 'tests/genericfacadetest.cpp')
-rw-r--r-- | tests/genericfacadetest.cpp | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp index fa086d1..7aaec23 100644 --- a/tests/genericfacadetest.cpp +++ b/tests/genericfacadetest.cpp | |||
@@ -35,11 +35,25 @@ public: | |||
35 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults; | 35 | QList<Akonadi2::ApplicationDomain::Event::Ptr> mResults; |
36 | }; | 36 | }; |
37 | 37 | ||
38 | class TestResourceAccess : public Akonadi2::ResourceAccessInterface | ||
39 | { | ||
40 | Q_OBJECT | ||
41 | public: | ||
42 | virtual ~TestResourceAccess() {}; | ||
43 | KAsync::Job<void> sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
44 | KAsync::Job<void> sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
45 | KAsync::Job<void> synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null<void>(); } | ||
46 | |||
47 | public Q_SLOTS: | ||
48 | void open() Q_DECL_OVERRIDE {} | ||
49 | void close() Q_DECL_OVERRIDE {} | ||
50 | }; | ||
51 | |||
38 | class TestResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> | 52 | class TestResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> |
39 | { | 53 | { |
40 | public: | 54 | public: |
41 | TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<EntityStorage<Akonadi2::ApplicationDomain::Event> > storage) | 55 | TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<EntityStorage<Akonadi2::ApplicationDomain::Event> > storage, const QSharedPointer<Akonadi2::ResourceAccessInterface> resourceAccess) |
42 | : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), storage) | 56 | : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), storage, resourceAccess) |
43 | { | 57 | { |
44 | 58 | ||
45 | } | 59 | } |
@@ -58,11 +72,12 @@ private Q_SLOTS: | |||
58 | { | 72 | { |
59 | Akonadi2::Query query; | 73 | Akonadi2::Query query; |
60 | query.liveQuery = false; | 74 | query.liveQuery = false; |
61 | auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create(); | ||
62 | 75 | ||
76 | auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create(); | ||
63 | auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create()); | 77 | auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create()); |
78 | auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); | ||
64 | storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); | 79 | storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); |
65 | TestResourceFacade facade("identifier", storage); | 80 | TestResourceFacade facade("identifier", storage, resourceAccess); |
66 | 81 | ||
67 | async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(resultSet->emitter()); | 82 | async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(resultSet->emitter()); |
68 | 83 | ||
@@ -74,6 +89,38 @@ private Q_SLOTS: | |||
74 | 89 | ||
75 | QCOMPARE(result.size(), 1); | 90 | QCOMPARE(result.size(), 1); |
76 | } | 91 | } |
92 | |||
93 | void testLiveQuery() | ||
94 | { | ||
95 | Akonadi2::Query query; | ||
96 | query.liveQuery = true; | ||
97 | |||
98 | auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create(); | ||
99 | auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create()); | ||
100 | auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); | ||
101 | storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); | ||
102 | TestResourceFacade facade("identifier", storage, resourceAccess); | ||
103 | |||
104 | async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(resultSet->emitter()); | ||
105 | |||
106 | facade.load(query, resultSet).exec().waitForFinished(); | ||
107 | resultSet->initialResultSetComplete(); | ||
108 | |||
109 | result.exec(); | ||
110 | QCOMPARE(result.size(), 1); | ||
111 | |||
112 | //Enter a second result | ||
113 | storage->mResults.clear(); | ||
114 | storage->mResults << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); | ||
115 | resourceAccess->emit revisionChanged(2); | ||
116 | |||
117 | //Hack to get event loop in synclistresult to abort again | ||
118 | resultSet->initialResultSetComplete(); | ||
119 | result.exec(); | ||
120 | |||
121 | // QTRY_COMPARE(result.size(), 2); | ||
122 | QCOMPARE(result.size(), 2); | ||
123 | } | ||
77 | }; | 124 | }; |
78 | 125 | ||
79 | QTEST_MAIN(GenericFacadeTest) | 126 | QTEST_MAIN(GenericFacadeTest) |