File indexing completed on 2025-01-05 04:49:42

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "briefheaderstyleplugintest.h"
0008 #include "../briefheaderstyleplugin/briefheaderstyleinterface.h"
0009 #include "../briefheaderstyleplugin/briefheaderstyleplugin.h"
0010 #include "utils.h"
0011 
0012 #include <MessageViewer/HeaderStyle>
0013 
0014 #include <KActionCollection>
0015 #include <KActionMenu>
0016 #include <QActionGroup>
0017 #include <QTest>
0018 
0019 BriefHeaderStylePluginTest::BriefHeaderStylePluginTest(QObject *parent)
0020     : QObject(parent)
0021 {
0022 }
0023 
0024 BriefHeaderStylePluginTest::~BriefHeaderStylePluginTest() = default;
0025 
0026 void BriefHeaderStylePluginTest::shouldHaveDefaultValue()
0027 {
0028     MessageViewer::BriefHeaderStylePlugin plugin;
0029     QVERIFY(plugin.headerStyle());
0030     QVERIFY(plugin.headerStrategy());
0031 }
0032 
0033 void BriefHeaderStylePluginTest::shouldCreateInterface()
0034 {
0035     MessageViewer::BriefHeaderStylePlugin plugin;
0036     auto menu = new KActionMenu(this);
0037     auto act = new QActionGroup(this);
0038     MessageViewer::HeaderStyleInterface *interface = plugin.createView(menu, act, new KActionCollection(this));
0039     QVERIFY(interface);
0040     QVERIFY(!interface->action().isEmpty());
0041     delete interface;
0042 }
0043 
0044 void BriefHeaderStylePluginTest::testFormatEmpty()
0045 {
0046     MessageViewer::BriefHeaderStylePlugin plugin;
0047     auto style = plugin.headerStyle();
0048     auto strategy = plugin.headerStrategy();
0049     style->setHeaderStrategy(strategy);
0050     QCOMPARE(style->headerStrategy(), strategy);
0051     auto aMsg = new KMime::Message();
0052     testHeaderFile(style->format(aMsg), QStringLiteral("empty.brief"));
0053     delete aMsg;
0054 }
0055 
0056 void BriefHeaderStylePluginTest::testFormat_data()
0057 {
0058     QTest::addColumn<QString>("mailbox");
0059 
0060     QDir dir(QStringLiteral(HEADER_DATA_DIR));
0061     const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks);
0062     for (const QString &file : l) {
0063         QTest::newRow(file.toLatin1().constData()) << file;
0064     }
0065 }
0066 
0067 void BriefHeaderStylePluginTest::testFormat()
0068 {
0069     QFETCH(QString, mailbox);
0070 
0071     MessageViewer::BriefHeaderStylePlugin plugin;
0072     auto style = plugin.headerStyle();
0073     auto strategy = plugin.headerStrategy();
0074     style->setHeaderStrategy(strategy);
0075     QCOMPARE(style->headerStrategy(), strategy);
0076     auto aMsg = readAndParseMail(mailbox);
0077     testHeaderFile(style->format(aMsg.data()), mailbox + QStringLiteral(".brief"));
0078 }
0079 
0080 QTEST_MAIN(BriefHeaderStylePluginTest)
0081 
0082 #include "moc_briefheaderstyleplugintest.cpp"