File indexing completed on 2024-12-22 05:05:17
0001 // SPDX-FileCopyrightText: 2015 Volker Krause <vkrause@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #include <MimeTreeParserCore/ObjectTreeParser> 0005 0006 #include "setupenv.h" 0007 0008 #include <QTest> 0009 0010 using namespace MimeTreeParser; 0011 0012 class AttachmentTest : public QObject 0013 { 0014 Q_OBJECT 0015 private Q_SLOTS: 0016 void initTestCase(); 0017 void testEncryptedAttachment_data(); 0018 void testEncryptedAttachment(); 0019 }; 0020 0021 QTEST_MAIN(AttachmentTest) 0022 0023 QByteArray readMailFromFile(const QString &mailFile) 0024 { 0025 QFile file(QLatin1StringView(MAIL_DATA_DIR) + QLatin1Char('/') + mailFile); 0026 file.open(QIODevice::ReadOnly); 0027 Q_ASSERT(file.isOpen()); 0028 return file.readAll(); 0029 } 0030 0031 void AttachmentTest::initTestCase() 0032 { 0033 MimeTreeParser::Test::setupEnv(); 0034 } 0035 0036 void AttachmentTest::testEncryptedAttachment_data() 0037 { 0038 QTest::addColumn<QString>("mbox"); 0039 QTest::newRow("encrypted") << "openpgp-encrypted-two-attachments.mbox"; 0040 QTest::newRow("signed") << "openpgp-signed-two-attachments.mbox"; 0041 QTest::newRow("signed+encrypted") << "openpgp-signed-encrypted-two-attachments.mbox"; 0042 QTest::newRow("encrypted+partial signed") << "openpgp-encrypted-partially-signed-attachments.mbox"; 0043 } 0044 0045 void AttachmentTest::testEncryptedAttachment() 0046 { 0047 QFETCH(QString, mbox); 0048 ObjectTreeParser otp; 0049 otp.parseObjectTree(readMailFromFile(mbox)); 0050 otp.decryptAndVerify(); 0051 otp.print(); 0052 0053 auto attachmentParts = otp.collectAttachmentParts(); 0054 QCOMPARE(attachmentParts.size(), 2); 0055 } 0056 0057 #include "attachmenttest.moc"