Skip to content

Commit

Permalink
Replace Q_ASSERT with QVERIFY in tests
Browse files Browse the repository at this point in the history
Q_ASSERT's are only evaluated in debug mode. However, tests should trigger in debug or release mode.
  • Loading branch information
m-kuhn committed Dec 27, 2017
1 parent e7e37ef commit e552b9b
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion tests/src/app/testqgsattributetable.cpp
Expand Up @@ -252,7 +252,7 @@ void TestQgsAttributeTable::testRegression15974()
QgsFeature f1( shpLayer->dataProvider()->fields(), 1 );
QgsGeometry geom;
geom = QgsGeometry().fromWkt( QStringLiteral( "polygon((0 0, 0 1, 1 1, 1 0, 0 0))" ) );
Q_ASSERT( geom.isGeosValid() );
QVERIFY( geom.isGeosValid() );
f1.setGeometry( geom );
QgsFeature f2( shpLayer->dataProvider()->fields(), 2 );
f2.setGeometry( geom );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testmaprendererjob.cpp
Expand Up @@ -50,7 +50,7 @@ class TestQgsMapRendererJob : public QObject
static QString _loadLayer( QString path )
{
QgsMapLayer *layer = new QgsVectorLayer( path, "testlayer", "ogr" );
Q_ASSERT( layer->isValid() );
QVERIFY( layer->isValid() );
QgsProject::instance()->addMapLayer( layer );
return layer->id();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/src/core/testqgsdxfexport.cpp
Expand Up @@ -73,15 +73,15 @@ void TestQgsDxfExport::init()
{
QString filename = QStringLiteral( TEST_DATA_DIR ) + "/points.shp";
mPointLayer = new QgsVectorLayer( filename, QStringLiteral( "points" ), QStringLiteral( "ogr" ) );
Q_ASSERT( mPointLayer->isValid() );
QVERIFY( mPointLayer->isValid() );
QgsProject::instance()->addMapLayer( mPointLayer );
filename = QStringLiteral( TEST_DATA_DIR ) + "/lines.shp";
mLineLayer = new QgsVectorLayer( filename, QStringLiteral( "lines" ), QStringLiteral( "ogr" ) );
Q_ASSERT( mLineLayer->isValid() );
QVERIFY( mLineLayer->isValid() );
QgsProject::instance()->addMapLayer( mLineLayer );
filename = QStringLiteral( TEST_DATA_DIR ) + "/polys.shp";
mPolygonLayer = new QgsVectorLayer( filename, QStringLiteral( "polygons" ), QStringLiteral( "ogr" ) );
Q_ASSERT( mPolygonLayer->isValid() );
QVERIFY( mPolygonLayer->isValid() );
QgsProject::instance()->addMapLayer( mPolygonLayer );
}

Expand Down
8 changes: 4 additions & 4 deletions tests/src/core/testqgsexpressioncontext.cpp
Expand Up @@ -533,13 +533,13 @@ void TestQgsExpressionContext::takeScopes()
auto scopes = context.takeScopes();

QCOMPARE( scopes.length(), 2 );
Q_ASSERT( scopes.at( 0 )->hasVariable( "test_global" ) );
Q_ASSERT( scopes.at( 1 )->hasVariable( "test_project" ) );
QVERIFY( scopes.at( 0 )->hasVariable( "test_global" ) );
QVERIFY( scopes.at( 1 )->hasVariable( "test_project" ) );

qDeleteAll( scopes );

Q_ASSERT( !context.variable( "test_global" ).isValid() );
Q_ASSERT( !context.variable( "test_project" ).isValid() );
QVERIFY( !context.variable( "test_global" ).isValid() );
QVERIFY( !context.variable( "test_project" ).isValid() );
}

void TestQgsExpressionContext::globalScope()
Expand Down
6 changes: 3 additions & 3 deletions tests/src/core/testqgslabelingengine.cpp
Expand Up @@ -86,7 +86,7 @@ void TestQgsLabelingEngine::init()
{
QString filename = QStringLiteral( TEST_DATA_DIR ) + "/points.shp";
vl = new QgsVectorLayer( filename, QStringLiteral( "points" ), QStringLiteral( "ogr" ) );
Q_ASSERT( vl->isValid() );
QVERIFY( vl->isValid() );
QgsProject::instance()->addMapLayer( vl );
}

Expand Down Expand Up @@ -179,7 +179,7 @@ void TestQgsLabelingEngine::testDiagrams()

bool res;
vl->loadNamedStyle( QStringLiteral( TEST_DATA_DIR ) + "/points_diagrams.qml", res );
Q_ASSERT( res );
QVERIFY( res );

QgsLabelingEngine engine;
engine.setMapSettings( mapSettings );
Expand Down Expand Up @@ -353,7 +353,7 @@ void TestQgsLabelingEngine::zOrder()
//add a second layer
QString filename = QStringLiteral( TEST_DATA_DIR ) + "/points.shp";
QgsVectorLayer *vl2 = new QgsVectorLayer( filename, QStringLiteral( "points" ), QStringLiteral( "ogr" ) );
Q_ASSERT( vl2->isValid() );
QVERIFY( vl2->isValid() );
QgsProject::instance()->addMapLayer( vl2 );

QgsPalLayerSettings pls2( pls1 );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgstaskmanager.cpp
Expand Up @@ -83,7 +83,7 @@ class TestTerminationTask : public TestTask
~TestTerminationTask() override
{
//make sure task has been terminated by manager prior to deletion
Q_ASSERT( status() == QgsTask::Terminated );
QVERIFY( status() == QgsTask::Terminated );
}

