Branch 'mimeobject' - kolabformat/mimeobject.cpp kolabformat/mimeobject.h tests/mimeobjecttest.cpp tests/mimeobjecttest.h utils/kolabformatchecker.cpp
Sofia Balicka
balicka at kolabsys.com
Mon Dec 17 23:11:52 CET 2012
kolabformat/mimeobject.cpp | 151 +++++++++++++++++++++++++++++++++++++++----
kolabformat/mimeobject.h | 36 +++++++++-
tests/mimeobjecttest.cpp | 136 +++++++++++++++++++++++++++++++++++---
tests/mimeobjecttest.h | 25 ++++++-
utils/kolabformatchecker.cpp | 17 ++++
5 files changed, 335 insertions(+), 30 deletions(-)
New commits:
commit 6e518f0363f3733ce7f49bfb9af5bc2e0e018a49
Author: Sofia Balicka <balicka at kolabsys.com>
Date: Mon Dec 17 23:10:56 2012 +0100
Compleated mimeobject and wrote testcases
diff --git a/kolabformat/mimeobject.cpp b/kolabformat/mimeobject.cpp
index 681d40b..559cf75 100644
--- a/kolabformat/mimeobject.cpp
+++ b/kolabformat/mimeobject.cpp
@@ -1,8 +1,26 @@
+/*
+ * Copyright (C) 2012 Sofia Balicka <balicka at kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include "mimeobject.h"
#include "conversion/kcalconversion.h"
+#include "conversion/kolabconversion.h"
+#include "conversion/kabcconversion.h"
#include "kolabformat/kolabobject.h"
#include <QString>
-#include <iostream>
namespace Kolab
{
@@ -12,28 +30,133 @@ MIMEObject::MIMEObject()
}
-Event MIMEObject::readEvent(const std::string &s)
+std::string MIMEObject::writeEvent(const Event &event, Version version, const std::string &productId)
{
- KMime::Message::Ptr msg(new KMime::Message);
- msg->setContent(QByteArray(s.c_str()));
- msg->parse();
-
- KCalCore::Event::Ptr event = KolabObjectReader(msg).getEvent();
-
- return Conversion::fromKCalCore(*event);
+ KCalCore::Event::Ptr KEvent = Conversion::toKCalCore(event);
+
+ KMime::Message::Ptr msg = KolabObjectWriter().writeEvent(KEvent, version, QString::fromStdString(productId));
+ msg->assemble();
+
+ return msg->encodedContent().data();
}
-std::string MIMEObject::writeEvent(const Event &event, Version version, const std::string &productId)
+Event MIMEObject::readEvent(const std::string &s)
{
- KCalCore::Event::Ptr KEvent = Conversion::toKCalCore(event);
+ KMime::Message::Ptr msg(new KMime::Message);
+ msg->setContent(QByteArray(s.c_str()));
+ msg->parse();
+
+ KCalCore::Event::Ptr event = KolabObjectReader(msg).getEvent();
+
+ return Conversion::fromKCalCore(*event);
+}
+
+std::string MIMEObject::writeTodo(const Todo &todo, Version version, const std::string &productId){
+ KCalCore::Todo::Ptr kTodo = Conversion::toKCalCore(todo);
- KMime::Message::Ptr msg = KolabObjectWriter().writeEvent(KEvent, version, QString::fromStdString(productId));
- msg->assemble();
+ KMime::Message::Ptr msg = KolabObjectWriter().writeTodo(kTodo, version, QString::fromStdString(productId));
+ msg->assemble();
- return msg->encodedContent().data();
+ return msg->encodedContent().data();
}
+
+Todo MIMEObject::readTodo(const std::string &s){
+
+ KMime::Message::Ptr msg(new KMime::Message);
+ msg->setContent(QByteArray(s.c_str()));
+ msg->parse();
+
+ KCalCore::Todo::Ptr todo = KolabObjectReader(msg).getTodo();
+
+ return Conversion::fromKCalCore(*todo);
+}
+
+
+std::string MIMEObject::writeJournal(const Journal &journal, Version version, const std::string &productId){
+ KCalCore::Journal::Ptr kJournal = Conversion::toKCalCore(journal);
+
+ KMime::Message::Ptr msg = KolabObjectWriter().writeJournal(kJournal, version, QString::fromStdString(productId));
+ msg->assemble();
+
+ return msg->encodedContent().data();
+}
+
+
+Journal MIMEObject::readJournal(const std::string &s){
+
+ KMime::Message::Ptr msg(new KMime::Message);
+ msg->setContent(QByteArray(s.c_str()));
+ msg->parse();
+
+ KCalCore::Journal::Ptr journal = KolabObjectReader(msg).getJournal();
+
+ return Conversion::fromKCalCore(*journal);
+}
+
+std::string MIMEObject::writeNote(const Note ¬e, Version version, const std::string &productId){
+ KMime::Message::Ptr kNote = Conversion::toNote(note);
+
+ KMime::Message::Ptr msg = KolabObjectWriter().writeNote(kNote, version, QString::fromStdString(productId));
+ msg->assemble();
+
+ return msg->encodedContent().data();
+}
+
+
+Note MIMEObject::readNote(const std::string &s){
+
+ KMime::Message::Ptr msg(new KMime::Message);
+ msg->setContent(QByteArray(s.c_str()));
+ msg->parse();
+
+ KMime::Message::Ptr note = KolabObjectReader(msg).getNote();
+
+ return Conversion::fromNote(note);
+}
+
+std::string MIMEObject::writeContact(const Contact &contact, Version version, const std::string &productId){
+ KABC::Addressee kContact = Conversion::toKABC(contact);
+
+ KMime::Message::Ptr msg = KolabObjectWriter().writeContact(kContact, version, QString::fromStdString(productId));
+ msg->assemble();
+
+ return msg->encodedContent().data();
+}
+
+
+Contact MIMEObject::readContact(const std::string &s){
+
+ KMime::Message::Ptr msg(new KMime::Message);
+ msg->setContent(QByteArray(s.c_str()));
+ msg->parse();
+
+ KABC::Addressee contact = KolabObjectReader(msg).getContact();
+
+ return Conversion::fromKABC(contact);
+}
+
+std::string MIMEObject::writeDistlist(const DistList &distlist, Version version, const std::string &productId){
+ KABC::ContactGroup kDistlist = Conversion::toKABC(distlist);
+
+ KMime::Message::Ptr msg = KolabObjectWriter().writeDistlist(kDistlist, version, QString::fromStdString(productId));
+ msg->assemble();
+
+ return msg->encodedContent().data();
+}
+
+
+DistList MIMEObject::readDistlist(const std::string &s){
+
+ KMime::Message::Ptr msg(new KMime::Message);
+ msg->setContent(QByteArray(s.c_str()));
+ msg->parse();
+
+ KABC::ContactGroup distlist = KolabObjectReader(msg).getDistlist();
+
+ return Conversion::fromKABC(distlist);
+}
}
diff --git a/kolabformat/mimeobject.h b/kolabformat/mimeobject.h
index ac4bd97..612f057 100644
--- a/kolabformat/mimeobject.h
+++ b/kolabformat/mimeobject.h
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2012 Sofia Balicka <balicka at kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef MIMEOBJECT_H
#define MIMEOBJECT_H
@@ -20,8 +37,25 @@ class KOLAB_EXPORT MIMEObject
public:
explicit MIMEObject();
+ std::string writeEvent(const Event &event, Version version, const std::string &productId = std::string());
Kolab::Event readEvent(const std::string &s);
- std::string writeEvent(const Kolab::Event &event, Version version, const std::string& productId = std::string());
+
+ std::string writeTodo(const Todo &todo, Version version, const std::string &productId = std::string());
+ Todo readTodo(const std::string &s);
+
+ std::string writeJournal(const Journal &journal, Version version, const std::string &productId = std::string());
+ Journal readJournal(const std::string &s);
+
+ std::string writeNote(const Note ¬e, Version version, const std::string &productId = std::string());
+ Note readNote(const std::string &s);
+
+ std::string writeContact(const Contact &contact, Version version, const std::string &productId = std::string());
+ Contact readContact(const std::string &s);
+
+ std::string writeDistlist(const DistList &distlist, Version version, const std::string &productId = std::string());
+ DistList readDistlist(const std::string &s);
+
+
};
}
#endif
diff --git a/tests/mimeobjecttest.cpp b/tests/mimeobjecttest.cpp
index 5aff4bb..0d5d42a 100644
--- a/tests/mimeobjecttest.cpp
+++ b/tests/mimeobjecttest.cpp
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2012 Sofia Balicka <balicka at kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include <QTest>
#include "mimeobjecttest.h"
#include "kolabformat/kolabobject.h"
@@ -9,24 +26,117 @@
void MIMEObjectTest::testEvent(){
- Kolab::MIMEObject mimeobject;
+ Kolab::MIMEObject mimeobject;
- std::ifstream t((TESTFILEDIR.toStdString()+"v3/event/simple.ics.mime").c_str());
- std::stringstream buffer;
- buffer << t.rdbuf();
+ std::ifstream t((TESTFILEDIR.toStdString()+"v3/event/simple.ics.mime").c_str());
+ std::stringstream buffer;
+ buffer << t.rdbuf();
Kolab::Event event = mimeobject.readEvent(buffer.str());
-
- std::string message = mimeobject.writeEvent(event, Kolab::KolabV3);
-
- QString qMessage = QString::fromStdString(message);
- QString input = QString::fromStdString(buffer.str());
-
- normalizeMimemessage(qMessage);
- normalizeMimemessage(input);
- QCOMPARE(input, qMessage);
+
+ std::string message = mimeobject.writeEvent(event, Kolab::KolabV3);
+
+ QString qMessage = QString::fromStdString(message);
+ QString input = QString::fromStdString(buffer.str());
+
+ normalizeMimemessage(qMessage);
+ normalizeMimemessage(input);
+
+ QCOMPARE(input.simplified(), qMessage.simplified());
+}
+/*
+void MIMEObjectTest::testTodo(){
+
+}
+*/
+
+void MIMEObjectTest::testJournal(){
+
+ Kolab::MIMEObject mimeobject;
+
+ std::ifstream t((TESTFILEDIR.toStdString()+"v3/journal/simple.ics.mime").c_str());
+ std::stringstream buffer;
+ buffer << t.rdbuf();
+
+ Kolab::Journal journal = mimeobject.readJournal(buffer.str());
+
+ std::string message = mimeobject.writeJournal(journal, Kolab::KolabV3);
+
+ QString qMessage = QString::fromStdString(message);
+ QString input = QString::fromStdString(buffer.str());
+
+ normalizeMimemessage(qMessage);
+ normalizeMimemessage(input);
+
+ QCOMPARE(input.simplified(), qMessage.simplified());
+
}
+void MIMEObjectTest::testNote(){
+
+ Kolab::MIMEObject mimeobject;
+
+ std::ifstream t((TESTFILEDIR.toStdString()+"v3/note/note.mime.mime").c_str());
+ std::stringstream buffer;
+ buffer << t.rdbuf();
+
+ Kolab::Note note = mimeobject.readNote(buffer.str());
+
+ std::string message = mimeobject.writeNote(note, Kolab::KolabV3);
+
+ QString qMessage = QString::fromStdString(message);
+ QString input = QString::fromStdString(buffer.str());
+
+ normalizeMimemessage(qMessage);
+ normalizeMimemessage(input);
+
+ QCOMPARE(input.simplified(), qMessage.simplified());
+
+}
+
+void MIMEObjectTest::testContact(){
+
+ Kolab::MIMEObject mimeobject;
+
+ std::ifstream t((TESTFILEDIR.toStdString()+"v3/contacts/simple.vcf.mime").c_str());
+ std::stringstream buffer;
+ buffer << t.rdbuf();
+
+ Kolab::Contact contact = mimeobject.readContact(buffer.str());
+
+ std::string message = mimeobject.writeContact(contact, Kolab::KolabV3);
+
+ QString qMessage = QString::fromStdString(message);
+ QString input = QString::fromStdString(buffer.str());
+
+ normalizeMimemessage(qMessage);
+ normalizeMimemessage(input);
+
+ QCOMPARE(input.simplified(), qMessage.simplified());
+
+}
+
+void MIMEObjectTest::testDistlist(){
+
+ Kolab::MIMEObject mimeobject;
+
+ std::ifstream t((TESTFILEDIR.toStdString()+"v3/contacts/distlist.vcf.mime").c_str());
+ std::stringstream buffer;
+ buffer << t.rdbuf();
+
+ Kolab::DistList distlist = mimeobject.readDistlist(buffer.str());
+
+ std::string message = mimeobject.writeDistlist(distlist, Kolab::KolabV3);
+
+ QString qMessage = QString::fromStdString(message);
+ QString input = QString::fromStdString(buffer.str());
+
+ normalizeMimemessage(qMessage);
+ normalizeMimemessage(input);
+
+ QCOMPARE(input.simplified(), qMessage.simplified());
+
+}
QTEST_MAIN( MIMEObjectTest )
#include "mimeobjecttest.moc"
diff --git a/tests/mimeobjecttest.h b/tests/mimeobjecttest.h
index 74619b9..badb4c5 100644
--- a/tests/mimeobjecttest.h
+++ b/tests/mimeobjecttest.h
@@ -1,13 +1,34 @@
+/*
+ * Copyright (C) 2012 Sofia Balicka <balicka at kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef MIMEOBJECTTEST_H
#define MIMEOBJECTTEST_H
#include <QObject>
class MIMEObjectTest: public QObject
{
- Q_OBJECT
+ Q_OBJECT
private slots:
- void testEvent();
+ void testEvent();
+ void testJournal();
+ void testNote();
+ void testContact();
+ void testDistlist();
};
#endif // MIMEOBJECTTEST_H
diff --git a/utils/kolabformatchecker.cpp b/utils/kolabformatchecker.cpp
index cfca944..aeee18c 100644
--- a/utils/kolabformatchecker.cpp
+++ b/utils/kolabformatchecker.cpp
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2012 Sofia Balicka <balicka at kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include <boost/program_options.hpp>
#include <iostream>
#include <string>
More information about the commits
mailing list