File indexing completed on 2024-12-01 04:35:26

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "parsemessageurlutilstest.h"
0008 #include "parsemessageurlutils.h"
0009 #include <QTest>
0010 QTEST_GUILESS_MAIN(ParseMessageUrlUtilsTest)
0011 ParseMessageUrlUtilsTest::ParseMessageUrlUtilsTest(QObject *parent)
0012     : QObject{parent}
0013 {
0014 }
0015 
0016 void ParseMessageUrlUtilsTest::shouldHaveDefaultValues()
0017 {
0018     ParseMessageUrlUtils w;
0019     QVERIFY(w.messageId().isEmpty());
0020     QVERIFY(w.roomId().isEmpty());
0021     QVERIFY(w.serverHost().isEmpty());
0022     QVERIFY(w.path().isEmpty());
0023 }
0024 
0025 void ParseMessageUrlUtilsTest::shouldParseUrl_data()
0026 {
0027     QTest::addColumn<QString>("messageUrl");
0028     QTest::addColumn<bool>("parsingValid");
0029     QTest::addColumn<QString>("messageId");
0030     QTest::addColumn<QString>("roomId");
0031     QTest::addColumn<QString>("serverHost");
0032     QTest::addColumn<QString>("path");
0033     QTest::addColumn<ParseMessageUrlUtils::ChannelType>("channelType");
0034     QTest::addColumn<ParseMessageUrlUtils::RoomIdType>("roomIdType");
0035 
0036     QTest::addRow("empty") << QString() << false << QString() << QString() << QString() << QString() << ParseMessageUrlUtils::ChannelType::Unknown
0037                            << ParseMessageUrlUtils::RoomIdType::Unknown;
0038     QTest::addRow("kde") << QStringLiteral("http://www.kde.org") << false << QString() << QString() << QString() << QString()
0039                          << ParseMessageUrlUtils::ChannelType::Unknown << ParseMessageUrlUtils::RoomIdType::Unknown;
0040     QTest::addRow("kde-1") << QStringLiteral("https://www.kde.org") << false << QString() << QString() << QString() << QString()
0041                            << ParseMessageUrlUtils::ChannelType::Unknown << ParseMessageUrlUtils::RoomIdType::Unknown;
0042     QTest::addRow("kde-2") << QStringLiteral("www.kde.org") << false << QString() << QString() << QString() << QString()
0043                            << ParseMessageUrlUtils::ChannelType::Unknown << ParseMessageUrlUtils::RoomIdType::Unknown;
0044     QTest::addRow("gorocketchat") << QStringLiteral("https://go.rocket.chat/") << false << QString() << QString() << QString() << QString()
0045                                   << ParseMessageUrlUtils::ChannelType::Unknown << ParseMessageUrlUtils::RoomIdType::Unknown;
0046     QTest::addRow("gorocketchat-1") << QStringLiteral(
0047         "https://go.rocket.chat/room?rid=NCrToCewka5MgMcDM&mid=Xope7b8WYWz82yHaq&host=www.kde.org&path=channel%2Ffoo%3Fmsg%3DXope7b8WYWz82yHaq")
0048                                     << true << QStringLiteral("Xope7b8WYWz82yHaq") << QStringLiteral("NCrToCewka5MgMcDM") << QStringLiteral("www.kde.org")
0049                                     << QStringLiteral("channel/foo?msg=Xope7b8WYWz82yHaq") << ParseMessageUrlUtils::ChannelType::Channel
0050                                     << ParseMessageUrlUtils::RoomIdType::RoomId;
0051 
0052     QTest::addRow("gorocketchat-2") << QStringLiteral(
0053         "https://go.rocket.chat/"
0054         "room?rid=XQv6u7Kyb4pfDhS4wuKK39zoewTkdacidH&mid=Bo8pcAH86LxiYzu98&host=www.kde.org&path=direct%2FXQv6u7Kyb4pfDhS4wuKK39zoewTkdacidH%3Fmsg%"
0055         "3DBo8pcAH86LxiYzu98") << true
0056                                     << QStringLiteral("Bo8pcAH86LxiYzu98") << QStringLiteral("XQv6u7Kyb4pfDhS4wuKK39zoewTkdacidH")
0057                                     << QStringLiteral("www.kde.org") << QStringLiteral("direct/XQv6u7Kyb4pfDhS4wuKK39zoewTkdacidH?msg=Bo8pcAH86LxiYzu98")
0058                                     << ParseMessageUrlUtils::ChannelType::Direct << ParseMessageUrlUtils::RoomIdType::RoomId;
0059 
0060     QTest::addRow("url-1") << QStringLiteral("https://www.kde.org/channel/python?msg=sn3gEQom7NcLxTg5h") << true << QStringLiteral("sn3gEQom7NcLxTg5h")
0061                            << QStringLiteral("python") << QStringLiteral("www.kde.org") << QStringLiteral("/channel/python")
0062                            << ParseMessageUrlUtils::ChannelType::Channel << ParseMessageUrlUtils::RoomIdType::RoomName;
0063 
0064     QTest::addRow("url-2") << QStringLiteral("https://www.kde.org/direct/python?msg=sn3gEQom7NcLxTg5h") << true << QStringLiteral("sn3gEQom7NcLxTg5h")
0065                            << QStringLiteral("python") << QStringLiteral("www.kde.org") << QStringLiteral("/direct/python")
0066                            << ParseMessageUrlUtils::ChannelType::Direct << ParseMessageUrlUtils::RoomIdType::RoomName;
0067 }
0068 
0069 void ParseMessageUrlUtilsTest::shouldParseUrl()
0070 {
0071     QFETCH(QString, messageUrl);
0072     QFETCH(bool, parsingValid);
0073     QFETCH(QString, messageId);
0074     QFETCH(QString, roomId);
0075     QFETCH(QString, serverHost);
0076     QFETCH(QString, path);
0077     QFETCH(ParseMessageUrlUtils::ChannelType, channelType);
0078     QFETCH(ParseMessageUrlUtils::RoomIdType, roomIdType);
0079 
0080     ParseMessageUrlUtils w;
0081     QCOMPARE(w.parseUrl(messageUrl), parsingValid);
0082     QCOMPARE(w.messageId(), messageId);
0083     QCOMPARE(w.roomId(), roomId);
0084     QCOMPARE(w.serverHost(), serverHost);
0085     QCOMPARE(w.path(), path);
0086     QCOMPARE(w.channelType(), channelType);
0087     QCOMPARE(w.roomIdType(), roomIdType);
0088 }
0089 
0090 #include "moc_parsemessageurlutilstest.cpp"