summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2020-04-03 11:08:38 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2020-04-09 08:20:59 +0300
commita58ec153e6e2f91e7cfa89c15ecd222c29bf3fb9 (patch)
tree42d5f7debf8f77446a35af2ae0def368d5a6c1c1
parent8c4f95f54336764ad4062d76ed454468e7815e28 (diff)
Add unit and CLI tests for AppendFileOperation
Task-number: QTIFW-1718 Change-Id: Ibe29bd072f6fc671b76fbcc76e4e747cc870cab2 Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
-rw-r--r--tests/auto/installer/appendfileoperation/appendfileoperation.pro10
-rw-r--r--tests/auto/installer/appendfileoperation/data/repository/A/1.0.2-1content.7zbin0 -> 156 bytes
-rw-r--r--tests/auto/installer/appendfileoperation/data/repository/A/1.0.2-1meta.7zbin0 -> 886 bytes
-rw-r--r--tests/auto/installer/appendfileoperation/data/repository/Updates.xml14
-rw-r--r--tests/auto/installer/appendfileoperation/settings.qrc7
-rw-r--r--tests/auto/installer/appendfileoperation/tst_appendfileoperation.cpp156
-rw-r--r--tests/auto/installer/installer.pro1
7 files changed, 188 insertions, 0 deletions
diff --git a/tests/auto/installer/appendfileoperation/appendfileoperation.pro b/tests/auto/installer/appendfileoperation/appendfileoperation.pro
new file mode 100644
index 000000000..64cea7039
--- /dev/null
+++ b/tests/auto/installer/appendfileoperation/appendfileoperation.pro
@@ -0,0 +1,10 @@
+include(../../qttest.pri)
+
+QT -= gui
+QT += testlib
+
+SOURCES += tst_appendfileoperation.cpp
+
+RESOURCES += \
+ settings.qrc \
+ ..\shared\config.qrc
diff --git a/tests/auto/installer/appendfileoperation/data/repository/A/1.0.2-1content.7z b/tests/auto/installer/appendfileoperation/data/repository/A/1.0.2-1content.7z
new file mode 100644
index 000000000..787e0db25
--- /dev/null
+++ b/tests/auto/installer/appendfileoperation/data/repository/A/1.0.2-1content.7z
Binary files differ
diff --git a/tests/auto/installer/appendfileoperation/data/repository/A/1.0.2-1meta.7z b/tests/auto/installer/appendfileoperation/data/repository/A/1.0.2-1meta.7z
new file mode 100644
index 000000000..946290ce4
--- /dev/null
+++ b/tests/auto/installer/appendfileoperation/data/repository/A/1.0.2-1meta.7z
Binary files differ
diff --git a/tests/auto/installer/appendfileoperation/data/repository/Updates.xml b/tests/auto/installer/appendfileoperation/data/repository/Updates.xml
new file mode 100644
index 000000000..a1c8f6aa2
--- /dev/null
+++ b/tests/auto/installer/appendfileoperation/data/repository/Updates.xml
@@ -0,0 +1,14 @@
+<Updates>
+ <ApplicationName>{AnyApplication}</ApplicationName>
+ <ApplicationVersion>1.0.0</ApplicationVersion>
+ <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>
+ <DownloadableArchives>content.7z</DownloadableArchives>
+ </PackageUpdate>
+</Updates>
diff --git a/tests/auto/installer/appendfileoperation/settings.qrc b/tests/auto/installer/appendfileoperation/settings.qrc
new file mode 100644
index 000000000..10cc3c3bb
--- /dev/null
+++ b/tests/auto/installer/appendfileoperation/settings.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>data/repository/Updates.xml</file>
+ <file>data/repository/A/1.0.2-1content.7z</file>
+ <file>data/repository/A/1.0.2-1meta.7z</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/installer/appendfileoperation/tst_appendfileoperation.cpp b/tests/auto/installer/appendfileoperation/tst_appendfileoperation.cpp
new file mode 100644
index 000000000..a2670b332
--- /dev/null
+++ b/tests/auto/installer/appendfileoperation/tst_appendfileoperation.cpp
@@ -0,0 +1,156 @@
+/**************************************************************************
+**
+** 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 <packagemanagercore.h>
+#include <binarycontent.h>
+#include <settings.h>
+#include <fileutils.h>
+#include <init.h>
+
+#include <QObject>
+#include <QFile>
+#include <QTest>
+
+using namespace KDUpdater;
+using namespace QInstaller;
+
+class tst_appendfileoperation : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase()
+ {
+ m_testFilePath = qApp->applicationDirPath() + QDir::toNativeSeparators("/test");
+ }
+
+ void testMissingArguments()
+ {
+ AppendFileOperation op;
+
+ QVERIFY(op.testOperation());
+ QVERIFY(!op.performOperation());
+
+ QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments);
+ QCOMPARE(op.errorString(), QString("Invalid arguments in AppendFile: "
+ "0 arguments given, exactly 2 arguments expected."));
+
+ op.setArguments(QStringList() << "" << "");
+ QTest::ignoreMessage(QtWarningMsg, "QFSFileEngine::open: No file name specified");
+ QTest::ignoreMessage(QtWarningMsg, "QFile::rename: Empty or null file name");
+ QVERIFY(!op.performOperation());
+
+ QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::UserDefinedError);
+ QCOMPARE(op.errorString(), QString("Cannot open file \"\" for writing: No file name specified"));
+ }
+
+ void testAppendText_data()
+ {
+ QTest::addColumn<QString>("source");
+ QTest::addColumn<QString>("append");
+ QTest::addColumn<QString>("expected");
+ QTest::newRow("newline") << "Line1\nLine2\nLine3\n" << "AppendedText"
+ << "Line1\nLine2\nLine3\nAppendedText";
+ QTest::newRow("no newline") << "Lorem ipsum " << "dolore sit amet"
+ << "Lorem ipsum dolore sit amet";
+ }
+
+ void testAppendText()
+ {
+ QFETCH(QString, source);
+ QFETCH(QString, append);
+ QFETCH(QString, expected);
+
+ QFile file(m_testFilePath);
+ QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text));
+
+ QTextStream stream(&file);
+ stream << source << flush;
+ file.close();
+
+ AppendFileOperation op;
+ op.setArguments(QStringList() << m_testFilePath << append);
+
+ op.backup();
+ QVERIFY(QFileInfo(op.value("backupOfFile").toString()).exists());
+
+ QVERIFY2(op.performOperation(), op.errorString().toLatin1());
+ QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
+ QCOMPARE(stream.readAll(), expected);
+ file.close();
+
+ QVERIFY2(op.undoOperation(), op.errorString().toLatin1());
+ QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
+ QCOMPARE(stream.readAll(), source);
+ file.close();
+
+ QVERIFY(file.remove());
+ }
+
+ void testPerformingFromCLI()
+ {
+ QInstaller::init(); //This will eat debug output
+ PackageManagerCore *core = new PackageManagerCore(BinaryContent::MagicInstallerMarker, QList<OperationBlob> ());
+ core->setAllowedRunningProcesses(QStringList() << QCoreApplication::applicationFilePath());
+ QSet<Repository> repoList;
+ Repository repo = Repository::fromUserInput(":///data/repository");
+ repoList.insert(repo);
+ core->settings().setDefaultRepositories(repoList);
+
+ QString installDir = QInstaller::generateTemporaryFileName();
+ QVERIFY(QDir().mkpath(installDir));
+
+ core->setValue(scTargetDir, installDir);
+ 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.
+ QVERIFY(core->uninstallComponentsSilently(QStringList() << "A"));
+
+ QDir dir(installDir);
+ QVERIFY(dir.removeRecursively());
+ core->deleteLater();
+ }
+
+private:
+ QString m_testFilePath;
+};
+
+QTEST_MAIN(tst_appendfileoperation)
+
+#include "tst_appendfileoperation.moc"
diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro
index da04efef0..d5926ab6e 100644
--- a/tests/auto/installer/installer.pro
+++ b/tests/auto/installer/installer.pro
@@ -28,6 +28,7 @@ SUBDIRS += \
cliinterface \
linereplaceoperation \
metadatajob \
+ appendfileoperation \
simplemovefileoperation \
deleteoperation \
copydirectoryoperation \