diff options
Diffstat (limited to 'tests/domainadaptortest.cpp')
-rw-r--r-- | tests/domainadaptortest.cpp | 96 |
1 files changed, 17 insertions, 79 deletions
diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index 74c0d62..1e285dc 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp | |||
@@ -13,89 +13,12 @@ | |||
13 | #include "metadata_generated.h" | 13 | #include "metadata_generated.h" |
14 | #include "entity_generated.h" | 14 | #include "entity_generated.h" |
15 | 15 | ||
16 | class TestEventAdaptor : public Akonadi2::ApplicationDomain::BufferAdaptor | 16 | class TestFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder, Akonadi2::ApplicationDomain::Buffer::EventBuilder> |
17 | { | ||
18 | public: | ||
19 | TestEventAdaptor() | ||
20 | : Akonadi2::ApplicationDomain::BufferAdaptor() | ||
21 | { | ||
22 | } | ||
23 | |||
24 | void setProperty(const QByteArray &key, const QVariant &value) | ||
25 | { | ||
26 | // if (mResourceMapper->mWriteAccessors.contains(key)) { | ||
27 | // // mResourceMapper.setProperty(key, value, mResourceBuffer); | ||
28 | // } else { | ||
29 | // // mLocalMapper.; | ||
30 | // } | ||
31 | } | ||
32 | |||
33 | virtual QVariant getProperty(const QByteArray &key) const | ||
34 | { | ||
35 | if (mResourceBuffer && mResourceMapper->hasMapping(key)) { | ||
36 | return mResourceMapper->getProperty(key, mResourceBuffer); | ||
37 | } else if (mLocalBuffer) { | ||
38 | return mLocalMapper->getProperty(key, mLocalBuffer); | ||
39 | } | ||
40 | return QVariant(); | ||
41 | } | ||
42 | |||
43 | Akonadi2::ApplicationDomain::Buffer::Event const *mLocalBuffer; | ||
44 | Akonadi2::ApplicationDomain::Buffer::Event const *mResourceBuffer; | ||
45 | |||
46 | QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> > mLocalMapper; | ||
47 | QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> > mResourceMapper; | ||
48 | }; | ||
49 | |||
50 | class TestFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::Event> | ||
51 | { | 17 | { |
52 | public: | 18 | public: |
53 | TestFactory() | 19 | TestFactory() |
54 | { | 20 | { |
55 | mResourceMapper = QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> >::create(); | 21 | mResourceWriteMapper = initializeWritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder>(); |
56 | mResourceMapper->addMapping("summary", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant { | ||
57 | if (buffer->summary()) { | ||
58 | return QString::fromStdString(buffer->summary()->c_str()); | ||
59 | } | ||
60 | return QVariant(); | ||
61 | }); | ||
62 | } | ||
63 | |||
64 | virtual QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity) | ||
65 | { | ||
66 | Akonadi2::ApplicationDomain::Buffer::Event const *resourceBuffer = 0; | ||
67 | if (auto resourceData = entity.resource()) { | ||
68 | flatbuffers::Verifier verifyer(resourceData->Data(), resourceData->size()); | ||
69 | if (Akonadi2::ApplicationDomain::Buffer::VerifyEventBuffer(verifyer)) { | ||
70 | resourceBuffer = Akonadi2::ApplicationDomain::Buffer::GetEvent(resourceData->Data()); | ||
71 | if (resourceBuffer->summary()) { | ||
72 | qDebug() << QString::fromStdString(std::string(resourceBuffer->summary()->c_str())); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | // Akonadi2::Metadata const *metadataBuffer = 0; | ||
78 | // if (auto metadataData = entity.metadata()) { | ||
79 | // flatbuffers::Verifier verifyer(metadataData->Data(), metadataData->size()); | ||
80 | // if (Akonadi2::VerifyMetadataBuffer(verifyer)) { | ||
81 | // metadataBuffer = Akonadi2::GetMetadata(metadataData); | ||
82 | // } | ||
83 | // } | ||
84 | |||
85 | Akonadi2::ApplicationDomain::Buffer::Event const *localBuffer = 0; | ||
86 | if (auto localData = entity.local()) { | ||
87 | flatbuffers::Verifier verifyer(localData->Data(), localData->size()); | ||
88 | if (Akonadi2::ApplicationDomain::Buffer::VerifyEventBuffer(verifyer)) { | ||
89 | localBuffer = Akonadi2::ApplicationDomain::Buffer::GetEvent(localData); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | auto adaptor = QSharedPointer<TestEventAdaptor>::create(); | ||
94 | adaptor->mLocalBuffer = localBuffer; | ||
95 | adaptor->mResourceBuffer = resourceBuffer; | ||
96 | adaptor->mResourceMapper = mResourceMapper; | ||
97 | adaptor->mLocalMapper = mLocalMapper; | ||
98 | return adaptor; | ||
99 | } | 22 | } |
100 | }; | 23 | }; |
101 | 24 | ||
@@ -111,6 +34,21 @@ private Q_SLOTS: | |||
111 | { | 34 | { |
112 | } | 35 | } |
113 | 36 | ||
37 | void testCreateBufferPart() | ||
38 | { | ||
39 | auto writeMapper = initializeWritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder>(); | ||
40 | |||
41 | Akonadi2::ApplicationDomain::Event event; | ||
42 | event.setProperty("summary", "foo"); | ||
43 | |||
44 | flatbuffers::FlatBufferBuilder fbb; | ||
45 | auto pos = createBufferPart<Akonadi2::ApplicationDomain::Buffer::EventBuilder, Akonadi2::ApplicationDomain::Buffer::Event>(event, fbb, *writeMapper); | ||
46 | Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); | ||
47 | |||
48 | flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize()); | ||
49 | QVERIFY(verifier.VerifyBuffer<Akonadi2::ApplicationDomain::Buffer::Event>()); | ||
50 | } | ||
51 | |||
114 | void testAdaptor() | 52 | void testAdaptor() |
115 | { | 53 | { |
116 | //Create entity buffer | 54 | //Create entity buffer |