File indexing completed on 2024-12-22 04:46:03
0001 /* 0002 SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "messageattachmentdelegatehelperimagetest.h" 0008 #include "messages/messageattachment.h" 0009 #include "rocketchataccount.h" 0010 #include "room/delegate/messageattachmentdelegatehelperimage.h" 0011 #include "testdata.h" 0012 0013 #include <QListView> 0014 #include <QStandardPaths> 0015 #include <QStyleOptionViewItem> 0016 #include <QTest> 0017 0018 QTEST_MAIN(MessageDelegateHelperImageTest) 0019 0020 MessageDelegateHelperImageTest::MessageDelegateHelperImageTest(QObject *parent) 0021 : QObject(parent) 0022 { 0023 initTestAccount(); 0024 } 0025 0026 void MessageDelegateHelperImageTest::shouldExtractMessageData() 0027 { 0028 auto listView = new QListView(); 0029 TextSelectionImpl textSelection; 0030 MessageAttachmentDelegateHelperImage helper(nullptr, listView, &textSelection); 0031 QStyleOptionViewItem option; 0032 QWidget fakeWidget; 0033 option.widget = &fakeWidget; 0034 const MessageAttachment msgAttach = testAttachment(); 0035 0036 const MessageAttachmentDelegateHelperImage::ImageLayout layout = helper.layoutImage(msgAttach, option, 500, 500); 0037 QCOMPARE(layout.title, msgAttach.title()); 0038 QCOMPARE(layout.hasDescription, msgAttach.hasDescription()); 0039 QVERIFY(layout.isShown); 0040 QVERIFY(!layout.isAnimatedImage); 0041 QVERIFY(layout.imagePreviewPath.endsWith(QLatin1String("/testfile.png"))); 0042 QVERIFY(qAbs(layout.imageSize.height() - layout.imageSize.width() * 2) <= 1); // aspect ratio is preserved, allow for one pixel rounding diff 0043 QCOMPARE(layout.pixmap.devicePixelRatioF(), fakeWidget.devicePixelRatioF()); 0044 QVERIFY(layout.imageSize.height() < 500 * fakeWidget.devicePixelRatioF()); 0045 delete listView; 0046 } 0047 0048 #include "moc_messageattachmentdelegatehelperimagetest.cpp"