PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_ptarray_append_ptarray ( void  )
static

Definition at line 105 of file cu_ptarray.c.

References POINTARRAY::flags, FLAGS_SET_READONLY, LW_FAILURE, LW_SUCCESS, lwfree(), lwgeom_as_lwline(), lwgeom_from_text(), lwgeom_to_text(), lwline_as_lwgeom(), lwline_free(), LWLINE::points, and ptarray_append_ptarray().

Referenced by ptarray_suite_setup().

106 {
107  LWLINE *line1, *line2;
108  int ret;
109  char *wkt;
110 
111  /* Empty first line */
112  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING EMPTY"));
113  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0,0 10,5 5)"));
114  ret = ptarray_append_ptarray(line1->points, line2->points, -1);
115  CU_ASSERT(ret == LW_SUCCESS);
116  wkt = lwgeom_to_text(lwline_as_lwgeom(line1));
117  CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING(0 0,0 10,5 5)");
118  lwfree(wkt);
119  lwline_free(line2);
120  lwline_free(line1);
121 
122  /* Empty second line */
123  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 5 5, 6 3)"));
124  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING EMPTY"));
125  ret = ptarray_append_ptarray(line1->points, line2->points, -1);
126  CU_ASSERT(ret == LW_SUCCESS);
127  wkt = lwgeom_to_text(lwline_as_lwgeom(line1));
128  CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING(0 0,5 5,6 3)");
129  lwfree(wkt);
130  lwline_free(line2);
131  lwline_free(line1);
132 
133  /* Both lines empty */
134  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING EMPTY"));
135  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING EMPTY"));
136  ret = ptarray_append_ptarray(line1->points, line2->points, -1);
137  CU_ASSERT(ret == LW_SUCCESS);
138  wkt = lwgeom_to_text(lwline_as_lwgeom(line1));
139  CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING EMPTY");
140  lwfree(wkt);
141  lwline_free(line2);
142  lwline_free(line1);
143 
144  /* Sane sewing */
145  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(10 4, 0 0,5 7)"));
146  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(5 7,12 43, 42 15)"));
147  ret = ptarray_append_ptarray(line1->points, line2->points, 0);
148  CU_ASSERT(ret == LW_SUCCESS);
149  wkt = lwgeom_to_text(lwline_as_lwgeom(line1));
150  CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING(10 4,0 0,5 7,12 43,42 15)");
151  lwfree(wkt);
152  lwline_free(line2);
153  lwline_free(line1);
154 
155  /* Untolerated sewing */
156  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(10 4, 0 0,5 7)"));
157  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(5.5 7,12 43, 42 15)"));
158  ret = ptarray_append_ptarray(line1->points, line2->points, 0);
159  CU_ASSERT(ret == LW_FAILURE);
160  lwline_free(line2);
161  lwline_free(line1);
162 
163  /* Tolerated sewing */
164  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(10 4, 0 0,5 7)"));
165  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(5.5 7,12 43, 42 15)"));
166  ret = ptarray_append_ptarray(line1->points, line2->points, .7);
167  CU_ASSERT(ret == LW_SUCCESS);
168  wkt = lwgeom_to_text(lwline_as_lwgeom(line1));
169  CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING(10 4,0 0,5 7,5.5 7,12 43,42 15)");
170  lwfree(wkt);
171  lwline_free(line2);
172  lwline_free(line1);
173 
174  /* Check user input trust (creates non-simple line */
175  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0,0 10)"));
176  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0,0 10)"));
177  ret = ptarray_append_ptarray(line1->points, line2->points, -1);
178  CU_ASSERT(ret == LW_SUCCESS);
179  wkt = lwgeom_to_text(lwline_as_lwgeom(line1));
180  CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING(0 0,0 10,0 0,0 10)");
181  lwfree(wkt);
182  lwline_free(line2);
183  lwline_free(line1);
184 
185  /* Mixed dimensionality is not allowed */
186  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 10 0, 10 0 0)"));
187  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(10 0,11 0)"));
188  ret = ptarray_append_ptarray(line1->points, line2->points, -1);
189  CU_ASSERT(ret == LW_FAILURE);
190  lwline_free(line2);
191  lwline_free(line1);
192 
193  /* Appending a read-only pointarray is allowed */
194  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 10, 10 0)"));
195  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(10 0,11 0)"));
196  FLAGS_SET_READONLY(line2->points->flags, 1);
197  ret = ptarray_append_ptarray(line1->points, line2->points, -1);
198  CU_ASSERT(ret == LW_SUCCESS);
199  wkt = lwgeom_to_text(lwline_as_lwgeom(line1));
200  CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING(0 10,10 0,11 0)");
201  lwfree(wkt);
202  FLAGS_SET_READONLY(line2->points->flags, 0); /* for lwline_free */
203  lwline_free(line2);
204  lwline_free(line1);
205 
206  /* Appending to a read-only pointarray is forbidden */
207  line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 10, 10 0)"));
208  line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(10 0,11 0)"));
209  FLAGS_SET_READONLY(line1->points->flags, 1);
210  ret = ptarray_append_ptarray(line1->points, line2->points, -1);
211  CU_ASSERT(ret == LW_FAILURE);
212  lwline_free(line2);
213  FLAGS_SET_READONLY(line1->points->flags, 0); /* for lwline_free */
214  lwline_free(line1);
215 
216 }
void lwfree(void *mem)
Definition: lwutil.c:190
#define LW_SUCCESS
Definition: liblwgeom.h:55
void lwline_free(LWLINE *line)
Definition: lwline.c:63
#define LW_FAILURE
Definition: liblwgeom.h:54
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_ptarray.c:25
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:249
uint8_t flags
Definition: liblwgeom.h:325
static char * lwgeom_to_text(const LWGEOM *geom)
Definition: cu_ptarray.c:33
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
Definition: ptarray.c:172
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
#define FLAGS_SET_READONLY(flags, value)
Definition: liblwgeom.h:116
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function:

Here is the caller graph for this function: