From ea2211605146608e2b1bd97edd93b487762b6f76 Mon Sep 17 00:00:00 2001 From: Daniel Baston Date: Thu, 10 Oct 2024 14:35:04 -0400 Subject: [PATCH] autotest: add tests for OGR AddCurveDirectly methods --- autotest/cpp/test_ogr.cpp | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/autotest/cpp/test_ogr.cpp b/autotest/cpp/test_ogr.cpp index 86da6b9ac515..300f6c612ab5 100644 --- a/autotest/cpp/test_ogr.cpp +++ b/autotest/cpp/test_ogr.cpp @@ -4256,4 +4256,91 @@ TEST_F(test_ogr, OGRCurve_reversePoints) } } +// Test OGRCurvePolygon::addRingDirectly +TEST_F(test_ogr, OGRCurvePolygon_addRingDirectly) +{ + OGRCurvePolygon cp; + OGRGeometry *ring; + + // closed CircularString + OGRGeometryFactory::createFromWkt( + "CIRCULARSTRING (0 0, 1 1, 2 0, 1 -1, 0 0)", nullptr, &ring); + ASSERT_TRUE(ring); + EXPECT_EQ(cp.addRingDirectly(ring->toCurve()), OGRERR_NONE); + + // open CircularString + OGRGeometryFactory::createFromWkt("CIRCULARSTRING (0 0, 1 1, 2 0)", nullptr, + &ring); + ASSERT_TRUE(ring); + { + CPLConfigOptionSetter oSetter("OGR_GEOMETRY_ACCEPT_UNCLOSED_RING", "NO", + false); + ASSERT_EQ(cp.addRingDirectly(ring->toCurve()), + OGRERR_UNSUPPORTED_GEOMETRY_TYPE); + } + EXPECT_EQ(cp.addRingDirectly(ring->toCurve()), OGRERR_NONE); + + // closed CompoundCurve + OGRGeometryFactory::createFromWkt( + "COMPOUNDCURVE( CIRCULARSTRING (0 0, 1 1, 2 0), (2 0, 0 0))", nullptr, + &ring); + ASSERT_TRUE(ring); + EXPECT_EQ(cp.addRingDirectly(ring->toCurve()), OGRERR_NONE); + + // closed LineString + OGRGeometryFactory::createFromWkt("LINESTRING (0 0, 1 0, 1 1, 0 1, 0 0)", + nullptr, &ring); + ASSERT_TRUE(ring); + EXPECT_EQ(cp.addRingDirectly(ring->toCurve()), OGRERR_NONE); + + // LinearRing + auto lr = std::make_unique(); + lr->addPoint(0, 0); + lr->addPoint(1, 0); + lr->addPoint(1, 1); + lr->addPoint(0, 1); + lr->addPoint(0, 0); + ASSERT_TRUE(ring); + ASSERT_EQ(cp.addRingDirectly(lr.get()), OGRERR_UNSUPPORTED_GEOMETRY_TYPE); +} + +// Test OGRPolygon::addRingDirectly +TEST_F(test_ogr, OGRPolygon_addRingDirectly) +{ + OGRPolygon p; + OGRGeometry *ring; + + // closed CircularString + OGRGeometryFactory::createFromWkt( + "CIRCULARSTRING (0 0, 1 1, 2 0, 1 -1, 0 0)", nullptr, &ring); + ASSERT_TRUE(ring); + EXPECT_EQ(p.addRingDirectly(ring->toCurve()), + OGRERR_UNSUPPORTED_GEOMETRY_TYPE); + delete ring; + + // closed LineString + OGRGeometryFactory::createFromWkt("LINESTRING (0 0, 1 0, 1 1, 0 1, 0 0)", + nullptr, &ring); + ASSERT_TRUE(ring); + EXPECT_EQ(p.addRingDirectly(ring->toCurve()), + OGRERR_UNSUPPORTED_GEOMETRY_TYPE); + delete ring; + + // open LineString + OGRGeometryFactory::createFromWkt("LINESTRING (0 0, 1 0)", nullptr, &ring); + ASSERT_TRUE(ring); + EXPECT_EQ(p.addRingDirectly(ring->toCurve()), + OGRERR_UNSUPPORTED_GEOMETRY_TYPE); + delete ring; + + // LinearRing + auto lr = std::make_unique(); + lr->addPoint(0, 0); + lr->addPoint(1, 0); + lr->addPoint(1, 1); + lr->addPoint(0, 1); + lr->addPoint(0, 0); + ASSERT_EQ(p.addRingDirectly(lr.release()), OGRERR_NONE); +} + } // namespace