[geos-commits] r2277 - in trunk: build/msvc90/geos_unit tests/unit
tests/unit/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Thu Mar 19 12:19:14 EDT 2009
Author: mloskot
Date: 2009-03-19 12:19:14 -0400 (Thu, 19 Mar 2009)
New Revision: 2277
Added:
trunk/tests/unit/capi/GEOSGeomFromWKBTest.cpp
Modified:
trunk/build/msvc90/geos_unit/geos_unit.vcproj
trunk/tests/unit/utility.h
Log:
* tests/unit/capi: added GEOSGeomFromWKBTest with test cases (see comment) reported as a bug (See http://postgis.refractions.net/pipermail/postgis-devel/2009-March/005199.html). TODO: Reproduce and ask the reporter to submit a ticket if necessary.
* test/unit/utility.h: Added helper class wkb_hex_decoder.
* Updated build/msvc90 projects.
Modified: trunk/build/msvc90/geos_unit/geos_unit.vcproj
===================================================================
--- trunk/build/msvc90/geos_unit/geos_unit.vcproj 2009-03-11 12:51:20 UTC (rev 2276)
+++ trunk/build/msvc90/geos_unit/geos_unit.vcproj 2009-03-19 16:19:14 UTC (rev 2277)
@@ -452,6 +452,18 @@
>
</File>
<File
+ RelativePath="..\..\..\tests\unit\capi\GEOSGeomFromWKBTest.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\tests\unit\capi\GEOSGeomToWKTTest.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\tests\unit\capi\GEOSPolygonizer_getCutEdgesTest.cpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\tests\unit\capi\GEOSSimplifyTest.cpp"
>
</File>
Added: trunk/tests/unit/capi/GEOSGeomFromWKBTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSGeomFromWKBTest.cpp (rev 0)
+++ trunk/tests/unit/capi/GEOSGeomFromWKBTest.cpp 2009-03-19 16:19:14 UTC (rev 2277)
@@ -0,0 +1,148 @@
+// $Id$
+//
+// Test Suite for C-API GEOSGeomFromWKB
+
+// TUT
+#include <tut.h>
+#include <utility.h> // wkb_hex_decoder
+// 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_capigeosgeomfromwkb_data
+ {
+ GEOSGeometry* geom1_;
+ GEOSGeometry* geom2_;
+ GEOSWKTReader* reader_;
+
+ 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_capigeosgeomfromwkb_data()
+ : geom1_(0), geom2_(0), reader_(0)
+ {
+ initGEOS(notice, notice);
+ reader_ = GEOSWKTReader_create();
+ }
+
+ ~test_capigeosgeomfromwkb_data()
+ {
+ GEOSGeom_destroy(geom2_);
+ geom2_ = 0;
+ GEOSGeom_destroy(geom1_);
+ geom1_ = 0;
+ GEOSWKTReader_destroy(reader_);
+ reader_ = 0;
+ finishGEOS();
+ }
+
+ void test_wkb(std::string const& wkbhex, std::string const& wkt)
+ {
+ wkb_hex_decoder::binary_type wkb;
+ wkb_hex_decoder::decode(wkbhex, wkb);
+
+ geom1_ = GEOSGeomFromWKB_buf(&wkb[0], wkb.size());
+ ensure("GEOSGeomFromWKB_buf failed to create geometry", 0 != geom1_ );
+
+ // TODO: Update test to compare with WKT-based geometry
+ // ATM, some XYZ and XYZM geometries fail
+ //geom2_ = GEOSWKTReader_read(reader_, wkt.c_str());
+ //ensure ( 0 != geom2_ );
+ //char result = GEOSEquals(geom1_, geom2_);
+ //ensure_equals(result, char(1));
+ }
+ };
+
+ typedef test_group<test_capigeosgeomfromwkb_data> group;
+ typedef group::object object;
+
+ group test_capigeosgeomfromwkb_group("capi::GEOSGeomFromWKB");
+
+ //
+ // Test Cases
+ //
+
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ // POINT(1.234 5.678)
+ std::string wkt("POINT (1.234 5.678)");
+ std::string wkb("01010000005839B4C876BEF33F83C0CAA145B61640");
+ test_wkb(wkb, wkt);
+ }
+
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ // SRID=4;POINT(0 0)
+ std::string wkt("POINT(0 0)");
+ std::string ewkb("01010000200400000000000000000000000000000000000000");
+ test_wkb(ewkb, wkt);
+ }
+
+ template<>
+ template<>
+ void object::test<3>()
+ {
+ // SRID=32632;POINT(1.234 5.678)
+ std::string wkt("POINT (1.234 5.678)");
+ std::string ewkb("0101000020787F00005839B4C876BEF33F83C0CAA145B61640");
+ test_wkb(ewkb, wkt);
+ }
+
+ template<>
+ template<>
+ void object::test<4>()
+ {
+ // POINT (1.234 5.678 15 79) -- XYZM
+ std::string wkt("POINT (1.234 5.678 15 79)");
+ std::string ewkb("01010000C05839B4C876BEF33F83C0CAA145B616400000000000002E400000000000C05340");
+ test_wkb(ewkb, wkt);
+ }
+
+ template<>
+ template<>
+ void object::test<5>()
+ {
+ std::string wkt("MULTIPOINT (1.123 1.456, 2.123 2.456, 3.123 3.456)");
+ std::string ewkb("01040000000300000001010000002b8716d9cef7f13fb29defa7c64bf73f010100000096438b6ce7fb0040d9cef753e3a50340010100000096438b6ce7fb0840d9cef753e3a50b40");
+ test_wkb(ewkb, wkt);
+ }
+
+ // TODO: Does GEOSGeomFromWKB_buf accept EWKB or WKB only?
+ // The cases below test EWKB input and they are failing.
+ //template<>
+ //template<>
+ //void object::test<6>()
+ //{
+ // // SELECT st_geomfromewkt('MULTIPOINT((0 0 1 1), (3 2 2 1))') ;
+ // std::string wkt("MULTIPOINT((0 0 1 1), (3 2 2 1))");
+ // std::string ewkb("01040000C00200000001010000C000000000000000000000000000000000000000000000F03F000000000000F03F01010000C0000000000000084000000000000000400000000000000040000000000000F03F");
+ // test_wkb(ewkb, wkt);
+ //}
+
+} // namespace tut
+
Modified: trunk/tests/unit/utility.h
===================================================================
--- trunk/tests/unit/utility.h 2009-03-11 12:51:20 UTC (rev 2276)
+++ trunk/tests/unit/utility.h 2009-03-19 16:19:14 UTC (rev 2277)
@@ -28,6 +28,8 @@
#include <memory>
#include <cstdlib>
#include <cassert>
+#include <string>
+#include <vector>
// tut
#include <tut.h>
@@ -215,6 +217,30 @@
ensure_equals_geometry(lhs, &pg);
}
+//
+// Utility functions
+//
+
+// Decodes hex-encoded WKB/EWKB to raw binary.
+struct wkb_hex_decoder
+{
+ typedef std::vector<unsigned char> binary_type;
+
+ // bytes [out] - buffer for binary output
+ static void decode(std::string const& hexstr, binary_type& bytes)
+ {
+ bytes.clear();
+ for(std::string::size_type i = 0; i < hexstr.size() / 2; ++i)
+ {
+ std::istringstream iss(hexstr.substr(i * 2, 2));
+ unsigned int n;
+ iss >> std::hex >> n;
+ bytes.push_back(static_cast<unsigned char>(n));
+ }
+ }
+};
+
+
} // namespace tut
#endif // #ifndef GEOS_TUT_UTILITY_H_INCLUDED
More information about the geos-commits
mailing list