Skip to content

Commit e552b9b

Browse files
committed
Replace Q_ASSERT with QVERIFY in tests
Q_ASSERT's are only evaluated in debug mode. However, tests should trigger in debug or release mode.
1 parent e7e37ef commit e552b9b

12 files changed

+29
-29
lines changed

tests/src/app/testqgsattributetable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void TestQgsAttributeTable::testRegression15974()
252252
QgsFeature f1( shpLayer->dataProvider()->fields(), 1 );
253253
QgsGeometry geom;
254254
geom = QgsGeometry().fromWkt( QStringLiteral( "polygon((0 0, 0 1, 1 1, 1 0, 0 0))" ) );
255-
Q_ASSERT( geom.isGeosValid() );
255+
QVERIFY( geom.isGeosValid() );
256256
f1.setGeometry( geom );
257257
QgsFeature f2( shpLayer->dataProvider()->fields(), 2 );
258258
f2.setGeometry( geom );

tests/src/core/testmaprendererjob.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TestQgsMapRendererJob : public QObject
5050
static QString _loadLayer( QString path )
5151
{
5252
QgsMapLayer *layer = new QgsVectorLayer( path, "testlayer", "ogr" );
53-
Q_ASSERT( layer->isValid() );
53+
QVERIFY( layer->isValid() );
5454
QgsProject::instance()->addMapLayer( layer );
5555
return layer->id();
5656
}

tests/src/core/testqgsdxfexport.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ void TestQgsDxfExport::init()
7373
{
7474
QString filename = QStringLiteral( TEST_DATA_DIR ) + "/points.shp";
7575
mPointLayer = new QgsVectorLayer( filename, QStringLiteral( "points" ), QStringLiteral( "ogr" ) );
76-
Q_ASSERT( mPointLayer->isValid() );
76+
QVERIFY( mPointLayer->isValid() );
7777
QgsProject::instance()->addMapLayer( mPointLayer );
7878
filename = QStringLiteral( TEST_DATA_DIR ) + "/lines.shp";
7979
mLineLayer = new QgsVectorLayer( filename, QStringLiteral( "lines" ), QStringLiteral( "ogr" ) );
80-
Q_ASSERT( mLineLayer->isValid() );
80+
QVERIFY( mLineLayer->isValid() );
8181
QgsProject::instance()->addMapLayer( mLineLayer );
8282
filename = QStringLiteral( TEST_DATA_DIR ) + "/polys.shp";
8383
mPolygonLayer = new QgsVectorLayer( filename, QStringLiteral( "polygons" ), QStringLiteral( "ogr" ) );
84-
Q_ASSERT( mPolygonLayer->isValid() );
84+
QVERIFY( mPolygonLayer->isValid() );
8585
QgsProject::instance()->addMapLayer( mPolygonLayer );
8686
}
8787

tests/src/core/testqgsexpressioncontext.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,13 @@ void TestQgsExpressionContext::takeScopes()
533533
auto scopes = context.takeScopes();
534534

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

539539
qDeleteAll( scopes );
540540

541-
Q_ASSERT( !context.variable( "test_global" ).isValid() );
542-
Q_ASSERT( !context.variable( "test_project" ).isValid() );
541+
QVERIFY( !context.variable( "test_global" ).isValid() );
542+
QVERIFY( !context.variable( "test_project" ).isValid() );
543543
}
544544

545545
void TestQgsExpressionContext::globalScope()

tests/src/core/testqgslabelingengine.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void TestQgsLabelingEngine::init()
8686
{
8787
QString filename = QStringLiteral( TEST_DATA_DIR ) + "/points.shp";
8888
vl = new QgsVectorLayer( filename, QStringLiteral( "points" ), QStringLiteral( "ogr" ) );
89-
Q_ASSERT( vl->isValid() );
89+
QVERIFY( vl->isValid() );
9090
QgsProject::instance()->addMapLayer( vl );
9191
}
9292

@@ -179,7 +179,7 @@ void TestQgsLabelingEngine::testDiagrams()
179179

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

184184
QgsLabelingEngine engine;
185185
engine.setMapSettings( mapSettings );
@@ -353,7 +353,7 @@ void TestQgsLabelingEngine::zOrder()
353353
//add a second layer
354354
QString filename = QStringLiteral( TEST_DATA_DIR ) + "/points.shp";
355355
QgsVectorLayer *vl2 = new QgsVectorLayer( filename, QStringLiteral( "points" ), QStringLiteral( "ogr" ) );
356-
Q_ASSERT( vl2->isValid() );
356+
QVERIFY( vl2->isValid() );
357357
QgsProject::instance()->addMapLayer( vl2 );
358358

359359
QgsPalLayerSettings pls2( pls1 );

tests/src/core/testqgstaskmanager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class TestTerminationTask : public TestTask
8383
~TestTerminationTask() override
8484
{
8585
//make sure task has been terminated by manager prior to deletion
86-
Q_ASSERT( status() == QgsTask::Terminated );
86+
QVERIFY( status() == QgsTask::Terminated );
8787
}
8888

8989
protected:
@@ -167,7 +167,7 @@ class FinishTask : public QgsTask
167167

168168
void finished( bool result ) override
169169
{
170-
Q_ASSERT( QApplication::instance()->thread() == QThread::currentThread() );
170+
QVERIFY( QApplication::instance()->thread() == QThread::currentThread() );
171171
*resultObtained = result;
172172
}
173173
};

