From 06f996a139a5ac660e98163fac796f94c1a6468f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 27 Jun 2017 20:57:31 +0200 Subject: Ensure we can deal with non-null terminated strings. --- tests/domainadaptortest.cpp | 51 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) (limited to 'tests') 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 @@ class TestFactory : public DomainTypeAdaptorFactory { public: - TestFactory() - { - } + TestFactory() = default; }; class TestMailFactory : public DomainTypeAdaptorFactory { public: - TestMailFactory() - { - } + TestMailFactory() = default; +}; + +class TestContactFactory : public DomainTypeAdaptorFactory +{ +public: + TestContactFactory() = default; }; /** @@ -135,6 +137,43 @@ private slots: } } + + void testContact() + { + auto writeMapper = QSharedPointer::create(); + Sink::ApplicationDomain::TypeImplementation::configure(*writeMapper); + + auto binaryData = QByteArray::fromRawData("\xEF\xBF\xBD\x00\xEF\xBF", 5); + + Sink::ApplicationDomain::Contact contact; + contact.setPhoto(binaryData); + QVERIFY(!contact.getPhoto().isEmpty()); + + 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(contact, mailFbb, *writeMapper); + Sink::ApplicationDomain::Buffer::FinishContactBuffer(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()); + + TestContactFactory factory; + auto adaptor = factory.createAdaptor(buffer.entity()); + Sink::ApplicationDomain::Contact readContact{QByteArray{}, QByteArray{}, 0, adaptor}; + QCOMPARE(readContact.getPhoto(), contact.getPhoto()); + } + + } }; QTEST_MAIN(DomainAdaptorTest) -- cgit v1.2.3