File indexing completed on 2025-01-26 04:58:12
0001 /* 0002 Copyright (c) 2015 Volker Krause <vkrause@kde.org> 0003 0004 This library is free software; you can redistribute it and/or modify it 0005 under the terms of the GNU Library General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or (at your 0007 option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, but WITHOUT 0010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0012 License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to the 0016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA. 0018 */ 0019 #include "objecttreeparser.h" 0020 0021 #include "setupenv.h" 0022 0023 #include <qtest.h> 0024 #include <QDebug> 0025 0026 using namespace MimeTreeParser; 0027 0028 class AttachmentTest : public QObject 0029 { 0030 Q_OBJECT 0031 private Q_SLOTS: 0032 void initTestCase(); 0033 void testEncryptedAttachment_data(); 0034 void testEncryptedAttachment(); 0035 }; 0036 0037 QTEST_MAIN(AttachmentTest) 0038 0039 0040 QByteArray readMailFromFile(const QString &mailFile) 0041 { 0042 QFile file(QLatin1String(MAIL_DATA_DIR) + QLatin1Char('/') + mailFile); 0043 file.open(QIODevice::ReadOnly); 0044 Q_ASSERT(file.isOpen()); 0045 return file.readAll(); 0046 } 0047 0048 void AttachmentTest::initTestCase() 0049 { 0050 MimeTreeParser::Test::setupEnv(); 0051 } 0052 0053 void AttachmentTest::testEncryptedAttachment_data() 0054 { 0055 QTest::addColumn<QString>("mbox"); 0056 QTest::newRow("encrypted") << "openpgp-encrypted-two-attachments.mbox"; 0057 QTest::newRow("signed") << "openpgp-signed-two-attachments.mbox"; 0058 QTest::newRow("signed+encrypted") << "openpgp-signed-encrypted-two-attachments.mbox"; 0059 QTest::newRow("encrypted+partial signed") << "openpgp-encrypted-partially-signed-attachments.mbox"; 0060 } 0061 0062 void AttachmentTest::testEncryptedAttachment() 0063 { 0064 QFETCH(QString, mbox); 0065 ObjectTreeParser otp; 0066 otp.parseObjectTree(readMailFromFile(mbox)); 0067 otp.decryptParts(); 0068 otp.print(); 0069 0070 auto attachmentParts = otp.collectAttachmentParts(); 0071 QCOMPARE(attachmentParts.size(), 2); 0072 } 0073 0074 #include "attachmenttest.moc"