[geos-commits] r2403 - in trunk/tests/unit: . operation/valid

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Apr 21 11:30:16 EDT 2009


Author: strk
Date: 2009-04-21 11:30:16 -0400 (Tue, 21 Apr 2009)
New Revision: 2403

Added:
   trunk/tests/unit/operation/valid/ValidClosedRingTest.cpp
Modified:
   trunk/tests/unit/Makefile.am
Log:
Port ValidClosedRingTest 


Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2009-04-21 15:13:23 UTC (rev 2402)
+++ trunk/tests/unit/Makefile.am	2009-04-21 15:30:16 UTC (rev 2403)
@@ -72,6 +72,7 @@
 	operation/overlay/OverlayResultValidatorTest.cpp \
 	operation/union/CascadedPolygonUnionTest.cpp \
 	operation/valid/IsValidTest.cpp \
+	operation/valid/ValidClosedRingTest.cpp \
 	precision/GeometrySnapperTest.cpp \
 	precision/LineStringSnapperTest.cpp \
 	precision/SimpleGeometryPrecisionReducerTest.cpp \

Added: trunk/tests/unit/operation/valid/ValidClosedRingTest.cpp
===================================================================
--- trunk/tests/unit/operation/valid/ValidClosedRingTest.cpp	                        (rev 0)
+++ trunk/tests/unit/operation/valid/ValidClosedRingTest.cpp	2009-04-21 15:30:16 UTC (rev 2403)
@@ -0,0 +1,163 @@
+// $Id$
+// 
+// Test Suite for geos::operation::valid::IsValidOp class
+// Ported from JTS junit/operation/valid/ValidClosedRingTest.java rev. 1.1
+
+#include <tut.hpp>
+// geos
+#include <geos/operation/valid/IsValidOp.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateArraySequence.h>
+#include <geos/geom/Dimension.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/LineString.h>
+#include <geos/geom/LinearRing.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/PrecisionModel.h>
+#include <geos/util/GEOSException.h>
+#include <geos/io/WKTReader.h>
+#include <geos/operation/valid/TopologyValidationError.h>
+#include <geos/platform.h> // for ISNAN
+// std
+#include <string>
+#include <memory>
+#include <iostream>
+
+using namespace geos::geom;
+//using namespace geos::operation;
+using namespace geos::operation::valid;
+using namespace geos::util;
+using namespace std;
+
+namespace tut
+{
+    //
+    // Test Group
+    //
+
+    struct test_validclosedring_data
+    {
+	typedef std::auto_ptr<Geometry> GeomPtr;
+
+        geos::geom::PrecisionModel pm_;
+        geos::geom::GeometryFactory factory_;
+        geos::io::WKTReader rdr;
+
+        test_validclosedring_data()
+			: pm_(1), factory_(&pm_, 0), rdr(&factory_)
+        {}
+
+	GeomPtr fromWKT(const std::string& wkt)
+	{
+		GeomPtr geom;
+		try {
+			geom.reset( rdr.read(wkt) );
+		}
+		catch (const GEOSException& ex) {
+			cerr << ex.what() << endl;
+		}
+		return geom;
+	}
+
+        void updateNonClosedRing(LinearRing& ring)
+	{
+		CoordinateSequence& pts = *(const_cast<CoordinateSequence*>(
+			ring.getCoordinatesRO()
+					    ));
+		Coordinate c = pts[0];
+		c.x += 0.0001;
+		pts.setAt(c, 0);
+	}
+
+	void checkIsValid(Geometry& geom, bool expected)
+	{
+		IsValidOp validator(&geom);
+		bool isValid = validator.isValid();
+		ensure_equals(isValid, expected);
+	}
+
+    };
+
+    typedef test_group<test_validclosedring_data> group;
+    typedef group::object object;
+
+    group test_validclosedring_group("geos::operation::valid::ValidClosedRing");
+
+    //
+    // Test Cases
+    //
+
+    // 1 - testBadLinearRing
+    template<>
+    template<>
+    void object::test<1>()
+    {
+	GeomPtr geom = fromWKT("LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)");
+	LinearRing* ring_chk = dynamic_cast<LinearRing*>(geom.get());
+	ensure(ring_chk);
+	LinearRing& ring = *ring_chk;
+	//cout << ring.toString() << endl;
+	updateNonClosedRing(ring);
+	//cout << ring.toString() << endl;
+	checkIsValid(*geom, false);
+    }
+
+    // 2 - testGoodLinearRing
+    template<>
+    template<>
+    void object::test<2>()
+    {
+	GeomPtr geom = fromWKT("LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)");
+	checkIsValid(*geom, true);
+    }
+
+    // 3 - testBadPolygonShell
+    template<>
+    template<>
+    void object::test<3>()
+    {
+	GeomPtr geom = fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1) ))");
+	Polygon* poly = dynamic_cast<Polygon*>(geom.get());
+	ensure(poly);
+	const LineString* ring = poly->getExteriorRing();
+
+	const LinearRing* lr = dynamic_cast<const LinearRing*>(ring);
+	ensure(lr);
+
+	LinearRing* nclr = const_cast<LinearRing*>(lr);
+
+	updateNonClosedRing(*nclr);
+	checkIsValid(*geom, false);
+    }
+
+    // 4 - testBadPolygonHole
+    template<>
+    template<>
+    void object::test<4>()
+    {
+	GeomPtr geom = fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1) ))");
+	Polygon* poly = dynamic_cast<Polygon*>(geom.get());
+	ensure(poly);
+	const LineString* ring = poly->getInteriorRingN(0);
+
+	const LinearRing* lr = dynamic_cast<const LinearRing*>(ring);
+	ensure(lr);
+
+	LinearRing* nclr = const_cast<LinearRing*>(lr);
+
+	updateNonClosedRing(*nclr);
+	checkIsValid(*geom, false);
+    }
+
+    // 5 - testGoodPolygon
+    template<>
+    template<>
+    void object::test<5>()
+    {
+	GeomPtr geom = fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
+	checkIsValid(*geom, true);
+    }
+
+
+} // namespace tut



More information about the geos-commits mailing list