4 commits - kolabformat/kolabobject.cpp mime/mimeutils.cpp tests/CMakeLists.txt tests/formattest.cpp tests/kcalconversiontest.cpp tests/preservationtest.cpp tests/preservationtest.h tests/testutils.h

Christian Mollekopf mollekopf at kolabsys.com
Fri Aug 10 01:32:32 CEST 2012


 kolabformat/kolabobject.cpp  |   26 +++++++++---------
 mime/mimeutils.cpp           |    2 -
 tests/CMakeLists.txt         |   43 ++++++++++---------------------
 tests/formattest.cpp         |    3 ++
 tests/kcalconversiontest.cpp |   18 +++++++++++++
 tests/preservationtest.cpp   |   59 +++++++++++++++++++++++++++++++++++++++++++
 tests/preservationtest.h     |   30 +++++++++++++++++++++
 tests/testutils.h            |    4 ++
 8 files changed, 142 insertions(+), 43 deletions(-)

New commits:
commit 10f747a77e2dc05eae226467f1045bdf328d65a3
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Fri Aug 10 01:32:20 2012 +0200

    fixed addTest macro

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index bf9e9f4..3cf0803 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -3,7 +3,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
 add_definitions(-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
 
 macro(addTest TEST_NAME)
-    QT4_AUTOMOC(${TEST_Name}.cpp)
+    QT4_AUTOMOC(${TEST_NAME}.cpp)
     add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
     target_link_libraries(${TEST_NAME} ${QT_QTTEST_LIBRARY} kolab_static)
     add_test(${TEST_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME})


commit dcaa9c284dd0a5d8a66a55ef14c1a9331d67bba9
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Fri Aug 10 01:32:00 2012 +0200

    To latin1 apparently works better as to Local8Bit, and also works independently of the locally set locale.
    
    I'm not quite sure why it also seems to work for unicode characters though...

diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index 7e67c85..69fe273 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -168,9 +168,9 @@ ObjectType KolabObjectReader::Private::readKolabV2(const KMime::Message::Ptr &ms
         mObjectType = objectType;
         return mObjectType;
     }
-    KMime::Content *xmlContent = Mime::findContentByType( msg, kolabType.toLocal8Bit() );
+    KMime::Content *xmlContent = Mime::findContentByType( msg, kolabType.toLatin1() );
     if ( !xmlContent ) {
-        Critical() << "no part with type" << kolabType.toLocal8Bit() << " found";
+        Critical() << "no part with type" << kolabType.toLatin1() << " found";
         printMessageDebugInfo(msg);
         return InvalidObject;
     }
@@ -420,10 +420,10 @@ KMime::Message::Ptr KolabObjectWriter::writeEvent(const KCalCore::Event::Ptr &i,
         const Kolab::Event &incidence = Kolab::Conversion::fromKCalCore(*ic);
         const std::string &v3String = Kolab::writeEvent(incidence, getProductId(productId).toStdString());
         ErrorHandler::handleLibkolabxmlErrors();
-        return Mime::createMessage(ic, xCalMimeType(), eventKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
+        return Mime::createMessage(ic, xCalMimeType(), eventKolabType(), QString::fromStdString(v3String).toLatin1(), true, getProductId(productId));
     }
     const QString &xml = KolabV2::Event::eventToXML(i, tz);
-    return Mime::createMessage(i, eventKolabType(), eventKolabType(), xml.toLocal8Bit(), false, getProductId(productId));
+    return Mime::createMessage(i, eventKolabType(), eventKolabType(), xml.toLatin1(), false, getProductId(productId));
 }
 
 KMime::Message::Ptr KolabObjectWriter::writeTodo(const KCalCore::Todo::Ptr &i, Version v, const QString &productId, const QString &tz)
@@ -435,10 +435,10 @@ KMime::Message::Ptr KolabObjectWriter::writeTodo(const KCalCore::Todo::Ptr &i, V
         const Kolab::Todo &incidence = Kolab::Conversion::fromKCalCore(*ic);
         const std::string &v3String = Kolab::writeTodo(incidence, getProductId(productId).toStdString());
         ErrorHandler::handleLibkolabxmlErrors();
-        return Mime::createMessage(ic, xCalMimeType(), todoKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
+        return Mime::createMessage(ic, xCalMimeType(), todoKolabType(), QString::fromStdString(v3String).toLatin1(), true, getProductId(productId));
     }
     const QString &xml = KolabV2::Task::taskToXML(i, tz);
-    return Mime::createMessage(i, todoKolabType(), todoKolabType(), xml.toLocal8Bit(), false, getProductId(productId));
+    return Mime::createMessage(i, todoKolabType(), todoKolabType(), xml.toLatin1(), false, getProductId(productId));
 }
 
 KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr &i, Version v, const QString &productId, const QString &tz)
