[geos-commits] [SCM] GEOS branch main updated. b3c6777b99fdec10a4cbdf26005697df0111f67d

git at osgeo.org git at osgeo.org
Fri Nov 17 17:51:18 PST 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, main has been updated
       via  b3c6777b99fdec10a4cbdf26005697df0111f67d (commit)
      from  18ba837b7ee44bf1f074df6fbbc1b4bbb7e6dc0c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b3c6777b99fdec10a4cbdf26005697df0111f67d
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Fri Nov 17 17:50:16 2023 -0800

    Clean up CAPI tests to use the CAPI helper headers more and
    be a little more terse.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a7b9773f6..0538293ca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -185,8 +185,8 @@ message(STATUS "GEOS: Archives output: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
 #  ./bin/test_geos_unit
 #
 
-set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -fno-common")
-set(CMAKE_CXX_FLAGS_ASAN "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -fno-common")
+set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_DEBUG} -g -O0 -fsanitize=address -fno-omit-frame-pointer -fno-common")
+set(CMAKE_CXX_FLAGS_ASAN "${CMAKE_CXX_FLAGS_DEBUG}  -g -O0 -fsanitize=address -fno-omit-frame-pointer -fno-common")
 set(CMAKE_EXE_LINKER_FLAGS_ASAN "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address")
 set(CMAKE_SHARED_LINKER_FLAGS_ASAN "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address")
 
diff --git a/tests/unit/capi/GEOSBoundaryTest.cpp b/tests/unit/capi/GEOSBoundaryTest.cpp
index b65883353..005ab388e 100644
--- a/tests/unit/capi/GEOSBoundaryTest.cpp
+++ b/tests/unit/capi/GEOSBoundaryTest.cpp
@@ -20,19 +20,16 @@ template<>
 template<>
 void object::test<1>()
 {
-    GEOSGeometry* input = GEOSGeomFromWKT("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))");
-    GEOSSetSRID(input, 3857);
+    input_ = fromWKT("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))");
+    GEOSSetSRID(input_, 3857);
 
-    GEOSGeometry* result = GEOSBoundary(input);
-    GEOSGeometry* expected = GEOSGeomFromWKT("MULTILINESTRING ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))");
+    result_ = GEOSBoundary(input_);
+    expected_ = fromWKT("MULTILINESTRING ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))");
 
-    ensure_equals(GEOSEqualsExact(result, expected, 0), 1);
-    ensure_equals(GEOSGetSRID(input), GEOSGetSRID(result));
-
-    GEOSGeom_destroy(input);
-    GEOSGeom_destroy(result);
-    GEOSGeom_destroy(expected);
+    ensure_geometry_equals_exact(result_, expected_, 0.0);
+    ensure_equals(GEOSGetSRID(input_), GEOSGetSRID(result_));
 }
 
+
 } // namespace tut
 
diff --git a/tests/unit/capi/GEOSBufferTest.cpp b/tests/unit/capi/GEOSBufferTest.cpp
index 8216bcc3a..e44d342e7 100644
--- a/tests/unit/capi/GEOSBufferTest.cpp
+++ b/tests/unit/capi/GEOSBufferTest.cpp
@@ -49,17 +49,14 @@ template<>
 template<>
 void object::test<1>()
 {
-    geom1_ = GEOSGeomFromWKT("POINT EMPTY");
-    ensure(nullptr != geom1_);
-
+    geom1_ = fromWKT("POINT EMPTY");
     geom2_ = GEOSBufferWithStyle(geom1_, 1, 8,
                                  GEOSBUF_CAP_ROUND,
                                  GEOSBUF_JOIN_BEVEL,
                                  5.0);
     ensure(nullptr != geom2_);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON EMPTY");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON EMPTY");
     ensure_geometry_equals(geom2_, geom3_);
 }
 
@@ -68,17 +65,14 @@ template<>
 template<>
 void object::test<2>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING EMPTY");
-    ensure(nullptr != geom1_);
-
+    geom1_ = fromWKT("LINESTRING EMPTY");
     geom2_ = GEOSBufferWithStyle(geom1_, 1, 8,
                                  GEOSBUF_CAP_ROUND,
                                  GEOSBUF_JOIN_BEVEL,
                                  5.0);
     ensure(nullptr != geom2_);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON EMPTY");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON EMPTY");
     ensure_geometry_equals(geom2_, geom3_);
 }
 
@@ -87,17 +81,14 @@ template<>
 template<>
 void object::test<3>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");
-    ensure(nullptr != geom1_);
-
+    geom1_ = fromWKT("POLYGON EMPTY");
     geom2_ = GEOSBufferWithStyle(geom1_, 1, 8,
                                  GEOSBUF_CAP_ROUND,
                                  GEOSBUF_JOIN_BEVEL,
                                  5.0);
     ensure(nullptr != geom2_);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON EMPTY");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON EMPTY");
     ensure_geometry_equals(geom2_, geom3_);
 }
 
@@ -106,9 +97,7 @@ template<>
 template<>
 void object::test<4>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 20)");
-    ensure(nullptr != geom1_);
-
+    geom1_ = fromWKT("LINESTRING(5 10, 10 20)");
     geom2_ = GEOSBuffer(geom1_, 5, 1);
     ensure(nullptr != geom2_);
 
@@ -122,9 +111,7 @@ template<>
 template<>
 void object::test<5>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 20)");
-    ensure(nullptr != geom1_);
-
+    geom1_ = fromWKT("LINESTRING(5 10, 10 20)");
     geom2_ = GEOSBuffer(geom1_, 5, 2);
     ensure(nullptr != geom2_);
 
@@ -138,8 +125,7 @@ template<>
 template<>
 void object::test<6>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 20)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 20)");
 
     bp_ = GEOSBufferParams_create();
     ensure_equals(GEOSBufferParams_setQuadrantSegments(bp_, 20), 1);
@@ -160,8 +146,7 @@ template<>
 template<>
 void object::test<7>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 20)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 20)");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 5, 20, GEOSBUF_CAP_FLAT,
                                  GEOSBUF_JOIN_ROUND, 5.0);
@@ -177,8 +162,7 @@ template<>
 template<>
 void object::test<8>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10)");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 5, 20, GEOSBUF_CAP_FLAT,
                                  GEOSBUF_JOIN_ROUND, 5.0);
@@ -188,8 +172,7 @@ void object::test<8>()
     ensure(0 != GEOSArea(geom2_, &area_));
     ensure_area(area_, 50.0, 0.001);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON ((10.0 15.0, 10.0 5.0, 5.0 5.0, 5.0 15.0, 10.0 15.0))");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON ((10.0 15.0, 10.0 5.0, 5.0 5.0, 5.0 15.0, 10.0 15.0))");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -198,8 +181,7 @@ template<>
 template<>
 void object::test<9>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10)");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 5, 20, GEOSBUF_CAP_SQUARE,
                                  GEOSBUF_JOIN_ROUND, 5.0);
@@ -209,8 +191,7 @@ void object::test<9>()
     ensure(0 != GEOSArea(geom2_, &area_));
     ensure_area(area_, 150.0, 0.001);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON ((10.0 15.0, 15.0 15.0, 15.0 5.0, 5.0 5.0, 0.0 5.0, 0.0 15.0, 10.0 15.0))");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON ((10.0 15.0, 15.0 15.0, 15.0 5.0, 5.0 5.0, 0.0 5.0, 0.0 15.0, 10.0 15.0))");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -220,8 +201,7 @@ template<>
 template<>
 void object::test<10>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10, 10 20)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10, 10 20)");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 5, 20, GEOSBUF_CAP_SQUARE,
                                  GEOSBUF_JOIN_ROUND, 5.0);
@@ -237,9 +217,7 @@ template<>
 template<>
 void object::test<11>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10, 10 20)");
-    ensure(nullptr != geom1_);
-
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10, 10 20)");
     geom2_ = GEOSBufferWithStyle(geom1_, 5, 20, GEOSBUF_CAP_SQUARE,
                                  GEOSBUF_JOIN_MITRE, 5.0);
 
@@ -248,8 +226,7 @@ void object::test<11>()
     ensure(0 != GEOSArea(geom2_, &area_));
     ensure_area(area_, 250.0, 0.001);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON ((5.0 15.0, 5.0 20.0, 5.0 25.0, 15.0 25.0, 15.0 5.0, 5.0 5.0, 0.0 5.0, 0.0 15.0, 5.0 15.0))");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON ((5.0 15.0, 5.0 20.0, 5.0 25.0, 15.0 25.0, 15.0 5.0, 5.0 5.0, 0.0 5.0, 0.0 15.0, 5.0 15.0))");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -259,8 +236,7 @@ template<>
 template<>
 void object::test<12>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10, 10 20)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10, 10 20)");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 5, 20, GEOSBUF_CAP_SQUARE,
                                  GEOSBUF_JOIN_BEVEL, 5.0);
@@ -269,8 +245,7 @@ void object::test<12>()
     ensure(0 != GEOSArea(geom2_, &area_));
     ensure_area(area_, 237.5, 0.001);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON ((5.0 15.0, 5.0 20.0, 5.0 25.0, 15.0 25.0, 15.0 10.0, 10.0 5.0, 5.0 5.0, 0.0 5.0, 0.0 15.0, 5.0 15.0))");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON ((5.0 15.0, 5.0 20.0, 5.0 25.0, 15.0 25.0, 15.0 10.0, 10.0 5.0, 5.0 5.0, 0.0 5.0, 0.0 15.0, 5.0 15.0))");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -281,8 +256,7 @@ template<>
 template<>
 void object::test<13>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10, 10 20)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10, 10 20)");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 5, 200, GEOSBUF_CAP_SQUARE,
                                  GEOSBUF_JOIN_BEVEL, 10.0);
