From 7efffd39ff3369d788a710819882b936a194956c Mon Sep 17 00:00:00 2001 From: hjk Date: Sat, 19 Nov 2011 00:09:53 +0100 Subject: Fix style in tests. Change-Id: Icebeec79fe25a65e71a8887ebf0f5ca751388cd1 Reviewed-by: Tim Jenssen --- .../extractarchiveoperationtest.cpp | 109 +++++++++++---------- 1 file changed, 58 insertions(+), 51 deletions(-) (limited to 'installerbuilder/tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp') diff --git a/installerbuilder/tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp b/installerbuilder/tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp index 475297e34..6adb74a20 100644 --- a/installerbuilder/tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp +++ b/installerbuilder/tests/extractarchiveoperationtest/extractarchiveoperationtest.cpp @@ -30,6 +30,7 @@ ** (qt-info@nokia.com). ** **************************************************************************/ + #include "extractarchiveoperationtest.h" #include "extractarchiveoperation.h" @@ -47,29 +48,31 @@ ExtractArchiveOperationTest::ExtractArchiveOperationTest() QInstaller::init(); } -void ExtractArchiveOperationTest::init( const QString& outdir ) { - if ( QDir( outdir ).exists() ) { - QFAIL( "output directory already exists!" ); - QVERIFY( false ); +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 ) ); + QDir cd(QDir::current()); + QVERIFY(cd.mkdir(outdir)); } -static bool recursiveRemove( const QString& path, QString* errorMsg ) { - if ( errorMsg ) +static bool recursiveRemove(const QString &path, QString *errorMsg) +{ + if (errorMsg) errorMsg->clear(); - if ( !QFileInfo( path ).exists() ) + 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() ) { + QDirIterator it(path, QDirIterator::Subdirectories); + while (it.hasNext()) { const QString n = it.next(); - if ( !QFileInfo( n ).isDir() ) { - QFile file( n ); - if ( !file.remove() ) { + if (!QFileInfo(n).isDir()) { + QFile file(n); + if (!file.remove()) { error = true; msg = file.errorString(); } @@ -77,86 +80,90 @@ static bool recursiveRemove( const QString& path, QString* errorMsg ) { } QStack dirs; - QDirIterator it2( path, QDirIterator::Subdirectories ); - while ( it2.hasNext() ) { + QDirIterator it2(path, QDirIterator::Subdirectories); + while (it2.hasNext()) { const QString n = it2.next(); - if ( !n.endsWith( QLatin1String( "/." ) ) && !n.endsWith( QLatin1String( "/.." ) ) ) - dirs.push( n ); + if (!n.endsWith(QLatin1String( "/." ) ) && !n.endsWith( QLatin1String( "/.." ))) + dirs.push(n); } - while ( !dirs.isEmpty() ) { + while (!dirs.isEmpty()) { const QString n = dirs.top(); dirs.pop(); - if ( !QDir( n ).rmdir( QDir::currentPath() + QLatin1String( "/" ) + n ) ) { + if (!QDir(n).rmdir(QDir::currentPath() + QLatin1String("/") + n)) { error = true; - msg = QObject::tr("Could not remove folder %1").arg( n ); + msg = QObject::tr("Could not remove folder %1").arg(n); qDebug() << msg; } } - if ( !QDir( path ).rmdir( QDir::currentPath() + QLatin1String( "/" ) + path ) ) { + if (!QDir(path).rmdir(QDir::currentPath() + QLatin1String("/") + path)) { error = true; - msg = QObject::tr("Could not remove folder %1: Unknown error").arg( path ); + msg = QObject::tr("Could not remove folder %1: Unknown error").arg(path); } - if ( errorMsg ) + if (errorMsg) *errorMsg = msg; return !error; } -void ExtractArchiveOperationTest::cleanup( const QString& dir ) { - QDir d( dir ); +void ExtractArchiveOperationTest::cleanup(const QString &dir) +{ + QDir d(dir); QString msg; - const bool removed = recursiveRemove( dir, &msg ); - if ( !removed ) + const bool removed = recursiveRemove(dir, &msg); + if (!removed) qCritical() << msg; - QVERIFY( removed ); + QVERIFY(removed); } -void ExtractArchiveOperationTest::testExtraction() { +void ExtractArchiveOperationTest::testExtraction() +{ const QString outdir = QLatin1String("test-extract-out" ); - init( outdir ); + init(outdir); KDUpdater::Application app; QInstaller::ExtractArchiveOperation op; - op.setArguments( QStringList() << QLatin1String("qt-bin-test.7z") << outdir ); + op.setArguments(QStringList() << QLatin1String("qt-bin-test.7z") << outdir); const bool ok = op.performOperation(); - if ( !ok ) { + if (!ok) { qCritical() << "Extraction failed:" << op.errorString(); - QFAIL( "Extraction failed" ); + QFAIL("Extraction failed"); } - cleanup( outdir ); + cleanup(outdir); } -void ExtractArchiveOperationTest::testExtractionErrors() { - const QString outdir = QLatin1String("test-extract-out" ); - init( 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 ); + op.setArguments(QStringList() << QLatin1String("qt-bin-test.7z") << outdir); const bool ok = op.performOperation(); - if ( !ok ) { + if (!ok) { qCritical() << "Extraction failed:" << op.errorString(); - QFAIL( "Extraction failed" ); + QFAIL("Extraction failed"); } - cleanup( outdir ); + cleanup(outdir); } -void ExtractArchiveOperationTest::testInvalidArchive() { - const QString outdir = QLatin1String("test-extract-out" ); - init( 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 ); + op.setArguments(QStringList() << QLatin1String("test-noarchive.7z") << outdir); const bool ok = op.performOperation(); - if ( ok ) { + if (ok) { qCritical() << "ExtractArchiveOperation does not report error on extracting invalid archive"; - QFAIL( "Extraction failed" ); + QFAIL("Extraction failed"); } - QVERIFY( op.error() != QInstaller::ExtractArchiveOperation::NoError ); + QVERIFY(op.error() != QInstaller::ExtractArchiveOperation::NoError); const QString str = op.errorString(); qDebug() << str; - QVERIFY( !str.isEmpty() ); - cleanup( outdir ); + QVERIFY(!str.isEmpty()); + cleanup(outdir); } QTEST_MAIN(ExtractArchiveOperationTest) -- cgit v1.2.3