15 #include "CUnit/Basic.h"
82 CU_ASSERT_EQUAL(size, 32);
88 CU_ASSERT_EQUAL(size, 40);
94 CU_ASSERT_EQUAL(size, 40);
112 CU_ASSERT_EQUAL(rv, srid);
123 CU_ASSERT_EQUAL(rv, srid);
128 CU_ASSERT_EQUAL(rv, srid);
133 CU_ASSERT_EQUAL(rv, srid);
143 CU_ASSERT_EQUAL( size, 32 );
148 CU_ASSERT_EQUAL( size, 40 );
153 CU_ASSERT_EQUAL( size, 80 );
158 CU_ASSERT_EQUAL( size, 48 );
163 CU_ASSERT_EQUAL( size, 96 );
168 CU_ASSERT_EQUAL( size, 104 );
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 );
183 char *in_ewkt, *out_ewkt;
191 "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
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))",
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)))",
215 for ( i = 0; i < (
sizeof ewkt/
sizeof(
char*)); i++ )
225 CU_ASSERT_EQUAL(size1, size2);
231 CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
236 CU_ASSERT(geom1->
bbox != NULL || geom2->
bbox == NULL);
253 CU_ASSERT_EQUAL(size1, size2);
273 struct gserialized_empty_cases {
278 struct gserialized_empty_cases cases[] = {
279 {
"POINT EMPTY", 1 },
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 },
297 while( cases[i].wkt )
304 CU_ASSERT_EQUAL(ie, cases[i].isempty);
347 "MULTIPOINT (EMPTY)",
348 "MULTILINESTRING EMPTY",
349 "MULTILINESTRING (EMPTY)"
352 for ( i = 0; i < (
sizeof ewkt/
sizeof(
char*)); i++ )
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))"
389 for ( i = 0; i < (
sizeof ewkt/
sizeof(
char*)); i++ )
393 GBOX box_from_lwgeom;
406 CU_ASSERT_TRUE(
gbox_same(&box_from_peek, &box_from_lwgeom));
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))"
425 for ( i = 0; i < (
sizeof ewkt/
sizeof(
char*)); i++ )
436 uint8_t* ptr = (uint8_t*) gser;
454 p->
x = p->
y = p->
z = p->
m = 0;
456 CU_ASSERT(geom != NULL);
458 CU_ASSERT(g != NULL);
473 CU_ASSERT_EQUAL(p.
x, 1);
474 CU_ASSERT_EQUAL(p.
y, 2);
477 CU_ASSERT_EQUAL(p.
x, 10);
478 CU_ASSERT_EQUAL(p.
y, 20);
479 CU_ASSERT_EQUAL(p.
z, 30);
482 CU_ASSERT_EQUAL(p.
x, 100);
483 CU_ASSERT_EQUAL(p.
y, 200);
484 CU_ASSERT_EQUAL(p.
m, 300);
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);
504 CU_pSuite suite = CU_add_suite(
"serialization/deserialization v2", NULL, NULL);
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)
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
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)...
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).
int gserialized2_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized2_peek_first_point(const GSERIALIZED *g, POINT4D *out_point)
LWGEOM * lwgeom_from_gserialized2(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized2_peek_gbox_p(const GSERIALIZED *g, GBOX *gbox)
uint8_t lwflags_get_g2flags(lwflags_t lwflags)
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.
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)
int gserialized2_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
#define G2FLAGS_SET_Z(gflags, value)
#define G2FLAGS_SET_VERSION(gflags, value)
#define G2FLAGS_GET_ZM(gflags)
#define G2FLAGS_GET_BBOX(gflags)
#define G2FLAGS_GET_VERSION(gflags)
#define G2FLAGS_SET_M(gflags, value)
#define G2FLAGS_GET_GEODETIC(gflags)
#define G2FLAGS_GET_Z(gflags)
#define G2FLAGS_GET_EXTENDED(gflags)
#define G2FLAGS_SET_GEODETIC(gflags, value)
#define G2FLAGS_GET_M(gflags)
#define G2FLAGS_SET_BBOX(gflags, value)
void cu_error_msg_reset()
#define PG_ADD_TEST(suite, testfunc)
void lwgeom_free(LWGEOM *geom)
#define LW_PARSER_CHECK_NONE
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
#define FLAGS_GET_SOLID(flags)
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...
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
void * lwalloc(size_t size)
#define SRID_UNKNOWN
Unknown SRID value.
#define FLAGS_SET_SOLID(flags, value)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.