mirror of
https://github.com/QuasarApp/installer-framework.git
synced 2025-05-19 00:09:33 +00:00
Fix style in tests.
Change-Id: Icebeec79fe25a65e71a8887ebf0f5ca751388cd1 Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
This commit is contained in:
parent
7d5c4a7211
commit
7efffd39ff
@ -77,7 +77,8 @@ void EnvironmentVariableTest::testPersistentNonSystem()
|
|||||||
settings.remove(key);
|
settings.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentVariableTest::testNonPersistentNonSystem() {
|
void EnvironmentVariableTest::testNonPersistentNonSystem()
|
||||||
|
{
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
QSKIP("This operation only works on Windows",SkipSingle);
|
QSKIP("This operation only works on Windows",SkipSingle);
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,14 +30,16 @@
|
|||||||
|
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
class EnvironmentVariableTest : public QObject {
|
class EnvironmentVariableTest : public QObject
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EnvironmentVariableTest();
|
EnvironmentVariableTest();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void testPersistentNonSystem();
|
void testPersistentNonSystem();
|
||||||
void testNonPersistentNonSystem();
|
void testNonPersistentNonSystem();
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXTRACTARCHIVEOPERATIONTEST_H
|
#endif // EXTRACTARCHIVEOPERATIONTEST_H
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
** (qt-info@nokia.com).
|
** (qt-info@nokia.com).
|
||||||
**
|
**
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "extractarchiveoperationtest.h"
|
#include "extractarchiveoperationtest.h"
|
||||||
#include "extractarchiveoperation.h"
|
#include "extractarchiveoperation.h"
|
||||||
|
|
||||||
@ -47,29 +48,31 @@ ExtractArchiveOperationTest::ExtractArchiveOperationTest()
|
|||||||
QInstaller::init();
|
QInstaller::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtractArchiveOperationTest::init( const QString& outdir ) {
|
void ExtractArchiveOperationTest::init(const QString &outdir)
|
||||||
if ( QDir( outdir ).exists() ) {
|
{
|
||||||
QFAIL( "output directory already exists!" );
|
if (QDir(outdir).exists()) {
|
||||||
QVERIFY( false );
|
QFAIL("output directory already exists!");
|
||||||
|
QVERIFY(false);
|
||||||
}
|
}
|
||||||
QDir cd( QDir::current() );
|
QDir cd(QDir::current());
|
||||||
QVERIFY( cd.mkdir( outdir ) );
|
QVERIFY(cd.mkdir(outdir));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool recursiveRemove( const QString& path, QString* errorMsg ) {
|
static bool recursiveRemove(const QString &path, QString *errorMsg)
|
||||||
if ( errorMsg )
|
{
|
||||||
|
if (errorMsg)
|
||||||
errorMsg->clear();
|
errorMsg->clear();
|
||||||
if ( !QFileInfo( path ).exists() )
|
if (!QFileInfo(path).exists())
|
||||||
return true;
|
return true;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
QString msg;
|
QString msg;
|
||||||
//first, delete all non-dir files
|
//first, delete all non-dir files
|
||||||
QDirIterator it( path, QDirIterator::Subdirectories );
|
QDirIterator it(path, QDirIterator::Subdirectories);
|
||||||
while ( it.hasNext() ) {
|
while (it.hasNext()) {
|
||||||
const QString n = it.next();
|
const QString n = it.next();
|
||||||
if ( !QFileInfo( n ).isDir() ) {
|
if (!QFileInfo(n).isDir()) {
|
||||||
QFile file( n );
|
QFile file(n);
|
||||||
if ( !file.remove() ) {
|
if (!file.remove()) {
|
||||||
error = true;
|
error = true;
|
||||||
msg = file.errorString();
|
msg = file.errorString();
|
||||||
}
|
}
|
||||||
@ -77,86 +80,90 @@ static bool recursiveRemove( const QString& path, QString* errorMsg ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QStack<QString> dirs;
|
QStack<QString> dirs;
|
||||||
QDirIterator it2( path, QDirIterator::Subdirectories );
|
QDirIterator it2(path, QDirIterator::Subdirectories);
|
||||||
while ( it2.hasNext() ) {
|
while (it2.hasNext()) {
|
||||||
const QString n = it2.next();
|
const QString n = it2.next();
|
||||||
if ( !n.endsWith( QLatin1String( "/." ) ) && !n.endsWith( QLatin1String( "/.." ) ) )
|
if (!n.endsWith(QLatin1String( "/." ) ) && !n.endsWith( QLatin1String( "/.." )))
|
||||||
dirs.push( n );
|
dirs.push(n);
|
||||||
}
|
}
|
||||||
while ( !dirs.isEmpty() ) {
|
while (!dirs.isEmpty()) {
|
||||||
const QString n = dirs.top();
|
const QString n = dirs.top();
|
||||||
dirs.pop();
|
dirs.pop();
|
||||||
if ( !QDir( n ).rmdir( QDir::currentPath() + QLatin1String( "/" ) + n ) ) {
|
if (!QDir(n).rmdir(QDir::currentPath() + QLatin1String("/") + n)) {
|
||||||
error = true;
|
error = true;
|
||||||
msg = QObject::tr("Could not remove folder %1").arg( n );
|
msg = QObject::tr("Could not remove folder %1").arg(n);
|
||||||
qDebug() << msg;
|
qDebug() << msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !QDir( path ).rmdir( QDir::currentPath() + QLatin1String( "/" ) + path ) ) {
|
if (!QDir(path).rmdir(QDir::currentPath() + QLatin1String("/") + path)) {
|
||||||
error = true;
|
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;
|
*errorMsg = msg;
|
||||||
return !error;
|
return !error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtractArchiveOperationTest::cleanup( const QString& dir ) {
|
void ExtractArchiveOperationTest::cleanup(const QString &dir)
|
||||||
QDir d( dir );
|
{
|
||||||
|
QDir d(dir);
|
||||||
QString msg;
|
QString msg;
|
||||||
const bool removed = recursiveRemove( dir, &msg );
|
const bool removed = recursiveRemove(dir, &msg);
|
||||||
if ( !removed )
|
if (!removed)
|
||||||
qCritical() << msg;
|
qCritical() << msg;
|
||||||
QVERIFY( removed );
|
QVERIFY(removed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtractArchiveOperationTest::testExtraction() {
|
void ExtractArchiveOperationTest::testExtraction()
|
||||||
|
{
|
||||||
const QString outdir = QLatin1String("test-extract-out" );
|
const QString outdir = QLatin1String("test-extract-out" );
|
||||||
init( outdir );
|
init(outdir);
|
||||||
KDUpdater::Application app;
|
KDUpdater::Application app;
|
||||||
QInstaller::ExtractArchiveOperation op;
|
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();
|
const bool ok = op.performOperation();
|
||||||
if ( !ok ) {
|
if (!ok) {
|
||||||
qCritical() << "Extraction failed:" << op.errorString();
|
qCritical() << "Extraction failed:" << op.errorString();
|
||||||
QFAIL( "Extraction failed" );
|
QFAIL("Extraction failed");
|
||||||
}
|
}
|
||||||
cleanup( outdir );
|
cleanup(outdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtractArchiveOperationTest::testExtractionErrors() {
|
void ExtractArchiveOperationTest::testExtractionErrors()
|
||||||
const QString outdir = QLatin1String("test-extract-out" );
|
{
|
||||||
init( outdir );
|
const QString outdir = QLatin1String("test-extract-out");
|
||||||
|
init(outdir);
|
||||||
KDUpdater::Application app;
|
KDUpdater::Application app;
|
||||||
QInstaller::ExtractArchiveOperation op;
|
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();
|
const bool ok = op.performOperation();
|
||||||
if ( !ok ) {
|
if (!ok) {
|
||||||
qCritical() << "Extraction failed:" << op.errorString();
|
qCritical() << "Extraction failed:" << op.errorString();
|
||||||
QFAIL( "Extraction failed" );
|
QFAIL("Extraction failed");
|
||||||
}
|
}
|
||||||
cleanup( outdir );
|
cleanup(outdir);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtractArchiveOperationTest::testInvalidArchive() {
|
void ExtractArchiveOperationTest::testInvalidArchive()
|
||||||
const QString outdir = QLatin1String("test-extract-out" );
|
{
|
||||||
init( outdir );
|
const QString outdir = QLatin1String("test-extract-out");
|
||||||
|
init(outdir);
|
||||||
KDUpdater::Application app;
|
KDUpdater::Application app;
|
||||||
QInstaller::ExtractArchiveOperation op;
|
QInstaller::ExtractArchiveOperation op;
|
||||||
op.setArguments( QStringList() << QLatin1String("test-noarchive.7z") << outdir );
|
op.setArguments(QStringList() << QLatin1String("test-noarchive.7z") << outdir);
|
||||||
const bool ok = op.performOperation();
|
const bool ok = op.performOperation();
|
||||||
if ( ok ) {
|
if (ok) {
|
||||||
qCritical() << "ExtractArchiveOperation does not report error on extracting invalid archive";
|
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();
|
const QString str = op.errorString();
|
||||||
qDebug() << str;
|
qDebug() << str;
|
||||||
QVERIFY( !str.isEmpty() );
|
QVERIFY(!str.isEmpty());
|
||||||
cleanup( outdir );
|
cleanup(outdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(ExtractArchiveOperationTest)
|
QTEST_MAIN(ExtractArchiveOperationTest)
|
||||||
|
@ -30,17 +30,21 @@
|
|||||||
|
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
class ExtractArchiveOperationTest : public QObject {
|
class ExtractArchiveOperationTest : public QObject
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExtractArchiveOperationTest();
|
ExtractArchiveOperationTest();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void testExtraction();
|
void testExtraction();
|
||||||
void testInvalidArchive();
|
void testInvalidArchive();
|
||||||
void testExtractionErrors();
|
void testExtractionErrors();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init( const QString& );
|
void init(const QString &);
|
||||||
void cleanup( const QString& );
|
void cleanup(const QString &);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXTRACTARCHIVEOPERATIONTEST_H
|
#endif // EXTRACTARCHIVEOPERATIONTEST_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user