summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-18 16:13:26 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-18 22:29:51 (GMT)
commitddc2785c0c96051aa571a4480c80c992e8ed0c08 (patch)
treeda3073639bcbbbd4d9f7980e9e2c4a3f78a90982
parent7379e619fa610643761a25c9a0ae6f5e0f8398f8 (diff)
Drop TestHelper test functions
copytest and addtest rely on TestHelper functions, which are untested and thus not reliable for test purposes. Instead we manually define the expected paths of the entries created by the jobs. A new base class is added, since movetest/copytest/addtest share the code that sets up the test rows. Closes T4073
-rw-r--r--autotests/kerfuffle/addtest.cpp159
-rw-r--r--autotests/kerfuffle/addtoarchivetest.cpp1
-rw-r--r--autotests/kerfuffle/copytest.cpp361
-rw-r--r--autotests/kerfuffle/extracttest.cpp2
-rw-r--r--autotests/kerfuffle/movetest.cpp324
-rw-r--r--autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp1
-rw-r--r--autotests/testhelper/CMakeLists.txt5
-rw-r--r--autotests/testhelper/abstractaddtest.cpp72
-rw-r--r--autotests/testhelper/abstractaddtest.h61
-rw-r--r--autotests/testhelper/testhelper.cpp106
-rw-r--r--autotests/testhelper/testhelper.h33
11 files changed, 608 insertions, 517 deletions
diff --git a/autotests/kerfuffle/addtest.cpp b/autotests/kerfuffle/addtest.cpp
index 312a36f..8306d18 100644
--- a/autotests/kerfuffle/addtest.cpp
+++ b/autotests/kerfuffle/addtest.cpp
@@ -23,31 +23,21 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "abstractaddtest.h"
+#include "archiveentry.h"
+#include "jobs.h"
#include "testhelper.h"
+#include <QTest>
+
using namespace Kerfuffle;
-class AddTest : public QObject
+class AddTest : public AbstractAddTest
{
Q_OBJECT
-private:
-void addAllFormatsRows(const QString &testName, const QString &archiveName, const QVector<Archive::Entry*> &entries, Archive::Entry *destination, uint numberOfEntries) {
- QStringList formats = QStringList()
- << QStringLiteral("7z")
- << QStringLiteral("rar")
- << QStringLiteral("tar.bz2")
- << QStringLiteral("zip");
-
- foreach (const QString &format, formats) {
- const QString testNameWithFormat = testName + QStringLiteral(" (") + format + QStringLiteral(")");
- QTest::newRow(testNameWithFormat.toUtf8())
- << archiveName + QLatin1Char('.') + format
- << entries
- << destination
- << numberOfEntries;
- }
-}
+public:
+ AddTest() : AbstractAddTest() {}
private Q_SLOTS:
void testAdding_data();
@@ -59,51 +49,73 @@ QTEST_GUILESS_MAIN(AddTest)
void AddTest::testAdding_data()
{
QTest::addColumn<QString>("archiveName");
- QTest::addColumn<QVector<Archive::Entry*>>("files");
+ QTest::addColumn<Plugin*>("plugin");
+ QTest::addColumn<QVector<Archive::Entry*>>("targetEntries");
QTest::addColumn<Archive::Entry*>("destination");
+ QTest::addColumn<QStringList>("expectedNewPaths");
QTest::addColumn<uint>("numberOfEntries");
- addAllFormatsRows(QStringLiteral("without destination"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("textfile1.txt")),
- new Archive::Entry(this, QStringLiteral("textfile2.txt")),
- },
- new Archive::Entry(this),
- 15);
-
- addAllFormatsRows(QStringLiteral("with destination, files"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("textfile1.txt")),
- new Archive::Entry(this, QStringLiteral("textfile2.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 15);
-
- addAllFormatsRows(QStringLiteral("with destination, directory"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("testdir/")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 16);
-
- addAllFormatsRows(QStringLiteral("without destination, directory 2"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("testdir2/")),
- },
- new Archive::Entry(this),
- 17);
-
- addAllFormatsRows(QStringLiteral("with destination, directory 2"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("testdir2/")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 17);
+ setupRows(QStringLiteral("without destination"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("textfile1.txt")),
+ new Archive::Entry(this, QStringLiteral("textfile2.txt"))
+ },
+ new Archive::Entry(this),
+ QStringList {
+ QStringLiteral("textfile1.txt"),
+ QStringLiteral("textfile2.txt")
+ },
+ 15);
+
+ setupRows(QStringLiteral("with destination, files"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("textfile1.txt")),
+ new Archive::Entry(this, QStringLiteral("textfile2.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/textfile1.txt"),
+ QStringLiteral("empty_dir/textfile2.txt")
+ },
+ 15);
+
+ setupRows(QStringLiteral("with destination, directory"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("testdir/")),
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/testdir/testfile1.txt"),
+ QStringLiteral("empty_dir/testdir/testfile2.txt")
+ },
+ 16);
+
+ setupRows(QStringLiteral("without destination, directory 2"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("testdir2/")),
+ },
+ new Archive::Entry(this),
+ QStringList {
+ QStringLiteral("testdir2/testdir/testfile1.txt"),
+ QStringLiteral("testdir2/testdir/testfile2.txt")
+ },
+ 17);
+
+ setupRows(QStringLiteral("with destination, directory 2"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("testdir2/")),
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/testdir2/testdir/testfile1.txt"),
+ QStringLiteral("empty_dir/testdir2/testdir/testfile2.txt")
+ },
+ 17);
}
void AddTest::testAdding()
@@ -114,7 +126,10 @@ void AddTest::testAdding()
const QString archivePath = temporaryDir.path() + QLatin1Char('/') + archiveName;
QVERIFY(QFile::copy(QFINDTESTDATA(QStringLiteral("data/") + archiveName), archivePath));
- auto loadJob = Archive::load(archivePath);
+ QFETCH(Plugin*, plugin);
+ QVERIFY(plugin);
+
+ auto loadJob = Archive::load(archivePath, plugin);
QVERIFY(loadJob);
loadJob->setAutoDelete(false);
@@ -126,18 +141,30 @@ void AddTest::testAdding()
QSKIP("Could not find a plugin to handle the archive. Skipping test.", SkipSingle);
}
- QFETCH(QVector<Archive::Entry*>, files);
+ QFETCH(QVector<Archive::Entry*>, targetEntries);
QFETCH(Archive::Entry*, destination);
+ QFETCH(QStringList, expectedNewPaths);
- QVector<Archive::Entry*> oldEntries = TestHelper::getEntryList(archive);
+ // Retrieve current paths in the archive.
+ QStringList oldPaths = getEntryPaths(archive);
+
+ // Check that the expected paths (after the AddJob) are not in the archive.
+ foreach (const auto &expectedPath, expectedNewPaths) {
+ QVERIFY(!oldPaths.contains(expectedPath));
+ }
CompressionOptions options;
options.setGlobalWorkDir(QFINDTESTDATA("data"));
- AddJob *addJob = archive->addFiles(files, destination, options);
+ AddJob *addJob = archive->addFiles(targetEntries, destination, options);
TestHelper::startAndWaitForResult(addJob);
- QVector<Archive::Entry*> resultedEntries = TestHelper::getEntryList(archive);
- TestHelper::verifyAddedEntriesWithDestination(files, destination, oldEntries, resultedEntries);
+ // Retrieve the resulting paths.
+ QStringList newPaths = getEntryPaths(archive);
+
+ // Check that the expected paths are now in the archive.
+ foreach (const auto &path, expectedNewPaths) {
+ QVERIFY(newPaths.contains(path));
+ }
QFETCH(uint, numberOfEntries);
QCOMPARE(archive->numberOfEntries(), numberOfEntries);
diff --git a/autotests/kerfuffle/addtoarchivetest.cpp b/autotests/kerfuffle/addtoarchivetest.cpp
index 34fedd5..2962d2d 100644
--- a/autotests/kerfuffle/addtoarchivetest.cpp
+++ b/autotests/kerfuffle/addtoarchivetest.cpp
@@ -24,6 +24,7 @@
*/
#include "addtoarchive.h"
+#include "jobs.h"
#include "pluginmanager.h"
#include "testhelper.h"
diff --git a/autotests/kerfuffle/copytest.cpp b/autotests/kerfuffle/copytest.cpp
index d538d39..a8ae18c 100644
--- a/autotests/kerfuffle/copytest.cpp
+++ b/autotests/kerfuffle/copytest.cpp
@@ -23,31 +23,21 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "abstractaddtest.h"
+#include "archiveentry.h"
+#include "jobs.h"
#include "testhelper.h"
+#include <QTest>
+
using namespace Kerfuffle;
-class CopyTest : public QObject
+class CopyTest : public AbstractAddTest
{
-Q_OBJECT
-
-private:
- void addAllFormatsRows(const QString &testName, const QString &archiveName, const QVector<Archive::Entry*> &entries, Archive::Entry *destination, uint numberOfEntries) {
- QStringList formats = QStringList()
- << QStringLiteral("7z")
- << QStringLiteral("rar")
- << QStringLiteral("tar.bz2")
- << QStringLiteral("zip");
-
- foreach (const QString &format, formats) {
- const QString testNameWithFormat = testName + QStringLiteral(" (") + format + QStringLiteral(")");
- QTest::newRow(testNameWithFormat.toUtf8())
- << archiveName + QLatin1Char('.') + format
- << entries
- << destination
- << numberOfEntries;
- }
- }
+ Q_OBJECT
+
+public:
+ CopyTest() : AbstractAddTest() {}
private Q_SLOTS:
void testCopying_data();
@@ -59,123 +49,189 @@ QTEST_GUILESS_MAIN(CopyTest)
void CopyTest::testCopying_data()
{
QTest::addColumn<QString>("archiveName");
- QTest::addColumn<QVector<Archive::Entry*>>("files");
+ QTest::addColumn<Plugin*>("plugin");
+ QTest::addColumn<QVector<Archive::Entry*>>("targetEntries");
QTest::addColumn<Archive::Entry*>("destination");
+ QTest::addColumn<QStringList>("expectedNewPaths");
QTest::addColumn<uint>("numberOfEntries");
- addAllFormatsRows(QStringLiteral("copy a single file"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("a.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 14);
-
- addAllFormatsRows(QStringLiteral("copy several files"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("a.txt")),
- new Archive::Entry(this, QStringLiteral("b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 15);
-
- addAllFormatsRows(QStringLiteral("copy a root directory"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 19);
-
- addAllFormatsRows(QStringLiteral("copy a root directory 2"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir2/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 17);
-
- addAllFormatsRows(QStringLiteral("copy a root directory 3"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir2/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("dir1/")),
- 17);
-
- addAllFormatsRows(QStringLiteral("copy a directory"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 16);
-
- addAllFormatsRows(QStringLiteral("copy several directories"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir2/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 23);
-
- addAllFormatsRows(QStringLiteral("copy several entries"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- 18);
-
- addAllFormatsRows(QStringLiteral("copy a directory inside itself"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("dir1/")),
- 19);
-
- addAllFormatsRows(QStringLiteral("copy a directory to the root"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("")),
- 16);
+ setupRows(QStringLiteral("copy a single file"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("a.txt")),
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/a.txt")
+ },
+ 14);
+
+ setupRows(QStringLiteral("copy several files"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("a.txt")),
+ new Archive::Entry(this, QStringLiteral("b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/a.txt"),
+ QStringLiteral("empty_dir/b.txt"),
+ },
+ 15);
+
+ setupRows(QStringLiteral("copy a root directory"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir1/"),
+ QStringLiteral("empty_dir/dir1/dir/"),
+ QStringLiteral("empty_dir/dir1/dir/a.txt"),
+ QStringLiteral("empty_dir/dir1/dir/b.txt"),
+ QStringLiteral("empty_dir/dir1/a.txt"),
+ QStringLiteral("empty_dir/dir1/b.txt")
+ },
+ 19);
+
+ setupRows(QStringLiteral("copy a root directory 2"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir2/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir2/"),
+ QStringLiteral("empty_dir/dir2/dir/"),
+ QStringLiteral("empty_dir/dir2/dir/a.txt"),
+ QStringLiteral("empty_dir/dir2/dir/b.txt")
+ },
+ 17);
+
+ setupRows(QStringLiteral("copy a root directory 3"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir2/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("dir1/")),
+ QStringList {
+ QStringLiteral("dir1/dir2/"),
+ QStringLiteral("dir1/dir2/dir/"),
+ QStringLiteral("dir1/dir2/dir/a.txt"),
+ QStringLiteral("dir1/dir2/dir/b.txt")
+ },
+ 17);
+
+ setupRows(QStringLiteral("copy a directory"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir/"),
+ QStringLiteral("empty_dir/dir/a.txt"),
+ QStringLiteral("empty_dir/dir/b.txt")
+ },
+ 16);
+
+ setupRows(QStringLiteral("copy several directories"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir2/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir1/"),
+ QStringLiteral("empty_dir/dir1/dir/"),
+ QStringLiteral("empty_dir/dir1/dir/a.txt"),
+ QStringLiteral("empty_dir/dir1/dir/b.txt"),
+ QStringLiteral("empty_dir/dir1/a.txt"),
+ QStringLiteral("empty_dir/dir1/b.txt"),
+ QStringLiteral("empty_dir/dir2/"),
+ QStringLiteral("empty_dir/dir2/dir/"),
+ QStringLiteral("empty_dir/dir2/dir/a.txt"),
+ QStringLiteral("empty_dir/dir2/dir/b.txt")
+ },
+ 23);
+
+ setupRows(QStringLiteral("copy several entries"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir/"),
+ QStringLiteral("empty_dir/dir/a.txt"),
+ QStringLiteral("empty_dir/dir/b.txt"),
+ QStringLiteral("empty_dir/a.txt"),
+ QStringLiteral("empty_dir/b.txt")
+ },
+ 18);
+
+ setupRows(QStringLiteral("copy a directory inside itself"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("dir1/")),
+ QStringList {
+ QStringLiteral("dir1/dir1/"),
+ QStringLiteral("dir1/dir1/dir/"),
+ QStringLiteral("dir1/dir1/dir/a.txt"),
+ QStringLiteral("dir1/dir1/dir/b.txt"),
+ QStringLiteral("dir1/dir1/a.txt"),
+ QStringLiteral("dir1/dir1/b.txt")
+ },
+ 19);
+
+ setupRows(QStringLiteral("copy a directory to the root"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("")),
+ QStringList {
+ QStringLiteral("dir/"),
+ QStringLiteral("dir/a.txt"),
+ QStringLiteral("dir/b.txt"),
+ },
+ 16);
}
void CopyTest::testCopying()
@@ -186,7 +242,10 @@ void CopyTest::testCopying()
const QString archivePath = temporaryDir.path() + QLatin1Char('/') + archiveName;
QVERIFY(QFile::copy(QFINDTESTDATA(QStringLiteral("data/") + archiveName), archivePath));
- auto loadJob = Archive::load(archivePath);
+ QFETCH(Plugin*, plugin);
+ QVERIFY(plugin);
+
+ auto loadJob = Archive::load(archivePath, plugin);
QVERIFY(loadJob);
loadJob->setAutoDelete(false);
@@ -200,18 +259,40 @@ void CopyTest::testCopying()
QSKIP("Could not find a plugin to handle the archive. Skipping test.", SkipSingle);
}
- QFETCH(QVector<Archive::Entry*>, files);
+ QFETCH(QVector<Archive::Entry*>, targetEntries);
QFETCH(Archive::Entry*, destination);
+ QFETCH(QStringList, expectedNewPaths);
+
+ // Retrieve current paths in the archive.
+ QStringList oldPaths = getEntryPaths(archive);
+
+ // Check that the entries to be copied are in the archive.
+ foreach (const auto entry, targetEntries) {
+ QVERIFY(oldPaths.contains(entry->fullPath()));
+ }
- const QVector<Archive::Entry*> oldEntries = TestHelper::getEntryList(archive);
+ // Check that the expected paths (after the CopyJob) are not in the archive.
+ foreach (const auto &expectedPath, expectedNewPaths) {
+ QVERIFY(!oldPaths.contains(expectedPath));
+ }
CompressionOptions options;
options.setGlobalWorkDir(QFINDTESTDATA("data"));
- CopyJob *copyJob = archive->copyFiles(files, destination, options);
+ CopyJob *copyJob = archive->copyFiles(targetEntries, destination, options);
TestHelper::startAndWaitForResult(copyJob);
- QVector<Archive::Entry*> resultedEntries = TestHelper::getEntryList(archive);
- TestHelper::verifyCopiedEntriesWithDestination(files, destination, oldEntries, resultedEntries);
+ // Retrieve the resulting paths.
+ QStringList newPaths = getEntryPaths(archive);
+
+ // Check that the expected paths are now in the archive.
+ foreach (const auto &path, expectedNewPaths) {
+ QVERIFY(newPaths.contains(path));
+ }
+
+ // Check also that the target paths are still in the archive.
+ foreach (const auto entry, targetEntries) {
+ QVERIFY(newPaths.contains(entry->fullPath()));
+ }
QFETCH(uint, numberOfEntries);
QCOMPARE(archive->numberOfEntries(), numberOfEntries);
diff --git a/autotests/kerfuffle/extracttest.cpp b/autotests/kerfuffle/extracttest.cpp
index 4469bfb..59d8e0c 100644
--- a/autotests/kerfuffle/extracttest.cpp
+++ b/autotests/kerfuffle/extracttest.cpp
@@ -24,6 +24,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "archive_kerfuffle.h"
+#include "jobs.h"
#include "testhelper.h"
#include <QDirIterator>
diff --git a/autotests/kerfuffle/movetest.cpp b/autotests/kerfuffle/movetest.cpp
index 00cf923..3f61fd5 100644
--- a/autotests/kerfuffle/movetest.cpp
+++ b/autotests/kerfuffle/movetest.cpp
@@ -23,58 +23,26 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "abstractaddtest.h"
+#include "archiveentry.h"
+#include "jobs.h"
#include "testhelper.h"
-#include "pluginmanager.h"
+
+#include <QMimeDatabase>
+#include <QTest>
using namespace Kerfuffle;
-class MoveTest : public QObject
+class MoveTest : public AbstractAddTest
{
Q_OBJECT
+public:
+ MoveTest() : AbstractAddTest() {}
+
private Q_SLOTS:
void testMoving_data();
void testMoving();
-
-private:
- void addAllFormatsRows(const QString &testName, const QString &archiveName, const QVector<Archive::Entry*> &targetEntries, Archive::Entry *destination, const QStringList &expectedNewPaths, uint numberOfEntries) {
- 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) {
- const QString filename = QStringLiteral("%1.%2").arg(archiveName, format);
- const auto mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
-
- const auto plugins = m_pluginManager.preferredWritePluginsFor(mime);
- foreach (const auto plugin, plugins) {
- QTest::newRow(QStringLiteral("%1 (%2, %3)").arg(testName, format, plugin->metaData().pluginId()).toUtf8())
- << filename
- << plugin
- << targetEntries
- << destination
- << expectedNewPaths
- << numberOfEntries;
- }
- }
- }
-
- // TODO: move this to testhelper.
- QStringList getEntryPaths(Archive *archive)
- {
- QStringList paths;
- auto loadJob = Archive::load(archive->fileName());
- QObject::connect(loadJob, &Job::newEntry, [&paths](Archive::Entry* entry) { paths << entry->fullPath(); });
- TestHelper::startAndWaitForResult(loadJob);
-
- return paths;
- }
-
- PluginManager m_pluginManager;
};
QTEST_GUILESS_MAIN(MoveTest)
@@ -88,141 +56,141 @@ void MoveTest::testMoving_data()
QTest::addColumn<QStringList>("expectedNewPaths");
QTest::addColumn<uint>("numberOfEntries");
- addAllFormatsRows(QStringLiteral("replace a single file"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("a.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/a.txt")),
- QStringList {
- QStringLiteral("empty_dir/a.txt")
- },
- 13);
-
- addAllFormatsRows(QStringLiteral("replace several files"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("a.txt")),
- new Archive::Entry(this, QStringLiteral("b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- QStringList {
- QStringLiteral("empty_dir/a.txt"),
- QStringLiteral("empty_dir/b.txt")
- },
- 13);
-
- addAllFormatsRows(QStringLiteral("replace a root directory"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- QStringList {
- QStringLiteral("empty_dir/a.txt"),
- QStringLiteral("empty_dir/b.txt"),
- QStringLiteral("empty_dir/dir/"),
- QStringLiteral("empty_dir/dir/a.txt"),
- QStringLiteral("empty_dir/dir/b.txt"),
- },
- 13);
-
- addAllFormatsRows(QStringLiteral("replace a root directory 2"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir2/dir/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/dir/")),
- QStringList {
- QStringLiteral("empty_dir/dir/"),
- QStringLiteral("empty_dir/dir/a.txt"),
- QStringLiteral("empty_dir/dir/b.txt"),
- },
- 13);
-
- addAllFormatsRows(QStringLiteral("replace a directory"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/dir/")),
- QStringList {
- QStringLiteral("empty_dir/dir/"),
- QStringLiteral("empty_dir/dir/a.txt"),
- QStringLiteral("empty_dir/dir/b.txt"),
- },
- 13);
-
- addAllFormatsRows(QStringLiteral("replace several directories"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir2/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- QStringList {
- QStringLiteral("empty_dir/dir1/"),
- QStringLiteral("empty_dir/dir1/a.txt"),
- QStringLiteral("empty_dir/dir1/b.txt"),
- QStringLiteral("empty_dir/dir1/dir/"),
- QStringLiteral("empty_dir/dir1/dir/a.txt"),
- QStringLiteral("empty_dir/dir1/dir/b.txt"),
- QStringLiteral("empty_dir/dir2/"),
- QStringLiteral("empty_dir/dir2/dir/"),
- QStringLiteral("empty_dir/dir2/dir/a.txt"),
- QStringLiteral("empty_dir/dir2/dir/b.txt")
- },
- 13);
-
- addAllFormatsRows(QStringLiteral("replace several entries"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("empty_dir/")),
- QStringList {
- QStringLiteral("empty_dir/dir/"),
- QStringLiteral("empty_dir/dir/a.txt"),
- QStringLiteral("empty_dir/dir/b.txt"),
- QStringLiteral("empty_dir/a.txt"),
- QStringLiteral("empty_dir/b.txt")
- },
- 13);
-
- addAllFormatsRows(QStringLiteral("move a directory to the root"),
- QStringLiteral("test"),
- QVector<Archive::Entry*> {
- new Archive::Entry(this, QStringLiteral("dir1/dir/")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
- new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
- },
- new Archive::Entry(this, QStringLiteral("dir/")),
- QStringList {
- QStringLiteral("dir/"),
- QStringLiteral("dir/a.txt"),
- QStringLiteral("dir/b.txt"),
- },
- 13);
+ setupRows(QStringLiteral("replace a single file"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("a.txt")),
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/a.txt")),
+ QStringList {
+ QStringLiteral("empty_dir/a.txt")
+ },
+ 13);
+
+ setupRows(QStringLiteral("replace several files"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("a.txt")),
+ new Archive::Entry(this, QStringLiteral("b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/a.txt"),
+ QStringLiteral("empty_dir/b.txt")
+ },
+ 13);
+
+ setupRows(QStringLiteral("replace a root directory"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/a.txt"),
+ QStringLiteral("empty_dir/b.txt"),
+ QStringLiteral("empty_dir/dir/"),
+ QStringLiteral("empty_dir/dir/a.txt"),
+ QStringLiteral("empty_dir/dir/b.txt")
+ },
+ 13);
+
+ setupRows(QStringLiteral("replace a root directory 2"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir2/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir/"),
+ QStringLiteral("empty_dir/dir/a.txt"),
+ QStringLiteral("empty_dir/dir/b.txt")
+ },
+ 13);
+
+ setupRows(QStringLiteral("replace a directory"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir/"),
+ QStringLiteral("empty_dir/dir/a.txt"),
+ QStringLiteral("empty_dir/dir/b.txt")
+ },
+ 13);
+
+ setupRows(QStringLiteral("replace several directories"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir2/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir1/"),
+ QStringLiteral("empty_dir/dir1/a.txt"),
+ QStringLiteral("empty_dir/dir1/b.txt"),
+ QStringLiteral("empty_dir/dir1/dir/"),
+ QStringLiteral("empty_dir/dir1/dir/a.txt"),
+ QStringLiteral("empty_dir/dir1/dir/b.txt"),
+ QStringLiteral("empty_dir/dir2/"),
+ QStringLiteral("empty_dir/dir2/dir/"),
+ QStringLiteral("empty_dir/dir2/dir/a.txt"),
+ QStringLiteral("empty_dir/dir2/dir/b.txt")
+ },
+ 13);
+
+ setupRows(QStringLiteral("replace several entries"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir/"),
+ QStringLiteral("empty_dir/dir/a.txt"),
+ QStringLiteral("empty_dir/dir/b.txt"),
+ QStringLiteral("empty_dir/a.txt"),
+ QStringLiteral("empty_dir/b.txt")
+ },
+ 13);
+
+ setupRows(QStringLiteral("move a directory to the root"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("dir1/dir/")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
+ new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt"))
+ },
+ new Archive::Entry(this, QStringLiteral("dir/")),
+ QStringList {
+ QStringLiteral("dir/"),
+ QStringLiteral("dir/a.txt"),
+ QStringLiteral("dir/b.txt")
+ },
+ 13);
}
void MoveTest::testMoving()
@@ -245,7 +213,7 @@ void MoveTest::testMoving()
QVERIFY(archive);
if (!archive->isValid()) {
- QSKIP("The plugin could not load the archive. Skipping test.", SkipSingle);
+ QSKIP("Could not find a plugin to handle the archive. Skipping test.", SkipSingle);
}
QFETCH(QVector<Archive::Entry*>, targetEntries);
diff --git a/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp b/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp
index de65636..52d7198 100644
--- a/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp
+++ b/autotests/plugins/cliunarchiverplugin/cliunarchivertest.cpp
@@ -18,6 +18,7 @@
*/
#include "cliunarchivertest.h"
+#include "jobs.h"
#include "testhelper.h"
#include <KPluginLoader>
diff --git a/autotests/testhelper/CMakeLists.txt b/autotests/testhelper/CMakeLists.txt
index 5c44a2f..85e7466 100644
--- a/autotests/testhelper/CMakeLists.txt
+++ b/autotests/testhelper/CMakeLists.txt
@@ -1,9 +1,8 @@
set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set(TESTHELPER_SOURCES
- testhelper.h
- testhelper.cpp
-)
+ abstractaddtest.cpp
+ testhelper.cpp)
add_library(testhelper STATIC ${TESTHELPER_SOURCES})
target_link_libraries(testhelper Qt5::Test kerfuffle)
diff --git a/autotests/testhelper/abstractaddtest.cpp b/autotests/testhelper/abstractaddtest.cpp
new file mode 100644
index 0000000..62c46ee
--- /dev/null
+++ b/autotests/testhelper/abstractaddtest.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2016 Vladyslav Batyrenko <mvlabat@gmail.com>
+ * Copyright (c) 2016 Elvis Angelaccio <elvis.angelaccio@kde.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "abstractaddtest.h"
+
+#include "jobs.h"
+#include "testhelper.h"
+
+#include <QEventLoop>
+#include <QTest>
+
+using namespace Kerfuffle;
+
+QStringList AbstractAddTest::getEntryPaths(Archive *archive)
+{
+ QStringList paths;
+ auto loadJob = Archive::load(archive->fileName());
+ QObject::connect(loadJob, &Job::newEntry, [&paths](Archive::Entry* entry) { paths << entry->fullPath(); });
+ TestHelper::startAndWaitForResult(loadJob);
+
+ return paths;
+}
+
+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) {
+ const QString filename = QStringLiteral("%1.%2").arg(archiveName, format);
+ const auto mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
+
+ const auto plugins = m_pluginManager.preferredWritePluginsFor(mime);
+ foreach (const auto plugin, plugins) {
+ QTest::newRow(QStringLiteral("%1 (%2, %3)").arg(testName, format, plugin->metaData().pluginId()).toUtf8())
+ << filename
+ << plugin
+ << targetEntries
+ << destination
+ << expectedNewPaths
+ << numberOfEntries;
+ }
+ }
+}
diff --git a/autotests/testhelper/abstractaddtest.h b/autotests/testhelper/abstractaddtest.h
new file mode 100644
index 0000000..25998c1
--- /dev/null
+++ b/autotests/testhelper/abstractaddtest.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016 Vladyslav Batyrenko <mvlabat@gmail.com>
+ * Copyright (c) 2016 Elvis Angelaccio <elvis.angelaccio@kde.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ABSTRACTADDTEST_H
+#define ABSTRACTADDTEST_H
+
+#include "archive_kerfuffle.h"
+#include "pluginmanager.h"
+
+/**
+ * Base class for tests about Add/Copy/Move jobs.
+ * Make sure to call the constructor in order to load the plugins.
+ */
+class AbstractAddTest : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ static QStringList getEntryPaths(Kerfuffle::Archive *archive);
+
+ /**
+ * Setup test cases for each format and for each plugin.
+ * @param testName Name of the test case shown in the debug output
+ * @param archiveName Archive name. The extension of the tested formats will be appended to it.
+ * @param targetEntries Entries passed to the job.
+ * @param destination Destination entry passed to the job.
+ * @param expectedNewPaths New expected paths that the job should create.
+ * @param numberOfEntries Number of entries in the archive expected after the job ends.
+ */
+ void setupRows(const QString &testName, const QString &archiveName, const QVector<Kerfuffle::Archive::Entry*> &targetEntries, Kerfuffle::Archive::Entry *destination, const QStringList &expectedNewPaths, uint numberOfEntries) const;
+
+protected:
+
+ Kerfuffle::PluginManager m_pluginManager;
+};
+
+#endif //ABSTRACTADDTEST_H
diff --git a/autotests/testhelper/testhelper.cpp b/autotests/testhelper/testhelper.cpp
index 9edb7ad..79a5954 100644
--- a/autotests/testhelper/testhelper.cpp
+++ b/autotests/testhelper/testhelper.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016 Vladyslav Batyrenko <mvlabat@gmail.com>
+ * Copyright (c) 2016 Elvis Angelaccio <elvis.angelaccio@kde.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,6 +26,10 @@
#include "testhelper.h"
+#include <KJob>
+
+#include <QEventLoop>
+
void TestHelper::startAndWaitForResult(KJob *job)
{
QEventLoop eventLoop;
@@ -33,104 +38,3 @@ void TestHelper::startAndWaitForResult(KJob *job)
eventLoop.exec(); // krazy:exclude=crashy
}
-QVector<Archive::Entry*> TestHelper::getEntryList(Archive *archive)
-{
- QVector<Archive::Entry*> list = QVector<Archive::Entry*>();
- auto loadJob = Archive::load(archive->fileName());
- QObject::connect(loadJob, &Job::newEntry, [&list](Archive::Entry* entry) { list << entry; });
- startAndWaitForResult(loadJob);
-
- return list;
-}
-
-void TestHelper::verifyAddedEntriesWithDestination(const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination, const QVector<Archive::Entry*> &oldEntries, const QVector<Archive::Entry*> &newEntries)
-{
- QStringList expectedPaths = getExpectedNewEntryPaths(argumentEntries, destination);
- QStringList actualPaths = ReadOnlyArchiveInterface::entryFullPaths(newEntries);
- foreach (const QString &path, expectedPaths) {
- QVERIFY2(actualPaths.contains(path), (QStringLiteral("No ") + path + QStringLiteral(" inside the archive (new entry)")).toUtf8());
- }
- foreach (const Archive::Entry *entry, oldEntries) {
- const QString path = entry->fullPath();
- QVERIFY2(actualPaths.contains(path), (QStringLiteral("No ") + path + QStringLiteral(" inside the archive (old entry)")).toUtf8());
- }
-}
-
-void TestHelper::verifyCopiedEntriesWithDestination(const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination, const QVector<Archive::Entry*> &oldEntries, const QVector<Archive::Entry*> &newEntries)
-{
- QStringList expectedPaths = getExpectedCopiedEntryPaths(oldEntries, argumentEntries, destination);
- QStringList actualPaths = ReadOnlyArchiveInterface::entryFullPaths(newEntries);
- foreach (const QString &path, expectedPaths) {
- QVERIFY2(actualPaths.contains(path), (QStringLiteral("No ") + path + QStringLiteral(" inside the archive")).toUtf8());
- }
- foreach (const QString &path, actualPaths) {
- QVERIFY2(expectedPaths.contains(path), (QStringLiteral("Entry ") + path + QStringLiteral(" is not expected to be inside the archive")).toUtf8());
- }
-}
-
-QStringList TestHelper::getExpectedNewEntryPaths(const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination)
-{
- QStringList expectedPaths = QStringList();
- const QString testDataPath = QFINDTESTDATA("data") + QLatin1Char('/');
-
- foreach (const Archive::Entry *entry, argumentEntries) {
- const QString entryPath = entry->fullPath();
- expectedPaths << destination->fullPath() + entryPath;
-
- if (entryPath.right(1) == QLatin1String("/")) {
- const QString workingDirectory = testDataPath + QLatin1Char('/') + entry->fullPath(NoTrailingSlash);
- QDirIterator it(workingDirectory, QDir::AllEntries | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
- while (it.hasNext()) {
- QString path = it.next();
- path = destination->fullPath() + path.right(path.count() - testDataPath.count() - 1);
- if (it.fileInfo().isDir()) {
- path += QLatin1Char('/');
- }
- expectedPaths << path;
- }
- }
- }
- return expectedPaths;
-}
-
-QStringList TestHelper::getExpectedCopiedEntryPaths(const QVector<Archive::Entry*> &entryList, const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination)
-{
- QStringList expectedPaths = QStringList();
- QMap<QString, Archive::Entry*> entryMap = getEntryMap(entryList);
- QStringList argumentPaths = ReadOnlyArchiveInterface::entryFullPaths(argumentEntries);
- QString lastCopiedFolder;
- // Destination path doesn't contain a target entry name, so we have to remember to include it while copying
- // folder contents.
- int nameLength = 0;
- foreach (const Archive::Entry *entry, entryMap) {
- const QString entryPath = entry->fullPath();
- if (lastCopiedFolder.count() > 0 && entryPath.startsWith(lastCopiedFolder)) {
- expectedPaths << destination->fullPath() + entryPath.right(entryPath.count() - lastCopiedFolder.count() + nameLength);
- } else if (argumentPaths.contains(entryPath)) {
- QString expectedPath = destination->fullPath() + entry->name();
- if (entryPath.right(1) == QLatin1String("/")) {
- expectedPath += QLatin1Char('/');
- nameLength = entry->name().count() + 1; // plus slash
- lastCopiedFolder = entryPath;
- } else {
- nameLength = 0;
- lastCopiedFolder = QString();
- }
- expectedPaths << expectedPath;
- } else {
- nameLength = 0;
- lastCopiedFolder = QString();
- }
- expectedPaths << entryPath;
- }
- return expectedPaths;
-}
-
-QMap<QString, Archive::Entry*> TestHelper::getEntryMap(const QVector<Archive::Entry*> &entries)
-{
- QMap<QString, Archive::Entry*> map;
- foreach (Archive::Entry* entry, entries) {
- map.insert(entry->fullPath(), entry);
- }
- return map;
-}
diff --git a/autotests/testhelper/testhelper.h b/autotests/testhelper/testhelper.h
index c3ee2f5..e355baa 100644
--- a/autotests/testhelper/testhelper.h
+++ b/autotests/testhelper/testhelper.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016 Vladyslav Batyrenko <mvlabat@gmail.com>
+ * Copyright (c) 2016 Elvis Angelaccio <elvis.angelaccio@kde.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,38 +27,12 @@
#ifndef TESTHELPER_H
#define TESTHELPER_H
-#include "kerfuffle/jobs.h"
-#include "kerfuffle/archiveentry.h"
+class KJob;
-#include <QTest>
-#include <QEventLoop>
-#include <QDirIterator>
-
-using namespace Kerfuffle;
-
-class TestHelper
+namespace TestHelper
{
-public:
-
- static void startAndWaitForResult(KJob *job);
- static QVector<Archive::Entry*> getEntryList(Archive *archive);
- static void verifyAddedEntriesWithDestination(const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination, const QVector<Archive::Entry*> &oldEntries, const QVector<Archive::Entry*> &newEntries);
- static void verifyCopiedEntriesWithDestination(const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination, const QVector<Archive::Entry*> &oldEntries, const QVector<Archive::Entry*> &newEntries);
+ void startAndWaitForResult(KJob *job);
-private:
- TestHelper() {}
-
- static QStringList getExpectedNewEntryPaths(const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination);
- static QStringList getExpectedMovedEntryPaths(const QVector<Archive::Entry*> &entryList, const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry* destination);
- static QStringList getExpectedCopiedEntryPaths(const QVector<Archive::Entry*> &entryList, const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry* destination);
-
- /**
- * Returns map of entries.
- *
- * It's useful when we need a sorted list of entries.
- */
- static QMap<QString, Archive::Entry*> getEntryMap(const QVector<Archive::Entry*> &entries);
};
-
#endif //TESTHELPER_H