diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-06-27 20:57:31 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-06-27 20:57:31 +0200 |
commit | 06f996a139a5ac660e98163fac796f94c1a6468f (patch) | |
tree | f1eca6b33e045d8e58bf2f397bbc638a136eb7e8 /tests/domainadaptortest.cpp | |
parent | 0f888b18bf7e6eecc0a2aa5aaa015cf3b9c755be (diff) | |
download | sink-06f996a139a5ac660e98163fac796f94c1a6468f.tar.gz sink-06f996a139a5ac660e98163fac796f94c1a6468f.zip |
Ensure we can deal with non-null terminated strings.
Diffstat (limited to 'tests/domainadaptortest.cpp')
-rw-r--r-- | tests/domainadaptortest.cpp | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index df44819..2aed0a9 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp | |||
@@ -17,17 +17,19 @@ | |||
17 | class TestFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Event> | 17 | class TestFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Event> |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | TestFactory() | 20 | TestFactory() = default; |
21 | { | ||
22 | } | ||
23 | }; | 21 | }; |
24 | 22 | ||
25 | class TestMailFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Mail> | 23 | class TestMailFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Mail> |
26 | { | 24 | { |
27 | public: | 25 | public: |
28 | TestMailFactory() | 26 | TestMailFactory() = default; |
29 | { | 27 | }; |
30 | } | 28 | |
29 | class TestContactFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Contact> | ||
30 | { | ||
31 | public: | ||
32 | TestContactFactory() = default; | ||
31 | }; | 33 | }; |
32 | 34 | ||
33 | /** | 35 | /** |
@@ -135,6 +137,43 @@ private slots: | |||
135 | } | 137 | } |
136 | 138 | ||
137 | } | 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 | } | ||
138 | }; | 177 | }; |
139 | 178 | ||
140 | QTEST_MAIN(DomainAdaptorTest) | 179 | QTEST_MAIN(DomainAdaptorTest) |