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 "icalendartest.h"
0008 
0009 #include <QTest>
0010 #include <kolabevent.h>
0011 
0012 #include "icalendar/icalendar.h"
0013 
0014 #include "testhelpers.h"
0015 
0016 void ICalendarTest::testFromICalEvent()
0017 {
0018     std::vector<Kolab::Event> events;
0019     Kolab::Event ev1;
0020     ev1.setStart(Kolab::cDateTime(2011, 10, 10, 12, 1, 1, true));
0021     ev1.setEnd(Kolab::cDateTime(2011, 10, 11, 12, 1, 1, true));
0022     events.push_back(ev1);
0023     events.push_back(ev1);
0024     const std::vector<Kolab::Event> &result = Kolab::fromICalEvents(Kolab::toICal(events));
0025     qDebug() << QString::fromStdString(Kolab::toICal(result));
0026 }
0027 
0028 void ICalendarTest::testToICal()
0029 {
0030     std::vector<Kolab::Event> events;
0031     Kolab::Event ev1;
0032     ev1.setStart(Kolab::cDateTime(2011, 10, 10, 12, 1, 1, true));
0033     ev1.setEnd(Kolab::cDateTime(2011, 10, 11, 12, 1, 1, true));
0034     events.push_back(ev1);
0035     events.push_back(ev1);
0036     qDebug() << QString::fromStdString(Kolab::toICal(events));
0037 }
0038 
0039 void ICalendarTest::testToITip()
0040 {
0041     Kolab::ITipHandler handler;
0042     Kolab::Event ev1;
0043     ev1.setStart(Kolab::cDateTime(2011, 10, 10, 12, 1, 1, true));
0044     ev1.setEnd(Kolab::cDateTime(2011, 10, 11, 12, 1, 1, true));
0045     ev1.setLastModified(Kolab::cDateTime(2011, 10, 11, 12, 1, 2, true));
0046     ev1.setCreated(Kolab::cDateTime(2011, 10, 11, 12, 1, 3, true));
0047 
0048     qDebug() << QString::fromStdString(handler.toITip(ev1, Kolab::ITipHandler::iTIPRequest));
0049 }
0050 
0051 void ICalendarTest::testToIMip()
0052 {
0053     Kolab::ITipHandler handler;
0054     Kolab::Event ev1;
0055     ev1.setStart(Kolab::cDateTime("Europe/Zurich", 2011, 10, 10, 12, 1, 1));
0056     ev1.setEnd(Kolab::cDateTime("Europe/Zurich", 2012, 5, 5, 3, 4, 4));
0057     ev1.setLastModified(Kolab::cDateTime(2011, 10, 11, 12, 1, 2, true));
0058     ev1.setCreated(Kolab::cDateTime(2011, 10, 11, 12, 1, 3, true));
0059 
0060     std::vector<Kolab::Attendee> attendees;
0061     attendees.emplace_back(Kolab::ContactReference("email1@test.org", "name1", "uid1"));
0062     attendees.emplace_back(Kolab::ContactReference("email2@test.org", "name2", "uid2"));
0063     ev1.setAttendees(attendees);
0064 
0065     ev1.setOrganizer(Kolab::ContactReference("organizer@test.org", "organizer", "uid3"));
0066     ev1.setSummary("summary");
0067 
0068     const std::string mimeResult = handler.toIMip(ev1, Kolab::ITipHandler::iTIPRequest, "test@test.com");
0069     qDebug() << QString::fromStdString(mimeResult);
0070     qDebug() << QString::fromStdString(handler.toIMip(ev1, Kolab::ITipHandler::iTIPReply, "test@test.com"));
0071 
0072     const std::vector<Kolab::Event> &eventResult = handler.fromIMip(mimeResult);
0073 
0074     //     qDebug() << QString::fromStdString(Kolab::toICal(eventResult));
0075 
0076     QCOMPARE((int)eventResult.size(), 1);
0077     QEXPECT_FAIL("", "to imip converts dates to utc", Continue);
0078     QCOMPARE(eventResult.front().start(), ev1.start());
0079     QEXPECT_FAIL("", "to imip converts dates to utc", Continue);
0080     QCOMPARE(eventResult.front().end(), ev1.end());
0081 }
0082 
0083 QTEST_MAIN(ICalendarTest)
0084 
0085 #include "moc_icalendartest.cpp"