diff options
author | Katja Marttila <katja.marttila@qt.io> | 2020-04-02 10:28:08 +0300 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2020-04-06 09:34:00 +0300 |
commit | 02b23b874d7ec93f94865ce36fc33eb9e3c3ee7d (patch) | |
tree | 4ccda94d9e054128c51e22104bcd70d79272c577 /tests | |
parent | 6bbafab326e6eef523bf6e833557080417d22c77 (diff) |
Create tests for MoveOperation
Task-number: QTIFW-1716
Change-Id: Ia1ca53315b389b8d8145f8a995c2cc2658502003
Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/installer/installer.pro | 3 | ||||
-rw-r--r-- | tests/auto/installer/moveoperation/data/repository/A/1.0.2-1meta.7z | bin | 0 -> 909 bytes | |||
-rw-r--r-- | tests/auto/installer/moveoperation/data/repository/Updates.xml | 14 | ||||
-rw-r--r-- | tests/auto/installer/moveoperation/moveoperation.pro | 10 | ||||
-rw-r--r-- | tests/auto/installer/moveoperation/settings.qrc | 6 | ||||
-rw-r--r-- | tests/auto/installer/moveoperation/tst_moveoperation.cpp | 158 |
6 files changed, 190 insertions, 1 deletions
diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro index 604dfeed4..654412856 100644 --- a/tests/auto/installer/installer.pro +++ b/tests/auto/installer/installer.pro @@ -30,7 +30,8 @@ SUBDIRS += \ metadatajob \ simplemovefileoperation \ deleteoperation \ - commandlineupdate + commandlineupdate \ + moveoperation win32 { SUBDIRS += registerfiletypeoperation diff --git a/tests/auto/installer/moveoperation/data/repository/A/1.0.2-1meta.7z b/tests/auto/installer/moveoperation/data/repository/A/1.0.2-1meta.7z Binary files differnew file mode 100644 index 000000000..bd8df91b3 --- /dev/null +++ b/tests/auto/installer/moveoperation/data/repository/A/1.0.2-1meta.7z diff --git a/tests/auto/installer/moveoperation/data/repository/Updates.xml b/tests/auto/installer/moveoperation/data/repository/Updates.xml new file mode 100644 index 000000000..6b1856d51 --- /dev/null +++ b/tests/auto/installer/moveoperation/data/repository/Updates.xml @@ -0,0 +1,14 @@ +<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> + </PackageUpdate> +</Updates> diff --git a/tests/auto/installer/moveoperation/moveoperation.pro b/tests/auto/installer/moveoperation/moveoperation.pro new file mode 100644 index 000000000..a5f17c889 --- /dev/null +++ b/tests/auto/installer/moveoperation/moveoperation.pro @@ -0,0 +1,10 @@ +include(../../qttest.pri) + +QT -= gui +QT += testlib + +SOURCES = tst_moveoperation.cpp + +RESOURCES += \ + settings.qrc \ + ..\shared\config.qrc diff --git a/tests/auto/installer/moveoperation/settings.qrc b/tests/auto/installer/moveoperation/settings.qrc new file mode 100644 index 000000000..d030220ab --- /dev/null +++ b/tests/auto/installer/moveoperation/settings.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file>data/repository/Updates.xml</file> + <file>data/repository/A/1.0.2-1meta.7z</file> + </qresource> +</RCC> diff --git a/tests/auto/installer/moveoperation/tst_moveoperation.cpp b/tests/auto/installer/moveoperation/tst_moveoperation.cpp new file mode 100644 index 000000000..fb3458874 --- /dev/null +++ b/tests/auto/installer/moveoperation/tst_moveoperation.cpp @@ -0,0 +1,158 @@ +/************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include <updateoperations.h> +#include <utils.h> +#include <packagemanagercore.h> +#include <binarycontent.h> +#include <settings.h> +#include <fileutils.h> +#include <init.h> + +#include <QDir> +#include <QObject> +#include <QTest> +#include <QFile> +#include <QDebug> + +using namespace KDUpdater; +using namespace QInstaller; + +class tst_moveoperation : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase() + { + m_testDirectory = QInstaller::generateTemporaryFileName(); + QVERIFY(QDir().mkpath(m_testDirectory)); + QVERIFY(QDir(m_testDirectory).exists()); + + QString testFile = QDir::toNativeSeparators("/testFile.txt"); + m_sourceFile = qApp->applicationDirPath() + testFile; + QFile file(m_sourceFile); + QVERIFY(file.open(QIODevice::WriteOnly)); //Generates the m_sourceFile + file.close(); + + m_destinationDirectory = m_testDirectory + QDir::toNativeSeparators("/test"); + QVERIFY(QDir().mkpath(m_destinationDirectory)); + m_destinationFile = m_destinationDirectory + QDir::toNativeSeparators(testFile); + } + + void testMissingArguments() + { + MoveOperation op; + + QVERIFY(op.testOperation()); + QVERIFY(!op.performOperation()); + + QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments); + QCOMPARE(op.errorString(), QString("Invalid arguments in Move: " + "0 arguments given, exactly 2 arguments expected.")); + } + + void testMoveFile() + { + MoveOperation op; + op.setArguments(QStringList() << m_sourceFile << m_destinationFile); + op.backup(); + QVERIFY2(op.performOperation(), op.errorString().toLatin1()); + QVERIFY(!QFile::exists(m_sourceFile)); + QVERIFY(QFile::exists(m_destinationFile)); + + QVERIFY(op.undoOperation()); + QVERIFY(QFile::exists(m_sourceFile)); + QVERIFY(!QFile::exists(m_destinationFile)); + } + + void testMoveFileDestinationExists() + { + QFile file(m_destinationFile); + QVERIFY(file.open(QIODevice::WriteOnly)); //Creates the destination file + file.close(); + + MoveOperation op; + op.setArguments(QStringList() << m_sourceFile << m_destinationFile); + op.backup(); + QVERIFY2(op.performOperation(), op.errorString().toLatin1()); + QVERIFY(!QFile::exists(m_sourceFile)); + QVERIFY(QFile::exists(m_destinationFile)); + + QVERIFY(op.undoOperation()); + QVERIFY(QFile::exists(m_sourceFile)); + QVERIFY(QFile::exists(m_destinationFile)); + } + + void testPerformingFromCLI() + { + QInstaller::init(); //This will eat debug output + PackageManagerCore *core = new PackageManagerCore(BinaryContent::MagicInstallerMarker, QList<OperationBlob> ()); + QString appFilePath = QCoreApplication::applicationFilePath(); + core->setAllowedRunningProcesses(QStringList() << appFilePath); + QSet<Repository> repoList; + Repository repo = Repository::fromUserInput(":///data/repository"); + repoList.insert(repo); + core->settings().setDefaultRepositories(repoList); + + core->setValue(scTargetDir, m_testDirectory); + 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()); + + core->deleteLater(); + } + + void cleanupTestCase() + { + QDir dir(m_testDirectory); + QVERIFY(dir.removeRecursively()); + QVERIFY(QFile::remove(m_sourceFile)); + } + +private: + QString m_testDirectory; + QString m_sourceFile; + QString m_destinationDirectory; + QString m_destinationFile; +}; + +QTEST_MAIN(tst_moveoperation) + +#include "tst_moveoperation.moc" |