@@ -291,8 +265,7 @@ void object::test<13>()
     ensure(0 != GEOSArea(geom2_, &area_));
     ensure_area(area_, 237.5, 0.001);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON ((5.0 15.0, 5.0 20.0, 5.0 25.0, 15.0 25.0, 15.0 10.0, 10.0 5.0, 5.0 5.0, 0.0 5.0, 0.0 15.0, 5.0 15.0))");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON ((5.0 15.0, 5.0 20.0, 5.0 25.0, 15.0 25.0, 15.0 10.0, 10.0 5.0, 5.0 5.0, 0.0 5.0, 0.0 15.0, 5.0 15.0))");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -301,8 +274,7 @@ template<>
 template<>
 void object::test<14>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((0 0, 10 0, 10 10, 0 0))");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("POLYGON((0 0, 10 0, 10 10, 0 0))");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 2, 200, GEOSBUF_CAP_FLAT,
                                  GEOSBUF_JOIN_MITRE, 1);
@@ -318,8 +290,7 @@ template<>
 template<>
 void object::test<15>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((0 0, 10 0, 10 10, 0 0))");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("POLYGON((0 0, 10 0, 10 10, 0 0))");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 2, 200, GEOSBUF_CAP_FLAT,
                                  GEOSBUF_JOIN_MITRE, 2);
@@ -335,8 +306,7 @@ template<>
 template<>
 void object::test<16>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((0 0, 10 0, 10 10, 0 0))");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("POLYGON((0 0, 10 0, 10 10, 0 0))");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 2, 200, GEOSBUF_CAP_FLAT,
                                  GEOSBUF_JOIN_MITRE, 3);
@@ -352,8 +322,7 @@ template<>
 template<>
 void object::test<17>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10)");
 
     bp_ = GEOSBufferParams_create();
     GEOSBufferParams_setEndCapStyle(bp_, GEOSBUF_CAP_SQUARE);
@@ -361,8 +330,7 @@ void object::test<17>()
 
     ensure(nullptr != geom2_);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON ((10 12, 12 12, 12 8, 5 8, 3 8, 3 12, 10 12))");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON ((10 12, 12 12, 12 8, 5 8, 3 8, 3 12, 10 12))");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -373,8 +341,7 @@ template<>
 template<>
 void object::test<18>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10)");
 
     bp_ = GEOSBufferParams_create();
     GEOSBufferParams_setEndCapStyle(bp_, GEOSBUF_CAP_SQUARE);
@@ -382,8 +349,7 @@ void object::test<18>()
     geom2_ = GEOSBufferWithParams(geom1_, bp_, 2);
     ensure(nullptr != geom2_);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON ((10 10, 5 10, 5 12, 10 12, 10 10))");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON ((10 10, 5 10, 5 12, 10 12, 10 10))");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -394,8 +360,7 @@ template<>
 template<>
 void object::test<19>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(5 10, 10 10)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(5 10, 10 10)");
 
     bp_ = GEOSBufferParams_create();
     GEOSBufferParams_setEndCapStyle(bp_, GEOSBUF_CAP_SQUARE);
@@ -403,8 +368,7 @@ void object::test<19>()
     geom2_ = GEOSBufferWithParams(geom1_, bp_, -2);
     ensure(nullptr != geom2_);
 
-    geom3_ = GEOSGeomFromWKT("POLYGON ((5 10, 10 10, 10 8, 5 8, 5 10))");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("POLYGON ((5 10, 10 10, 10 8, 5 8, 5 10))");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -414,14 +378,12 @@ template<>
 template<>
 void object::test<20>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0, 10 10)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINESTRING(0 0, 10 0, 10 10)");
 
     geom2_ = GEOSSingleSidedBuffer(geom1_, 10, 8, GEOSBUF_JOIN_BEVEL, 0, 0);
     ensure(nullptr != geom2_);
 
-    geom3_ = GEOSGeomFromWKT("LINESTRING (20.0 10.0, 20.0 0.0, 10.0 -10.0, 0.0 -10.0)");
-    ensure(nullptr != geom3_);
+    geom3_ = fromWKT("LINESTRING (20.0 10.0, 20.0 0.0, 10.0 -10.0, 0.0 -10.0)");
     ensure_geometry_equals(geom2_, geom3_, 0.00001);
 }
 
@@ -432,7 +394,7 @@ template<>
 template<>
 void object::test<21>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((-6503873.862740669 -3656747.43316935, -6481859.9985945 -3656747.43316935, -6481859.9985945 -3688545.2369360398, -6506319.8476458 -3688545.2369360398, -6506319.8476458 -3664085.38788474, -6501427.87783554 -3664085.38788474, -6501427.87783554 -3661639.40297961, -6498981.89293041 -3661639.40297961, -6498981.89293041 -3659193.41807448, -6503873.862740669 -3659193.41807448, -6503873.862740669 -3656747.43316935))");
+    geom1_ = fromWKT("POLYGON((-6503873.862740669 -3656747.43316935, -6481859.9985945 -3656747.43316935, -6481859.9985945 -3688545.2369360398, -6506319.8476458 -3688545.2369360398, -6506319.8476458 -3664085.38788474, -6501427.87783554 -3664085.38788474, -6501427.87783554 -3661639.40297961, -6498981.89293041 -3661639.40297961, -6498981.89293041 -3659193.41807448, -6503873.862740669 -3659193.41807448, -6503873.862740669 -3656747.43316935))");
     ensure(nullptr != geom1_);
 
     bp_ = GEOSBufferParams_create();
@@ -452,8 +414,7 @@ template<>
 template<>
 void object::test<22>()
 {
-    geom1_ = GEOSGeomFromWKT("LINEARRING(38.7066196617741550 -28.8266827415760860, -48.9228243285119790 100.6496977731573000, 54.4799195800256510 129.8110447359351000, 108.8101748540030500 45.8263654831350490, 86.7372079193139310 22.3209346883718070, 71.8793256882949690 36.0080540867567290, 55.2741306329362700 34.2630391674088840, 52.0696193064635370 19.4304123529519610, 62.0890652576763390 -3.9267923737325212, 38.7066196617741550 -28.8266827415760860)");
-    ensure(nullptr != geom1_);
+    geom1_ = fromWKT("LINEARRING(38.7066196617741550 -28.8266827415760860, -48.9228243285119790 100.6496977731573000, 54.4799195800256510 129.8110447359351000, 108.8101748540030500 45.8263654831350490, 86.7372079193139310 22.3209346883718070, 71.8793256882949690 36.0080540867567290, 55.2741306329362700 34.2630391674088840, 52.0696193064635370 19.4304123529519610, 62.0890652576763390 -3.9267923737325212, 38.7066196617741550 -28.8266827415760860)");
 
     geom2_ = GEOSBufferWithStyle(geom1_, 22.532378519833863, 6, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 5);
     ensure(nullptr != geom2_);
@@ -490,12 +451,12 @@ template<>
 template<>
 void object::test<25>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON ((4.6664239253667485 4.9470840685113275, 4.666423925366749 4.947084068511328, 3.569508914897422 -10.739531408188364, -9.082056557097435 19.893317266250286, 5.639581102785941 18.86388007810711, 4.6664239253667485 4.9470840685113275))");
+    geom1_ = fromWKT("POLYGON ((4.6664239253667485 4.9470840685113275, 4.666423925366749 4.947084068511328, 3.569508914897422 -10.739531408188364, -9.082056557097435 19.893317266250286, 5.639581102785941 18.86388007810711, 4.6664239253667485 4.9470840685113275))");
     geom2_ = GEOSBufferWithStyle(geom1_, -1, 8,
                                  GEOSBUF_CAP_ROUND,
                                  GEOSBUF_JOIN_MITRE,
                                  5);
-    geom3_ = GEOSGeomFromWKT("POLYGON ((3.3225774291798533 0.0647708524944821, 3.3225774291798555 0.0647708524944812, 2.8688758567150883 -6.4234639154696263, -7.5416226086581215 18.7831577331451953, 4.5722605787819921 17.9360725015914078, 3.3225774291798533 0.0647708524944821))");
+    geom3_ = fromWKT("POLYGON ((3.3225774291798533 0.0647708524944821, 3.3225774291798555 0.0647708524944812, 2.8688758567150883 -6.4234639154696263, -7.5416226086581215 18.7831577331451953, 4.5722605787819921 17.9360725015914078, 3.3225774291798533 0.0647708524944821))");
     ensure_geometry_equals(geom3_, geom2_, 0.001);
 }
 
