Commit dee2c080 authored by Laurent Montel's avatar Laurent Montel 😁

Improve autotest

parent 91ab0ee3
include_directories(${libksieve_SOURCE_DIR}
${libksieve_SOURCE_DIR}/src/ksieveui/
)
add_definitions( -DKSIEVEUI_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
ecm_qt_declare_logging_category(ksieveui_sieveeditor_autocreatescripts_LIB_SRCS HEADER
libksieve_debug.h IDENTIFIER LIBKSIEVE_LOG CATEGORY_NAME org.kde.pim.libksieve)
......
......@@ -19,12 +19,77 @@
#include "sieveeditorgraphicalmodewidgettest.h"
#include "../sieveeditorgraphicalmodewidget.h"
#include "scriptsparsing/parsingutil.h"
#include <QTest>
#include <QStandardPaths>
#include <QProcess>
SieveEditorGraphicalModeWidgetTest::SieveEditorGraphicalModeWidgetTest(QObject *parent)
: QObject(parent)
{
QStandardPaths::setTestModeEnabled(true);
}
QString readSieveFile(const QString &sieveFile)
{
QFile file(sieveFile);
file.open(QIODevice::ReadOnly);
Q_ASSERT(file.isOpen());
const QString data = QString::fromUtf8(file.readAll());
return data;
}
void SieveEditorGraphicalModeWidgetTest::shouldLoadScripts()
{
QFETCH(QString, input);
QFETCH(bool, hasError);
QFETCH(bool, success);
KSieveUi::SieveEditorGraphicalModeWidget w;
const QString originalFile = QLatin1String(KSIEVEUI_DATA_DIR) + QLatin1Char('/') + input + QStringLiteral(".siv");
const QString refFile = QLatin1String(KSIEVEUI_DATA_DIR) + QLatin1Char('/') + input + QStringLiteral("-ref.siv");
const QString generatedFile = QLatin1String(KSIEVEUI_DATA_DIR) + QLatin1Char('/') + input + QStringLiteral("-generated.siv");
QString script = readSieveFile(originalFile);
bool result = false;
const QDomDocument doc = KSieveUi::ParsingUtil::parseScript(script, result);
QCOMPARE(success, result);
if (success) {
QString error;
w.loadScript(doc, error);
QCOMPARE(hasError, !error.isEmpty());
const QString generatedScript = w.currentscript();
//Create generated file
QFile f(generatedFile);
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate));
f.write(generatedScript.toUtf8());
f.close();
qDebug() << " generatedScript" << generatedScript;
//TODO compare script.
// compare to reference file
QStringList args = QStringList()
<< QStringLiteral("-u")
<< refFile
<< generatedFile;
QProcess proc;
proc.setProcessChannelMode(QProcess::ForwardedChannels);
proc.start(QStringLiteral("diff"), args);
QVERIFY(proc.waitForFinished());
QCOMPARE(proc.exitCode(), 0);
}
}
void SieveEditorGraphicalModeWidgetTest::shouldLoadScripts_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<bool>("hasError");
QTest::addColumn<bool>("success");
QTest::newRow("simplescript") << QStringLiteral("simple") << false << true;
}
QTEST_MAIN(SieveEditorGraphicalModeWidgetTest)
......@@ -29,6 +29,9 @@ class SieveEditorGraphicalModeWidgetTest : public QObject
public:
explicit SieveEditorGraphicalModeWidgetTest(QObject *parent = nullptr);
~SieveEditorGraphicalModeWidgetTest() = default;
private Q_SLOTS:
void shouldLoadScripts();
void shouldLoadScripts_data();
};
#endif // SIEVEEDITORGRAPHICALMODEWIDGETTEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment