Skip to content

Commit

Permalink
Test infrastructure: check GDAL_DCAP_UPDATE and GDAL_DMD_UPDATE_ITEMS
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 25, 2025
1 parent 1b5c4c1 commit 6b1b41a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
19 changes: 19 additions & 0 deletions apps/test_ogrsf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4436,6 +4436,25 @@ static int TestOGRLayer(GDALDataset *poDS, OGRLayer *poLayer, int bIsSQLLayer)
/* -------------------------------------------------------------------- */
if (LOG_ACTION(poLayer->TestCapability(OLCRandomWrite)))
{
if (!poDS->GetDriver()->GetMetadataItem(GDAL_DCAP_UPDATE))
{
printf("ERROR: Driver %s does not declare GDAL_DCAP_UPDATE\n",
poDS->GetDriver()->GetDescription());
bRet = false;
}
else
{
const char *pszItems =
poDS->GetDriver()->GetMetadataItem(GDAL_DMD_UPDATE_ITEMS);
if (!pszItems || !strstr(pszItems, "Features"))
{
printf("ERROR: Driver %s does not declare Features in "
"GDAL_DMD_UPDATE_ITEMS\n",
poDS->GetDriver()->GetDescription());
bRet = false;
}
}

bRet &= TestOGRLayerRandomWrite(poLayer);
}

Expand Down
55 changes: 54 additions & 1 deletion autotest/gcore/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import gdaltest
import pytest

from osgeo import gdal
from osgeo import gdal, osr


###############################################################################
Expand Down Expand Up @@ -118,6 +118,8 @@ def get_filename(drv, dirname):
filename += ".kmz"
elif drv.ShortName == "RRASTER":
filename += ".grd"
elif drv.ShortName == "KEA":
filename += ".kea"

return filename

Expand Down Expand Up @@ -314,6 +316,55 @@ def misc_6_internal(datatype, nBands, setDriversDone):
dst_ds.GetMetadataItem("", None)
dst_ds = None

if (
has_succeeded
and nBands > 0
and "DCAP_UPDATE" in md
and drv.ShortName not in ("VRT",)
):
ds = gdal.Open(filename, gdal.GA_Update)
assert ds, (drv.ShortName, filename)

flags_str = drv.GetMetadataItem(gdal.DMD_UPDATE_ITEMS)
if ds.RasterCount and "RasterValues" in flags_str:
assert (
ds.GetRasterBand(1).WriteRaster(
0, 0, 1, 1, b"\x00", buf_type=gdal.GDT_Byte
)
== gdal.CE_None
), (drv.ShortName, filename)

if "GeoTransform" in flags_str and drv.ShortName not in ("netCDF",):
assert ds.SetGeoTransform([0, 1, 0, 0, 0, -1]) == gdal.CE_None, (
drv.ShortName,
filename,
)

if "SRS" in flags_str and drv.ShortName not in ("netCDF",):
srs = osr.SpatialReference()
srs.SetFromUserInput("WGS84")
assert ds.SetSpatialRef(srs) == gdal.CE_None, (
drv.ShortName,
filename,
)

if ds.RasterCount and "NoData" in flags_str:
assert ds.GetRasterBand(1).SetNoDataValue(0) == gdal.CE_None, (
drv.ShortName,
filename,
)

if "DatasetMetadata" in flags_str:
assert ds.SetMetadata({"FOO": "BAR"}) == gdal.CE_None, (
drv.ShortName,
filename,
)

if ds.RasterCount and "BandMetadata" in flags_str:
assert (
ds.GetRasterBand(1).SetMetadata({"FOO": "BAR"}) == gdal.CE_None
), (drv.ShortName, filename)

size = 0
stat = gdal.VSIStatL(filename)
if stat is not None:
Expand Down Expand Up @@ -400,6 +451,7 @@ def misc_6_internal(datatype, nBands, setDriversDone):
"USGSDEM",
"KMLSUPEROVERLAY",
"GMT",
"NULL",
]:
dst_ds = drv.CreateCopy(
filename, ds, callback=misc_6_interrupt_callback_class().cbk
Expand Down Expand Up @@ -440,6 +492,7 @@ def misc_6_internal(datatype, nBands, setDriversDone):
)
)
pytest.fail(reason)

ds = None


Expand Down
27 changes: 27 additions & 0 deletions autotest/gcore/test_driver_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,30 @@ def test_metadata_creation_field_defn_flags(driver_name):
if flags_str is not None:
for flag in flags_str.split(" "):
assert flag in supported_flags


@pytest.mark.parametrize("driver_name", ogr_driver_names)
def test_metadata_update_items(driver_name):
"""Test if DMD_UPDATE_ITEMS metadataitem returns valid flags"""

supported_flags = {
"GeoTransform",
"SRS",
"GCPs",
"NoData",
"ColorInterpretation",
"RasterValues",
"DatasetMetadata",
"BandMetadata",
"Features",
"LayerMetadata",
}

driver = gdal.GetDriverByName(driver_name)
flags_str = driver.GetMetadataItem(gdal.DMD_UPDATE_ITEMS)
if flags_str is not None:
assert driver.GetMetadataItem(gdal.DCAP_UPDATE)
for flag in flags_str.split(" "):
assert flag in supported_flags
else:
assert not driver.GetMetadataItem(gdal.DCAP_UPDATE)

0 comments on commit 6b1b41a

Please sign in to comment.