File indexing completed on 2024-11-24 04:44:09

0001 /*
0002  * SPDX-FileCopyrightText: 2012 Christian Mollekopf <mollekopf@kolabsys.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-3.0-or-later
0005  */
0006 
0007 #include "kolabobjecttest.h"
0008 
0009 #include <QTest>
0010 
0011 #include "kolabformat/errorhandler.h"
0012 #include "kolabformat/kolabobject.h"
0013 
0014 void KolabObjectTest::preserveLatin1()
0015 {
0016     KCalendarCore::Event::Ptr event(new KCalendarCore::Event());
0017     event->setDtStart(QDateTime(QDate(2014, 1, 1), {}));
0018     event->setAllDay(true);
0019     const QString summary(QLatin1StringView("äöü%@$£é¤¼²°"));
0020     event->setSummary(summary);
0021     QCOMPARE(event->summary(), summary);
0022     // std::cout << event->summary().toStdString() << std::endl;
0023     KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event);
0024     //     qDebug() << msg->encodedContent();
0025     KCalendarCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent();
0026     QVERIFY(readEvent);
0027     //     std::cout << readEvent->summary().toStdString() << std::endl;
0028     QCOMPARE(readEvent->summary(), summary);
0029 }
0030 
0031 void KolabObjectTest::preserveUnicode()
0032 {
0033     KCalendarCore::Event::Ptr event(new KCalendarCore::Event());
0034     event->setDtStart(QDateTime(QDate(2014, 1, 1), {}));
0035     event->setAllDay(true);
0036     QString summary(QStringLiteral("€Š�ـأبـ☺"));
0037     event->setSummary(summary);
0038     QCOMPARE(event->summary(), summary);
0039     //     std::cout << event->summary().toStdString() << std::endl;
0040     KMime::Message::Ptr msg = Kolab::KolabObjectWriter::writeEvent(event);
0041     //     qDebug() << msg->encodedContent();
0042     KCalendarCore::Event::Ptr readEvent = Kolab::KolabObjectReader(msg).getEvent();
0043     QVERIFY(readEvent);
0044     //     std::cout << readEvent->summary().toStdString() << std::endl;
0045     QCOMPARE(readEvent->summary(), summary);
0046 }
0047 
0048 void KolabObjectTest::dontCrashWithEmptyOrganizer()
0049 {
0050     KCalendarCore::Event::Ptr event(new KCalendarCore::Event());
0051     event->setDtStart(QDateTime(QDate(2012, 11, 11), {}));
0052     event->setAllDay(true);
0053     Kolab::KolabObjectWriter::writeEvent(event, Kolab::KolabV2);
0054     QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
0055     Kolab::KolabObjectWriter::writeEvent(event);
0056     qDebug() << Kolab::ErrorHandler::instance().error();
0057     QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
0058 }
0059 
0060 void KolabObjectTest::dontCrashWithEmptyIncidence()
0061 {
0062     Kolab::KolabObjectWriter::writeEvent(KCalendarCore::Event::Ptr());
0063     QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
0064     Kolab::KolabObjectWriter::writeTodo(KCalendarCore::Todo::Ptr());
0065     QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
0066     Kolab::KolabObjectWriter::writeJournal(KCalendarCore::Journal::Ptr());
0067     QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
0068     Kolab::KolabObjectWriter::writeIncidence(KCalendarCore::Event::Ptr());
0069     QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
0070     Kolab::KolabObjectWriter::writeNote(KMime::Message::Ptr());
0071     QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Critical);
0072 }
0073 
0074 void KolabObjectTest::parseRelationMembers()
0075 {
0076     {
0077         QString memberString(QStringLiteral(
0078             "imap:/user/jan.aachen%40lhm.klab.cc/INBOX/"
0079             "20?message-id=%3Cf06aa3345a25005380b47547ad161d36%40lhm.klab.cc%3E&subject=Re%3A+test&date=Tue%2C+12+Aug+2014+20%3A42%3A59+%2B0200"));
0080         Kolab::RelationMember member = Kolab::parseMemberUrl(memberString);
0081 
0082         QString result = Kolab::generateMemberUrl(member);
0083         qDebug() << result;
0084         result.replace(QLatin1StringView("%20"), QLatin1StringView("+"));
0085         QEXPECT_FAIL("", "This is currently failing, probably a bug in the recent changes regarding the encoding.", Continue);
0086         QCOMPARE(result, memberString);
0087     }
0088 
0089     // user namespace by uid
0090     {
0091         Kolab::RelationMember member;
0092         member.uid = 20;
0093         member.mailbox = QList<QByteArray>() << "INBOX";
0094         member.user = QStringLiteral("john.doe@example.org");
0095         member.messageId = QStringLiteral("messageid");
0096         member.date = QStringLiteral("date");
0097         member.subject = QStringLiteral("subject");
0098         QString url = Kolab::generateMemberUrl(member);
0099         qDebug() << url;
0100         Kolab::RelationMember result = Kolab::parseMemberUrl(url);
0101         QCOMPARE(result.uid, member.uid);
0102         QCOMPARE(result.mailbox, member.mailbox);
0103         QEXPECT_FAIL("", "This is currently failing, probably a bug in the recent changes regarding the encoding.", Continue);
0104         QCOMPARE(result.user, member.user);
0105         QCOMPARE(result.messageId, member.messageId);
0106         QCOMPARE(result.date, member.date);
0107         QCOMPARE(result.subject, member.subject);
0108     }
0109 
0110     // shared namespace by uid
0111     {
0112         Kolab::RelationMember member;
0113         member.uid = 20;
0114         member.mailbox = QList<QByteArray>() << "foo"
0115                                              << "bar";
0116         member.messageId = QStringLiteral("messageid");
0117         member.date = QStringLiteral("date");
0118         member.subject = QStringLiteral("subject");
0119         QString url = Kolab::generateMemberUrl(member);
0120         qDebug() << url;
0121         Kolab::RelationMember result = Kolab::parseMemberUrl(url);
0122         QCOMPARE(result.uid, member.uid);
0123         QCOMPARE(result.mailbox, member.mailbox);
0124         QVERIFY(result.user.isEmpty());
0125         QCOMPARE(result.messageId, member.messageId);
0126         QCOMPARE(result.date, member.date);
0127         QCOMPARE(result.subject, member.subject);
0128     }
0129 
0130     // by uuid/gid
0131     {
0132         Kolab::RelationMember member;
0133         member.gid = QStringLiteral("fooobar");
0134         QString url = Kolab::generateMemberUrl(member);
0135         qDebug() << url;
0136         Kolab::RelationMember result = Kolab::parseMemberUrl(url);
0137         QCOMPARE(result.gid, member.gid);
0138     }
0139 
0140     // chars to en/decode
0141     {
0142         Kolab::RelationMember member;
0143         member.uid = 20;
0144         member.mailbox = QList<QByteArray>() << "spaces in folders"
0145                                              << "+^,:@";
0146         member.user = QStringLiteral("john.doe:^@example.org");
0147         member.messageId = QStringLiteral("messageid+^,:@");
0148         member.date = QStringLiteral("date+^,:@");
0149         member.subject = QStringLiteral("subject+^,:@");
0150 
0151         QString url = Kolab::generateMemberUrl(member);
0152         qDebug() << url;
0153         Kolab::RelationMember result = Kolab::parseMemberUrl(url);
0154         QCOMPARE(result.uid, member.uid);
0155         QEXPECT_FAIL("", "This is currently failing, probably a bug in the recent changes regarding the encoding.", Continue);
0156         QCOMPARE(result.mailbox, member.mailbox);
0157         QEXPECT_FAIL("", "This is currently failing, probably a bug in the recent changes regarding the encoding.", Continue);
0158         QCOMPARE(result.user, member.user);
0159         QCOMPARE(result.messageId, member.messageId);
0160         QCOMPARE(result.date, member.date);
0161         QCOMPARE(result.subject, member.subject);
0162     }
0163 }
0164 
0165 QTEST_MAIN(KolabObjectTest)
0166 
0167 #include "moc_kolabobjecttest.cpp"