src/kolabconversions.h tests/bindingstest.cpp
Christian Mollekopf
mollekopf at kolabsys.com
Fri Jun 8 12:41:59 CEST 2012
src/kolabconversions.h | 77 +++++++++++++++++++++++++++++++++++++++++++++----
tests/bindingstest.cpp | 13 ++++++++
2 files changed, 84 insertions(+), 6 deletions(-)
New commits:
commit 37ad9789ddc54f8dc151555887dbc357421d542a
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Jun 8 12:41:51 2012 +0200
Note attachments.
diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index 6174f19..2c4e0dc 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -33,16 +33,66 @@
#include "kolabnote.h"
#include "shared_conversions.h"
#include "kolabconfiguration.h"
+#include "base64.h"
namespace Kolab {
namespace KolabObjects {
const char* const KOLAB_NAMESPACE = "http://kolab.org";
+const char* const BASE64 = "BASE64";
using namespace Kolab::Utils;
using namespace Kolab::Shared;
+Kolab::Attachment toAttachment(KolabXSD::attachmentPropType aProp)
+{
+ Kolab::Attachment a;
+ const KolabXSD::attachmentPropType ::parameters_type ¶meters = aProp.parameters();
+ std::string mimetype = parameters.fmttype();
+ if (parameters.encoding() && (*parameters.encoding() != BASE64)) {
+ ERROR("wrong encoding");
+ return Kolab::Attachment();
+ }
+ if (parameters.x_label()) {
+ a.setLabel(*parameters.x_label());
+ }
+ if (mimetype.empty()) {
+ ERROR("no mimetype");
+ }
+
+ if (aProp.uri()) {
+ a.setUri(*aProp.uri(), mimetype);
+ } else if (aProp.binary()) {
+ a.setData(base64_decode(*aProp.binary()), mimetype);
+ } else {
+ ERROR("not uri and no data available");
+ }
+ return a;
+}
+
+KolabXSD::attachmentPropType fromAttachment(const Kolab::Attachment &a)
+{
+ KolabXSD::attachmentPropType::parameters_type p(a.mimetype());
+ if (!a.label().empty()) {
+ p.x_label(a.label());
+ }
+ if (!a.data().empty()) {
+ p.encoding(BASE64);
+ }
+
+ KolabXSD::attachmentPropType attachment(p);
+ if (!a.uri().empty()) {
+ attachment.uri(a.uri());
+ } else if (!a.data().empty()) {
+ attachment.binary(base64_encode(reinterpret_cast<const unsigned char*>(a.data().c_str()), static_cast<unsigned int>(a.data().length())));
+ } else {
+ ERROR("no uri and no data");
+ }
+ return attachment;
+}
+
+
void writeColors(KolabXSD::Configuration::categorycolor_sequence &colors, const std::vector<CategoryColor> &input)
{
BOOST_FOREACH (const CategoryColor &entry, input) {
@@ -91,7 +141,6 @@ std::string serializeObject <Kolab::Configuration> (const Kolab::Configuration &
{
clearErrors();
try {
-
const std::string &uid = getUID(note.uid());
setCreatedUid(uid);
@@ -144,7 +193,6 @@ std::string serializeObject <Kolab::Note> (const Kolab::Note ¬e, const std::s
{
clearErrors();
try {
-
const std::string &uid = getUID(note.uid());
setCreatedUid(uid);
@@ -185,8 +233,13 @@ std::string serializeObject <Kolab::Note> (const Kolab::Note ¬e, const std::s
default:
ERROR("unknown classification");
}
- //TODO
-// n.attachment();
+
+ if (!note.attachments().empty()) {
+ const std::vector<Kolab::Attachment> &l = note.attachments();
+ BOOST_FOREACH(const Kolab::Attachment &a, l) {
+ n.attachment().push_back(fromAttachment(a));
+ }
+ }
n.summary(note.summary());
n.description(note.description());
n.color(note.color());
@@ -258,8 +311,20 @@ boost::shared_ptr<Kolab::Note> deserializeObject <Kolab::Note> (const std::strin
ERROR("unknown classification");
}
}
- //TODO
-// n->setAttachments();
+
+ if (!note->attachment().empty()) {
+ std::vector<Kolab::Attachment> attachments;
+ BOOST_FOREACH(KolabXSD::Note::attachment_type &aProp, note->attachment()) {
+ const Kolab::Attachment &a = toAttachment(aProp);
+ if (!a.isValid()) {
+ ERROR("invalid attachment");
+ continue;
+ }
+ attachments.push_back(a);
+ }
+ n->setAttachments(attachments);
+ }
+
if (note->summary()) {
n->setSummary(*note->summary());
}
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index 276b572..70e68ca 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -88,6 +88,18 @@ void BindingsTest::noteCompletness()
note.setSummary("summary");
note.setDescription("description");
note.setColor("color");
+
+ std::vector<Kolab::Attachment> attachments;
+ Kolab::Attachment attachment;
+ attachment.setData("data", "mimetype");
+ attachment.setLabel("label");
+ attachments.push_back(attachment);
+ Kolab::Attachment attachment2;
+ attachment2.setUri("data", "mimetype");
+ attachment2.setLabel("label2");
+ attachments.push_back(attachment2);
+ note.setAttachments(attachments);
+
const std::string &result = Kolab::writeNote(note);
QCOMPARE(Kolab::error(), Kolab::NoError);
// std::cout << result << std::endl;
@@ -102,6 +114,7 @@ void BindingsTest::noteCompletness()
QCOMPARE(re.summary(), note.summary());
QCOMPARE(re.description(), note.description());
QCOMPARE(re.color(), note.color());
+ QCOMPARE(re.attachments(), note.attachments());
}
More information about the commits
mailing list