diff --git a/tests/unit/capi/GEOSBuildAreaTest.cpp b/tests/unit/capi/GEOSBuildAreaTest.cpp
index a06b7e72f..c7f23ac4b 100644
--- a/tests/unit/capi/GEOSBuildAreaTest.cpp
+++ b/tests/unit/capi/GEOSBuildAreaTest.cpp
@@ -17,11 +17,7 @@ namespace tut {
 //
 
 // Common data used in test cases.
-struct test_capi_buildarea_data : public capitest::utility {
-    test_capi_buildarea_data()
-    {
-    }
-};
+struct test_capi_buildarea_data : public capitest::utility {};
 
 typedef test_group<test_capi_buildarea_data> group;
 typedef group::object object;
@@ -34,11 +30,12 @@ group test_capi_buildarea_group("capi::GEOSBuildArea");
 
 template<>
 template<>
-void object::test<1>
-()
+void object::test<1>()
 {
-    geom1_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION(LINESTRING(0 0,0 1,1 1),LINESTRING(1 1,1 0,0 0))");
-    geom2_ = GEOSBuildArea(geom1_);
-    ensure_equals(toWKT(geom2_), std::string("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"));
+    input_ = fromWKT("GEOMETRYCOLLECTION(LINESTRING(0 0,0 1,1 1),LINESTRING(1 1,1 0,0 0))");
+    result_ = GEOSBuildArea(input_);
+    expected_ = fromWKT("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))");
+    ensure_geometry_equals(result_, expected_, 0);
 }
+
 } // namespace tut
diff --git a/tests/unit/capi/GEOSClipByRectTest.cpp b/tests/unit/capi/GEOSClipByRectTest.cpp
index 27f27aa29..0fcdb530d 100644
--- a/tests/unit/capi/GEOSClipByRectTest.cpp
+++ b/tests/unit/capi/GEOSClipByRectTest.cpp
@@ -19,25 +19,29 @@ namespace tut {
 
 // Common data used in test cases.
 struct test_capigeosclipbyrect_data : public capitest::utility {
+
     void
-    isEqual(GEOSGeom g, const char* exp_wkt)
+    checkClipByRect(
+        const char* wktInput,
+        double xmin, double ymin,
+        double xmax, double ymax,
+        const char* wktExpected)
     {
-        ensure(g);
-        geom3_ = GEOSGeomFromWKT(exp_wkt);
-        bool eq = GEOSEquals(geom3_, g) != 0;
-        if(! eq) {
-            std::printf("EXP: %s\n", exp_wkt);
-            char* obt_wkt = GEOSWKTWriter_write(wktw_, g);
-            std::printf("OBT: %s\n", obt_wkt);
-            free(obt_wkt);
+        input_ = fromWKT(wktInput);
+        result_ = GEOSClipByRect(input_, xmin, ymin, xmax, ymax);
+        expected_ = fromWKT(wktExpected);
+
+        bool equal = GEOSEquals(result_, expected_) == 1;
+        if (!equal) {
+            wkt_ = GEOSWKTWriter_write(wktw_, expected_);
+            std::printf("EXP: %s\n", wkt_);
+            GEOSFree(wkt_);
+            wkt_ = GEOSWKTWriter_write(wktw_, result_);
+            std::printf("OBT: %s\n", wkt_);
         }
-        ensure(eq);
+        ensure(equal);
     }
 
-    test_capigeosclipbyrect_data()
-    {
-        GEOSWKTWriter_setRoundingPrecision(wktw_, 8);
-    }
 };
 
 typedef test_group<test_capigeosclipbyrect_data> group;
@@ -50,141 +54,181 @@ group test_capigeosclipbyrect_group("capi::GEOSClipByRect");
 //
 
 /// Point outside
-template<> template<> void object::test<1>
-()
+template<>
+template<>
+void object::test<1>()
 {
-    geom1_ = GEOSGeomFromWKT("POINT(0 0)");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "POINT EMPTY");
+    checkClipByRect(
+        "POINT(0 0)",
+        10, 10, 20, 20,
+        "POINT EMPTY"
+        );
 }
 
 /// Point inside
-template<> template<> void object::test<2>
-()
+template<>
+template<>
+void object::test<2>()
 {
-    geom1_ = GEOSGeomFromWKT("POINT(15 15)");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "POINT(15 15)");
+    checkClipByRect(
+        "POINT(15 15)",
+        10, 10, 20, 20,
+        "POINT(15 15)"
+        );
 }
 
 /// Point on boundary
-template<> template<> void object::test<3>
-()
+template<>
+template<>
+void object::test<3>()
 {
-    geom1_ = GEOSGeomFromWKT("POINT(15 10)");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "POINT EMPTY");
+    checkClipByRect(
+        "POINT(15 10)",
+        10, 10, 20, 20,
+        "POINT EMPTY"
+        );
 }
 
 /// Line outside
-template<> template<> void object::test<4>
-()
+template<>
+template<>
+void object::test<4>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, -5 5)");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "LINESTRING EMPTY");
+    checkClipByRect(
+        "LINESTRING(0 0, -5 5)",
+        10, 10, 20, 20,
+        "LINESTRING EMPTY"
+        );
 }
 
 /// Line inside
-template<> template<> void object::test<5>
-()
+template<>
+template<>
+void object::test<5>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(15 15, 16 15)");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "LINESTRING(15 15, 16 15)");
+    checkClipByRect(
+        "LINESTRING(15 15, 16 15)",
+        10, 10, 20, 20,
+        "LINESTRING(15 15, 16 15)"
+        );
 }
 
 /// Line on boundary
-template<> template<> void object::test<6>
-()
+template<>
+template<>
+void object::test<6>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(10 15, 10 10, 15 10)");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "LINESTRING EMPTY");
+    checkClipByRect(
+        "LINESTRING(10 15, 10 10, 15 10)",
+        10, 10, 20, 20,
+        "LINESTRING EMPTY"
+        );
 }
 
 /// Line splitting rectangle
-template<> template<> void object::test<7>
-()
+template<>
+template<>
+void object::test<7>()
 {
-    geom1_ = GEOSGeomFromWKT("LINESTRING(10 5, 25 20)");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "LINESTRING (15 10, 20 15)");
+    checkClipByRect(
+        "LINESTRING(10 5, 25 20)",
+        10, 10, 20, 20,
+        "LINESTRING (15 10, 20 15)"
+        );
 }
 
 /// Polygon shell (CCW) fully on rectangle boundary
-template<> template<> void object::test<8>
-()
+template<>
+template<>
+void object::test<8>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((10 10, 20 10, 20 20, 10 20, 10 10))");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "POLYGON((10 10, 20 10, 20 20, 10 20, 10 10))");
+    checkClipByRect(
+        "POLYGON((10 10, 20 10, 20 20, 10 20, 10 10))",
+        10, 10, 20, 20,
+        "POLYGON((10 10, 20 10, 20 20, 10 20, 10 10))"
+        );
 }
 
 /// Polygon shell (CW) fully on rectangle boundary
-template<> template<> void object::test<9>
-()
+template<>
+template<>
+void object::test<9>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "POLYGON((10 10, 20 10, 20 20, 10 20, 10 10))");
+    checkClipByRect(
+        "POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))",
+        10, 10, 20, 20,
+        "POLYGON((10 10, 20 10, 20 20, 10 20, 10 10))"
+        );
 }
 
 /// Polygon hole (CCW) fully on rectangle boundary
-template<> template<> void object::test<10>
-()
+template<>
+template<>
+void object::test<10>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((0 0, 0 30, 30 30, 30 0, 0 0),(10 10, 20 10, 20 20, 10 20, 10 10))");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "POLYGON EMPTY");
+    checkClipByRect(
+        "POLYGON((0 0, 0 30, 30 30, 30 0, 0 0),(10 10, 20 10, 20 20, 10 20, 10 10))",
+        10, 10, 20, 20,
+        "POLYGON EMPTY"
+        );
 }
 
 /// Polygon hole (CW) fully on rectangle boundary
-template<> template<> void object::test<11>
-()
+template<>
+template<>
+void object::test<11>()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((0 0, 0 30, 30 30, 30 0, 0 0),(10 10, 10 20, 20 20, 20 10, 10 10))");
-    geom2_ = GEOSClipByRect(geom1_, 10, 10, 20, 20);
-    isEqual(geom2_, "POLYGON EMPTY");
+    checkClipByRect(
+        "POLYGON((0 0, 0 30, 30 30, 30 0, 0 0),(10 10, 10 20, 20 20, 20 10, 10 10))",
+        10, 10, 20, 20,
+        "POLYGON EMPTY"
+        );
 }
 
 /// Polygon fully within rectangle
-template<> template<> void object::test<12>
-()
+template<>
+template<>
+void object::test<12>()
 {
     const char* wkt = "POLYGON((1 1, 1 30, 30 30, 30 1, 1 1),(10 10, 20 10, 20 20, 10 20, 10 10))";
-    geom1_ = GEOSGeomFromWKT(wkt);
-    geom2_ = GEOSClipByRect(geom1_, 0, 0, 40, 40);
-    isEqual(geom2_, wkt);
+    checkClipByRect(
+        wkt,
+        0, 0, 40, 40,
+        wkt);
 }
 
 /// Polygon overlapping rectangle
-template<> template<> void object::test<13>
-()
+template<>
+template<>
+void object::test<13>()
 {
-    const char* wkt = "POLYGON((0 0, 0 30, 30 30, 30 0, 0 0),(10 10, 20 10, 20 20, 10 20, 10 10))";
-    geom1_ = GEOSGeomFromWKT(wkt);
-    geom2_ = GEOSClipByRect(geom1_, 5, 5, 15, 15);
-    isEqual(geom2_, "POLYGON ((5 5, 5 15, 10 15, 10 10, 15 10, 15 5, 5 5))");
+    checkClipByRect(
+        "POLYGON((0 0, 0 30, 30 30, 30 0, 0 0),(10 10, 20 10, 20 20, 10 20, 10 10))",
+        5, 5, 15, 15,
+        "POLYGON ((5 5, 5 15, 10 15, 10 10, 15 10, 15 5, 5 5))"
+        );
 }
 
 /// Clipping invalid polygon
