Skip to content

Commit

Permalink
Fix 2 tests to be compatible of GDAL 3.10
Browse files Browse the repository at this point in the history
GDAL 3.10 has deprecated the MEM::: open syntax
  • Loading branch information
rouault authored and nyalldawson committed Nov 11, 2024
1 parent 72412e6 commit 9b5e5bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 16 additions & 3 deletions tests/src/core/testqgslegendrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
#include "qgsfillsymbol.h"
#include "qgsheatmaprenderer.h"
#include "qgsmeshlayer.h"

#include "gdal.h"

class TestRasterRenderer : public QgsPalettedRasterRenderer
{
public:
Expand Down Expand Up @@ -294,9 +297,17 @@ void TestQgsLegendRenderer::init()
}
QgsProject::instance()->addMapLayer( mVL3 );

static const char RASTER_ARRAY[] = { 1, 2, 2, 1 };
const QString rasterUri = QStringLiteral( "MEM:::DATAPOINTER=%1,PIXELS=2,LINES=2" ).arg( ( qulonglong ) RASTER_ARRAY );
mRL = new QgsRasterLayer( rasterUri, QStringLiteral( "Raster Layer" ), QStringLiteral( "gdal" ) );
char RASTER_ARRAY[] = { 1, 2, 2, 1 };
GDALDriverH hGTiffDrv = GDALGetDriverByName( "GTiff" );
Q_ASSERT( hGTiffDrv );
const char *tempFileName = "/vsimem/temp.tif";
GDALDatasetH hDS = GDALCreate( hGTiffDrv, tempFileName, 2, 2, 1, GDT_Byte, NULL );
Q_ASSERT( hDS );
CPLErr eErr = GDALRasterIO( GDALGetRasterBand( hDS, 1 ), GF_Write, 0, 0, 2, 2, RASTER_ARRAY, 2, 2, GDT_Byte, 1, 2 );
QVERIFY( eErr == CE_None );
GDALClose( hDS );

mRL = new QgsRasterLayer( QString( tempFileName ), QStringLiteral( "Raster Layer" ), QStringLiteral( "gdal" ) );

std::unique_ptr< TestRasterRenderer > rasterRenderer( new TestRasterRenderer( mRL->dataProvider(), 1,
{
Expand Down Expand Up @@ -326,6 +337,8 @@ void TestQgsLegendRenderer::init()
grp1->addLayer( mVL2 );
mRoot->addLayer( mVL3 );
mRoot->addLayer( mRL );

VSIUnlink( tempFileName );
}

void TestQgsLegendRenderer::cleanup()
Expand Down
17 changes: 11 additions & 6 deletions tests/src/core/testqgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,16 +808,21 @@ void TestQgsRasterLayer::palettedRendererNoDataColor()

void TestQgsRasterLayer::palettedRendererConstantInt()
{
char data { 2 };
std::unique_ptr< QgsRasterLayer> rl = std::make_unique< QgsRasterLayer >( QStringLiteral( "MEM:::DATAPOINTER=0x%1,PIXELS=1,LINES=1,BANDS=1,DATATYPE=Byte" )
.arg( reinterpret_cast<quintptr>( &data ),
QT_POINTER_SIZE * 2, 16, QChar( '0' ) ).toStdString().c_str(),
QStringLiteral( "rl" ) );
constexpr double value = 2.0;
GDALDriverH hGTiffDrv = GDALGetDriverByName( "GTiff" );
Q_ASSERT( hGTiffDrv );
const char *tempFileName = "/vsimem/temp.tif";
GDALDatasetH hDS = GDALCreate( hGTiffDrv, tempFileName, 1, 1, 1, GDT_Byte, NULL );
Q_ASSERT( hDS );
GDALFillRaster( GDALGetRasterBand( hDS, 1 ), value, 0 );
GDALClose( hDS );
std::unique_ptr< QgsRasterLayer> rl = std::make_unique< QgsRasterLayer >( QString( tempFileName ), QStringLiteral( "rl" ) );
Q_ASSERT( rl->isValid() );
const auto classData { QgsPalettedRasterRenderer::classDataFromRaster( rl->dataProvider(), 1 ) };
QCOMPARE( classData.size(), 1 );
QCOMPARE( classData.first().value, 2.0 );
QCOMPARE( classData.first().value, value );
rl.reset( );
VSIUnlink( tempFileName );
}

void TestQgsRasterLayer::singleBandGrayRendererNoData()
Expand Down

0 comments on commit 9b5e5bb

Please sign in to comment.