[geos-commits] r2162 - in trunk/tests/unit: . algorithm geom geom/prep simplify

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Aug 18 12:30:56 EDT 2008


Author: mloskot
Date: 2008-08-18 12:30:56 -0400 (Mon, 18 Aug 2008)
New Revision: 2162

Modified:
   trunk/tests/unit/algorithm/ConvexHullTest.cpp
   trunk/tests/unit/geom/GeometryFactoryTest.cpp
   trunk/tests/unit/geom/LineStringTest.cpp
   trunk/tests/unit/geom/MultiLineStringTest.cpp
   trunk/tests/unit/geom/MultiPointTest.cpp
   trunk/tests/unit/geom/PolygonTest.cpp
   trunk/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
   trunk/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
   trunk/tests/unit/utility.h
Log:
tests/unit: added tests cases to PreparedGeometryFactoryTest, refactored casting utils and geometry comparators, small cleanup.

Modified: trunk/tests/unit/algorithm/ConvexHullTest.cpp
===================================================================
--- trunk/tests/unit/algorithm/ConvexHullTest.cpp	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/algorithm/ConvexHullTest.cpp	2008-08-18 16:30:56 UTC (rev 2162)
@@ -3,9 +3,6 @@
 // Test Suite for geos::algorithm::ConvexHull
 // Ported from JTS junit/algorithm/ConvexHullTest.java
 
-// tut
-#include <tut.h>
-#include <utility.h>
 // geos
 #include <geos/algorithm/ConvexHull.h>
 #include <geos/geom/LineString.h>
@@ -19,6 +16,9 @@
 // std
 #include <sstream>
 #include <memory>
