summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2020-04-06 13:59:11 +0300
committerKatja Marttila <katja.marttila@qt.io>2020-04-09 09:50:03 +0300
commit90523cb44306949893b5ae0f3706185c7d364c6f (patch)
tree285ffe703d752caf91d108980b6c004ced07ffe0 /tests
parenta58ec153e6e2f91e7cfa89c15ecd222c29bf3fb9 (diff)
Fix shortcut creation when installing from CLI
Change default button from Retry to Cancel if operation fails to avoid infinite loop when running from command line interface. Added also unit tests for shortcut operation. Task-number: QTIFW-1666 QTIFW-1710 Change-Id: I171b6aecd9886acce0051b7082842f8f76b22046 Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/installer/createshortcutoperation/createshortcutoperation.pro9
-rw-r--r--tests/auto/installer/createshortcutoperation/data/repository/A/1.0.2-1content.7zbin0 -> 185 bytes
-rw-r--r--tests/auto/installer/createshortcutoperation/data/repository/A/1.0.2-1meta.7zbin0 -> 975 bytes
-rw-r--r--tests/auto/installer/createshortcutoperation/data/repository/Updates.xml17
-rw-r--r--tests/auto/installer/createshortcutoperation/installer-config/config.xml6
-rw-r--r--tests/auto/installer/createshortcutoperation/settings.qrc10
-rw-r--r--tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp105
-rw-r--r--tests/auto/installer/installer.pro3
8 files changed, 149 insertions, 1 deletions
diff --git a/tests/auto/installer/createshortcutoperation/createshortcutoperation.pro b/tests/auto/installer/createshortcutoperation/createshortcutoperation.pro
new file mode 100644
index 000000000..c57bcfb98
--- /dev/null
+++ b/tests/auto/installer/createshortcutoperation/createshortcutoperation.pro
@@ -0,0 +1,9 @@
+include(../../qttest.pri)
+
+QT -= gui
+QT += testlib
+
+SOURCES = tst_createshortcutoperation.cpp
+
+RESOURCES += \
+ settings.qrc
diff --git a/tests/auto/installer/createshortcutoperation/data/repository/A/1.0.2-1content.7z b/tests/auto/installer/createshortcutoperation/data/repository/A/1.0.2-1content.7z
new file mode 100644
index 000000000..8ba90b13b
--- /dev/null
+++ b/tests/auto/installer/createshortcutoperation/data/repository/A/1.0.2-1content.7z
Binary files differ
diff --git a/tests/auto/installer/createshortcutoperation/data/repository/A/1.0.2-1meta.7z b/tests/auto/installer/createshortcutoperation/data/repository/A/1.0.2-1meta.7z
new file mode 100644
index 000000000..17eae879d
--- /dev/null
+++ b/tests/auto/installer/createshortcutoperation/data/repository/A/1.0.2-1meta.7z
Binary files differ
diff --git a/tests/auto/installer/createshortcutoperation/data/repository/Updates.xml b/tests/auto/installer/createshortcutoperation/data/repository/Updates.xml
new file mode 100644
index 000000000..0826afae8
--- /dev/null
+++ b/tests/auto/installer/createshortcutoperation/data/repository/Updates.xml
@@ -0,0 +1,17 @@
+<Updates>
+ <ApplicationName>{AnyApplication}</ApplicationName>
+ <ApplicationVersion>1.0.0</ApplicationVersion>
+ <Checksum>false</Checksum>
+ <PackageUpdate>
+ <Name>A</Name>
+ <DisplayName>A</DisplayName>
+ <Description>Example component A</Description>
+ <Version>1.0.2-1</Version>
+ <ReleaseDate>2015-01-01</ReleaseDate>
+ <Default>true</Default>
+ <Script>script.qs</Script>
+ <UpdateFile CompressedSize="225" UncompressedSize="75" OS="Any"/>
+ <DownloadableArchives>content.7z</DownloadableArchives>
+ <SHA1>6d7a3e15d11a4d94b81452fc2aa18e705a01c922</SHA1>
+ </PackageUpdate>
+</Updates>
diff --git a/tests/auto/installer/createshortcutoperation/installer-config/config.xml b/tests/auto/installer/createshortcutoperation/installer-config/config.xml
new file mode 100644
index 000000000..c201d4fa5
--- /dev/null
+++ b/tests/auto/installer/createshortcutoperation/installer-config/config.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Installer>
+ <Name>test</Name>
+ <Version>1.0.0</Version>
+ <StartMenuDir>Qt Installer Framework Unit Test</StartMenuDir>
+</Installer>
diff --git a/tests/auto/installer/createshortcutoperation/settings.qrc b/tests/auto/installer/createshortcutoperation/settings.qrc
new file mode 100644
index 000000000..410fbf81a
--- /dev/null
+++ b/tests/auto/installer/createshortcutoperation/settings.qrc
@@ -0,0 +1,10 @@
+<RCC>
+ <qresource prefix="/">
+ <file>data/repository/Updates.xml</file>
+ <file>data/repository/A/1.0.2-1content.7z</file>
+ <file>data/repository/A/1.0.2-1meta.7z</file>
+ </qresource>
+ <qresource prefix="/metadata">
+ <file>installer-config/config.xml</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp b/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp
new file mode 100644
index 000000000..5b90c9628
--- /dev/null
+++ b/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp
@@ -0,0 +1,105 @@
+/**************************************************************************
+**
+** Copyright (C) 2020 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 <init.h>
+#include <createshortcutoperation.h>
+#include <utils.h>
+#include <binarycontent.h>
+#include <packagemanagercore.h>
+#include <settings.h>
+#include <fileutils.h>
+
+#include <QDir>
+#include <QObject>
+#include <QTest>
+#include <QFile>
+#include <qsettingswrapper.h>
+#include <QDebug>
+
+using namespace KDUpdater;
+using namespace QInstaller;
+
+class tst_createshortcutoperation : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testMissingArguments()
+ {
+ CreateShortcutOperation op;
+
+ QVERIFY(op.testOperation());
+ QVERIFY(!op.performOperation());
+
+ QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments);
+ QCOMPARE(op.errorString(), QString("Invalid arguments in CreateShortcut: 0 arguments given,"
+ " 2 or 3 arguments expected in the form: <target> <link location> "
+ "[target arguments] [\"workingDirectory=...\"] [\"iconPath=...\"] "
+ "[\"iconId=...\"] [\"description=...\"]."));
+ }
+
+ void testCreateShortcutForCurrentUserFromCLI()
+ {
+ QInstaller::init();
+ PackageManagerCore *core = new PackageManagerCore(BinaryContent::MagicInstallerMarker, QList<OperationBlob> (),
+ QString(), Protocol::DefaultAuthorizationKey, Protocol::Mode::Production,
+ QHash<QString, QString>(), true);
+ core->setAllowedRunningProcesses(QStringList() << QCoreApplication::applicationFilePath());
+ QSet<Repository> repoList;
+ Repository repo = Repository::fromUserInput(":///data/repository");
+ repoList.insert(repo);
+ core->settings().setDefaultRepositories(repoList);
+
+ QString installDir = QInstaller::generateTemporaryFileName();
+ QDir().mkpath(installDir);
+ core->setValue(scTargetDir, installDir);
+ core->installDefaultComponentsSilently();
+
+ QSettingsWrapper user(QLatin1String("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\"
+ "CurrentVersion\\Explorer\\User Shell Folders"), QSettingsWrapper::NativeFormat);
+ //Replace %USERS% from "Programs"
+ const QString programs = replaceWindowsEnvironmentVariables(user.value(QLatin1String("Programs"), QString()).toString());
+ const QString startMenuDir = programs + QDir::separator() + "Qt Installer Framework Unit Test";
+ QCOMPARE(startMenuDir, core->value("StartMenuDir"));
+
+ QString linkLocation = core->value("StartMenuDir") + QDir::separator() + "A.lnk";
+ QFile file(linkLocation);
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ file.close();
+
+ core->setPackageManager();
+ core->commitSessionOperations();
+ core->uninstallComponentsSilently(QStringList() << "A");
+ QVERIFY(!QFile::exists(linkLocation));
+ core->deleteLater();
+ }
+};
+
+QTEST_MAIN(tst_createshortcutoperation)
+
+#include "tst_createshortcutoperation.moc"
diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro
index d5926ab6e..ecba4f9bb 100644
--- a/tests/auto/installer/installer.pro
+++ b/tests/auto/installer/installer.pro
@@ -37,7 +37,8 @@ SUBDIRS += \
environmentvariableoperation
win32 {
- SUBDIRS += registerfiletypeoperation
+ SUBDIRS += registerfiletypeoperation \
+ createshortcutoperation
}
linux-g++* {