protected:
Expand Down Expand Up @@ -167,7 +167,7 @@ class FinishTask : public QgsTask

void finished( bool result ) override
{
Q_ASSERT( QApplication::instance()->thread() == QThread::currentThread() );
QVERIFY( QApplication::instance()->thread() == QThread::currentThread() );
*resultObtained = result;
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgstracer.cpp
Expand Up @@ -338,7 +338,7 @@ void TestQgsTracer::testCurved()

QgsPolylineXY points1 = tracer.findShortestPath( QgsPointXY( 0, 0 ), QgsPointXY( 10, 10 ) );

QVERIFY( points1.count() != 0 );
QVERIFY( !points1.isEmpty() );

QgsGeometry tmpG1 = QgsGeometry::fromPolylineXY( points1 );
double l = tmpG1.length();
Expand Down
8 changes: 4 additions & 4 deletions tests/src/gui/testqgsattributeform.cpp
Expand Up @@ -188,10 +188,10 @@ void TestQgsAttributeForm::testFieldMultiConstraints()
ww3 = qobject_cast<QgsEditorWidgetWrapper *>( form.mWidgets[3] );

// no constraint so we expect an empty label
Q_ASSERT( constraintsLabel( &form, ww0 )->text().isEmpty() );
Q_ASSERT( constraintsLabel( &form, ww1 )->text().isEmpty() );
Q_ASSERT( constraintsLabel( &form, ww2 )->text().isEmpty() );
Q_ASSERT( constraintsLabel( &form, ww3 )->text().isEmpty() );
QVERIFY( constraintsLabel( &form, ww0 )->text().isEmpty() );
QVERIFY( constraintsLabel( &form, ww1 )->text().isEmpty() );
QVERIFY( constraintsLabel( &form, ww2 )->text().isEmpty() );
QVERIFY( constraintsLabel( &form, ww3 )->text().isEmpty() );

// update constraint
layer->setConstraintExpression( 0, QStringLiteral( "col0 < (col1 * col2)" ) );
Expand Down
10 changes: 5 additions & 5 deletions tests/src/gui/testqgsfeaturelistcombobox.cpp
Expand Up @@ -99,7 +99,7 @@ void TestQgsFeatureListComboBox::testSetGetLayer()
{
std::unique_ptr<QgsFeatureListComboBox> cb( new QgsFeatureListComboBox() );

Q_ASSERT( cb->sourceLayer() == nullptr );
QVERIFY( cb->sourceLayer() == nullptr );
cb->setSourceLayer( mLayer.get() );
QCOMPARE( cb->sourceLayer(), mLayer.get() );
}
Expand All @@ -109,25 +109,25 @@ void TestQgsFeatureListComboBox::testSetGetForeignKey()
QgsFeatureListComboBox *cb = new QgsFeatureListComboBox();
// std::unique_ptr<QgsFeatureListComboBox> cb( new QgsFeatureListComboBox() );

Q_ASSERT( cb->identifierValue().isNull() );
QVERIFY( cb->identifierValue().isNull() );

cb->setSourceLayer( mLayer.get() );
cb->setDisplayExpression( "\"material\"" );
cb->lineEdit()->setText( "ro" );
emit cb->lineEdit()->textChanged( "ro" );
Q_ASSERT( cb->identifierValue().isNull() );
QVERIFY( cb->identifierValue().isNull() );

waitForLoaded( cb );

Q_ASSERT( cb->identifierValue().isNull() );
QVERIFY( cb->identifierValue().isNull() );

cb->setIdentifierValue( 20 );
QCOMPARE( cb->identifierValue(), QVariant( 20 ) );
}

void TestQgsFeatureListComboBox::testAllowNull()
{
Q_ASSERT( false );
QVERIFY( false );
// Note to self: implement this!
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/gui/testqgsfiledownloader.cpp
Expand Up @@ -133,7 +133,7 @@ void TestQgsFileDownloader::init()
mCompleted = false;
mExited = false;
mTempFile = new QTemporaryFile();
Q_ASSERT( mTempFile->open() );
QVERIFY( mTempFile->open() );
mTempFile->close();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/gui/testrenderergui.cpp
Expand Up @@ -55,8 +55,8 @@ void TestRendererGUI::loadLayers()
void TestRendererGUI::setRenderer()
{
QgsMapLayer *layer = mMapCanvas->layer( 0 );
Q_ASSERT( layer );
Q_ASSERT( layer->type() == QgsMapLayer::VectorLayer );
QVERIFY( layer );
QVERIFY( layer->type() == QgsMapLayer::VectorLayer );
QgsVectorLayer *vlayer = static_cast<QgsVectorLayer *>( layer );

QgsRendererPropertiesDialog dlg( vlayer, QgsStyle::defaultStyle() );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/providers/grass/testqgsgrassprovider.cpp
Expand Up @@ -1209,7 +1209,7 @@ void TestQgsGrassProvider::edit()
grassLayer->startEditing();
grassProvider->startEditing( grassLayer );

Q_ASSERT( expectedLayer );
QVERIFY( expectedLayer );
expectedLayer->startEditing();
}

Expand Down Expand Up @@ -1577,7 +1577,7 @@ bool TestQgsGrassProvider::compare( QMap<QString, QgsVectorLayer *> layers, bool
Q_FOREACH ( const QString &grassUri, layers.keys() )
{
QgsVectorLayer *layer = layers.value( grassUri );
Q_ASSERT( layer );
QVERIFY( layer );
if ( !compare( grassUri, layer, ok ) )
{
reportRow( "comparison failed: " + grassUri );
Expand Down

0 comments on commit e552b9b

Please sign in to comment.