summaryrefslogtreecommitdiffstats
path: root/tests/packagecreator/tst_packagecreator.cpp
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@pelagicore.com>2015-10-20 11:31:13 +0200
committerRobert Griebl <robert.griebl@pelagicore.com>2015-10-26 09:46:22 +0000
commit2491a2ba4b7c4bdc04566df84e1b6841c1393bb3 (patch)
tree8d87a4534b1d8abbaf6e358929b969168901304c /tests/packagecreator/tst_packagecreator.cpp
parent0c9e6ac0803ef00401ddfd08dc7558c20eefd0c4 (diff)
Initial commit of Pelagicore's ApplicationManager with squashed history.
(minus all 3rd party stuff - we will re-add them later, potentially changing the way some of them are handled completely) Change-Id: I55f15b12f0dbe0c4f979206eaa163d4793ff7073 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'tests/packagecreator/tst_packagecreator.cpp')
-rw-r--r--tests/packagecreator/tst_packagecreator.cpp146
1 files changed, 146 insertions, 0 deletions
diff --git a/tests/packagecreator/tst_packagecreator.cpp b/tests/packagecreator/tst_packagecreator.cpp
new file mode 100644
index 00000000..1f40cc8c
--- /dev/null
+++ b/tests/packagecreator/tst_packagecreator.cpp
@@ -0,0 +1,146 @@
+;/****************************************************************************
+**
+** Copyright (C) 2015 Pelagicore AG
+** Contact: http://www.pelagicore.com/
+**
+** This file is part of the Pelagicore Application Manager.
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+** $QT_BEGIN_LICENSE:GPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Pelagicore Application Manager
+** 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
+** Pelagicore. For licensing terms and conditions, contact us at:
+** http://www.pelagicore.com.
+**
+** 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 and appearing in the file LICENSE.GPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3 requirements will be
+** met: http://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest>
+
+#include "installationreport.h"
+#include "utilities.h"
+#include "packagecreator.h"
+
+#include "../error-checking.h"
+
+
+class tst_PackageCreator : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_PackageCreator();
+
+private slots:
+ void initTestCase();
+
+ void createAndVerify_data();
+ void createAndVerify();
+
+private:
+ QDir m_baseDir;
+ bool m_tarAvailable = false;
+};
+
+tst_PackageCreator::tst_PackageCreator()
+ : m_baseDir(AM_TESTDATA_DIR)
+{ }
+
+void tst_PackageCreator::initTestCase()
+{
+ // check if tar command is available at all
+
+ QProcess tar;
+ tar.start("tar", { "--version" });
+ m_tarAvailable = tar.waitForStarted(3000)
+ && tar.waitForFinished(3000)
+ && (tar.exitStatus() == QProcess::NormalExit);
+}
+
+void tst_PackageCreator::createAndVerify_data()
+{
+ QTest::addColumn<QStringList>("files");
+ QTest::addColumn<bool>("expectedSuccess");
+ QTest::addColumn<QString>("errorString");
+
+ QTest::newRow("basic") << QStringList { "testfile" } << true << QString();
+ QTest::newRow("no-such-file") << QStringList { "tastfile" } << false << "~file not found: .*";
+}
+
+void tst_PackageCreator::createAndVerify()
+{
+ QFETCH(QStringList, files);
+ QFETCH(bool, expectedSuccess);
+ QFETCH(QString, errorString);
+
+ QTemporaryFile output;
+ QVERIFY(output.open());
+
+ InstallationReport report("com.pelagicore.test");
+ report.addFiles(files);
+
+ PackageCreator creator(m_baseDir, &output, report);
+ bool result = creator.create();
+ output.close();
+
+ if (expectedSuccess) {
+ QVERIFY2(result, qPrintable(creator.errorString()));
+ } else {
+ QVERIFY(creator.errorCode() != Error::None);
+ QVERIFY(creator.errorCode() != Error::Canceled);
+ QVERIFY(!creator.wasCanceled());
+
+ AM_CHECK_ERRORSTRING(creator.errorString(), errorString);
+ return;
+ }
+
+ // check the tar listing
+ if (!m_tarAvailable)
+ QSKIP("No tar command found in PATH - skipping the verification part of the test!");
+
+ QProcess tar;
+ tar.start("tar", { "-taf", output.fileName() });
+ QVERIFY2(tar.waitForStarted(3000) &&
+ tar.waitForFinished(3000) &&
+ (tar.exitStatus() == QProcess::NormalExit) &&
+ (tar.exitCode() == 0), qPrintable(tar.errorString()));
+
+ QStringList expectedContents = files;
+ expectedContents.sort();
+ expectedContents.prepend("--PACKAGE-HEADER--");
+ expectedContents.append("--PACKAGE-FOOTER--");
+ QCOMPARE(expectedContents, QString::fromLocal8Bit(tar.readAllStandardOutput()).split('\n', QString::SkipEmptyParts));
+
+ // check the contents of the files
+
+ foreach (const QString &file, files) {
+ QFile src(m_baseDir.absoluteFilePath(file));
+ QVERIFY2(src.open(QFile::ReadOnly), qPrintable(src.errorString()));
+ QByteArray data = src.readAll();
+
+ tar.start("tar", { "-xaOf", output.fileName(), file });
+ QVERIFY2(tar.waitForStarted(3000) &&
+ tar.waitForFinished(3000) &&
+ (tar.exitStatus() == QProcess::NormalExit) &&
+ (tar.exitCode() == 0), qPrintable(tar.errorString()));
+
+ QCOMPARE(tar.readAllStandardOutput(), data);
+ }
+}
+
+QTEST_GUILESS_MAIN(tst_PackageCreator)
+
+#include "tst_packagecreator.moc"