From f02c3a2f2a6a5db84a947ca6d4f4ab5f5d867d41 Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Tue, 22 Nov 2022 13:59:25 +0200 Subject: 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 --- .../data/repository/B/1.0.0meta.7z | Bin 0 -> 967 bytes .../data/repository/C/1.0.0meta.7z | Bin 0 -> 958 bytes .../settingsoperation/data/repository/Updates.xml | 20 ++++++- .../auto/installer/settingsoperation/settings.qrc | 2 + .../settingsoperation/tst_settingsoperation.cpp | 66 ++++++++++++++++++++- 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 tests/auto/installer/settingsoperation/data/repository/B/1.0.0meta.7z create mode 100644 tests/auto/installer/settingsoperation/data/repository/C/1.0.0meta.7z (limited to 'tests') 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 Binary files /dev/null and b/tests/auto/installer/settingsoperation/data/repository/B/1.0.0meta.7z 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 Binary files /dev/null and b/tests/auto/installer/settingsoperation/data/repository/C/1.0.0meta.7z 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 @@ Example component A 1.0.2-1 2015-01-01 - true + false 5dc8a98f591998de0c555e194e228fa740a15632 + + B + B + Example component B + 1.0.0 + 2015-01-01 + false + + + + C + C + Example component C + 1.0.0 + 2015-01-01 + false + + 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 @@ data/repository/Updates.xml data/repository/A/1.0.2-1meta.7z + data/repository/B/1.0.0meta.7z + data/repository/C/1.0.0meta.7z 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() { -- cgit v1.2.3