File indexing completed on 2024-12-01 04:35:25
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "messageurltest.h" 0008 #include "messages/messageurl.h" 0009 #include <QJsonObject> 0010 #include <QTest> 0011 QTEST_GUILESS_MAIN(MessageUrlTest) 0012 0013 MessageUrlTest::MessageUrlTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void MessageUrlTest::shouldHaveDefaultValue() 0019 { 0020 MessageUrl url; 0021 QVERIFY(url.url().isEmpty()); 0022 QVERIFY(url.pageTitle().isEmpty()); 0023 QVERIFY(url.description().isEmpty()); 0024 QVERIFY(url.isEmpty()); 0025 QVERIFY(url.imageUrl().isEmpty()); 0026 QVERIFY(url.authorName().isEmpty()); 0027 QVERIFY(url.authorUrl().isEmpty()); 0028 QVERIFY(url.siteUrl().isEmpty()); 0029 QVERIFY(url.urlId().isEmpty()); 0030 QCOMPARE(url.imageHeight(), -1); 0031 QCOMPARE(url.imageWidth(), -1); 0032 QVERIFY(url.showPreview()); 0033 QVERIFY(!url.hasPreviewUrl()); 0034 QVERIFY(!url.hasHtmlDescription()); 0035 } 0036 0037 void MessageUrlTest::shouldSerializeData() 0038 { 0039 { 0040 MessageUrl input; 0041 input.setUrl(QStringLiteral("foo1")); 0042 input.setPageTitle(QStringLiteral("foo2")); 0043 input.setDescription(QStringLiteral("foo3")); 0044 const QJsonObject ba = MessageUrl::serialize(input); 0045 const MessageUrl output = MessageUrl::deserialize(ba); 0046 QCOMPARE(input, output); 0047 } 0048 { 0049 MessageUrl input; 0050 input.setPageTitle(QStringLiteral("foo2")); 0051 input.setDescription(QStringLiteral("foo3")); 0052 const QJsonObject ba = MessageUrl::serialize(input); 0053 const MessageUrl output = MessageUrl::deserialize(ba); 0054 QCOMPARE(input, output); 0055 } 0056 { 0057 MessageUrl input; 0058 input.setUrl(QStringLiteral("foo1")); 0059 input.setDescription(QStringLiteral("foo3")); 0060 const QJsonObject ba = MessageUrl::serialize(input); 0061 const MessageUrl output = MessageUrl::deserialize(ba); 0062 QCOMPARE(input, output); 0063 } 0064 { 0065 MessageUrl input; 0066 input.setUrl(QStringLiteral("foo1")); 0067 input.setDescription(QStringLiteral("foo3")); 0068 input.setImageUrl(QStringLiteral("foo4")); 0069 const QJsonObject ba = MessageUrl::serialize(input); 0070 const MessageUrl output = MessageUrl::deserialize(ba); 0071 QCOMPARE(input, output); 0072 } 0073 { 0074 MessageUrl input; 0075 input.setUrl(QStringLiteral("foo1")); 0076 input.setDescription(QStringLiteral("foo3")); 0077 input.setImageUrl(QStringLiteral("foo4")); 0078 input.setAuthorName(QStringLiteral("foo5")); 0079 const QJsonObject ba = MessageUrl::serialize(input); 0080 const MessageUrl output = MessageUrl::deserialize(ba); 0081 QCOMPARE(input, output); 0082 } 0083 { 0084 MessageUrl input; 0085 input.setUrl(QStringLiteral("foo1")); 0086 input.setDescription(QStringLiteral("foo3")); 0087 input.setImageUrl(QStringLiteral("foo4")); 0088 input.setAuthorName(QStringLiteral("foo5")); 0089 input.setAuthorUrl(QStringLiteral("foo6")); 0090 const QJsonObject ba = MessageUrl::serialize(input); 0091 const MessageUrl output = MessageUrl::deserialize(ba); 0092 QCOMPARE(input, output); 0093 } 0094 { 0095 MessageUrl input; 0096 input.setUrl(QStringLiteral("foo1")); 0097 input.setDescription(QStringLiteral("foo3")); 0098 input.setImageUrl(QStringLiteral("foo4")); 0099 input.setAuthorName(QStringLiteral("foo5")); 0100 input.setAuthorUrl(QStringLiteral("foo6")); 0101 input.setSiteUrl(QStringLiteral("foo7")); 0102 const QJsonObject ba = MessageUrl::serialize(input); 0103 const MessageUrl output = MessageUrl::deserialize(ba); 0104 QCOMPARE(input, output); 0105 } 0106 { 0107 MessageUrl input; 0108 input.setUrl(QStringLiteral("foo1")); 0109 input.setDescription(QStringLiteral("foo3")); 0110 input.setImageUrl(QStringLiteral("foo4")); 0111 input.setAuthorName(QStringLiteral("foo5")); 0112 input.setAuthorUrl(QStringLiteral("foo6")); 0113 input.setSiteUrl(QStringLiteral("foo7")); 0114 input.setImageHeight(8); 0115 const QJsonObject ba = MessageUrl::serialize(input); 0116 const MessageUrl output = MessageUrl::deserialize(ba); 0117 QCOMPARE(input, output); 0118 } 0119 { 0120 MessageUrl input; 0121 input.setUrl(QStringLiteral("foo1")); 0122 input.setDescription(QStringLiteral("foo3")); 0123 input.setImageUrl(QStringLiteral("foo4")); 0124 input.setAuthorName(QStringLiteral("foo5")); 0125 input.setAuthorUrl(QStringLiteral("foo6")); 0126 input.setSiteUrl(QStringLiteral("foo7")); 0127 input.setImageHeight(8); 0128 input.setImageWidth(32); 0129 const QJsonObject ba = MessageUrl::serialize(input); 0130 const MessageUrl output = MessageUrl::deserialize(ba); 0131 QCOMPARE(input, output); 0132 } 0133 } 0134 0135 void MessageUrlTest::shouldTestPreviewUrl() 0136 { 0137 MessageUrl url; 0138 QVERIFY(!url.hasPreviewUrl()); 0139 url.setDescription(QStringLiteral("bla")); 0140 QVERIFY(url.hasPreviewUrl()); 0141 url.setDescription(QString()); 0142 url.setAuthorUrl(QStringLiteral("bla")); 0143 QVERIFY(!url.hasPreviewUrl()); 0144 url.setImageUrl(QStringLiteral("bla1")); 0145 QVERIFY(url.hasPreviewUrl()); 0146 } 0147 0148 void MessageUrlTest::shouldGenerateHtmlDescription() 0149 { 0150 QFETCH(MessageUrl, messageUrl); 0151 QFETCH(QString, htmlDescription); 0152 messageUrl.generateHtmlDescription(); 0153 qDebug() << " messageUrl.htmlDescription()" << messageUrl.htmlDescription(); 0154 QCOMPARE(messageUrl.htmlDescription(), htmlDescription); 0155 } 0156 0157 void MessageUrlTest::shouldGenerateHtmlDescription_data() 0158 { 0159 QTest::addColumn<MessageUrl>("messageUrl"); 0160 QTest::addColumn<QString>("htmlDescription"); 0161 { 0162 MessageUrl url; 0163 url.setPageTitle(QStringLiteral("Title")); 0164 url.setUrl(QStringLiteral("Title_url")); 0165 0166 url.setDescription(QStringLiteral("Description")); 0167 0168 url.setSiteName(QStringLiteral("SiteName")); 0169 url.setSiteUrl(QStringLiteral("SiteUrl")); 0170 0171 QTest::newRow("generateHtmlDescription-test1") << url << QStringLiteral("[Title](Title_url)\nDescription\n[SiteName](SiteUrl)"); 0172 } 0173 0174 { 0175 MessageUrl url; 0176 url.setPageTitle(QStringLiteral("Title")); 0177 url.setUrl(QStringLiteral("Title_url")); 0178 0179 url.setDescription(QStringLiteral("Description")); 0180 QTest::newRow("generateHtmlDescription-test2") << url << QStringLiteral("[Title](Title_url)\nDescription"); 0181 } 0182 { 0183 MessageUrl url; 0184 url.setPageTitle(QStringLiteral("Title")); 0185 url.setUrl(QStringLiteral("Title_url")); 0186 0187 QTest::newRow("generateHtmlDescription-test3") << url << QStringLiteral("[Title](Title_url)"); 0188 } 0189 { 0190 MessageUrl url; 0191 QTest::newRow("generateHtmlDescription-test4") << url << QString(); 0192 } 0193 { 0194 MessageUrl url; 0195 url.setPageTitle(QStringLiteral( 0196 " Shan Hadden Fanpage on Instagram: \"The Iconic video that started it all\n. \n. \n. \n#shanhadden #queenshanhadden #egirl #minecraft\"")); 0197 url.setUrl(QStringLiteral("https://www.instagram.com/p/C0vwctGuxnI/")); 0198 0199 url.setDescription( 0200 QStringLiteral("19K likes, 66 comments - queenshanfan on December 12, 2023: \"The Iconic video that started it all\n. \n. \n. \n#shanhadden " 0201 "#queenshanhadden #egirl #minecraft\"")); 0202 0203 url.setSiteName(QStringLiteral("Instagram")); 0204 url.setSiteUrl(QStringLiteral("https://www.instagram.com/reel/C0vwctGuxnI/")); 0205 0206 QTest::newRow("generateHtmlDescription-test5") 0207 << url 0208 << QStringLiteral( 0209 "[ Shan Hadden Fanpage on Instagram: \"The Iconic video that started it all. . . #shanhadden #queenshanhadden #egirl " 0210 "#minecraft\"](https://www.instagram.com/p/C0vwctGuxnI/)\n19K likes, 66 comments - queenshanfan on December 12, 2023: \"The Iconic video " 0211 "that started it all. . . #shanhadden #queenshanhadden #egirl #minecraft\"\n[Instagram](https://www.instagram.com/reel/C0vwctGuxnI/)"); 0212 } 0213 { 0214 MessageUrl url; 0215 url.setPageTitle(QStringLiteral("ZED 2 - AI Stereo Camera | Stereolabs")); 0216 url.setUrl(QStringLiteral("https://www.stereolabs.com/products/zed-2")); 0217 0218 url.setDescription( 0219 QStringLiteral("The ZED 2 family is a next-generation series of USB 3.1 stereo cameras that seamlessly integrate advanced depth sensing with AI " 0220 "capabilities. This combination empowers you to develop cutting-edge spatial intelligence applications")); 0221 0222 url.setSiteName(QString()); 0223 url.setSiteUrl(QStringLiteral("https://www.stereolabs.com/products/zed-")); 0224 0225 QTest::newRow("generateHtmlDescription-test6") 0226 << url 0227 << QStringLiteral( 0228 "[ZED 2 - AI Stereo Camera | Stereolabs](https://www.stereolabs.com/products/zed-2)\nThe ZED 2 family is a next-generation series of USB " 0229 "3.1 stereo cameras that seamlessly integrate advanced depth sensing with AI capabilities. This combination empowers you to develop " 0230 "cutting-edge spatial intelligence applications"); 0231 } 0232 } 0233 0234 #include "moc_messageurltest.cpp"