Commit 6ed83bcc authored by Elvis Angelaccio's avatar Elvis Angelaccio

Remove code duplication in tests

parent 2b656fc4
......@@ -55,15 +55,8 @@ void DeleteTest::testDelete_data()
QTest::addColumn<uint>("expectedEntriesCount");
QTest::addColumn<uint>("expectedRemainingEntriesCount");
const auto formats = QStringList {
QStringLiteral("7z"),
QStringLiteral("rar"),
QStringLiteral("tar.bz2"),
QStringLiteral("zip")
};
// Repeat the same test case for each format and for each plugin supporting the format.
foreach (const QString &format, formats) {
foreach (const QString &format, TestHelper::testFormats()) {
const QString filename = QStringLiteral("test.%1").arg(format);
const auto mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
......
......@@ -460,15 +460,8 @@ void ExtractTest::testPreservePermissions_data()
QTest::addColumn<QString>("testFile");
QTest::addColumn<int>("expectedPermissions");
const auto formats = QStringList {
QStringLiteral("7z"),
QStringLiteral("rar"),
QStringLiteral("tar.gz"),
QStringLiteral("zip")
};
// Repeat the same test case for each format and for each plugin supporting the format.
foreach (const QString &format, formats) {
foreach (const QString &format, TestHelper::testFormats()) {
const QString filename = QFINDTESTDATA(QStringLiteral("data/test_permissions.%1").arg(format));
const auto mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
const auto plugins = m_pluginManager.preferredWritePluginsFor(mime);
......
......@@ -47,15 +47,8 @@ QStringList AbstractAddTest::getEntryPaths(Archive *archive)
void AbstractAddTest::setupRows(const QString &testName, const QString &archiveName, const QVector<Archive::Entry *> &targetEntries, Archive::Entry *destination, const QStringList &expectedNewPaths, uint numberOfEntries) const
{
const auto formats = QStringList {
QStringLiteral("7z"),
QStringLiteral("rar"),
QStringLiteral("tar.bz2"),
QStringLiteral("zip")
};
// Repeat the same test case for each format and for each plugin supporting the format.
foreach (const QString &format, formats) {
foreach (const QString &format, TestHelper::testFormats()) {
const QString filename = QStringLiteral("%1.%2").arg(archiveName, format);
const auto mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
......
......@@ -38,3 +38,13 @@ void TestHelper::startAndWaitForResult(KJob *job)
eventLoop.exec(); // krazy:exclude=crashy
}
QStringList TestHelper::testFormats()
{
return {
QStringLiteral("7z"),
QStringLiteral("rar"),
QStringLiteral("tar.bz2"),
QStringLiteral("zip")
};
}
......@@ -29,10 +29,16 @@
class KJob;
#include <QStringList>
namespace TestHelper
{
void startAndWaitForResult(KJob *job);
/**
* @return List of format extensions (without the leading dot) to be used in tests.
*/
QStringList testFormats();
};
#endif //TESTHELPER_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