From 02b23b874d7ec93f94865ce36fc33eb9e3c3ee7d Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Thu, 2 Apr 2020 10:28:08 +0300 Subject: Create tests for MoveOperation Task-number: QTIFW-1716 Change-Id: Ia1ca53315b389b8d8145f8a995c2cc2658502003 Reviewed-by: Arttu Tarkiainen --- tests/auto/installer/installer.pro | 3 +- .../moveoperation/data/repository/A/1.0.2-1meta.7z | Bin 0 -> 909 bytes .../moveoperation/data/repository/Updates.xml | 14 ++ .../auto/installer/moveoperation/moveoperation.pro | 10 ++ tests/auto/installer/moveoperation/settings.qrc | 6 + .../installer/moveoperation/tst_moveoperation.cpp | 158 +++++++++++++++++++++ 6 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 tests/auto/installer/moveoperation/data/repository/A/1.0.2-1meta.7z create mode 100644 tests/auto/installer/moveoperation/data/repository/Updates.xml create mode 100644 tests/auto/installer/moveoperation/moveoperation.pro create mode 100644 tests/auto/installer/moveoperation/settings.qrc create mode 100644 tests/auto/installer/moveoperation/tst_moveoperation.cpp 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 new file mode 100644 index 000000000..bd8df91b3 Binary files /dev/null and b/tests/auto/installer/moveoperation/data/repository/A/1.0.2-1meta.7z differ 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 @@ + + {AnyApplication} + 1.0.0 + false + + A + A + Example component A + 1.0.2-1 + 2015-01-01 + true + + + 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 @@ + + + data/repository/Updates.xml + data/repository/A/1.0.2-1meta.7z + + 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +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 ()); + QString appFilePath = QCoreApplication::applicationFilePath(); + core->setAllowedRunningProcesses(QStringList() << appFilePath); + QSet 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" -- cgit v1.2.3