Skip to content

Commit 5acb128

Browse files
committed
testqgsgml.cpp: fix memory leaks in test
1 parent 544e8bd commit 5acb128

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/src/core/testqgsgml.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ void TestQgsGML::testFromURL()
106106
tmpFile.flush();
107107
QCOMPARE( gmlParser.getFeatures( QUrl::fromLocalFile( tmpFile.fileName() ).toString(), &wkbType ), 0 );
108108
QCOMPARE( wkbType, QGis::WKBPoint );
109-
QCOMPARE( gmlParser.featuresMap().size(), 1 );
109+
QMap<QgsFeatureId, QgsFeature* > featureMaps = gmlParser.featuresMap();
110+
QCOMPARE( featureMaps.size(), 1 );
110111
QCOMPARE( gmlParser.idsMap().size(), 1 );
111112
QCOMPARE( gmlParser.crs().authid(), QString( "EPSG:27700" ) );
113+
delete featureMaps[ 0 ];
112114
}
113115

114116
void TestQgsGML::testFromByteArray()
@@ -125,6 +127,7 @@ void TestQgsGML::testFromByteArray()
125127
QMap<QgsFeatureId, QString > idsMap = gmlParser.idsMap();
126128
QVERIFY( idsMap.constFind( 0 ) != idsMap.constEnd() );
127129
QCOMPARE( idsMap[ 0 ], QString( "mytypename.1" ) );
130+
delete featureMaps[ 0 ];
128131
}
129132

130133
void TestQgsGML::testStreamingParser()
@@ -155,6 +158,7 @@ void TestQgsGML::testStreamingParser()
155158
QCOMPARE( gmlParser.getAndStealReadyFeatures().size(), 0 );
156159
QCOMPARE( gmlParser.getEPSGCode(), 27700 );
157160
QCOMPARE( gmlParser.wkbType(), QGis::WKBPoint );
161+
delete features[0].first;
158162
}
159163

160164
void TestQgsGML::testStreamingParserInvalidGML()
@@ -188,6 +192,7 @@ void TestQgsGML::testPointGML2()
188192
QVERIFY( features[0].first->constGeometry() != nullptr );
189193
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
190194
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 10, 20 ) );
195+
delete features[0].first;
191196
}
192197

193198
void TestQgsGML::testLineStringGML2()
@@ -216,6 +221,7 @@ void TestQgsGML::testLineStringGML2()
216221
QCOMPARE( line.size(), 2 );
217222
QCOMPARE( line[0], QgsPoint( 10, 20 ) );
218223
QCOMPARE( line[1], QgsPoint( 30, 40 ) );
224+
delete features[0].first;
219225
}
220226

221227
void TestQgsGML::testPolygonGML2()
@@ -253,6 +259,7 @@ void TestQgsGML::testPolygonGML2()
253259
QCOMPARE( poly.size(), 2 );
254260
QCOMPARE( poly[0].size(), 5 );
255261
QCOMPARE( poly[1].size(), 4 );
262+
delete features[0].first;
256263
}
257264

258265
void TestQgsGML::testMultiPointGML2()
@@ -290,6 +297,7 @@ void TestQgsGML::testMultiPointGML2()
290297
QCOMPARE( multi.size(), 2 );
291298
QCOMPARE( multi[0], QgsPoint( 10, 20 ) );
292299
QCOMPARE( multi[1], QgsPoint( 30, 40 ) );
300+
delete features[0].first;
293301
}
294302

295303
void TestQgsGML::testMultiLineStringGML2()
@@ -329,6 +337,7 @@ void TestQgsGML::testMultiLineStringGML2()
329337
QCOMPARE( multi[0][0], QgsPoint( 10, 20 ) );
330338
QCOMPARE( multi[0][1], QgsPoint( 30, 40 ) );
331339
QCOMPARE( multi[1].size(), 3 );
340+
delete features[0].first;
332341
}
333342

334343
void TestQgsGML::testMultiPolygonGML2()
@@ -365,6 +374,7 @@ void TestQgsGML::testMultiPolygonGML2()
365374
QCOMPARE( multi.size(), 1 );
366375
QCOMPARE( multi[0].size(), 1 );
367376
QCOMPARE( multi[0][0].size(), 5 );
377+
delete features[0].first;
368378
}
369379

370380
void TestQgsGML::testPointGML3()
@@ -392,6 +402,7 @@ void TestQgsGML::testPointGML3()
392402
QCOMPARE( features[0].second, QString( "mytypename.1" ) );
393403
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
394404
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 10, 20 ) );
405+
delete features[0].first;
395406
}
396407

397408
void TestQgsGML::testPointGML3_EPSG_4326()
@@ -419,6 +430,7 @@ void TestQgsGML::testPointGML3_EPSG_4326()
419430
QCOMPARE( features[0].second, QString( "mytypename.1" ) );
420431
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
421432
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 2, 49 ) );
433+
delete features[0].first;
422434
}
423435

424436
void TestQgsGML::testPointGML3_urn_EPSG_4326()
@@ -446,6 +458,7 @@ void TestQgsGML::testPointGML3_urn_EPSG_4326()
446458
QCOMPARE( features[0].second, QString( "mytypename.1" ) );
447459
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
448460
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 2, 49 ) );
461+
delete features[0].first;
449462
}
450463

