File indexing completed on 2024-12-22 05:05:24
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "exportmailjobinterfacetest.h" 0008 #include "archivestorage.h" 0009 #include "exportmailjobinterfacetestimpl.h" 0010 #include "testexportfile.h" 0011 #include <KMime/Message> 0012 #include <QTest> 0013 0014 QTEST_MAIN(ExportMailJobInterfaceTest) 0015 0016 ExportMailJobInterfaceTest::ExportMailJobInterfaceTest(QObject *parent) 0017 : QObject(parent) 0018 { 0019 } 0020 0021 void ExportMailJobInterfaceTest::exportMail_data() 0022 { 0023 QTest::addColumn<QByteArray>("configpath"); 0024 QTest::addColumn<Utils::StoredTypes>("options"); 0025 const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); 0026 Utils::StoredTypes options = {Utils::StoredType::Config}; 0027 QTest::newRow("mailonlyconfig") << pathConfig + QByteArray("mailonlyconfig/") << options; 0028 0029 options = {Utils::StoredType::Config | Utils::StoredType::Resources}; 0030 QTest::newRow("mailconfigandresource") << pathConfig + QByteArray("mailconfigandresource/") << options; 0031 0032 options = {Utils::StoredType::MailTransport}; 0033 QTest::newRow("mailtransport") << pathConfig + QByteArray("mailtransport/") << options; 0034 0035 options = {Utils::StoredType::MailTransport}; 0036 QTest::newRow("mailtransport2") << pathConfig + QByteArray("mailtransport2/") << options; 0037 0038 options = {Utils::StoredType::Identity}; 0039 QTest::newRow("identities") << pathConfig + QByteArray("identities/") << options; 0040 0041 options = {Utils::StoredType::Identity | Utils::StoredType::Config}; 0042 QTest::newRow("identitiesandconfig") << pathConfig + QByteArray("identitiesandconfig/") << options; 0043 0044 options = {Utils::StoredType::Config | Utils::StoredType::Identity | Utils::StoredType::MailTransport}; 0045 QTest::newRow("identitiesandconfigandmailtransport") << pathConfig + QByteArray("identitiesandconfigandmailtransport/") << options; 0046 0047 options = {Utils::StoredType::Config | Utils::StoredType::Identity | Utils::StoredType::MailTransport | Utils::StoredType::Resources 0048 | Utils::StoredType::Mails}; 0049 QTest::newRow("identitiesandconfigandmailtransportandresources") << pathConfig + QByteArray("identitiesandconfigandmailtransportandresources/") << options; 0050 } 0051 0052 void ExportMailJobInterfaceTest::exportMail() 0053 { 0054 QFETCH(QByteArray, configpath); 0055 QFETCH(Utils::StoredTypes, options); 0056 std::unique_ptr<TestExportFile> file{new TestExportFile(this)}; 0057 file->setPathConfig(configpath); 0058 QList<Utils::AkonadiInstanceInfo> lstInfo; 0059 Utils::AkonadiInstanceInfo info; 0060 0061 info.identifier = QStringLiteral("akonadi_mbox_resource_1"); 0062 info.mimeTypes = QStringList() << KMime::Message::mimeType(); 0063 info.capabilities = QStringList() << QStringLiteral("Resource"); 0064 lstInfo << info; 0065 info.identifier = QStringLiteral("akonadi_maildir_resource_1"); 0066 info.mimeTypes = QStringList() << KMime::Message::mimeType(); 0067 info.capabilities = QStringList() << QStringLiteral("Resource"); 0068 lstInfo << info; 0069 info.identifier = QStringLiteral("akonadi_mixedmaildir_resource_1"); 0070 info.mimeTypes = QStringList() << KMime::Message::mimeType(); 0071 info.capabilities = QStringList() << QStringLiteral("Resource"); 0072 lstInfo << info; 0073 0074 // Pop3 support 0075 info.identifier = QStringLiteral("akonadi_pop3_resource_1"); 0076 info.mimeTypes = QStringList() << KMime::Message::mimeType(); 0077 info.capabilities = QStringList() << QStringLiteral("Resource"); 0078 lstInfo << info; 0079 0080 // Imap support 0081 info.identifier = QStringLiteral("akonadi_imap_resource_1"); 0082 info.mimeTypes = QStringList() << KMime::Message::mimeType(); 0083 info.capabilities = QStringList() << QStringLiteral("Resource"); 0084 lstInfo << info; 0085 0086 // Kolab support 0087 info.identifier = QStringLiteral("akonadi_kolab_resource_1"); 0088 info.mimeTypes = QStringList() << KMime::Message::mimeType(); 0089 info.capabilities = QStringList() << QStringLiteral("Resource"); 0090 lstInfo << info; 0091 0092 // Add extra resource. 0093 info.identifier = QStringLiteral("akonadi_kalarm_dir_resource_2"); 0094 lstInfo << info; 0095 0096 auto exportMail = new ExportMailJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); 0097 exportMail->setListOfResource(lstInfo); 0098 exportMail->setPathConfig(QLatin1StringView(configpath)); 0099 file->setAbstractImportExportJob(exportMail); 0100 file->start(); 0101 delete exportMail; 0102 } 0103 0104 #include "moc_exportmailjobinterfacetest.cpp"