From e7bd600ab30c4a628fbb3cf4257b39ebb2bd6e47 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 13 Aug 2021 16:36:15 +0200 Subject: [PATCH] testqgsogrutils.cpp: fix build with GDAL 3.4 --- tests/src/core/testqgsogrutils.cpp | 45 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/src/core/testqgsogrutils.cpp b/tests/src/core/testqgsogrutils.cpp index 5c9f61aa442..d312ccc23bb 100644 --- a/tests/src/core/testqgsogrutils.cpp +++ b/tests/src/core/testqgsogrutils.cpp @@ -722,30 +722,33 @@ void TestQgsOgrUtils::convertStyleString() void TestQgsOgrUtils::ogrCrsConversion() { // test conversion utilities for OGR srs objects - - const QgsCoordinateReferenceSystem crs1( QStringLiteral( "EPSG:3111" ) ); - OGRSpatialReferenceH srs = QgsOgrUtils::crsToOGRSpatialReference( crs1 ); - QVERIFY( srs ); - const QgsCoordinateReferenceSystem crs2( QgsOgrUtils::OGRSpatialReferenceToCrs( srs ) ); - // round trip should be lossless - QCOMPARE( crs1, crs2 ); - OSRRelease( srs ); - srs = nullptr; + { + const QgsCoordinateReferenceSystem crs1( QStringLiteral( "EPSG:3111" ) ); + OGRSpatialReferenceH srs = QgsOgrUtils::crsToOGRSpatialReference( crs1 ); + QVERIFY( srs ); + const QgsCoordinateReferenceSystem crs2( QgsOgrUtils::OGRSpatialReferenceToCrs( srs ) ); + // round trip should be lossless + QCOMPARE( crs1, crs2 ); + OSRRelease( srs ); #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0) - QVERIFY( std::isnan( crs2.coordinateEpoch() ) ); + QVERIFY( std::isnan( crs2.coordinateEpoch() ) ); +#endif + } - // test conversion with a coordinate epoch, should work on GDAL 3.4+ - crs1 = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ); - crs1.setCoordinateEpoch( 2020.7 ); - srs = QgsOgrUtils::crsToOGRSpatialReference( crs1 ); - QVERIFY( srs ); - crs2 = QgsCoordinateReferenceSystem( QgsOgrUtils::OGRSpatialReferenceToCrs( srs ) ); - // round trip should be lossless - QCOMPARE( crs1, crs2 ); - QCOMPARE( crs2.coordinateEpoch(), 2020.7 ); - OSRRelease( srs ); - srs = nullptr; +#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0) + { + // test conversion with a coordinate epoch, should work on GDAL 3.4+ + QgsCoordinateReferenceSystem crs1( QStringLiteral( "EPSG:4326" ) ); + crs1.setCoordinateEpoch( 2020.7 ); + OGRSpatialReferenceH srs = QgsOgrUtils::crsToOGRSpatialReference( crs1 ); + QVERIFY( srs ); + const QgsCoordinateReferenceSystem crs2( QgsOgrUtils::OGRSpatialReferenceToCrs( srs ) ); + // round trip should be lossless + QCOMPARE( crs1, crs2 ); + QCOMPARE( crs2.coordinateEpoch(), 2020.7 ); + OSRRelease( srs ); + } #endif }