-template<> template<> void object::test<14>
+template<>
+template<>
+void object::test<14>
 ()
 {
-    const char* wkt = "POLYGON((1410 2055, 1410 2056, 1410 2057, 1410 2055))";
-    geom1_ = GEOSGeomFromWKT(wkt);
+    geom1_ = fromWKT("POLYGON((1410 2055, 1410 2056, 1410 2057, 1410 2055))");
     geom2_ = GEOSClipByRect(geom1_, -8, -8, 2056, 2056);
     if (geom2_ != nullptr) {
-        char* obt_wkt = GEOSWKTWriter_write(wktw_, geom2_);
-        std::printf("OBT: %s\n", obt_wkt);
+        wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
+        std::printf("OBT: %s\n", wkt_);
     }
     ensure(nullptr == geom2_);
 }
 
 // Polygon fully covering rectangle
 // https://trac.osgeo.org/postgis/ticket/4904
-template<> template<> void object::test<15>
+template<>
+template<>
+void object::test<15>
 ()
 {
     //  POLYGON((0 0,10 0,10 10,0 10))
@@ -195,16 +239,17 @@ template<> template<> void object::test<15>
     GEOSCoordSeq_setXY(cs, 2, 10, 10);
     GEOSCoordSeq_setXY(cs, 3,  0, 10);
     GEOSCoordSeq_setXY(cs, 4,  0,  0);
-    GEOSGeometry *shell = GEOSGeom_createLinearRing(cs);
-    geom1_ = GEOSGeom_createPolygon(shell, NULL, 0);
-
-
-    geom2_ = GEOSClipByRect(geom1_, 2, 2, 5, 5);
-    isEqual(geom2_, "POLYGON ((2 2, 2 5, 5 5, 5 2, 2 2))");
+    GEOSGeometry *shell = GEOSGeom_createLinearRing(cs); // take ownership of cs
+    input_ = GEOSGeom_createPolygon(shell, NULL, 0); // take ownership of shell
+    result_ = GEOSClipByRect(input_, 2, 2, 5, 5);
+    expected_ = GEOSGeomFromWKT("POLYGON ((2 2, 2 5, 5 5, 5 2, 2 2))");
+    ensure_geometry_equals(result_, expected_);
 }
 
 /// Empty combinations - always return GEOMETRYCOLLECTION EMPTY
-template<> template<> void object::test<16>
+template<>
+template<>
+void object::test<16>
 ()
 {
     std::vector<const char*> variants{
@@ -218,14 +263,11 @@ template<> template<> void object::test<16>
         "LINEARRING EMPTY",
     };
     for (const auto& wkt : variants) {
-        GEOSGeom geom1 = GEOSGeomFromWKT(wkt);
-        GEOSGeom geom2 = GEOSClipByRect(geom1, 0, 0, 1, 1);
-        char* obt_wkt = GEOSWKTWriter_write(wktw_, geom2);
-        std::string obt_wkt2(obt_wkt);
-        GEOSFree(obt_wkt);
-        GEOSGeom_destroy(geom1);
-        GEOSGeom_destroy(geom2);
-        ensure_equals(obt_wkt2, "GEOMETRYCOLLECTION EMPTY");
+        GEOSGeometry* a = fromWKT(wkt);
+        GEOSGeometry* b = GEOSClipByRect(a, 0, 0, 1, 1);
+        ensure("GEOS_GEOMETRYCOLLECTION", GEOSGeomTypeId(b) == GEOS_GEOMETRYCOLLECTION);
+        GEOSGeom_destroy(a);
+        GEOSGeom_destroy(b);
     }
 }
 
diff --git a/tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp b/tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp
index a5a485e9d..8de6baf54 100644
--- a/tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp
+++ b/tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp
@@ -34,11 +34,10 @@ template<>
 template<>
 void object::test<1>()
 {
-    input_ = GEOSGeomFromWKT("POLYGON EMPTY");
-    ensure(nullptr != input_);
+    input_ = fromWKT("POLYGON EMPTY");
     geom1_ = GEOSConcaveHullOfPolygons(input_, 0.7, false, false);
     ensure(nullptr != geom1_);
-    expected_ = GEOSGeomFromWKT("POLYGON EMPTY");
+    expected_ = fromWKT("POLYGON EMPTY");
     ensure_geometry_equals(geom1_, expected_);
 }
 
@@ -46,11 +45,10 @@ template<>
 template<>
 void object::test<2>()
 {
-    input_ = GEOSGeomFromWKT("MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))");
-    ensure(nullptr != input_);
+    input_ = fromWKT("MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))");
     geom1_ = GEOSConcaveHullOfPolygons(input_, 0.7, false, false);
     ensure(nullptr != geom1_);
-    expected_ = GEOSGeomFromWKT("MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))");
+    expected_ = fromWKT("MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))");
     ensure_geometry_equals(geom1_, expected_);
 }
 
diff --git a/tests/unit/capi/GEOSConcaveHullTest.cpp b/tests/unit/capi/GEOSConcaveHullTest.cpp
index ec2eae673..690ce5425 100644
--- a/tests/unit/capi/GEOSConcaveHullTest.cpp
+++ b/tests/unit/capi/GEOSConcaveHullTest.cpp
@@ -33,34 +33,24 @@ template<>
 template<>
 void object::test<1>()
 {
-    input_ = GEOSGeomFromWKT("MULTIPOINT ((10 90), (10 10), (90 10), (90 90), (40 40), (60 30), (30 70), (40 60), (60 50), (60 72), (47 66), (90 60))");
-    ensure(nullptr != input_);
-
-    expected_ = GEOSGeomFromWKT("POLYGON ((30 70, 10 90, 60 72, 90 90, 90 60, 90 10, 60 30, 10 10, 40 40, 60 50, 47 66, 40 60, 30 70))");
-    ensure(nullptr != expected_);
-
-    GEOSGeometry* output = GEOSConcaveHull(input_, 0, 0);
-    ensure(nullptr != output);
-    ensure(0 == GEOSisEmpty(output));
-    ensure_geometry_equals(output, expected_);
-    GEOSGeom_destroy(output);
+    input_ = fromWKT("MULTIPOINT ((10 90), (10 10), (90 10), (90 90), (40 40), (60 30), (30 70), (40 60), (60 50), (60 72), (47 66), (90 60))");
+    expected_ = fromWKT("POLYGON ((30 70, 10 90, 60 72, 90 90, 90 60, 90 10, 60 30, 10 10, 40 40, 60 50, 47 66, 40 60, 30 70))");
+    result_ = GEOSConcaveHull(input_, 0, 0);
+    ensure(nullptr != result_);
+    ensure(0 == GEOSisEmpty(result_));
+    ensure_geometry_equals(result_, expected_);
 }
 
 template<>
 template<>
 void object::test<2>()
 {
-    input_ = GEOSGeomFromWKT("MULTIPOINT ((10 90), (10 10), (90 10), (90 90), (40 40), (60 30), (30 70), (40 60), (60 50), (60 72), (47 66), (90 60))");
-    ensure(nullptr != input_);
-
-    expected_ = GEOSGeomFromWKT("POLYGON ((30 70, 10 90, 60 72, 90 90, 90 60, 90 10, 60 30, 10 10, 40 40, 30 70))");
-    ensure(nullptr != expected_);
-
-    GEOSGeometry* output = GEOSConcaveHullByLength(input_, 50, 0);
-    ensure(nullptr != output);
-    ensure(0 == GEOSisEmpty(output));
-    ensure_geometry_equals(output, expected_);
-    GEOSGeom_destroy(output);
+    input_ = fromWKT("MULTIPOINT ((10 90), (10 10), (90 10), (90 90), (40 40), (60 30), (30 70), (40 60), (60 50), (60 72), (47 66), (90 60))");
+    expected_ = fromWKT("POLYGON ((30 70, 10 90, 60 72, 90 90, 90 60, 90 10, 60 30, 10 10, 40 40, 30 70))");
+    result_ = GEOSConcaveHullByLength(input_, 50, 0);
+    ensure(nullptr != result_);
+    ensure(0 == GEOSisEmpty(result_));
+    ensure_geometry_equals(result_, expected_);
 }
 
 } // namespace tut
diff --git a/tests/unit/capi/GEOSConstrainedDelaunayTriangulationTest.cpp b/tests/unit/capi/GEOSConstrainedDelaunayTriangulationTest.cpp
index 81e3c7d90..24687a6b8 100644
--- a/tests/unit/capi/GEOSConstrainedDelaunayTriangulationTest.cpp
+++ b/tests/unit/capi/GEOSConstrainedDelaunayTriangulationTest.cpp
@@ -38,7 +38,7 @@ template<>
 void object::test<1>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");
+    geom1_ = fromWKT("POLYGON EMPTY");
     ensure_equals(GEOSisEmpty(geom1_), 1);
 
     geom2_ = GEOSConstrainedDelaunayTriangulation(geom1_);
@@ -53,7 +53,7 @@ template<>
 void object::test<2>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("POINT(0 0)");
+    geom1_ = fromWKT("POINT(0 0)");
     geom2_ = GEOSConstrainedDelaunayTriangulation(geom1_);
     ensure_equals(GEOSisEmpty(geom2_), 1);
     ensure_equals(GEOSGeomTypeId(geom2_), GEOS_GEOMETRYCOLLECTION);
@@ -65,8 +65,8 @@ template<>
 void object::test<3>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON ((10 10, 20 40, 90 90, 90 10, 10 10))");
