Commit 34a46359 authored by Ragnar Thomsen's avatar Ragnar Thomsen
Browse files

Check numberOfEntries in Add-, Copy- and MoveTest

Verify that ReadOnlyArchiveInterface::m_numberOfEntries is updated
properly in these tests.
parent ef1753b4
......@@ -32,7 +32,7 @@ class AddTest : 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*> &entries, Archive::Entry *destination, uint numberOfEntries) {
QStringList formats = QStringList()
<< QStringLiteral("7z")
<< QStringLiteral("rar")
......@@ -44,7 +44,8 @@ void addAllFormatsRows(const QString &testName, const QString &archiveName, cons
QTest::newRow(testNameWithFormat.toUtf8())
<< archiveName + QLatin1Char('.') + format
<< entries
<< destination;
<< destination
<< numberOfEntries;
}
}
......@@ -60,6 +61,7 @@ void AddTest::testAdding_data()
QTest::addColumn<QString>("archiveName");
QTest::addColumn<QVector<Archive::Entry*>>("files");
QTest::addColumn<Archive::Entry*>("destination");
QTest::addColumn<uint>("numberOfEntries");
addAllFormatsRows(QStringLiteral("without destination"),
QStringLiteral("test"),
......@@ -67,7 +69,8 @@ void AddTest::testAdding_data()
new Archive::Entry(this, QStringLiteral("textfile1.txt")),
new Archive::Entry(this, QStringLiteral("textfile2.txt")),
},
new Archive::Entry(this));
new Archive::Entry(this),
15);
addAllFormatsRows(QStringLiteral("with destination, files"),
QStringLiteral("test"),
......@@ -75,28 +78,32 @@ void AddTest::testAdding_data()
new Archive::Entry(this, QStringLiteral("textfile1.txt")),
new Archive::Entry(this, QStringLiteral("textfile2.txt")),
},
new Archive::Entry(this, QStringLiteral("empty_dir/")));
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/")));
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));
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/")));
new Archive::Entry(this, QStringLiteral("empty_dir/")),
17);
}
void AddTest::testAdding()
......@@ -132,6 +139,9 @@ void AddTest::testAdding()
QVector<Archive::Entry*> resultedEntries = TestHelper::getEntryList(archive);
TestHelper::verifyAddedEntriesWithDestination(files, destination, oldEntries, resultedEntries);
QFETCH(uint, numberOfEntries);
QCOMPARE(archive->numberOfEntries(), numberOfEntries);
loadJob->deleteLater();
archive->deleteLater();
}
......
......@@ -32,7 +32,7 @@ class CopyTest : 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*> &entries, Archive::Entry *destination, uint numberOfEntries) {
QStringList formats = QStringList()
<< QStringLiteral("7z")
<< QStringLiteral("rar")
......@@ -44,7 +44,8 @@ private:
QTest::newRow(testNameWithFormat.toUtf8())
<< archiveName + QLatin1Char('.') + format
<< entries
<< destination;
<< destination
<< numberOfEntries;
}
}
......@@ -60,13 +61,15 @@ void CopyTest::testCopying_data()
QTest::addColumn<QString>("archiveName");
QTest::addColumn<QVector<Archive::Entry*>>("files");
QTest::addColumn<Archive::Entry*>("destination");
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/")));
new Archive::Entry(this, QStringLiteral("empty_dir/")),
14);
addAllFormatsRows(QStringLiteral("copy several files"),
QStringLiteral("test"),
......@@ -74,7 +77,8 @@ void CopyTest::testCopying_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/")),
15);
addAllFormatsRows(QStringLiteral("copy a root directory"),
QStringLiteral("test"),
......@@ -86,7 +90,8 @@ void CopyTest::testCopying_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/")),
19);
addAllFormatsRows(QStringLiteral("copy a root directory 2"),
QStringLiteral("test"),
......@@ -96,7 +101,8 @@ void CopyTest::testCopying_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/")),
17);
addAllFormatsRows(QStringLiteral("copy a root directory 3"),
QStringLiteral("test"),
......@@ -106,7 +112,8 @@ void CopyTest::testCopying_data()
new Archive::Entry(this, QStringLiteral("dir2/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir2/dir/b.txt")),
},
new Archive::Entry(this, QStringLiteral("dir1/")));
new Archive::Entry(this, QStringLiteral("dir1/")),
17);
addAllFormatsRows(QStringLiteral("copy a directory"),
QStringLiteral("test"),
......@@ -115,7 +122,8 @@ void CopyTest::testCopying_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/")));
new Archive::Entry(this, QStringLiteral("empty_dir/")),
16);
addAllFormatsRows(QStringLiteral("copy several directories"),
QStringLiteral("test"),
......@@ -131,7 +139,8 @@ void CopyTest::testCopying_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/")),
23);
addAllFormatsRows(QStringLiteral("copy several entries"),
QStringLiteral("test"),
......@@ -142,7 +151,8 @@ void CopyTest::testCopying_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/")),
18);
addAllFormatsRows(QStringLiteral("copy a directory inside itself"),
QStringLiteral("test"),
......@@ -154,7 +164,8 @@ void CopyTest::testCopying_data()
new Archive::Entry(this, QStringLiteral("dir1/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/b.txt")),
},
new Archive::Entry(this, QStringLiteral("dir1/")));
new Archive::Entry(this, QStringLiteral("dir1/")),
19);
addAllFormatsRows(QStringLiteral("copy a directory to the root"),
QStringLiteral("test"),
......@@ -163,7 +174,8 @@ void CopyTest::testCopying_data()
new Archive::Entry(this, QStringLiteral("dir1/dir/a.txt")),
new Archive::Entry(this, QStringLiteral("dir1/dir/b.txt")),
},
new Archive::Entry(this, QStringLiteral("")));
new Archive::Entry(this, QStringLiteral("")),
16);
}
void CopyTest::testCopying()
......@@ -201,6 +213,9 @@ void CopyTest::testCopying()
QVector<Archive::Entry*> resultedEntries = TestHelper::getEntryList(archive);
TestHelper::verifyCopiedEntriesWithDestination(files, destination, oldEntries, resultedEntries);
QFETCH(uint, numberOfEntries);
QCOMPARE(archive->numberOfEntries(), numberOfEntries);
archive->deleteLater();
}
......
......@@ -37,7 +37,7 @@ private Q_SLOTS:
void testMoving();
private:
void addAllFormatsRows(const QString &testName, const QString &archiveName, const QVector<Archive::Entry*> &targetEntries, Archive::Entry *destination, const QStringList &expectedNewPaths) {
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"),
......@@ -57,7 +57,8 @@ private:
<< plugin
<< targetEntries
<< destination
<< expectedNewPaths;
<< expectedNewPaths
<< numberOfEntries;
}
}
}
......@@ -85,6 +86,7 @@ void MoveTest::testMoving_data()
QTest::addColumn<QVector<Archive::Entry*>>("targetEntries");
QTest::addColumn<Archive::Entry*>("destination");
QTest::addColumn<QStringList>("expectedNewPaths");
QTest::addColumn<uint>("numberOfEntries");
addAllFormatsRows(QStringLiteral("replace a single file"),
QStringLiteral("test"),
......@@ -94,7 +96,8 @@ void MoveTest::testMoving_data()
new Archive::Entry(this, QStringLiteral("empty_dir/a.txt")),
QStringList {
QStringLiteral("empty_dir/a.txt")
});
},
13);
addAllFormatsRows(QStringLiteral("replace several files"),
QStringLiteral("test"),
......@@ -106,7 +109,8 @@ void MoveTest::testMoving_data()
QStringList {
QStringLiteral("empty_dir/a.txt"),
QStringLiteral("empty_dir/b.txt")
});
},
13);
addAllFormatsRows(QStringLiteral("replace a root directory"),
QStringLiteral("test"),
......@@ -124,7 +128,8 @@ void MoveTest::testMoving_data()
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"),
......@@ -138,7 +143,8 @@ void MoveTest::testMoving_data()
QStringLiteral("empty_dir/dir/"),
QStringLiteral("empty_dir/dir/a.txt"),
QStringLiteral("empty_dir/dir/b.txt"),
});
},
13);
addAllFormatsRows(QStringLiteral("replace a directory"),
QStringLiteral("test"),
......@@ -152,7 +158,8 @@ void MoveTest::testMoving_data()
QStringLiteral("empty_dir/dir/"),
QStringLiteral("empty_dir/dir/a.txt"),
QStringLiteral("empty_dir/dir/b.txt"),
});
},
13);
addAllFormatsRows(QStringLiteral("replace several directories"),
QStringLiteral("test"),
......@@ -180,7 +187,8 @@ void MoveTest::testMoving_data()
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"),
......@@ -198,7 +206,8 @@ void MoveTest::testMoving_data()
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"),
......@@ -212,7 +221,8 @@ void MoveTest::testMoving_data()
QStringLiteral("dir/"),
QStringLiteral("dir/a.txt"),
QStringLiteral("dir/b.txt"),
});
},
13);
}
void MoveTest::testMoving()
......@@ -273,6 +283,9 @@ void MoveTest::testMoving()
QVERIFY(!newPaths.contains(entry->fullPath()));
}
QFETCH(uint, numberOfEntries);
QCOMPARE(archive->numberOfEntries(), numberOfEntries);
loadJob->deleteLater();
archive->deleteLater();
}
......
Supports Markdown
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