summaryrefslogtreecommitdiffstats
path: root/tests/auto/installer/repository/tst_repository.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/installer/repository/tst_repository.cpp')
-rw-r--r--tests/auto/installer/repository/tst_repository.cpp102
1 files changed, 100 insertions, 2 deletions
diff --git a/tests/auto/installer/repository/tst_repository.cpp b/tests/auto/installer/repository/tst_repository.cpp
index db538ba5d..112098130 100644
--- a/tests/auto/installer/repository/tst_repository.cpp
+++ b/tests/auto/installer/repository/tst_repository.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2023 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -39,6 +39,8 @@
using namespace QInstaller;
+typedef QList<QPair<QString, QString>> SettingsPairList;
+
class tst_Repository : public QObject
{
Q_OBJECT
@@ -168,7 +170,7 @@ private slots:
categories.insert(category);
settings.setRepositoryCategories(categories);
- QHash<QString, QPair<Repository, Repository>> update;
+ QMultiHash<QString, QPair<Repository, Repository>> update;
// non-empty update
update.insert(QLatin1String("replace"), qMakePair(original, replacement));
@@ -210,6 +212,102 @@ private slots:
QVERIFY(dir.removeRecursively());
core->deleteLater();
}
+
+ void testPostLoadScriptFromRepository_data()
+ {
+ QTest::addColumn<QStringList>("installComponent");
+ QTest::addColumn<bool>("repositoryPostLoadSetting");
+ QTest::addColumn<SettingsPairList>("expectedSettingsBeforeInstall");
+ QTest::addColumn<SettingsPairList>("expectedSettingsAfterInstall");
+ QTest::addColumn<QStringList>("unexpectedSettings");
+
+ // component A has postLoad = true in component.xml
+ // component B has no postLoad attribute
+ // component C has postLoad = false in component.xml
+
+ SettingsPairList expectedSettingsListAfterInstall;
+ expectedSettingsListAfterInstall.append(QPair<QString, QString>("componentAKey", "componentAValue"));
+
+ SettingsPairList expectedSettingsListBeforeInstall;
+ expectedSettingsListBeforeInstall.append(QPair<QString, QString>("componentBKey", "componentBValue"));
+ expectedSettingsListBeforeInstall.append(QPair<QString, QString>("componentCKey", "componentCValue"));
+
+ QTest::newRow("noRepoPostLoadComponentA")
+ << (QStringList() << "A")
+ << false
+ << expectedSettingsListBeforeInstall
+ << expectedSettingsListAfterInstall
+ << (QStringList());
+
+ // Component B is installed so values from component A and component C should not be set
+ expectedSettingsListAfterInstall.clear();
+ expectedSettingsListAfterInstall.append(QPair<QString, QString>("componentBKey", "componentBValue"));
+ QTest::newRow("noRepoPostLoadComponentB")
+ << (QStringList() << "B")
+ << false
+ << expectedSettingsListBeforeInstall
+ << expectedSettingsListAfterInstall
+ << (QStringList() << "componentAValue" << "componentCValue");
+
+ // PostLoad is set to whole repository. Since only A is installed,
+ // values from component B and component C values are not set
+ expectedSettingsListBeforeInstall.clear();
+ expectedSettingsListAfterInstall.clear();
+ expectedSettingsListAfterInstall.append(QPair<QString, QString>("componentAKey", "componentAValue"));
+ QTest::newRow("repoPostLoadComponentA") << (QStringList() << "A")
+ << true
+ << expectedSettingsListBeforeInstall
+ << expectedSettingsListAfterInstall
+ << (QStringList() << "componentBValue" << "componentCValue");
+
+ // PostLoad is set to whole repository. Since only B is installed,
+ // values from component C and component A are not set.
+ expectedSettingsListAfterInstall.clear();
+ expectedSettingsListAfterInstall.append(QPair<QString, QString>("componentBKey", "componentBValue"));
+ QTest::newRow("repoPostLoadComponentB") << (QStringList() << "B")
+ << true
+ << expectedSettingsListBeforeInstall
+ << expectedSettingsListAfterInstall
+ << (QStringList() << "componentCValue" << "componentAValue");
+
+ // PostLoad is set to whole repository. Since component C has its postload = false,
+ // value is set to component C before install
+ expectedSettingsListBeforeInstall.clear();
+ expectedSettingsListAfterInstall.clear();
+ expectedSettingsListBeforeInstall.append(QPair<QString, QString>("componentCKey", "componentCValue"));
+ QTest::newRow("repoPostLoadComponentC") << (QStringList() << "C")
+ << true
+ << expectedSettingsListBeforeInstall
+ << expectedSettingsListAfterInstall
+ << (QStringList() << "componentAValue" << "componentBValue");
+ }
+
+ void testPostLoadScriptFromRepository()
+ {
+ QFETCH(QStringList, installComponent);
+ QFETCH(bool, repositoryPostLoadSetting);
+ QFETCH(SettingsPairList, expectedSettingsBeforeInstall);
+ QFETCH(SettingsPairList, expectedSettingsAfterInstall);
+ QFETCH(QStringList, unexpectedSettings);
+
+ QString installDir = QInstaller::generateTemporaryFileName();
+ QScopedPointer<PackageManagerCore> core(PackageManager::getPackageManagerWithInit(installDir));
+ QSet<Repository> repoList;
+ Repository repo = Repository::fromUserInput(":///data/repository");
+ repo.setPostLoadComponentScript(repositoryPostLoadSetting);
+ repoList.insert(repo);
+ core->settings().setDefaultRepositories(repoList);
+ QVERIFY(core->fetchRemotePackagesTree());
+
+ for (const QPair<QString, QString> settingValue : expectedSettingsBeforeInstall)
+ QCOMPARE(core->value(settingValue.first), settingValue.second);
+
+ core->installSelectedComponentsSilently(installComponent);
+ for (const QPair<QString, QString> settingValue : expectedSettingsAfterInstall)
+ QCOMPARE(core->value(settingValue.first), settingValue.second);
+ for (const QString unexpectedSetting : unexpectedSettings)
+ QVERIFY2(!core->containsValue(unexpectedSetting), "Core contains unexpected value");
+ }
};
QTEST_MAIN(tst_Repository)