-    geom2_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION (POLYGON ((10 10, 20 40, 90 10, 10 10)), POLYGON ((90 90, 20 40, 90 10, 90 90)))");
+    geom1_ = fromWKT("POLYGON ((10 10, 20 40, 90 90, 90 10, 10 10))");
+    geom2_ = fromWKT("GEOMETRYCOLLECTION (POLYGON ((10 10, 20 40, 90 10, 10 10)), POLYGON ((90 90, 20 40, 90 10, 90 90)))");
     geom3_ = GEOSConstrainedDelaunayTriangulation(geom1_);
     ensure_geometry_equals(geom2_, geom3_);
 }
diff --git a/tests/unit/capi/GEOSContainsTest.cpp b/tests/unit/capi/GEOSContainsTest.cpp
index 03a59c36d..7dd017ff7 100644
--- a/tests/unit/capi/GEOSContainsTest.cpp
+++ b/tests/unit/capi/GEOSContainsTest.cpp
@@ -37,18 +37,13 @@ template<>
 void object::test<1>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");
-    geom2_ = GEOSGeomFromWKT("POLYGON EMPTY");
-
-    ensure(nullptr != geom1_);
-    ensure(nullptr != geom2_);
+    geom1_ = fromWKT("POLYGON EMPTY");
+    geom2_ = fromWKT("POLYGON EMPTY");
 
     char const r1 = GEOSContains(geom1_, geom2_);
-
     ensure_equals(r1, 0);
 
     char const r2 = GEOSContains(geom2_, geom1_);
-
     ensure_equals(r2, 0);
 }
 
@@ -57,18 +52,13 @@ template<>
 void object::test<2>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((1 1,1 5,5 5,5 1,1 1))");
-    geom2_ = GEOSGeomFromWKT("POINT(2 2)");
-
-    ensure(nullptr != geom1_);
-    ensure(nullptr != geom2_);
+    geom1_ = fromWKT("POLYGON((1 1,1 5,5 5,5 1,1 1))");
+    geom2_ = fromWKT("POINT(2 2)");
 
     char const r1 = GEOSContains(geom1_, geom2_);
-
     ensure_equals(int(r1), 1);
 
     char const r2 = GEOSContains(geom2_, geom1_);
-
     ensure_equals(int(r2), 0);
 }
 
@@ -77,18 +67,13 @@ template<>
 void object::test<3>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))");
-    geom2_ = GEOSGeomFromWKT("POLYGON((1 1,1 2,2 2,2 1,1 1))");
-
-    ensure(nullptr != geom1_);
-    ensure(nullptr != geom2_);
+    geom1_ = fromWKT("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))");
+    geom2_ = fromWKT("POLYGON((1 1,1 2,2 2,2 1,1 1))");
 
     char const r1 = GEOSContains(geom1_, geom2_);
-
     ensure_equals(int(r1), 1);
 
     char const r2 = GEOSContains(geom2_, geom1_);
-
     ensure_equals(int(r2), 0);
 }
 
diff --git a/tests/unit/capi/GEOSConvexHullTest.cpp b/tests/unit/capi/GEOSConvexHullTest.cpp
index f4a162744..9b99c8cad 100644
--- a/tests/unit/capi/GEOSConvexHullTest.cpp
+++ b/tests/unit/capi/GEOSConvexHullTest.cpp
@@ -34,17 +34,12 @@ template<>
 void object::test<1>
 ()
 {
-    input_ = GEOSGeomFromWKT("MULTIPOINT ((130 240), (130 240), (570 240), (570 290), (650 240))");
-    ensure(nullptr != input_);
-
-    expected_ = GEOSGeomFromWKT("POLYGON ((130 240, 570 290, 650 240, 130 240))");
-    ensure(nullptr != expected_);
-
-    GEOSGeometry* output = GEOSConvexHull(input_);
-    ensure(nullptr != output);
-    ensure(0 == GEOSisEmpty(output));
-    ensure_geometry_equals(output, expected_);
-    GEOSGeom_destroy(output);
+    input_ = fromWKT("MULTIPOINT ((130 240), (130 240), (570 240), (570 290), (650 240))");
+    expected_ = fromWKT("POLYGON ((130 240, 570 290, 650 240, 130 240))");
+    result_ = GEOSConvexHull(input_);
+    ensure(nullptr != result_);
+    ensure(0 == GEOSisEmpty(result_));
+    ensure_geometry_equals(result_, expected_);
 }
 
 } // namespace tut
diff --git a/tests/unit/capi/GEOSCoveredByTest.cpp b/tests/unit/capi/GEOSCoveredByTest.cpp
index 19f4a084c..6f9bfc947 100644
--- a/tests/unit/capi/GEOSCoveredByTest.cpp
+++ b/tests/unit/capi/GEOSCoveredByTest.cpp
@@ -21,11 +21,8 @@ template<>
 void object::test<1>()
 {
     geom1_ = fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
-    ensure(nullptr != geom1_);
     geom2_ = fromWKT("POLYGON ((5 5, 5 7, 7 7, 7 5, 5 5))");
-    ensure(nullptr != geom2_);
     geom3_ = fromWKT("POLYGON ((20 20, 20 30, 30 30, 30 20, 20 20))");
-    ensure(nullptr != geom3_);
 
     ensure_equals(1, GEOSCoveredBy(geom2_, geom1_));
     ensure_equals(0, GEOSCoveredBy(geom1_, geom2_));
diff --git a/tests/unit/capi/GEOSCoversTest.cpp b/tests/unit/capi/GEOSCoversTest.cpp
index e7c9b92b7..ee976743a 100644
--- a/tests/unit/capi/GEOSCoversTest.cpp
+++ b/tests/unit/capi/GEOSCoversTest.cpp
@@ -21,11 +21,8 @@ template<>
 void object::test<1>()
 {
     geom1_ = fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
-    ensure(nullptr != geom1_);
     geom2_ = fromWKT("POLYGON ((5 5, 5 7, 7 7, 7 5, 5 5))");
-    ensure(nullptr != geom2_);
     geom3_ = fromWKT("POLYGON ((20 20, 20 30, 30 30, 30 20, 20 20))");
-    ensure(nullptr != geom3_);
 
     ensure_equals(1, GEOSCovers(geom1_, geom2_));
     ensure_equals(0, GEOSCovers(geom2_, geom1_));
diff --git a/tests/unit/capi/GEOSCrossesTest.cpp b/tests/unit/capi/GEOSCrossesTest.cpp
index 641c177f7..ab19caa9f 100644
--- a/tests/unit/capi/GEOSCrossesTest.cpp
+++ b/tests/unit/capi/GEOSCrossesTest.cpp
@@ -21,11 +21,8 @@ template<>
 void object::test<1>()
 {
     geom1_ = fromWKT("LINESTRING (1 1, 10 10)");
-    ensure(nullptr != geom1_);
     geom2_ = fromWKT("LINESTRING (10 1, 1 10)");
-    ensure(nullptr != geom2_);
     geom3_ = fromWKT("LINESTRING (20 20, 30 30)");
-    ensure(nullptr != geom3_);
 
     ensure_equals(1, GEOSCrosses(geom1_, geom2_));
     ensure_equals(1, GEOSCrosses(geom2_, geom1_));
diff --git a/tests/unit/capi/GEOSDelaunayTriangulationTest.cpp b/tests/unit/capi/GEOSDelaunayTriangulationTest.cpp
index c55f093fe..a5568e59e 100644
--- a/tests/unit/capi/GEOSDelaunayTriangulationTest.cpp
+++ b/tests/unit/capi/GEOSDelaunayTriangulationTest.cpp
@@ -38,7 +38,7 @@ template<>
 void object::test<1>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");
+    geom1_ = fromWKT("POLYGON EMPTY");
 
     ensure_equals(GEOSisEmpty(geom1_), 1);
 
@@ -47,69 +47,54 @@ void object::test<1>
     ensure_equals(GEOSisEmpty(geom2_), 1);
     ensure_equals(GEOSGeomTypeId(geom2_), GEOS_GEOMETRYCOLLECTION);
 
-    GEOSGeom_destroy(geom2_);
-    geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
-    ensure_equals(GEOSisEmpty(geom2_), 1);
-    ensure_equals(GEOSGeomTypeId(geom2_), GEOS_MULTILINESTRING);
-
-
+    geom3_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
+    ensure_equals(GEOSisEmpty(geom3_), 1);
+    ensure_equals(GEOSGeomTypeId(geom3_), GEOS_MULTILINESTRING);
 }
 
 // Single point
 template<>
 template<>
-void object::test<2>
-()
+void object::test<2>()
 {
-    geom1_ = GEOSGeomFromWKT("POINT(0 0)");
+    geom1_ = fromWKT("POINT(0 0)");
 
     geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 0);
     ensure_equals(GEOSisEmpty(geom2_), 1);
     ensure_equals(GEOSGeomTypeId(geom2_), GEOS_GEOMETRYCOLLECTION);
 
-    GEOSGeom_destroy(geom2_);
-    geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
-    ensure_equals(GEOSisEmpty(geom2_), 1);
-    ensure_equals(GEOSGeomTypeId(geom2_), GEOS_MULTILINESTRING);
+    geom3_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
+    ensure_equals(GEOSisEmpty(geom3_), 1);
+    ensure_equals(GEOSGeomTypeId(geom3_), GEOS_MULTILINESTRING);
 }
 
 // Three collinear points
 template<>
 template<>
-void object::test<3>
-()
+void object::test<3>()
 {
-    geom1_ = GEOSGeomFromWKT("MULTIPOINT((0 0), (5 0), (10 0))");
+    geom1_ = fromWKT("MULTIPOINT((0 0), (5 0), (10 0))");
 
     geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 0);
     ensure_equals(GEOSisEmpty(geom2_), 1);
     ensure_equals(GEOSGeomTypeId(geom2_), GEOS_GEOMETRYCOLLECTION);
 
-    GEOSGeom_destroy(geom2_);
-    geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
-    char* wkt_c = GEOSWKTWriter_write(wktw_, geom2_);
-    std::string out(wkt_c);
-    free(wkt_c);
-    ensure_equals(out, "MULTILINESTRING ((5 0, 10 0), (0 0, 5 0))");
+    geom3_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
+    ensure_geometry_equals(geom3_, "MULTILINESTRING ((5 0, 10 0), (0 0, 5 0))");
 }
 
 // Three points
 template<>
 template<>
