From 678d12092c661c6437e71833235ee854f69d36cf Mon Sep 17 00:00:00 2001 From: kh1 Date: Tue, 30 Apr 2013 13:34:59 +0200 Subject: Rewrote extract operation test in preparation for lzma update. Change-Id: I719aaeaad3c213b3767c4c6ecd40b89a35bc81ca Reviewed-by: Tim Jenssen --- .../installer/extractarchiveoperationtest/data.qrc | 6 + .../extractarchiveoperationtest/data/invalid.7z | Bin 0 -> 25600 bytes .../extractarchiveoperationtest/data/valid.7z | Bin 0 -> 950 bytes .../extractarchiveoperationtest.pro | 7 + .../tst_extractarchiveoperationtest.cpp | 101 +++++++++++ tests/auto/installer/installer.pro | 3 +- .../extractarchiveoperationtest.cpp | 177 ------------------- .../extractarchiveoperationtest.h | 66 ------- .../extractarchiveoperationtest.pro | 15 -- tests/test-noarchive.7z | 190 --------------------- tests/test1.7z | Bin 282 -> 0 bytes tests/test2.7z | Bin 629 -> 0 bytes 12 files changed, 116 insertions(+), 449 deletions(-) create mode 100644 tests/auto/installer/extractarchiveoperationtest/data.qrc create mode 100644 tests/auto/installer/extractarchiveoperationtest/data/invalid.7z create mode 100644 tests/auto/installer/extractarchiveoperationtest/data/valid.7z create mode 100644 tests/auto/installer/extractarchiveoperationtest/extractarchiveoperationtest.pro create mode 100644 tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp delete mode 100644 tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp delete mode 100644 tests/extractarchiveoperationtest/extractarchiveoperationtest.h delete mode 100644 tests/extractarchiveoperationtest/extractarchiveoperationtest.pro delete mode 100644 tests/test-noarchive.7z delete mode 100644 tests/test1.7z delete mode 100644 tests/test2.7z (limited to 'tests') 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 @@ + + + data/valid.7z + data/invalid.7z + + diff --git a/tests/auto/installer/extractarchiveoperationtest/data/invalid.7z b/tests/auto/installer/extractarchiveoperationtest/data/invalid.7z new file mode 100644 index 000000000..bcf81250e Binary files /dev/null and b/tests/auto/installer/extractarchiveoperationtest/data/invalid.7z differ diff --git a/tests/auto/installer/extractarchiveoperationtest/data/valid.7z b/tests/auto/installer/extractarchiveoperationtest/data/valid.7z new file mode 100644 index 000000000..e583bdf99 Binary files /dev/null and b/tests/auto/installer/extractarchiveoperationtest/data/valid.7z differ 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/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp b/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp new file mode 100644 index 000000000..eb3b0378e --- /dev/null +++ b/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp @@ -0,0 +1,101 @@ +/************************************************************************** +** +** 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. +** +** $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 "init.h" +#include "extractarchiveoperation.h" + +#include +#include +#include + +using namespace KDUpdater; +using namespace QInstaller; + +class tst_extractarchiveoperationtest : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase() + { + QInstaller::init(); + } + + void testMissingArguments() + { + ExtractArchiveOperation op; + + 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")); + } +}; + +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 - -#include -#include -#include -#include - -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 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.h b/tests/extractarchiveoperationtest/extractarchiveoperationtest.h deleted file mode 100644 index 4dad9d00a..000000000 --- a/tests/extractarchiveoperationtest/extractarchiveoperationtest.h +++ /dev/null @@ -1,66 +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$ -** -**************************************************************************/ - -#ifndef EXTRACTIONARCHIVEOPERATIONTEST_H -#define EXTRACTIONARCHIVEOPERATIONTEST_H - -#include - -#include - -class ExtractArchiveOperationTest : public QObject -{ - Q_OBJECT - -public: - ExtractArchiveOperationTest(); - -private Q_SLOTS: - void testExtraction(); - void testInvalidArchive(); - void testExtractionErrors(); - -private: - void init(const QString &); - void cleanup(const QString &); -}; - -#endif // EXTRACTARCHIVEOPERATIONTEST_H 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 <&2 -where options include: - -EOF -if [ "$INSTALLATION_SUPPORTED" = "true" ]; then - cat <&2 - -prefix - install $Product into -EOF -fi -cat <&2 - - -release / -debug - build in debug/release mode -EOF -if [ "$STATIC_BUILD_SUPPORTED" = "true" ]; then - cat <&2 - - -static / -shared - build static/shared libraries -EOF -fi -cat <&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 <&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 deleted file mode 100644 index 38a4c53ac..000000000 Binary files a/tests/test1.7z and /dev/null differ diff --git a/tests/test2.7z b/tests/test2.7z deleted file mode 100644 index 99d199695..000000000 Binary files a/tests/test2.7z and /dev/null differ -- cgit v1.2.3