From e85967518b9041e9943ec5f1765c6694bb153840 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 12 Apr 2015 16:02:10 +0200 Subject: More generic domainadpator code. This should cover read and write for entites that have a 1:1 mapping to the resource buffers. --- tests/domainadaptortest.cpp | 96 ++++++++------------------------------------- 1 file changed, 17 insertions(+), 79 deletions(-) (limited to 'tests/domainadaptortest.cpp') 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 @@ #include "metadata_generated.h" #include "entity_generated.h" -class TestEventAdaptor : public Akonadi2::ApplicationDomain::BufferAdaptor -{ -public: - TestEventAdaptor() - : Akonadi2::ApplicationDomain::BufferAdaptor() - { - } - - void setProperty(const QByteArray &key, const QVariant &value) - { - // if (mResourceMapper->mWriteAccessors.contains(key)) { - // // mResourceMapper.setProperty(key, value, mResourceBuffer); - // } else { - // // mLocalMapper.; - // } - } - - virtual QVariant getProperty(const QByteArray &key) const - { - if (mResourceBuffer && mResourceMapper->hasMapping(key)) { - return mResourceMapper->getProperty(key, mResourceBuffer); - } else if (mLocalBuffer) { - return mLocalMapper->getProperty(key, mLocalBuffer); - } - return QVariant(); - } - - Akonadi2::ApplicationDomain::Buffer::Event const *mLocalBuffer; - Akonadi2::ApplicationDomain::Buffer::Event const *mResourceBuffer; - - QSharedPointer > mLocalMapper; - QSharedPointer > mResourceMapper; -}; - -class TestFactory : public DomainTypeAdaptorFactory +class TestFactory : public DomainTypeAdaptorFactory { public: TestFactory() { - mResourceMapper = QSharedPointer >::create(); - mResourceMapper->addMapping("summary", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant { - if (buffer->summary()) { - return QString::fromStdString(buffer->summary()->c_str()); - } - return QVariant(); - }); - } - - virtual QSharedPointer createAdaptor(const Akonadi2::Entity &entity) - { - Akonadi2::ApplicationDomain::Buffer::Event const *resourceBuffer = 0; - if (auto resourceData = entity.resource()) { - flatbuffers::Verifier verifyer(resourceData->Data(), resourceData->size()); - if (Akonadi2::ApplicationDomain::Buffer::VerifyEventBuffer(verifyer)) { - resourceBuffer = Akonadi2::ApplicationDomain::Buffer::GetEvent(resourceData->Data()); - if (resourceBuffer->summary()) { - qDebug() << QString::fromStdString(std::string(resourceBuffer->summary()->c_str())); - } - } - } - - // Akonadi2::Metadata const *metadataBuffer = 0; - // if (auto metadataData = entity.metadata()) { - // flatbuffers::Verifier verifyer(metadataData->Data(), metadataData->size()); - // if (Akonadi2::VerifyMetadataBuffer(verifyer)) { - // metadataBuffer = Akonadi2::GetMetadata(metadataData); - // } - // } - - Akonadi2::ApplicationDomain::Buffer::Event const *localBuffer = 0; - if (auto localData = entity.local()) { - flatbuffers::Verifier verifyer(localData->Data(), localData->size()); - if (Akonadi2::ApplicationDomain::Buffer::VerifyEventBuffer(verifyer)) { - localBuffer = Akonadi2::ApplicationDomain::Buffer::GetEvent(localData); - } - } - - auto adaptor = QSharedPointer::create(); - adaptor->mLocalBuffer = localBuffer; - adaptor->mResourceBuffer = resourceBuffer; - adaptor->mResourceMapper = mResourceMapper; - adaptor->mLocalMapper = mLocalMapper; - return adaptor; + mResourceWriteMapper = initializeWritePropertyMapper(); } }; @@ -111,6 +34,21 @@ private Q_SLOTS: { } + void testCreateBufferPart() + { + auto writeMapper = initializeWritePropertyMapper(); + + Akonadi2::ApplicationDomain::Event event; + event.setProperty("summary", "foo"); + + flatbuffers::FlatBufferBuilder fbb; + auto pos = createBufferPart(event, fbb, *writeMapper); + Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); + + flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize()); + QVERIFY(verifier.VerifyBuffer()); + } + void testAdaptor() { //Create entity buffer -- cgit v1.2.3