-void object::test<4>
-()
+void object::test<4>()
 {
-    geom1_ = GEOSGeomFromWKT("MULTIPOINT((0 0), (5 0), (10 10))");
-
+    geom1_ = fromWKT("MULTIPOINT((0 0), (5 0), (10 10))");
     geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 0);
     ensure(geom2_ != nullptr);
-    ensure_geometry_equals(geom2_,
-                      "GEOMETRYCOLLECTION (POLYGON ((0 0, 10 10, 5 0, 0 0)))");
+    ensure_geometry_equals(geom2_, "GEOMETRYCOLLECTION (POLYGON ((0 0, 10 10, 5 0, 0 0)))");
 
-    GEOSGeom_destroy(geom2_);
-    geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
-    ensure_geometry_equals(geom2_,
-                      "MULTILINESTRING ((5 0, 10 10), (0 0, 10 10), (0 0, 5 0))");
+    geom3_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
+    ensure_geometry_equals(geom3_, "MULTILINESTRING ((5 0, 10 10), (0 0, 10 10), (0 0, 5 0))");
 }
 
 // A polygon with a hole
@@ -118,16 +103,15 @@ template<>
 void object::test<5>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2))");
+    geom1_ = fromWKT("POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2))");
 
     geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 0);
     ensure(geom2_ != nullptr);
     ensure_geometry_equals(geom2_,
                       "GEOMETRYCOLLECTION (POLYGON ((8 2, 10 10, 8.5 1, 8 2)), POLYGON ((7 8, 10 10, 8 2, 7 8)), POLYGON ((3 8, 10 10, 7 8, 3 8)), POLYGON ((2 2, 8 2, 8.5 1, 2 2)), POLYGON ((2 2, 7 8, 8 2, 2 2)), POLYGON ((2 2, 3 8, 7 8, 2 2)), POLYGON ((0.5 9, 10 10, 3 8, 0.5 9)), POLYGON ((0.5 9, 3 8, 2 2, 0.5 9)), POLYGON ((0 0, 2 2, 8.5 1, 0 0)), POLYGON ((0 0, 0.5 9, 2 2, 0 0)))");
 
-    GEOSGeom_destroy(geom2_);
-    geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
-    ensure_geometry_equals(geom2_,
+    geom3_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
+    ensure_geometry_equals(geom3_,
                       "MULTILINESTRING ((8.5 1, 10 10), (8 2, 10 10), (8 2, 8.5 1), (7 8, 10 10), (7 8, 8 2), (3 8, 10 10), (3 8, 7 8), (2 2, 8.5 1), (2 2, 8 2), (2 2, 7 8), (2 2, 3 8), (0.5 9, 10 10), (0.5 9, 3 8), (0.5 9, 2 2), (0 0, 8.5 1), (0 0, 2 2), (0 0, 0.5 9))");
 }
 
@@ -137,9 +121,8 @@ template<>
 void object::test<6>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("MULTIPOINT((0 0), (10 0), (10 10), (11 10))");
+    geom1_ = fromWKT("MULTIPOINT((0 0), (10 0), (10 10), (11 10))");
 
-    GEOSGeom_destroy(geom2_);
     geom2_ = GEOSDelaunayTriangulation(geom1_, 2, 1);
     ensure_geometry_equals(geom2_,
                       "MULTILINESTRING ((10 0, 10 10), (0 0, 10 10), (0 0, 10 0))");
diff --git a/tests/unit/capi/GEOSDensifyTest.cpp b/tests/unit/capi/GEOSDensifyTest.cpp
index 006a36834..cd11e1cea 100644
--- a/tests/unit/capi/GEOSDensifyTest.cpp
+++ b/tests/unit/capi/GEOSDensifyTest.cpp
@@ -14,26 +14,23 @@ namespace tut {
 
 struct test_capigeosdensify_data : public capitest::utility
 {
-    void testDensify(const std::string &wkt_input,
-                            const std::string &wkt_output,
-                            double tolerance)
+    void testDensify(
+        const std::string &wkt_input,
+        const std::string &wkt_output,
+        double tolerance)
     {
         int srid = 3857;
 
-        GEOSGeometry *input = GEOSGeomFromWKT(wkt_input.c_str());
-        GEOSSetSRID(input, srid);
+        input_ = fromWKT(wkt_input.c_str());
+        GEOSSetSRID(input_, srid);
 
-        GEOSGeometry *expected = GEOSGeomFromWKT(wkt_output.c_str());
+        expected_ = fromWKT(wkt_output.c_str());
 
-        GEOSGeometry *result = GEOSDensify(input, tolerance);
-        ensure("result not NULL", result != nullptr);
+        result_ = GEOSDensify(input_, tolerance);
+        ensure("result not NULL", result_ != nullptr);
 
-        ensure_geometry_equals(result, expected);
-        ensure_equals("result SRID == expected SRID", GEOSGetSRID(result), srid);
-
-        GEOSGeom_destroy(input);
-        GEOSGeom_destroy(expected);
-        GEOSGeom_destroy(result);
+        ensure_geometry_equals(result_, expected_);
+        ensure_equals("result SRID == expected SRID", GEOSGetSRID(result_), srid);
     }
 };
 
@@ -153,15 +150,13 @@ template <>
 template <>
 void object::test<9>()
 {
-    GEOSGeometry *input = GEOSGeomFromWKT("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))");
+    input_ = fromWKT("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))");
 
-    GEOSGeometry *result = GEOSDensify(input, 0.0);
-    ensure("result expected to be NULL", result == nullptr);
+    result_ = GEOSDensify(input_, 0.0);
+    ensure("result expected to be NULL", result_ == nullptr);
 
-    result = GEOSDensify(input, -1.0);
-    ensure("result expected to be NULL", result == nullptr);
-
-    GEOSGeom_destroy(input);
+    result_ = GEOSDensify(input_, -1.0);
+    ensure("result expected to be NULL", result_ == nullptr);
 }
 
 } // namespace tut
diff --git a/tests/unit/capi/GEOSDifferencePrecTest.cpp b/tests/unit/capi/GEOSDifferencePrecTest.cpp
index 45e4b82f0..ecd4759b0 100644
--- a/tests/unit/capi/GEOSDifferencePrecTest.cpp
+++ b/tests/unit/capi/GEOSDifferencePrecTest.cpp
@@ -20,24 +20,15 @@ template<>
 template<>
 void object::test<1>()
 {
-    GEOSGeometry* a = GEOSGeomFromWKT("LINESTRING (2 8, 10 8)");
-    GEOSGeometry* b = GEOSGeomFromWKT("LINESTRING (3.9 8.1, 6.1 7.9)");
+    geom1_ = fromWKT("LINESTRING (2 8, 10 8)");
+    geom2_ = fromWKT("LINESTRING (3.9 8.1, 6.1 7.9)");
+    GEOSSetSRID(geom1_, 4326);
 
-    ensure(a);
-    ensure(b);
+    result_ = GEOSDifferencePrec(geom1_, geom2_, 2);
+    ensure(result_);
 
-    GEOSSetSRID(a, 4326);
-
-    GEOSGeometry* result = GEOSDifferencePrec(a, b, 2);
-
-    ensure(result);
-
-    ensure_geometry_equals(result, "MULTILINESTRING ((6 8, 10 8), (2 8, 4 8))");
-    ensure_equals(GEOSGetSRID(a), GEOSGetSRID(result));
-
-    GEOSGeom_destroy(a);
-    GEOSGeom_destroy(b);
-    GEOSGeom_destroy(result);
+    ensure_geometry_equals(result_, "MULTILINESTRING ((6 8, 10 8), (2 8, 4 8))");
+    ensure_equals(GEOSGetSRID(geom1_), GEOSGetSRID(result_));
 }
 
 } // namespace tut
