summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2021-08-24 11:09:54 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2021-09-14 15:04:15 +0300
commit7be4b9c71af4d4668deab355db73beb7feaf35c1 (patch)
tree6589191ca2f89756cb5c080645b73aca6e8441cc /tests
parent50292e14683727e6da81799cedd4ee352c3e0497 (diff)
Add tests for the new archive handling classes
Change-Id: I1e3a91fd0722b0b73197257ec5092a617b41516e Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/installer/archivefactory/archivefactory.pro5
-rw-r--r--tests/auto/installer/archivefactory/tst_archivefactory.cpp142
-rw-r--r--tests/auto/installer/clientserver/tst_clientserver.cpp60
-rw-r--r--tests/auto/installer/installer.pro7
-rw-r--r--tests/auto/installer/lib7zarchive/data.qrc (renamed from tests/auto/installer/lib7zfacade/data.qrc)0
-rw-r--r--tests/auto/installer/lib7zarchive/data/invalid.7z (renamed from tests/auto/installer/lib7zfacade/data/invalid.7z)bin25600 -> 25600 bytes
-rw-r--r--tests/auto/installer/lib7zarchive/data/valid.7z (renamed from tests/auto/installer/lib7zfacade/data/valid.7z)bin950 -> 950 bytes
-rw-r--r--tests/auto/installer/lib7zarchive/lib7zarchive.pro (renamed from tests/auto/installer/lib7zfacade/lib7zfacade.pro)2
-rw-r--r--tests/auto/installer/lib7zarchive/tst_lib7zarchive.cpp150
-rw-r--r--tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp175
-rw-r--r--tests/auto/installer/libarchivearchive/data.qrc8
-rw-r--r--tests/auto/installer/libarchivearchive/data/valid.tar.bz2bin0 -> 127 bytes
-rw-r--r--tests/auto/installer/libarchivearchive/data/valid.tar.gzbin0 -> 5194 bytes
-rw-r--r--tests/auto/installer/libarchivearchive/data/valid.tar.xzbin0 -> 964 bytes
-rw-r--r--tests/auto/installer/libarchivearchive/data/valid.zipbin0 -> 5298 bytes
-rw-r--r--tests/auto/installer/libarchivearchive/libarchivearchive.pro7
-rw-r--r--tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp197
17 files changed, 576 insertions, 177 deletions
diff --git a/tests/auto/installer/archivefactory/archivefactory.pro b/tests/auto/installer/archivefactory/archivefactory.pro
new file mode 100644
index 000000000..3d8ee90ab
--- /dev/null
+++ b/tests/auto/installer/archivefactory/archivefactory.pro
@@ -0,0 +1,5 @@
+include(../../qttest.pri)
+
+QT -= gui
+
+SOURCES += tst_archivefactory.cpp
diff --git a/tests/auto/installer/archivefactory/tst_archivefactory.cpp b/tests/auto/installer/archivefactory/tst_archivefactory.cpp
new file mode 100644
index 000000000..20fd4ab70
--- /dev/null
+++ b/tests/auto/installer/archivefactory/tst_archivefactory.cpp
@@ -0,0 +1,142 @@
+/**************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+#include <archivefactory.h>
+
+#include <QObject>
+#include <QTest>
+
+using namespace QInstaller;
+
+class MyRarArchive : public AbstractArchive
+{
+ Q_OBJECT
+
+public:
+ MyRarArchive(QObject *parent = nullptr)
+ : AbstractArchive(parent)
+ {}
+ MyRarArchive(const QString &filename, QObject *parent = nullptr)
+ : AbstractArchive(parent)
+ {
+ Q_UNUSED(filename)
+ }
+
+ bool open(QIODevice::OpenMode mode)
+ {
+ Q_UNUSED(mode)
+ return true;
+ };
+ void close() {};
+ void setFilename(const QString &filename) { Q_UNUSED(filename) };
+ bool extract(const QString &dirPath)
+ {
+ Q_UNUSED(dirPath)
+ return true;
+ };
+ bool extract(const QString &dirPath, const quint64 totalFiles)
+ {
+ Q_UNUSED(dirPath)
+ Q_UNUSED(totalFiles)
+ return true;
+ };
+ bool create(const QStringList &data)
+ {
+ Q_UNUSED(data)
+ return true;
+ };
+ QVector<ArchiveEntry> list() { return QVector<ArchiveEntry>(); };
+ bool isSupported() { return true; };
+
+public slots:
+ void cancel() {};
+};
+
+class tst_archivefactory : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testCreateDefaultArchiveHandler_data()
+ {
+ QTest::addColumn<QString>("handler");
+ QTest::addColumn<QString>("filename");
+ QTest::addColumn<QStringList>("types");
+ QTest::newRow("Lib7z")
+ << "Lib7z" << "myfile.7z" << (QStringList() << "7z");
+#ifdef IFW_LIBARCHIVE
+ QTest::newRow("LibArchive")
+ << "LibArchive" << "myfile.zip" << (QStringList() << "tar.gz" << "tar.bz2" << "tar.xz" << "zip");
+#endif
+ }
+
+ void testCreateDefaultArchiveHandler()
+ {
+ QFETCH(QString, handler);
+ QFETCH(QString, filename);
+ QFETCH(QStringList, types);
+
+ QVERIFY(ArchiveFactory::instance().containsProduct(handler));
+ for (auto &type : types)
+ QVERIFY(ArchiveFactory::isSupportedType("file." + type));
+
+ QScopedPointer<AbstractArchive> archive(ArchiveFactory::instance().create(filename));
+ QVERIFY(archive);
+ }
+
+ void testCreateUnknownArchive_data()
+ {
+ QTest::addColumn<QString>("filename");
+ QTest::newRow("Unknown suffix") << "invalid.file";
+ QTest::newRow("Suffix with known part 1") << "myfile.7z.sha1";
+ QTest::newRow("Suffix with known part 2") << "myfile.tar.gz.sha1";
+ }
+
+ void testCreateUnknownArchive()
+ {
+ QFETCH(QString, filename);
+
+ QVERIFY(!ArchiveFactory::isSupportedType(filename));
+ QScopedPointer<AbstractArchive> archive(ArchiveFactory::instance().create(filename));
+ QVERIFY(!archive);
+ }
+
+ void testRegisterNewHandler()
+ {
+ ArchiveFactory::instance().registerArchive<MyRarArchive>("MyRarHandler", QStringList() << "rar");
+ QVERIFY(ArchiveFactory::instance().containsProduct("MyRarHandler"));
+ QVERIFY(ArchiveFactory::isSupportedType("file.rar"));
+
+ QScopedPointer<AbstractArchive> archive(ArchiveFactory::instance().create("myfile.rar"));
+ QVERIFY(archive);
+ }
+};
+
+QTEST_MAIN(tst_archivefactory)
+
+#include "tst_archivefactory.moc"
diff --git a/tests/auto/installer/clientserver/tst_clientserver.cpp b/tests/auto/installer/clientserver/tst_clientserver.cpp
index 29d4283b9..c0a2b1c3f 100644
--- a/tests/auto/installer/clientserver/tst_clientserver.cpp
+++ b/tests/auto/installer/clientserver/tst_clientserver.cpp
@@ -26,12 +26,19 @@
**
**************************************************************************/
+#include "../shared/verifyinstaller.h"
+
#include <protocol.h>
#include <qprocesswrapper.h>
#include <qsettingswrapper.h>
#include <remoteclient.h>
#include <remotefileengine.h>
#include <remoteserver.h>
+#include <fileutils.h>
+
+#ifdef IFW_LIBARCHIVE
+#include <libarchivewrapper_p.h>
+#endif
#include <QBuffer>
#include <QSettings>
@@ -513,6 +520,59 @@ private slots:
QCOMPARE(file.atEnd(), true);
}
+ void testArchiveWrapper_data()
+ {
+ QTest::addColumn<QString>("suffix");
+ QTest::newRow("ZIP archive") << ".zip";
+ QTest::newRow("gzip compressed tar archive") << ".tar.gz";
+ QTest::newRow("bzip2 compressed tar archive") << ".tar.bz2";
+ QTest::newRow("xz compressed tar archive") << ".tar.xz";
+ }
+
+ void testArchiveWrapper()
+ {
+#ifndef IFW_LIBARCHIVE
+ QSKIP("Installer Framework built without libarchive support");
+#else
+ QFETCH(QString, suffix);
+
+ const QString archiveName = generateTemporaryFileName() + suffix;
+ const QString targetName = QDir::tempPath() + "/tst_archivewrapper/";
+
+ QTemporaryFile source;
+ source.open();
+ source.write("Source File");
+ source.setAutoRemove(false);
+
+ RemoteServer server;
+ QString socketName = QUuid::createUuid().toString();
+ server.init(socketName, QLatin1String("SomeKey"), Protocol::Mode::Production);
+ server.start();
+
+ RemoteClient::instance().init(socketName, QLatin1String("SomeKey"), Protocol::Mode::Debug,
+ Protocol::StartAs::User);
+
+ LibArchiveWrapperPrivate archive;
+ QCOMPARE(archive.isConnectedToServer(), false);
+ archive.setFilename(archiveName);
+ QCOMPARE(archive.isConnectedToServer(), true);
+
+ QVERIFY(archive.open(QIODevice::ReadWrite));
+ QVERIFY(archive.create(QStringList() << source.fileName()));
+ QVERIFY(QFileInfo::exists(archiveName));
+
+ QVERIFY(archive.extract(targetName, 1));
+ const QString sourceFilename = QFileInfo(source.fileName()).fileName();
+ QVERIFY(QFileInfo::exists(targetName + sourceFilename));
+ VerifyInstaller::verifyFileContent(targetName + sourceFilename, source.readAll());
+ archive.close();
+
+ QVERIFY(source.remove());
+ QVERIFY(QFile::remove(archiveName));
+ removeDirectory(targetName);
+#endif
+ }
+
void cleanupTestCase()
{
RemoteClient::instance().setActive(false);
diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro
index cb0438ab3..b877e5d20 100644
--- a/tests/auto/installer/installer.pro
+++ b/tests/auto/installer/installer.pro
@@ -1,6 +1,7 @@
TEMPLATE = subdirs
SUBDIRS += \
+ archivefactory \
settings \
repository \
compareversion\
@@ -9,7 +10,7 @@ SUBDIRS += \
fakestopprocessforupdateoperation \
messageboxhandler \
extractarchiveoperationtest \
- lib7zfacade \
+ lib7zarchive \
fileutils \
unicodeexecutable \
scriptengine \
@@ -42,6 +43,10 @@ SUBDIRS += \
createoffline \
contentshaupdate
+CONFIG(libarchive) {
+ SUBDIRS += libarchivearchive
+}
+
win32 {
SUBDIRS += registerfiletypeoperation \
createshortcutoperation
diff --git a/tests/auto/installer/lib7zfacade/data.qrc b/tests/auto/installer/lib7zarchive/data.qrc
index d6453a9b3..d6453a9b3 100644
--- a/tests/auto/installer/lib7zfacade/data.qrc
+++ b/tests/auto/installer/lib7zarchive/data.qrc
diff --git a/tests/auto/installer/lib7zfacade/data/invalid.7z b/tests/auto/installer/lib7zarchive/data/invalid.7z
index bcf81250e..bcf81250e 100644
--- a/tests/auto/installer/lib7zfacade/data/invalid.7z
+++ b/tests/auto/installer/lib7zarchive/data/invalid.7z
Binary files differ
diff --git a/tests/auto/installer/lib7zfacade/data/valid.7z b/tests/auto/installer/lib7zarchive/data/valid.7z
index e583bdf99..e583bdf99 100644
--- a/tests/auto/installer/lib7zfacade/data/valid.7z
+++ b/tests/auto/installer/lib7zarchive/data/valid.7z
Binary files differ
diff --git a/tests/auto/installer/lib7zfacade/lib7zfacade.pro b/tests/auto/installer/lib7zarchive/lib7zarchive.pro
index 034cf1eed..aabf724b6 100644
--- a/tests/auto/installer/lib7zfacade/lib7zfacade.pro
+++ b/tests/auto/installer/lib7zarchive/lib7zarchive.pro
@@ -4,4 +4,4 @@ QT -= gui
QT += testlib
RESOURCES += data.qrc
-SOURCES = tst_lib7zfacade.cpp
+SOURCES = tst_lib7zarchive.cpp
diff --git a/tests/auto/installer/lib7zarchive/tst_lib7zarchive.cpp b/tests/auto/installer/lib7zarchive/tst_lib7zarchive.cpp
new file mode 100644
index 000000000..1c9c48861
--- /dev/null
+++ b/tests/auto/installer/lib7zarchive/tst_lib7zarchive.cpp
@@ -0,0 +1,150 @@
+/**************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+#include <lib7z_facade.h>
+#include <lib7zarchive.h>
+#include <fileutils.h>
+
+#include <QDir>
+#include <QObject>
+#include <QTemporaryFile>
+#include <QTest>
+
+using namespace QInstaller;
+
+class tst_lib7zarchive : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase()
+ {
+ Lib7z::initSevenZ();
+
+ m_file.path = "valid";
+ m_file.permissions_enum = 0;
+ m_file.compressedSize = 836;
+ m_file.uncompressedSize = 5242880;
+ m_file.isDirectory = false;
+ m_file.archiveIndex = QPoint(0, 0);
+ m_file.utcTime = QDateTime(QDate::fromJulianDay(2456413), QTime(10, 50, 42), Qt::UTC);
+ }
+
+ void testIsSupportedArchive()
+ {
+ Lib7zArchive archive(":///data/valid.7z");
+ QVERIFY(archive.open(QIODevice::ReadOnly));
+ QCOMPARE(archive.isSupported(), true);
+ archive.close();
+
+ archive.setFilename(":///data/invalid.7z");
+ QVERIFY(archive.open(QIODevice::ReadOnly));
+ QCOMPARE(archive.isSupported(), false);
+ }
+
+ void testListArchive()
+ {
+
+ Lib7zArchive archive(":///data/valid.7z");
+ QVERIFY(archive.open(QIODevice::ReadOnly));
+
+ QVector<ArchiveEntry> files = archive.list();
+ QCOMPARE(files.count(), 1);
+ QCOMPARE(files.first(), m_file);
+ archive.close();
+
+ archive.setFilename(":///data/invalid.7z");
+ QVERIFY(archive.open(QIODevice::ReadOnly));
+ files = archive.list();
+
+ QVERIFY(files.isEmpty());
+ QCOMPARE(archive.errorString(), QString("Cannot open archive \":///data/invalid.7z\"."));
+ }
+
+ void testCreateArchive()
+ {
+ QString path1 = tempSourceFile("Source File 1.");
+ QString path2 = tempSourceFile("Source File 2.");
+
+ QString filename = generateTemporaryFileName();
+ Lib7zArchive target(filename);
+ QVERIFY(target.open(QIODevice::ReadWrite));
+ QVERIFY(target.create(QStringList() << path1 << path2));
+ QCOMPARE(target.list().count(), 2);
+ target.close();
+ QVERIFY(QFile::remove(filename));
+
+
+ path1 = tempSourceFile(
+ "Source File 1.",
+ QDir::tempPath() + "/temp file with spaces.XXXXXX"
+ );
+ path2 = tempSourceFile(
+ "Source File 2.",
+ QDir::tempPath() + "/temp file with spaces.XXXXXX"
+ );
+
+ filename = QDir::tempPath() + "/target file with spaces.XXXXXX";
+ target.setFilename(filename);
+ QVERIFY(target.open(QIODevice::ReadWrite));
+ QVERIFY(target.create(QStringList() << path1 << path2));
+ QCOMPARE(target.list().count(), 2);
+ target.close();
+ QVERIFY(QFile::remove(filename));
+ }
+
+ void testExtractArchive()
+ {
+ Lib7zArchive source(":///data/valid.7z");
+ QVERIFY(source.open(QIODevice::ReadOnly));
+
+ QVERIFY(source.extract(QDir::tempPath()));
+ QCOMPARE(QFile::exists(QDir::tempPath() + QString("/valid")), true);
+ QVERIFY(QFile::remove(QDir::tempPath() + QString("/valid")));
+ }
+
+private:
+ QString tempSourceFile(const QByteArray &data, const QString &templateName = QString())
+ {
+ QTemporaryFile source;
+ if (!templateName.isEmpty()) {
+ source.setFileTemplate(templateName);
+ }
+ source.open();
+ source.write(data);
+ source.setAutoRemove(false);
+ return source.fileName();
+ }
+
+private:
+ ArchiveEntry m_file;
+};
+
+QTEST_MAIN(tst_lib7zarchive)
+
+#include "tst_lib7zarchive.moc"
diff --git a/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp b/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
deleted file mode 100644
index 4175bdf40..000000000
--- a/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
+++ /dev/null
@@ -1,175 +0,0 @@
-/**************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Installer Framework.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-**************************************************************************/
-
-#include <lib7z_create.h>
-#include <lib7z_extract.h>
-#include <lib7z_facade.h>
-#include <lib7z_list.h>
-
-#include <QDir>
-#include <QObject>
-#include <QTemporaryFile>
-#include <QTest>
-
-class tst_lib7zfacade : public QObject
-{
- Q_OBJECT
-
-private slots:
- void initTestCase()
- {
- Lib7z::initSevenZ();
-
- m_file.path = "valid";
- m_file.permissions_enum = 0;
- m_file.compressedSize = 836;
- m_file.uncompressedSize = 5242880;
- m_file.isDirectory = false;
- m_file.archiveIndex = QPoint(0, 0);
- m_file.utcTime = QDateTime(QDate::fromJulianDay(2456413), QTime(10, 50, 42), Qt::UTC);
- }
-
- void testIsSupportedArchive()
- {
- QCOMPARE(Lib7z::isSupportedArchive(":///data/valid.7z"), true);
- QCOMPARE(Lib7z::isSupportedArchive(":///data/invalid.7z"), false);
-
- try {
- QFile file(":///data/valid.7z");
- QVERIFY(file.open(QIODevice::ReadOnly));
- QCOMPARE(Lib7z::isSupportedArchive(&file), true);
- } catch (...) {
- QFAIL("Unexpected error during Lib7z::isSupportedArchive.");
- }
-
- try {
- QFile file(":///data/invalid.7z");
- QVERIFY(file.open(QIODevice::ReadOnly));
- QCOMPARE(Lib7z::isSupportedArchive(&file), false);
- } catch (...) {
- QFAIL("Unexpected error during Lib7z::isSupportedArchive.");
- }
- }
-
- void testListArchive()
- {
- try {
- QFile file(":///data/valid.7z");
- QVERIFY(file.open(QIODevice::ReadOnly));
-
- QVector<Lib7z::File> files = Lib7z::listArchive(&file);
- QCOMPARE(files.count(), 1);
- QCOMPARE(files.first(), m_file);
- } catch (...) {
- QFAIL("Unexpected error during list archive.");
- }
-
- try {
- QFile file(":///data/invalid.7z");
- QVERIFY(file.open(QIODevice::ReadOnly));
- QVector<Lib7z::File> files = Lib7z::listArchive(&file);
- } catch (const Lib7z::SevenZipException& e) {
- QCOMPARE(e.message(), QString("Cannot open archive \":///data/invalid.7z\"."));
- } catch (...) {
- QFAIL("Unexpected error during list archive.");
- }
- }
-
- void testCreateArchive()
- {
- try {
- const QString path = tempSourceFile("Source File 1.");
- const QString path2 = tempSourceFile("Source File 2.");
-
- QTemporaryFile target;
- QVERIFY(target.open());
- Lib7z::createArchive(&target, QStringList() << path << path2);
- QCOMPARE(Lib7z::listArchive(&target).count(), 2);
- } catch (const Lib7z::SevenZipException& e) {
- QFAIL(e.message().toUtf8());
- } catch (...) {
- QFAIL("Unexpected error during create archive.");
- }
-
- try {
- const QString path1 = tempSourceFile(
- "Source File 1.",
- QDir::tempPath() + "/temp file with spaces.XXXXXX"
- );
- const QString path2 = tempSourceFile(
- "Source File 2.",
- QDir::tempPath() + "/temp file with spaces.XXXXXX"
- );
-
- QTemporaryFile target(QDir::tempPath() + "/target file with spaces.XXXXXX");
- QVERIFY(target.open());
- Lib7z::createArchive(&target, QStringList() << path1 << path2);
- QCOMPARE(Lib7z::listArchive(&target).count(), 2);
- } catch (const Lib7z::SevenZipException& e) {
- QFAIL(e.message().toUtf8());
- } catch (...) {
- QFAIL("Unexpected error during create archive.");
- }
-
- }
-
- void testExtractArchive()
- {
- QFile source(":///data/valid.7z");
- QVERIFY(source.open(QIODevice::ReadOnly));
-
- try {
- Lib7z::extractArchive(&source, QDir::tempPath());
- QCOMPARE(QFile::exists(QDir::tempPath() + QString("/valid")), true);
- } catch (const Lib7z::SevenZipException& e) {
- QFAIL(e.message().toUtf8());
- } catch (...) {
- QFAIL("Unexpected error during extract archive.");
- }
- }
-
-private:
- QString tempSourceFile(const QByteArray &data, const QString &templateName = QString())
- {
- QTemporaryFile source;
- if (!templateName.isEmpty()) {
- source.setFileTemplate(templateName);
- }
- source.open();
- source.write(data);
- source.setAutoRemove(false);
- return source.fileName();
- }
-
-private:
- Lib7z::File m_file;
-};
-
-QTEST_MAIN(tst_lib7zfacade)
-
-#include "tst_lib7zfacade.moc"
diff --git a/tests/auto/installer/libarchivearchive/data.qrc b/tests/auto/installer/libarchivearchive/data.qrc
new file mode 100644
index 000000000..83f15d241
--- /dev/null
+++ b/tests/auto/installer/libarchivearchive/data.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/">
+ <file>data/valid.zip</file>
+ <file>data/valid.tar.gz</file>
+ <file>data/valid.tar.bz2</file>
+ <file>data/valid.tar.xz</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/installer/libarchivearchive/data/valid.tar.bz2 b/tests/auto/installer/libarchivearchive/data/valid.tar.bz2
new file mode 100644
index 000000000..1a79b4cd4
--- /dev/null
+++ b/tests/auto/installer/libarchivearchive/data/valid.tar.bz2
Binary files differ
diff --git a/tests/auto/installer/libarchivearchive/data/valid.tar.gz b/tests/auto/installer/libarchivearchive/data/valid.tar.gz
new file mode 100644
index 000000000..d574487d2
--- /dev/null
+++ b/tests/auto/installer/libarchivearchive/data/valid.tar.gz
Binary files differ
diff --git a/tests/auto/installer/libarchivearchive/data/valid.tar.xz b/tests/auto/installer/libarchivearchive/data/valid.tar.xz
new file mode 100644
index 000000000..4851a63b1
--- /dev/null
+++ b/tests/auto/installer/libarchivearchive/data/valid.tar.xz
Binary files differ
diff --git a/tests/auto/installer/libarchivearchive/data/valid.zip b/tests/auto/installer/libarchivearchive/data/valid.zip
new file mode 100644
index 000000000..d6923e016
--- /dev/null
+++ b/tests/auto/installer/libarchivearchive/data/valid.zip
Binary files differ
diff --git a/tests/auto/installer/libarchivearchive/libarchivearchive.pro b/tests/auto/installer/libarchivearchive/libarchivearchive.pro
new file mode 100644
index 000000000..ac4856ede
--- /dev/null
+++ b/tests/auto/installer/libarchivearchive/libarchivearchive.pro
@@ -0,0 +1,7 @@
+include(../../qttest.pri)
+
+QT -= gui
+QT += testlib
+
+RESOURCES += data.qrc
+SOURCES = tst_libarchivearchive.cpp
diff --git a/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp b/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp
new file mode 100644
index 000000000..f12de22a4
--- /dev/null
+++ b/tests/auto/installer/libarchivearchive/tst_libarchivearchive.cpp
@@ -0,0 +1,197 @@
+/**************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+#include <libarchivearchive.h>
+#include <fileutils.h>
+
+#include <QDir>
+#include <QObject>
+#include <QTemporaryFile>
+#include <QTest>
+
+using namespace QInstaller;
+
+class tst_libarchivearchive : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase()
+ {
+ m_file.path = "valid";
+ m_file.compressedSize = 0; // unused
+ m_file.uncompressedSize = 5242880;
+ m_file.isDirectory = false;
+ m_file.archiveIndex = QPoint(0, 0);
+ m_file.utcTime = QDateTime(QDate::fromJulianDay(2456413), QTime(10, 50, 42), Qt::UTC);
+ }
+
+ void testIsSupportedArchive_data()
+ {
+ archiveFilenamesTestData();
+ }
+
+ void testIsSupportedArchive()
+ {
+ QFETCH(QString, filename);
+
+ LibArchiveArchive archive(filename);
+ QVERIFY(archive.open(QIODevice::ReadOnly));
+ QCOMPARE(archive.isSupported(), true);
+ }
+
+ void testListArchive_data()
+ {
+ archiveFilenamesTestData();
+ }
+
+ void testListArchive()
+ {
+ QFETCH(QString, filename);
+
+ LibArchiveArchive archive(filename);
+ QVERIFY(archive.open(QIODevice::ReadOnly));
+
+ QVector<ArchiveEntry> files = archive.list();
+ QCOMPARE(files.count(), 1);
+ QVERIFY(entriesMatch(files.first(), m_file));
+ }
+
+ void testCreateArchive_data()
+ {
+ archiveSuffixesTestData();
+ }
+
+ void testCreateArchive()
+ {
+ QFETCH(QString, suffix);
+
+ const QString path1 = tempSourceFile("Source File 1.");
+ const QString path2 = tempSourceFile("Source File 2.");
+
+ const QString filename = generateTemporaryFileName() + suffix;
+ LibArchiveArchive target(filename);
+ QVERIFY(target.open(QIODevice::ReadWrite));
+ QVERIFY(target.create(QStringList() << path1 << path2));
+ QCOMPARE(target.list().count(), 2);
+ target.close();
+ QVERIFY(QFile(filename).remove());
+ }
+
+ void testCreateArchiveWithSpaces_data()
+ {
+ archiveSuffixesTestData();
+ }
+
+ void testCreateArchiveWithSpaces()
+ {
+ QFETCH(QString, suffix);
+
+ const QString path1 = tempSourceFile(
+ "Source File 1.",
+ QDir::tempPath() + "/temp file with spaces.XXXXXX"
+ );
+ const QString path2 = tempSourceFile(
+ "Source File 2.",
+ QDir::tempPath() + "/temp file with spaces.XXXXXX"
+ );
+
+ const QString filename = QDir::tempPath() + "/target file with spaces" + suffix;
+ LibArchiveArchive target(filename);
+ target.setFilename(filename);
+ QVERIFY(target.open(QIODevice::ReadWrite));
+ QVERIFY(target.create(QStringList() << path1 << path2));
+ QCOMPARE(target.list().count(), 2);
+ target.close();
+ QVERIFY(QFile(filename).remove());
+ }
+
+ void testExtractArchive_data()
+ {
+ archiveFilenamesTestData();
+ }
+
+ void testExtractArchive()
+ {
+ QFETCH(QString, filename);
+
+ LibArchiveArchive source(filename);
+ QVERIFY(source.open(QIODevice::ReadOnly));
+
+ QVERIFY(source.extract(QDir::tempPath()));
+ QCOMPARE(QFile::exists(QDir::tempPath() + QString("/valid")), true);
+ QVERIFY(QFile(QDir::tempPath() + QString("/valid")).remove());
+ }
+
+private:
+ void archiveFilenamesTestData()
+ {
+ QTest::addColumn<QString>("filename");
+ QTest::newRow("ZIP archive") << ":///data/valid.zip";
+ QTest::newRow("gzip compressed tar archive") << ":///data/valid.tar.gz";
+ QTest::newRow("bzip2 compressed tar archive") << ":///data/valid.tar.bz2";
+ QTest::newRow("xz compressed tar archive") << ":///data/valid.tar.xz";
+ }
+
+ void archiveSuffixesTestData()
+ {
+ QTest::addColumn<QString>("suffix");
+ QTest::newRow("ZIP archive") << ".zip";
+ QTest::newRow("gzip compressed tar archive") << ".tar.gz";
+ QTest::newRow("bzip2 compressed tar archive") << ".tar.bz2";
+ QTest::newRow("xz compressed tar archive") << ".tar.xz";
+ }
+
+ bool entriesMatch(const ArchiveEntry &lhs, const ArchiveEntry &rhs)
+ {
+ return lhs.path == rhs.path
+ && lhs.utcTime == rhs.utcTime
+ && lhs.isDirectory == rhs.isDirectory
+ && lhs.compressedSize == rhs.compressedSize
+ && lhs.uncompressedSize == rhs.uncompressedSize;
+ }
+
+ QString tempSourceFile(const QByteArray &data, const QString &templateName = QString())
+ {
+ QTemporaryFile source;
+ if (!templateName.isEmpty()) {
+ source.setFileTemplate(templateName);
+ }
+ source.open();
+ source.write(data);
+ source.setAutoRemove(false);
+ return source.fileName();
+ }
+
+private:
+ ArchiveEntry m_file;
+};
+
+QTEST_MAIN(tst_libarchivearchive)
+
+#include "tst_libarchivearchive.moc"