[geos-commits] [SCM] GEOS branch master updated. 19dc3b19338c2aded5197ca0e5a5456b028defbd

git at osgeo.org git at osgeo.org
Sat Jun 20 05:19:18 PDT 2020


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, master has been updated
       via  19dc3b19338c2aded5197ca0e5a5456b028defbd (commit)
       via  bfa50020fdf725fd9e6b96278f3af645cda4769f (commit)
      from  099e74b3127348e1f8544ab279b609e2fdc6cc74 (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 19dc3b19338c2aded5197ca0e5a5456b028defbd
Merge: 099e74b bfa5002
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Jun 20 08:18:58 2020 -0400

    Merge remote-tracking branch 'dbaston/capi-tests'


commit bfa50020fdf725fd9e6b96278f3af645cda4769f
Author: Daniel Baston <dbaston at gmail.com>
Date:   Fri Jan 17 22:47:18 2020 -0500

    Add some CAPI tests

diff --git a/tests/unit/capi/GEOSBoundaryTest.cpp b/tests/unit/capi/GEOSBoundaryTest.cpp
new file mode 100644
index 0000000..1368155
--- /dev/null
+++ b/tests/unit/capi/GEOSBoundaryTest.cpp
@@ -0,0 +1,38 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosboundary_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosboundary_data> group;
+typedef group::object object;
+
+group test_geosboundary("capi::GEOSBoundary");
+
+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);
+
+    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))");
+
+    ensure_equals(GEOSEqualsExact(result, expected, 0), 1);
+    ensure_equals(GEOSGetSRID(input), GEOSGetSRID(result));
+
+    GEOSGeom_destroy(input);
+    GEOSGeom_destroy(result);
+    GEOSGeom_destroy(expected);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSEnvelopeTest.cpp b/tests/unit/capi/GEOSEnvelopeTest.cpp
new file mode 100644
index 0000000..bc1a635
--- /dev/null
+++ b/tests/unit/capi/GEOSEnvelopeTest.cpp
@@ -0,0 +1,36 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosenvelope_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosenvelope_data> group;
+typedef group::object object;
+
+group test_geosenvelope("capi::GEOSEnvelope");
+
+template<>
+template<>
+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);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSGeom_createLineStringTest.cpp b/tests/unit/capi/GEOSGeom_createLineStringTest.cpp
new file mode 100644
index 0000000..a9181bc
--- /dev/null
+++ b/tests/unit/capi/GEOSGeom_createLineStringTest.cpp
@@ -0,0 +1,40 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosgeom_createlinestring_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosgeom_createlinestring_data> group;
+typedef group::object object;
+
+group test_geosgeom_createlinestring("capi::GEOSGeom_createLineString");
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    GEOSCoordSequence* seq = GEOSCoordSeq_create(3, 2);
+
+    GEOSCoordSeq_setXY(seq, 0, 1, 2);
+    GEOSCoordSeq_setXY(seq, 1, 4, 5);
+    GEOSCoordSeq_setXY(seq, 2, 9, -2);
+
+    GEOSGeometry* result = GEOSGeom_createLineString(seq);
+    GEOSGeometry* expected = GEOSGeomFromWKT("LINESTRING (1 2, 4 5, 9 -2)");
+
+    ensure_equals(GEOSEqualsExact(result, expected, 0), 1);
+
+    GEOSGeom_destroy(result);
+    GEOSGeom_destroy(expected);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSGeom_getCoordSeqTest.cpp b/tests/unit/capi/GEOSGeom_getCoordSeqTest.cpp
new file mode 100644
index 0000000..62b12b3
--- /dev/null
+++ b/tests/unit/capi/GEOSGeom_getCoordSeqTest.cpp
@@ -0,0 +1,50 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosgeom_getcoordseq_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosgeom_getcoordseq_data> group;
+typedef group::object object;
+
+group test_geosgeom_getcoordseq("capi::GEOSGeom_getCoordSeq");
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("LINESTRING (1 2, 4 5, 9 -2)");
+    const GEOSCoordSequence* seq = GEOSGeom_getCoordSeq(input);
+
+    double x = -1;
+    double y = -1;
+    GEOSCoordSeq_getXY(seq,  2, &x, &y);
+
+    ensure_equals(x, 9);
+    ensure_equals(y, -2);
+
+    GEOSGeom_destroy(input);
+}
+
+template<>
+template<>
+void object::test<2>()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("POLYGON ((1 1, 2 1, 2 2, 1 1))");
+    const GEOSCoordSequence* seq = GEOSGeom_getCoordSeq(input);
+
+    ensure(seq == nullptr); // can't get seq from Polygon
+
+    GEOSGeom_destroy(input);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSGeom_getCoordinateDimensionTest.cpp b/tests/unit/capi/GEOSGeom_getCoordinateDimensionTest.cpp
new file mode 100644
index 0000000..fa736e9
--- /dev/null
+++ b/tests/unit/capi/GEOSGeom_getCoordinateDimensionTest.cpp
@@ -0,0 +1,38 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosgeom_getcoordinatedimension_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosgeom_getcoordinatedimension_data> group;
+typedef group::object object;
+
+group test_geosgeom_getcoordinatedimension("capi::GEOSGeom_getCoordinateDimension");
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    GEOSGeometry* point = GEOSGeomFromWKT("POINT (4 2 7)");
+    GEOSGeometry* line = GEOSGeomFromWKT("LINESTRING (4 2 7, 8 2 9)");
+    GEOSGeometry* poly = GEOSGeomFromWKT("POLYGON ((0 0, 1 0, 1 1, 0 0))");
+
+    ensure_equals(GEOSGeom_getCoordinateDimension(point), 3);
+    ensure_equals(GEOSGeom_getCoordinateDimension(line), 3);
+    ensure_equals(GEOSGeom_getCoordinateDimension(poly), 2);
+
+    GEOSGeom_destroy(point);
+    GEOSGeom_destroy(line);
+    GEOSGeom_destroy(poly);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSGeom_getDimensionsTest.cpp b/tests/unit/capi/GEOSGeom_getDimensionsTest.cpp
new file mode 100644
index 0000000..f03296a
--- /dev/null
+++ b/tests/unit/capi/GEOSGeom_getDimensionsTest.cpp
@@ -0,0 +1,38 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosgeom_getdimensions_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosgeom_getdimensions_data> group;
+typedef group::object object;
+
+group test_geosgeom_getdimensions("capi::GEOSGeom_getDimensions");
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    GEOSGeometry* point = GEOSGeomFromWKT("POINT (4 2 7)");
+    GEOSGeometry* line = GEOSGeomFromWKT("LINESTRING (4 2 7, 8 2 9)");
+    GEOSGeometry* poly = GEOSGeomFromWKT("POLYGON ((0 0, 1 0, 1 1, 0 0))");
+
+    ensure_equals(GEOSGeom_getDimensions(point), 0);
+    ensure_equals(GEOSGeom_getDimensions(line), 1);
+    ensure_equals(GEOSGeom_getDimensions(poly), 2);
+
+    GEOSGeom_destroy(point);
+    GEOSGeom_destroy(line);
+    GEOSGeom_destroy(poly);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSGetNumInteriorRingsTest.cpp b/tests/unit/capi/GEOSGetNumInteriorRingsTest.cpp
new file mode 100644
index 0000000..ce9d96b
--- /dev/null
+++ b/tests/unit/capi/GEOSGetNumInteriorRingsTest.cpp
@@ -0,0 +1,42 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosgetnuminteriorrings_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosgetnuminteriorrings_data> group;
+typedef group::object object;
+
+group test_getnuminteriorrings("capi::GEOSGetNumInteriorRings");
+
+template<>
+template<>
+void object::test<1>()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("POLYGON ((1 -2, 9 -2, 9 5, 1 5, 1 -2))");
+
+    ensure_equals(GEOSGetNumInteriorRings(input), 0);
+
+    GEOSGeom_destroy(input);
+}
+
+template<>
+template<>
+void object::test<2>()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("LINESTRING (3 8, 4 7)");
+
+    ensure_equals(GEOSGetNumInteriorRings(input), -1);
+
+    GEOSGeom_destroy(input);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSLengthTest.cpp b/tests/unit/capi/GEOSLengthTest.cpp
new file mode 100644
index 0000000..9214e76
--- /dev/null
+++ b/tests/unit/capi/GEOSLengthTest.cpp
@@ -0,0 +1,36 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geoslength_data : public capitest::test_handlers {};
+
+typedef test_group<test_geoslength_data> group;
+typedef group::object object;
+
+group test_geoslength("capi::GEOSLength");
+
+template<>
+template<>
+void object::test<1>()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("LINESTRING (1 0, 5 0)");
+
+    double length = -1;
+
+    int ret = GEOSLength(input, &length);
+
+    ensure_equals(ret, 1);
+    ensure_equals(length, 4);
+
+    GEOSGeom_destroy(input);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSSetSRIDTest.cpp b/tests/unit/capi/GEOSSetSRIDTest.cpp
new file mode 100644
index 0000000..13a7645
--- /dev/null
+++ b/tests/unit/capi/GEOSSetSRIDTest.cpp
@@ -0,0 +1,33 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geossetsrid_data : public capitest::test_handlers {};
+
+typedef test_group<test_geossetsrid_data> group;
+typedef group::object object;
+
+group test_geossetsrid("capi::GEOSSetSRID");
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("LINESTRING (1 2, 4 5, 9 -2)");
+    GEOSSetSRID(input, 1234);
+
+    ensure_equals(GEOSGetSRID(input), 1234);
+
+    GEOSGeom_destroy(input);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSUnionTest.cpp b/tests/unit/capi/GEOSUnionTest.cpp
new file mode 100644
index 0000000..ed962db
--- /dev/null
+++ b/tests/unit/capi/GEOSUnionTest.cpp
@@ -0,0 +1,47 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosunion_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosunion_data> group;
+typedef group::object object;
+
+group test_geosunion("capi::GEOSUnion");
+
+template<>
+template<>
+void object::test<1>()
+{
+    GEOSGeometry* a = GEOSGeomFromWKT("POINT (2 8)");
+    GEOSGeometry* b = GEOSGeomFromWKT("POINT (3 9)");
+
+    ensure(a);
+    ensure(b);
+
+    GEOSSetSRID(a, 4326);
+
+    GEOSGeometry* result = GEOSUnion(a, b);
+    GEOSGeometry* expected = GEOSGeomFromWKT("MULTIPOINT (2 8, 3 9)");
+
+    ensure(result);
+    ensure(expected);
+
+    ensure_equals(GEOSEqualsExact(result, expected, 0), 1);
+    ensure_equals(GEOSGetSRID(a), GEOSGetSRID(result));
+
+    GEOSGeom_destroy(a);
+    GEOSGeom_destroy(b);
+    GEOSGeom_destroy(result);
+    GEOSGeom_destroy(expected);
+}
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSisValidReasonTest.cpp b/tests/unit/capi/GEOSisValidReasonTest.cpp
new file mode 100644
index 0000000..4f4bfd7
--- /dev/null
+++ b/tests/unit/capi/GEOSisValidReasonTest.cpp
@@ -0,0 +1,43 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosisvalid_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosisvalid_data> group;
+typedef group::object object;
+
+group test_geosisvalid("capi::GEOSisValid");
+
+template<>
+template<>
+void object::test<1>()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("LINESTRING (1 2, 4 5, 9 -2)");
+
+    ensure_equals(1, GEOSisValid(input));
+
+    GEOSGeom_destroy(input);
+}
+
+template<>
+template<>
+void object::test<2>()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("POLYGON ((0 0, 1 0, 0 1, 1 1, 0 0))");
+
+    ensure_equals(0, GEOSisValid(input));
+
+    GEOSGeom_destroy(input);
+}
+
+
+} // namespace tut
+
diff --git a/tests/unit/capi/GEOSisValidTest.cpp b/tests/unit/capi/GEOSisValidTest.cpp
new file mode 100644
index 0000000..b1aa68a
--- /dev/null
+++ b/tests/unit/capi/GEOSisValidTest.cpp
@@ -0,0 +1,49 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosisvalidreason_data : public capitest::test_handlers {};
+
+typedef test_group<test_geosisvalidreason_data> group;
+typedef group::object object;
+
+group test_geosisvalidreason("capi::GEOSisValidReason");
+
+template<>
+template<>
+void object::test<1>()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("LINESTRING (1 2, 4 5, 9 -2)");
+
+    char* reason = GEOSisValidReason(input);
+
+    ensure_equals(std::string(reason), "Valid Geometry");
+
+    GEOSGeom_destroy(input);
+    GEOSFree(reason);
+}
+
+template<>
+template<>
+void object::test<2>()
+{
+    GEOSGeometry* input = GEOSGeomFromWKT("POLYGON ((0 0, 1 0, 0 1, 1 1, 0 0))");
+
+    char* reason = GEOSisValidReason(input);
+
+    ensure_equals(std::string(reason), "Self-intersection[0.5 0.5]");
+
+    GEOSGeom_destroy(input);
+    GEOSFree(reason);
+}
+
+
+} // namespace tut
+
diff --git a/tests/unit/capi/capi_test_utils.h b/tests/unit/capi/capi_test_utils.h
new file mode 100644
index 0000000..3a4a6e5
--- /dev/null
+++ b/tests/unit/capi/capi_test_utils.h
@@ -0,0 +1,42 @@
+#ifndef GEOS_CAPI_TEST_UTILS_H
+#define GEOS_CAPI_TEST_UTILS_H
+
+#include <geos_c.h>
+
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+
+
+
+namespace capitest {
+
+    struct test_handlers {
+        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_handlers()
+        {
+            initGEOS(notice, notice);
+        }
+
+        ~test_handlers()
+        {
+            finishGEOS();
+        }
+    };
+
+}
+
+#endif

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

