Commit 33928e42 authored by Ragnar Thomsen's avatar Ragnar Thomsen

Add testcases for multivolume rar and 7z archives to ArchiveTest

We test two additional properties in testProperties: isMultiVolume and
numberOfVolumes. These properties are only correct after listing an
archive so we now call listIfNotListed() in isMultiVolume(). This change
required isMultiVolume() and isReadOnly() to be made non-const.

The testcases revealed a bug in Archive::completeBaseName(), where the
basename was not generated correctly for multi-volume archives. This is
also fixed now.

Differential Revision: D2291
parent 1c7d8f54
......@@ -54,6 +54,8 @@ void ArchiveTest::testProperties_data()
QTest::addColumn<bool>("isReadOnly");
QTest::addColumn<bool>("canFallbackOnReadOnly");
QTest::addColumn<bool>("isSingleFolder");
QTest::addColumn<bool>("isMultiVolume");
QTest::addColumn<int>("numberOfVolumes");
QTest::addColumn<Archive::EncryptionType>("expectedEncryptionType");
QTest::addColumn<QString>("expectedSubfolderName");
......@@ -61,81 +63,81 @@ void ArchiveTest::testProperties_data()
QTest::newRow("non-existent tar archive")
<< QStringLiteral("/tmp/foo.tar.gz")
<< QStringLiteral("foo")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QString();
// Test non-archive file
QTest::newRow("not an archive")
<< QStringLiteral("/tmp/foo.pdf")
<< QString()
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QString();
// Test dummy source code tarball.
QTest::newRow("dummy source code tarball")
<< QFINDTESTDATA("data/code-x.y.z.tar.gz")
<< QStringLiteral("code-x.y.z")
<< false << false << true << Archive::Unencrypted
<< false << false << true << false << 0 << Archive::Unencrypted
<< QStringLiteral("awesome_project");
QTest::newRow("simple compressed tar archive")
<< QFINDTESTDATA("data/simplearchive.tar.gz")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
QTest::newRow("encrypted zip, single entry")
<< QFINDTESTDATA("data/archivetest_encrypted.zip")
<< QStringLiteral("archivetest_encrypted")
<< false << true << false << Archive::Encrypted
<< false << true << false << false << 0 << Archive::Encrypted
<< QStringLiteral("archivetest_encrypted");
QTest::newRow("simple zip, one unencrypted entry")
<< QFINDTESTDATA("data/archivetest_unencrypted.zip")
<< QStringLiteral("archivetest_unencrypted")
<< false << true << false << Archive::Unencrypted
<< false << true << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("archivetest_unencrypted");
QTest::newRow("rpm archive, no single folder")
<< QFINDTESTDATA("data/wget.rpm")
<< QStringLiteral("wget")
<< true << false << false << Archive::Unencrypted
<< true << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("wget");
QTest::newRow("bzip2-compressed tarball")
<< QFINDTESTDATA("data/simplearchive.tar.bz2")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
QTest::newRow("xz-compressed tarball")
<< QFINDTESTDATA("data/simplearchive.tar.xz")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
QTest::newRow("lzma-compressed tarball")
<< QFINDTESTDATA("data/simplearchive.tar.lzma")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
QTest::newRow("compress (.Z) tarball")
<< QFINDTESTDATA("data/simplearchive.tar.Z")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
QTest::newRow("lzipped tarball")
<< QFINDTESTDATA("data/simplearchive.tar.lz")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
QTest::newRow("lzop-compressed tarball")
<< QFINDTESTDATA("data/simplearchive.tar.lzo")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
// Only run test for lrzipped tar if lrzip executable is found in path.
......@@ -143,7 +145,7 @@ void ArchiveTest::testProperties_data()
QTest::newRow("lrzipped tarball")
<< QFINDTESTDATA("data/simplearchive.tar.lrz")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
} else {
qDebug() << "lrzip executable not found in path. Skipping lrzip test.";
......@@ -154,7 +156,7 @@ void ArchiveTest::testProperties_data()
QTest::newRow("lz4-compressed tarball")
<< QFINDTESTDATA("data/simplearchive.tar.lz4")
<< QStringLiteral("simplearchive")
<< false << false << false << Archive::Unencrypted
<< false << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
} else {
qDebug() << "lz4 executable not found in path. Skipping lz4 test.";
......@@ -163,20 +165,32 @@ void ArchiveTest::testProperties_data()
QTest::newRow("xar archive")
<< QFINDTESTDATA("data/simplearchive.xar")
<< QStringLiteral("simplearchive")
<< true << false << false << Archive::Unencrypted
<< true << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("simplearchive");
QTest::newRow("mimetype child of application/zip")
<< QFINDTESTDATA("data/test.odt")
<< QStringLiteral("test")
<< false << true << false << Archive::Unencrypted
<< false << true << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("test");
QTest::newRow("AppImage")
<< QFINDTESTDATA("data/hello-2.8-x86_64.AppImage")
<< QStringLiteral("hello-2.8-x86_64")
<< true << false << false << Archive::Unencrypted
<< true << false << false << false << 0 << Archive::Unencrypted
<< QStringLiteral("hello-2.8-x86_64");
QTest::newRow("7z multivolume")
<< QFINDTESTDATA("data/archive-multivolume.7z.001")
<< QStringLiteral("archive-multivolume")
<< true << false << false << true << 3 << Archive::Unencrypted
<< QStringLiteral("archive-multivolume");
QTest::newRow("rar multivolume")
<< QFINDTESTDATA("data/archive-multivolume.part1.rar")
<< QStringLiteral("archive-multivolume")
<< true << false << false << true << 3 << Archive::Unencrypted
<< QStringLiteral("archive-multivolume");
}
void ArchiveTest::testProperties()
......@@ -207,6 +221,12 @@ void ArchiveTest::testProperties()
QFETCH(bool, isSingleFolder);
QCOMPARE(archive->isSingleFolderArchive(), isSingleFolder);
QFETCH(bool, isMultiVolume);
QCOMPARE(archive->isMultiVolume(), isMultiVolume);
QFETCH(int, numberOfVolumes);
QCOMPARE(archive->numberOfVolumes(), numberOfVolumes);
QFETCH(Archive::EncryptionType, expectedEncryptionType);
QCOMPARE(archive->encryptionType(), expectedEncryptionType);
......@@ -523,6 +543,20 @@ void ArchiveTest::testExtraction_data()
<< QVariantList()
<< optionsPreservePaths
<< 7;
archivePath = QFINDTESTDATA("data/archive-multivolume.7z.001");
QTest::newRow("extract all entries from a multivolume 7z archive with path")
<< archivePath
<< QVariantList()
<< optionsPreservePaths
<< 3;
archivePath = QFINDTESTDATA("data/archive-multivolume.part1.rar");
QTest::newRow("extract all entries from a multivolume rar archive with path")
<< archivePath
<< QVariantList()
<< optionsPreservePaths
<< 3;
}
void ArchiveTest::testExtraction()
......
......@@ -38,6 +38,7 @@
#include <QFile>
#include <QFileInfo>
#include <QMimeDatabase>
#include <QRegularExpression>
#include <KPluginFactory>
#include <KPluginLoader>
......@@ -151,11 +152,24 @@ Archive::~Archive()
QString Archive::completeBaseName() const
{
const QString suffix = QFileInfo(fileName()).suffix();
QString base = QFileInfo(fileName()).completeBaseName();
// Special case for compressed tar archives.
if (base.right(4).toUpper() == QLatin1String(".TAR")) {
base.chop(4);
// Multi-volume 7z's are named name.7z.001.
} else if (base.right(3).toUpper() == QLatin1String(".7Z")) {
base.chop(3);
// Multi-volume zip's are named name.zip.001.
} else if (base.right(4).toUpper() == QLatin1String(".ZIP")) {
base.chop(4);
// For multivolume rar's we want to remove the ".partNNN" suffix.
} else if (suffix.toUpper() == QLatin1String("RAR")) {
base.remove(QRegularExpression(QStringLiteral("\\.part[0-9]{1,3}$")));
}
return base;
......@@ -208,7 +222,7 @@ QMimeType Archive::mimeType()
return m_mimeType;
}
bool Archive::isReadOnly() const
bool Archive::isReadOnly()
{
return isValid() ? (m_iface->isReadOnly() || m_isReadOnly ||
(isMultiVolume() && (m_numberOfFiles > 0 || m_numberOfFolders > 0))) : false;
......@@ -229,8 +243,12 @@ bool Archive::hasComment() const
return isValid() ? !comment().isEmpty() : false;
}
bool Archive::isMultiVolume() const
bool Archive::isMultiVolume()
{
if (!isValid()) {
return false;
}
listIfNotListed();
return m_iface->isMultiVolume();
}
......
......@@ -174,9 +174,9 @@ public:
QString fileName() const;
QString comment() const;
QMimeType mimeType();
bool isReadOnly() const;
bool isReadOnly();
bool isSingleFolderArchive();
bool isMultiVolume() const;
bool isMultiVolume();
void setMultiVolume(bool value);
bool hasComment() const;
int numberOfVolumes() const;
......
......@@ -52,6 +52,7 @@ void CliPlugin::resetParsing()
{
m_parseState = ParseStateTitle;
m_comment.clear();
m_numberOfVolumes = 0;
}
ParameterList CliPlugin::parameterList() const
......
......@@ -57,6 +57,7 @@ void CliPlugin::resetParsing()
m_parseState = ParseStateTitle;
m_remainingIgnoreLines = 1;
m_comment.clear();
m_numberOfVolumes = 0;
}
// #272281: the proprietary unrar program does not like trailing '/'s
......
......@@ -76,6 +76,7 @@ bool CliPlugin::copyFiles(const QList<QVariant> &files, const QString &destinati
void CliPlugin::resetParsing()
{
m_jsonOutput.clear();
m_numberOfVolumes = 0;
}
ParameterList CliPlugin::parameterList() const
......
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