From e82ab45ed71d9b807dc23eae559c759f4584b79d Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Thu, 19 Nov 2020 07:25:01 +0200 Subject: Add option to define operations in component.xml Operations can from now on be declared also in component.xml. The operations are performed, backuped and rollbacked the same way as they would be when defined from scripting api. Task-number: QTIFW-507 Change-Id: Ia509219b94737136c3de25db0cb0c72076b48380 Reviewed-by: Leena Miettinen Reviewed-by: Arttu Tarkiainen --- doc/examples/package.xml | 13 +++ doc/installerfw.qdoc | 10 +++ doc/operations.qdoc | 20 ++++- doc/scripting.qdoc | 2 + src/libs/ifwtools/repositorygen.cpp | 4 +- src/libs/installer/component.cpp | 47 ++++++++++- src/libs/installer/component.h | 5 ++ src/libs/installer/extractarchiveoperation.cpp | 16 +++- src/libs/kdtools/updatesinfo.cpp | 30 +++++++ src/libs/kdtools/updatesinfodata_p.h | 2 + .../data/xmloperationrepository/A/1.0.0content.7z | Bin 0 -> 133 bytes .../data/xmloperationrepository/Updates.xml | 20 +++++ .../installer/appendfileoperation/settings.qrc | 2 + .../tst_appendfileoperation.cpp | 55 +++++++----- .../xmloperationrepository/A/1.0.2-1content.7z | Bin 0 -> 340 bytes .../data/xmloperationrepository/A/1.0.2-1meta.7z | Bin 0 -> 901 bytes .../data/xmloperationrepository/Updates.xml | 22 +++++ .../installer/copydirectoryoperation/settings.qrc | 2 + .../tst_copydirectoryoperation.cpp | 65 ++++++++------ .../xmloperationrepository/A/1.0.2-1content.7z | Bin 0 -> 185 bytes .../data/xmloperationrepository/Updates.xml | 25 ++++++ .../auto/installer/copyoperationtest/settings.qrc | 2 + .../copyoperationtest/tst_copyoperationtest.cpp | 56 +++++++----- .../data/xmloperationrepository/Updates.xml | 18 ++++ .../createdesktopentryoperation/settings.qrc | 1 + .../tst_createdesktopentryoperation.cpp | 94 ++++++++++++--------- .../xmloperationrepository/A/1.0.2-1content.7z | Bin 0 -> 185 bytes .../data/xmloperationrepository/Updates.xml | 26 ++++++ .../installer/createshortcutoperation/settings.qrc | 2 + .../tst_createshortcutoperation.cpp | 46 ++++++---- .../data/xmloperationrepository/Updates.xml | 17 ++++ tests/auto/installer/deleteoperation/settings.qrc | 1 + .../deleteoperation/tst_deleteoperation.cpp | 50 ++++++----- .../data/xmloperationrepository/Updates.xml | 25 ++++++ .../environmentvariableoperation/settings.qrc | 1 + .../tst_environmentvariableoperation.cpp | 54 +++++++----- .../installer/extractarchiveoperationtest/data.qrc | 4 + .../A/1.0.0anothercontent.7z | Bin 0 -> 114 bytes .../data/xmloperationrepository/A/1.0.0content.7z | Bin 0 -> 98 bytes .../data/xmloperationrepository/A/1.0.0default.7z | Bin 0 -> 98 bytes .../data/xmloperationrepository/Updates.xml | 26 ++++++ .../extractarchiveoperationtest.pro | 3 +- .../tst_extractarchiveoperationtest.cpp | 34 ++++++++ .../xmloperationrepository/A/1.0.2-1content.7z | Bin 0 -> 384 bytes .../data/xmloperationrepository/Updates.xml | 18 ++++ .../installer/installiconsoperation/settings.qrc | 2 + .../tst_installiconsoperation.cpp | 77 +++++++++-------- .../xmloperationrepository/A/1.0.2-1content.7z | Bin 0 -> 185 bytes .../A/1.0.2-1content.7z.sha1 | 1 + .../data/xmloperationrepository/Updates.xml | 23 +++++ .../installer/linereplaceoperation/settings.qrc | 3 + .../tst_linereplaceoperation.cpp | 40 +++++---- .../data/xmloperationrepository/Updates.xml | 22 +++++ tests/auto/installer/moveoperation/settings.qrc | 1 + .../installer/moveoperation/tst_moveoperation.cpp | 45 ++++++---- 55 files changed, 780 insertions(+), 252 deletions(-) create mode 100644 tests/auto/installer/appendfileoperation/data/xmloperationrepository/A/1.0.0content.7z create mode 100644 tests/auto/installer/appendfileoperation/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/A/1.0.2-1content.7z create mode 100644 tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/A/1.0.2-1meta.7z create mode 100644 tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/copyoperationtest/data/xmloperationrepository/A/1.0.2-1content.7z create mode 100644 tests/auto/installer/copyoperationtest/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/createdesktopentryoperation/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/createshortcutoperation/data/xmloperationrepository/A/1.0.2-1content.7z create mode 100644 tests/auto/installer/createshortcutoperation/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/deleteoperation/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/environmentvariableoperation/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0anothercontent.7z create mode 100644 tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0content.7z create mode 100644 tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0default.7z create mode 100644 tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/installiconsoperation/data/xmloperationrepository/A/1.0.2-1content.7z create mode 100644 tests/auto/installer/installiconsoperation/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/linereplaceoperation/data/xmloperationrepository/A/1.0.2-1content.7z create mode 100644 tests/auto/installer/linereplaceoperation/data/xmloperationrepository/A/1.0.2-1content.7z.sha1 create mode 100644 tests/auto/installer/linereplaceoperation/data/xmloperationrepository/Updates.xml create mode 100644 tests/auto/installer/moveoperation/data/xmloperationrepository/Updates.xml diff --git a/doc/examples/package.xml b/doc/examples/package.xml index 118adcf73..4248a7e83 100644 --- a/doc/examples/package.xml +++ b/doc/examples/package.xml @@ -28,4 +28,17 @@ false false com.vendor.root.component2old + + + @TargetDir@/A.txt + lorem ipsum + + + @TargetDir@/Folder1 + content.7z + + + @TargetDir@/Folder2 + + diff --git a/doc/installerfw.qdoc b/doc/installerfw.qdoc index bbdbff09e..22407e17d 100644 --- a/doc/installerfw.qdoc +++ b/doc/installerfw.qdoc @@ -918,6 +918,16 @@ \li ExpandedByDefault \li Set to \c true if you want this item to be expanded by default. Optional. + \row + \li Operations + \li List of operations that are performed when component is installed. To add + several operations, specify several \c child elements that each + specify the operation \c name. \c Operation can have several \c + child elements depending on the operation to be run. Adding \c + is an alternative way of defining operations to defining them in scripts. + For more information, see \l{Adding Operations}. For a + summary of available operations, see \l {Operations}. + \endtable \section2 Component Dependencies diff --git a/doc/operations.qdoc b/doc/operations.qdoc index 1fc3c00b8..983985dc7 100644 --- a/doc/operations.qdoc +++ b/doc/operations.qdoc @@ -33,8 +33,8 @@ \title Operations - The operations are prepared by component and controller scripts and performed by the - installer. + The operations are prepared by component and controller scripts or component.xml + and performed by the installer. \note Operations are performed threaded. Internally, each operation has a \e DO step that contains instructions for @@ -43,7 +43,19 @@ \section1 Summary of Operations - The following table summarizes the available operations and their syntax. + The following table summarizes the available operations and their syntax in component + and controller scripts. Syntax for operations in component.xml is: + \code + + + argument1 + argument2 + + + \endcode + \note The argument order in component.xml is the same as in scripting, except for + \c Extract operation where the argument \c archive is optional, and must be defined + as the last argument. \table \header @@ -163,6 +175,8 @@ \li Extract \li "Extract" \c archive \c targetdirectory \li Extracts \c archive to \c targetdirectory. + Extract operations are called before other operations. Note that in component.xml + argument \c archive is optional and thus must be defined as the last parameter. \row \li GlobalConfig diff --git a/doc/scripting.qdoc b/doc/scripting.qdoc index ae90c62c7..ea29e9956 100644 --- a/doc/scripting.qdoc +++ b/doc/scripting.qdoc @@ -120,6 +120,8 @@ update operations to the installation from within a script using component::addOperation(). If you need to run an operation that requires administrative rights, use component::addElevatedOperation() instead. + Alternative way of adding custom operations is to use \c component.xml, see + \l{Package Directory} Operations need to be added before the actual installation step. Override \l component::createOperations() to register custom operations for a diff --git a/src/libs/ifwtools/repositorygen.cpp b/src/libs/ifwtools/repositorygen.cpp index 819ab1ac8..5b7ec44a9 100644 --- a/src/libs/ifwtools/repositorygen.cpp +++ b/src/libs/ifwtools/repositorygen.cpp @@ -190,7 +190,7 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met // list of current unused or later transformed tags QStringList blackList; blackList << QLatin1String("UserInterfaces") << QLatin1String("Translations") << - QLatin1String("Licenses") << QLatin1String("Name"); + QLatin1String("Licenses") << QLatin1String("Name") << QLatin1String("Operations"); bool foundDefault = false; bool foundVirtual = false; @@ -379,6 +379,8 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met } update.appendChild(package.firstChildElement(QLatin1String("Licenses")).cloneNode()); } + // operations + update.appendChild(package.firstChildElement(QLatin1String("Operations")).cloneNode()); } else { // Extract metadata from archive if (!info.metaFile.isEmpty()){ diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index e8f036ccd..cb028b940 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -237,6 +237,7 @@ static const QLatin1String scUnstable("Unstable"); */ Component::Component(PackageManagerCore *core) : d(new ComponentPrivate(core, this)) + , m_defaultArchivePath(QLatin1String("@TargetDir@")) { setPrivate(d); @@ -342,6 +343,9 @@ void Component::loadDataFromPackage(const Package &package) QHash licenseHash = package.data(QLatin1String("Licenses")).toHash(); if (!licenseHash.isEmpty()) loadLicenses(QString::fromLatin1("%1/%2/").arg(localTempPath(), name()), licenseHash); + QVariant operationsVariant = package.data(QLatin1String("Operations")); + if (operationsVariant.canConvert>>()) + m_operationsList = operationsVariant.value>>(); } /*! @@ -688,6 +692,39 @@ void Component::loadLicenses(const QString &directory, const QHashm_operationsCreated = true; return; } - + loadXMLExtractOperations(); foreach (const QString &archive, archives()) createOperationsForArchive(archive); + loadXMLOperations(); d->m_operationsCreated = true; } diff --git a/src/libs/installer/component.h b/src/libs/installer/component.h index 6ff5c8c38..494d79b13 100644 --- a/src/libs/installer/component.h +++ b/src/libs/installer/component.h @@ -121,6 +121,8 @@ public: void loadTranslations(const QDir &directory, const QStringList &qms); void loadUserInterfaces(const QDir &directory, const QStringList &uis); void loadLicenses(const QString &directory, const QHash &hash); + void loadXMLOperations(); + void loadXMLExtractOperations(); void markAsPerformedInstallation(); QStringList userInterfaces() const; @@ -227,6 +229,9 @@ private: private: QString validatorCallbackName; ComponentPrivate *d; + QList> m_operationsList; + QHash m_archivesHash; + QString m_defaultArchivePath; }; QDebug operator<<(QDebug dbg, Component *component); diff --git a/src/libs/installer/extractarchiveoperation.cpp b/src/libs/installer/extractarchiveoperation.cpp index 99dd88a7e..5b13b1f25 100644 --- a/src/libs/installer/extractarchiveoperation.cpp +++ b/src/libs/installer/extractarchiveoperation.cpp @@ -122,9 +122,15 @@ bool ExtractArchiveOperation::performOperation() QStringList files = callback.extractedFiles(); - const QString resourcesPath = targetDir + QLatin1Char('/') + QLatin1String("installerResources"); - QString fileDirectory = resourcesPath + QLatin1Char('/') + - archivePath.section(QLatin1Char('/'), 1, 1, QString::SectionSkipEmpty) + QLatin1Char('/'); + QString installDir = targetDir; + // If we have package manager in use (normal installer run) then use + // TargetDir for saving filenames, otherwise those would be saved to + // extracted folder. + if (packageManager()) + installDir = packageManager()->value(QLatin1String("TargetDir")); + const QString resourcesPath = installDir + QLatin1Char('/') + QLatin1String("installerResources"); + QString fileDirectory = resourcesPath + QLatin1Char('/') + archivePath.section(QLatin1Char('/'), 1, 1, + QString::SectionSkipEmpty) + QLatin1Char('/'); QString archiveFileName = archivePath.section(QLatin1Char('/'), 2, 2, QString::SectionSkipEmpty); QFileInfo fileInfo2(archiveFileName); QString suffix = fileInfo2.suffix(); @@ -145,7 +151,7 @@ bool ExtractArchiveOperation::performOperation() setDefaultFilePermissions(file.fileName(), DefaultFilePermissions::NonExecutable); QDataStream out (&file); for (int i = 0; i < files.count(); ++i) { - files[i] = replacePath(files.at(i), targetDir, QLatin1String(scRelocatable)); + files[i] = replacePath(files.at(i), installDir, QLatin1String(scRelocatable)); } out << files; setValue(QLatin1String("files"), file.fileName()); @@ -176,6 +182,8 @@ bool ExtractArchiveOperation::undoOperation() // If yes, files are listed in .dat instead of in a separate file. bool useStringListType(value(QLatin1String("files")).type() == QVariant::StringList); QString targetDir = arguments().at(1); + if (packageManager()) + targetDir = packageManager()->value(QLatin1String("TargetDir")); QStringList files; if (useStringListType) { files = value(QLatin1String("files")).toStringList(); diff --git a/src/libs/kdtools/updatesinfo.cpp b/src/libs/kdtools/updatesinfo.cpp index 2d7e001ea..3119b6240 100644 --- a/src/libs/kdtools/updatesinfo.cpp +++ b/src/libs/kdtools/updatesinfo.cpp @@ -154,6 +154,10 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE) } else if (childE.tagName() == QLatin1String("UpdateFile")) { info.data[QLatin1String("CompressedSize")] = childE.attribute(QLatin1String("CompressedSize")); info.data[QLatin1String("UncompressedSize")] = childE.attribute(QLatin1String("UncompressedSize")); + } else if (childE.tagName() == QLatin1String("Operations")) { + const QDomNodeList operationNodes = childE.childNodes(); + QVariant operationListVariant = parseOperations(childE.childNodes()); + info.data.insert(QLatin1String("Operations"), operationListVariant); } else { info.data[childE.tagName()] = childE.text(); } @@ -197,6 +201,32 @@ void UpdatesInfoData::processLocalizedTag(const QDomElement &childE, QHash> operationsList; + for (int i = 0; i < operationNodes.count(); ++i) { + const QDomNode operationNode = operationNodes.at(i); + if (operationNode.nodeName() == QLatin1String("Operation")) { + const QDomNodeList argumentNodes = operationNode.childNodes(); + QStringList attributes; + for (int i = 0; i < argumentNodes.count(); ++i) { + const QDomNode argumentNode = argumentNodes.at(i); + if (argumentNode.nodeName() == QLatin1String("Argument")) { + QDomElement argumentElement = argumentNode.toElement(); + attributes.append(argumentElement.text()); + } + } + QPair pair; + pair.first = operationNode.toElement().attributeNode(QLatin1String("name")).value(); + pair.second = attributes; + operationsList.append(pair); + } + } + operationListVariant.setValue(operationsList); + return operationListVariant; +} + // // UpdatesInfo diff --git a/src/libs/kdtools/updatesinfodata_p.h b/src/libs/kdtools/updatesinfodata_p.h index 69b004bc3..07da6fcf0 100644 --- a/src/libs/kdtools/updatesinfodata_p.h +++ b/src/libs/kdtools/updatesinfodata_p.h @@ -33,6 +33,7 @@ #include QT_FORWARD_DECLARE_CLASS(QDomElement) +QT_FORWARD_DECLARE_CLASS(QDomNodeList) namespace KDUpdater { @@ -60,6 +61,7 @@ public: private: void processLocalizedTag(const QDomElement &childE, QHash &info) const; + QVariant parseOperations(const QDomNodeList &operationNodes); }; } // namespace KDUpdater diff --git a/tests/auto/installer/appendfileoperation/data/xmloperationrepository/A/1.0.0content.7z b/tests/auto/installer/appendfileoperation/data/xmloperationrepository/A/1.0.0content.7z new file mode 100644 index 000000000..90b958cdb Binary files /dev/null and b/tests/auto/installer/appendfileoperation/data/xmloperationrepository/A/1.0.0content.7z differ diff --git a/tests/auto/installer/appendfileoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/appendfileoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..708ba6539 --- /dev/null +++ b/tests/auto/installer/appendfileoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,20 @@ + + {AnyApplication} + 1.0.0 + + A + A + Example component A + 1.0.0 + 2020-01-01 + true + + content.7z + + + @TargetDir@/A.txt + lorem ipsum + + + + diff --git a/tests/auto/installer/appendfileoperation/settings.qrc b/tests/auto/installer/appendfileoperation/settings.qrc index 10cc3c3bb..66d0c8da1 100644 --- a/tests/auto/installer/appendfileoperation/settings.qrc +++ b/tests/auto/installer/appendfileoperation/settings.qrc @@ -3,5 +3,7 @@ data/repository/Updates.xml data/repository/A/1.0.2-1content.7z data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml + data/xmloperationrepository/A/1.0.0content.7z diff --git a/tests/auto/installer/appendfileoperation/tst_appendfileoperation.cpp b/tests/auto/installer/appendfileoperation/tst_appendfileoperation.cpp index 1b2d63fd7..9fbfb08e7 100644 --- a/tests/auto/installer/appendfileoperation/tst_appendfileoperation.cpp +++ b/tests/auto/installer/appendfileoperation/tst_appendfileoperation.cpp @@ -40,6 +40,33 @@ class tst_appendfileoperation : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + QString installDir = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(installDir)); + PackageManagerCore *core = PackageManager::getPackageManagerWithInit + (installDir, repository); + core->installDefaultComponentsSilently(); + + QFile file(installDir + QDir::separator() + "A.txt"); + QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); + QTextStream stream(&file); + QCOMPARE(stream.readAll(), QLatin1String("Appended text: lorem ipsum")); + file.close(); + + core->setPackageManager(); + core->commitSessionOperations(); + // We cannot check the file contents here as it will be deleted on + // undo Extract, but at least check that the uninstallation succeeds. + QCOMPARE(PackageManagerCore::Success, core->uninstallComponentsSilently + (QStringList()<< "A")); + + QDir dir(installDir); + QVERIFY(dir.removeRecursively()); + core->deleteLater(); + } + private slots: void initTestCase() { @@ -109,30 +136,14 @@ private slots: QVERIFY(file.remove()); } - void testPerformingFromCLI() + void testApppendFromScript() { - QString installDir = QInstaller::generateTemporaryFileName(); - QVERIFY(QDir().mkpath(installDir)); - PackageManagerCore *core = PackageManager::getPackageManagerWithInit - (installDir, ":///data/repository"); - core->installDefaultComponentsSilently(); - - QFile file(installDir + QDir::separator() + "A.txt"); - QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); - QTextStream stream(&file); - QCOMPARE(stream.readAll(), QLatin1String("Appended text: lorem ipsum")); - file.close(); - - core->setPackageManager(); - core->commitSessionOperations(); - // We cannot check the file contents here as it will be deleted on - // undo Extract, but at least check that the uninstallation succeeds. - QCOMPARE(PackageManagerCore::Success, core->uninstallComponentsSilently - (QStringList()<< "A")); + installFromCLI(":///data/repository"); + } - QDir dir(installDir); - QVERIFY(dir.removeRecursively()); - core->deleteLater(); + void testAppendFromComponentXML() + { + installFromCLI(":///data/xmloperationrepository"); } private: diff --git a/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/A/1.0.2-1content.7z b/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/A/1.0.2-1content.7z new file mode 100644 index 000000000..920ed1d99 Binary files /dev/null and b/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/A/1.0.2-1content.7z differ diff --git a/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/A/1.0.2-1meta.7z b/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/A/1.0.2-1meta.7z new file mode 100644 index 000000000..7449d052b Binary files /dev/null and b/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/A/1.0.2-1meta.7z differ diff --git a/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..90b26a387 --- /dev/null +++ b/tests/auto/installer/copydirectoryoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,22 @@ + + {AnyApplication} + 1.0.0 + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + content.7z + + + @TargetDir@/destination/directory + + + @TargetDir@/directory + @TargetDir@/destination/directory + + + + diff --git a/tests/auto/installer/copydirectoryoperation/settings.qrc b/tests/auto/installer/copydirectoryoperation/settings.qrc index 10cc3c3bb..094bd449b 100644 --- a/tests/auto/installer/copydirectoryoperation/settings.qrc +++ b/tests/auto/installer/copydirectoryoperation/settings.qrc @@ -3,5 +3,7 @@ data/repository/Updates.xml data/repository/A/1.0.2-1content.7z data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml + data/xmloperationrepository/A/1.0.2-1content.7z diff --git a/tests/auto/installer/copydirectoryoperation/tst_copydirectoryoperation.cpp b/tests/auto/installer/copydirectoryoperation/tst_copydirectoryoperation.cpp index 19a8b36b7..bf95f635d 100644 --- a/tests/auto/installer/copydirectoryoperation/tst_copydirectoryoperation.cpp +++ b/tests/auto/installer/copydirectoryoperation/tst_copydirectoryoperation.cpp @@ -43,6 +43,38 @@ class tst_copydirectoryoperation : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + QString installDir = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(installDir)); + PackageManagerCore *core = PackageManager::getPackageManagerWithInit + (installDir, repository); + + core->setValue(scTargetDir, installDir); + core->installDefaultComponentsSilently(); + + // Matches path in component install script + QFileInfo targetInfo(installDir + QDir::toNativeSeparators("/directory")); + QMap targetMap; + VerifyInstaller::addToFileMap(QDir(targetInfo.absoluteFilePath()), targetInfo, targetMap); + + QFileInfo destinationInfo(installDir + QDir::toNativeSeparators("/destination/directory")); + QMap destinationMap; + VerifyInstaller::addToFileMap(QDir(destinationInfo.absoluteFilePath()), destinationInfo, destinationMap); + + QVERIFY(targetMap == destinationMap); + + core->setPackageManager(); + core->commitSessionOperations(); + core->uninstallComponentsSilently(QStringList() << "A"); + QVERIFY(!destinationInfo.exists()); + + QDir dir(installDir); + QVERIFY(dir.removeRecursively()); + core->deleteLater(); + } + private slots: void initTestCase() { @@ -140,35 +172,14 @@ private slots: QVERIFY2(op.performOperation(), op.errorString().toLatin1()); } - void testPerformingFromCLI() + void testCopyDirectoryFromScript() { - QString installDir = QInstaller::generateTemporaryFileName(); - QVERIFY(QDir().mkpath(installDir)); - PackageManagerCore *core = PackageManager::getPackageManagerWithInit - (installDir, ":///data/repository"); - - core->setValue(scTargetDir, installDir); - core->installDefaultComponentsSilently(); - - // Matches path in component install script - QFileInfo targetInfo(installDir + QDir::toNativeSeparators("/directory")); - QMap targetMap; - VerifyInstaller::addToFileMap(QDir(targetInfo.absoluteFilePath()), targetInfo, targetMap); - - QFileInfo destinationInfo(installDir + QDir::toNativeSeparators("/destination/directory")); - QMap destinationMap; - VerifyInstaller::addToFileMap(QDir(destinationInfo.absoluteFilePath()), destinationInfo, destinationMap); - - QVERIFY(targetMap == destinationMap); - - core->setPackageManager(); - core->commitSessionOperations(); - core->uninstallComponentsSilently(QStringList() << "A"); - QVERIFY(!destinationInfo.exists()); + installFromCLI(":///data/repository"); + } - QDir dir(installDir); - QVERIFY(dir.removeRecursively()); - core->deleteLater(); + void testCopyDirectoryFromComponentXML() + { + installFromCLI(":///data/xmloperationrepository"); } private: diff --git a/tests/auto/installer/copyoperationtest/data/xmloperationrepository/A/1.0.2-1content.7z b/tests/auto/installer/copyoperationtest/data/xmloperationrepository/A/1.0.2-1content.7z new file mode 100644 index 000000000..8ba90b13b Binary files /dev/null and b/tests/auto/installer/copyoperationtest/data/xmloperationrepository/A/1.0.2-1content.7z differ diff --git a/tests/auto/installer/copyoperationtest/data/xmloperationrepository/Updates.xml b/tests/auto/installer/copyoperationtest/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..4ad1e243b --- /dev/null +++ b/tests/auto/installer/copyoperationtest/data/xmloperationrepository/Updates.xml @@ -0,0 +1,25 @@ + + {AnyApplication} + 1.0.0 + false + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + + content.7z + 6d7a3e15d11a4d94b81452fc2aa18e705a01c922 + + + @TargetDir@/AnotherFolder + + + @TargetDir@/A.txt + @TargetDir@/AnotherFolder/A.txt + + + + diff --git a/tests/auto/installer/copyoperationtest/settings.qrc b/tests/auto/installer/copyoperationtest/settings.qrc index 10cc3c3bb..094bd449b 100644 --- a/tests/auto/installer/copyoperationtest/settings.qrc +++ b/tests/auto/installer/copyoperationtest/settings.qrc @@ -3,5 +3,7 @@ data/repository/Updates.xml data/repository/A/1.0.2-1content.7z data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml + data/xmloperationrepository/A/1.0.2-1content.7z diff --git a/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp b/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp index aee192400..d41853eee 100644 --- a/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp +++ b/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp @@ -40,6 +40,33 @@ class tst_copyoperationtest : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + QString installDir = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(installDir)); + PackageManagerCore *core = PackageManager::getPackageManagerWithInit(installDir, repository); + core->installDefaultComponentsSilently(); + + QFile copiedFile(installDir + QDir::separator() + "AnotherFolder/A.txt"); + QVERIFY(copiedFile.exists()); + QFile originalFile(installDir + QDir::separator() + "A.txt"); + QVERIFY(originalFile.exists()); + + QByteArray destinationFileHash = QInstaller::calculateHash(copiedFile.fileName(), QCryptographicHash::Sha1); + QByteArray testFileHash = QInstaller::calculateHash(originalFile.fileName(), QCryptographicHash::Sha1); + QVERIFY(testFileHash == destinationFileHash); + + core->setPackageManager(); + core->commitSessionOperations(); + core->uninstallComponentsSilently(QStringList() << "A"); + QVERIFY(!copiedFile.exists()); + + QDir dir(installDir); + QVERIFY(dir.removeRecursively()); + core->deleteLater(); + } + private slots: void initTestCase() { @@ -132,30 +159,13 @@ private slots: QVERIFY(testFileHash == currentFileHash); } - void testPerformingFromCLI() + void testCopyFromScript() { - QString installDir = QInstaller::generateTemporaryFileName(); - QVERIFY(QDir().mkpath(installDir)); - PackageManagerCore *core = PackageManager::getPackageManagerWithInit(installDir, ":///data/repository"); - core->installDefaultComponentsSilently(); - - QFile copiedFile(installDir + QDir::separator() + "AnotherFolder/A.txt"); - QVERIFY(copiedFile.exists()); - QFile originalFile(installDir + QDir::separator() + "A.txt"); - QVERIFY(originalFile.exists()); - - QByteArray destinationFileHash = QInstaller::calculateHash(copiedFile.fileName(), QCryptographicHash::Sha1); - QByteArray testFileHash = QInstaller::calculateHash(originalFile.fileName(), QCryptographicHash::Sha1); - QVERIFY(testFileHash == destinationFileHash); - - core->setPackageManager(); - core->commitSessionOperations(); - core->uninstallComponentsSilently(QStringList() << "A"); - QVERIFY(!copiedFile.exists()); - - QDir dir(installDir); - QVERIFY(dir.removeRecursively()); - core->deleteLater(); + installFromCLI(":///data/repository"); + } + void testCopyFromComponentXML() + { + installFromCLI(":///data/xmloperationrepository"); } void init() diff --git a/tests/auto/installer/createdesktopentryoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/createdesktopentryoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..a5131552d --- /dev/null +++ b/tests/auto/installer/createdesktopentryoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,18 @@ + + {AnyApplication} + 1.0.0 + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + + + org.qtproject.ifw-test.desktop + Type=Application\nName=Test\nVersion=1.0 + + + + diff --git a/tests/auto/installer/createdesktopentryoperation/settings.qrc b/tests/auto/installer/createdesktopentryoperation/settings.qrc index d030220ab..04a7daf71 100644 --- a/tests/auto/installer/createdesktopentryoperation/settings.qrc +++ b/tests/auto/installer/createdesktopentryoperation/settings.qrc @@ -2,5 +2,6 @@ data/repository/Updates.xml data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml diff --git a/tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp b/tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp index a1297e5a2..ac3fffbe1 100644 --- a/tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp +++ b/tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp @@ -48,6 +48,53 @@ class tst_createdesktopentryoperation : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + QString installDir = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(installDir)); + PackageManagerCore *core = PackageManager::getPackageManagerWithInit + (installDir, repository); + + core->installDefaultComponentsSilently(); + + CreateDesktopEntryOperation *createDesktopEntryOp = nullptr; + OperationList operations = core->componentByName("A")->operations(); + foreach (Operation *op, operations) { + if (op->name() == QLatin1String("CreateDesktopEntry")) + createDesktopEntryOp = dynamic_cast(op); + } + QVERIFY(createDesktopEntryOp); + + QString entryFileName = createDesktopEntryOp->absoluteFileName(); + QVERIFY(QFileInfo(entryFileName).exists()); + if (QFileInfo(createDesktopEntryOp->arguments().first()).isRelative()) { + QStringList directories = QString::fromLocal8Bit(qgetenv("XDG_DATA_HOME")) + .split(QLatin1Char(':'), QString::SkipEmptyParts); + // Default path if XDG_DATA_HOME is not set + directories.append(QDir::home().absoluteFilePath(QLatin1String(".local/share"))); + bool validPath = false; + foreach (const QString &dir, directories) { + // Desktop entry should be in one of the expected locations + if (QFileInfo(entryFileName).absolutePath() == QDir(dir).absoluteFilePath("applications")) { + validPath = true; + break; + } + } + QVERIFY(validPath); + } + core->setPackageManager(); + core->commitSessionOperations(); + core->uninstallComponentsSilently(QStringList() << "A"); + QVERIFY2(!QFileInfo(entryFileName).exists(), "Please make sure there " + "does not exist a desktop entry with the same name."); + + QDir dir(installDir); + QVERIFY(dir.removeRecursively()); + core->deleteLater(); + + } + private slots: void initTestCase() { @@ -111,49 +158,14 @@ private slots: QVERIFY(QFile(filename).remove()); } - void testPerformingFromCLI() + void testDesktopEntryFromScript() { - QString installDir = QInstaller::generateTemporaryFileName(); - QVERIFY(QDir().mkpath(installDir)); - PackageManagerCore *core = PackageManager::getPackageManagerWithInit - (installDir, ":///data/repository"); - - core->installDefaultComponentsSilently(); - - CreateDesktopEntryOperation *createDesktopEntryOp = nullptr; - OperationList operations = core->componentByName("A")->operations(); - foreach (Operation *op, operations) { - if (op->name() == QLatin1String("CreateDesktopEntry")) - createDesktopEntryOp = dynamic_cast(op); - } - QVERIFY(createDesktopEntryOp); - - QString entryFileName = createDesktopEntryOp->absoluteFileName(); - QVERIFY(QFileInfo(entryFileName).exists()); - if (QFileInfo(createDesktopEntryOp->arguments().first()).isRelative()) { - QStringList directories = QString::fromLocal8Bit(qgetenv("XDG_DATA_HOME")) - .split(QLatin1Char(':'), QString::SkipEmptyParts); - // Default path if XDG_DATA_HOME is not set - directories.append(QDir::home().absoluteFilePath(QLatin1String(".local/share"))); - bool validPath = false; - foreach (const QString &dir, directories) { - // Desktop entry should be in one of the expected locations - if (QFileInfo(entryFileName).absolutePath() == QDir(dir).absoluteFilePath("applications")) { - validPath = true; - break; - } - } - QVERIFY(validPath); - } - core->setPackageManager(); - core->commitSessionOperations(); - core->uninstallComponentsSilently(QStringList() << "A"); - QVERIFY2(!QFileInfo(entryFileName).exists(), "Please make sure there " - "does not exist a desktop entry with the same name."); + installFromCLI(":///data/repository"); + } - QDir dir(installDir); - QVERIFY(dir.removeRecursively()); - core->deleteLater(); + void testDesktopEntryFromXML() + { + installFromCLI(":///data/xmloperationrepository"); } private: diff --git a/tests/auto/installer/createshortcutoperation/data/xmloperationrepository/A/1.0.2-1content.7z b/tests/auto/installer/createshortcutoperation/data/xmloperationrepository/A/1.0.2-1content.7z new file mode 100644 index 000000000..8ba90b13b Binary files /dev/null and b/tests/auto/installer/createshortcutoperation/data/xmloperationrepository/A/1.0.2-1content.7z differ diff --git a/tests/auto/installer/createshortcutoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/createshortcutoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..a7d287d4d --- /dev/null +++ b/tests/auto/installer/createshortcutoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,26 @@ + + {AnyApplication} + 1.0.0 + false + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + + content.7z + 6d7a3e15d11a4d94b81452fc2aa18e705a01c922 + + + @TargetDir@/A.txt + @StartMenuDir@/A.lnk + workingDirectory=@TargetDir@ + iconPath=%SystemRoot%/system32/SHELL32.dl + iconId=2 + description=Open A file + + + + diff --git a/tests/auto/installer/createshortcutoperation/settings.qrc b/tests/auto/installer/createshortcutoperation/settings.qrc index 410fbf81a..d2365cab3 100644 --- a/tests/auto/installer/createshortcutoperation/settings.qrc +++ b/tests/auto/installer/createshortcutoperation/settings.qrc @@ -3,6 +3,8 @@ data/repository/Updates.xml data/repository/A/1.0.2-1content.7z data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml + data/xmloperationrepository/A/1.0.2-1content.7z installer-config/config.xml diff --git a/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp b/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp index 19fbee0a9..a57098d2a 100644 --- a/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp +++ b/tests/auto/installer/createshortcutoperation/tst_createshortcutoperation.cpp @@ -48,22 +48,8 @@ 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 arguments] [\"workingDirectory=...\"] [\"iconPath=...\"] " - "[\"iconId=...\"] [\"description=...\"].")); - } - - void testCreateShortcutForCurrentUserFromCLI() +private: + void installFromCLI(const QString &repository) { QInstaller::init(); PackageManagerCore *core = new PackageManagerCore(BinaryContent::MagicInstallerMarker, QList (), @@ -73,7 +59,7 @@ private slots: core->disableWriteMaintenanceTool(); core->setAutoConfirmCommand(); QSet repoList; - Repository repo = Repository::fromUserInput(":///data/repository"); + Repository repo = Repository::fromUserInput(repository); repoList.insert(repo); core->settings().setDefaultRepositories(repoList); @@ -98,7 +84,31 @@ private slots: core->commitSessionOperations(); core->uninstallComponentsSilently(QStringList() << "A"); QVERIFY(!QFile::exists(linkLocation)); - core->deleteLater(); + } + +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 arguments] [\"workingDirectory=...\"] [\"iconPath=...\"] " + "[\"iconId=...\"] [\"description=...\"].")); + } + + void testCreateShortcutFromScript() + { + installFromCLI(":///data/repository"); + } + + void testCreateShortcutFromXML() + { + installFromCLI(":///data/xmloperationrepository"); } }; diff --git a/tests/auto/installer/deleteoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/deleteoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..6856014b9 --- /dev/null +++ b/tests/auto/installer/deleteoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,17 @@ + + {AnyApplication} + 1.0.0 + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + + + @TargetDir@/test + + + + diff --git a/tests/auto/installer/deleteoperation/settings.qrc b/tests/auto/installer/deleteoperation/settings.qrc index d030220ab..04a7daf71 100644 --- a/tests/auto/installer/deleteoperation/settings.qrc +++ b/tests/auto/installer/deleteoperation/settings.qrc @@ -2,5 +2,6 @@ data/repository/Updates.xml data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml diff --git a/tests/auto/installer/deleteoperation/tst_deleteoperation.cpp b/tests/auto/installer/deleteoperation/tst_deleteoperation.cpp index 72509f074..807d03498 100644 --- a/tests/auto/installer/deleteoperation/tst_deleteoperation.cpp +++ b/tests/auto/installer/deleteoperation/tst_deleteoperation.cpp @@ -41,6 +41,30 @@ using namespace QInstaller; class tst_deleteoperation : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + QString installDir = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(installDir)); + PackageManagerCore *core = PackageManager::getPackageManagerWithInit(installDir, repository); + + // Matches filename in component install script + QFile file(installDir + QDir::toNativeSeparators("/test")); + QVERIFY(file.open(QIODevice::ReadWrite)); + file.close(); + + core->installDefaultComponentsSilently(); + QVERIFY(!file.exists()); + + core->setPackageManager(); + core->commitSessionOperations(); + core->uninstallComponentsSilently(QStringList() << "A"); + QVERIFY(file.exists()); + + QDir dir(installDir); + QVERIFY(dir.removeRecursively()); + core->deleteLater(); + } private slots: void testMissingArguments() @@ -102,28 +126,14 @@ private slots: QVERIFY(QFile(path).remove()); } - void testPerformingFromCLI() + void testDeleteFromScript() { - QString installDir = QInstaller::generateTemporaryFileName(); - QVERIFY(QDir().mkpath(installDir)); - PackageManagerCore *core = PackageManager::getPackageManagerWithInit(installDir, ":///data/repository"); - - // Matches filename in component install script - QFile file(installDir + QDir::toNativeSeparators("/test")); - QVERIFY(file.open(QIODevice::ReadWrite)); - file.close(); - - core->installDefaultComponentsSilently(); - QVERIFY(!file.exists()); - - core->setPackageManager(); - core->commitSessionOperations(); - core->uninstallComponentsSilently(QStringList() << "A"); - QVERIFY(file.exists()); + installFromCLI(":///data/repository"); + } - QDir dir(installDir); - QVERIFY(dir.removeRecursively()); - core->deleteLater(); + void testDeleteFromXML() + { + installFromCLI(":///data/xmloperationrepository"); } }; diff --git a/tests/auto/installer/environmentvariableoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/environmentvariableoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..9c33caf6d --- /dev/null +++ b/tests/auto/installer/environmentvariableoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,25 @@ + + {AnyApplication} + 1.0.0 + false + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + + + IFW_UNIT_TEST_LOCAL + IFW_UNIT_TEST_VALUE + false + + + IFW_UNIT_TEST_PERSISTENT + IFW_UNIT_TEST_PERSISTENT_VALUE + true + + + + diff --git a/tests/auto/installer/environmentvariableoperation/settings.qrc b/tests/auto/installer/environmentvariableoperation/settings.qrc index d030220ab..04a7daf71 100644 --- a/tests/auto/installer/environmentvariableoperation/settings.qrc +++ b/tests/auto/installer/environmentvariableoperation/settings.qrc @@ -2,5 +2,6 @@ data/repository/Updates.xml data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml diff --git a/tests/auto/installer/environmentvariableoperation/tst_environmentvariableoperation.cpp b/tests/auto/installer/environmentvariableoperation/tst_environmentvariableoperation.cpp index 6cddad2e5..d0ded4c58 100644 --- a/tests/auto/installer/environmentvariableoperation/tst_environmentvariableoperation.cpp +++ b/tests/auto/installer/environmentvariableoperation/tst_environmentvariableoperation.cpp @@ -42,6 +42,32 @@ class tst_environmentvariableoperation : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + QString installDir = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(installDir)); + PackageManagerCore *core = PackageManager::getPackageManagerWithInit + (installDir, repository); + core->installDefaultComponentsSilently(); + + QVERIFY(m_settings->value("IFW_UNIT_TEST_LOCAL").toString().isEmpty()); + + // Persistent is in settings in Windows platform only, otherwise it is written to local env. +#ifdef Q_OS_WIN + QCOMPARE(m_settings->value("IFW_UNIT_TEST_PERSISTENT").toString(), QLatin1String("IFW_UNIT_TEST_PERSISTENT_VALUE")); +#else + QCOMPARE(Environment::instance().value("IFW_UNIT_TEST_PERSISTENT"), QLatin1String("IFW_UNIT_TEST_PERSISTENT_VALUE")); +#endif + QCOMPARE(Environment::instance().value("IFW_UNIT_TEST_LOCAL"), QLatin1String("IFW_UNIT_TEST_VALUE")); + + core->commitSessionOperations(); + core->setPackageManager(); + core->uninstallComponentsSilently(QStringList() << "A"); + QVERIFY(m_settings->value("IFW_UNIT_TEST_PERSISTENT").toString().isEmpty()); + QVERIFY(Environment::instance().value("IFW_UNIT_TEST_LOCAL").isEmpty()); + } + private slots: void initTestCase() { @@ -135,30 +161,14 @@ private slots: QCOMPARE(m_oldValue, Environment::instance().value(m_key)); } - void testPerformingFromCLI() + void testEnvVariableFromScript() { - QString installDir = QInstaller::generateTemporaryFileName(); - QVERIFY(QDir().mkpath(installDir)); - PackageManagerCore *core = PackageManager::getPackageManagerWithInit - (installDir, ":///data/repository"); - core->installDefaultComponentsSilently(); - - QVERIFY(m_settings->value("IFW_UNIT_TEST_LOCAL").toString().isEmpty()); - - // Persistent is in settings in Windows platform only, otherwise it is written to local env. -#ifdef Q_OS_WIN - QCOMPARE(QLatin1String("IFW_UNIT_TEST_PERSISTENT_VALUE"), m_settings->value("IFW_UNIT_TEST_PERSISTENT").toString()); -#else - QCOMPARE(QLatin1String("IFW_UNIT_TEST_PERSISTENT_VALUE"), Environment::instance().value("IFW_UNIT_TEST_PERSISTENT")); -#endif - QCOMPARE(QLatin1String("IFW_UNIT_TEST_VALUE"), Environment::instance().value("IFW_UNIT_TEST_LOCAL")); + installFromCLI(":///data/repository"); + } - core->commitSessionOperations(); - core->setPackageManager(); - core->uninstallComponentsSilently(QStringList() << "A"); - QVERIFY(m_settings->value("IFW_UNIT_TEST_PERSISTENT").toString().isEmpty()); - QVERIFY(Environment::instance().value("IFW_UNIT_TEST_LOCAL").isEmpty()); - core->deleteLater(); + void testEnvVariableFromSXML() + { + installFromCLI(":///data/xmloperationrepository"); } private: diff --git a/tests/auto/installer/extractarchiveoperationtest/data.qrc b/tests/auto/installer/extractarchiveoperationtest/data.qrc index d6453a9b3..d6eb2cf92 100644 --- a/tests/auto/installer/extractarchiveoperationtest/data.qrc +++ b/tests/auto/installer/extractarchiveoperationtest/data.qrc @@ -2,5 +2,9 @@ data/valid.7z data/invalid.7z + data/xmloperationrepository/Updates.xml + data/xmloperationrepository/A/1.0.0content.7z + data/xmloperationrepository/A/1.0.0anothercontent.7z + data/xmloperationrepository/A/1.0.0default.7z diff --git a/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0anothercontent.7z b/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0anothercontent.7z new file mode 100644 index 000000000..949b50689 Binary files /dev/null and b/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0anothercontent.7z differ diff --git a/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0content.7z b/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0content.7z new file mode 100644 index 000000000..585f58296 Binary files /dev/null and b/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0content.7z differ diff --git a/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0default.7z b/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0default.7z new file mode 100644 index 000000000..1c0c5ccfb Binary files /dev/null and b/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/A/1.0.0default.7z differ diff --git a/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/Updates.xml b/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..3a8bdd018 --- /dev/null +++ b/tests/auto/installer/extractarchiveoperationtest/data/xmloperationrepository/Updates.xml @@ -0,0 +1,26 @@ + + {AnyApplication} + 1.0.0 + + A + A + Example component A + 1.0.0 + 2015-01-01 + true + content.7z,anothercontent.7z,default.7z + + + @TargetDir@/FolderForContent + content.7z + + + @TargetDir@/FolderForAnotherContent + anothercontent.7z + + + @TargetDir@/FolderForDefault + + + + diff --git a/tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro b/tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro index fb53c9a8a..2343f546e 100644 --- a/tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro +++ b/tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro @@ -3,5 +3,6 @@ include(../../qttest.pri) QT -= gui QT += testlib -RESOURCES += data.qrc +RESOURCES += data.qrc \ + ..\shared\config.qrc SOURCES = tst_extractarchiveoperationtest.cpp diff --git a/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp b/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp index a5f38e0ea..baaf58da2 100644 --- a/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp +++ b/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp @@ -26,6 +26,8 @@ ** **************************************************************************/ +#include "../shared/packagemanager.h" + #include "init.h" #include "extractarchiveoperation.h" @@ -40,6 +42,8 @@ class tst_extractarchiveoperationtest : public QObject { Q_OBJECT +private: + private slots: void initTestCase() { @@ -83,6 +87,36 @@ private slots: QCOMPARE(op.errorString(), QString("Error while extracting archive \":///data/invalid.7z\": " "Cannot open archive \":///data/invalid.7z\".")); } + + void testExtractArchiveFromXML() + { + m_testDirectory = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(m_testDirectory)); + QVERIFY(QDir(m_testDirectory).exists()); + + PackageManagerCore *core = PackageManager::getPackageManagerWithInit + (m_testDirectory, ":///data/xmloperationrepository"); + core->installDefaultComponentsSilently(); + + QFile extractedFile(m_testDirectory + QDir::separator() + "FolderForContent/content.txt"); + QVERIFY(extractedFile.exists()); + + extractedFile.setFileName(m_testDirectory + QDir::separator() + "FolderForAnotherContent/anothercontent.txt"); + QVERIFY(extractedFile.exists()); + + extractedFile.setFileName(m_testDirectory + QDir::separator() + "FolderForDefault/default.txt"); + QVERIFY(extractedFile.exists()); + + core->setPackageManager(); + core->commitSessionOperations(); + + core->uninstallComponentsSilently(QStringList() << "A"); + QDir dir(m_testDirectory); + QVERIFY(dir.removeRecursively()); + } + +private: + QString m_testDirectory; }; QTEST_MAIN(tst_extractarchiveoperationtest) diff --git a/tests/auto/installer/installiconsoperation/data/xmloperationrepository/A/1.0.2-1content.7z b/tests/auto/installer/installiconsoperation/data/xmloperationrepository/A/1.0.2-1content.7z new file mode 100644 index 000000000..9d58b172e Binary files /dev/null and b/tests/auto/installer/installiconsoperation/data/xmloperationrepository/A/1.0.2-1content.7z differ diff --git a/tests/auto/installer/installiconsoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/installiconsoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..5977964f2 --- /dev/null +++ b/tests/auto/installer/installiconsoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,18 @@ + + {AnyApplication} + 1.0.0 + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + content.7z + + + @TargetDir@/icons + + + + diff --git a/tests/auto/installer/installiconsoperation/settings.qrc b/tests/auto/installer/installiconsoperation/settings.qrc index 10cc3c3bb..094bd449b 100644 --- a/tests/auto/installer/installiconsoperation/settings.qrc +++ b/tests/auto/installer/installiconsoperation/settings.qrc @@ -3,5 +3,7 @@ data/repository/Updates.xml data/repository/A/1.0.2-1content.7z data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml + data/xmloperationrepository/A/1.0.2-1content.7z diff --git a/tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp b/tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp index cb95e49da..d1a9c680e 100644 --- a/tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp +++ b/tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp @@ -42,6 +42,43 @@ using namespace QInstaller; class tst_installiconsoperation : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + QString installDir = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(installDir)); + PackageManagerCore *core = PackageManager::getPackageManagerWithInit + (installDir, repository); + core->installDefaultComponentsSilently(); + + InstallIconsOperation *installIconsOp = nullptr; + OperationList operations = core->componentByName("A")->operations(); + foreach (Operation *op, operations) { + if (op->name() == QLatin1String("InstallIcons")) + installIconsOp = dynamic_cast(op); + } + QVERIFY(installIconsOp); + + // As the original directory containing icons will be deleted by the operation, + // we will use a copy with the exact same contents. + QFileInfo fakeSourceInfo(installDir + "/icons_copy/test"); + QMap fakeSourceMap; + VerifyInstaller::addToFileMap(QDir(fakeSourceInfo.absoluteFilePath()), fakeSourceInfo, fakeSourceMap); + + QFileInfo destinationInfo(installIconsOp->value("directory").toString() + "/test"); + QMap destinationMap; + VerifyInstaller::addToFileMap(QDir(destinationInfo.absoluteFilePath()), destinationInfo, destinationMap); + + QVERIFY(fakeSourceMap == destinationMap); + + core->setPackageManager(); + core->commitSessionOperations(); + core->uninstallComponentsSilently(QStringList() << "A"); + QVERIFY(!destinationInfo.exists()); + + QDir dir(installDir); + QVERIFY(dir.removeRecursively()); + } private slots: void initTestCase() @@ -77,42 +114,14 @@ private slots: QCOMPARE(op.errorString(), QString("Invalid Argument: source directory must not be empty.")); } - void testPerformingFromCLI() + void testInstallIconsFromScript() { - QString installDir = QInstaller::generateTemporaryFileName(); - QVERIFY(QDir().mkpath(installDir)); - PackageManagerCore *core = PackageManager::getPackageManagerWithInit - (installDir, ":///data/repository"); - core->installDefaultComponentsSilently(); - - InstallIconsOperation *installIconsOp = nullptr; - OperationList operations = core->componentByName("A")->operations(); - foreach (Operation *op, operations) { - if (op->name() == QLatin1String("InstallIcons")) - installIconsOp = dynamic_cast(op); - } - QVERIFY(installIconsOp); - - // As the original directory containing icons will be deleted by the operation, - // we will use a copy with the exact same contents. - QFileInfo fakeSourceInfo(installDir + "/icons_copy/test"); - QMap fakeSourceMap; - VerifyInstaller::addToFileMap(QDir(fakeSourceInfo.absoluteFilePath()), fakeSourceInfo, fakeSourceMap); - - QFileInfo destinationInfo(installIconsOp->value("directory").toString() + "/test"); - QMap destinationMap; - VerifyInstaller::addToFileMap(QDir(destinationInfo.absoluteFilePath()), destinationInfo, destinationMap); - - QVERIFY(fakeSourceMap == destinationMap); - - core->setPackageManager(); - core->commitSessionOperations(); - core->uninstallComponentsSilently(QStringList() << "A"); - QVERIFY(!destinationInfo.exists()); + installFromCLI(":///data/repository"); + } - QDir dir(installDir); - QVERIFY(dir.removeRecursively()); - core->deleteLater(); + void testInstallIconsFromXML() + { + installFromCLI(":///data/xmloperationrepository"); } void testInstallIconsWithUndo() diff --git a/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/A/1.0.2-1content.7z b/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/A/1.0.2-1content.7z new file mode 100644 index 000000000..8ba90b13b Binary files /dev/null and b/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/A/1.0.2-1content.7z differ diff --git a/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/A/1.0.2-1content.7z.sha1 b/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/A/1.0.2-1content.7z.sha1 new file mode 100644 index 000000000..a5f4399b3 --- /dev/null +++ b/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/A/1.0.2-1content.7z.sha1 @@ -0,0 +1 @@ +a0268f80fd2954271fe7d2eae584c13a6d143838 \ No newline at end of file diff --git a/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..131a2d9ff --- /dev/null +++ b/tests/auto/installer/linereplaceoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,23 @@ + + {AnyApplication} + 1.0.0 + true + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + + content.7z + 6d7a3e15d11a4d94b81452fc2aa18e705a01c922 + + + @TargetDir@/A.txt + Line to replace. + This line was replaced. + + + + diff --git a/tests/auto/installer/linereplaceoperation/settings.qrc b/tests/auto/installer/linereplaceoperation/settings.qrc index 66969539d..15da313dd 100644 --- a/tests/auto/installer/linereplaceoperation/settings.qrc +++ b/tests/auto/installer/linereplaceoperation/settings.qrc @@ -4,5 +4,8 @@ data/repository/A/1.0.2-1content.7z data/repository/A/1.0.2-1content.7z.sha1 data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml + data/xmloperationrepository/A/1.0.2-1content.7z + data/xmloperationrepository/A/1.0.2-1content.7z.sha1 diff --git a/tests/auto/installer/linereplaceoperation/tst_linereplaceoperation.cpp b/tests/auto/installer/linereplaceoperation/tst_linereplaceoperation.cpp index 0492bd104..762ef0211 100644 --- a/tests/auto/installer/linereplaceoperation/tst_linereplaceoperation.cpp +++ b/tests/auto/installer/linereplaceoperation/tst_linereplaceoperation.cpp @@ -40,6 +40,25 @@ class tst_linereplaceoperation : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + QString installDir = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(installDir)); + PackageManagerCore *core = PackageManager::getPackageManagerWithInit + (installDir, repository); + core->installDefaultComponentsSilently(); + + QFile file(installDir + QDir::separator() + "A.txt"); + QVERIFY(file.open(QIODevice::ReadOnly) | QIODevice::Text); + QTextStream stream(&file); + QCOMPARE(stream.readLine(), QLatin1String("This line was replaced.")); + QCOMPARE(stream.readLine(), QLatin1String("Another line.")); + file.close(); + QDir dir(installDir); + QVERIFY(dir.removeRecursively()); + } + private slots: void initTestCase() { @@ -115,23 +134,14 @@ private slots: QVERIFY(file.remove()); } - void testPerformingFromCLI() + void testLineReplaceFromScript() { - QString installDir = QInstaller::generateTemporaryFileName(); - QVERIFY(QDir().mkpath(installDir)); - PackageManagerCore *core = PackageManager::getPackageManagerWithInit - (installDir, ":///data/repository"); - core->installDefaultComponentsSilently(); + installFromCLI(":///data/repository"); + } - QFile file(installDir + QDir::separator() + "A.txt"); - QVERIFY(file.open(QIODevice::ReadOnly) | QIODevice::Text); - QTextStream stream(&file); - QCOMPARE(stream.readLine(), QLatin1String("This line was replaced.")); - QCOMPARE(stream.readLine(), QLatin1String("Another line.")); - file.close(); - QDir dir(installDir); - QVERIFY(dir.removeRecursively()); - core->deleteLater(); + void testLineReplaceFromXML() + { + installFromCLI(":///data/xmloperationrepository"); } private: diff --git a/tests/auto/installer/moveoperation/data/xmloperationrepository/Updates.xml b/tests/auto/installer/moveoperation/data/xmloperationrepository/Updates.xml new file mode 100644 index 000000000..6707452d8 --- /dev/null +++ b/tests/auto/installer/moveoperation/data/xmloperationrepository/Updates.xml @@ -0,0 +1,22 @@ + + {AnyApplication} + 1.0.0 + false + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + + + @TargetDir@/DestinationFolder + + + @InstallerDirPath@/testFile.txt + @TargetDir@/DestinationFolder/testFile.txt + + + + diff --git a/tests/auto/installer/moveoperation/settings.qrc b/tests/auto/installer/moveoperation/settings.qrc index d030220ab..04a7daf71 100644 --- a/tests/auto/installer/moveoperation/settings.qrc +++ b/tests/auto/installer/moveoperation/settings.qrc @@ -2,5 +2,6 @@ data/repository/Updates.xml data/repository/A/1.0.2-1meta.7z + data/xmloperationrepository/Updates.xml diff --git a/tests/auto/installer/moveoperation/tst_moveoperation.cpp b/tests/auto/installer/moveoperation/tst_moveoperation.cpp index f5b7bbcd9..6bc72242a 100644 --- a/tests/auto/installer/moveoperation/tst_moveoperation.cpp +++ b/tests/auto/installer/moveoperation/tst_moveoperation.cpp @@ -39,6 +39,27 @@ class tst_moveoperation : public QObject { Q_OBJECT +private: + void installFromCLI(const QString &repository) + { + PackageManagerCore *core = PackageManager::getPackageManagerWithInit + (m_testDirectory, repository); + core->installDefaultComponentsSilently(); + + QFile movedFile(m_testDirectory + QDir::separator() + "DestinationFolder/testFile.txt"); + QVERIFY(movedFile.exists()); + QFile originalFile(m_sourceFile); + QVERIFY(!originalFile.exists()); + + core->setPackageManager(); + core->commitSessionOperations(); + + core->uninstallComponentsSilently(QStringList() << "A"); + + QVERIFY(!movedFile.exists()); + QVERIFY(originalFile.exists()); + } + private slots: void initTestCase() { @@ -101,26 +122,14 @@ private slots: QVERIFY(QFile::exists(m_destinationFile)); } - void testPerformingFromCLI() + void testMoveOperationFromScript() { - PackageManagerCore *core = PackageManager::getPackageManagerWithInit - (m_testDirectory, ":///data/repository"); - core->installDefaultComponentsSilently(); - - QFile movedFile(m_testDirectory + QDir::separator() + "DestinationFolder/testFile.txt"); - QVERIFY(movedFile.exists()); - QFile originalFile(m_sourceFile); - QVERIFY(!originalFile.exists()); - - core->setPackageManager(); - core->commitSessionOperations(); - - core->uninstallComponentsSilently(QStringList() << "A"); - - QVERIFY(!movedFile.exists()); - QVERIFY(originalFile.exists()); + installFromCLI(":///data/repository"); + } - core->deleteLater(); + void testMoveOperationFromXML() + { + installFromCLI(":///data/xmloperationrepository"); } void cleanupTestCase() -- cgit v1.2.3