conversion/kcalconversion.cpp tests/kcalconversiontest.cpp tests/testhelpers.h
Christian Mollekopf
mollekopf at kolabsys.com
Mon Jun 4 14:04:18 CEST 2012
conversion/kcalconversion.cpp | 22 +++++++++++++++++++---
tests/kcalconversiontest.cpp | 17 +++++++++++++++--
tests/testhelpers.h | 22 ++++++++++++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
New commits:
commit 692004f38cf7e62e2fd8680382ec8c3fc4314297
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Mon Jun 4 11:33:34 2012 +0200
kcalconversion custom properties
diff --git a/conversion/kcalconversion.cpp b/conversion/kcalconversion.cpp
index 9f703cd..cc40276 100644
--- a/conversion/kcalconversion.cpp
+++ b/conversion/kcalconversion.cpp
@@ -322,8 +322,18 @@ void setIncidence(KCalCore::Incidence &i, const T &e)
}
i.addAttachment(ptr);
}
-
-// i.setCustomProperties(); //TODO
+
+ QMap<QByteArray, QString> props;
+ foreach (const Kolab::CustomProperty &prop, e.customProperties()) {
+ QString key;
+ if (prop.identifier.compare(0, 5, "X-KDE")) {
+ key.append(QString::fromLatin1("X-KOLAB-"));
+ }
+ key.append(QString::fromStdString(prop.identifier));
+ props.insert(key.toLatin1(), QString::fromStdString(prop.value));
+// i.setCustomProperty("KOLAB", QString::fromStdString(prop.identifier).toLatin1(), QString::fromStdString(prop.value));
+ }
+ i.setCustomProperties(props);
}
template <typename T, typename I>
@@ -378,7 +388,13 @@ void getIncidence(T &i, const I &e)
}
i.setAttachments(attachments);
- //TODO custom properties
+ std::vector<Kolab::CustomProperty> customProperties;
+ const QMap<QByteArray, QString> &props = e.customProperties();
+ for (QMap<QByteArray, QString>::const_iterator it = props.begin(); it != props.end(); it++) {
+ QString key = QString(it.key());
+ customProperties.push_back(Kolab::CustomProperty(key.remove("X-KOLAB-").toStdString(), it.value().toStdString()));
+ }
+ i.setCustomProperties(customProperties);
}
int toWeekDay(Kolab::Weekday wday)
diff --git a/tests/kcalconversiontest.cpp b/tests/kcalconversiontest.cpp
index 086b66a..f0cb52e 100644
--- a/tests/kcalconversiontest.cpp
+++ b/tests/kcalconversiontest.cpp
@@ -177,7 +177,11 @@ void KCalConversionTest::testConversion_data()
alarm->setEmailAlarm("subject", "text", addressees, QStringList()); //No support for attachments
kcal.addAlarm(alarm);
//TODO alarms
- //TODO custom properties
+
+ kcal.setNonKDECustomProperty("X-KOLAB-key1", "value1");
+ kcal.setNonKDECustomProperty("X-KOLAB-key2", "value2");
+ kcal.setCustomProperty("SOMEOTHERAPP", "key2", "value2");
+ Q_ASSERT(kcal.customProperty("KOLAB", "key1") == "value1");
Kolab::Event kolab;
kolab.setUid("uid");
@@ -230,6 +234,14 @@ void KCalConversionTest::testConversion_data()
// Kolab::Alarm alarm2("summary", "description", receipents);
// kolab.setAlarms(std::vector<Kolab::Alarm>() << alarm2);
+ //The sorting is random, just sort them here how we think they should arrive so we don't have to sort during compare (due to lazyness).
+ std::vector<Kolab::CustomProperty> customproperties;
+ customproperties.push_back(Kolab::CustomProperty("X-KDE-SOMEOTHERAPP-key2", "value2"));
+ customproperties.push_back(Kolab::CustomProperty("key1", "value1"));
+ customproperties.push_back(Kolab::CustomProperty("key2", "value2"));
+
+ kolab.setCustomProperties(customproperties);
+
QTest::newRow( "with endDate and recurrence duration" ) << kcal << kolab;
}
{
@@ -318,7 +330,7 @@ void KCalConversionTest::testConversion()
comparePointerVectors(e->attachments(), kcal.attachments());
// QCOMPARE(e->alarms(), kcal.alarms()); //TODO
-//TODO custom properties
+ QCOMPARE(e->customProperties(), kcal.customProperties());
// QBENCHMARK {
// toKCalCore(kolab);
@@ -348,6 +360,7 @@ void KCalConversionTest::testConversion()
QCOMPARE(b.organizer(), kolab.organizer());
QCOMPARE(b.attendees(), kolab.attendees());
QCOMPARE(b.attachments(), kolab.attachments());
+ QCOMPARE(b.customProperties(), kolab.customProperties());
}
diff --git a/tests/testhelpers.h b/tests/testhelpers.h
index d425686..614ddd2 100644
--- a/tests/testhelpers.h
+++ b/tests/testhelpers.h
@@ -248,6 +248,28 @@ namespace QTest {
return qstrdup(ba.data());
}
+ template<>
+ char *toString(const Kolab::CustomProperty &a)
+ {
+ QByteArray ba = "Kolab::CustomProperty(";
+ ba += QString::fromStdString(a.identifier).toAscii()+ ", ";
+ ba += QString::fromStdString(a.value).toAscii();
+ ba += ")";
+ return qstrdup(ba.data());
+ }
+
+ template<>
+ char *toString(const std::vector<Kolab::CustomProperty> &v)
+ {
+ QByteArray ba = "vector<Kolab::CustomProperty>(";
+ for (int i = 0; i < v.size(); i++) {
+ ba += QByteArray(toString(v.at(i)))+ "\n";
+ }
+ ba += ")";
+ return qstrdup(ba.data());
+ }
+
+
}
More information about the commits
mailing list