@@ -450,10 +450,10 @@ KMime::Message::Ptr KolabObjectWriter::writeJournal(const KCalCore::Journal::Ptr
         const Kolab::Journal &incidence = Kolab::Conversion::fromKCalCore(*ic);
         const std::string &v3String = Kolab::writeJournal(incidence, getProductId(productId).toStdString());
         ErrorHandler::handleLibkolabxmlErrors();
-        return  Mime::createMessage(ic, xCalMimeType(), journalKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
+        return  Mime::createMessage(ic, xCalMimeType(), journalKolabType(), QString::fromStdString(v3String).toLatin1(), true, getProductId(productId));
     }
     const QString &xml = KolabV2::Journal::journalToXML(i, tz);
-    return Mime::createMessage(i, journalKolabType(), journalKolabType(), xml.toLocal8Bit(), false, getProductId(productId));
+    return Mime::createMessage(i, journalKolabType(), journalKolabType(), xml.toLatin1(), false, getProductId(productId));
 }
 
 KMime::Message::Ptr KolabObjectWriter::writeIncidence(const KCalCore::Incidence::Ptr &i, Version v, const QString& productId, const QString& tz)
@@ -479,7 +479,7 @@ KMime::Message::Ptr KolabObjectWriter::writeContact(const KABC::Addressee &addre
         const Kolab::Contact &contact = Kolab::Conversion::fromKABC(addressee);
         const std::string &v3String = Kolab::writeContact(contact, getProductId(productId).toStdString());
         ErrorHandler::handleLibkolabxmlErrors();
-        return  Mime::createMessage(addressee, xCardMimeType(), contactKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
+        return  Mime::createMessage(addressee, xCardMimeType(), contactKolabType(), QString::fromStdString(v3String).toLatin1(), true, getProductId(productId));
     }
     KolabV2::Contact contact(&addressee);
     return contactToKolabFormat(contact, getProductId(productId));
@@ -492,7 +492,7 @@ KMime::Message::Ptr KolabObjectWriter::writeDistlist(const KABC::ContactGroup &d
         const Kolab::DistList &dist = Kolab::Conversion::fromKABC(distlist);
         const std::string &v3String = Kolab::writeDistlist(dist, getProductId(productId).toStdString());
         ErrorHandler::handleLibkolabxmlErrors();
-        return  Mime::createMessage(QString::fromStdString(dist.uid()), xCardMimeType(), contactKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
+        return  Mime::createMessage(QString::fromStdString(dist.uid()), xCardMimeType(), contactKolabType(), QString::fromStdString(v3String).toLatin1(), true, getProductId(productId));
     }
     KolabV2::DistributionList d(&distlist);
     return distListToKolabFormat(d, getProductId(productId));
@@ -506,7 +506,7 @@ KMime::Message::Ptr KolabObjectWriter::writeNote(const KMime::Message::Ptr &note
         const Kolab::Note &n = Kolab::Conversion::fromNote(note);
         const std::string &v3String = Kolab::writeNote(n, getProductId(productId).toStdString());
         ErrorHandler::handleLibkolabxmlErrors();
-        return  Mime::createMessage(QString::fromStdString(n.uid()), kolabMimeType(), noteKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
+        return  Mime::createMessage(QString::fromStdString(n.uid()), kolabMimeType(), noteKolabType(), QString::fromStdString(v3String).toLatin1(), true, getProductId(productId));
     }
     return noteToKolab(note, getProductId(productId));
 }
@@ -527,7 +527,7 @@ KMime::Message::Ptr KolabObjectWriter::writeDictionary(const QStringList &entrie
     Kolab::Configuration configuration(dictionary); //TODO preserve creation/lastModified date
     const std::string &v3String = Kolab::writeConfiguration(configuration, getProductId(productId).toStdString());
     ErrorHandler::handleLibkolabxmlErrors();
-    return  Mime::createMessage(QString::fromStdString(configuration.uid()), kolabMimeType(), dictKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
+    return  Mime::createMessage(QString::fromStdString(configuration.uid()), kolabMimeType(), dictKolabType(), QString::fromStdString(v3String).toLatin1(), true, getProductId(productId));
 }
 
 KMime::Message::Ptr KolabObjectWriter::writeFreebusy(const Freebusy &freebusy, Version v, const QString& productId)
@@ -538,7 +538,7 @@ KMime::Message::Ptr KolabObjectWriter::writeFreebusy(const Freebusy &freebusy, V
     }
     const std::string &v3String = Kolab::writeFreebusy(freebusy, getProductId(productId).toStdString());
     ErrorHandler::handleLibkolabxmlErrors();
-    return  Mime::createMessage(QString::fromStdString(freebusy.uid()), xCalMimeType(), freebusyKolabType(), QString::fromStdString(v3String).toLocal8Bit(), true, getProductId(productId));
+    return  Mime::createMessage(QString::fromStdString(freebusy.uid()), xCalMimeType(), freebusyKolabType(), QString::fromStdString(v3String).toLatin1(), true, getProductId(productId));
 }
 
 
diff --git a/tests/preservationtest.cpp b/tests/preservationtest.cpp
index 8caa904..7b131f9 100644
--- a/tests/preservationtest.cpp
+++ b/tests/preservationtest.cpp
@@ -22,22 +22,38 @@
 #include "kolabformat/kolabobject.h"
 #include <kdebug.h>
 
-void PreservationTest::preserveUtf8()
+void PreservationTest::preserveLatin1()
 {
     KCalCore::Event::Ptr event(new KCalCore::Event());
-    QString summary("äöü");
+    QString summary("äöü%@$£é¤¼²°");
     event->setSummary(summary);
     QCOMPARE(event->summary(), summary);
-    std::cout << event->summary().toStdString() << std::endl;
+    //std::cout << event->summary().toStdString() << std::endl;
     KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event);
-    kDebug() << msg->encodedContent();
+//     kDebug() << msg->encodedContent();
     KCalCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent();
     QVERIFY(readEvent);
-    std::cout << readEvent->summary().toStdString() << std::endl;
+//     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"
\ No newline at end of file
+#include "preservationtest.moc"
diff --git a/tests/preservationtest.h b/tests/preservationtest.h
index 835fd1b..3eefb0a 100644
--- a/tests/preservationtest.h
+++ b/tests/preservationtest.h
@@ -23,7 +23,8 @@ class PreservationTest: public QObject
 {
     Q_OBJECT
 private slots:
-    void preserveUtf8();
+    void preserveLatin1();
+    void preserveUnicode();
 };
 
 #endif // PRESERVATIONTEST_H


commit a20a5d779d0bb4ef11c6eb88c7a69af3b5ac52e3
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Fri Aug 10 00:52:38 2012 +0200

    Conversiontest for latin1+unicode

diff --git a/tests/kcalconversiontest.cpp b/tests/kcalconversiontest.cpp
index 9db2a01..35f4c99 100644
--- a/tests/kcalconversiontest.cpp
+++ b/tests/kcalconversiontest.cpp
@@ -314,6 +314,24 @@ void KCalConversionTest::testConversion_data()
         
         QTest::newRow("date only dates") << kcal << kolab;
     }
+    {
+        KCalCore::Event kcal;
+        kcal.setUid("uid");
+        kcal.setCreated(toDate(date));
+        kcal.setLastModified(toDate(date));
+        kcal.setDtStart(toDate(date));
+        kcal.setSummary("äöü%@$£é¤¼²°€Š�");
+        
+        Kolab::Event kolab;
+        kolab.setUid("uid");
+        kolab.setCreated(date);
+        kolab.setLastModified(date);
+        kolab.setStart(date);
+        kolab.setSummary("äöü%@$£é¤¼²°€Š�");
+        
+        QTest::newRow("latin1+Unicode") << kcal << kolab;
+
+    }
 }
 
 void KCalConversionTest::testConversion()


