Skip to content

Commit

Permalink
Fix coverity warnings in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 3, 2018
1 parent d164f8f commit 09241ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions tests/src/analysis/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
QCOMPARE( sinkParam->defaultFileExtension(), QStringLiteral( "shp" ) ); // before alg is accessible
QVERIFY( !sinkParam->algorithm() );
QVERIFY( !sinkParam->provider() );
addParameter( sinkParam );
QVERIFY( addParameter( sinkParam ) );
QCOMPARE( sinkParam->defaultFileExtension(), QStringLiteral( "shp" ) );
QCOMPARE( sinkParam->algorithm(), this );
QVERIFY( !sinkParam->provider() );

// default raster format extension
QgsProcessingParameterRasterDestination *rasterParam = new QgsProcessingParameterRasterDestination( "raster" );
QCOMPARE( rasterParam->defaultFileExtension(), QStringLiteral( "tif" ) ); // before alg is accessible
addParameter( rasterParam );
QVERIFY( addParameter( rasterParam ) );
QCOMPARE( rasterParam->defaultFileExtension(), QStringLiteral( "tif" ) );

// should allow parameters with same name but different case (required for grass provider)
Expand All @@ -165,15 +165,15 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
QCOMPARE( sinkParam->defaultFileExtension(), QStringLiteral( "shp" ) ); // before alg is accessible
QVERIFY( !sinkParam->algorithm() );
QVERIFY( !sinkParam->provider() );
addParameter( sinkParam );
QVERIFY( addParameter( sinkParam ) );
QCOMPARE( sinkParam->defaultFileExtension(), QStringLiteral( "xshp" ) );
QCOMPARE( sinkParam->algorithm(), this );
QCOMPARE( sinkParam->provider(), provider() );

// default raster format extension
QgsProcessingParameterRasterDestination *rasterParam = new QgsProcessingParameterRasterDestination( "raster2" );
QCOMPARE( rasterParam->defaultFileExtension(), QStringLiteral( "tif" ) ); // before alg is accessible
addParameter( rasterParam );
QVERIFY( addParameter( rasterParam ) );
QCOMPARE( rasterParam->defaultFileExtension(), QStringLiteral( "pcx" ) );
}

Expand Down Expand Up @@ -1096,7 +1096,7 @@ void TestQgsProcessing::algorithm()
QVERIFY( !p->algorithms().empty() );

QgsProcessingRegistry r;
r.addProvider( p );
QVERIFY( r.addProvider( p ) );
QCOMPARE( r.algorithms().size(), 2 );
QVERIFY( r.algorithms().contains( p->algorithm( "alg1" ) ) );
QVERIFY( r.algorithms().contains( p->algorithm( "alg2" ) ) );
Expand Down Expand Up @@ -1134,7 +1134,7 @@ void TestQgsProcessing::algorithm()
// test that adding a provider to the registry automatically refreshes algorithms (via load)
DummyProvider *p3 = new DummyProvider( "p3" );
QVERIFY( p3->algorithms().isEmpty() );
r.addProvider( p3 );
QVERIFY( r.addProvider( p3 ) );
QCOMPARE( p3->algorithms().size(), 2 );
}

Expand Down
12 changes: 6 additions & 6 deletions tests/src/core/testqgscompositionconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ void TestQgsCompositionConverter::isCompositionTemplate()
QString templatePath( QStringLiteral( TEST_DATA_DIR ) + "/layouts/2x_template.qpt" );
QDomDocument doc( "mydocument" );
QFile file( templatePath );
file.open( QIODevice::ReadOnly );
doc.setContent( &file );
QVERIFY( file.open( QIODevice::ReadOnly ) );
QVERIFY( doc.setContent( &file ) );
file.close();

QVERIFY( QgsCompositionConverter::isCompositionTemplate( doc ) );
Expand All @@ -579,8 +579,8 @@ void TestQgsCompositionConverter::convertCompositionTemplate()
QString templatePath( QStringLiteral( TEST_DATA_DIR ) + "/layouts/2x_template.qpt" );
QDomDocument doc( "mydocument" );
QFile file( templatePath );
file.open( QIODevice::ReadOnly );
doc.setContent( &file );
QVERIFY( file.open( QIODevice::ReadOnly ) );
QVERIFY( doc.setContent( &file ) );
file.close();

QgsProject project;
Expand Down Expand Up @@ -711,8 +711,8 @@ QDomElement TestQgsCompositionConverter::loadComposer( const QString name )
QString templatePath( QStringLiteral( TEST_DATA_DIR ) + "/layouts/" + name );
QDomDocument doc( "mydocument" );
QFile file( templatePath );
file.open( QIODevice::ReadOnly );
doc.setContent( &file );
Q_ASSERT( file.open( QIODevice::ReadOnly ) );
Q_ASSERT( doc.setContent( &file ) );
file.close();
QDomNodeList nodes( doc.elementsByTagName( QStringLiteral( "Composer" ) ) );
if ( nodes.length() > 0 )
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void TestQgsProject::testPathResolver()
QgsPathResolver tempRel( tmpName );
QFileInfo fi( tmpName );
QFile testFile( fi.path() + QStringLiteral( "/file1.txt" ) );
testFile.open( QIODevice::WriteOnly | QIODevice::Text );
QVERIFY( testFile.open( QIODevice::WriteOnly | QIODevice::Text ) );
testFile.close();
QVERIFY( QFile::exists( fi.path() + QStringLiteral( "/file1.txt" ) ) );
QCOMPARE( tempRel.readPath( "file1.txt" ), fi.path() + QStringLiteral( "/file1.txt" ) );
Expand Down

0 comments on commit 09241ea

Please sign in to comment.