From c915dc1bff688f73643d77567f378c6566e3880a Mon Sep 17 00:00:00 2001 From: strk Date: Sat, 20 Aug 2011 20:52:21 +0000 Subject: [PATCH] Fix Geometry::clone() to copy SRID. Closes ticket #464. git-svn-id: http://svn.osgeo.org/geos/branches/3.3@3460 5242fede-7e19-0410-aef8-94bd7d2200fb --- NEWS | 1 + src/geom/GeometryCollection.cpp | 2 +- src/geom/LineString.cpp | 2 +- src/geom/Point.cpp | 2 +- src/geom/Polygon.cpp | 2 +- tests/unit/Makefile.am | 3 +- tests/unit/geom/Geometry/clone.cpp | 152 +++++++++++++++++++++++++++++++++++++ 7 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 tests/unit/geom/Geometry/clone.cpp diff --git a/NEWS b/NEWS index 3fbc78fb..d4fec8e2 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ Changes in 3.3.1 - Fix for SOLARIS build - Fix EMPTY result from GEOSOffsetCurve with distance 0 (#454) - Fix out of source builds + - Fix Geometry::clone to copy SRID (#464) Changes in 3.3.0 2011-05-30 diff --git a/src/geom/GeometryCollection.cpp b/src/geom/GeometryCollection.cpp index 986238a1..4f3e3402 100644 --- a/src/geom/GeometryCollection.cpp +++ b/src/geom/GeometryCollection.cpp @@ -45,7 +45,7 @@ namespace geom { // geos::geom /*protected*/ GeometryCollection::GeometryCollection(const GeometryCollection &gc) : - Geometry(gc.getFactory()) + Geometry(gc) { size_t ngeoms=gc.geometries->size(); diff --git a/src/geom/LineString.cpp b/src/geom/LineString.cpp index 53f81355..5148293a 100644 --- a/src/geom/LineString.cpp +++ b/src/geom/LineString.cpp @@ -49,7 +49,7 @@ namespace geom { // geos::geom /*protected*/ LineString::LineString(const LineString &ls) : - Geometry(ls.getFactory()), + Geometry(ls), points(ls.points->clone()) { //points=ls.points->clone(); diff --git a/src/geom/Point.cpp b/src/geom/Point.cpp index 9492a773..85f1fa1b 100644 --- a/src/geom/Point.cpp +++ b/src/geom/Point.cpp @@ -62,7 +62,7 @@ Point::Point(CoordinateSequence *newCoords, const GeometryFactory *factory) /*protected*/ Point::Point(const Point &p) : - Geometry(p.getFactory()), + Geometry(p), coordinates(p.coordinates->clone()) { } diff --git a/src/geom/Polygon.cpp b/src/geom/Polygon.cpp index 39220306..cddfa886 100644 --- a/src/geom/Polygon.cpp +++ b/src/geom/Polygon.cpp @@ -53,7 +53,7 @@ namespace geom { // geos::geom /*protected*/ Polygon::Polygon(const Polygon &p) : - Geometry(p.getFactory()) + Geometry(p) { shell=new LinearRing(*p.shell); size_t nholes=p.holes->size(); diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index bfbbff15..c5fd79f3 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -47,8 +47,9 @@ geos_unit_SOURCES = \ geom/CoordinateTest.cpp \ geom/DimensionTest.cpp \ geom/EnvelopeTest.cpp \ - geom/Geometry/isRectangleTest.cpp \ + geom/Geometry/clone.cpp \ geom/Geometry/coversTest.cpp \ + geom/Geometry/isRectangleTest.cpp \ geom/GeometryFactoryTest.cpp \ geom/IntersectionMatrixTest.cpp \ geom/LinearRingTest.cpp \ diff --git a/tests/unit/geom/Geometry/clone.cpp b/tests/unit/geom/Geometry/clone.cpp new file mode 100644 index 00000000..e5ec59b0 --- /dev/null +++ b/tests/unit/geom/Geometry/clone.cpp @@ -0,0 +1,152 @@ +// $Id$ +// +// Test Suite for Geometry's clone() + +// tut +#include +// geos +#include +#include +#include +#include +// std +#include +#include + +namespace tut { + +// +// Test Group +// + +struct test_geometry_clone_data +{ + typedef std::auto_ptr GeomAutoPtr; + geos::geom::GeometryFactory factory; + geos::io::WKTReader reader; + + test_geometry_clone_data() + : reader(&factory) + {} +}; + +typedef test_group group; +typedef group::object object; + +group test_geometry_clone_data("geos::geom::Geometry::clone"); + +// +// Test Cases +// + +template<> +template<> +void object::test<1>() +{ + GeomAutoPtr g1(reader.read( + "POINT (0 100)" + )); + g1->setSRID(66); + GeomAutoPtr g2(g1->clone()); + + ensure( g1->equalsExact(g2.get()) ); + ensure_equals( g1->getSRID(), 66 ); + ensure_equals( g1->getSRID(), g2->getSRID() ); + +} + +template<> +template<> +void object::test<2>() +{ + GeomAutoPtr g1(reader.read( + "LINESTRING (0 0, 0 100, 100 100, 100 0)" + )); + g1->setSRID(66); + GeomAutoPtr g2(g1->clone()); + + ensure( g1->equalsExact(g2.get()) ); + ensure_equals( g1->getSRID(), 66 ); + ensure_equals( g1->getSRID(), g2->getSRID() ); + +} + +template<> +template<> +void object::test<3>() +{ + GeomAutoPtr g1(reader.read( + "POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))" + )); + g1->setSRID(66); + GeomAutoPtr g2(g1->clone()); + + ensure( g1->equalsExact(g2.get()) ); + ensure_equals( g1->getSRID(), 66 ); + ensure_equals( g1->getSRID(), g2->getSRID() ); + +} + +template<> +template<> +void object::test<4>() +{ + GeomAutoPtr g1(reader.read( + "MULTIPOINT (0 100, 5 6)" + )); + g1->setSRID(66); + GeomAutoPtr g2(g1->clone()); + + ensure( g1->equalsExact(g2.get()) ); + ensure_equals( g1->getSRID(), 66 ); + ensure_equals( g1->getSRID(), g2->getSRID() ); + +} + +template<> +template<> +void object::test<5>() +{ + GeomAutoPtr g1(reader.read( + "MULTILINESTRING ((0 0, 0 100, 100 100, 100 0), (15 25, 25 52))" + )); + g1->setSRID(66); + GeomAutoPtr g2(g1->clone()); + + ensure( g1->equalsExact(g2.get()) ); + ensure_equals( g1->getSRID(), 66 ); + ensure_equals( g1->getSRID(), g2->getSRID() ); + +} + +template<> +template<> +void object::test<6>() +{ + GeomAutoPtr g1(reader.read( + "MULTIPOLYGON (((0 0, 0 100, 100 100, 100 0, 0 0)))" + )); + g1->setSRID(66); + GeomAutoPtr g2(g1->clone()); + ensure( g1->equalsExact(g2.get()) ); + ensure_equals( g1->getSRID(), 66 ); + ensure_equals( g1->getSRID(), g2->getSRID() ); +} + +template<> +template<> +void object::test<7>() +{ + GeomAutoPtr g1(reader.read( + "GEOMETRYCOLLECTION(MULTIPOLYGON (((0 0, 0 100, 100 100, 100 0, 0 0))),POINT(3 4))" + )); + g1->setSRID(66); + GeomAutoPtr g2(g1->clone()); + ensure( g1->equalsExact(g2.get()) ); + ensure_equals( g1->getSRID(), 66 ); + ensure_equals( g1->getSRID(), g2->getSRID() ); +} + + +} // namespace tut + -- 2.11.4.GIT