Skip to content

Commit

Permalink
Merge pull request OSGeo#11436 from rouault/gml_detect_write_error
Browse files Browse the repository at this point in the history
GML: detect and report write error
  • Loading branch information
rouault authored Dec 6, 2024
2 parents 0b59e8b + 1007ee6 commit b8372bd
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 152 deletions.
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,16 @@ if (BUILD_PYTHON_BINDINGS)
endif()
endif()

#
include(${CMAKE_CURRENT_SOURCE_DIR}/gdal.cmake)

option(BUILD_TESTING "Build the testing tree." ON)
# Make sure enable_testing() is defined before including gdal.cmake for
# Java and CSharp tests
if (BUILD_TESTING)
enable_testing()
endif()

#
include(${CMAKE_CURRENT_SOURCE_DIR}/gdal.cmake)

if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/autotest")
# unit tests
add_subdirectory(autotest/cpp)
Expand Down
25 changes: 25 additions & 0 deletions autotest/ogr/ogr_gml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4951,3 +4951,28 @@ def test_ogr_gml_type_override(
assert (
gdal.GetLastErrorMsg().find(expected_warning) != -1
), f"Warning {expected_warning} not found, got {gdal.GetLastErrorMsg()} instead"


###############################################################################
# Test a write error


@gdaltest.enable_exceptions()
def test_ogr_gml_write_error(tmp_vsimem):

filename = str(tmp_vsimem / "test.gml||maxlength=200")
ds = ogr.GetDriverByName("GML").CreateDataSource(
filename, options=["XSISCHEMA=OFF"]
)
with pytest.raises(Exception, match="Could not write line"):
ds.Close()

filename = str(tmp_vsimem / "test.gml||maxlength=600")
ds = ogr.GetDriverByName("GML").CreateDataSource(
filename, options=["XSISCHEMA=OFF"]
)
lyr = ds.CreateLayer("test")
f = ogr.Feature(lyr.GetLayerDefn())
with pytest.raises(Exception, match="Could not write line"):
lyr.CreateFeature(f)
ds.Close()
8 changes: 8 additions & 0 deletions ogr/ogrsf_frmts/gml/ogr_gml.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class OGRGMLDataSource final : public GDALDataset
VSILFILE *fpOutput;
bool bFpOutputIsNonSeekable;
bool bFpOutputSingleFile;
bool m_bWriteError = false;
OGREnvelope3D sBoundingRect{};
bool bBBOX3D;
int nBoundedByLocation;
Expand Down Expand Up @@ -178,6 +179,7 @@ class OGRGMLDataSource final : public GDALDataset
virtual ~OGRGMLDataSource();

bool Open(GDALOpenInfo *poOpenInfo);
CPLErr Close() override;
bool Create(const char *pszFile, char **papszOptions);

int GetLayerCount() override
Expand Down Expand Up @@ -226,6 +228,12 @@ class OGRGMLDataSource final : public GDALDataset
return bIsOutputGML32;
}

/** Returns whether a writing error has occured */
inline bool HasWriteError() const
{
return m_bWriteError;
}

OGRGMLSRSNameFormat GetSRSNameFormat() const
{
return eSRSNameFormat;
Expand Down
Loading

0 comments on commit b8372bd

Please sign in to comment.