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

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Aug 28 17:35:13 EDT 2008


Author: mloskot
Date: 2008-08-28 17:35:13 -0400 (Thu, 28 Aug 2008)
New Revision: 2173

Added:
   trunk/tests/unit/capi/GEOSGeomToWKTTest.cpp
Modified:
   trunk/tests/unit/Makefile.am
Log:
tests/unit: added GEOSGeomToWKTTest.

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2008-08-28 19:16:09 UTC (rev 2172)
+++ trunk/tests/unit/Makefile.am	2008-08-28 21:35:13 UTC (rev 2173)
@@ -57,7 +57,8 @@
 	simplify/DouglasPeuckerSimplifierTest.cpp \
 	simplify/TopologyPreservingSimplifierTest.cpp \
 	util/UniqueCoordinateArrayFilterTest.cpp \
-	capi/GEOSCoordSeqTest.cpp	\
+	capi/GEOSCoordSeqTest.cpp \
+	capi/GEOSGeomToWKTTest.cpp \
 	capi/GEOSSimplifyTest.cpp \
 	capi/GEOSPolygonizer_getCutEdgesTest.cpp
 

Added: trunk/tests/unit/capi/GEOSGeomToWKTTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSGeomToWKTTest.cpp	                        (rev 0)
+++ trunk/tests/unit/capi/GEOSGeomToWKTTest.cpp	2008-08-28 21:35:13 UTC (rev 2173)
@@ -0,0 +1,171 @@
+// $Id$
+// 
+// Test Suite for C-API GEOSGeomToWKT
+
+// TUT
+#include <tut.h>
+// GEOS CAPI
+#include <geos_c.h>
+// C+
+#include <string>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <memory>
+
+namespace tut
+{
+    //
+    // Test Group
+    //
+
+    // Common data used in test cases.
+    struct test_capigeosgeomtowkt_data
+	{
+	    GEOSGeometry* geom1_;
+
+		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_capigeosgeomtowkt_data()
+            : geom1_(0)
+		{
+			initGEOS(notice, notice);
+		}		
+
+		~test_capigeosgeomtowkt_data()
+		{
+            GEOSGeom_destroy(geom1_);
+            geom1_ = 0;
+			finishGEOS();
+		}
+
+        void test_wkt(std::string const& wkt)
+        {
+            geom1_ = GEOSGeomFromWKT(wkt.c_str());
+            ensure ( 0 != geom1_ );
+
+            std::string out(GEOSGeomToWKT(geom1_));
+
+            ensure_equals(out, wkt);
+        }
+        
+        void test_wkt(std::string const& wkt, std::string::size_type n)
+        {
+            geom1_ = GEOSGeomFromWKT(wkt.c_str());
+            ensure ( 0 != geom1_ );
+
+            std::string out(GEOSGeomToWKT(geom1_));
+
+            ensure_equals(out.substr(0, n), wkt.substr(0, n));
+        }
+	};
+
+	typedef test_group<test_capigeosgeomtowkt_data> group;
+	typedef group::object object;
+
+	group test_capigeosgeomtowkt_group("capi::GEOSGeomToWKT");
+
+    //
+    // Test Cases
+    //
+
+    template<>
+    template<>
+    void object::test<1>()
+    {
+        test_wkt("POINT EMPTY");
+    }
+    
+    template<>
+    template<>
+    void object::test<2>()
+    {
+        test_wkt("LINESTRING EMPTY");
+    }
+    
+    template<>
+    template<>
+    void object::test<3>()
+    {
+        test_wkt("POLYGON EMPTY");
+    }
+    
+    template<>
+    template<>
+    void object::test<4>()
+    {
+        test_wkt("MULTIPOINT EMPTY");
+    }
+    
+    template<>
+    template<>
+    void object::test<5>()
+    {
+        test_wkt("MULTILINESTRING EMPTY");
+    }
+
+    template<>
+    template<>
+    void object::test<6>()
+    {
+        test_wkt("MULTIPOLYGON EMPTY");
+    }
+
+    // Comparing string based on float-point numbers does not make sense,
+    // so make poor-man comparison of WKT type tag.
+
+    template<>
+    template<>
+    void object::test<7>()
+    {
+        test_wkt("POINT (1.234 5.678)", 7);
+    }
+
+    template<>
+    template<>
+    void object::test<8>()
+    {
+        test_wkt("LINESTRING (0 0, 5 5, 10 5, 10 10)", 13);
+    }
+    
+    template<>
+    template<>
+    void object::test<9>()
+    {
+        test_wkt("POLYGON ((0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))", 11);
+    }
+    
+    template<>
+    template<>
+    void object::test<10>()
+    {
+        test_wkt("MULTIPOINT (0 0, 5 5, 10 10, 15 15, 20 20)", 13);
+    }
+    
+    template<>
+    template<>
+    void object::test<11>()
+    {
+        test_wkt("MULTILINESTRING ((0 0, 10 0, 10 10, 0 10, 10 20),(2 2, 2 6, 6 4, 20 2))", 19);
+    }
+
+    template<>
+    template<>
+    void object::test<12>()
+    {
+        test_wkt("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)))", 17);
+    }
+
+
+} // namespace tut
+


Property changes on: trunk/tests/unit/capi/GEOSGeomToWKTTest.cpp
___________________________________________________________________
Name: svn:keyword
   + Id



More information about the geos-commits mailing list