diff options
-rw-r--r-- | tests/auto/installer/extractarchiveoperationtest/data.qrc | 6 | ||||
-rw-r--r-- | tests/auto/installer/extractarchiveoperationtest/data/invalid.7z | bin | 0 -> 25600 bytes | |||
-rw-r--r-- | tests/auto/installer/extractarchiveoperationtest/data/valid.7z | bin | 0 -> 950 bytes | |||
-rw-r--r-- | tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro | 7 | ||||
-rw-r--r-- | tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp (renamed from tests/extractarchiveoperationtest/extractarchiveoperationtest.h) | 65 | ||||
-rw-r--r-- | tests/auto/installer/installer.pro | 3 | ||||
-rw-r--r-- | tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp | 177 | ||||
-rw-r--r-- | tests/extractarchiveoperationtest/extractarchiveoperationtest.pro | 15 | ||||
-rw-r--r-- | tests/test-noarchive.7z | 190 | ||||
-rw-r--r-- | tests/test1.7z | bin | 282 -> 0 bytes | |||
-rw-r--r-- | tests/test2.7z | bin | 629 -> 0 bytes |
11 files changed, 65 insertions, 398 deletions
diff --git a/tests/auto/installer/extractarchiveoperationtest/data.qrc b/tests/auto/installer/extractarchiveoperationtest/data.qrc new file mode 100644 index 000000000..d6453a9b3 --- /dev/null +++ b/tests/auto/installer/extractarchiveoperationtest/data.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file>data/valid.7z</file> + <file>data/invalid.7z</file> + </qresource> +</RCC> diff --git a/tests/auto/installer/extractarchiveoperationtest/data/invalid.7z b/tests/auto/installer/extractarchiveoperationtest/data/invalid.7z Binary files differnew file mode 100644 index 000000000..bcf81250e --- /dev/null +++ b/tests/auto/installer/extractarchiveoperationtest/data/invalid.7z diff --git a/tests/auto/installer/extractarchiveoperationtest/data/valid.7z b/tests/auto/installer/extractarchiveoperationtest/data/valid.7z Binary files differnew file mode 100644 index 000000000..e583bdf99 --- /dev/null +++ b/tests/auto/installer/extractarchiveoperationtest/data/valid.7z diff --git a/tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro b/tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro new file mode 100644 index 000000000..fb53c9a8a --- /dev/null +++ b/tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro @@ -0,0 +1,7 @@ +include(../../qttest.pri) + +QT -= gui +QT += testlib + +RESOURCES += data.qrc +SOURCES = tst_extractarchiveoperationtest.cpp diff --git a/tests/extractarchiveoperationtest/extractarchiveoperationtest.h b/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp index 4dad9d00a..eb3b0378e 100644 --- a/tests/extractarchiveoperationtest/extractarchiveoperationtest.h +++ b/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Installer Framework. @@ -39,28 +39,63 @@ ** **************************************************************************/ -#ifndef EXTRACTIONARCHIVEOPERATIONTEST_H -#define EXTRACTIONARCHIVEOPERATIONTEST_H +#include "init.h" +#include "extractarchiveoperation.h" +#include <QDir> #include <QObject> +#include <QTest> -#include <QtTest/QtTest> +using namespace KDUpdater; +using namespace QInstaller; -class ExtractArchiveOperationTest : public QObject +class tst_extractarchiveoperationtest : public QObject { Q_OBJECT -public: - ExtractArchiveOperationTest(); +private slots: + void initTestCase() + { + QInstaller::init(); + } -private Q_SLOTS: - void testExtraction(); - void testInvalidArchive(); - void testExtractionErrors(); + void testMissingArguments() + { + ExtractArchiveOperation op; -private: - void init(const QString &); - void cleanup(const QString &); + QVERIFY(op.testOperation()); + QVERIFY(!op.performOperation()); + //QVERIFY(!op.undoOperation()); Can't test for failure as we run into Q_ASSERT + + QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments); + QCOMPARE(op.errorString(), QString("Invalid arguments in Extract: 0 arguments given, exactly 2 expected.")); + + } + + void testExtractOperationValidFile() + { + ExtractArchiveOperation op; + op.setArguments(QStringList() << ":///data/valid.7z" << QDir::tempPath()); + + QVERIFY(op.testOperation()); + QVERIFY(op.performOperation()); + QVERIFY(op.undoOperation()); + } + + void testExtractOperationInvalidFile() + { + ExtractArchiveOperation op; + op.setArguments(QStringList() << ":///data/invalid.7z" << QDir::tempPath()); + + QVERIFY(op.testOperation()); + QVERIFY(!op.performOperation()); + QVERIFY(op.undoOperation()); + + QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::UserDefinedError); + QCOMPARE(op.errorString(), QString("Error while extracting ':///data/invalid.7z': Could not open archive")); + } }; -#endif // EXTRACTARCHIVEOPERATIONTEST_H +QTEST_MAIN(tst_extractarchiveoperationtest) + +#include "tst_extractarchiveoperationtest.moc" diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro index e8d31a23e..e22407368 100644 --- a/tests/auto/installer/installer.pro +++ b/tests/auto/installer/installer.pro @@ -5,4 +5,5 @@ SUBDIRS += \ repository \ componentmodel \ fakestopprocessforupdateoperation \ - messageboxhandler + messageboxhandler \ + extractarchiveoperationtest diff --git a/tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp b/tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp deleted file mode 100644 index 2f5fd18a5..000000000 --- a/tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Installer Framework. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -**************************************************************************/ - -#include "extractarchiveoperationtest.h" -#include "extractarchiveoperation.h" - -#include "init.h" - -#include <kdupdaterapplication.h> - -#include <QDir> -#include <QDirIterator> -#include <QFileInfo> -#include <QStack> - -ExtractArchiveOperationTest::ExtractArchiveOperationTest() -{ - QInstaller::init(); -} - -void ExtractArchiveOperationTest::init(const QString &outdir) -{ - if (QDir(outdir).exists()) { - QFAIL("output directory already exists!"); - QVERIFY(false); - } - QDir cd(QDir::current()); - QVERIFY(cd.mkdir(outdir)); -} - -static bool recursiveRemove(const QString &path, QString *errorMsg) -{ - if (errorMsg) - errorMsg->clear(); - if (!QFileInfo(path).exists()) - return true; - bool error = false; - QString msg; - //first, delete all non-dir files - QDirIterator it(path, QDirIterator::Subdirectories); - while (it.hasNext()) { - const QString n = it.next(); - if (!QFileInfo(n).isDir()) { - QFile file(n); - if (!file.remove()) { - error = true; - msg = file.errorString(); - } - } - } - - QStack<QString> dirs; - QDirIterator it2(path, QDirIterator::Subdirectories); - while (it2.hasNext()) { - const QString n = it2.next(); - if (!n.endsWith(QLatin1String( "/." ) ) && !n.endsWith( QLatin1String( "/.." ))) - dirs.push(n); - } - while (!dirs.isEmpty()) { - const QString n = dirs.top(); - dirs.pop(); - if (!QDir(n).rmdir(QDir::currentPath() + QLatin1String("/") + n)) { - error = true; - msg = QObject::tr("Could not remove folder %1").arg(n); - qDebug() << msg; - } - } - - if (!QDir(path).rmdir(QDir::currentPath() + QLatin1String("/") + path)) { - error = true; - msg = QObject::tr("Could not remove folder %1: Unknown error").arg(path); - } - - if (errorMsg) - *errorMsg = msg; - return !error; -} - -void ExtractArchiveOperationTest::cleanup(const QString &dir) -{ - QDir d(dir); - QString msg; - const bool removed = recursiveRemove(dir, &msg); - if (!removed) - qCritical() << msg; - QVERIFY(removed); -} - -void ExtractArchiveOperationTest::testExtraction() -{ - const QString outdir = QLatin1String("test-extract-out" ); - init(outdir); - KDUpdater::Application app; - QInstaller::ExtractArchiveOperation op; - op.setArguments(QStringList() << QLatin1String("qt-bin-test.7z") << outdir); - const bool ok = op.performOperation(); - if (!ok) { - qCritical() << "Extraction failed:" << op.errorString(); - QFAIL("Extraction failed"); - } - cleanup(outdir); -} - -void ExtractArchiveOperationTest::testExtractionErrors() -{ - const QString outdir = QLatin1String("test-extract-out"); - init(outdir); - KDUpdater::Application app; - QInstaller::ExtractArchiveOperation op; - op.setArguments(QStringList() << QLatin1String("qt-bin-test.7z") << outdir); - const bool ok = op.performOperation(); - if (!ok) { - qCritical() << "Extraction failed:" << op.errorString(); - QFAIL("Extraction failed"); - } - cleanup(outdir); - -} - -void ExtractArchiveOperationTest::testInvalidArchive() -{ - const QString outdir = QLatin1String("test-extract-out"); - init(outdir); - KDUpdater::Application app; - QInstaller::ExtractArchiveOperation op; - op.setArguments(QStringList() << QLatin1String("test-noarchive.7z") << outdir); - const bool ok = op.performOperation(); - if (ok) { - qCritical() << "ExtractArchiveOperation does not report error on extracting invalid archive"; - QFAIL("Extraction failed"); - } - QVERIFY(op.error() != QInstaller::ExtractArchiveOperation::NoError); - const QString str = op.errorString(); - qDebug() << str; - QVERIFY(!str.isEmpty()); - cleanup(outdir); -} - -QTEST_MAIN(ExtractArchiveOperationTest) diff --git a/tests/extractarchiveoperationtest/extractarchiveoperationtest.pro b/tests/extractarchiveoperationtest/extractarchiveoperationtest.pro deleted file mode 100644 index 32d66495b..000000000 --- a/tests/extractarchiveoperationtest/extractarchiveoperationtest.pro +++ /dev/null @@ -1,15 +0,0 @@ -TEMPLATE = app -INCLUDEPATH += . .. -TARGET = extractarchiveoperationtest - -include(../../installerfw.pri) - -QT -= gui -QT += testlib - -CONFIG += console -CONFIG -= app_bundle -DESTDIR = $$IFW_APP_PATH - -HEADERS = extractarchiveoperationtest.h -SOURCES = extractarchiveoperationtest.cpp diff --git a/tests/test-noarchive.7z b/tests/test-noarchive.7z deleted file mode 100644 index 963107aca..000000000 --- a/tests/test-noarchive.7z +++ /dev/null @@ -1,190 +0,0 @@ -#!/bin/bash - -PRODUCT=SDKINSTALLER -Product=SDKInstaller -product=sdkinstaller - -VERSION=0.0.1 - -default_prefix=/usr/local/KDAB/$Product-$VERSION - -hide_symbols=yes -shared=yes -debug=no -release=yes -prefix= -unittests=no - -STATIC_BUILD_SUPPORTED=false - -function die { - echo "$1" 1>&2 - exit 1 -} - - -function usage { - [ -z "$1" ] || echo "$0: unknown option \"$1\"" 1>&2 - echo "usage: $0 [options]" 1>&2 - cat <<EOF 1>&2 -where options include: - -EOF -if [ "$INSTALLATION_SUPPORTED" = "true" ]; then - cat <<EOF 1>&2 - -prefix <path> - install $Product into <path> -EOF -fi -cat <<EOF 1>&2 - - -release / -debug - build in debug/release mode -EOF -if [ "$STATIC_BUILD_SUPPORTED" = "true" ]; then - cat <<EOF 1>&2 - - -static / -shared - build static/shared libraries -EOF -fi -cat <<EOF 1>&2 - - -[no-]hide-symbols (Unix only) - reduce the number of exported symbols - - -[no-]unittests - enable/disable compiled-in unittests - -EOF - exit 1 -} - -if [ -z "$QTDIR" ] ; then - QTDIR="$(qmake -query QT_INSTALL_PREFIX)" - if [ $? -ne 0 ] ; then - QTDIR= - fi -fi - -[ -z "$QTDIR" ] && die "You need QTDIR defined, or qmake in the PATH" - -while [ $# -ne 0 ] ; do - case "$1" in - -prefix) - shift - if [ $# -eq 0 ] ; then - echo "-prefix needs an argument" 2>&1 - usage - fi - prefix="$1" - ;; - -no-hide-symbols) - hide_symbols=no - ;; - -hide-symbols) - hide_symbols=yes - ;; - -no-unittests) - unittests=no - ;; - -unittests) - unittests=yes - ;; - -shared) - shared=yes - ;; - -static) - if [ "$STATIC_BUILD_SUPPORTED" != "true" ]; then - echo "Static build not supported, -static option not allowed" 2>&1 - usage - fi - shared=no - ;; - -debug) - debug=yes - release=no - ;; - -release) - debug=no - release=yes - ;; - *) - usage "$1" - ;; - esac - shift -done - -find . -name debug -o -name release -o -name Makefile\* | xargs rm -rf - -if [ -f src/src.pro ] ; then - rm -rf lib bin -fi - -if [ -z "$prefix" ] ; then - prefix="$default_prefix" -fi - -echo -n > ".qmake.cache" -( - echo "CONFIG += ${product}_target" - -# The following disabled to make debug builds work again: -# echo '!contains($$list($$[QT_VERSION]), 4.2.*):CONFIG += debug_and_release build_all' -# [ "$debug" = "yes" ] && echo "else:CONFIG -=release += debug" -# [ "$release" = "yes" ] && echo "else:CONFIG -=debug += release" - - if [ "$debug" = "yes" ]; then - echo "CONFIG -= release" - echo "CONFIG += debug" - echo "CONFIG -= debug_and_release" - fi - - if [ "$release" = "yes" ]; then - echo "CONFIG += release" - echo "CONFIG -= debug" - echo "CONFIG -= debug_and_release" - fi - - [ "$hide_symbols" = "yes" ] && echo "CONFIG += hide_symbols" - [ "$unittests" = "yes" ] && echo "CONFIG += unittests" - - if [ "$shared" = "yes" ]; then - echo "CONFIG -= static" - echo "CONFIG -= staticlib" - echo "CONFIG += shared" - else - echo "CONFIG += static" - echo "CONFIG += staticlib" - echo "CONFIG -= shared" - fi - - if [ -d "$QTDIR/include/Qt/private" ] ; then - echo "CONFIG += have_private_qt_headers" - echo "INCLUDEPATH += $QTDIR/include/Qt/private" - #else - #echo "QTDIR must point to an installation that has private headers installed." - #echo "Some features will not be available." - fi -echo "${PRODUCT}_INSTALL_PREFIX = $prefix" -echo "${PRODUCT}_BASE = `pwd`" - -) >> ".qmake.cache" - -cat <<EOF 1>&2 -$Product v$VERSION configuration: - - Install Prefix.............: $prefix - (default: $default_prefix) - Debug......................: $debug (default: no) - Release....................: $release (default: yes) - Compiled-In Unit Tests.....: $unittests (default: no) - Restricted symbol export - (shared build only)......: $hide_symbols (default: yes) - -EOF - -$QTDIR/bin/qmake $product.pro -recursive "CONFIG+=pk7zip_library" || die "qmake failed" - -echo "Ok, now run make, then make install to install into $prefix" diff --git a/tests/test1.7z b/tests/test1.7z Binary files differdeleted file mode 100644 index 38a4c53ac..000000000 --- a/tests/test1.7z +++ /dev/null diff --git a/tests/test2.7z b/tests/test2.7z Binary files differdeleted file mode 100644 index 99d199695..000000000 --- a/tests/test2.7z +++ /dev/null |