[geos-commits] r2908 - in trunk: . capi tests/unit tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Feb 10 19:10:31 EST 2010


Author: strk
Date: 2010-02-10 19:10:30 -0500 (Wed, 10 Feb 2010)
New Revision: 2908

Added:
   trunk/tests/unit/capi/GEOSGeom_create.cpp
Modified:
   trunk/NEWS
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
   trunk/tests/unit/Makefile.am
Log:
GEOSContext_setNoticeHandler, GEOSContext_setErrorHandler, GEOSGeom_createEmptyPolygon_r (and test)


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2010-02-09 17:52:35 UTC (rev 2907)
+++ trunk/NEWS	2010-02-11 00:10:30 UTC (rev 2908)
@@ -2,6 +2,8 @@
 
 - New things:
   - CAPI: GEOSisValidDetail: tell state, reason & location apart
+  - CAPI: GEOSContext_setNoticeHandler, GEOSContext_setErrorHandler
+  - CAPI: GEOSGeom_createEmptyPolygon_r
 
 Changes in 3.2.0 
 

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-02-09 17:52:35 UTC (rev 2907)
+++ trunk/capi/geos_c.h.in	2010-02-11 00:10:30 UTC (rev 2908)
@@ -153,6 +153,11 @@
                                     GEOSMessageHandler error_function);
 extern void GEOS_DLL finishGEOS_r(GEOSContextHandle_t handle);
 
+extern GEOSMessageHandler GEOS_DLL GEOSContext_setNoticeHandler(GEOSContextHandle_t extHandle,
+                                                                GEOSMessageHandler nf);
+extern GEOSMessageHandler GEOS_DLL GEOSContext_setErrorHandler(GEOSContextHandle_t extHandle,
+                                                               GEOSMessageHandler nf);
+
 extern const char GEOS_DLL *GEOSversion();
 
 
@@ -430,6 +435,8 @@
 extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection(int type,
 	GEOSGeometry* *geoms, unsigned int ngeoms);
 
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon_r(
+                                       GEOSContextHandle_t handle);
 extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon_r(
                                        GEOSContextHandle_t handle,
                                        GEOSGeometry* shell,

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-02-09 17:52:35 UTC (rev 2907)
+++ trunk/capi/geos_ts_c.cpp	2010-02-11 00:10:30 UTC (rev 2908)
@@ -188,6 +188,40 @@
     return static_cast<GEOSContextHandle_t>(extHandle);
 }
 
+GEOSMessageHandler
+GEOSContext_setNoticeHandler(GEOSContextHandle_t extHandle, GEOSMessageHandler nf)
+{
+    GEOSMessageHandler f;
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return NULL;
+    }
+
+    f = handle->NOTICE_MESSAGE;
+    handle->NOTICE_MESSAGE = nf;
+
+    return f;
+}
+
+GEOSMessageHandler
+GEOSContext_setErrorHandler(GEOSContextHandle_t extHandle, GEOSMessageHandler nf)
+{
+    GEOSMessageHandler f;
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return NULL;
+    }
+
+    f = handle->ERROR_MESSAGE;
+    handle->ERROR_MESSAGE = nf;
+
+    return f;
+}
+
 void
 finishGEOS_r(GEOSContextHandle_t extHandle)
 {
@@ -3022,6 +3056,38 @@
 }
 
 Geometry *
+GEOSGeom_createEmptyPolygon_r(GEOSContextHandle_t extHandle)
+{
+    if ( 0 == extHandle )
+    {
+        return NULL;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return NULL;
+    }
+
+    try
+    {
+        const GeometryFactory *gf = handle->geomFactory;
+        return gf->createPolygon();
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+    
+    return NULL;
+}
+
+Geometry *
 GEOSGeom_createPolygon_r(GEOSContextHandle_t extHandle, Geometry *shell, Geometry **holes, unsigned int nholes)
 {
     // FIXME: holes must be non-nullptr or may be nullptr?

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2010-02-09 17:52:35 UTC (rev 2907)
+++ trunk/tests/unit/Makefile.am	2010-02-11 00:10:30 UTC (rev 2908)
@@ -91,7 +91,8 @@
 	capi/GEOSSimplifyTest.cpp \
 	capi/GEOSPreparedGeometryTest.cpp \
 	capi/GEOSPolygonizer_getCutEdgesTest.cpp \
-	capi/GEOSBufferTest.cpp
+	capi/GEOSBufferTest.cpp \
+	capi/GEOSGeom_create.cpp
 
 noinst_HEADERS = \
 	utility.h

Added: trunk/tests/unit/capi/GEOSGeom_create.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSGeom_create.cpp	                        (rev 0)
+++ trunk/tests/unit/capi/GEOSGeom_create.cpp	2010-02-11 00:10:30 UTC (rev 2908)
@@ -0,0 +1,74 @@
+// $Id: GEOSGeomToWKTTest.cpp 2424 2009-04-29 23:52:36Z mloskot $
+// 
+// Test Suite for C-API GEOSGeom_createPolygon
+
+#include <tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <string>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <memory>
+
+namespace tut
+{
+    //
+    // Test Group
+    //
+
+    // Common data used in test cases.
+    struct test_capigeosgeom_create_data
+    {
+        GEOSGeometry* geom1_;
+	GEOSContextHandle_t handle_;
+
+        static void notice(const char *fmt, ...)
+        {
+            std::fprintf( stdout, "NOTICE: ");
+
+            va_list ap;
+            va_start(ap, fmt);
+            std::vfprintf(stdout, fmt, ap);
+            va_end(ap);
+        
+            std::fprintf(stdout, "\n");
+        }
+
+        test_capigeosgeom_create_data()
+            : geom1_(0), handle_(initGEOS_r(notice, notice))
+        {
+        }       
+
+        ~test_capigeosgeom_create_data()
+        {
+            GEOSGeom_destroy(geom1_); geom1_ = 0;
+            finishGEOS_r(handle_);
+        }
+
+    };
+
+    typedef test_group<test_capigeosgeom_create_data> group;
+    typedef group::object object;
+
+    group test_capigeosgeom_create_group("capi::GEOSGeom_create");
+
+    //
+    // Test Cases
+    //
+
+    // EMPTY polygon
+    template<>
+    template<>
+    void object::test<1>()
+    {
+        geom1_ = GEOSGeom_createEmptyPolygon_r(handle_);
+        ensure(GEOSisEmpty_r(handle_, geom1_));
+	ensure_equals(GEOSGeomTypeId_r(handle_, geom1_), GEOS_POLYGON);
+	GEOSGeom_destroy(geom1_); geom1_=0;
+    }
+    
+
+} // namespace tut
+



More information about the geos-commits mailing list