summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2020-04-01 12:43:35 +0300
committerKatja Marttila <katja.marttila@qt.io>2020-04-06 12:28:03 +0300
commit7e4296f95ac3cd5d947b8d52bb64a379b7d62fe1 (patch)
treefc1bf07d3635ff24b1b7c236d2de60a8b6b19712 /tests
parent02b23b874d7ec93f94865ce36fc33eb9e3c3ee7d (diff)
Add CLI test for RegisterFileType
Task-number: QTIFW-1714 Change-Id: I530a30705a700152f3dc087d9fc775d933f5d586 Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/installer/registerfiletypeoperation/data/repository/A/1.0.2-1content.7zbin0 -> 185 bytes
-rw-r--r--tests/auto/installer/registerfiletypeoperation/data/repository/A/1.0.2-1meta.7zbin0 -> 975 bytes
-rw-r--r--tests/auto/installer/registerfiletypeoperation/data/repository/Updates.xml17
-rw-r--r--tests/auto/installer/registerfiletypeoperation/registerfiletypeoperation.pro4
-rw-r--r--tests/auto/installer/registerfiletypeoperation/settings.qrc7
-rw-r--r--tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp95
6 files changed, 100 insertions, 23 deletions
diff --git a/tests/auto/installer/registerfiletypeoperation/data/repository/A/1.0.2-1content.7z b/tests/auto/installer/registerfiletypeoperation/data/repository/A/1.0.2-1content.7z
new file mode 100644
index 000000000..8ba90b13b
--- /dev/null
+++ b/tests/auto/installer/registerfiletypeoperation/data/repository/A/1.0.2-1content.7z
Binary files differ
diff --git a/tests/auto/installer/registerfiletypeoperation/data/repository/A/1.0.2-1meta.7z b/tests/auto/installer/registerfiletypeoperation/data/repository/A/1.0.2-1meta.7z
new file mode 100644
index 000000000..f3f25d357
--- /dev/null
+++ b/tests/auto/installer/registerfiletypeoperation/data/repository/A/1.0.2-1meta.7z
Binary files differ
diff --git a/tests/auto/installer/registerfiletypeoperation/data/repository/Updates.xml b/tests/auto/installer/registerfiletypeoperation/data/repository/Updates.xml
new file mode 100644
index 000000000..0826afae8
--- /dev/null
+++ b/tests/auto/installer/registerfiletypeoperation/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/registerfiletypeoperation/registerfiletypeoperation.pro b/tests/auto/installer/registerfiletypeoperation/registerfiletypeoperation.pro
index 0e541ceed..88e366b6d 100644
--- a/tests/auto/installer/registerfiletypeoperation/registerfiletypeoperation.pro
+++ b/tests/auto/installer/registerfiletypeoperation/registerfiletypeoperation.pro
@@ -4,3 +4,7 @@ QT -= gui
QT += testlib network
SOURCES = tst_registerfiletypeoperation.cpp
+
+RESOURCES += \
+ settings.qrc \
+ ..\shared\config.qrc
diff --git a/tests/auto/installer/registerfiletypeoperation/settings.qrc b/tests/auto/installer/registerfiletypeoperation/settings.qrc
new file mode 100644
index 000000000..10cc3c3bb
--- /dev/null
+++ b/tests/auto/installer/registerfiletypeoperation/settings.qrc
@@ -0,0 +1,7 @@
+<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>
+</RCC>
diff --git a/tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp b/tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp
index afb50b196..f33fcb5d9 100644
--- a/tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp
+++ b/tests/auto/installer/registerfiletypeoperation/tst_registerfiletypeoperation.cpp
@@ -26,9 +26,12 @@
**
**************************************************************************/
-#include "init.h"
-#include "registerfiletypeoperation.h"
-#include "packagemanagercore.h"
+#include <init.h>
+#include <registerfiletypeoperation.h>
+#include <packagemanagercore.h>
+#include <binarycontent.h>
+#include <settings.h>
+#include <fileutils.h>
#include <QDir>
#include <QObject>
@@ -36,6 +39,8 @@
#include <QFile>
#include <QTextStream>
#include <QSettings>
+#include <QtGlobal>
+
#include "qsettingswrapper.h"
using namespace KDUpdater;
@@ -45,6 +50,24 @@ class tst_registerfiletypeoperation : public QObject
{
Q_OBJECT
+private:
+ void verifySettings()
+ {
+ QCOMPARE(m_settings->value(m_defaultKey).toString(), m_progId);
+ QCOMPARE(m_settings->value(m_openWithProgIdkey).toString(), QString());
+ QCOMPARE(m_settings->value(m_shellKey).toString(), m_command);
+ QCOMPARE(m_settings->value(m_shellAppkey).toString(), m_command);
+ }
+
+ void verifySettingsCleaned()
+ {
+ //Test that values have been removed after undo operation
+ QCOMPARE(m_settings->value(m_defaultKey).toString(), QString());
+ QCOMPARE(m_settings->value(m_openWithProgIdkey).toString(), QString());
+ QCOMPARE(m_settings->value(m_shellKey).toString(), QString());
+ QCOMPARE(m_settings->value(m_shellAppkey).toString(), QString());
+ }
+
private slots:
void initTestCase()
{
@@ -62,7 +85,22 @@ private slots:
m_command = m_core.environmentVariable("SystemRoot") + "\\notepad.exe";
m_progId = "QtProject.QtInstallerFramework." + m_fileType;
+ qputenv("ifw_random_filetype", m_fileType.toUtf8());
+ qputenv("ifw_random_programid", m_progId.toUtf8());
+
+ const QString settingsPath = QString::fromLatin1("HKEY_CURRENT_USER\\Software\\Classes\\");
+ m_settings = new QSettings(settingsPath, QSettings::NativeFormat);
+ m_defaultKey = "." + m_fileType + "/Default";
+ m_openWithProgIdkey = "." + m_fileType + "/OpenWithProgIds/" + m_progId;
+ m_shellKey = m_progId + "/shell/Open/Command/Default/";
+ m_shellAppkey = "/Applications/" + m_progId + "/shell/Open/Command/Default/";
+ }
+ void cleanupTestCase()
+ {
+ qunsetenv("ifw_random_filetype");
+ qunsetenv("ifw_random_programid");
+ delete m_settings;
}
void testMissingArguments()
@@ -82,31 +120,37 @@ private slots:
RegisterFileTypeOperation op(&m_core);
op.setArguments(QStringList() << m_fileType << m_command << "test filetype" <<
"text/plain" << 0 << "ProgId="+m_progId);
-
- const QString settingsPath = QString::fromLatin1("HKEY_CURRENT_USER\\Software\\Classes\\");
- QSettings settings(settingsPath, QSettings::NativeFormat);
-
-
QVERIFY(op.testOperation());
QVERIFY(op.performOperation());
- QString defaultKey = "."+m_fileType+ "/Default";
- QString openWithProgIdkey = "." + m_fileType + "/OpenWithProgIds/" +m_progId;
- QString shellKey = m_progId + "/shell/Open/Command/Default/";
- QString shellAppkey = "/Applications/" + m_progId + "/shell/Open/Command/Default/";
-
- QCOMPARE(settings.value(defaultKey).toString(), m_progId);
- QCOMPARE(settings.value(openWithProgIdkey).toString(), QString());
- QCOMPARE(settings.value(shellKey).toString(), m_command);
- QCOMPARE(settings.value(shellAppkey).toString(), m_command);
-
+ verifySettings();
QVERIFY(op.undoOperation());
+ verifySettingsCleaned();
+ }
- //Test that values have been removed after undo operation
- QCOMPARE(settings.value(defaultKey).toString(), QString());
- QCOMPARE(settings.value(openWithProgIdkey).toString(), QString());
- QCOMPARE(settings.value(shellKey).toString(), QString());
- QCOMPARE(settings.value(shellAppkey).toString(), QString());
+ void testPerformingFromCLI()
+ {
+ QInstaller::init(); //This will eat debug output
+ PackageManagerCore *core = new PackageManagerCore(BinaryContent::MagicInstallerMarker, QList<OperationBlob> ());
+ 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();
+ verifySettings();
+
+ core->commitSessionOperations();
+ core->setPackageManager();
+ core->uninstallComponentsSilently(QStringList() << "A");
+ verifySettingsCleaned();
+
+ QDir dir(installDir);
+ QVERIFY(dir.removeRecursively());
+ core->deleteLater();
}
private:
@@ -114,6 +158,11 @@ private:
QString m_command;
QString m_progId;
PackageManagerCore m_core;
+ QSettings *m_settings;
+ QString m_defaultKey = "."+m_fileType+ "/Default";
+ QString m_openWithProgIdkey = "." + m_fileType + "/OpenWithProgIds/" +m_progId;
+ QString m_shellKey = m_progId + "/shell/Open/Command/Default/";
+ QString m_shellAppkey = "/Applications/" + m_progId + "/shell/Open/Command/Default/";
};
QTEST_MAIN(tst_registerfiletypeoperation)