[geos-commits] r2164 - trunk/tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Aug 18 19:30:00 EDT 2008


Author: mloskot
Date: 2008-08-18 19:30:00 -0400 (Mon, 18 Aug 2008)
New Revision: 2164

Modified:
   trunk/tests/unit/capi/GEOSCoordSeqTest.cpp
   trunk/tests/unit/capi/GEOSSimplifyTest.cpp
Log:
tests/unit/capi: Fixed number of memory leaks.

Modified: trunk/tests/unit/capi/GEOSCoordSeqTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSCoordSeqTest.cpp	2008-08-18 16:32:50 UTC (rev 2163)
+++ trunk/tests/unit/capi/GEOSCoordSeqTest.cpp	2008-08-18 23:30:00 UTC (rev 2164)
@@ -21,6 +21,9 @@
     // Common data used in test cases.
     struct test_capigeoscoordseq_data
 	{
+
+        GEOSCoordSequence* cs_;
+
 		static void notice(const char *fmt, ...)
 		{
             std::fprintf( stdout, "NOTICE: ");
@@ -33,13 +36,15 @@
 			std::fprintf(stdout, "\n");
 		}
 
-		test_capigeoscoordseq_data()
+		test_capigeoscoordseq_data() : cs_(0)
 		{
 			initGEOS(notice, notice);
 		}		
 
 		~test_capigeoscoordseq_data()
 		{
+            GEOSCoordSeq_destroy(cs_);
+            cs_ = 0;
 			finishGEOS();
 		}
 
@@ -59,15 +64,15 @@
     template<>
     void object::test<1>()
     {
-		GEOSCoordSequence* cs = GEOSCoordSeq_create(5, 3);
+		cs_ = GEOSCoordSeq_create(5, 3);
 		
 		unsigned int size;
 		unsigned int dims;
 
-		ensure ( 0 != GEOSCoordSeq_getSize(cs, &size) );
+		ensure ( 0 != GEOSCoordSeq_getSize(cs_, &size) );
 		ensure_equals( size, 5u );
 
-		ensure ( 0 != GEOSCoordSeq_getDimensions(cs, &dims) );
+		ensure ( 0 != GEOSCoordSeq_getDimensions(cs_, &dims) );
 		ensure_equals( dims, 3u );
 
 		for (unsigned int i=0; i<5; ++i)
@@ -76,14 +81,14 @@
 			double y = i*10+1;
 			double z = i*10+2;
 
-			GEOSCoordSeq_setX(cs, i, x);
-			GEOSCoordSeq_setY(cs, i, y);
-			GEOSCoordSeq_setZ(cs, i, z);
+			GEOSCoordSeq_setX(cs_, i, x);
+			GEOSCoordSeq_setY(cs_, i, y);
+			GEOSCoordSeq_setZ(cs_, i, z);
 
 			double xcheck, ycheck, zcheck;
-			ensure( 0 != GEOSCoordSeq_getX(cs, i, &xcheck) );
-			ensure( 0 != GEOSCoordSeq_getY(cs, i, &ycheck) );
-			ensure( 0 != GEOSCoordSeq_getZ(cs, i, &zcheck) );
+			ensure( 0 != GEOSCoordSeq_getX(cs_, i, &xcheck) );
+			ensure( 0 != GEOSCoordSeq_getY(cs_, i, &ycheck) );
+			ensure( 0 != GEOSCoordSeq_getZ(cs_, i, &zcheck) );
 
 			ensure_equals( xcheck, x );
 			ensure_equals( ycheck, y );
@@ -96,15 +101,15 @@
     template<>
     void object::test<2>()
     {
-		GEOSCoordSequence* cs = GEOSCoordSeq_create(1, 3);
+		cs_ = GEOSCoordSeq_create(1, 3);
 		
 		unsigned int size;
 		unsigned int dims;
 
-		ensure ( 0 != GEOSCoordSeq_getSize(cs, &size) );
+		ensure ( 0 != GEOSCoordSeq_getSize(cs_, &size) );
 		ensure_equals( size, 1u );
 
-		ensure ( 0 != GEOSCoordSeq_getDimensions(cs, &dims) );
+		ensure ( 0 != GEOSCoordSeq_getDimensions(cs_, &dims) );
 		ensure_equals( dims, 3u );
 
 		double x = 10;
@@ -112,14 +117,14 @@
 		double z = 12;
 
         // X, Y, Z
-		GEOSCoordSeq_setX(cs, 0, x);
-		GEOSCoordSeq_setY(cs, 0, y);
-		GEOSCoordSeq_setZ(cs, 0, z);
+		GEOSCoordSeq_setX(cs_, 0, x);
+		GEOSCoordSeq_setY(cs_, 0, y);
+		GEOSCoordSeq_setZ(cs_, 0, z);
 
 		double xcheck, ycheck, zcheck;
-		ensure( 0 != GEOSCoordSeq_getY(cs, 0, &ycheck) );
-		ensure( 0 != GEOSCoordSeq_getX(cs, 0, &xcheck) );
-		ensure( 0 != GEOSCoordSeq_getZ(cs, 0, &zcheck) );
+		ensure( 0 != GEOSCoordSeq_getY(cs_, 0, &ycheck) );
+		ensure( 0 != GEOSCoordSeq_getX(cs_, 0, &xcheck) );
+		ensure( 0 != GEOSCoordSeq_getZ(cs_, 0, &zcheck) );
 
 		ensure_equals( xcheck, x );
 		ensure_equals( ycheck, y );
@@ -131,15 +136,15 @@
     template<>
     void object::test<3>()
     {
-		GEOSCoordSequence* cs = GEOSCoordSeq_create(1, 3);
+		cs_ = GEOSCoordSeq_create(1, 3);
 		
 		unsigned int size;
 		unsigned int dims;
 
-		ensure ( 0 != GEOSCoordSeq_getSize(cs, &size) );
+		ensure ( 0 != GEOSCoordSeq_getSize(cs_, &size) );
 		ensure_equals( size, 1u );
 
-		ensure ( 0 != GEOSCoordSeq_getDimensions(cs, &dims) );
+		ensure ( 0 != GEOSCoordSeq_getDimensions(cs_, &dims) );
 		ensure_equals( dims, 3u );
 
 		double x = 10;
@@ -147,14 +152,14 @@
 		double z = 12;
 
         // X, Y, Z
-		GEOSCoordSeq_setOrdinate(cs, 0, 0, x);
-		GEOSCoordSeq_setOrdinate(cs, 0, 1, y);
-		GEOSCoordSeq_setOrdinate(cs, 0, 2, z);
+		GEOSCoordSeq_setOrdinate(cs_, 0, 0, x);
+		GEOSCoordSeq_setOrdinate(cs_, 0, 1, y);
+		GEOSCoordSeq_setOrdinate(cs_, 0, 2, z);
 
 		double xcheck, ycheck, zcheck;
-		ensure( 0 != GEOSCoordSeq_getOrdinate(cs, 0, 1, &ycheck) );
-		ensure( 0 != GEOSCoordSeq_getOrdinate(cs, 0, 0, &xcheck) );
-		ensure( 0 != GEOSCoordSeq_getOrdinate(cs, 0, 2, &zcheck) );
+		ensure( 0 != GEOSCoordSeq_getOrdinate(cs_, 0, 1, &ycheck) );
+		ensure( 0 != GEOSCoordSeq_getOrdinate(cs_, 0, 0, &xcheck) );
+		ensure( 0 != GEOSCoordSeq_getOrdinate(cs_, 0, 2, &zcheck) );
 
 		ensure_equals( xcheck, x );
 		ensure_equals( ycheck, y );
@@ -166,15 +171,15 @@
     template<>
     void object::test<4>()
     {
-		GEOSCoordSequence* cs = GEOSCoordSeq_create(1, 3);
+		cs_ = GEOSCoordSeq_create(1, 3);
 		
 		unsigned int size;
 		unsigned int dims;
 
-		ensure ( 0 != GEOSCoordSeq_getSize(cs, &size) );
+		ensure ( 0 != GEOSCoordSeq_getSize(cs_, &size) );
 		ensure_equals( size, 1u );
 
-		ensure ( 0 != GEOSCoordSeq_getDimensions(cs, &dims) );
+		ensure ( 0 != GEOSCoordSeq_getDimensions(cs_, &dims) );
 		ensure_equals( dims, 3u );
 
 		double x = 10;
@@ -182,14 +187,14 @@
 		double z = 12;
 
         // Y, X, Z
-		GEOSCoordSeq_setY(cs, 0, y);
-		GEOSCoordSeq_setX(cs, 0, x);
-		GEOSCoordSeq_setZ(cs, 0, z);
+		GEOSCoordSeq_setY(cs_, 0, y);
+		GEOSCoordSeq_setX(cs_, 0, x);
+		GEOSCoordSeq_setZ(cs_, 0, z);
 
 		double xcheck, ycheck, zcheck;
-		ensure( 0 != GEOSCoordSeq_getY(cs, 0, &ycheck) );
-		ensure( 0 != GEOSCoordSeq_getX(cs, 0, &xcheck) );
-		ensure( 0 != GEOSCoordSeq_getZ(cs, 0, &zcheck) );
+		ensure( 0 != GEOSCoordSeq_getY(cs_, 0, &ycheck) );
+		ensure( 0 != GEOSCoordSeq_getX(cs_, 0, &xcheck) );
+		ensure( 0 != GEOSCoordSeq_getZ(cs_, 0, &zcheck) );
 
 		ensure_equals( xcheck, x );
 		ensure_equals( ycheck, y );
@@ -201,15 +206,15 @@
     template<>
     void object::test<5>()
     {
-		GEOSCoordSequence* cs = GEOSCoordSeq_create(1, 3);
+		cs_ = GEOSCoordSeq_create(1, 3);
 		
 		unsigned int size;
 		unsigned int dims;
 
-		ensure ( 0 != GEOSCoordSeq_getSize(cs, &size) );
+		ensure ( 0 != GEOSCoordSeq_getSize(cs_, &size) );
 		ensure_equals( size, 1u );
 
-		ensure ( 0 != GEOSCoordSeq_getDimensions(cs, &dims) );
+		ensure ( 0 != GEOSCoordSeq_getDimensions(cs_, &dims) );
 		ensure_equals( dims, 3u );
 
 		double x = 10;
@@ -217,14 +222,14 @@
 		double z = 12;
 
         // Y, X, Z
-		GEOSCoordSeq_setOrdinate(cs, 0, 1, y);
-		GEOSCoordSeq_setOrdinate(cs, 0, 0, x);
-		GEOSCoordSeq_setOrdinate(cs, 0, 2, z);
+		GEOSCoordSeq_setOrdinate(cs_, 0, 1, y);
+		GEOSCoordSeq_setOrdinate(cs_, 0, 0, x);
+		GEOSCoordSeq_setOrdinate(cs_, 0, 2, z);
 
 		double xcheck, ycheck, zcheck;
-		ensure( 0 != GEOSCoordSeq_getOrdinate(cs, 0, 1, &ycheck) );
-		ensure( 0 != GEOSCoordSeq_getOrdinate(cs, 0, 0, &xcheck) );
-		ensure( 0 != GEOSCoordSeq_getOrdinate(cs, 0, 2, &zcheck) );
+		ensure( 0 != GEOSCoordSeq_getOrdinate(cs_, 0, 1, &ycheck) );
+		ensure( 0 != GEOSCoordSeq_getOrdinate(cs_, 0, 0, &xcheck) );
+		ensure( 0 != GEOSCoordSeq_getOrdinate(cs_, 0, 2, &zcheck) );
 
 		ensure_equals( xcheck, x );
 		ensure_equals( ycheck, y );

Modified: trunk/tests/unit/capi/GEOSSimplifyTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSSimplifyTest.cpp	2008-08-18 16:32:50 UTC (rev 2163)
+++ trunk/tests/unit/capi/GEOSSimplifyTest.cpp	2008-08-18 23:30:00 UTC (rev 2164)
@@ -21,6 +21,9 @@
     // Common data used in test cases.
     struct test_capigeossimplify_data
 	{
+	    GEOSGeometry* geom1_;
+	    GEOSGeometry* geom2_;
+
 		static void notice(const char *fmt, ...)
 		{
 			std::fprintf( stdout, "NOTICE: ");
@@ -34,12 +37,17 @@
 		}
 
 		test_capigeossimplify_data()
+            : geom1_(0), geom2_(0)
 		{
 			initGEOS(notice, notice);
 		}		
 
 		~test_capigeossimplify_data()
 		{
+            GEOSGeom_destroy(geom1_);
+            GEOSGeom_destroy(geom2_);
+            geom1_ = 0;
+            geom2_ = 0;
 			finishGEOS();
 		}
 
@@ -59,13 +67,13 @@
     template<>
     void object::test<1>()
     {
-	    GEOSGeometry* geom1 = GEOSGeomFromWKT("POLYGON EMPTY");
+	    geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");
 
-		ensure ( 0 != GEOSisEmpty(geom1) );
+		ensure ( 0 != GEOSisEmpty(geom1_) );
 
-		GEOSGeometry* geom2 = GEOSSimplify(geom1, 43.2);
+		geom2_ = GEOSSimplify(geom1_, 43.2);
 
-		ensure ( 0 != GEOSisEmpty(geom2) );
+		ensure ( 0 != GEOSisEmpty(geom2_) );
     }
     
 } // namespace tut



More information about the geos-commits mailing list