summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2022-11-22 13:59:25 +0200
committerKatja Marttila <katja.marttila@qt.io>2022-11-25 13:36:52 +0200
commitf02c3a2f2a6a5db84a947ca6d4f4ab5f5d867d41 (patch)
treec375cced025a037c4da770cbc54102756deaa3fe /tests/auto
parent2d618ef8fa7df7f01b680fdcec0799692a8f6001 (diff)
Make Settings operation to support _OLD and placeholders
Setting can be a file. The Settings path was hard coded to .dat file, which made it impossible to move the settings file to a different location or use some other settings file instead. This change saves the settings path with placeholder name, which is resolved before performing settings operation or undo operation. In case settings path is hard coded to .dat file and the settings file is relocated, this can be overcome by setting variable name _OLD to point to the location where the settings file originally was. Installer uses this _OLD syntax to resolve the new location. For example in the following example Tools.ini is relocated from OldLocation to NewLocation. Setting the installer values the following way will tell installer to use the settings from NewLocation instead of OldLocation. installer.setValue("MY_OWN_EXECUTABLE", "C:/Qt/NewLocation/Tools.ini") installer.setValue("MY_OWN_EXECUTABLE_OLD", "C:/Qt/OldLocation/Tools.ini") Task-number: QTIFW-2882 Change-Id: I47dc68dfba8a49f37ab361edc8c64d3e5523e02e Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/installer/settingsoperation/data/repository/B/1.0.0meta.7zbin0 -> 967 bytes
-rw-r--r--tests/auto/installer/settingsoperation/data/repository/C/1.0.0meta.7zbin0 -> 958 bytes
-rw-r--r--tests/auto/installer/settingsoperation/data/repository/Updates.xml20
-rw-r--r--tests/auto/installer/settingsoperation/settings.qrc2
-rw-r--r--tests/auto/installer/settingsoperation/tst_settingsoperation.cpp66
5 files changed, 86 insertions, 2 deletions
diff --git a/tests/auto/installer/settingsoperation/data/repository/B/1.0.0meta.7z b/tests/auto/installer/settingsoperation/data/repository/B/1.0.0meta.7z
new file mode 100644
index 000000000..211bc0e0a
--- /dev/null
+++ b/tests/auto/installer/settingsoperation/data/repository/B/1.0.0meta.7z
Binary files differ
diff --git a/tests/auto/installer/settingsoperation/data/repository/C/1.0.0meta.7z b/tests/auto/installer/settingsoperation/data/repository/C/1.0.0meta.7z
new file mode 100644
index 000000000..a990fdbf1
--- /dev/null
+++ b/tests/auto/installer/settingsoperation/data/repository/C/1.0.0meta.7z
Binary files differ
diff --git a/tests/auto/installer/settingsoperation/data/repository/Updates.xml b/tests/auto/installer/settingsoperation/data/repository/Updates.xml
index eddb160c0..3e88f849d 100644
--- a/tests/auto/installer/settingsoperation/data/repository/Updates.xml
+++ b/tests/auto/installer/settingsoperation/data/repository/Updates.xml
@@ -8,8 +8,26 @@
<Description>Example component A</Description>
<Version>1.0.2-1</Version>
<ReleaseDate>2015-01-01</ReleaseDate>
- <Default>true</Default>
+ <Default>false</Default>
<Script>script.qs</Script>
<SHA1>5dc8a98f591998de0c555e194e228fa740a15632</SHA1>
</PackageUpdate>
+ <PackageUpdate>
+ <Name>B</Name>
+ <DisplayName>B</DisplayName>
+ <Description>Example component B</Description>
+ <Version>1.0.0</Version>
+ <ReleaseDate>2015-01-01</ReleaseDate>
+ <Default>false</Default>
+ <Script>script.qs</Script>
+ </PackageUpdate>
+ <PackageUpdate>
+ <Name>C</Name>
+ <DisplayName>C</DisplayName>
+ <Description>Example component C</Description>
+ <Version>1.0.0</Version>
+ <ReleaseDate>2015-01-01</ReleaseDate>
+ <Default>false</Default>
+ <Script>script.qs</Script>
+ </PackageUpdate>
</Updates>
diff --git a/tests/auto/installer/settingsoperation/settings.qrc b/tests/auto/installer/settingsoperation/settings.qrc
index d030220ab..8da639ad6 100644
--- a/tests/auto/installer/settingsoperation/settings.qrc
+++ b/tests/auto/installer/settingsoperation/settings.qrc
@@ -2,5 +2,7 @@
<qresource prefix="/">
<file>data/repository/Updates.xml</file>
<file>data/repository/A/1.0.2-1meta.7z</file>
+ <file>data/repository/B/1.0.0meta.7z</file>
+ <file>data/repository/C/1.0.0meta.7z</file>
</qresource>
</RCC>
diff --git a/tests/auto/installer/settingsoperation/tst_settingsoperation.cpp b/tests/auto/installer/settingsoperation/tst_settingsoperation.cpp
index 9b08d4f6f..2da0870c7 100644
--- a/tests/auto/installer/settingsoperation/tst_settingsoperation.cpp
+++ b/tests/auto/installer/settingsoperation/tst_settingsoperation.cpp
@@ -177,6 +177,7 @@ private slots:
QFile testFile(testFilePath);
QVERIFY2(testFile.open(QIODevice::WriteOnly | QIODevice::Text), contentFile.errorString().toLatin1());
+ m_cleanupFilePaths << testFilePath;
QTextStream out(&testFile);
@@ -244,6 +245,7 @@ private slots:
QFile testFile(testFilePath);
QVERIFY2(testFile.open(QIODevice::WriteOnly | QIODevice::Text), contentFile.errorString()
.toLatin1());
+ m_cleanupFilePaths << testFilePath;
QTextStream out(&testFile);
@@ -293,7 +295,7 @@ private slots:
QCOMPARE(testSettings.value("testcategory/categoryarrayvalue1").toStringList(),
QStringList() << "value1" << "value2" << "value3");
- core->installDefaultComponentsSilently();
+ core->installSelectedComponentsSilently(QStringList() << "A");
QCOMPARE(testSettings.value("testcategory/categoryarrayvalue1").toStringList(),
QStringList() << "value1" << "value2" << "value3" << "valueFromScript");
@@ -309,6 +311,68 @@ private slots:
core->deleteLater();
}
+ void testPerformingFromCLIWithPlaceholders()
+ {
+ QString installDir = QInstaller::generateTemporaryFileName();
+ QVERIFY(QDir().mkpath(installDir));
+ PackageManagerCore *core = PackageManager::getPackageManagerWithInit
+ (installDir, ":///data/repository");
+
+ core->installSelectedComponentsSilently(QStringList() << "B");
+ // Path is set in component constructor in install script
+ const QString settingsFile = core->value("SettingsPathFromVariable");
+ QSettings testSettings(QDir(m_testSettingsDirPath).filePath(settingsFile),
+ QSettings::IniFormat);
+
+ QCOMPARE(testSettings.value("testcategory/categoryarrayvalue1").toStringList(),
+ QStringList() << "ValueFromPlaceholder");
+
+ core->commitSessionOperations();
+ core->setPackageManager();
+ core->uninstallComponentsSilently(QStringList() << "B");
+
+ // Settings file is removed as it is empty
+ QVERIFY(!QFile::exists(settingsFile));
+ QDir dir(installDir);
+ QVERIFY(dir.removeRecursively());
+ core->deleteLater();
+ }
+
+ void testPerformingFromCLIWithSettingsFileMoved()
+ {
+ QString installDir = QInstaller::generateTemporaryFileName();
+ QVERIFY(QDir().mkpath(installDir));
+ PackageManagerCore *core = PackageManager::getPackageManagerWithInit
+ (installDir, ":///data/repository");
+
+
+ core->installSelectedComponentsSilently(QStringList() << "C");
+
+ const QString settingsFileName = qApp->applicationDirPath() + "/oldTestSettings.ini";
+ QSettings testSettings(QDir(m_testSettingsDirPath).filePath(settingsFileName),
+ QSettings::IniFormat);
+
+ QCOMPARE(testSettings.value("testcategory/categoryarrayvalue1").toStringList(),
+ QStringList() << "valueFromScript");
+
+ QFile settingsFile(settingsFileName);
+ // Move the settings path to new location. Script has set values
+ // ComponentCSettingsPath (@InstallerDirPath@/newTestSettings.ini) and
+ // ComponentCSettingsPath_OLD (@InstallerDirPath@/oldTestSettings.ini) so
+ // UNDO operation should delete the moved newTestSettings.ini file instead.
+ QVERIFY2(settingsFile.rename(qApp->applicationDirPath() + "/newTestSettings.ini"), "Could not move settings file.");
+ core->commitSessionOperations();
+ core->setPackageManager();
+ core->uninstallComponentsSilently(QStringList() << "C");
+
+ // Settings file is removed in uninstall as it is empty
+ QVERIFY2(!QFile::exists(qApp->applicationDirPath() + "/newTestSettings.ini"), "Settings file not deleted correctly");
+
+ QDir dir(installDir);
+ QVERIFY(dir.removeRecursively());
+ core->deleteLater();
+ }
+
// called after all tests
void cleanupTestCase()
{