diff --git a/tests/unit/capi/GEOSDifferenceTest.cpp b/tests/unit/capi/GEOSDifferenceTest.cpp
index b2ff86a2c..efaf1ad0d 100644
--- a/tests/unit/capi/GEOSDifferenceTest.cpp
+++ b/tests/unit/capi/GEOSDifferenceTest.cpp
@@ -20,24 +20,16 @@ template<>
 template<>
 void object::test<1>()
 {
-    GEOSGeometry* a = GEOSGeomFromWKT("LINESTRING (2 8, 10 8)");
-    GEOSGeometry* b = GEOSGeomFromWKT("LINESTRING (4 8, 6 8)");
+    geom1_ = fromWKT("LINESTRING (2 8, 10 8)");
+    geom2_ = fromWKT("LINESTRING (4 8, 6 8)");
 
-    ensure(a);
-    ensure(b);
+    GEOSSetSRID(geom1_, 4326);
 
-    GEOSSetSRID(a, 4326);
+    result_ = GEOSDifference(geom1_, geom2_);
+    ensure(result_);
 
-    GEOSGeometry* result = GEOSDifference(a, b);
-
-    ensure(result);
-
-    ensure_geometry_equals(result, "MULTILINESTRING ((6 8, 10 8), (2 8, 4 8))");
-    ensure_equals(GEOSGetSRID(a), GEOSGetSRID(result));
-
-    GEOSGeom_destroy(a);
-    GEOSGeom_destroy(b);
-    GEOSGeom_destroy(result);
+    ensure_geometry_equals(result_, "MULTILINESTRING ((6 8, 10 8), (2 8, 4 8))");
+    ensure_equals(GEOSGetSRID(geom1_), GEOSGetSRID(result_));
 }
 
 } // namespace tut
