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

Add autotests

parent dff3a0e4
......@@ -41,4 +41,4 @@ macro(add_diff_bodyformatter_class_unittest _source _additional)
)
endmacro ()
add_diff_bodyformatter_class_unittest(diffhighlightertest.cpp "")
add_diff_bodyformatter_class_unittest(diffhighlightertest.cpp "../xdiff/diffhighlighter.cpp")
diff --git a/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp b/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp
index b69f56c0..2cc4ab92 100644
--- a/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp
+++ b/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp
@@ -166,7 +166,7 @@ public:
attFileName = att->name();
}
bodyPart->nodeHelper()->addTempFile(dir + QDir::separator() + attFileName);
- const QString href = QStringLiteral("file:") + QString::fromLatin1(QUrl::toPercentEncoding(dir + QDir::separator() + att->name()));
+ const QString href = QStringLiteral("file:") + dir + QDir::separator() + attFileName;
const QString iconName = QUrl::fromLocalFile(MessageViewer::Util::iconPathForMimetype(att->mimeTag(),
KIconLoader::Desktop, attFileName)).url();
......@@ -18,7 +18,9 @@
*/
#include "diffhighlightertest.h"
#include "../xdiff/diffhighlighter.h"
#include <QProcess>
#include <QTest>
DiffHighlighterTest::DiffHighlighterTest(QObject *parent)
......@@ -27,7 +29,6 @@ DiffHighlighterTest::DiffHighlighterTest(QObject *parent)
}
QString readDiffFile(const QString &diffFile)
{
QFile file(diffFile);
......@@ -37,5 +38,44 @@ QString readDiffFile(const QString &diffFile)
return data;
}
void DiffHighlighterTest::shouldGenerateDiff_data()
{
QTest::addColumn<QString>("input");
QTest::newRow("test1") << QStringLiteral("test1");
}
void DiffHighlighterTest::shouldGenerateDiff()
{
QFETCH(QString, input);
const QString originalFile = QLatin1String(DIFF_DATA_DIR) + QLatin1Char('/') + input + QStringLiteral(".diff");
const QString refFile = QLatin1String(DIFF_DATA_DIR) + QLatin1Char('/') + input + QStringLiteral("-ref.diff");
const QString generatedFile = QLatin1String(DIFF_DATA_DIR) + QLatin1Char('/') + input + QStringLiteral("-generated.diff");
QString diff = readDiffFile(originalFile);
DiffHighlighter highLighter;
highLighter.highlightDiff(diff);
const QString html = highLighter.outputDiff();
//Create generated file
QFile f(generatedFile);
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate));
f.write(html.toUtf8());
f.close();
// 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);
}
QTEST_MAIN(DiffHighlighterTest)
......@@ -28,6 +28,9 @@ class DiffHighlighterTest : public QObject
public:
explicit DiffHighlighterTest(QObject *parent = nullptr);
~DiffHighlighterTest() = default;
private Q_SLOTS:
void shouldGenerateDiff_data();
void shouldGenerateDiff();
};
#endif // DIFFHIGHLIGHTERTEST_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