commit 80bdf41a5343946057e5a3dd070a0b64950e3234
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Thu Aug 9 23:59:48 2012 +0200

    Preservation test which proofs that utf8 characters are not correctly preserved + minor cleanups.

diff --git a/mime/mimeutils.cpp b/mime/mimeutils.cpp
index 60baaf6..9784f50 100644
--- a/mime/mimeutils.cpp
+++ b/mime/mimeutils.cpp
@@ -249,7 +249,7 @@ void getAttachments(KCalCore::Incidence::Ptr incidence, const QStringList &attac
             continue;
         }
         const QByteArray c = content->decodedContent().toBase64();
-        Debug() << c;
+//         Debug() << c;
         KCalCore::Attachment::Ptr attachment( new KCalCore::Attachment( c, QString::fromLatin1( type ) ) );
         attachment->setLabel( name );
         incidence->addAttachment(attachment);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b093234..bf9e9f4 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,36 +2,21 @@
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 add_definitions(-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
 
+macro(addTest TEST_NAME)
+    QT4_AUTOMOC(${TEST_Name}.cpp)
+    add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
+    target_link_libraries(${TEST_NAME} ${QT_QTTEST_LIBRARY} kolab_static)
+    add_test(${TEST_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME})
+endmacro()
+
 QT4_AUTOMOC(benchmark.cpp)
 add_executable(benchmarktest benchmark.cpp)
 target_link_libraries(benchmarktest ${QT_QTTEST_LIBRARY} kolab_static)
 
-QT4_AUTOMOC(formattest.cpp)
-add_executable(formattest formattest.cpp)
-target_link_libraries(formattest ${QT_QTTEST_LIBRARY} kolab_static)
-add_test(formattest ${CMAKE_CURRENT_BINARY_DIR}/formattest)
-
-QT4_AUTOMOC(upgradetest.cpp)
-add_executable(upgradetest upgradetest.cpp)
-target_link_libraries(upgradetest ${QT_QTTEST_LIBRARY} kolab_static)
-add_test(upgradetest ${CMAKE_CURRENT_BINARY_DIR}/upgradetest)
-
-QT4_AUTOMOC(kcalconversiontest.cpp)
-add_executable(kcalconversiontest kcalconversiontest.cpp)
-target_link_libraries(kcalconversiontest ${QT_QTTEST_LIBRARY} kolab_static)
-add_test(kcalconversiontest ${CMAKE_CURRENT_BINARY_DIR}/kcalconversiontest)
-
-QT4_AUTOMOC(calendaringtest.cpp)
-add_executable(calendaringtest calendaringtest.cpp)
-target_link_libraries(calendaringtest ${QT_QTTEST_LIBRARY} kolab_static)
-add_test(calendaringtest ${CMAKE_CURRENT_BINARY_DIR}/calendaringtest)
-
-QT4_AUTOMOC(icalendartest.cpp)
-add_executable(icalendartest icalendartest.cpp)
-target_link_libraries(icalendartest ${QT_QTTEST_LIBRARY} kolab_static)
-add_test(icalendartest ${CMAKE_CURRENT_BINARY_DIR}/icalendartest)
-
-QT4_AUTOMOC(freebusytest.cpp)
-add_executable(freebusytest freebusytest.cpp)
-target_link_libraries(freebusytest ${QT_QTTEST_LIBRARY} kolab_static)
-add_test(freebusytest ${CMAKE_CURRENT_BINARY_DIR}/freebusytest)
+addTest(formattest)
+addTest(upgradetest)
+addTest(kcalconversiontest)
+addTest(calendaringtest)
+addTest(icalendartest)
+addTest(freebusytest)
+addTest(preservationtest)
diff --git a/tests/formattest.cpp b/tests/formattest.cpp
index 31697f7..08a1e83 100644
--- a/tests/formattest.cpp
+++ b/tests/formattest.cpp
@@ -133,6 +133,7 @@ void FormatTest::testIncidence()
     Kolab::ObjectType t = reader.parseMimeMessage(msg);
     QCOMPARE(t, type);
     QCOMPARE(reader.getVersion(), version);
+    QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
 
     KCalCore::Incidence::Ptr convertedIncidence = reader.getIncidence();
     
@@ -232,6 +233,7 @@ void FormatTest::testContact()
     Kolab::ObjectType t = reader.parseMimeMessage(msg);
     QCOMPARE(t, type);
     QCOMPARE(reader.getVersion(), version);
+    QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
     
     KABC::Addressee convertedAddressee = reader.getContact();
     QVERIFY(!convertedAddressee.isEmpty());
@@ -301,6 +303,7 @@ void FormatTest::testNote()
     Kolab::ObjectType t = reader.parseMimeMessage(msg);
     QCOMPARE(t, type);
     QCOMPARE(reader.getVersion(), version);
+    QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
 
     KMime::Message::Ptr convertedNote = reader.getNote();
     QVERIFY(convertedNote.get());
diff --git a/tests/preservationtest.cpp b/tests/preservationtest.cpp
new file mode 100644
index 0000000..8caa904
--- /dev/null
+++ b/tests/preservationtest.cpp
@@ -0,0 +1,43 @@
+/*
+ * 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::preserveUtf8()
+{
+    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"
\ No newline at end of file
diff --git a/tests/preservationtest.h b/tests/preservationtest.h
new file mode 100644
index 0000000..835fd1b
--- /dev/null
+++ b/tests/preservationtest.h
@@ -0,0 +1,29 @@
+/*
+ * 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 preserveUtf8();
+};
+
+#endif // PRESERVATIONTEST_H
diff --git a/tests/testutils.h b/tests/testutils.h
index b6afcf5..5056587 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -74,6 +74,10 @@ static KMime::Message::Ptr readMimeFile( const QString &fileName, bool &ok)
     //   qDebug() << fileName;
     QFile file( fileName );
     ok = file.open( QFile::ReadOnly );
+    if (!ok) {
+        kWarning() << "failed to open file: " << fileName;
+        return KMime::Message::Ptr();
+    }
     const QByteArray data = file.readAll();
     
     KMime::Message::Ptr msg = KMime::Message::Ptr(new KMime::Message);





More information about the commits mailing list