conversion/kcalconversion.cpp kolabformat/kolabobject.cpp kolabformatV2/incidence.cpp mime/mimeutils.cpp tests/CMakeLists.txt tests/kolabobjecttest.cpp tests/kolabobjecttest.h tests/preservationtest.cpp tests/preservationtest.h
Christian Mollekopf
mollekopf at kolabsys.com
Mon Aug 13 12:15:00 CEST 2012
conversion/kcalconversion.cpp | 2
kolabformat/kolabobject.cpp | 20 +++++++++
kolabformatV2/incidence.cpp | 6 +-
mime/mimeutils.cpp | 5 ++
tests/CMakeLists.txt | 2
tests/kolabobjecttest.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++
tests/kolabobjecttest.h | 32 +++++++++++++++
tests/preservationtest.cpp | 59 ----------------------------
tests/preservationtest.h | 30 --------------
9 files changed, 151 insertions(+), 93 deletions(-)
New commits:
commit e77273b73381f722d06b0a870264251f4e620d70
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Mon Aug 13 12:14:43 2012 +0200
Don't crash when invalid pointers are being passed in + tests. BUG 904
diff --git a/conversion/kcalconversion.cpp b/conversion/kcalconversion.cpp
index cc40276..4ab8cf5 100644
--- a/conversion/kcalconversion.cpp
+++ b/conversion/kcalconversion.cpp
@@ -701,7 +701,7 @@ void getTodoEvent(T &i, const I &e)
{
i.setPriority(fromPriority(e.priority()));
i.setLocation(e.location().toStdString());
- if (!e.organizer()->email().isEmpty()) {
+ if (e.organizer() && !e.organizer()->email().isEmpty()) {
i.setOrganizer(Kolab::ContactReference(Kolab::ContactReference::EmailReference, e.organizer()->email().toStdString(), e.organizer()->name().toStdString())); //TODO handle uid too
}
i.setRecurrenceID(fromDate(e.recurrenceId()), false); //TODO THISANDFUTURE
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index 4ead6e7..4b835de 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -465,6 +465,10 @@ QString getProductId(const QString &pId)
KMime::Message::Ptr KolabObjectWriter::writeEvent(const KCalCore::Event::Ptr &i, Version v, const QString &productId, const QString &tz)
{
ErrorHandler::clearErrors();
+ if (!i) {
+ Critical() << "passed a null pointer";
+ return KMime::Message::Ptr();
+ }
Q_ASSERT(!i.isNull());
if (v == KolabV3) {
KCalCore::Event::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Event>();
@@ -480,6 +484,10 @@ KMime::Message::Ptr KolabObjectWriter::writeEvent(const KCalCore::Event::Ptr &i,
KMime::Message::Ptr KolabObjectWriter::writeTodo(const KCalCore::Todo::Ptr &i, Version v, const QString &productId, const QString &tz)
{
ErrorHandler::clearErrors();
+ if (!i) {
+ Critical() << "passed a null pointer";
+ return KMime::Message::Ptr();
+ }
Q_ASSERT(!i.isNull());
if (v == KolabV3) {
KCalCore::Todo::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Todo>();
@@ -495,6 +503,10 @@ KMime::Message::Ptr KolabObjectWriter::writeTodo(const KCalCore::Todo::Ptr &i, V
KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr &i, Version v, const QString &productId, const QString &tz)
{
ErrorHandler::clearErrors();
+ if (!i) {
+ Critical() << "passed a null pointer";
+ return KMime::Message::Ptr();
+ }
Q_ASSERT(!i.isNull());
if (v == KolabV3) {
KCalCore::Journal::Ptr ic = normalizeIncidence(i).dynamicCast<KCalCore::Journal>();
@@ -509,6 +521,10 @@ KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr
KMime::Message::Ptr KolabObjectWriter::writeIncidence(const KCalCore::Incidence::Ptr &i, Version v, const QString& productId, const QString& tz)
{
+ if (!i) {
+ Critical() << "passed a null pointer";
+ return KMime::Message::Ptr();
+ }
switch (i->type()) {
case KCalCore::IncidenceBase::TypeEvent:
return writeEvent(i.dynamicCast<KCalCore::Event>(),v,productId,tz);
@@ -552,6 +568,10 @@ KMime::Message::Ptr KolabObjectWriter::writeDistlist(const KABC::ContactGroup &d
KMime::Message::Ptr KolabObjectWriter::writeNote(const KMime::Message::Ptr ¬e, Version v, const QString &productId)
{
ErrorHandler::clearErrors();
+ if (!note) {
+ Critical() << "passed a null pointer";
+ return KMime::Message::Ptr();
+ }
Q_ASSERT(note.get());
if (v == KolabV3) {
const Kolab::Note &n = Kolab::Conversion::fromNote(note);
diff --git a/kolabformatV2/incidence.cpp b/kolabformatV2/incidence.cpp
index 4ac7a3e..f627334 100644
--- a/kolabformatV2/incidence.cpp
+++ b/kolabformatV2/incidence.cpp
@@ -772,8 +772,10 @@ void Incidence::setFields( const KCalCore::Incidence::Ptr &incidence )
}
}
- Email org( incidence->organizer()->name(), incidence->organizer()->email() );
- setOrganizer( org );
+ if (incidence->organizer()) {
+ Email org( incidence->organizer()->name(), incidence->organizer()->email() );
+ setOrganizer( org );
+ }
// Attendees:
KCalCore::Attendee::List attendees = incidence->attendees();
diff --git a/mime/mimeutils.cpp b/mime/mimeutils.cpp
index 9784f50..d00e305 100644
--- a/mime/mimeutils.cpp
+++ b/mime/mimeutils.cpp
@@ -94,6 +94,11 @@ QString fromCid(const QString &cid)
KMime::Message::Ptr createMessage(const KCalCore::Incidence::Ptr &incidencePtr, const QString &mimetype, const QString &xKolabType, const QByteArray &xml, bool v3, const QString &productId)
{
KMime::Message::Ptr message = createMessage( xKolabType, v3, productId );
+ if (!incidencePtr) {
+ Error() << "invalid incidence passed in";
+ message->assemble();
+ return message;
+ }
if ( incidencePtr->organizer() && !incidencePtr->organizer()->email().isEmpty()) {
message->from()->addAddress( incidencePtr->organizer()->email().toUtf8(), incidencePtr->organizer()->name() );
}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3cf0803..7362351 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -19,4 +19,4 @@ addTest(kcalconversiontest)
addTest(calendaringtest)
addTest(icalendartest)
addTest(freebusytest)
-addTest(preservationtest)
+addTest(kolabobjecttest)
diff --git a/tests/kolabobjecttest.cpp b/tests/kolabobjecttest.cpp
new file mode 100644
index 0000000..19d7de7
--- /dev/null
+++ b/tests/kolabobjecttest.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf 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 "kolabobjecttest.h"
+
+#include <QTest>
+
+#include "kolabformat/kolabobject.h"
+#include <kdebug.h>
+#include <kolab/errorhandler.h>
+
+void KolabObjectTest::preserveLatin1()
+{
+ KCalCore::Event::Ptr event(new KCalCore::Event());
+ QString summary("äöü%@$£é¤¼²°");
+ event->setSummary(summary);
+ QCOMPARE(event->summary(), summary);
+ //std::cout << event->summary().toStdString() << std::endl;
+ KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event);
+// kDebug() << msg->encodedContent();
+ KCalCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent();
+ QVERIFY(readEvent);
+// std::cout << readEvent->summary().toStdString() << std::endl;
+ QCOMPARE(readEvent->summary(), summary);
+}
+
+void KolabObjectTest::preserveUnicode()
+{
+ KCalCore::Event::Ptr event(new KCalCore::Event());
+ QString summary("â¬Å �ÙأبÙâº");
+ event->setSummary(summary);
+ QCOMPARE(event->summary(), summary);
+// std::cout << event->summary().toStdString() << std::endl;
+ KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event);
+// kDebug() << msg->encodedContent();
+ KCalCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent();
+ QVERIFY(readEvent);
+// std::cout << readEvent->summary().toStdString() << std::endl;
+ QCOMPARE(readEvent->summary(), summary);
+}
+
+void KolabObjectTest::dontCrashWithEmptyOrganizer()
+{
+ KCalCore::Event::Ptr event(new KCalCore::Event());
+ event->setOrganizer(KCalCore::Person::Ptr());
+ event->setDtStart(KDateTime(QDate(2012,11,11)));
+ Kolab::KolabObjectWriter::writeEvent(event, Kolab::KolabV2);
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
+ Kolab::KolabObjectWriter::writeEvent(event);
+ qDebug() << Kolab::ErrorHandler::instance().error();
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
+}
+
+
+void KolabObjectTest::dontCrashWithEmptyIncidence()
+{
+ Kolab::KolabObjectWriter::writeEvent(KCalCore::Event::Ptr());
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
+ Kolab::KolabObjectWriter::writeTodo(KCalCore::Todo::Ptr());
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
+ Kolab::KolabObjectWriter::writeJournal(KCalCore::Journal::Ptr());
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
+ Kolab::KolabObjectWriter::writeIncidence(KCalCore::Event::Ptr());
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
+ Kolab::KolabObjectWriter::writeNote(KMime::Message::Ptr());
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
+}
+
+
+
+
+QTEST_MAIN( KolabObjectTest )
+
+#include "kolabobjecttest.moc"
diff --git a/tests/kolabobjecttest.h b/tests/kolabobjecttest.h
new file mode 100644
index 0000000..9e0b760
--- /dev/null
+++ b/tests/kolabobjecttest.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf 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 KOLABOBJECTTEST_H
+#define KOLABOBJECTTEST_H
+#include <QObject>
+
+class KolabObjectTest: public QObject
+{
+ Q_OBJECT
+private slots:
+ void preserveLatin1();
+ void preserveUnicode();
+ void dontCrashWithEmptyOrganizer();
+ void dontCrashWithEmptyIncidence();
+};
+
+#endif // KOLABOBJECTTEST_H
diff --git a/tests/preservationtest.cpp b/tests/preservationtest.cpp
deleted file mode 100644
index 7b131f9..0000000
--- a/tests/preservationtest.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2012 Christian Mollekopf <mollekopf 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 "preservationtest.h"
-
-#include <QTest>
-
-#include "kolabformat/kolabobject.h"
-#include <kdebug.h>
-
-void PreservationTest::preserveLatin1()
-{
- KCalCore::Event::Ptr event(new KCalCore::Event());
- QString summary("äöü%@$£é¤¼²°");
- event->setSummary(summary);
- QCOMPARE(event->summary(), summary);
- //std::cout << event->summary().toStdString() << std::endl;
- KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event);
-// kDebug() << msg->encodedContent();
- KCalCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent();
- QVERIFY(readEvent);
-// std::cout << readEvent->summary().toStdString() << std::endl;
- QCOMPARE(readEvent->summary(), summary);
-}
-
-void PreservationTest::preserveUnicode()
-{
- KCalCore::Event::Ptr event(new KCalCore::Event());
- QString summary("â¬Å �ÙأبÙâº");
- event->setSummary(summary);
- QCOMPARE(event->summary(), summary);
-// std::cout << event->summary().toStdString() << std::endl;
- KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event);
-// kDebug() << msg->encodedContent();
- KCalCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent();
- QVERIFY(readEvent);
-// std::cout << readEvent->summary().toStdString() << std::endl;
- QCOMPARE(readEvent->summary(), summary);
-}
-
-
-
-QTEST_MAIN( PreservationTest )
-
-#include "preservationtest.moc"
diff --git a/tests/preservationtest.h b/tests/preservationtest.h
deleted file mode 100644
index 3eefb0a..0000000
--- a/tests/preservationtest.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2012 Christian Mollekopf <mollekopf 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 PRESERVATIONTEST_H
-#define PRESERVATIONTEST_H
-#include <QObject>
-
-class PreservationTest: public QObject
-{
- Q_OBJECT
-private slots:
- void preserveLatin1();
- void preserveUnicode();
-};
-
-#endif // PRESERVATIONTEST_H
More information about the commits
mailing list