diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/dummyresourcetest.cpp | 83 |
1 files changed, 66 insertions, 17 deletions
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index b39b2b1..ddb59a5 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp | |||
@@ -2,8 +2,21 @@ | |||
2 | 2 | ||
3 | #include <QString> | 3 | #include <QString> |
4 | 4 | ||
5 | // #include "dummycalendar_generated.h" | ||
6 | #include "event_generated.h" | ||
7 | #include "entity_generated.h" | ||
8 | #include "metadata_generated.h" | ||
9 | #include "createentity_generated.h" | ||
5 | #include "dummyresource/resourcefactory.h" | 10 | #include "dummyresource/resourcefactory.h" |
6 | #include "clientapi.h" | 11 | #include "clientapi.h" |
12 | #include "commands.h" | ||
13 | #include "entitybuffer.h" | ||
14 | |||
15 | static void removeFromDisk(const QString &name) | ||
16 | { | ||
17 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy", Akonadi2::Storage::ReadWrite); | ||
18 | store.removeFromDisk(); | ||
19 | } | ||
7 | 20 | ||
8 | class DummyResourceTest : public QObject | 21 | class DummyResourceTest : public QObject |
9 | { | 22 | { |
@@ -13,34 +26,70 @@ private Q_SLOTS: | |||
13 | { | 26 | { |
14 | auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); | 27 | auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); |
15 | QVERIFY(factory); | 28 | QVERIFY(factory); |
16 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy", Akonadi2::Storage::ReadWrite); | 29 | removeFromDisk("org.kde.dummy"); |
17 | store.removeFromDisk(); | 30 | removeFromDisk("org.kde.dummy.userqueue"); |
31 | removeFromDisk("org.kde.dummy.synchronizerqueue"); | ||
18 | } | 32 | } |
19 | 33 | ||
20 | void cleanupTestCase() | 34 | void cleanupTestCase() |
21 | { | 35 | { |
22 | } | 36 | } |
23 | 37 | ||
24 | void testResource() | 38 | void testProcessCommand() |
25 | { | 39 | { |
40 | flatbuffers::FlatBufferBuilder eventFbb; | ||
41 | eventFbb.Clear(); | ||
42 | { | ||
43 | auto summary = eventFbb.CreateString("summary"); | ||
44 | Akonadi2::Domain::Buffer::EventBuilder eventBuilder(eventFbb); | ||
45 | eventBuilder.add_summary(summary); | ||
46 | auto eventLocation = eventBuilder.Finish(); | ||
47 | Akonadi2::Domain::Buffer::FinishEventBuffer(eventFbb, eventLocation); | ||
48 | } | ||
49 | |||
50 | flatbuffers::FlatBufferBuilder entityFbb; | ||
51 | Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), 0, 0); | ||
52 | |||
53 | flatbuffers::FlatBufferBuilder fbb; | ||
54 | auto type = fbb.CreateString(Akonadi2::Domain::getTypeName<Akonadi2::Domain::Event>().toStdString().data()); | ||
55 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
56 | Akonadi2::Commands::CreateEntityBuilder builder(fbb); | ||
57 | builder.add_domainType(type); | ||
58 | builder.add_delta(delta); | ||
59 | auto location = builder.Finish(); | ||
60 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | ||
61 | |||
62 | const QByteArray command(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
63 | |||
26 | Akonadi2::Pipeline pipeline("org.kde.dummy"); | 64 | Akonadi2::Pipeline pipeline("org.kde.dummy"); |
27 | DummyResource resource; | 65 | DummyResource resource; |
28 | auto job = resource.synchronizeWithSource(&pipeline); | 66 | resource.configurePipeline(&pipeline); |
29 | auto future = job.exec(); | 67 | resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command, command.size(), &pipeline); |
30 | QTRY_VERIFY(future.isFinished()); | 68 | //TODO wait until the pipeline has processed the command |
69 | QTest::qWait(1000); | ||
31 | } | 70 | } |
32 | 71 | ||
33 | void testSyncAndFacade() | 72 | // void testResourceSync() |
34 | { | 73 | // { |
35 | Akonadi2::Query query; | 74 | // Akonadi2::Pipeline pipeline("org.kde.dummy"); |
36 | query.resources << "org.kde.dummy"; | 75 | // DummyResource resource; |
37 | 76 | // auto job = resource.synchronizeWithSource(&pipeline); | |
38 | async::SyncListResult<Akonadi2::Domain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::Domain::Event>(query)); | 77 | // auto future = job.exec(); |
39 | result.exec(); | 78 | // QTRY_VERIFY(future.isFinished()); |
40 | QVERIFY(!result.isEmpty()); | 79 | // } |
41 | auto value = result.first(); | 80 | |
42 | QVERIFY(!value->getProperty("summary").toString().isEmpty()); | 81 | // void testSyncAndFacade() |
43 | } | 82 | // { |
83 | // Akonadi2::Query query; | ||
84 | // query.resources << "org.kde.dummy"; | ||
85 | |||
86 | // async::SyncListResult<Akonadi2::Domain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::Domain::Event>(query)); | ||
87 | // result.exec(); | ||
88 | // QVERIFY(!result.isEmpty()); | ||
89 | // auto value = result.first(); | ||
90 | // QVERIFY(!value->getProperty("summary").toString().isEmpty()); | ||
91 | // qDebug() << value->getProperty("summary").toString(); | ||
92 | // } | ||
44 | 93 | ||
45 | }; | 94 | }; |
46 | 95 | ||