From 319a303bdceba18d0e5629f3de7a2b85646223be Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 6 Dec 2016 18:32:32 +0100 Subject: Wrap blob properties in type so we can distinguish it from other properties. When moving an entity to another resource we have to move the blob properties to a temporary directory first, and that requires that we are able to distinguish blob properties from the rest at runtime. --- tests/domainadaptortest.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests') diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index c29e61b..4fd04db 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp @@ -10,6 +10,7 @@ #include "common/domainadaptor.h" #include "common/entitybuffer.h" #include "event_generated.h" +#include "mail_generated.h" #include "metadata_generated.h" #include "entity_generated.h" @@ -23,6 +24,16 @@ public: } }; +class TestMailFactory : public DomainTypeAdaptorFactory +{ +public: + TestMailFactory() + { + mResourceWriteMapper = QSharedPointer>::create(); + Sink::ApplicationDomain::TypeImplementation::configure(*mResourceWriteMapper); + } +}; + /** * Test of domain adaptor, that it can read and write buffers. */ @@ -90,6 +101,42 @@ private slots: QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary1")); } } + + void testMail() + { + auto writeMapper = QSharedPointer>::create(); + Sink::ApplicationDomain::TypeImplementation::configure(*writeMapper); + + Sink::ApplicationDomain::Mail mail; + mail.setExtractedSubject("summary"); + mail.setMimeMessage("foobar"); + + flatbuffers::FlatBufferBuilder metadataFbb; + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); + metadataBuilder.add_revision(1); + auto metadataBuffer = metadataBuilder.Finish(); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); + + flatbuffers::FlatBufferBuilder mailFbb; + auto pos = createBufferPart(mail, mailFbb, *writeMapper); + Sink::ApplicationDomain::Buffer::FinishMailBuffer(mailFbb, pos); + + flatbuffers::FlatBufferBuilder fbb; + Sink::EntityBuffer::assembleEntityBuffer( + fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), mailFbb.GetBufferPointer(), mailFbb.GetSize(), mailFbb.GetBufferPointer(), mailFbb.GetSize()); + + { + std::string data(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); + Sink::EntityBuffer buffer((void *)(data.data()), data.size()); + + TestMailFactory factory; + auto adaptor = factory.createAdaptor(buffer.entity()); + Sink::ApplicationDomain::Mail readMail{QByteArray{}, QByteArray{}, 0, adaptor}; + QCOMPARE(readMail.getSubject(), mail.getSubject()); + QCOMPARE(readMail.getMimeMessage(), mail.getMimeMessage()); + } + + } }; QTEST_MAIN(DomainAdaptorTest) -- cgit v1.2.3