diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-06 18:32:32 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-06 18:32:32 +0100 |
commit | 319a303bdceba18d0e5629f3de7a2b85646223be (patch) | |
tree | 7e4ccb76fa5ee875f49ea3d65e9e519e90573354 /tests | |
parent | 59aa460cf704d5f1a1fb1fe6b8ede4457da083ff (diff) | |
download | sink-319a303bdceba18d0e5629f3de7a2b85646223be.tar.gz sink-319a303bdceba18d0e5629f3de7a2b85646223be.zip |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/domainadaptortest.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
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 @@ | |||
10 | #include "common/domainadaptor.h" | 10 | #include "common/domainadaptor.h" |
11 | #include "common/entitybuffer.h" | 11 | #include "common/entitybuffer.h" |
12 | #include "event_generated.h" | 12 | #include "event_generated.h" |
13 | #include "mail_generated.h" | ||
13 | #include "metadata_generated.h" | 14 | #include "metadata_generated.h" |
14 | #include "entity_generated.h" | 15 | #include "entity_generated.h" |
15 | 16 | ||
@@ -23,6 +24,16 @@ public: | |||
23 | } | 24 | } |
24 | }; | 25 | }; |
25 | 26 | ||
27 | class TestMailFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Mail, Sink::ApplicationDomain::Buffer::Mail, Sink::ApplicationDomain::Buffer::MailBuilder> | ||
28 | { | ||
29 | public: | ||
30 | TestMailFactory() | ||
31 | { | ||
32 | mResourceWriteMapper = QSharedPointer<WritePropertyMapper<Sink::ApplicationDomain::Buffer::MailBuilder>>::create(); | ||
33 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Mail>::configure(*mResourceWriteMapper); | ||
34 | } | ||
35 | }; | ||
36 | |||
26 | /** | 37 | /** |
27 | * Test of domain adaptor, that it can read and write buffers. | 38 | * Test of domain adaptor, that it can read and write buffers. |
28 | */ | 39 | */ |
@@ -90,6 +101,42 @@ private slots: | |||
90 | QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary1")); | 101 | QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary1")); |
91 | } | 102 | } |
92 | } | 103 | } |
104 | |||
105 | void testMail() | ||
106 | { | ||
107 | auto writeMapper = QSharedPointer<WritePropertyMapper<Sink::ApplicationDomain::Buffer::MailBuilder>>::create(); | ||
108 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Mail>::configure(*writeMapper); | ||
109 | |||
110 | Sink::ApplicationDomain::Mail mail; | ||
111 | mail.setExtractedSubject("summary"); | ||
112 | mail.setMimeMessage("foobar"); | ||
113 | |||
114 | flatbuffers::FlatBufferBuilder metadataFbb; | ||
115 | auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); | ||
116 | metadataBuilder.add_revision(1); | ||
117 | auto metadataBuffer = metadataBuilder.Finish(); | ||
118 | Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); | ||
119 | |||
120 | flatbuffers::FlatBufferBuilder mailFbb; | ||
121 | auto pos = createBufferPart<Sink::ApplicationDomain::Buffer::MailBuilder, Sink::ApplicationDomain::Buffer::Mail>(mail, mailFbb, *writeMapper); | ||
122 | Sink::ApplicationDomain::Buffer::FinishMailBuffer(mailFbb, pos); | ||
123 | |||
124 | flatbuffers::FlatBufferBuilder fbb; | ||
125 | Sink::EntityBuffer::assembleEntityBuffer( | ||
126 | fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), mailFbb.GetBufferPointer(), mailFbb.GetSize(), mailFbb.GetBufferPointer(), mailFbb.GetSize()); | ||
127 | |||
128 | { | ||
129 | std::string data(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
130 | Sink::EntityBuffer buffer((void *)(data.data()), data.size()); | ||
131 | |||
132 | TestMailFactory factory; | ||
133 | auto adaptor = factory.createAdaptor(buffer.entity()); | ||
134 | Sink::ApplicationDomain::Mail readMail{QByteArray{}, QByteArray{}, 0, adaptor}; | ||
135 | QCOMPARE(readMail.getSubject(), mail.getSubject()); | ||
136 | QCOMPARE(readMail.getMimeMessage(), mail.getMimeMessage()); | ||
137 | } | ||
138 | |||
139 | } | ||
93 | }; | 140 | }; |
94 | 141 | ||
95 | QTEST_MAIN(DomainAdaptorTest) | 142 | QTEST_MAIN(DomainAdaptorTest) |