diff options
-rw-r--r-- | common/contactpreprocessor.cpp | 3 | ||||
-rw-r--r-- | common/propertymapper.cpp | 16 | ||||
-rw-r--r-- | tests/domainadaptortest.cpp | 51 |
3 files changed, 55 insertions, 15 deletions
diff --git a/common/contactpreprocessor.cpp b/common/contactpreprocessor.cpp index 68a8acb..d331421 100644 --- a/common/contactpreprocessor.cpp +++ b/common/contactpreprocessor.cpp | |||
@@ -36,8 +36,7 @@ void updatedProperties(Sink::ApplicationDomain::Contact &contact, const KContact | |||
36 | } | 36 | } |
37 | contact.setEmails(emails); | 37 | contact.setEmails(emails); |
38 | 38 | ||
39 | const auto photo = addressee.photo().rawData(); | 39 | contact.setPhoto(addressee.photo().rawData()); |
40 | contact.setPhoto(photo); | ||
41 | } | 40 | } |
42 | 41 | ||
43 | ContactPropertyExtractor::~ContactPropertyExtractor() | 42 | ContactPropertyExtractor::~ContactPropertyExtractor() |
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index c14a62e..dbf93a3 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp | |||
@@ -58,7 +58,9 @@ template <> | |||
58 | flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | 58 | flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) |
59 | { | 59 | { |
60 | if (property.isValid()) { | 60 | if (property.isValid()) { |
61 | return fbb.CreateString(property.toByteArray().toStdString()).o; | 61 | const auto ba = property.toByteArray(); |
62 | const auto s = fbb.CreateString(ba.constData(), ba.size()); | ||
63 | return s.o; | ||
62 | } | 64 | } |
63 | return 0; | 65 | return 0; |
64 | } | 66 | } |
@@ -135,7 +137,7 @@ QString propertyToString(const flatbuffers::String *property) | |||
135 | { | 137 | { |
136 | if (property) { | 138 | if (property) { |
137 | // We have to copy the memory, otherwise it would become eventually invalid | 139 | // We have to copy the memory, otherwise it would become eventually invalid |
138 | return QString::fromStdString(property->c_str()); | 140 | return QString::fromStdString(property->str()); |
139 | } | 141 | } |
140 | return QString(); | 142 | return QString(); |
141 | } | 143 | } |
@@ -145,7 +147,7 @@ QVariant propertyToVariant<QString>(const flatbuffers::String *property) | |||
145 | { | 147 | { |
146 | if (property) { | 148 | if (property) { |
147 | // We have to copy the memory, otherwise it would become eventually invalid | 149 | // We have to copy the memory, otherwise it would become eventually invalid |
148 | return QString::fromStdString(property->c_str()); | 150 | return QString::fromStdString(property->str()); |
149 | } | 151 | } |
150 | return QVariant(); | 152 | return QVariant(); |
151 | } | 153 | } |
@@ -155,7 +157,7 @@ QVariant propertyToVariant<Sink::ApplicationDomain::BLOB>(const flatbuffers::Str | |||
155 | { | 157 | { |
156 | if (property) { | 158 | if (property) { |
157 | // We have to copy the memory, otherwise it would become eventually invalid | 159 | // We have to copy the memory, otherwise it would become eventually invalid |
158 | auto s = QString::fromStdString(property->c_str()); | 160 | auto s = QString::fromStdString(property->str()); |
159 | auto ext = s.endsWith(":ext"); | 161 | auto ext = s.endsWith(":ext"); |
160 | s.chop(4); | 162 | s.chop(4); |
161 | 163 | ||
@@ -171,7 +173,7 @@ QVariant propertyToVariant<Sink::ApplicationDomain::Reference>(const flatbuffers | |||
171 | { | 173 | { |
172 | if (property) { | 174 | if (property) { |
173 | // We have to copy the memory, otherwise it would become eventually invalid | 175 | // We have to copy the memory, otherwise it would become eventually invalid |
174 | return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->c_str()).toUtf8()}); | 176 | return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->str()).toUtf8()}); |
175 | } | 177 | } |
176 | return QVariant(); | 178 | return QVariant(); |
177 | } | 179 | } |
@@ -181,7 +183,7 @@ QVariant propertyToVariant<QByteArray>(const flatbuffers::String *property) | |||
181 | { | 183 | { |
182 | if (property) { | 184 | if (property) { |
183 | // We have to copy the memory, otherwise it would become eventually invalid | 185 | // We have to copy the memory, otherwise it would become eventually invalid |
184 | return QString::fromStdString(property->c_str()).toUtf8(); | 186 | return QByteArray(property->c_str(), property->Length()); |
185 | } | 187 | } |
186 | return QVariant(); | 188 | return QVariant(); |
187 | } | 189 | } |
@@ -203,7 +205,7 @@ QVariant propertyToVariant<QByteArrayList>(const flatbuffers::Vector<flatbuffers | |||
203 | QByteArrayList list; | 205 | QByteArrayList list; |
204 | for (auto it = property->begin(); it != property->end();) { | 206 | for (auto it = property->begin(); it != property->end();) { |
205 | // We have to copy the memory, otherwise it would become eventually invalid | 207 | // We have to copy the memory, otherwise it would become eventually invalid |
206 | list << QString::fromStdString((*it)->c_str()).toUtf8(); | 208 | list << QString::fromStdString((*it)->str()).toUtf8(); |
207 | it.operator++(); | 209 | it.operator++(); |
208 | } | 210 | } |
209 | return QVariant::fromValue(list); | 211 | return QVariant::fromValue(list); |
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) |