diff --git a/tests/unit/capi/GEOSDisjointSubsetUnionTest.cpp b/tests/unit/capi/GEOSDisjointSubsetUnionTest.cpp
index 4099c15b5..456b39ee9 100644
--- a/tests/unit/capi/GEOSDisjointSubsetUnionTest.cpp
+++ b/tests/unit/capi/GEOSDisjointSubsetUnionTest.cpp
@@ -27,7 +27,7 @@ template<>
 template<>
 void object::test<1>()
 {
-    input_ = GEOSGeomFromWKT("POLYGON EMPTY");
+    input_ = fromWKT("POLYGON EMPTY");
     GEOSSetSRID(input_, 1234);
 
     result_ = GEOSDisjointSubsetUnion(input_);
@@ -40,10 +40,9 @@ template<>
 template<>
 void object::test<2>()
 {
-    input_ = GEOSGeomFromWKT("MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((1 0, 2 0, 2 1, 1 1, 1 0)), ((3 3, 4 3, 4 4, 3 3)))");
-    expected_ = GEOSGeomFromWKT("MULTIPOLYGON (((0 0, 1 0, 2 0, 2 1, 1 1, 0 1, 0 0)), ((3 3, 4 3, 4 4, 3 3)))");
+    input_ = fromWKT("MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((1 0, 2 0, 2 1, 1 1, 1 0)), ((3 3, 4 3, 4 4, 3 3)))");
+    expected_ = fromWKT("MULTIPOLYGON (((0 0, 1 0, 2 0, 2 1, 1 1, 0 1, 0 0)), ((3 3, 4 3, 4 4, 3 3)))");
     result_ = GEOSDisjointSubsetUnion(input_);
-
     ensure_geometry_equals(result_, expected_);
 }
 
diff --git a/tests/unit/capi/GEOSDisjointTest.cpp b/tests/unit/capi/GEOSDisjointTest.cpp
index 1a127f4be..cb8fde2a2 100644
--- a/tests/unit/capi/GEOSDisjointTest.cpp
+++ b/tests/unit/capi/GEOSDisjointTest.cpp
@@ -21,11 +21,8 @@ template<>
 void object::test<1>()
 {
     geom1_ = fromWKT("POINT (0 0)");
-    ensure(geom1_);
     geom2_ = fromWKT("LINESTRING(2 0, 0 2)");
-    ensure(geom2_);
     geom3_ = fromWKT("LINESTRING(0 0, 0 2)");
-    ensure(geom3_);
 
     ensure_equals(1, GEOSDisjoint(geom1_, geom2_));
     ensure_equals(0, GEOSDisjoint(geom1_, geom3_));
diff --git a/tests/unit/capi/GEOSDistanceTest.cpp b/tests/unit/capi/GEOSDistanceTest.cpp
index 4c953c4bf..5bf03c90b 100644
--- a/tests/unit/capi/GEOSDistanceTest.cpp
+++ b/tests/unit/capi/GEOSDistanceTest.cpp
@@ -22,8 +22,33 @@ namespace tut {
 
 // Common data used in test cases.
 struct test_capigeosdistance_data : public capitest::utility {
-    test_capigeosdistance_data() {
+    test_capigeosdistance_data() {};
+
+    GEOSGeometry*
+    random_polygon(double x, double y, double r, std::size_t num_points)
+    {
+        std::vector<double> angle(num_points);
+        std::vector<double> radius(num_points);
+
+
+        for(std::size_t i = 0; i < num_points; i++) {
+            angle[i] = 2 * geos::MATH_PI * std::rand() / RAND_MAX;
+            radius[i] = r * std::rand() / RAND_MAX;
+        }
+
+        std::sort(angle.begin(), angle.end());
+
+        GEOSCoordSequence* seq_1 = GEOSCoordSeq_create(static_cast<unsigned int>(num_points), 2);
+        for(unsigned int i = 0; i < num_points; i++) {
+            auto idx = i == (num_points - 1) ? 0 : i;
+
+            GEOSCoordSeq_setX(seq_1, i, x + radius[idx] * cos(angle[idx]));
+            GEOSCoordSeq_setY(seq_1, i, y + radius[idx] * sin(angle[idx]));
+        }
+
+        return GEOSGeom_createPolygon(GEOSGeom_createLinearRing(seq_1), nullptr, 0);
     }
+
 };
 
 typedef test_group<test_capigeosdistance_data> group;
@@ -41,8 +66,8 @@ template<>
 void object::test<1>
 ()
 {
-    geom1_ = GEOSGeomFromWKT("POINT(10 10)");
-    geom2_ = GEOSGeomFromWKT("POINT(3 6)");
+    geom1_ = fromWKT("POINT(10 10)");
+    geom2_ = fromWKT("POINT(3 6)");
 
     double dist;
     int ret = GEOSDistance(geom1_, geom2_, &dist);
@@ -51,31 +76,6 @@ void object::test<1>
     ensure_distance(dist, 8.06225774829855, 1e-12);
 }
 
-GEOSGeometry*
-random_polygon(double x, double y, double r, std::size_t num_points)
-{
-    std::vector<double> angle(num_points);
-    std::vector<double> radius(num_points);
-
-
-    for(std::size_t i = 0; i < num_points; i++) {
-        angle[i] = 2 * geos::MATH_PI * std::rand() / RAND_MAX;
-        radius[i] = r * std::rand() / RAND_MAX;
-    }
-
-    std::sort(angle.begin(), angle.end());
-
-    GEOSCoordSequence* seq_1 = GEOSCoordSeq_create(static_cast<unsigned int>(num_points), 2);
-    for(unsigned int i = 0; i < num_points; i++) {
-        auto idx = i == (num_points - 1) ? 0 : i;
-
-        GEOSCoordSeq_setX(seq_1, i, x + radius[idx] * cos(angle[idx]));
-        GEOSCoordSeq_setY(seq_1, i, y + radius[idx] * sin(angle[idx]));
-    }
-
-    return GEOSGeom_createPolygon(GEOSGeom_createLinearRing(seq_1), nullptr, 0);
-}
-
 /* Generate two complex polygons and verify that GEOSDistance and GEOSDistanceIndexed
  * return identical results.
  */
@@ -86,17 +86,14 @@ void object::test<2>
 {
     std::srand(12345);
 
-    GEOSGeometry* g1 = random_polygon(-3, -8, 7, 1000);
-    GEOSGeometry* g2 = random_polygon(14, 22, 6, 500);
+    geom1_ = random_polygon(-3, -8, 7, 1000);
+    geom2_ = random_polygon(14, 22, 6, 500);
 
     double d_raw, d_indexed;
-    ensure(GEOSDistance(g1, g2, &d_raw) != 0);
-    ensure(GEOSDistanceIndexed(g1, g2, &d_indexed) != 0);
+    ensure(GEOSDistance(geom1_, geom2_, &d_raw) != 0);
+    ensure(GEOSDistanceIndexed(geom1_, geom2_, &d_indexed) != 0);
 
     ensure_equals(d_indexed, d_raw);
-
-    GEOSGeom_destroy(g1);
-    GEOSGeom_destroy(g2);
 }
 
 // https://github.com/libgeos/geos/issues/295
@@ -105,16 +102,13 @@ template<>
 void object::test<3>
 ()
 {
-    GEOSGeometry* g1 = GEOSGeomFromWKT("MultiPolygon Z (EMPTY,((-0.14000000000000001 44.89999999999999858 0, -0.14699999999999999 44.90400000000000347 0, -0.14729999999999999 44.90500000000000114 0, -0.14000000000000001 44.89999999999999858 0)))");
-    GEOSGeometry* g2 = GEOSGeomFromWKT("POLYGON ((0 0, 1 0, 1 1, 0 0))");
+    geom1_ = fromWKT("MultiPolygon Z (EMPTY,((-0.14000000000000001 44.89999999999999858 0, -0.14699999999999999 44.90400000000000347 0, -0.14729999999999999 44.90500000000000114 0, -0.14000000000000001 44.89999999999999858 0)))");
+    geom2_ = fromWKT("POLYGON ((0 0, 1 0, 1 1, 0 0))");
 
     double d;
-    int status = GEOSDistance(g1, g2, &d);
+    int status = GEOSDistance(geom1_, geom2_, &d);
 
     ensure_equals(status, 1);
-
-    GEOSGeom_destroy(g1);
-    GEOSGeom_destroy(g2);
 }
 
 // point distance does not raise floating point exception
@@ -123,14 +117,14 @@ template<>
 void object::test<4>
 ()
 {
-    GEOSGeometry* g1 = GEOSGeomFromWKT("POINT (0 0)");
-    GEOSGeometry* g2 = GEOSGeomFromWKT("POINT (1 1)");
+    geom1_ = fromWKT("POINT (0 0)");
+    geom2_ = fromWKT("POINT (1 1)");
 
     // clear all floating point exceptions
     feclearexcept (FE_ALL_EXCEPT);
 
     double d;
-    int status = GEOSDistance(g1, g2, &d);
+    int status = GEOSDistance(geom1_, geom2_, &d);
 
     ensure_equals(status, 1);
     ensure_equals(d, std::sqrt(2));
@@ -138,9 +132,6 @@ void object::test<4>
     // check for floating point overflow exceptions
     int raised = fetestexcept(FE_OVERFLOW);
     ensure_equals(raised & FE_OVERFLOW, 0);
-
-    GEOSGeom_destroy(g1);
-    GEOSGeom_destroy(g2);
 }
 
 // same distance between boundables should not raise floating point exception
@@ -149,14 +140,14 @@ template<>
 void object::test<5>
 ()
 {
-    GEOSGeometry* g1 = GEOSGeomFromWKT("LINESTRING (0 0, 1 1)");
-    GEOSGeometry* g2 = GEOSGeomFromWKT("LINESTRING (2 1, 1 2)");
+    geom1_ = fromWKT("LINESTRING (0 0, 1 1)");
+    geom2_ = fromWKT("LINESTRING (2 1, 1 2)");
 
     // clear all floating point exceptions
     feclearexcept (FE_ALL_EXCEPT);
 
     double d;
-    int status = GEOSDistance(g1, g2, &d);
+    int status = GEOSDistance(geom1_, geom2_, &d);
 
     ensure_equals(status, 1);
     // ensure_equals(d, std::sqrt(2));
@@ -164,9 +155,6 @@ void object::test<5>
     // check for floating point overflow exceptions
     int raised = fetestexcept(FE_OVERFLOW);
     ensure_equals(raised & FE_OVERFLOW, 0);
-
-    GEOSGeom_destroy(g1);
-    GEOSGeom_destroy(g2);
 }
 
 } // namespace tut
diff --git a/tests/unit/capi/GEOSDistanceWithinTest.cpp b/tests/unit/capi/GEOSDistanceWithinTest.cpp
index 19218b13f..a76aa05e9 100644
--- a/tests/unit/capi/GEOSDistanceWithinTest.cpp
+++ b/tests/unit/capi/GEOSDistanceWithinTest.cpp
@@ -21,22 +21,16 @@ namespace tut {
 //
 
 struct test_capigeosdistancewithin_data : public capitest::utility {
-  void testGEOSDistanceWithin(const char* wkt1, const char* wkt2,
-                              double distance, char expectedResult) {
 
-    GEOSGeometry *input1 = GEOSGeomFromWKT(wkt1);
-    ensure(input1 != nullptr);
-    GEOSGeometry *input2 = GEOSGeomFromWKT(wkt2);
-    ensure(input2 != nullptr);
-
-    char ret = GEOSDistanceWithin(input1, input2, distance);
-
-    GEOSGeom_destroy(input1);
-    GEOSGeom_destroy(input2);
-
-    ensure_equals("return code", (int)ret, (int)expectedResult);
-
-  };
+    void testGEOSDistanceWithin(
+        const char* wkt1, const char* wkt2,
+        double distance, char expectedResult)
+    {
+        geom1_ = fromWKT(wkt1);
+        geom2_ = fromWKT(wkt2);
+        char ret = GEOSDistanceWithin(geom1_, geom2_, distance);
+        ensure_equals("return code", (int)ret, (int)expectedResult);
+    };
 };
 
 typedef test_group<test_capigeosdistancewithin_data> group;
diff --git a/tests/unit/capi/GEOSEnvelopeTest.cpp b/tests/unit/capi/GEOSEnvelopeTest.cpp
index ce609a1bc..99b603103 100644
--- a/tests/unit/capi/GEOSEnvelopeTest.cpp
+++ b/tests/unit/capi/GEOSEnvelopeTest.cpp
@@ -9,7 +9,18 @@ namespace tut {
 // Test Group
 //
 
-struct test_geosenvelope_data : public capitest::utility {};
+struct test_geosenvelope_data : public capitest::utility
+{
+    void
+    checkEnvelope(const char* wktIn, const char* wktExp)
+    {
+        input_ = fromWKT(wktIn);
+        result_ = GEOSEnvelope(input_);
+        expected_ = fromWKT(wktExp);
+        ensure_geometry_equals(result_, expected_, 0);
+    }
+
+};
 
 typedef test_group<test_geosenvelope_data> group;
 typedef group::object object;
@@ -19,72 +30,42 @@ group test_geosenvelope("capi::GEOSEnvelope");
 // non-degenerate input
 template<>
 template<>
-void object::test<1>
-()
+void object::test<1>()
 {
-    GEOSGeometry* input = GEOSGeomFromWKT("LINESTRING (1 2, 4 5, 9 -2)");
-    GEOSGeometry* result = GEOSEnvelope(input);
-    GEOSGeometry* expected = GEOSGeomFromWKT("POLYGON ((1 -2, 9 -2, 9 5, 1 5, 1 -2))");
-
-    ensure_equals(GEOSEqualsExact(result, expected, 0), 1);
-
-    GEOSGeom_destroy(input);
-    GEOSGeom_destroy(result);
-    GEOSGeom_destroy(expected);
+    checkEnvelope(
+        "LINESTRING (1 2, 4 5, 9 -2)",
+        "POLYGON ((1 -2, 9 -2, 9 5, 1 5, 1 -2))"
+        );
 }
 
 // point input
 template<>
 template<>
-void object::test<2>
-()
+void object::test<2>()
 {
-    GEOSGeometry* input = GEOSGeomFromWKT("POINT (3 8)");
-    GEOSGeometry* result = GEOSEnvelope(input);
-
-    GEOSGeometry* expected = GEOSGeomFromWKT("POINT (3 8)");
-
-    ensure_geometry_equals(result, expected);
-
-    GEOSGeom_destroy(input);
-    GEOSGeom_destroy(result);
-    GEOSGeom_destroy(expected);
+    checkEnvelope(
+        "POINT (3 8)",
+        "POINT (3 8)");
 }
 
 // empty point input
 template<>
 template<>
-void object::test<3>
-()
+void object::test<3>()
 {
-    GEOSGeometry* input = GEOSGeomFromWKT("POINT EMPTY");
-    GEOSGeometry* result = GEOSEnvelope(input);
-
-    GEOSGeometry* expected = GEOSGeomFromWKT("POINT EMPTY");
-
-    ensure_geometry_equals(result, expected);
-
-    GEOSGeom_destroy(input);
-    GEOSGeom_destroy(result);
-    GEOSGeom_destroy(expected);
+    checkEnvelope(
+        "POINT EMPTY",
+        "POINT EMPTY");
 }
 
 // empty polygon input
 template<>
 template<>
-void object::test<4>
-()
+void object::test<4>()
 {
-    GEOSGeometry* input = GEOSGeomFromWKT("POLYGON EMPTY");
-    GEOSGeometry* result = GEOSEnvelope(input);
-
-    GEOSGeometry* expected = GEOSGeomFromWKT("POINT EMPTY");
-
-    ensure_geometry_equals(result, expected);
-
-    GEOSGeom_destroy(input);
-    GEOSGeom_destroy(result);
-    GEOSGeom_destroy(expected);
+    checkEnvelope(
+        "POLYGON EMPTY",
+        "POINT EMPTY");
 }
 
 } // namespace tut

-----------------------------------------------------------------------

Summary of changes:
 CMakeLists.txt                                     |   4 +-
 tests/unit/capi/GEOSBoundaryTest.cpp               |  17 +-
 tests/unit/capi/GEOSBufferTest.cpp                 | 111 +++-------
 tests/unit/capi/GEOSBuildAreaTest.cpp              |  17 +-
 tests/unit/capi/GEOSClipByRectTest.cpp             | 244 ++++++++++++---------
 tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp  |  10 +-
 tests/unit/capi/GEOSConcaveHullTest.cpp            |  34 +--
 .../GEOSConstrainedDelaunayTriangulationTest.cpp   |   8 +-
 tests/unit/capi/GEOSContainsTest.cpp               |  27 +--
 tests/unit/capi/GEOSConvexHullTest.cpp             |  17 +-
 tests/unit/capi/GEOSCoveredByTest.cpp              |   3 -
 tests/unit/capi/GEOSCoversTest.cpp                 |   3 -
 tests/unit/capi/GEOSCrossesTest.cpp                |   3 -
 tests/unit/capi/GEOSDelaunayTriangulationTest.cpp  |  61 ++----
 tests/unit/capi/GEOSDensifyTest.cpp                |  37 ++--
 tests/unit/capi/GEOSDifferencePrecTest.cpp         |  23 +-
 tests/unit/capi/GEOSDifferenceTest.cpp             |  22 +-
 tests/unit/capi/GEOSDisjointSubsetUnionTest.cpp    |   7 +-
 tests/unit/capi/GEOSDisjointTest.cpp               |   3 -
 tests/unit/capi/GEOSDistanceTest.cpp               |  94 ++++----
 tests/unit/capi/GEOSDistanceWithinTest.cpp         |  24 +-
 tests/unit/capi/GEOSEnvelopeTest.cpp               |  77 +++----
 22 files changed, 361 insertions(+), 485 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list