Commit f3601127 authored by Ragnar Thomsen's avatar Ragnar Thomsen

Extend AddToArchiveTest

Check for correct number of added folders. Add tests for empty subdirs
and folders with multiple level of subfolders.

Also test the RAR format, even though we currently dont provide a
"Compress Here (as RAR)" action in the service menu.
parent d78e151c
......@@ -25,8 +25,10 @@
#include "kerfuffle/addtoarchive.h"
#include "kerfuffle/archive_kerfuffle.h"
#include "kerfuffle/pluginmanager.h"
#include <QEventLoop>
#include <QMimeDatabase>
#include <QStandardPaths>
#include <QTest>
......@@ -48,18 +50,35 @@ void AddToArchiveTest::testCompressHere_data()
QTest::addColumn<QStringList>("inputFiles");
QTest::addColumn<QString>("expectedArchiveName");
QTest::addColumn<qulonglong>("expectedNumberOfFiles");
QTest::addColumn<qulonglong>("expectedNumberOfFolders");
QTest::newRow("compress here (as TAR) - whole folder")
QTest::newRow("compress here (as TAR) - dir with files")
<< QStringLiteral("tar.gz")
<< QStringList {QFINDTESTDATA("data/testdir")}
<< QStringLiteral("testdir.tar.gz")
<< 2ULL
<< 1ULL;
QTest::newRow("compress here (as TAR) - dir with subdirs")
<< QStringLiteral("tar.gz")
<< QStringList {QFINDTESTDATA("data/testdirwithsubdirs")}
<< QStringLiteral("testdirwithsubdirs.tar.gz")
<< 4ULL
<< 4ULL;
QTest::newRow("compress here (as TAR) - dir with empty subdir")
<< QStringLiteral("tar.gz")
<< QStringList {QFINDTESTDATA("data/testdirwithemptysubdir")}
<< QStringLiteral("testdirwithemptysubdir.tar.gz")
<< 2ULL
<< 2ULL;
QTest::newRow("compress here (as TAR) - single file")
<< QStringLiteral("tar.gz")
<< QStringList {QFINDTESTDATA("data/testfile.txt")}
<< QStringLiteral("testfile.tar.gz")
<< 1ULL;
<< 1ULL
<< 0ULL;
QTest::newRow("compress here (as TAR) - file + folder")
<< QStringLiteral("tar.gz")
......@@ -68,26 +87,44 @@ void AddToArchiveTest::testCompressHere_data()
QFINDTESTDATA("data/testfile.txt")
}
<< QStringLiteral("data.tar.gz")
<< 3ULL;
<< 3ULL
<< 1ULL;
QTest::newRow("compress here (as TAR) - bug #362690")
<< QStringLiteral("tar.gz")
<< QStringList {QFINDTESTDATA("data/test-3.4.0")}
<< QStringLiteral("test-3.4.0.tar.gz")
<< 1ULL
<< 1ULL;
if (!QStandardPaths::findExecutable(QStringLiteral("zip")).isEmpty()) {
QTest::newRow("compress here (as ZIP) - whole folder")
if (!PluginManager().preferredWritePluginsFor(QMimeDatabase().mimeTypeForName(QStringLiteral("application/zip"))).isEmpty()) {
QTest::newRow("compress here (as ZIP) - dir with files")
<< QStringLiteral("zip")
<< QStringList {QFINDTESTDATA("data/testdir")}
<< QStringLiteral("testdir.zip")
<< 2ULL
<< 1ULL;
QTest::newRow("compress here (as ZIP) - dir with subdirs")
<< QStringLiteral("zip")
<< QStringList {QFINDTESTDATA("data/testdirwithsubdirs")}
<< QStringLiteral("testdirwithsubdirs.zip")
<< 4ULL
<< 4ULL;
QTest::newRow("compress here (as ZIP) - dir with empty subdir")
<< QStringLiteral("zip")
<< QStringList {QFINDTESTDATA("data/testdirwithemptysubdir")}
<< QStringLiteral("testdirwithemptysubdir.zip")
<< 2ULL
<< 2ULL;
QTest::newRow("compress here (as ZIP) - single file")
<< QStringLiteral("zip")
<< QStringList {QFINDTESTDATA("data/testfile.txt")}
<< QStringLiteral("testfile.zip")
<< 1ULL;
<< 1ULL
<< 0ULL;
QTest::newRow("compress here (as ZIP) - file + folder")
<< QStringLiteral("zip")
......@@ -96,9 +133,52 @@ void AddToArchiveTest::testCompressHere_data()
QFINDTESTDATA("data/testfile.txt")
}
<< QStringLiteral("data.zip")
<< 3ULL;
<< 3ULL
<< 1ULL;
} else {
qDebug() << "7z/zip executable not found in path. Skipping compress-here-(ZIP) tests.";
}
if (!PluginManager().preferredWritePluginsFor(QMimeDatabase().mimeTypeForName(QStringLiteral("application/x-rar"))).isEmpty()) {
QTest::newRow("compress here (as RAR) - dir with files")
<< QStringLiteral("rar")
<< QStringList {QFINDTESTDATA("data/testdir")}
<< QStringLiteral("testdir.rar")
<< 2ULL
<< 1ULL;
QTest::newRow("compress here (as RAR) - dir with subdirs")
<< QStringLiteral("rar")
<< QStringList {QFINDTESTDATA("data/testdirwithsubdirs")}
<< QStringLiteral("testdirwithsubdirs.rar")
<< 4ULL
<< 4ULL;
QTest::newRow("compress here (as RAR) - dir with empty subdir")
<< QStringLiteral("rar")
<< QStringList {QFINDTESTDATA("data/testdirwithemptysubdir")}
<< QStringLiteral("testdirwithemptysubdir.rar")
<< 2ULL
<< 2ULL;
QTest::newRow("compress here (as RAR) - single file")
<< QStringLiteral("rar")
<< QStringList {QFINDTESTDATA("data/testfile.txt")}
<< QStringLiteral("testfile.rar")
<< 1ULL
<< 0ULL;
QTest::newRow("compress here (as RAR) - file + folder")
<< QStringLiteral("rar")
<< QStringList {
QFINDTESTDATA("data/testdir"),
QFINDTESTDATA("data/testfile.txt")
}
<< QStringLiteral("data.rar")
<< 3ULL
<< 1ULL;
} else {
qDebug() << "zip executable not found in path. Skipping compress-here-(ZIP) tests.";
qDebug() << "rar executable not found in path. Skipping compress-here-(RAR) tests.";
}
}
......@@ -132,6 +212,9 @@ void AddToArchiveTest::testCompressHere()
QFETCH(qulonglong, expectedNumberOfFiles);
QCOMPARE(archive->numberOfFiles(), expectedNumberOfFiles);
QFETCH(qulonglong, expectedNumberOfFolders);
QCOMPARE(archive->numberOfFolders(), expectedNumberOfFolders);
QVERIFY(QFile(archive->fileName()).remove());
}
......
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