Skip to content

Commit

Permalink
[GRASS] cleanup tmp files after test
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Sep 21, 2015
1 parent 5c69400 commit 22313dc
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions tests/src/providers/grass/testqgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TestQgsGrassProvider: public QObject
// compare with tolerance
bool compare( double expected, double got, bool& ok );
bool copyRecursively( const QString &srcFilePath, const QString &tgtFilePath, QString *error );
bool removeRecursively( const QString &filePath, QString *error = 0 );
bool copyLocation( QString& tmpGisdbase );
bool createTmpLocation( QString& tmpGisdbase, QString& tmpLocation, QString& tmpMapset );
QString mGisdbase;
Expand Down Expand Up @@ -296,6 +297,7 @@ void TestQgsGrassProvider::mapsets()
}
}
}
removeRecursively( tmpGisdbase );
GVERIFY( ok );
}

Expand Down Expand Up @@ -455,7 +457,7 @@ void TestQgsGrassProvider::info()
ok = false;
}
}

removeRecursively( tmpGisdbase );
GVERIFY( ok );
}

Expand Down Expand Up @@ -505,6 +507,49 @@ bool TestQgsGrassProvider::copyRecursively( const QString &srcFilePath, const QS
return true;
}

// From Qt creator
bool TestQgsGrassProvider::removeRecursively( const QString &filePath, QString *error )
{
QFileInfo fileInfo( filePath );
if ( !fileInfo.exists() )
return true;
QFile::setPermissions( filePath, fileInfo.permissions() | QFile::WriteUser );
if ( fileInfo.isDir() )
{
QDir dir( filePath );
QStringList fileNames = dir.entryList( QDir::Files | QDir::Hidden
| QDir::System | QDir::Dirs | QDir::NoDotAndDotDot );
foreach ( const QString &fileName, fileNames )
{
if ( !removeRecursively( filePath + QLatin1Char( '/' ) + fileName, error ) )
return false;
}
dir.cdUp();
if ( !dir.rmdir( fileInfo.fileName() ) )
{
if ( error )
{
*error = QCoreApplication::translate( "Utils::FileUtils", "Failed to remove directory '%1'." )
.arg( QDir::toNativeSeparators( filePath ) );
}
return false;
}
}
else
{
if ( !QFile::remove( filePath ) )
{
if ( error )
{
*error = QCoreApplication::translate( "Utils::FileUtils", "Failed to remove file '%1'." )
.arg( QDir::toNativeSeparators( filePath ) );
}
return false;
}
}
return true;
}

// copy test location to temporary
bool TestQgsGrassProvider::copyLocation( QString& tmpGisdbase )
{
Expand Down Expand Up @@ -627,7 +672,7 @@ void TestQgsGrassProvider::rasterImport()
}
delete import;
}

removeRecursively( tmpGisdbase );
GVERIFY( ok );
}

Expand Down Expand Up @@ -683,6 +728,7 @@ void TestQgsGrassProvider::vectorImport()
QStringList layers = QgsGrass::vectorLayers( tmpGisdbase, tmpLocation, tmpMapset, name );
reportRow( "created layers: " + layers.join( "," ) );
}
removeRecursively( tmpGisdbase );
GVERIFY( ok );
}

Expand Down

0 comments on commit 22313dc

Please sign in to comment.