PostGIS  2.4.9dev-r@@SVN_REVISION@@
cu_sfcgal.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  *
7  * This is free software; you can redistribute and/or modify it under
8  * the terms of the GNU General Public Licence. See the COPYING file.
9  *
10  **********************************************************************/
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include "CUnit/Basic.h"
16 
17 #include "cu_tester.h"
18 #include "liblwgeom.h"
19 
20 extern LWGEOM* lwgeom_sfcgal_noop( const LWGEOM* geom_in );
21 
22 static void test_sfcgal_noop(void)
23 {
24  int i;
25 
26  char *ewkt[] =
27  {
28  "POINT(0 0.2)",
29  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
30  "TRIANGLE((0 0,-1 1,0 -1,0 0))",
31  "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)",
32  "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))",
33  "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))",
34  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
35  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
36  "SRID=4326;POLYGON((-1 -1 1,-1 2.5 1,2 2 2,2 -1 2,-1 -1 2),(0 0 1,0 1 1,1 1 1,1 0 2,0 0 2))",
37  "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 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0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)))",
43  "TIN(((0 0,0 -1,-1 1,0 0)),((0 0,1 0,0 -1,0 0)))",
44  };
45 
46  char *expected_ewkt[] =
47  {
48  "POINT(0 0.2)",
49  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
50  "TRIANGLE((0 0,-1 1,0 -1,0 0))",
51  "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)",
52  "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))",
53  "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))",
54  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
55  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
56  "SRID=4326;POLYGON((-1 -1 1,-1 2.5 1,2 2 2,2 -1 2,-1 -1 2),(0 0 1,0 1 1,1 1 1,1 0 2,0 0 2))",
57  "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))",
58  "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))",
59  "SRID=4326;MULTIPO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*geom_in, *geom_out;
69  char *in_ewkt;
70  char *out_ewkt;
71 
72  in_ewkt = ewkt[i];
73  geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
74  geom_out = lwgeom_sfcgal_noop(geom_in);
75  if ( ! geom_out ) {
76  fprintf(stderr, "\nNull return from lwgeom_sfcgal_noop with wkt: %s\n", in_ewkt);
77  lwgeom_free(geom_in);
78  continue;
79  }
80  out_ewkt = lwgeom_to_ewkt(geom_out);
81  if (strcmp(expected_ewkt[i], out_ewkt))
82  fprintf(stderr, "\nExp: %s\nObt: %s\n", expected_ewkt[i], out_ewkt);
83  CU_ASSERT_STRING_EQUAL(expected_ewkt[i], out_ewkt);
84  lwfree(out_ewkt);
85  lwgeom_free(geom_out);
86  lwgeom_free(geom_in);
87  }
88 }
89 
90 
91 /*
92 ** Used by test harness to register the tests in this file.
93 */
94 void sfcgal_suite_setup(void);
96 {
97  CU_pSuite suite = CU_add_suite("SFCGAL", NULL, NULL);
99 }
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:518
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
LWGEOM * lwgeom_sfcgal_noop(const LWGEOM *geom_in)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
#define PG_ADD_TEST(suite, testfunc)
static void test_sfcgal_noop(void)
Definition: cu_sfcgal.c:22
void sfcgal_suite_setup(void)
Definition: cu_sfcgal.c:95
This library is the generic geometry handling section of PostGIS.