File indexing completed on 2024-04-21 03:52:39

0001 /*
0002   This file is part of the kcalcore library.
0003   SPDX-FileCopyrightText: 2020 Daniel Vrátil <dvratil@kde.org>
0004 
0005   SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "testconference.h"
0009 #include "conference.h"
0010 #include "filestorage.h"
0011 #include "memorycalendar.h"
0012 
0013 #include <QDataStream>
0014 #include <QTest>
0015 
0016 QTEST_MAIN(ConferenceTest)
0017 
0018 using namespace KCalendarCore;
0019 
0020 void ConferenceTest::testValidity()
0021 {
0022     {
0023         Conference test;
0024         QVERIFY(test.isNull());
0025     }
0026 
0027     {
0028         Conference test(QUrl(QStringLiteral("tel:000326870")), QStringLiteral("Phone call for conference"));
0029         QVERIFY(!test.isNull());
0030     }
0031 }
0032 
0033 void ConferenceTest::testCompare()
0034 {
0035     Conference conf1{QUrl{QStringLiteral("tel:123456789")}, QStringLiteral("Conference call"), {QStringLiteral("PHONE")}, QStringLiteral("en")};
0036     Conference conf2{QUrl{QStringLiteral("xmpp:conference@conference.conference")},
0037                      QStringLiteral("Conference chat"),
0038                      {QStringLiteral("CHAT")},
0039                      QStringLiteral("en")};
0040     QVERIFY(conf1 != conf2);
0041 
0042     conf2.setUri(QUrl{QStringLiteral("tel:123456789")});
0043     conf2.setLabel(QStringLiteral("Conference call"));
0044     conf2.setFeatures({QStringLiteral("PHONE")});
0045     conf2.setLanguage(QStringLiteral("en"));
0046 
0047     QVERIFY(conf1 == conf2);
0048 }
0049 
0050 void ConferenceTest::testAssign()
0051 {
0052     Conference conf1{QUrl{QStringLiteral("sip:1234-5678@sip.example")}, QStringLiteral("SIP Call")};
0053     Conference conf2;
0054     conf2 = conf1;
0055     QCOMPARE(conf1, conf2);
0056 
0057     conf2.setLanguage(QStringLiteral("en"));
0058     QVERIFY(!(conf1 == conf2));
0059 }
0060 
0061 void ConferenceTest::testCopyConstructor()
0062 {
0063     Conference conf1{QUrl{QStringLiteral("sip:1234-5678@sip.example")}, QStringLiteral("SIP Call")};
0064     Conference conf3 {conf1};
0065     QCOMPARE(conf3, conf1);
0066 }
0067 
0068 void ConferenceTest::testDataStream()
0069 {
0070     Conference conf1;
0071     conf1.setUri(QUrl{QStringLiteral("tel:000326870")});
0072     conf1.setLabel(QStringLiteral("Phone conference"));
0073     conf1.addFeature(QStringLiteral("PHONE"));
0074     conf1.setLanguage(QStringLiteral("en"));
0075 
0076     QByteArray byteArray;
0077     QDataStream out_stream(&byteArray, QIODevice::WriteOnly);
0078 
0079     out_stream << conf1;
0080 
0081     QDataStream in_stream(&byteArray, QIODevice::ReadOnly);
0082 
0083     Conference conf2;
0084 
0085     in_stream >> conf2;
0086 
0087     QCOMPARE(conf2.uri(), conf1.uri());
0088     QCOMPARE(conf2.label(), conf1.label());
0089     QCOMPARE(conf2.features(), conf1.features());
0090     QCOMPARE(conf2.language(), conf1.language());
0091 }
0092 
0093 void ConferenceTest::testLoading()
0094 {
0095     MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc()));
0096     FileStorage store(cal, QLatin1String(ICALTESTDATADIR) + QLatin1String("test_conference.ics"));
0097     QVERIFY(store.load());
0098     const auto events = cal->events();
0099     QCOMPARE(events.size(), 1);
0100 
0101     const auto event = events.at(0);
0102     const auto conferences = event->conferences();
0103     QCOMPARE(conferences.size(), 1);
0104     const auto conference = conferences.at(0);
0105     QCOMPARE(conference.uri(), QUrl{QStringLiteral("https://corp.kde.example/call/efi83r28")});
0106     QCOMPARE(conference.features(), (QStringList{QStringLiteral("AUDIO"), QStringLiteral("VIDEO")}));
0107     QCOMPARE(conference.label(), QStringLiteral("Join NextCloud Talk, password is 12345"));
0108 }
0109 
0110 #include "moc_testconference.cpp"