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 "fancyheaderstyleplugintest.h" 0008 #include "../fancyheaderstyleplugin/fancyheaderstyleinterface.h" 0009 #include "../fancyheaderstyleplugin/fancyheaderstyleplugin.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 FancyHeaderStylePluginTest::FancyHeaderStylePluginTest(QObject *parent) 0020 : QObject(parent) 0021 { 0022 } 0023 0024 FancyHeaderStylePluginTest::~FancyHeaderStylePluginTest() = default; 0025 0026 void FancyHeaderStylePluginTest::shouldHaveDefaultValue() 0027 { 0028 MessageViewer::FancyHeaderStylePlugin plugin; 0029 QVERIFY(plugin.headerStyle()); 0030 QVERIFY(plugin.headerStrategy()); 0031 } 0032 0033 void FancyHeaderStylePluginTest::shouldCreateInterface() 0034 { 0035 MessageViewer::FancyHeaderStylePlugin plugin; 0036 auto menu = new KActionMenu(this); 0037 auto act = new QActionGroup(this); 0038 0039 MessageViewer::HeaderStyleInterface *interface = plugin.createView(menu, act, new KActionCollection(this)); 0040 QVERIFY(interface); 0041 QVERIFY(!interface->action().isEmpty()); 0042 delete interface; 0043 } 0044 0045 void FancyHeaderStylePluginTest::testFormatEmpty() 0046 { 0047 MessageViewer::FancyHeaderStylePlugin plugin; 0048 auto style = plugin.headerStyle(); 0049 auto strategy = plugin.headerStrategy(); 0050 style->setHeaderStrategy(strategy); 0051 QCOMPARE(style->headerStrategy(), strategy); 0052 auto aMsg = new KMime::Message(); 0053 testHeaderFile(style->format(aMsg), QStringLiteral("empty.fancy")); 0054 delete aMsg; 0055 } 0056 0057 void FancyHeaderStylePluginTest::testFormat_data() 0058 { 0059 QTest::addColumn<QString>("mailbox"); 0060 0061 QDir dir(QStringLiteral(HEADER_DATA_DIR)); 0062 const auto l = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); 0063 for (const QString &file : l) { 0064 QTest::newRow(file.toLatin1().constData()) << file; 0065 } 0066 } 0067 0068 void FancyHeaderStylePluginTest::testFormat() 0069 { 0070 QFETCH(QString, mailbox); 0071 0072 MessageViewer::FancyHeaderStylePlugin plugin; 0073 auto style = plugin.headerStyle(); 0074 auto strategy = plugin.headerStrategy(); 0075 style->setHeaderStrategy(strategy); 0076 QCOMPARE(style->headerStrategy(), strategy); 0077 auto aMsg = readAndParseMail(mailbox); 0078 testHeaderFile(style->format(aMsg.data()), mailbox + QStringLiteral(".fancy")); 0079 } 0080 0081 QTEST_MAIN(FancyHeaderStylePluginTest) 0082 0083 #include "moc_fancyheaderstyleplugintest.cpp"