[geos-commits] r3442 - in trunk/tests/unit: . capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Jul 20 10:19:32 EDT 2011
Author: strk
Date: 2011-07-20 07:19:32 -0700 (Wed, 20 Jul 2011)
New Revision: 3442
Added:
trunk/tests/unit/capi/GEOSDistanceTest.cpp
Modified:
trunk/tests/unit/Makefile.am
Log:
Add unit test for bug #337.
Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am 2011-07-20 14:04:16 UTC (rev 3441)
+++ trunk/tests/unit/Makefile.am 2011-07-20 14:19:32 UTC (rev 3442)
@@ -100,6 +100,7 @@
capi/GEOSGeomFromWKBTest.cpp \
capi/GEOSGeomToWKTTest.cpp \
capi/GEOSContainsTest.cpp \
+ capi/GEOSDistanceTest.cpp \
capi/GEOSIntersectsTest.cpp \
capi/GEOSWithinTest.cpp \
capi/GEOSSimplifyTest.cpp \
Added: trunk/tests/unit/capi/GEOSDistanceTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSDistanceTest.cpp (rev 0)
+++ trunk/tests/unit/capi/GEOSDistanceTest.cpp 2011-07-20 14:19:32 UTC (rev 3442)
@@ -0,0 +1,87 @@
+//
+// Test Suite for C-API GEOSDistance
+
+#include <tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <memory>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used in test cases.
+ struct test_capigeosdistance_data
+ {
+ GEOSGeometry* geom1_;
+ GEOSGeometry* geom2_;
+ GEOSGeometry* geom3_;
+ GEOSWKTWriter* w_;
+
+ 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_capigeosdistance_data()
+ : geom1_(0), geom2_(0), geom3_(0), w_(0)
+ {
+ initGEOS(notice, notice);
+ w_ = GEOSWKTWriter_create();
+ GEOSWKTWriter_setTrim(w_, 1);
+ }
+
+ ~test_capigeosdistance_data()
+ {
+ GEOSGeom_destroy(geom1_);
+ GEOSGeom_destroy(geom2_);
+ GEOSGeom_destroy(geom3_);
+ GEOSWKTWriter_destroy(w_);
+ geom1_ = 0;
+ geom2_ = 0;
+ geom3_ = 0;
+ finishGEOS();
+ }
+
+ };
+
+ typedef test_group<test_capigeosdistance_data> group;
+ typedef group::object object;
+
+ group test_capigeosdistance_group("capi::GEOSDistance");
+
+ //
+ // Test Cases
+ //
+
+ /// See http://trac.osgeo.org/geos/ticket/377
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ geom1_ = GEOSGeomFromWKT("POINT(10 10)");
+ geom2_ = GEOSGeomFromWKT("POINT(3 6)");
+
+ double dist;
+ int ret = GEOSDistance(geom1_, geom2_, &dist);
+
+ ensure_equals(ret, 1);
+ ensure_distance(dist, 8.06225774829855, 1e-12);
+ }
+
+
+} // namespace tut
+
More information about the geos-commits
mailing list