tests/src/core/testqgstracer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void TestQgsTracer::testCurved()
338338

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

341-
QVERIFY( points1.count() != 0 );
341+
QVERIFY( !points1.isEmpty() );
342342

343343
QgsGeometry tmpG1 = QgsGeometry::fromPolylineXY( points1 );
344344
double l = tmpG1.length();

tests/src/gui/testqgsattributeform.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ void TestQgsAttributeForm::testFieldMultiConstraints()
188188
ww3 = qobject_cast<QgsEditorWidgetWrapper *>( form.mWidgets[3] );
189189

190190
// no constraint so we expect an empty label
191-
Q_ASSERT( constraintsLabel( &form, ww0 )->text().isEmpty() );
192-
Q_ASSERT( constraintsLabel( &form, ww1 )->text().isEmpty() );
193-
Q_ASSERT( constraintsLabel( &form, ww2 )->text().isEmpty() );
194-
Q_ASSERT( constraintsLabel( &form, ww3 )->text().isEmpty() );
191+
QVERIFY( constraintsLabel( &form, ww0 )->text().isEmpty() );
192+
QVERIFY( constraintsLabel( &form, ww1 )->text().isEmpty() );
193+
QVERIFY( constraintsLabel( &form, ww2 )->text().isEmpty() );
194+
QVERIFY( constraintsLabel( &form, ww3 )->text().isEmpty() );
195195

196196
// update constraint
197197
layer->setConstraintExpression( 0, QStringLiteral( "col0 < (col1 * col2)" ) );

tests/src/gui/testqgsfeaturelistcombobox.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void TestQgsFeatureListComboBox::testSetGetLayer()
9999
{
100100
std::unique_ptr<QgsFeatureListComboBox> cb( new QgsFeatureListComboBox() );
101101

102-
Q_ASSERT( cb->sourceLayer() == nullptr );
102+
QVERIFY( cb->sourceLayer() == nullptr );
103103
cb->setSourceLayer( mLayer.get() );
104104
QCOMPARE( cb->sourceLayer(), mLayer.get() );
105105
}
@@ -109,25 +109,25 @@ void TestQgsFeatureListComboBox::testSetGetForeignKey()
109109
QgsFeatureListComboBox *cb = new QgsFeatureListComboBox();
110110
// std::unique_ptr<QgsFeatureListComboBox> cb( new QgsFeatureListComboBox() );
111111

112-
Q_ASSERT( cb->identifierValue().isNull() );
112+
QVERIFY( cb->identifierValue().isNull() );
113113

114114
cb->setSourceLayer( mLayer.get() );
115115
cb->setDisplayExpression( "\"material\"" );
116116
cb->lineEdit()->setText( "ro" );
117117
emit cb->lineEdit()->textChanged( "ro" );
118-
Q_ASSERT( cb->identifierValue().isNull() );
118+
QVERIFY( cb->identifierValue().isNull() );
119119

120120
waitForLoaded( cb );
121121

122-
Q_ASSERT( cb->identifierValue().isNull() );
122+
QVERIFY( cb->identifierValue().isNull() );
123123

124124
cb->setIdentifierValue( 20 );
125125
QCOMPARE( cb->identifierValue(), QVariant( 20 ) );
126126
}
127127

128128
void TestQgsFeatureListComboBox::testAllowNull()
129129
{
130-
Q_ASSERT( false );
130+
QVERIFY( false );
131131
// Note to self: implement this!
132132
}
133133

tests/src/gui/testqgsfiledownloader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void TestQgsFileDownloader::init()
133133
mCompleted = false;
134134
mExited = false;
135135
mTempFile = new QTemporaryFile();
136-
Q_ASSERT( mTempFile->open() );
136+
QVERIFY( mTempFile->open() );
137137
mTempFile->close();
138138
}
139139

tests/src/gui/testrenderergui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ void TestRendererGUI::loadLayers()
5555
void TestRendererGUI::setRenderer()
5656
{
5757
QgsMapLayer *layer = mMapCanvas->layer( 0 );
58-
Q_ASSERT( layer );
59-
Q_ASSERT( layer->type() == QgsMapLayer::VectorLayer );
58+
QVERIFY( layer );
59+
QVERIFY( layer->type() == QgsMapLayer::VectorLayer );
6060
QgsVectorLayer *vlayer = static_cast<QgsVectorLayer *>( layer );
6161

6262
QgsRendererPropertiesDialog dlg( vlayer, QgsStyle::defaultStyle() );

tests/src/providers/grass/testqgsgrassprovider.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ void TestQgsGrassProvider::edit()
12091209
grassLayer->startEditing();
12101210
grassProvider->startEditing( grassLayer );
12111211

1212-
Q_ASSERT( expectedLayer );
1212+
QVERIFY( expectedLayer );
12131213
expectedLayer->startEditing();
12141214
}
12151215

@@ -1577,7 +1577,7 @@ bool TestQgsGrassProvider::compare( QMap<QString, QgsVectorLayer *> layers, bool
15771577
Q_FOREACH ( const QString &grassUri, layers.keys() )
15781578
{
15791579
QgsVectorLayer *layer = layers.value( grassUri );
1580-
Q_ASSERT( layer );
1580+
QVERIFY( layer );
15811581
if ( !compare( grassUri, layer, ok ) )
15821582
{
15831583
reportRow( "comparison failed: " + grassUri );

0 commit comments

Comments
 (0)