File indexing completed on 2024-05-12 16:25: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 "messageattachmenttest.h"
0008 #include "messages/messageattachment.h"
0009 #include <QJsonObject>
0010 #include <QStandardPaths>
0011 #include <QTest>
0012 QTEST_GUILESS_MAIN(MessageAttachmentTest)
0013 
0014 MessageAttachmentTest::MessageAttachmentTest(QObject *parent)
0015     : QObject(parent)
0016 {
0017     QStandardPaths::setTestModeEnabled(true);
0018 }
0019 
0020 void MessageAttachmentTest::shouldHaveDefaultValue()
0021 {
0022     MessageAttachment attachment;
0023     QVERIFY(attachment.description().isEmpty());
0024     QVERIFY(attachment.title().isEmpty());
0025     QVERIFY(attachment.link().isEmpty());
0026     QVERIFY(!attachment.isValid());
0027     QVERIFY(attachment.color().isEmpty());
0028     QVERIFY(attachment.mimeType().isEmpty());
0029     QVERIFY(attachment.authorName().isEmpty());
0030     QCOMPARE(attachment.imageHeight(), -1);
0031     QCOMPARE(attachment.imageWidth(), -1);
0032     QVERIFY(!attachment.isAnimatedImage());
0033     QVERIFY(attachment.attachmentFields().isEmpty());
0034     QVERIFY(!attachment.collapsed());
0035     QVERIFY(!attachment.showAttachment());
0036     QVERIFY(!attachment.hasDescription());
0037 }
0038 
0039 void MessageAttachmentTest::shouldSerializeData()
0040 {
0041     {
0042         MessageAttachment input;
0043         input.setColor(QStringLiteral("foo1"));
0044         input.setDescription(QStringLiteral("foo2"));
0045         input.setTitle(QStringLiteral("foo3"));
0046         input.setLink(QStringLiteral("foo4"));
0047         input.setImageHeight(53);
0048         input.setImageWidth(83);
0049         input.setAuthorName(QStringLiteral("auth"));
0050         const QJsonObject ba = MessageAttachment::serialize(input);
0051         const MessageAttachment output = MessageAttachment::deserialize(ba);
0052         QCOMPARE(input, output);
0053     }
0054 
0055     {
0056         MessageAttachment input;
0057         input.setDescription(QStringLiteral("foo2"));
0058         input.setTitle(QStringLiteral("foo3"));
0059         input.setLink(QStringLiteral("foo4"));
0060         const QJsonObject ba = MessageAttachment::serialize(input);
0061         const MessageAttachment output = MessageAttachment::deserialize(ba);
0062         QCOMPARE(input, output);
0063     }
0064 
0065     {
0066         MessageAttachment input;
0067         input.setColor(QStringLiteral("foo1"));
0068         input.setDescription(QStringLiteral("foo2"));
0069         input.setTitle(QStringLiteral("foo3"));
0070         input.setLink(QStringLiteral("foo4"));
0071         input.setAuthorName(QStringLiteral("auth"));
0072         const QJsonObject ba = MessageAttachment::serialize(input);
0073         const MessageAttachment output = MessageAttachment::deserialize(ba);
0074         QCOMPARE(input, output);
0075     }
0076 }
0077 
0078 void MessageAttachmentTest::shouldAllowToDownloadAttachment()
0079 {
0080     MessageAttachment input;
0081     input.setColor(QStringLiteral("foo1"));
0082     input.setDescription(QStringLiteral("foo2"));
0083     input.setTitle(QStringLiteral("foo3"));
0084     input.setLink(QStringLiteral("http://www.kde.org"));
0085     input.setAuthorName(QStringLiteral("auth"));
0086     QVERIFY(!input.canDownloadAttachment());
0087     input.setLink(QStringLiteral("bla"));
0088     QVERIFY(input.canDownloadAttachment());
0089 }
0090 
0091 #include "moc_messageattachmenttest.cpp"