Summary of changes:
 tests/unit/capi/GEOSBoundaryTest.cpp               | 38 ++++++++++++++++
 tests/unit/capi/GEOSEnvelopeTest.cpp               | 36 ++++++++++++++++
 tests/unit/capi/GEOSGeom_createLineStringTest.cpp  | 40 +++++++++++++++++
 tests/unit/capi/GEOSGeom_getCoordSeqTest.cpp       | 50 ++++++++++++++++++++++
 .../capi/GEOSGeom_getCoordinateDimensionTest.cpp   | 38 ++++++++++++++++
 tests/unit/capi/GEOSGeom_getDimensionsTest.cpp     | 38 ++++++++++++++++
 tests/unit/capi/GEOSGetNumInteriorRingsTest.cpp    | 42 ++++++++++++++++++
 tests/unit/capi/GEOSLengthTest.cpp                 | 36 ++++++++++++++++
 tests/unit/capi/GEOSSetSRIDTest.cpp                | 33 ++++++++++++++
 tests/unit/capi/GEOSUnionTest.cpp                  | 47 ++++++++++++++++++++
 tests/unit/capi/GEOSisValidReasonTest.cpp          | 43 +++++++++++++++++++
 tests/unit/capi/GEOSisValidTest.cpp                | 49 +++++++++++++++++++++
 tests/unit/capi/capi_test_utils.h                  | 42 ++++++++++++++++++
 13 files changed, 532 insertions(+)
 create mode 100644 tests/unit/capi/GEOSBoundaryTest.cpp
 create mode 100644 tests/unit/capi/GEOSEnvelopeTest.cpp
 create mode 100644 tests/unit/capi/GEOSGeom_createLineStringTest.cpp
 create mode 100644 tests/unit/capi/GEOSGeom_getCoordSeqTest.cpp
 create mode 100644 tests/unit/capi/GEOSGeom_getCoordinateDimensionTest.cpp
 create mode 100644 tests/unit/capi/GEOSGeom_getDimensionsTest.cpp
 create mode 100644 tests/unit/capi/GEOSGetNumInteriorRingsTest.cpp
 create mode 100644 tests/unit/capi/GEOSLengthTest.cpp
 create mode 100644 tests/unit/capi/GEOSSetSRIDTest.cpp
 create mode 100644 tests/unit/capi/GEOSUnionTest.cpp
 create mode 100644 tests/unit/capi/GEOSisValidReasonTest.cpp
 create mode 100644 tests/unit/capi/GEOSisValidTest.cpp
 create mode 100644 tests/unit/capi/capi_test_utils.h


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list