summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-15 17:24:54 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-15 17:41:24 (GMT)
commit38e1b6a1a65472b5f83a3bef9d0e3f6452e088fc (patch)
treeddcbdf60dfaa4ff685c5bacf4459bcf90826c372
parent89a7b5bbb52ee6acac620b50efea419446795e82 (diff)
Drop testhelper code in movetest
Instead, manually define what we actually want as expected result. This brings the number of failures down to only four.
-rw-r--r--autotests/kerfuffle/movetest.cpp119
-rw-r--r--autotests/testhelper/testhelper.cpp68
-rw-r--r--autotests/testhelper/testhelper.h1
-rw-r--r--kerfuffle/archive_kerfuffle.cpp2
4 files changed, 103 insertions, 87 deletions
diff --git a/autotests/kerfuffle/movetest.cpp b/autotests/kerfuffle/movetest.cpp
index bd290d0..c49b1be 100644
--- a/autotests/kerfuffle/movetest.cpp
+++ b/autotests/kerfuffle/movetest.cpp
@@ -32,7 +32,7 @@ class MoveTest : public QObject
Q_OBJECT
private:
- void addAllFormatsRows(const QString &testName, const QString &archiveName, const QVector<Archive::Entry*> &entries, Archive::Entry *destination) {
+ void addAllFormatsRows(const QString &testName, const QString &archiveName, const QVector<Archive::Entry*> &targetEntries, Archive::Entry *destination, const QStringList &expectedNewPaths) {
QStringList formats = QStringList()
<< QStringLiteral("7z")
<< QStringLiteral("rar")
@@ -43,11 +43,23 @@ private:
const QString testNameWithFormat = testName + QStringLiteral(" (") + format + QStringLiteral(")");
QTest::newRow(testNameWithFormat.toUtf8())
<< archiveName + QLatin1Char('.') + format
- << entries
- << destination;
+ << targetEntries
+ << destination
+ << expectedNewPaths;
}
}
+ // 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;
+ }
+
private Q_SLOTS:
void testMoving_data();
void testMoving();
@@ -58,15 +70,19 @@ QTEST_GUILESS_MAIN(MoveTest)
void MoveTest::testMoving_data()
{
QTest::addColumn<QString>("archiveName");
- QTest::addColumn<QVector<Archive::Entry*>>("files");
+ QTest::addColumn<QVector<Archive::Entry*>>("targetEntries");
QTest::addColumn<Archive::Entry*>("destination");
+ QTest::addColumn<QStringList>("expectedNewPaths");
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")));
+ new Archive::Entry(this, QStringLiteral("empty_dir/a.txt")),
+ QStringList {
+ QStringLiteral("empty_dir/a.txt")
+ });
addAllFormatsRows(QStringLiteral("replace several files"),
QStringLiteral("test"),
@@ -74,7 +90,11 @@ void MoveTest::testMoving_data()
new Archive::Entry(this, QStringLiteral("a.txt")),
new Archive::Entry(this, QStringLiteral("b.txt")),
},
- new Archive::Entry(this, QStringLiteral("empty_dir/")));
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/a.txt"),
+ QStringLiteral("empty_dir/b.txt")
+ });
addAllFormatsRows(QStringLiteral("replace a root directory"),
QStringLiteral("test"),
@@ -86,7 +106,14 @@ void MoveTest::testMoving_data()
new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
},
- new Archive::Entry(this, QStringLiteral("empty_dir/dir/")));
+ 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"),
+ });
addAllFormatsRows(QStringLiteral("replace a root directory 2"),
QStringLiteral("test"),
@@ -96,7 +123,12 @@ void MoveTest::testMoving_data()
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/")));
+ new Archive::Entry(this, QStringLiteral("empty_dir/")),
+ QStringList {
+ QStringLiteral("empty_dir/dir/"),
+ QStringLiteral("empty_dir/dir/a.txt"),
+ QStringLiteral("empty_dir/dir/b.txt"),
+ });
addAllFormatsRows(QStringLiteral("replace a directory"),
QStringLiteral("test"),
@@ -105,7 +137,12 @@ void MoveTest::testMoving_data()
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/")));
+ 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"),
+ });
addAllFormatsRows(QStringLiteral("replace several directories"),
QStringLiteral("test"),
@@ -121,7 +158,19 @@ void MoveTest::testMoving_data()
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/")));
+ 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")
+ });
addAllFormatsRows(QStringLiteral("replace several entries"),
QStringLiteral("test"),
@@ -132,7 +181,14 @@ void MoveTest::testMoving_data()
new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
},
- new Archive::Entry(this, QStringLiteral("empty_dir/")));
+ 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")
+ });
addAllFormatsRows(QStringLiteral("move a directory to the root"),
QStringLiteral("test"),
@@ -141,7 +197,12 @@ void MoveTest::testMoving_data()
new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
},
- new Archive::Entry(this, QStringLiteral("dir/")));
+ new Archive::Entry(this, QStringLiteral("dir/")),
+ QStringList {
+ QStringLiteral("dir/"),
+ QStringLiteral("dir/a.txt"),
+ QStringLiteral("dir/b.txt"),
+ });
}
void MoveTest::testMoving()
@@ -164,18 +225,40 @@ void MoveTest::testMoving()
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);
- CompressionOptions options = CompressionOptions();
+ // Check that the entries to be moved are in the archive.
+ foreach (const auto entry, targetEntries) {
+ QVERIFY(oldPaths.contains(entry->fullPath()));
+ }
+
+ // Check that the expected paths (after the MoveJob) are not in the archive.
+ foreach (const auto &expectedPath, expectedNewPaths) {
+ QVERIFY(!oldPaths.contains(expectedPath));
+ }
+
+ CompressionOptions options;
options.setGlobalWorkDir(QFINDTESTDATA("data"));
- MoveJob *moveJob = archive->moveFiles(files, destination, options);
+ MoveJob *moveJob = archive->moveFiles(targetEntries, destination, options);
TestHelper::startAndWaitForResult(moveJob);
- QVector<Archive::Entry*> resultedEntries = TestHelper::getEntryList(archive);
- TestHelper::verifyMovedEntriesWithDestination(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 that the target paths are no longer in the archive.
+ foreach (const auto entry, targetEntries) {
+ QVERIFY(!newPaths.contains(entry->fullPath()));
+ }
loadJob->deleteLater();
archive->deleteLater();
diff --git a/autotests/testhelper/testhelper.cpp b/autotests/testhelper/testhelper.cpp
index e011764..9edb7ad 100644
--- a/autotests/testhelper/testhelper.cpp
+++ b/autotests/testhelper/testhelper.cpp
@@ -39,6 +39,7 @@ QVector<Archive::Entry*> TestHelper::getEntryList(Archive *archive)
auto loadJob = Archive::load(archive->fileName());
QObject::connect(loadJob, &Job::newEntry, [&list](Archive::Entry* entry) { list << entry; });
startAndWaitForResult(loadJob);
+
return list;
}
@@ -55,22 +56,6 @@ void TestHelper::verifyAddedEntriesWithDestination(const QVector<Archive::Entry*
}
}
-void TestHelper::verifyMovedEntriesWithDestination(const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination, const QVector<Archive::Entry*> &oldEntries, const QVector<Archive::Entry*> &newEntries)
-{
- QStringList expectedPaths = getExpectedMovedEntryPaths(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());
- }
- foreach (const Archive::Entry *entry, argumentEntries) {
- const QString path = entry->fullPath();
- QVERIFY2(!actualPaths.contains(path), (QStringLiteral("Entry ") + path + QStringLiteral(" is still inside the archive, when it shouldn't be")).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);
@@ -108,57 +93,6 @@ QStringList TestHelper::getExpectedNewEntryPaths(const QVector<Archive::Entry*>
return expectedPaths;
}
-QStringList TestHelper::getExpectedMovedEntryPaths(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 lastMovedFolder;
- if (ReadOnlyArchiveInterface::entriesWithoutChildren(argumentEntries).count() > 1) {
- // Destination path doesn't contain a target entry name, so we have to remember to include it while moving
- // folder contents.
- int nameLength = 0;
- foreach (const Archive::Entry *entry, entryMap) {
- const QString entryPath = entry->fullPath();
- if (lastMovedFolder.count() > 0 && entryPath.startsWith(lastMovedFolder)) {
- expectedPaths << destination->fullPath() + entryPath.right(entryPath.count() - lastMovedFolder.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
- lastMovedFolder = entryPath;
- } else {
- nameLength = 0;
- lastMovedFolder = QString();
- }
- expectedPaths << expectedPath;
- } else {
- expectedPaths << entryPath;
- nameLength = 0;
- lastMovedFolder = QString();
- }
- }
- } else {
- foreach (const Archive::Entry *entry, entryMap) {
- const QString entryPath = entry->fullPath();
- if (lastMovedFolder.count() > 0 && entryPath.startsWith(lastMovedFolder)) {
- expectedPaths << destination->fullPath() + entryPath.right(entryPath.count() - lastMovedFolder.count());
- } else if (argumentPaths.contains(entryPath)) {
- if (entryPath.right(1) == QLatin1String("/")) {
- lastMovedFolder = entryPath;
- } else if (lastMovedFolder.count() > 0) {
- lastMovedFolder = QString();
- }
- expectedPaths << destination->fullPath();
- } else {
- expectedPaths << entryPath;
- }
- }
- }
- return expectedPaths;
-}
-
QStringList TestHelper::getExpectedCopiedEntryPaths(const QVector<Archive::Entry*> &entryList, const QVector<Archive::Entry*> &argumentEntries, const Archive::Entry *destination)
{
QStringList expectedPaths = QStringList();
diff --git a/autotests/testhelper/testhelper.h b/autotests/testhelper/testhelper.h
index 29c4364..c3ee2f5 100644
--- a/autotests/testhelper/testhelper.h
+++ b/autotests/testhelper/testhelper.h
@@ -42,7 +42,6 @@ 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 verifyMovedEntriesWithDestination(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);
private:
diff --git a/kerfuffle/archive_kerfuffle.cpp b/kerfuffle/archive_kerfuffle.cpp
index 2d92ae3..047fa60 100644
--- a/kerfuffle/archive_kerfuffle.cpp
+++ b/kerfuffle/archive_kerfuffle.cpp
@@ -422,7 +422,7 @@ MoveJob* Archive::moveFiles(const QVector<Archive::Entry*> &files, Archive::Entr
newOptions.setEncryptedArchiveHint(true);
}
- qCDebug(ARK) << "Going to move files" << files << "with options" << newOptions;
+ qCDebug(ARK) << "Going to move files" << files << "to destinatian" << destination << "with options" << newOptions;
Q_ASSERT(!m_iface->isReadOnly());
MoveJob *newJob = new MoveJob(files, destination, newOptions, static_cast<ReadWriteArchiveInterface*>(m_iface));