451464
void TestQgsGML::testPointGML3_EPSG_4326_honour_EPSG()
@@ -473,6 +486,7 @@ void TestQgsGML::testPointGML3_EPSG_4326_honour_EPSG()
473486
QCOMPARE( features[0].second, QString( "mytypename.1" ) );
474487
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
475488
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 2, 49 ) );
489+
delete features[0].first;
476490
}
477491

478492
void TestQgsGML::testPointGML3_EPSG_4326_honour_EPSG_invert()
@@ -500,6 +514,7 @@ void TestQgsGML::testPointGML3_EPSG_4326_honour_EPSG_invert()
500514
QCOMPARE( features[0].second, QString( "mytypename.1" ) );
501515
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
502516
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 2, 49 ) );
517+
delete features[0].first;
503518
}
504519

505520
void TestQgsGML::testLineStringGML3()
@@ -528,6 +543,7 @@ void TestQgsGML::testLineStringGML3()
528543
QCOMPARE( line.size(), 2 );
529544
QCOMPARE( line[0], QgsPoint( 10, 20 ) );
530545
QCOMPARE( line[1], QgsPoint( 30, 40 ) );
546+
delete features[0].first;
531547
}
532548

533549
void TestQgsGML::testLineStringGML3_LineStringSegment()
@@ -554,6 +570,7 @@ void TestQgsGML::testLineStringGML3_LineStringSegment()
554570
QCOMPARE( line.size(), 2 );
555571
QCOMPARE( line[0], QgsPoint( 10, 20 ) );
556572
QCOMPARE( line[1], QgsPoint( 30, 40 ) );
573+
delete features[0].first;
557574
}
558575

559576
void TestQgsGML::testPolygonGML3()
@@ -591,6 +608,7 @@ void TestQgsGML::testPolygonGML3()
591608
QCOMPARE( poly.size(), 2 );
592609
QCOMPARE( poly[0].size(), 5 );
593610
QCOMPARE( poly[1].size(), 4 );
611+
delete features[0].first;
594612
}
595613

596614
void TestQgsGML::testPolygonGML3_srsDimension_on_Polygon()
@@ -622,6 +640,7 @@ void TestQgsGML::testPolygonGML3_srsDimension_on_Polygon()
622640
QgsPolygon poly = features[0].first->constGeometry()->asPolygon();
623641
QCOMPARE( poly.size(), 1 );
624642
QCOMPARE( poly[0].size(), 5 );
643+
delete features[0].first;
625644
}
626645

627646
void TestQgsGML::testMultiLineStringGML3()
@@ -661,6 +680,7 @@ void TestQgsGML::testMultiLineStringGML3()
661680
QCOMPARE( multi[0][0], QgsPoint( 10, 20 ) );
662681
QCOMPARE( multi[0][1], QgsPoint( 30, 40 ) );
663682
QCOMPARE( multi[1].size(), 3 );
683+
delete features[0].first;
664684
}
665685

666686
void TestQgsGML::testMultiPolygonGML3()
@@ -706,6 +726,7 @@ void TestQgsGML::testMultiPolygonGML3()
706726
QCOMPARE( multi.size(), 2 );
707727
QCOMPARE( multi[0].size(), 1 );
708728
QCOMPARE( multi[0][0].size(), 5 );
729+
delete features[0].first;
709730
}
710731

711732
void TestQgsGML::testPointGML3_2()
@@ -734,6 +755,7 @@ void TestQgsGML::testPointGML3_2()
734755
QCOMPARE( features[0].second, QString( "mytypename.1" ) );
735756
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
736757
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 10, 20 ) );
758+
delete features[0].first;
737759
}
738760

739761
void TestQgsGML::testBoundingBoxGML2()
@@ -761,6 +783,7 @@ void TestQgsGML::testBoundingBoxGML2()
761783
QgsPolygon poly = features[0].first->constGeometry()->asPolygon();
762784
QCOMPARE( poly.size(), 1 );
763785
QCOMPARE( poly[0].size(), 5 );
786+
delete features[0].first;
764787
}
765788

766789
void TestQgsGML::testBoundingBoxGML3()
@@ -789,6 +812,7 @@ void TestQgsGML::testBoundingBoxGML3()
789812
QgsPolygon poly = features[0].first->constGeometry()->asPolygon();
790813
QCOMPARE( poly.size(), 1 );
791814
QCOMPARE( poly[0].size(), 5 );
815+
delete features[0].first;
792816
}
793817

794818
void TestQgsGML::testNumberMatchedNumberReturned()
@@ -930,6 +954,7 @@ void TestQgsGML::testTuple()
930954
QCOMPARE( features[0].second, QString( "firstlayer.1|secondlayer.1" ) );
931955
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
932956
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 10, 20 ) );
957+
delete features[0].first;
933958
}
934959

935960
void TestQgsGML::testRenamedFields()
@@ -969,6 +994,7 @@ void TestQgsGML::testRenamedFields()
969994
QCOMPARE( features[0].second, QString( "mylayer.1" ) );
970995
QCOMPARE( features[0].first->constGeometry()->wkbType(), QGis::WKBPoint );
971996
QCOMPARE( features[0].first->constGeometry()->asPoint(), QgsPoint( 10, 20 ) );
997+
delete features[0].first;
972998
}
973999

9741000
void TestQgsGML::testTruncatedResponse()

0 commit comments

Comments
 (0)