diff options
Diffstat (limited to 'tests/domainadaptortest.cpp')
-rw-r--r-- | tests/domainadaptortest.cpp | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index a17152e..2aed0a9 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp | |||
@@ -14,24 +14,22 @@ | |||
14 | #include "metadata_generated.h" | 14 | #include "metadata_generated.h" |
15 | #include "entity_generated.h" | 15 | #include "entity_generated.h" |
16 | 16 | ||
17 | class TestFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Event, Sink::ApplicationDomain::Buffer::Event, Sink::ApplicationDomain::Buffer::EventBuilder> | 17 | class TestFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Event> |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | TestFactory() | 20 | TestFactory() = default; |
21 | { | ||
22 | mResourceWriteMapper = QSharedPointer<WritePropertyMapper<Sink::ApplicationDomain::Buffer::EventBuilder>>::create(); | ||
23 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Event>::configure(*mResourceWriteMapper); | ||
24 | } | ||
25 | }; | 21 | }; |
26 | 22 | ||
27 | class TestMailFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Mail, Sink::ApplicationDomain::Buffer::Mail, Sink::ApplicationDomain::Buffer::MailBuilder> | 23 | class TestMailFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Mail> |
28 | { | 24 | { |
29 | public: | 25 | public: |
30 | TestMailFactory() | 26 | TestMailFactory() = default; |
31 | { | 27 | }; |
32 | mResourceWriteMapper = QSharedPointer<WritePropertyMapper<Sink::ApplicationDomain::Buffer::MailBuilder>>::create(); | 28 | |
33 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Mail>::configure(*mResourceWriteMapper); | 29 | class TestContactFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Contact> |
34 | } | 30 | { |
31 | public: | ||
32 | TestContactFactory() = default; | ||
35 | }; | 33 | }; |
36 | 34 | ||
37 | /** | 35 | /** |
@@ -51,7 +49,7 @@ private slots: | |||
51 | 49 | ||
52 | void testCreateBufferPart() | 50 | void testCreateBufferPart() |
53 | { | 51 | { |
54 | auto writeMapper = QSharedPointer<WritePropertyMapper<Sink::ApplicationDomain::Buffer::EventBuilder>>::create(); | 52 | auto writeMapper = QSharedPointer<PropertyMapper>::create(); |
55 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Event>::configure(*writeMapper); | 53 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Event>::configure(*writeMapper); |
56 | 54 | ||
57 | Sink::ApplicationDomain::Event event; | 55 | Sink::ApplicationDomain::Event event; |
@@ -104,7 +102,7 @@ private slots: | |||
104 | 102 | ||
105 | void testMail() | 103 | void testMail() |
106 | { | 104 | { |
107 | auto writeMapper = QSharedPointer<WritePropertyMapper<Sink::ApplicationDomain::Buffer::MailBuilder>>::create(); | 105 | auto writeMapper = QSharedPointer<PropertyMapper>::create(); |
108 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Mail>::configure(*writeMapper); | 106 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Mail>::configure(*writeMapper); |
109 | 107 | ||
110 | Sink::ApplicationDomain::Mail mail; | 108 | Sink::ApplicationDomain::Mail mail; |
@@ -139,6 +137,43 @@ private slots: | |||
139 | } | 137 | } |
140 | 138 | ||
141 | } | 139 | } |
140 | |||
141 | void testContact() | ||
142 | { | ||
143 | auto writeMapper = QSharedPointer<PropertyMapper>::create(); | ||
144 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Contact>::configure(*writeMapper); | ||
145 | |||
146 | auto binaryData = QByteArray::fromRawData("\xEF\xBF\xBD\x00\xEF\xBF", 5); | ||
147 | |||
148 | Sink::ApplicationDomain::Contact contact; | ||
149 | contact.setPhoto(binaryData); | ||
150 | QVERIFY(!contact.getPhoto().isEmpty()); | ||
151 | |||
152 | flatbuffers::FlatBufferBuilder metadataFbb; | ||
153 | auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); | ||
154 | metadataBuilder.add_revision(1); | ||
155 | auto metadataBuffer = metadataBuilder.Finish(); | ||
156 | Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); | ||
157 | |||
158 | flatbuffers::FlatBufferBuilder mailFbb; | ||
159 | auto pos = createBufferPart<Sink::ApplicationDomain::Buffer::ContactBuilder, Sink::ApplicationDomain::Buffer::Contact>(contact, mailFbb, *writeMapper); | ||
160 | Sink::ApplicationDomain::Buffer::FinishContactBuffer(mailFbb, pos); | ||
161 | |||
162 | flatbuffers::FlatBufferBuilder fbb; | ||
163 | Sink::EntityBuffer::assembleEntityBuffer( | ||
164 | fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), mailFbb.GetBufferPointer(), mailFbb.GetSize(), mailFbb.GetBufferPointer(), mailFbb.GetSize()); | ||
165 | |||
166 | { | ||
167 | std::string data(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
168 | Sink::EntityBuffer buffer((void *)(data.data()), data.size()); | ||
169 | |||
170 | TestContactFactory factory; | ||
171 | auto adaptor = factory.createAdaptor(buffer.entity()); | ||
172 | Sink::ApplicationDomain::Contact readContact{QByteArray{}, QByteArray{}, 0, adaptor}; | ||
173 | QCOMPARE(readContact.getPhoto(), contact.getPhoto()); | ||
174 | } | ||
175 | |||
176 | } | ||
142 | }; | 177 | }; |
143 | 178 | ||
144 | QTEST_MAIN(DomainAdaptorTest) | 179 | QTEST_MAIN(DomainAdaptorTest) |