mirror of
https://github.com/QuasarApp/installer-framework.git
synced 2025-05-18 15:59: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);
|
||||
}
|
||||
|
||||
void EnvironmentVariableTest::testNonPersistentNonSystem() {
|
||||
void EnvironmentVariableTest::testNonPersistentNonSystem()
|
||||
{
|
||||
#ifndef Q_OS_WIN
|
||||
QSKIP("This operation only works on Windows",SkipSingle);
|
||||
#endif
|
||||
|
@ -30,14 +30,16 @@
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
class EnvironmentVariableTest : public QObject {
|
||||
class EnvironmentVariableTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EnvironmentVariableTest();
|
||||
|
||||
private Q_SLOTS:
|
||||
void testPersistentNonSystem();
|
||||
void testNonPersistentNonSystem();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // EXTRACTARCHIVEOPERATIONTEST_H
|
||||
|
@ -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<QString> 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)
|
||||
|
@ -30,17 +30,21 @@
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
class ExtractArchiveOperationTest : public QObject {
|
||||
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& );
|
||||
void init(const QString &);
|
||||
void cleanup(const QString &);
|
||||
};
|
||||
|
||||
#endif // EXTRACTARCHIVEOPERATIONTEST_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user