+// tut
+#include <tut.h>
+#include <utility.h>
 
 namespace geos {
 	namespace geom {
@@ -65,7 +65,6 @@
     void object::test<1>()
     {   
         using geos::geom::LineString;
-        using utility::dynamic_cast_auto_ptr;
 
         GeometryAPtr lineGeom(reader_.read("LINESTRING (30 220, 240 220, 240 220)"));
         LineStringAPtr line(dynamic_cast_auto_ptr<LineString>(lineGeom));
@@ -84,7 +83,6 @@
     void object::test<2>()
     {   
         using geos::geom::LineString;
-        using utility::dynamic_cast_auto_ptr;
 
         GeometryAPtr geom(reader_.read("MULTIPOINT (130 240, 130 240, 130 240, 570 240, 570 240, 570 240, 650 240)"));
         ensure(0 != geom.get());
@@ -102,7 +100,6 @@
     void object::test<3>()
     {   
         using geos::geom::LineString;
-        using utility::dynamic_cast_auto_ptr;
 
         GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 10 0)"));
         ensure(0 != geom.get());
@@ -120,7 +117,6 @@
     void object::test<4>()
     {   
         using geos::geom::LineString;
-        using utility::dynamic_cast_auto_ptr;
 
         GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 10 0, 10 0)"));
         ensure(0 != geom.get());
@@ -138,7 +134,6 @@
     void object::test<5>()
     {   
         using geos::geom::LineString;
-        using utility::dynamic_cast_auto_ptr;
 
         GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 0, 10 0)"));
         ensure(0 != geom.get());
@@ -156,7 +151,6 @@
     void object::test<6>()
     {   
         using geos::geom::LineString;
-        using utility::dynamic_cast_auto_ptr;
 
         GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 1, 10 0)"));
         ensure(0 != geom.get());
@@ -176,7 +170,6 @@
     void object::test<7>()
     {   
         using geos::geom::LineString;
-        using utility::dynamic_cast_auto_ptr;
 
         GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 5 0, 5 0, 10 0, 10 0)"));
         ensure(0 != geom.get());
@@ -189,3 +182,4 @@
     }
 
 } // namespace tut
+

Modified: trunk/tests/unit/geom/GeometryFactoryTest.cpp
===================================================================
--- trunk/tests/unit/geom/GeometryFactoryTest.cpp	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/geom/GeometryFactoryTest.cpp	2008-08-18 16:30:56 UTC (rev 2162)
@@ -2,9 +2,7 @@
 // 
 // Test Suite for geos::geom::GeometryFactory class.
 
-// TUT
-#include <tut.h>
-// GEOS
+// geos
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/GeometryCollection.h>
 #include <geos/geom/Coordinate.h>
@@ -22,9 +20,12 @@
 #include <geos/geom/PrecisionModel.h>
 #include <geos/io/WKTReader.h>
 #include <geos/util/IllegalArgumentException.h>
-// STL
+// std
 #include <vector>
 #include <cstring> // std::size_t
+// tut
+#include <tut.h>
+#include <utility.h>
 
 /*!
  * \brief
@@ -47,36 +48,6 @@
 	// Common data used by tests
 	struct test_geometryfactory_data
 	{
-		// Typedefs used as short names by test cases
-
-		typedef geos::geom::Coordinate* CoordinatePtr;
-		typedef geos::geom::Coordinate const* CoordinateCPtr;
-
-		typedef geos::geom::CoordinateArraySequence* CoordArrayPtr;
-		typedef geos::geom::CoordinateArraySequence const* CoordArrayCPtr;
-		
-		typedef geos::geom::Geometry* GeometryPtr;
-		typedef geos::geom::Geometry const* GeometryCPtr;
-
-		typedef geos::geom::Point* PointPtr;
-		typedef geos::geom::Point const* PointCPtr;
-		typedef geos::geom::LinearRing* LinearRingPtr;
-		typedef geos::geom::LinearRing const* LinearRingCPtr;
-		typedef geos::geom::LineString* LineStringPtr;
-		typedef geos::geom::LineString const* LineStringCPtr;
-		typedef geos::geom::Polygon* PolygonPtr;
-		typedef geos::geom::Polygon const* PolygonCPtr;
-
-		typedef geos::geom::GeometryCollection* GeometryColPtr;
-		typedef geos::geom::GeometryCollection const* GeometryColCPtr;
-
-		typedef geos::geom::MultiPoint* MultiPointPtr;
-		typedef geos::geom::MultiPoint const* MultiPointCPtr;
-		typedef geos::geom::MultiLineString* MultiLineStringPtr;
-		typedef geos::geom::MultiLineString const* MultiLineStringCPtr;
-		typedef geos::geom::MultiPolygon* MultiPolygonPtr;
-		typedef geos::geom::MultiPolygon const* MultiPolygonCPtr;
-
 		// Test data
 		const int x_;
 		const int y_;

Modified: trunk/tests/unit/geom/LineStringTest.cpp
===================================================================
--- trunk/tests/unit/geom/LineStringTest.cpp	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/geom/LineStringTest.cpp	2008-08-18 16:30:56 UTC (rev 2162)
@@ -2,9 +2,7 @@
 // 
 // Test Suite for geos::geom::LineString class.
 
-// TUT
-#include <tut.h>
-// GEOS
+// geos
 #include <geos/geom/LineString.h>
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/CoordinateArraySequence.h>
@@ -15,9 +13,12 @@
 #include <geos/io/WKTReader.h>
 #include <geos/util/GEOSException.h>
 #include <geos/util/IllegalArgumentException.h>
-// STL
+// std 
 #include <cmath>
 #include <string>
+// tut
+#include <tut.h>
+#include <utility.h>
 
 namespace tut
 {
@@ -29,18 +30,7 @@
     struct test_linestring_data
     {
 		// Typedefs used as short names by test cases
-		typedef geos::geom::Geometry* GeometryPtr;
-		typedef geos::geom::Geometry const* GeometryCPtr;
-
-		typedef geos::geom::Coordinate* CoordinatePtr;
-		typedef geos::geom::Coordinate const* CoordinateCPtr;
-
-		typedef geos::geom::CoordinateArraySequence* CoordArrayPtr;
-		typedef geos::geom::CoordinateArraySequence const* CoordArrayCPtr;
-
-		typedef geos::geom::LineString* LineStringPtr;
 		typedef std::auto_ptr<geos::geom::LineString> LineStringAutoPtr;
-		typedef geos::geom::LineString const* LineStringCPtr;
 
 		geos::geom::PrecisionModel pm_;
 		geos::geom::GeometryFactory factory_;
@@ -506,3 +496,4 @@
 	}
 
 } // namespace tut
+

Modified: trunk/tests/unit/geom/MultiLineStringTest.cpp
===================================================================
--- trunk/tests/unit/geom/MultiLineStringTest.cpp	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/geom/MultiLineStringTest.cpp	2008-08-18 16:30:56 UTC (rev 2162)
@@ -2,10 +2,10 @@
 // 
 // Test Suite for geos::geom::MultiLineString class.
 
-// TUT
+// geos
+#include <geos/geom/MultiLineString.h>
+// tut
 #include <tut.h>
-// GEOS
-#include <geos/geom/MultiLineString.h>
 
 namespace tut
 {
@@ -37,3 +37,4 @@
     }
 
 } // namespace tut
+

Modified: trunk/tests/unit/geom/MultiPointTest.cpp
===================================================================
--- trunk/tests/unit/geom/MultiPointTest.cpp	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/geom/MultiPointTest.cpp	2008-08-18 16:30:56 UTC (rev 2162)
@@ -2,9 +2,7 @@
 // 
 // Test Suite for geos::geom::MultiPoint class.
 
-// TUT
-#include <tut.h>
-// GEOS
+// geos
 #include <geos/geom/MultiPoint.h>
 #include <geos/geom/Dimension.h>
 #include <geos/geom/Geometry.h>
@@ -12,8 +10,11 @@
 #include <geos/geom/PrecisionModel.h>
 #include <geos/io/ParseException.h>
 #include <geos/io/WKTReader.h>
-// STL
+// std
 #include <cmath>
+// tut
+#include <tut.h>
+#include <utility.h>
 
 namespace tut
 {
@@ -24,15 +25,7 @@
 	// Common data used by tests
 	struct test_multipoint_data
 	{
-		typedef geos::geom::Geometry* GeometryPtr;
-		typedef geos::geom::Geometry const* GeometryCPtr;
-
-		typedef geos::geom::Point* PointPtr;
-		typedef geos::geom::Point const* PointCPtr;
-
-		typedef geos::geom::MultiPoint* MultiPointPtr;
 		typedef std::auto_ptr<geos::geom::MultiPoint> MultiPointAutoPtr;
-		typedef geos::geom::MultiPoint const* MultiPointCPtr;
 
 		geos::geom::PrecisionModel pm_;
 		geos::geom::GeometryFactory factory_;
@@ -382,3 +375,4 @@
 	}
 
 } // namespace tut
+

Modified: trunk/tests/unit/geom/PolygonTest.cpp
===================================================================
--- trunk/tests/unit/geom/PolygonTest.cpp	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/geom/PolygonTest.cpp	2008-08-18 16:30:56 UTC (rev 2162)
@@ -2,9 +2,7 @@
 // 
 // Test Suite for geos::geom::Polygon class.
 
-// TUT
-#include <tut.h>
-// GEOS
+// geos
 #include <geos/geom/Polygon.h>
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/CoordinateSequence.h>
@@ -17,9 +15,12 @@
 #include <geos/geom/PrecisionModel.h>
 #include <geos/io/WKTReader.h>
 #include <geos/util/IllegalArgumentException.h>
-// STL
+// std
 #include <cmath>
 #include <string>
+// tut
+#include <tut.h>
+#include <utility.h>
 
 namespace tut
 {
@@ -31,27 +32,7 @@
     struct test_polygon_data
     {
 		// Typedefs used as short names by test cases
-		typedef geos::geom::Geometry* GeometryPtr;
-		typedef geos::geom::Geometry const* GeometryCPtr;
 		typedef std::auto_ptr<geos::geom::Geometry> GeometryAutoPtr;
-
-		typedef geos::geom::Coordinate* CoordinatePtr;
-		typedef geos::geom::Coordinate const* CoordinateCPtr;
-		typedef geos::geom::CoordinateSequence* CoordSeqPtr;
-		typedef geos::geom::CoordinateSequence const* CoordSeqCPtr;
-		typedef geos::geom::CoordinateArraySequence* CoordArrayPtr;
-		typedef geos::geom::CoordinateArraySequence const* CoordArrayCPtr;
-
-		typedef geos::geom::Envelope* EnvelopePtr;
-		typedef geos::geom::Envelope const* EnvelopeCPtr;
-		typedef geos::geom::Point* PointPtr;
-		typedef geos::geom::Point const* PointCPtr;
-		typedef geos::geom::LineString* LineStringPtr;
-		typedef geos::geom::LineString const* LineStringCPtr;
-		typedef geos::geom::LinearRing* LinearRingPtr;
-		typedef geos::geom::LinearRing const* LinearRingCPtr;
-		typedef geos::geom::Polygon* PolygonPtr;
-		typedef geos::geom::Polygon const* PolygonCPtr;
 		typedef std::auto_ptr<geos::geom::Polygon> PolygonAutoPtr;
 
 		geos::geom::PrecisionModel pm_;
@@ -64,7 +45,7 @@
 
 		test_polygon_data() 
 			: pm_(1), factory_(&pm_, 0), reader_(&factory_),
-			empty_poly_(factory_.createPolygon()), poly_size_(7)
+                empty_poly_(factory_.createPolygon()), poly_size_(7)
 		{
 			// Create non-empty LinearRing
 			GeometryPtr geo = 0;

Modified: trunk/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
===================================================================
--- trunk/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp	2008-08-18 16:30:56 UTC (rev 2162)
@@ -2,18 +2,20 @@
 // 
 // Test Suite for geos::geom::prep::PreparedGeometryFactory class.
 
-// TUT
-#include <tut.h>
-// GEOS
+// geos
+#include <geos/geom/prep/PreparedGeometryFactory.h>
+#include <geos/geom/prep/PreparedGeometry.h>
+#include <geos/geom/GeometryFactory.h>
 #include <geos/geom/Geometry.h>
-#include <geos/geom/GeometryFactory.h>
-#include <geos/geom/prep/PreparedGeometry.h>
-#include <geos/geom/prep/PreparedGeometryFactory.h>
 #include <geos/io/WKTReader.h>
 #include <geos/util/IllegalArgumentException.h>
-// STL
+#include <geos/util.h>
+// std
 #include <vector>
 #include <cstring> // std::size_t
+// tut
+#include <tut.h>
+#include <utility.h>
 
 using namespace geos::geom;
 
@@ -26,6 +28,28 @@
     // Common data used by tests
     struct test_preparedgeometryfactory_data
     {
+        GeometryPtr g_;
+        PreparedGeometryPtr pg_;
+        geos::geom::PrecisionModel pm_;
+        geos::geom::GeometryFactory factory_;
+        geos::io::WKTReader reader_;
+
+        test_preparedgeometryfactory_data()
+            : g_(0), pg_(0), pm_(1.0), factory_(&pm_), reader_(&factory_)
+        {
+            assert(0 == g_);
+            assert(0 == pg_);
+        }
+        
+        ~test_preparedgeometryfactory_data()
+        {
+            // FREE MEMORY per test case
+            prep::PreparedGeometryFactory::destroy(pg_);
+            factory_.destroyGeometry(g_);
+            pg_ = 0;
+            g_ = 0;
+        }
+
     };
 
     typedef test_group<test_preparedgeometryfactory_data> group;
@@ -43,7 +67,7 @@
     void object::test<1>()
     {
         prep::PreparedGeometryFactory pgf;
-        (void)pgf;
+        UNREFERENCED_PARAMETER(pgf);
     }
 
     // Test passing null-pointer to prepare static method
@@ -51,7 +75,7 @@
     template<>
     void object::test<2>()
     {
-        // FIXME: null pointer throws segfault (Ticket #197)
+        // FIXME - mloskot: null pointer throws segfault (Ticket #197)
         // ensure(0 == prep::PreparedGeometryFactory::prepare(0));
     }
 
@@ -61,46 +85,387 @@
     void object::test<3>()
     {
         prep::PreparedGeometryFactory pgf;
-        (void)pgf;
+        UNREFERENCED_PARAMETER(pgf);
 
-        // FIXME: null pointer throws segfault (Ticket #197)
+        // FIXME - mloskot: null pointer throws segfault (Ticket #197)
         // ensure(0 == pgf.create(0));
     }
 
-    // Test prepare with empty POINT
+    // Test prepare empty GEOMETRY
     template<>
     template<>
     void object::test<4>()
     {
-        GeometryFactory gf;
-        Geometry* g = gf.createEmptyGeometry();
-        ensure( 0 != g );
+        g_ = factory_.createEmptyGeometry();
+        ensure( 0 != g_ );
         
-        prep::PreparedGeometry const* pg = prep::PreparedGeometryFactory::prepare(g);
-        ensure( 0 != pg );
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
 
-        // FREE MEMORY
-        prep::PreparedGeometryFactory::destroy(pg);
-        gf.destroyGeometry(g);
+        ensure_equals_geometry( g_, pg_ );
     }
 
-    // Test create with empty POINT
+    // Test create empty GEOMETRY
     template<>
     template<>
     void object::test<5>()
     {
-        GeometryFactory gf;
-        Geometry* g = gf.createEmptyGeometry();
-        ensure( 0 != g );
+        g_ = factory_.createEmptyGeometry();
+        ensure( 0 != g_ );
         
         prep::PreparedGeometryFactory pgf;
-        prep::PreparedGeometry const* pg = pgf.create(g);
-        ensure( 0 != pg );
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
         
-        // FREE MEMORY
-        prep::PreparedGeometryFactory::destroy(pg);
-        gf.destroyGeometry(g);
+        ensure_equals_geometry( g_, pg_ );
     }
+    
+    // Test prepare empty POINT
+    template<>
+    template<>
+    void object::test<6>()
+    {
+        g_ = factory_.createPoint();
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
 
+    // Test create empty POINT
+    template<>
+    template<>
+    void object::test<7>()
+    {
+        g_ = factory_.createPoint();
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test prepare empty LINESTRING
+    template<>
+    template<>
+    void object::test<8>()
+    {
+        g_ = factory_.createLineString();
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+
+        ensure_equals_geometry( g_, pg_ );
+    }
+
+    // Test create empty LINESTRING
+    template<>
+    template<>
+    void object::test<9>()
+    {
+        g_ = factory_.createLineString();
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test prepare empty POLYGON
+    template<>
+    template<>
+    void object::test<10>()
+    {
+        g_ = factory_.createPolygon();
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+
+    // Test create empty POLYGON
+    template<>
+    template<>
+    void object::test<11>()
+    {
+        g_ = factory_.createPolygon();
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test prepare empty MULTIPOINT
+    template<>
+    template<>
+    void object::test<12>()
+    {
+        g_ = factory_.createMultiPoint();
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+
+    // Test create empty MULTIPOINT
+    template<>
+    template<>
+    void object::test<13>()
+    {
+        g_ = factory_.createMultiPoint();
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test prepare empty MULTILINESTRING
+    template<>
+    template<>
+    void object::test<14>()
+    {
+        g_ = factory_.createMultiLineString();
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+
+    // Test create empty MULTILINESTRING
+    template<>
+    template<>
+    void object::test<15>()
+    {
+        g_ = factory_.createMultiLineString();
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test prepare empty MULTIPOLYGON
+    template<>
+    template<>
+    void object::test<16>()
+    {
+        g_ = factory_.createMultiPolygon();
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+
+    // Test create empty MULTIPOLYGON
+    template<>
+    template<>
+    void object::test<17>()
+    {
+        g_ = factory_.createMultiPolygon();
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+
+    // Test prepare non-empty POINT
+    template<>
+    template<>
+    void object::test<18>()
+    {
+        g_ = reader_.read("POINT(1.234 5.678)");
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test create non-empty POINT
+    template<>
+    template<>
+    void object::test<19>()
+    {
+        g_ = reader_.read("POINT(1.234 5.678)");
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+
+    // Test prepare non-empty LINESTRING
+    template<>
+    template<>
+    void object::test<20>()
+    {
+		g_ = reader_.read("LINESTRING (0 0, 5 5, 10 5, 10 10)");
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test create non-empty LINESTRING
+    template<>
+    template<>
+    void object::test<21>()
+    {
+		g_ = reader_.read("LINESTRING (0 0, 5 5, 10 5, 10 10)");
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test prepare non-empty LINESTRING
+    template<>
+    template<>
+    void object::test<22>()
+    {
+        g_ = reader_.read("POLYGON((0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))");
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test create non-empty LINESTRING
+    template<>
+    template<>
+    void object::test<23>()
+    {
+        g_ = reader_.read("POLYGON((0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))");
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+  
+    // Test prepare non-empty MULTIPOINT
+    template<>
+    template<>
+    void object::test<24>()
+    {
+        g_ = reader_.read("MULTIPOINT(0 0, 5 5, 10 10, 15 15, 20 20)");
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test create non-empty MULTIPOINT
+    template<>
+    template<>
+    void object::test<25>()
+    {
+        g_ = reader_.read("MULTIPOINT(0 0, 5 5, 10 10, 15 15, 20 20)");
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+
+    // Test prepare non-empty MULTILINESTRING
+    template<>
+    template<>
+    void object::test<26>()
+    {
+		g_ = reader_.read("MULTILINESTRING ((20 120, 120 20), (20 20, 120 120))");
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test create non-empty MULTILINESTRING
+    template<>
+    template<>
+    void object::test<27>()
+    {
+		g_ = reader_.read("MULTILINESTRING ((20 120, 120 20), (20 20, 120 120))");
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test prepare non-empty POLYGON
+    template<>
+    template<>
+    void object::test<28>()
+    {
+        g_ = reader_.read("MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0),(2 2, 2 6, 6 4, 2 2)),((60 60, 60 50, 70 40, 60 60)))");
+        ensure( 0 != g_ );
+        
+        pg_ = prep::PreparedGeometryFactory::prepare(g_);
+        ensure( 0 != pg_ );
+
+        ensure_equals_geometry( g_, pg_ );
+    }
+    
+    // Test create non-empty POLYGON
+    template<>
+    template<>
+    void object::test<29>()
+    {
+        g_ = reader_.read("MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0),(2 2, 2 6, 6 4, 2 2)),((60 60, 60 50, 70 40, 60 60)))");
+        ensure( 0 != g_ );
+        
+        prep::PreparedGeometryFactory pgf;
+        pg_ = pgf.create(g_);
+        ensure( 0 != pg_ );
+        
+        ensure_equals_geometry( g_, pg_ );
+    }
+
 } // namespace tut
 

Modified: trunk/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
===================================================================
--- trunk/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp	2008-08-18 16:30:56 UTC (rev 2162)
@@ -2,19 +2,19 @@
 // 
 // Test Suite for geos::simplify::TopologyPreservingSimplifier
 
-// TUT
-#include <tut.h>
-#include "utility.h"
-// GEOS
+// geos
 #include <geos/io/WKTReader.h>
 #include <geos/geom/PrecisionModel.h>
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/Geometry.h>
 #include <geos/geom/LineString.h>
 #include <geos/simplify/TopologyPreservingSimplifier.h>
-// C++ SL
+// std
 #include <string>
 #include <memory>
+// tut
+#include <tut.h>
+#include <utility.h>
 
 namespace tut
 {
@@ -34,10 +34,7 @@
 		typedef geos::geom::Geometry::AutoPtr GeomPtr;
 
 		test_tpsimp_data()
-			:
-			pm(1.0),
-			gf(&pm),
-			wktreader(&gf)
+            : pm(1.0), gf(&pm), wktreader(&gf)
 		{}
 	};
 
@@ -63,8 +60,8 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-		ensure( simplified->equals(g.get()) );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+		ensure( "Simplified and original geometry inequal", simplified->equals(g.get()) );
+        ensure_equals_geometry( g.get(), simplified.get() );
 	}
 
     // PolygonNoReductionWithConflicts
@@ -80,7 +77,7 @@
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
 		ensure( "Topology has been changed by simplification!", simplified->equals(g.get()) );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry( g.get(), simplified.get() );
     }
 
     // PolygonWithTouchingHole
@@ -98,7 +95,7 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry( g.get(), simplified.get() );
 
         GeomPtr g_expected(wktreader.read(wkt_expected));
 
@@ -117,7 +114,7 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry( g.get(), simplified.get() );
     }
 
     // PolygonWithFlattishHole
@@ -134,7 +131,7 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry( g.get(), simplified.get() );
         ensure( g_expected->equalsExact(simplified.get()) );
     }
 
@@ -149,7 +146,7 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry( g.get(), simplified.get() );
     }
 
     // TinyLineString
@@ -163,7 +160,7 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry(g.get(), simplified.get() );
     }
 
     // MultiPoint
@@ -178,7 +175,7 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry(g.get(), simplified.get() );
     }
 
     // MultiLineString
@@ -193,7 +190,7 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry(g.get(), simplified.get() );
     }
     
     // GeometryCollection
@@ -210,7 +207,7 @@
 		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);
 
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
-        ensure( utility::isSameStructure(g.get(), simplified.get()) );
+        ensure_equals_geometry(g.get(), simplified.get() );
     }
 } // namespace tut
 

Modified: trunk/tests/unit/utility.h
===================================================================
--- trunk/tests/unit/utility.h	2008-08-18 16:29:09 UTC (rev 2161)
+++ trunk/tests/unit/utility.h	2008-08-18 16:30:56 UTC (rev 2162)
@@ -1,38 +1,92 @@
 // $Id$
 // 
-// Utility for GEOS Test Suite
+// GEOS Unit Test utilities, extension of TUT Framework namespace
 //
-#ifndef UTILITY_H_INCLUDED
-#define UTILITY_H_INCLUDED
+#ifndef GEOS_TUT_UTILITY_H_INCLUDED
+#define GEOS_TUT_UTILITY_H_INCLUDED 
 
+// geos
 #include <geos/geom/Geometry.h>
 #include <geos/geom/GeometryCollection.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateArraySequence.h>
+#include <geos/geom/CoordinateArraySequenceFactory.h>
+#include <geos/geom/CoordinateSequenceFactory.h>
+#include <geos/geom/Dimension.h>
+#include <geos/geom/Point.h>
 #include <geos/geom/Polygon.h>
-
-#include <iostream>
+#include <geos/geom/LinearRing.h>
+#include <geos/geom/LineString.h>
+#include <geos/geom/MultiPoint.h>
+#include <geos/geom/MultiLineString.h>
+#include <geos/geom/MultiPolygon.h>
+#include <geos/geom/PrecisionModel.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/prep/PreparedGeometry.h>
+#include <geos/io/WKTReader.h>
+// std
 #include <memory>
+#include <cstdlib>
 #include <cassert>
+// tut
+#include <tut.h>
 
+namespace tut
+{
+
 //
-// GEOS Unit Test utilities
+// Helper typedefs
 //
-namespace utility
-{
+typedef geos::geom::Coordinate* CoordinatePtr;
+typedef geos::geom::Coordinate const* CoordinateCPtr;
 
+typedef geos::geom::CoordinateSequence* CoordSeqPtr;
+typedef geos::geom::CoordinateSequence const* CoordSeqCPtr;
+
+typedef geos::geom::CoordinateArraySequence* CoordArrayPtr;
+typedef geos::geom::CoordinateArraySequence const* CoordArrayCPtr;
+
+typedef geos::geom::Geometry* GeometryPtr;
+typedef geos::geom::Geometry const* GeometryCPtr;
+
+typedef geos::geom::Point* PointPtr;
+typedef geos::geom::Point const* PointCPtr;
+typedef geos::geom::LinearRing* LinearRingPtr;
+typedef geos::geom::LinearRing const* LinearRingCPtr;
+typedef geos::geom::LineString* LineStringPtr;
+typedef geos::geom::LineString const* LineStringCPtr;
+typedef geos::geom::Polygon* PolygonPtr;
+typedef geos::geom::Polygon const* PolygonCPtr;
+
+typedef geos::geom::GeometryCollection* GeometryColPtr;
+typedef geos::geom::GeometryCollection const* GeometryColCPtr;
+
+typedef geos::geom::MultiPoint* MultiPointPtr;
+typedef geos::geom::MultiPoint const* MultiPointCPtr;
+typedef geos::geom::MultiLineString* MultiLineStringPtr;
+typedef geos::geom::MultiLineString const* MultiLineStringCPtr;
+typedef geos::geom::MultiPolygon* MultiPolygonPtr;
+typedef geos::geom::MultiPolygon const* MultiPolygonCPtr;
+
+// prepared geometries always returend as const
+typedef geos::geom::prep::PreparedGeometry const* PreparedGeometryPtr;
+
 //
 // Type cast helper utilities
 //
 
-template<class Type, class InstanceType>
-inline bool isInstanceOf(InstanceType* instance)
+template<typename Type, typename InstanceType>
+inline bool isInstanceOf(InstanceType const* instance)
 {
-    return ( 0 != dynamic_cast<Type *>(instance) );
+    assert(0 != instance);
+    return (0 != dynamic_cast<Type const*>(instance) );
 }
 
-template<class Type, class InstanceType>
-inline Type* instanceOf(InstanceType* instance)
+template<typename Type, typename InstanceType>
+inline Type const* instanceOf(InstanceType const* instance)
 {
-    return dynamic_cast<Type *>(instance);
+    assert(0 != instance);
+    return dynamic_cast<Type const*>(instance);
 }
 
 template <typename Dst, typename Src>
@@ -56,91 +110,112 @@
 // Geometries structure comparators
 //
 
-template <class T1, class T2>
-inline bool isSameStructure(T1 lhs, T2 rhs)
+template <typename T1, typename T2>
+inline void ensure_equals_geometry(T1 const* lhs, T2 const* rhs)
 {
-    // Different types can't have the smame structure
-    return false;
+    assert(0 != lhs);
+    assert(0 != rhs);
+
+    assert(!"DIFFERENT TYPES ARE NOT OF THE SAME STRUCTURE");
 }
 
-template <class T>
-inline bool isSameStructure(T* lhs, T* rhs)
+template <typename T>
+inline void ensure_equals_geometry(T const* lhs, T const* rhs)
 {
+    assert(0 != lhs);
+    assert(0 != rhs);
+
     using geos::geom::Polygon;
     using geos::geom::GeometryCollection;
     
-    assert( 0 != lhs );
-    assert( 0 != rhs );
+    ensure_equals("is-valid do not match",
+                  lhs->isValid(), rhs->isValid());
 
-    // Both are empty
-    if (!(lhs->isEmpty() == rhs->isEmpty()))
-        return false;
+    ensure_equals("is-empty do not match",
+                  lhs->isEmpty(), rhs->isEmpty());
 
-    // Both are non-empty
-    if (!(!lhs->isEmpty()) == (!rhs->isEmpty()))
-        return false;
+    if (!isInstanceOf<GeometryCollection>(lhs)
+         && !isInstanceOf<GeometryCollection>(rhs))
+    {
+        ensure_equals("is-simple do not match",
+                      lhs->isSimple(), rhs->isSimple());
+    }
 
-    // Both are valid
-    if (!(lhs->isValid() == rhs->isValid()))
-        return false;
+    ensure_equals("type do not match",
+                  lhs->getGeometryType(), rhs->getGeometryType());
 
+    ensure_equals("type id do not match",
+                  lhs->getGeometryTypeId(), rhs->getGeometryTypeId());
+
+    ensure_equals("dimension do not match",
+                  lhs->getDimension(), rhs->getDimension());
+
+    ensure_equals("boundary dimension do not match",
+                  lhs->getBoundaryDimension(), rhs->getBoundaryDimension());
+
+    // NOTE - mloskot: Intentionally disabled, so simplified geometry
+    // can be compared to its original
+    //ensure_equals("number of points do not match",
+    //              lhs->getNumPoints(), rhs->getNumPoints());
+
     // Dispatch to run more specific testes
     if (isInstanceOf<Polygon>(lhs)
         && isInstanceOf<Polygon>(rhs))
     {
-        return isSameStructure(instanceOf<Polygon>(lhs),
-                               instanceOf<Polygon>(rhs));
+        ensure_equals_geometry(instanceOf<Polygon>(lhs),
+                        instanceOf<Polygon>(rhs));
     }
     else if (isInstanceOf<GeometryCollection>(lhs)
-            && isInstanceOf<GeometryCollection>(rhs))
+             && isInstanceOf<GeometryCollection>(rhs))
     {
-        return isSameStructure(instanceOf<GeometryCollection>(lhs),
-                               instanceOf<GeometryCollection>(rhs));
+        ensure_equals_geometry(instanceOf<GeometryCollection>(lhs),
+                        instanceOf<GeometryCollection>(rhs));
     }
-
-    return true;
 }
 
 template <>
-inline bool isSameStructure(geos::geom::Polygon* lhs,
-                            geos::geom::Polygon* rhs)
+inline void ensure_equals_geometry(geos::geom::Polygon const* lhs,
+                                   geos::geom::Polygon const* rhs)
 {
-    assert( 0 != lhs );
-    assert( 0 != rhs );
+    assert(0 != lhs);
+    assert(0 != rhs);
 
-    return (lhs->getNumInteriorRing() == rhs->getNumInteriorRing());
+    ensure_equals("number of interior ring do not match",
+                  lhs->getNumInteriorRing(), rhs->getNumInteriorRing());
 }
 
 template <>
-inline bool isSameStructure(geos::geom::GeometryCollection* lhs,
-                            geos::geom::GeometryCollection* rhs)
+inline void ensure_equals_geometry(geos::geom::GeometryCollection const* lhs,
+                                   geos::geom::GeometryCollection const* rhs)
 {
+    assert(0 != lhs);
+    assert(0 != rhs);
+
     using geos::geom::Geometry;
 
-    assert( 0 != lhs );
-    assert( 0 != rhs );
+    ensure_equals("number of geometries do not match",
+                  lhs->getNumGeometries(), rhs->getNumGeometries());
 
-    if (lhs->getNumGeometries() != rhs->getNumGeometries())
-        return false;
-
     for (std::size_t i = 0, n = lhs->getNumGeometries(); i < n; ++i)
     {
-        // Dirty, but necessary!
-        // isSameStructure promises to not to try to change geometries
-        // @@ why doesn't you take const pointers ?
-        Geometry* g1 = const_cast<Geometry*>(lhs->getGeometryN(i));
-        Geometry* g2 = const_cast<Geometry*>(rhs->getGeometryN(i));
-        if (!isSameStructure(g1, g2))
-        {
-            return false;
-        }
+        Geometry const* g1 = lhs->getGeometryN(i);
+        Geometry const* g2 = rhs->getGeometryN(i);
+        ensure_equals_geometry(g1, g2); // breaks on failure 
     }
+}
 
-    return true;
+template <>
+inline void ensure_equals_geometry(geos::geom::Geometry const* lhs,
+                                   geos::geom::prep::PreparedGeometry const* rhs)
+{
+    assert(0 != lhs);
+    assert(0 != rhs);
+    
+    geos::geom::Geometry const& pg = rhs->getGeometry();
+    ensure_equals_geometry(lhs, &pg);
 }
 
-} // namespace unit
+} // namespace tut
 
-#endif // #ifndef UTILITY_H_INCLUDED
+#endif // #ifndef GEOS_TUT_UTILITY_H_INCLUDED
 
-



More information about the geos-commits mailing list