PostGIS  3.0.6dev-r@@SVN_REVISION@@
cu_gserialized2.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2019 Paul Ramsey <pramsey@cleverelephant.ca>
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 "liblwgeom_internal.h"
18 #include "gserialized2.c" /* for gserialized_peek_gbox_p */
19 #include "cu_tester.h"
20 
21 
22 static void test_g2flags_macros(void)
23 {
24  uint8_t flags = 0;
25 
26  CU_ASSERT_EQUAL(0, G2FLAGS_GET_Z(flags));
27  G2FLAGS_SET_Z(flags, 1);
28  CU_ASSERT_EQUAL(1, G2FLAGS_GET_Z(flags));
29  G2FLAGS_SET_Z(flags, 0);
30  CU_ASSERT_EQUAL(0, G2FLAGS_GET_Z(flags));
31  CU_ASSERT_EQUAL(0, G2FLAGS_GET_BBOX(flags));
32 
33  CU_ASSERT_EQUAL(0, G2FLAGS_GET_M(flags));
34  G2FLAGS_SET_M(flags, 1);
35  CU_ASSERT_EQUAL(1, G2FLAGS_GET_M(flags));
36 
37  CU_ASSERT_EQUAL(0, G2FLAGS_GET_BBOX(flags));
38  G2FLAGS_SET_BBOX(flags, 1);
39  CU_ASSERT_EQUAL(1, G2FLAGS_GET_BBOX(flags));
40 
41  CU_ASSERT_EQUAL(0, G2FLAGS_GET_GEODETIC(flags));
42  G2FLAGS_SET_GEODETIC(flags, 1);
43  CU_ASSERT_EQUAL(1, G2FLAGS_GET_GEODETIC(flags));
44 
45  flags = g2flags(1, 0, 1); /* z=1, m=0, geodetic=1 */
46 
47  CU_ASSERT_EQUAL(1, G2FLAGS_GET_GEODETIC(flags));
48  CU_ASSERT_EQUAL(1, G2FLAGS_GET_Z(flags));
49  CU_ASSERT_EQUAL(0, G2FLAGS_GET_M(flags));
50  CU_ASSERT_EQUAL(2, G2FLAGS_GET_ZM(flags));
51 
52  flags = g2flags(1, 1, 1); /* z=1, m=1, geodetic=1 */
53 
54  CU_ASSERT_EQUAL(1, G2FLAGS_GET_GEODETIC(flags));
55  CU_ASSERT_EQUAL(1, G2FLAGS_GET_Z(flags));
56  CU_ASSERT_EQUAL(1, G2FLAGS_GET_M(flags));
57  CU_ASSERT_EQUAL(3, G2FLAGS_GET_ZM(flags));
58 
59  flags = g2flags(0, 1, 0); /* z=0, m=1, geodetic=0 */
60 
61  CU_ASSERT_EQUAL(0, G2FLAGS_GET_GEODETIC(flags));
62  CU_ASSERT_EQUAL(0, G2FLAGS_GET_Z(flags));
63  CU_ASSERT_EQUAL(1, G2FLAGS_GET_M(flags));
64  CU_ASSERT_EQUAL(1, G2FLAGS_GET_ZM(flags));
65 
66  flags = 0;
67  G2FLAGS_SET_VERSION(flags, 0);
68  CU_ASSERT_EQUAL(0, G2FLAGS_GET_VERSION(flags));
69  G2FLAGS_SET_VERSION(flags, 1);
70  CU_ASSERT_EQUAL(1, G2FLAGS_GET_VERSION(flags));
71 }
72 
74 {
75  LWGEOM *lwg1, *lwg2;
76  GSERIALIZED *g;
77  size_t size = 0;
78 
79  /* No extended flags, so 32 bytes for a point */
80  lwg1 = lwgeom_from_wkt("POINT(100 100)", LW_PARSER_CHECK_NONE);
81  size = gserialized2_from_lwgeom_size(lwg1);
82  CU_ASSERT_EQUAL(size, 32);
83 
84  /* Add extended flag, we now expect 8 extra bytes */
85  FLAGS_SET_SOLID(lwg1->flags, 1);
86  CU_ASSERT_EQUAL(1, FLAGS_GET_SOLID(lwg1->flags));
87  size = gserialized2_from_lwgeom_size(lwg1);
88  CU_ASSERT_EQUAL(size, 40);
89 
90  /* We expect that the extended bit will be set on the serialization */
91  g = gserialized2_from_lwgeom(lwg1, &size);
92  CU_ASSERT_EQUAL(1, G2FLAGS_GET_EXTENDED(g->gflags));
93  /* And that the serialization in fact hits 40 bytes */
94  CU_ASSERT_EQUAL(size, 40);
95  lwgeom_free(lwg1);
96  lwg2 = lwgeom_from_gserialized2(g);
97  lwfree(g);
98  /* And that when deserialized again, the solid flag is still there */
99  CU_ASSERT_EQUAL(1, FLAGS_GET_SOLID(lwg2->flags));
100  lwgeom_free(lwg2);
101 
102 }
103 
104 static void test_gserialized2_srid(void)
105 {
106  GSERIALIZED s;
107  int32_t srid, rv;
108 
109  srid = 4326;
110  gserialized2_set_srid(&s, srid);
111  rv = gserialized2_get_srid(&s);
112  CU_ASSERT_EQUAL(rv, srid);
113 
114  srid = -3005;
115  gserialized2_set_srid(&s, srid);
116  rv = gserialized2_get_srid(&s);
117  //printf("srid=%d rv=%d\n",srid,rv);
118  CU_ASSERT_EQUAL(rv, SRID_UNKNOWN);
119 
120  srid = SRID_UNKNOWN;
121  gserialized2_set_srid(&s, srid);
122  rv = gserialized2_get_srid(&s);
123  CU_ASSERT_EQUAL(rv, srid);
124 
125  srid = SRID_UNKNOWN;
126  gserialized2_set_srid(&s, srid);
127  rv = gserialized2_get_srid(&s);
128  CU_ASSERT_EQUAL(rv, srid);
129 
130  srid = 100000;
131  gserialized2_set_srid(&s, srid);
132  rv = gserialized2_get_srid(&s);
133  CU_ASSERT_EQUAL(rv, srid);
134 }
135 
137 {
138  LWGEOM *g;
139  size_t size = 0;
140 
141  g = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
143  CU_ASSERT_EQUAL( size, 32 );
144  lwgeom_free(g);
145 
146  g = lwgeom_from_wkt("POINT(0 0 0)", LW_PARSER_CHECK_NONE);
148  CU_ASSERT_EQUAL( size, 40 );
149  lwgeom_free(g);
150 
151  g = lwgeom_from_wkt("MULTIPOINT(0 0 0, 1 1 1)", LW_PARSER_CHECK_NONE);
153  CU_ASSERT_EQUAL( size, 80 );
154  lwgeom_free(g);
155 
156  g = lwgeom_from_wkt("LINESTRING(0 0, 1 1)", LW_PARSER_CHECK_NONE);
158  CU_ASSERT_EQUAL( size, 48 );
159  lwgeom_free(g);
160 
161  g = lwgeom_from_wkt("MULTILINESTRING((0 0, 1 1),(0 0, 1 1))", LW_PARSER_CHECK_NONE);
163  CU_ASSERT_EQUAL( size, 96 );
164  lwgeom_free(g);
165 
166  g = lwgeom_from_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
168  CU_ASSERT_EQUAL( size, 104 );
169  lwgeom_free(g);
170 
171  g = lwgeom_from_wkt("POLYGON((-1 -1, -1 2, 2 2, 2 -1, -1 -1), (0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
173  CU_ASSERT_EQUAL( size, 184 );
174  lwgeom_free(g);
175 
176 }
177 
178 
180 {
181  LWGEOM *geom1, *geom2;
182  GSERIALIZED *g1, *g2;
183  char *in_ewkt, *out_ewkt;
184  size_t i = 0;
185 
186  char *ewkt[] =
187  {
188  "POINT EMPTY",
189  "POINT(0 0.2)",
190  "LINESTRING EMPTY",
191  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
192  "MULTIPOINT EMPTY",
193  "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)",
194  "MULTIPOINT(0.9 0.9,0.9 0.9,EMPTY,0.9 0.9,0.9 0.9,0.9 0.9)",
195  "SRID=1;MULTILINESTRING EMPTY",
196  "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))",
197  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
198  "POLYGON EMPTY",
199  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
200  "SRID=4326;POLYGON EMPTY",
201  "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))",
202  "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))",
203  "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)))",
204  "SRID=4326;MULTIPOLYGON EMPTY",
205  "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))))",
206  "SRID=4326;GEOMETRYCOLLECTION EMPTY",
207  "SRID=4326;GEOMETRYCOLLECTION(POINT EMPTY,MULTIPOLYGON EMPTY)",
208  "SRID=4326;GEOMETRYCOLLECTION(POINT(0 0.2),POINT EMPTY,POINT(0 0.2))",
209  "MULTICURVE((5 5 1 3,3 5 2 2,3 3 3 1,0 3 1 1),CIRCULARSTRING(0 0 0 0,0.26794 1 3 -2,0.5857864 1.414213 1 2))",
210  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0)),((7 8,10 10,6 14,4 11,7 8)))",
211  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING EMPTY))",
212  "POLYHEDRALSURFACE(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)),((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((1 0 0,1 1 0,1 1 1,1 0 1,1 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)))",
213  };
214 
215  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
216  {
217  size_t size1, size2;
218 
219  in_ewkt = ewkt[i];
220  geom1 = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
221  lwgeom_add_bbox(geom1);
222  if (geom1->bbox) gbox_float_round(geom1->bbox);
223  size1 = gserialized2_from_lwgeom_size(geom1);
224  g1 = gserialized2_from_lwgeom(geom1, &size2);
225  CU_ASSERT_EQUAL(size1, size2);
226 
227  geom2 = lwgeom_from_gserialized2(g1);
228  out_ewkt = lwgeom_to_ewkt(geom2);
229 
230  /* printf("\n in = %s\nout = %s\n", in_ewkt, out_ewkt); */
231  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
232  g2 = gserialized2_from_lwgeom(geom2, &size2);
233  CU_ASSERT_EQUAL(g1->gflags, g2->gflags);
234 
235  /* either both or none of the bboxes are null */
236  CU_ASSERT(geom1->bbox != NULL || geom2->bbox == NULL);
237 
238  /* either both are null or they are the same */
239  CU_ASSERT(geom1->bbox == NULL || gbox_same(geom1->bbox, geom2->bbox));
240 
241  lwfree(out_ewkt);
242  lwfree(g1);
243  lwfree(g2);
244  lwgeom_free(geom1);
245  lwgeom_free(geom2);
246 
247  /* SOLID / BOX INTERACTION */
248  geom1 = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
249  lwgeom_add_bbox(geom1);
250  FLAGS_SET_SOLID(geom1->flags, 1);
251  size1 = gserialized2_from_lwgeom_size(geom1);
252  g1 = gserialized2_from_lwgeom(geom1, &size2);
253  CU_ASSERT_EQUAL(size1, size2);
254  CU_ASSERT_EQUAL(SIZE_GET(g1->size), size2);
255  geom2 = lwgeom_from_gserialized2(g1);
256  CU_ASSERT_EQUAL(geom1->flags, geom2->flags);
257  g2 = gserialized2_from_lwgeom(geom2, &size2);
258  CU_ASSERT_EQUAL(SIZE_GET(g2->size), size2);
259  CU_ASSERT_EQUAL(g1->gflags, g2->gflags);
260  CU_ASSERT_EQUAL(FLAGS_GET_SOLID(geom2->flags), 1);
261  lwfree(g1);
262  lwfree(g2);
263  lwgeom_free(geom1);
264  lwgeom_free(geom2);
265  }
266 
267 }
268 
269 
270 static void test_gserialized2_is_empty(void)
271 {
272  int i = 0;
273  struct gserialized_empty_cases {
274  const char* wkt;
275  int isempty;
276  };
277 
278  struct gserialized_empty_cases cases[] = {
279  { "POINT EMPTY", 1 },
280  { "POINT(1 1)", 0 },
281  { "LINESTRING EMPTY", 1 },
282  { "MULTILINESTRING EMPTY", 1 },
283  { "MULTILINESTRING(EMPTY)", 1 },
284  { "MULTILINESTRING(EMPTY,EMPTY)", 1 },
285  { "MULTILINESTRING(EMPTY,(0 0,1 1))", 0 },
286  { "MULTILINESTRING((0 0,1 1),EMPTY)", 0 },
287  { "MULTILINESTRING(EMPTY,(0 0,1 1),EMPTY)", 0 },
288  { "MULTILINESTRING(EMPTY,EMPTY,EMPTY)", 1 },
289  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY,EMPTY,EMPTY))", 1 },
290  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY),POINT(1 1))", 0 },
291  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY, (0 0)),POINT EMPTY)", 0 },
292  { "GEOMETRYCOLLECTION(POLYGON EMPTY,POINT EMPTY,MULTILINESTRING(EMPTY,EMPTY),POINT EMPTY)", 1 },
293  { "GEOMETRYCOLLECTION(POLYGON EMPTY,GEOMETRYCOLLECTION(POINT EMPTY),MULTILINESTRING(EMPTY,EMPTY),POINT EMPTY)", 1 },
294  { NULL, 0 }
295  };
296 
297  while( cases[i].wkt )
298  {
299  // i = 11;
300  LWGEOM *lw = lwgeom_from_wkt(cases[i].wkt, LW_PARSER_CHECK_NONE);
302  int ie = gserialized2_is_empty(g);
303  // printf("%s: we say %d, they say %d\n", cases[i].wkt, cases[i].isempty, ie);
304  CU_ASSERT_EQUAL(ie, cases[i].isempty);
305  lwgeom_free(lw);
306  lwfree(g);
307  i++;
308  }
309 }
310 
311 
312 
314 {
315  LWGEOM *lwgeom;
316  GSERIALIZED *g_ser1;
317  size_t ret_size;
318 
319  lwgeom = lwgeom_from_wkt("MULTIPOINT(-1 -1,-1 2.5,2 2,2 -1,1 1,2 2,4 5)", LW_PARSER_CHECK_NONE);
320  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
321  g_ser1 = gserialized2_from_lwgeom(lwgeom, &ret_size);
322  lwgeom_free(lwgeom);
323 
324  lwgeom = lwgeom_from_gserialized2(g_ser1);
325  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
326  lwgeom_free(lwgeom);
327 
328  lwgeom = lwgeom_from_gserialized2(g_ser1);
329 
330  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
331  lwgeom_free(lwgeom);
332 
333  lwfree(g_ser1);
334 
335 }
336 
337 
339 {
340  uint32_t i;
341 
342  char *ewkt[] =
343  {
344  "POINT EMPTY",
345  "LINESTRING EMPTY",
346  "MULTIPOINT EMPTY",
347  "MULTIPOINT (EMPTY)",
348  "MULTILINESTRING EMPTY",
349  "MULTILINESTRING (EMPTY)"
350  };
351 
352  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
353  {
354  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
355  GBOX box;
356  gbox_init(&box);
357 
358  GSERIALIZED* gser = gserialized2_from_lwgeom(geom, NULL);
359 
360  CU_ASSERT_FALSE(gserialized2_has_bbox(gser));
361 
362  CU_ASSERT_EQUAL(LW_FAILURE, gserialized2_peek_gbox_p(gser, &box));
363 
364  lwgeom_free(geom);
365  lwfree(gser);
366  }
367 }
368 
370 {
371  uint32_t i;
372 
373  char *ewkt[] =
374  {
375  "POINT (2.2945672355 48.85822923236)",
376  "POINTZ (2.2945672355 48.85822923236 15)",
377  "POINTM (2.2945672355 48.85822923236 12)",
378  "POINT ZM (2.2945672355 48.85822923236 12 2)",
379  "MULTIPOINT ((-76.45402132523 44.225406213532))",
380  "MULTIPOINT Z ((-76.45402132523 44.225406213532 112))",
381  "MULTIPOINT ZM ((-76.45402132523 44.225406213532 112 44))",
382  "LINESTRING (2.2945672355 48.85822923236, -76.45402132523 44.225406213532)",
383  "LINESTRING Z (2.2945672355 48.85822923236 6, -76.45402132523 44.225406213532 8)",
384  "LINESTRING ZM (2.2945672355 48.85822923236 3 2, -76.45402132523 44.225406213532 9 4)",
385  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532))",
386  "MULTILINESTRING Z ((2.2945672355 48.85822923236 4, -76.45402132523 44.225406213532 3))"
387  };
388 
389  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
390  {
391  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
392  GBOX box_from_peek;
393  GBOX box_from_lwgeom;
394  gbox_init(&box_from_peek);
395  gbox_init(&box_from_lwgeom);
396 
397  GSERIALIZED* gser = gserialized2_from_lwgeom(geom, NULL);
398 
399  CU_ASSERT_FALSE(gserialized2_has_bbox(gser));
400 
401  lwgeom_calculate_gbox(geom, &box_from_lwgeom);
402  gserialized2_peek_gbox_p(gser, &box_from_peek);
403 
404  gbox_float_round(&box_from_lwgeom);
405 
406  CU_ASSERT_TRUE(gbox_same(&box_from_peek, &box_from_lwgeom));
407 
408  lwgeom_free(geom);
409  lwfree(gser);
410  }
411 }
412 
414 {
415  uint32_t i;
416 
417  char *ewkt[] =
418  {
419  "MULTIPOINT ((-76.45402132523 44.225406213532), (-72 33))",
420  "LINESTRING (2.2945672355 48.85822923236, -76.45402132523 44.225406213532, -72 33)",
421  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532, -72 33))",
422  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532), (-72 33, -71 32))"
423  };
424 
425  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
426  {
427  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
428  GBOX box;
429  gbox_init(&box);
430  lwgeom_drop_bbox(geom);
431 
432  /* Construct a GSERIALIZED* that doesn't have a box, so that we can test the
433  * actual logic of the peek function */
434  size_t expected_size = gserialized2_from_lwgeom_size(geom);
435  GSERIALIZED* gser = lwalloc(expected_size);
436  uint8_t* ptr = (uint8_t*) gser;
437 
438  ptr += 8; // Skip header
439  gserialized2_from_lwgeom_any(geom, ptr);
440  gser->gflags = lwflags_get_g2flags(geom->flags);
441 
442  CU_ASSERT_FALSE(gserialized2_has_bbox(gser));
443  CU_ASSERT_EQUAL(LW_FAILURE, gserialized2_peek_gbox_p(gser, &box));
444 
445  lwgeom_free(geom);
446  lwfree(gser);
447  }
448 }
449 
450 static int
451 peek2_point_helper(char *geometry, POINT4D *p)
452 {
454  p->x = p->y = p->z = p->m = 0;
455  LWGEOM *geom = lwgeom_from_wkt(geometry, LW_PARSER_CHECK_NONE);
456  CU_ASSERT(geom != NULL);
457  GSERIALIZED *g = gserialized2_from_lwgeom(geom, NULL);
458  CU_ASSERT(g != NULL);
459 
460  int ret = gserialized2_peek_first_point(g, p);
461  lwfree(g);
462  lwgeom_free(geom);
463 
464  return ret;
465 }
466 
467 static void
469 {
470  POINT4D p = {0};
471 
472  CU_ASSERT(peek2_point_helper("POINT(1 2)", &p) == LW_SUCCESS);
473  CU_ASSERT_EQUAL(p.x, 1);
474  CU_ASSERT_EQUAL(p.y, 2);
475 
476  CU_ASSERT(peek2_point_helper("POINTZ(10 20 30)", &p) == LW_SUCCESS);
477  CU_ASSERT_EQUAL(p.x, 10);
478  CU_ASSERT_EQUAL(p.y, 20);
479  CU_ASSERT_EQUAL(p.z, 30);
480 
481  CU_ASSERT(peek2_point_helper("POINTM(100 200 300)", &p) == LW_SUCCESS);
482  CU_ASSERT_EQUAL(p.x, 100);
483  CU_ASSERT_EQUAL(p.y, 200);
484  CU_ASSERT_EQUAL(p.m, 300);
485 
486  CU_ASSERT(peek2_point_helper("POINTZM(1000 2000 3000 4000)", &p) == LW_SUCCESS);
487  CU_ASSERT_EQUAL(p.x, 1000);
488  CU_ASSERT_EQUAL(p.y, 2000);
489  CU_ASSERT_EQUAL(p.z, 3000);
490  CU_ASSERT_EQUAL(p.m, 4000);
491 
492  CU_ASSERT(peek2_point_helper("MULTIPOINT((0 0), (1 1))", &p) == LW_FAILURE);
493  CU_ASSERT(peek2_point_helper("LINESTRING(0 0, 1 1)", &p) == LW_FAILURE);
494  CU_ASSERT(peek2_point_helper("MULTILINESTRING((0 0, 1 1), (0 0, 1 1))", &p) == LW_FAILURE);
495  CU_ASSERT(peek2_point_helper("POLYGON((0 0, 1 1, 1 0, 0 0))", &p) == LW_FAILURE);
496 }
497 
498 /*
499 ** Used by test harness to register the tests in this file.
500 */
501 void gserialized2_suite_setup(void);
503 {
504  CU_pSuite suite = CU_add_suite("serialization/deserialization v2", NULL, NULL);
516 }
static void test_gserialized2_peek_gbox_p_fails_for_unsupported_cases(void)
static void test_gserialized2_from_lwgeom_size(void)
static void test_gserialized2_peek_first_point(void)
void gserialized2_suite_setup(void)
static void test_gserialized2_peek_gbox_p_gets_correct_box(void)
static void test_gserialized2_is_empty(void)
static int peek2_point_helper(char *geometry, POINT4D *p)
static void test_g2flags_macros(void)
static void test_lwgeom_from_gserialized2(void)
static void test_gserialized2_peek_gbox_p_no_box_when_empty(void)
static void test_gserialized2_extended_flags(void)
static void test_gserialized2_srid(void)
static void test_on_gser2_lwgeom_count_vertices(void)
char * s
Definition: cu_in_wkt.c:23
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: gbox.c:164
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: gbox.c:774
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: gbox.c:40
int32_t gserialized2_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized2.c:190
void gserialized2_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function).
Definition: gserialized2.c:207
int gserialized2_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized2.c:251
int gserialized2_peek_first_point(const GSERIALIZED *g, POINT4D *out_point)
Definition: gserialized2.c:548
LWGEOM * lwgeom_from_gserialized2(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized2_peek_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Definition: gserialized2.c:360
uint8_t lwflags_get_g2flags(lwflags_t lwflags)
Definition: gserialized2.c:116
static size_t gserialized2_from_lwgeom_any(const LWGEOM *geom, uint8_t *buf)
size_t gserialized2_from_lwgeom_size(const LWGEOM *geom)
Return the memory size a GSERIALIZED will occupy for a given LWGEOM.
Definition: gserialized2.c:774
GSERIALIZED * gserialized2_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
uint8_t g2flags(int has_z, int has_m, int is_geodetic)
Definition: gserialized2.c:134
int gserialized2_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: gserialized2.c:146
#define G2FLAGS_SET_Z(gflags, value)
Definition: gserialized2.h:29
#define G2FLAGS_SET_VERSION(gflags, value)
Definition: gserialized2.h:34
#define G2FLAGS_GET_ZM(gflags)
Definition: gserialized2.h:37
#define G2FLAGS_GET_BBOX(gflags)
Definition: gserialized2.h:24
#define G2FLAGS_GET_VERSION(gflags)
Definition: gserialized2.h:21
#define G2FLAGS_SET_M(gflags, value)
Definition: gserialized2.h:30
#define G2FLAGS_GET_GEODETIC(gflags)
Definition: gserialized2.h:25
#define G2FLAGS_GET_Z(gflags)
Definition: gserialized2.h:22
#define G2FLAGS_GET_EXTENDED(gflags)
Definition: gserialized2.h:26
#define G2FLAGS_SET_GEODETIC(gflags, value)
Definition: gserialized2.h:32
#define G2FLAGS_GET_M(gflags)
Definition: gserialized2.h:23
#define G2FLAGS_SET_BBOX(gflags, value)
Definition: gserialized2.h:31
void cu_error_msg_reset()
#define PG_ADD_TEST(suite, testfunc)
#define LW_FAILURE
Definition: liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2060
#define LW_SUCCESS
Definition: liblwgeom.h:111
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:547
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:664
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1229
void lwfree(void *mem)
Definition: lwutil.c:242
#define FLAGS_GET_SOLID(flags)
Definition: liblwgeom.h:184
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:737
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:905
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
#define FLAGS_SET_SOLID(flags, value)
Definition: liblwgeom.h:191
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:677
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
uint32_t size
Definition: liblwgeom.h:430
uint8_t gflags
Definition: liblwgeom.h:432
GBOX * bbox
Definition: liblwgeom.h:444
lwflags_t flags
Definition: liblwgeom.h:447
double m
Definition: liblwgeom.h:400
double x
Definition: liblwgeom.h:400
double z
Definition: liblwgeom.h:400
double y
Definition: liblwgeom.h:400