From 8997ec51b7603fafe5cd34dcff21ba1151c76f32 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Wed, 2 Dec 2020 16:36:26 +0200 Subject: Add unit tests for offline generation This also changes some of the return values in our CLI-related functions in PackageManagerCore class to better catch cases where we exit without failing but also without doing anything. Also adapt existing tests. Task-number: QTIFW-2028 Change-Id: I73c4ca1b20d439773d0e290195f137d0d7369d17 Reviewed-by: Katja Marttila --- .../installer/cliinterface/tst_cliinterface.cpp | 10 +- .../commandlineupdate/tst_commandlineupdate.cpp | 11 +- .../auto/installer/createoffline/createoffline.pro | 9 ++ .../2020-12-01-1511_meta.7z | Bin 0 -> 13745 bytes .../data/repository-bothmeta-license/Updates.xml | 22 +++ .../1.0.0-1content.7z | Bin 0 -> 242 bytes .../1.0.0-1content.7z.sha1 | 1 + .../1.0.0-1meta.7z | Bin 0 -> 13745 bytes .../2020-12-01-1524_meta.7z | Bin 0 -> 1489 bytes .../repository-bothmeta-userinteface/Updates.xml | 20 +++ .../1.0.0-1content.7z | Bin 0 -> 175 bytes .../1.0.0-1content.7z.sha1 | 1 + .../1.0.0-1meta.7z | Bin 0 -> 1489 bytes .../repository-componentmeta-script/Updates.xml | 17 ++ .../org.qtproject.ifw.example/1.0.0-1content.7z | Bin 0 -> 257 bytes .../1.0.0-1content.7z.sha1 | 1 + .../org.qtproject.ifw.example/1.0.0-1meta.7z | Bin 0 -> 1078 bytes .../data/repository-missingdependency/Updates.xml | 22 +++ .../2020-12-01-1519_meta.7z | Bin 0 -> 1078 bytes .../data/repository-unifiedmeta-script/Updates.xml | 18 +++ .../org.qtproject.ifw.example/1.0.0-1content.7z | Bin 0 -> 257 bytes .../1.0.0-1content.7z.sha1 | 1 + tests/auto/installer/createoffline/settings.qrc | 27 ++++ .../installer/createoffline/tst_createoffline.cpp | 171 +++++++++++++++++++++ tests/auto/installer/installer.pro | 3 +- tests/auto/installer/shared/packagemanager.h | 2 + 26 files changed, 321 insertions(+), 15 deletions(-) create mode 100644 tests/auto/installer/createoffline/createoffline.pro create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-license/2020-12-01-1511_meta.7z create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-license/Updates.xml create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z.sha1 create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1meta.7z create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/2020-12-01-1524_meta.7z create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/Updates.xml create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z.sha1 create mode 100644 tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1meta.7z create mode 100644 tests/auto/installer/createoffline/data/repository-componentmeta-script/Updates.xml create mode 100644 tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z create mode 100644 tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 create mode 100644 tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1meta.7z create mode 100644 tests/auto/installer/createoffline/data/repository-missingdependency/Updates.xml create mode 100644 tests/auto/installer/createoffline/data/repository-unifiedmeta-script/2020-12-01-1519_meta.7z create mode 100644 tests/auto/installer/createoffline/data/repository-unifiedmeta-script/Updates.xml create mode 100644 tests/auto/installer/createoffline/data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z create mode 100644 tests/auto/installer/createoffline/data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 create mode 100644 tests/auto/installer/createoffline/settings.qrc create mode 100644 tests/auto/installer/createoffline/tst_createoffline.cpp (limited to 'tests') diff --git a/tests/auto/installer/cliinterface/tst_cliinterface.cpp b/tests/auto/installer/cliinterface/tst_cliinterface.cpp index c3e1eff57..550f45da2 100644 --- a/tests/auto/installer/cliinterface/tst_cliinterface.cpp +++ b/tests/auto/installer/cliinterface/tst_cliinterface.cpp @@ -103,24 +103,24 @@ private slots: QTest::ignoreMessage(QtDebugMsg, "Preparing meta information download..."); QTest::ignoreMessage(QtDebugMsg, "Cannot install component A. Component is installed only as automatic dependency to autoDep.\n"); - QCOMPARE(PackageManagerCore::Success, core->installSelectedComponentsSilently(QStringList() + QCOMPARE(PackageManagerCore::Canceled, core->installSelectedComponentsSilently(QStringList() << QLatin1String("A"))); QTest::ignoreMessage(QtDebugMsg, "Preparing meta information download..."); QTest::ignoreMessage(QtDebugMsg, "Cannot install component AB. Component is not checkable meaning you have to select one of the subcomponents.\n"); - QCOMPARE(PackageManagerCore::Success, core->installSelectedComponentsSilently(QStringList() + QCOMPARE(PackageManagerCore::Canceled, core->installSelectedComponentsSilently(QStringList() << QLatin1String("AB"))); QTest::ignoreMessage(QtDebugMsg, "Preparing meta information download..."); QTest::ignoreMessage(QtDebugMsg, "Cannot install B. Component is virtual.\n"); - QCOMPARE(PackageManagerCore::Success, core->installSelectedComponentsSilently(QStringList() + QCOMPARE(PackageManagerCore::Canceled, core->installSelectedComponentsSilently(QStringList() << QLatin1String("B"))); QTest::ignoreMessage(QtDebugMsg, "Preparing meta information download..."); QTest::ignoreMessage(QtDebugMsg, "Cannot install MissingComponent. Component not found.\n"); - QCOMPARE(PackageManagerCore::Success, core->installSelectedComponentsSilently(QStringList() + QCOMPARE(PackageManagerCore::Canceled, core->installSelectedComponentsSilently(QStringList() << QLatin1String("MissingComponent"))); - QCOMPARE(PackageManagerCore::Success, core->status()); + QCOMPARE(PackageManagerCore::Canceled, core->status()); } void testUninstallPackageFails() diff --git a/tests/auto/installer/commandlineupdate/tst_commandlineupdate.cpp b/tests/auto/installer/commandlineupdate/tst_commandlineupdate.cpp index 5a25bbb39..07dad9d31 100644 --- a/tests/auto/installer/commandlineupdate/tst_commandlineupdate.cpp +++ b/tests/auto/installer/commandlineupdate/tst_commandlineupdate.cpp @@ -171,20 +171,13 @@ private slots: void testUpdateNoUpdatesForSelectedPackage() { setRepository(":///data/installPackagesRepositoryUpdate"); - // Succeeds as no updates available for component so nothing to do - QCOMPARE(PackageManagerCore::Success, core->updateComponentsSilently(QStringList() + // No updates available for component so nothing to do + QCOMPARE(PackageManagerCore::Canceled, core->updateComponentsSilently(QStringList() << "componentInvalid")); } void testUpdateTwoPackageSilently() { - setRepository(":///data/installPackagesRepository"); - QCOMPARE(PackageManagerCore::Success, core->installSelectedComponentsSilently(QStringList() - << "componentA" << "componentB" << "componentG")); - VerifyInstaller::verifyInstallerResources(m_installDir, "componentB", "2.0.0content.txt"); - VerifyInstaller::verifyInstallerResources(m_installDir, "componentG", "1.0.0content.txt"); - core->commitSessionOperations(); - setRepository(":///data/installPackagesRepositoryUpdate"); QCOMPARE(PackageManagerCore::Success, core->updateComponentsSilently(QStringList() << "componentB" << "componentG")); diff --git a/tests/auto/installer/createoffline/createoffline.pro b/tests/auto/installer/createoffline/createoffline.pro new file mode 100644 index 000000000..5f14bf0bd --- /dev/null +++ b/tests/auto/installer/createoffline/createoffline.pro @@ -0,0 +1,9 @@ +include(../../qttest.pri) + +QT -= gui +QT += testlib + +SOURCES = tst_createoffline.cpp + +RESOURCES += settings.qrc \ + ..\shared\config.qrc diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-license/2020-12-01-1511_meta.7z b/tests/auto/installer/createoffline/data/repository-bothmeta-license/2020-12-01-1511_meta.7z new file mode 100644 index 000000000..31ffc5764 Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-bothmeta-license/2020-12-01-1511_meta.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-license/Updates.xml b/tests/auto/installer/createoffline/data/repository-bothmeta-license/Updates.xml new file mode 100644 index 000000000..064fc6529 --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-bothmeta-license/Updates.xml @@ -0,0 +1,22 @@ + + {AnyApplication} + 1.0.0 + true + + org.qtproject.ifw.example.licenseagreement + README (requires license agreement) + README can only be installed if the user agrees to the licenses. + 2021-01-01 + 1.0.0-1 + true + + content.7z + + + + + 6d6a4cead84562b7034fcf1b9975779f1f030151 + + 6d6a4cead84562b7034fcf1b9975779f1f030151 + 2020-12-01-1511_meta.7z + diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z b/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z new file mode 100644 index 000000000..d80146aa8 Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z.sha1 b/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z.sha1 new file mode 100644 index 000000000..49df32fea --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z.sha1 @@ -0,0 +1 @@ +192106030e00704e880fb729c3f7bed8ced8db92 \ No newline at end of file diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1meta.7z b/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1meta.7z new file mode 100644 index 000000000..31ffc5764 Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1meta.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/2020-12-01-1524_meta.7z b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/2020-12-01-1524_meta.7z new file mode 100644 index 000000000..93f95c1d7 Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/2020-12-01-1524_meta.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/Updates.xml b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/Updates.xml new file mode 100644 index 000000000..cc0ae0206 --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/Updates.xml @@ -0,0 +1,20 @@ + + {AnyApplication} + 1.0.0 + true + + or.qtproject.ifw.example.openreadme + Open readme + Show checkbox asking whether to open Readme at the end + 1.0.0-1 + 2021-01-01 + true + + + content.7z + readmecheckboxform.ui + 9b8977a50cb49a77a6ff037d776b73c341412a25 + + 9b8977a50cb49a77a6ff037d776b73c341412a25 + 2020-12-01-1524_meta.7z + diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z new file mode 100644 index 000000000..98154743c Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z.sha1 b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z.sha1 new file mode 100644 index 000000000..154c20383 --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z.sha1 @@ -0,0 +1 @@ +27cdf6cc53d2317aa2a869cb3f93e7a54c489b5f \ No newline at end of file diff --git a/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1meta.7z b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1meta.7z new file mode 100644 index 000000000..93f95c1d7 Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1meta.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-componentmeta-script/Updates.xml b/tests/auto/installer/createoffline/data/repository-componentmeta-script/Updates.xml new file mode 100644 index 000000000..42458e7ce --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-componentmeta-script/Updates.xml @@ -0,0 +1,17 @@ + + {AnyApplication} + 1.0.0 + true + + org.qtproject.ifw.example + README.txt + A README.txt, accessible through a start menu entry. + 1.0.0-1 + 2021-01-01 + true + + + content.7z + 08c2a05d861543e88a8808f576d5c731e0301ab4 + + diff --git a/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z b/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z new file mode 100644 index 000000000..40ebd637a Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 b/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 new file mode 100644 index 000000000..d1c96e12b --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 @@ -0,0 +1 @@ +d9ad62d190d93c92175741c02d17aa6c39b0e03d \ No newline at end of file diff --git a/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1meta.7z b/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1meta.7z new file mode 100644 index 000000000..f35ec6071 Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1meta.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-missingdependency/Updates.xml b/tests/auto/installer/createoffline/data/repository-missingdependency/Updates.xml new file mode 100644 index 000000000..2ec3a5ac4 --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-missingdependency/Updates.xml @@ -0,0 +1,22 @@ + + {AnyApplication} + 1.0.0 + true + + example.with.unstable.dependency + README.txt + A README.txt, accessible through a start menu entry. + 1.0.0-1 + 2021-01-01 + false + missing.dependency.component + + + example.without.unstable.dependency + README.txt + A README.txt, accessible through a start menu entry. + 1.0.0-1 + 2013-01-01 + false + + diff --git a/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/2020-12-01-1519_meta.7z b/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/2020-12-01-1519_meta.7z new file mode 100644 index 000000000..e96ed9ec0 Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/2020-12-01-1519_meta.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/Updates.xml b/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/Updates.xml new file mode 100644 index 000000000..e0826ae86 --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/Updates.xml @@ -0,0 +1,18 @@ + + {AnyApplication} + 1.0.0 + true + + org.qtproject.ifw.example + README.txt + A README.txt, accessible through a start menu entry. + 1.0.0-1 + 2021-01-01 + true + + + content.7z + + 70ff1e1062ada01ea698a908f7549fcb826f17e1 + 2020-12-01-1519_meta.7z + diff --git a/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z b/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z new file mode 100644 index 000000000..40ebd637a Binary files /dev/null and b/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z differ diff --git a/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 b/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 new file mode 100644 index 000000000..d1c96e12b --- /dev/null +++ b/tests/auto/installer/createoffline/data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 @@ -0,0 +1 @@ +d9ad62d190d93c92175741c02d17aa6c39b0e03d \ No newline at end of file diff --git a/tests/auto/installer/createoffline/settings.qrc b/tests/auto/installer/createoffline/settings.qrc new file mode 100644 index 000000000..2c546d7f2 --- /dev/null +++ b/tests/auto/installer/createoffline/settings.qrc @@ -0,0 +1,27 @@ + + + data/repository-bothmeta-license/2020-12-01-1511_meta.7z + data/repository-bothmeta-license/Updates.xml + data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z + data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1content.7z.sha1 + data/repository-bothmeta-license/org.qtproject.ifw.example.licenseagreement/1.0.0-1meta.7z + + data/repository-bothmeta-userinteface/2020-12-01-1524_meta.7z + data/repository-bothmeta-userinteface/Updates.xml + data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z + data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1content.7z.sha1 + data/repository-bothmeta-userinteface/or.qtproject.ifw.example.openreadme/1.0.0-1meta.7z + + data/repository-componentmeta-script/Updates.xml + data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z + data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 + data/repository-componentmeta-script/org.qtproject.ifw.example/1.0.0-1meta.7z + + data/repository-missingdependency/Updates.xml + + data/repository-unifiedmeta-script/2020-12-01-1519_meta.7z + data/repository-unifiedmeta-script/Updates.xml + data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z + data/repository-unifiedmeta-script/org.qtproject.ifw.example/1.0.0-1content.7z.sha1 + + diff --git a/tests/auto/installer/createoffline/tst_createoffline.cpp b/tests/auto/installer/createoffline/tst_createoffline.cpp new file mode 100644 index 000000000..474b1d5de --- /dev/null +++ b/tests/auto/installer/createoffline/tst_createoffline.cpp @@ -0,0 +1,171 @@ +/************************************************************************** +** +** 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 "../shared/packagemanager.h" + +#include +#include + +#include +#include + +using namespace QInstaller; + +class tst_CreateOffline : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase() + { + // Need to provide a replacement base binary as we are not running actual installer +#ifdef Q_OS_WIN + m_installerBase = "../../../../bin/installerbase.exe"; +#else + m_installerBase = "../../../../bin/installerbase"; +#endif + if (!QFile(m_installerBase).exists()) { + QSKIP("No \"installerbase\" binary found in source tree. This can be " + "the case if this is an out of sources build or the binaries are " + "installed to a location with a different path prefix."); + } + } + + void init() + { + // Get new target directory for each test function + m_targetDir = QInstaller::generateTemporaryFileName(); + } + + void cleanup() + { + QDir dir(m_targetDir); + QVERIFY(dir.removeRecursively()); + } + + void testCreateOfflineInstaller_data() + { + QTest::addColumn("repository"); + QTest::addColumn("component"); + QTest::addColumn("expectedStatus"); + QTest::newRow("Both metaformats | License") + << ":///data/repository-bothmeta-license" << "org.qtproject.ifw.example.licenseagreement" + << PackageManagerCore::Success; + QTest::newRow("Both metaformats | UserInterface") + << ":///data/repository-bothmeta-userinteface" << "or.qtproject.ifw.example.openreadme" + << PackageManagerCore::Success; + QTest::newRow("Component metaformat | Script") + << ":///data/repository-componentmeta-script" << "org.qtproject.ifw.example" + << PackageManagerCore::Success; + QTest::newRow("Unified metaformat | Script") + << ":///data/repository-unifiedmeta-script" << "org.qtproject.ifw.example" + << PackageManagerCore::Success; + QTest::newRow("Non-existing component") + << ":///data/repository-unifiedmeta-script" << "a.dummy.component" + << PackageManagerCore::Canceled; + QTest::newRow("Invalid repository") + << ":///data/repository-invalid" << "a.dummy.component" + << PackageManagerCore::Failure; + } + + void testCreateOfflineInstaller() + { + QFETCH(QString, repository); + QFETCH(QString, component); + QFETCH(PackageManagerCore::Status, expectedStatus); + + PackageManagerCore *core = PackageManager::getPackageManagerWithInit(m_targetDir, repository); + core->setCommandLineInstance(true); + core->setOfflineBaseBinary(m_installerBase); + core->setOfflineBinaryName("ifw_test_offline"); + core->setAutoAcceptLicenses(); + + // Replace the custom message handler installed in QInstaller::init() to suppress all output + qInstallMessageHandler(silentTestMessageHandler); + + QCOMPARE(expectedStatus, core->createOfflineInstaller(QStringList() << component)); + + if (expectedStatus == PackageManagerCore::Success) { +#ifdef Q_OS_LINUX + QVERIFY(QFile::exists(m_targetDir + QDir::separator() + "ifw_test_offline")); +#elif defined Q_OS_MACOS + QVERIFY(QFile::exists(m_targetDir + QDir::separator() + "ifw_test_offline.dmg")); +#elif defined Q_OS_WIN + QVERIFY(QFile::exists(m_targetDir + QDir::separator() + "ifw_test_offline.exe")); +#endif + } + } + + void testCreateOfflineWithUnstableComponent_data() + { + QTest::addColumn("repository"); + QTest::addColumn("component"); + QTest::addColumn("allowUnstable"); + QTest::addColumn("expectedStatus"); + QTest::newRow("Allow unstable | Missing dependency with selected component") + << ":///data/repository-missingdependency" << "example.with.unstable.dependency" + << true << PackageManagerCore::Canceled; + QTest::newRow("Disallow unstable | Missing dependency with selected component") + << ":///data/repository-missingdependency" << "example.with.unstable.dependency" + << false << PackageManagerCore::Failure; + QTest::newRow("Allow unstable | Missing dependency with other component") + << ":///data/repository-missingdependency" << "example.without.unstable.dependency" + << true << PackageManagerCore::Success; + QTest::newRow("Disallow unstable | Missing dependency with other component") + << ":///data/repository-missingdependency" << "example.without.unstable.dependency" + << false << PackageManagerCore::Failure; + } + + void testCreateOfflineWithUnstableComponent() + { + QFETCH(QString, repository); + QFETCH(QString, component); + QFETCH(bool, allowUnstable); + QFETCH(PackageManagerCore::Status, expectedStatus); + + PackageManagerCore *core = PackageManager::getPackageManagerWithInit(m_targetDir, repository); + core->setCommandLineInstance(true); + core->setOfflineBaseBinary(m_installerBase); + core->setOfflineBinaryName("ifw_test_offline"); + core->settings().setAllowUnstableComponents(allowUnstable); + core->autoAcceptMessageBoxes(); + + // Replace the custom message handler installed in QInstaller::init() to suppress all output + qInstallMessageHandler(silentTestMessageHandler); + + QCOMPARE(expectedStatus, core->createOfflineInstaller(QStringList() << component)); + } + +private: + QString m_targetDir; + QString m_installerBase; +}; + +QTEST_GUILESS_MAIN(tst_CreateOffline) + +#include "tst_createoffline.moc" diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro index 2f65d607e..114c43d7a 100644 --- a/tests/auto/installer/installer.pro +++ b/tests/auto/installer/installer.pro @@ -38,7 +38,8 @@ SUBDIRS += \ licenseagreement \ globalsettingsoperation \ elevatedexecuteoperation \ - treename + treename \ + createoffline win32 { SUBDIRS += registerfiletypeoperation \ diff --git a/tests/auto/installer/shared/packagemanager.h b/tests/auto/installer/shared/packagemanager.h index d5260ef5e..4cc5426ad 100644 --- a/tests/auto/installer/shared/packagemanager.h +++ b/tests/auto/installer/shared/packagemanager.h @@ -39,6 +39,8 @@ using namespace QInstaller; +void silentTestMessageHandler(QtMsgType, const QMessageLogContext &, const QString &) {} + struct PackageManager { static PackageManagerCore *getPackageManager(const QString &targetDir, const QString &repository = QString()) -- cgit v1.2.3