PostGIS  2.1.10dev-r@@SVN_REVISION@@
cu_geos.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright 2011 Sandro Santilli <strk@keybit.net>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "CUnit/Basic.h"
17 
18 #include "lwgeom_geos.h"
19 #include "cu_tester.h"
20 
21 static void test_geos_noop(void)
22 {
23  int i;
24 
25  char *ewkt[] =
26  {
27  "POINT(0 0.2)",
28  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
29  "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
30  "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
31  "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
32  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
33  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
34  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
35  "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
36  "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
37  "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
38  "GEOMETRYCOLLECTION( LINESTRING (1 1, 2 2), POINT EMPTY, TRIANGLE ((0 0, 1 0, 1 1, 0 0)) )",
39  };
40 
41 
42  for ( i = 0; i < (sizeof ewkt/sizeof(char *)); i++ )
43  {
44  LWGEOM *geom_in, *geom_out;
45  char *in_ewkt;
46  char *out_ewkt;
47 
48  in_ewkt = ewkt[i];
49  geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
50  geom_out = lwgeom_geos_noop(geom_in);
51  if ( ! geom_out ) {
52  fprintf(stderr, "\nNull return from lwgeom_geos_noop with wkt: %s\n", in_ewkt);
53  lwgeom_free(geom_in);
54  continue;
55  }
56  out_ewkt = lwgeom_to_ewkt(geom_out);
57  if (strcmp(in_ewkt, out_ewkt))
58  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
59  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
60  lwfree(out_ewkt);
61  lwgeom_free(geom_out);
62  lwgeom_free(geom_in);
63  }
64 
65 
66 }
67 
68 
69 /*
70 ** Used by test harness to register the tests in this file.
71 */
72 void geos_suite_setup(void);
73 void geos_suite_setup(void)
74 {
75  CU_pSuite suite = CU_add_suite("GEOS", NULL, NULL);
77 }
void lwfree(void *mem)
Definition: lwutil.c:190
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:425
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWGEOM * lwgeom_geos_noop(const LWGEOM *geom)
Convert an LWGEOM to a GEOS Geometry and convert back – for debug only.
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
void geos_suite_setup(void)
Definition: cu_geos.c:73
static void test_geos_noop(void)
Definition: cu_geos.c:21
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
#define PG_ADD_TEST(suite, testfunc)