/* CurvePolygon */ do_geojson_unsupported( "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))", "lwgeom_to_geojson: 'CurvePolygon' geometry type not supported"); /* MultiCurve */ do_geojson_unsupported( "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))", "lwgeom_to_geojson: 'MultiCurve' geometry type not supported"); /* MultiSurface */ do_geojson_unsupported( "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)))", "lwgeom_to_geojson: 'MultiSurface' geometry type not supported"); } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo out_geojson_tests[] = { PG_TEST(out_geojson_test_precision), PG_TEST(out_geojson_test_dims), PG_TEST(out_geojson_test_srid), PG_TEST(out_geojson_test_bbox), PG_TEST(out_geojson_test_geoms), CU_TEST_INFO_NULL }; CU_SuiteInfo out_geojson_suite = {"GeoJson Out Suite", NULL, NULL, out_geojson_tests};
c1 = lwgeom_calculate_circ_tree(lwg1); c2 = lwgeom_calculate_circ_tree(lwg2); d1 = circ_tree_distance_tree(c1, c2, &s, threshold); d2 = lwgeom_distance_spheroid(lwg1, lwg2, &s, threshold); // printf("distance_tree %g\n", distance_tree); // printf("distance_geom %g\n", distance_geom); // circ_tree_print(cline, 0); // circ_tree_print(cpoint, 0); circ_tree_free(c1); circ_tree_free(c2); lwgeom_free(lwg1); lwgeom_free(lwg2); CU_ASSERT_DOUBLE_EQUAL(d1, d2, 0.00001); } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo tree_tests[] = { PG_TEST(test_tree_circ_create), PG_TEST(test_tree_circ_pip), PG_TEST(test_tree_circ_pip2), PG_TEST(test_tree_circ_distance), CU_TEST_INFO_NULL }; CU_SuiteInfo tree_suite = {"Internal Spatial Trees", NULL, NULL, tree_tests};
rect_tree_free(tree1); rect_tree_free(tree2); } static void test_lwgeom_segmentize2d(void) { LWGEOM *linein = lwgeom_from_wkt("LINESTRING(0 0,10 0)", LW_PARSER_CHECK_NONE); LWGEOM *lineout = lwgeom_segmentize2d(linein, 5); char *strout = lwgeom_to_ewkt(lineout); CU_ASSERT_STRING_EQUAL(strout, "LINESTRING(0 0,5 0,10 0)"); lwfree(strout); lwgeom_free(linein); lwgeom_free(lineout); } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo measures_tests[] = { PG_TEST(test_mindistance2d_tolerance), PG_TEST(test_rect_tree_contains_point), PG_TEST(test_rect_tree_intersects_tree), PG_TEST(test_lwgeom_segmentize2d), CU_TEST_INFO_NULL }; CU_SuiteInfo measures_suite = {"PostGIS Measures Suite", NULL, NULL, measures_tests};
rv = lwgeom_parse_wkt(&p, wkt, LW_PARSER_CHECK_ALL); CU_ASSERT_EQUAL(12,p.errlocation); lwgeom_parser_result_free(&p); // printf("errlocation %d\n", p.errlocation); // printf("message %s\n", p.message); } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo wkt_in_tests[] = { PG_TEST(test_wkt_in_point), PG_TEST(test_wkt_in_linestring), PG_TEST(test_wkt_in_polygon), PG_TEST(test_wkt_in_multipoint), PG_TEST(test_wkt_in_multilinestring), PG_TEST(test_wkt_in_multipolygon), PG_TEST(test_wkt_in_collection), PG_TEST(test_wkt_in_circularstring), PG_TEST(test_wkt_in_compoundcurve), PG_TEST(test_wkt_in_curvpolygon), PG_TEST(test_wkt_in_multicurve), PG_TEST(test_wkt_in_multisurface), PG_TEST(test_wkt_in_tin), PG_TEST(test_wkt_in_polyhedralsurface), PG_TEST(test_wkt_in_errlocation), CU_TEST_INFO_NULL
do_gml3_extent_test( "GEOMETRYCOLLECTION EMPTY", "<Envelope/>", NULL, 15, 0, ""); /* GML3: empty with srsName */ do_gml3_extent_test( "GEOMETRYCOLLECTION EMPTY", "<Envelope srsName=\"urn:ogc:def:crs:EPSG::4326\"/>", "urn:ogc:def:crs:EPSG::4326", 15, 0, ""); } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo out_gml_tests[] = { PG_TEST(out_gml_test_precision), PG_TEST(out_gml_test_srid), PG_TEST(out_gml_test_dims), PG_TEST(out_gml_test_geodetic), PG_TEST(out_gml_test_geoms), PG_TEST(out_gml_test_geoms_prefix), PG_TEST(out_gml_test_geoms_nodims), PG_TEST(out_gml2_extent), PG_TEST(out_gml3_extent), CU_TEST_INFO_NULL }; CU_SuiteInfo out_gml_suite = {"out_gml", NULL, NULL, out_gml_tests};
NULL, 0); **/ /* TODO: Implement Empty GeometryCollection correctly or throw a not-implemented */ /** do_x3d3_test( "GEOMETRYCOLLECTION EMPTY", "", NULL, 0); **/ /* CircularString */ do_x3d3_unsupported( "CIRCULARSTRING(-2 0 1,0 2 1,2 0 1,0 2 1,2 4 1)", "lwgeom_to_x3d3: 'CircularString' geometry type not supported"); /* CompoundCurve */ do_x3d3_unsupported( "COMPOUNDCURVE(CIRCULARSTRING(0 0 1,1 1 1,1 0 1),(1 0 1,0 1 1))", "lwgeom_to_x3d3: 'CompoundCurve' geometry type not supported"); } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo out_x3d_tests[] = { PG_TEST(out_x3d3_test_precision), PG_TEST(out_x3d3_test_geoms), CU_TEST_INFO_NULL }; CU_SuiteInfo out_x3d_suite = {"X3D Out Suite", NULL, NULL, out_x3d_tests};
CU_ASSERT_EQUAL(rt_raster_get_width(rast), 122); CU_ASSERT_EQUAL(rt_raster_get_height(rast), 116); CU_ASSERT_NOT_EQUAL(rt_raster_get_num_bands(rast), 0); band = rt_raster_get_band(rast, 0); CU_ASSERT(band != NULL); CU_ASSERT(rt_band_get_hasnodata_flag(band)); rt_band_get_nodata(band, &value); CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON); CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, NULL), ES_NONE); CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON); cu_free_raster(rast); cu_free_raster(raster); } /* register tests */ CU_TestInfo gdal_tests[] = { PG_TEST(test_gdal_configured), PG_TEST(test_gdal_drivers), PG_TEST(test_gdal_rasterize), PG_TEST(test_gdal_polygonize), PG_TEST(test_raster_to_gdal), PG_TEST(test_gdal_to_raster), PG_TEST(test_gdal_warp), CU_TEST_INFO_NULL }; CU_SuiteInfo gdal_suite = {"gdal", NULL, NULL, gdal_tests};
out = lwgeom_node(in); tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); CU_ASSERT_STRING_EQUAL("MULTILINESTRING((0 0,5 5,10 0),(10 0,11 0,12 0,20 0),(20 0,22 0))", tmp); lwfree(tmp); lwgeom_free(out); lwgeom_free(in); wkt = "MULTILINESTRING((0 0,5 5,10 0, 11 0, 20 0),(22 0, 12 0, 10 0),(0 5, 5 0))"; in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); out = lwgeom_node(in); tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); CU_ASSERT_STRING_EQUAL( "MULTILINESTRING((0 0,2.5 2.5),(0 5,2.5 2.5),(22 0,20 0),(20 0,12 0,11 0,10 0),(10 0,5 5,2.5 2.5),(2.5 2.5,5 0))", tmp); lwfree(tmp); lwgeom_free(out); lwgeom_free(in); #endif /* POSTGIS_GEOS_VERSION >= 33 */ } /* ** Used by test harness to register the tests in this file. */ /* ** Used by test harness to register the tests in this file. */ CU_TestInfo node_tests[] = { PG_TEST(test_lwgeom_node), CU_TEST_INFO_NULL }; CU_SuiteInfo node_suite = {"node", NULL, NULL, node_tests};
tmp = lwgeom_delaunay_triangulation(in, 0, 0); lwgeom_free(in); out = lwgeom_normalize(tmp); lwgeom_free(tmp); wkt = lwgeom_to_ewkt(out); lwgeom_free(out); exp_wkt = "GEOMETRYCOLLECTION(POLYGON((5 5,20 0,10 0,5 5)))"; if ( strcmp(wkt, exp_wkt) ) { fprintf(stderr, "\nExp: %s\nObt: %s\n", exp_wkt, wkt); } CU_ASSERT_STRING_EQUAL(wkt, exp_wkt); lwfree(wkt); #endif /* POSTGIS_GEOS_VERSION >= 33 */ } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo triangulate_tests[] = { PG_TEST(test_lwgeom_delaunay_triangulation), CU_TEST_INFO_NULL }; CU_SuiteInfo triangulate_suite = {"triangulate", NULL, NULL, triangulate_tests};
/*** Unclosed ring ***/ lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, 2 0)")); pa = lwline->points; cu_error_msg_reset(); rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_STRING_EQUAL("ptarrayarc_contains_point called on unclosed ring", cu_error_msg); lwline_free(lwline); } /* ** Used by the test harness to register the tests in this file. */ CU_TestInfo ptarray_tests[] = { PG_TEST(test_ptarray_append_point), PG_TEST(test_ptarray_append_ptarray), PG_TEST(test_ptarray_locate_point), PG_TEST(test_ptarray_isccw), PG_TEST(test_ptarray_signed_area), PG_TEST(test_ptarray_desegmentize), PG_TEST(test_ptarray_insert_point), PG_TEST(test_ptarray_contains_point), PG_TEST(test_ptarrayarc_contains_point), CU_TEST_INFO_NULL }; CU_SuiteInfo ptarray_suite = {"ptarray", NULL, NULL, ptarray_tests };
stringbuffer_destroy(sb); } static void test_stringbuffer_aprintf(void) { stringbuffer_t *sb; const char *str; sb = stringbuffer_create_with_size(2); stringbuffer_aprintf(sb, "hello %dth world", 14); str = stringbuffer_getstring(sb); CU_ASSERT_STRING_EQUAL("hello 14th world", str); stringbuffer_destroy(sb); } /* TODO: add more... */ /* ** Used by the test harness to register the tests in this file. */ CU_TestInfo stringbuffer_tests[] = { PG_TEST(test_stringbuffer_append), PG_TEST(test_stringbuffer_aprintf), CU_TEST_INFO_NULL }; CU_SuiteInfo stringbuffer_suite = {"stringbuffer", NULL, NULL, stringbuffer_tests };
width = rt_raster_get_width(raster); height = rt_raster_get_height(raster); datasize = rt_pixtype_size(PT_8BUI) * width * height; mem = rtalloc(datasize); band = rt_band_new_inline(width, height, PT_8BUI, 1, 1, mem); CU_ASSERT(band != NULL); rt_band_set_ownsdata_flag(band, 1); rband = rt_raster_replace_band(raster, band, 0); CU_ASSERT(rband != NULL); rt_band_get_nodata(rt_raster_get_band(raster, 0), &nodata); CU_ASSERT_DOUBLE_EQUAL(nodata, 1, DBL_EPSILON); rt_band_destroy(rband); cu_free_raster(raster); } /* register tests */ CU_TestInfo raster_basics_tests[] = { PG_TEST(test_raster_new), PG_TEST(test_raster_empty), PG_TEST(test_raster_metadata), PG_TEST(test_raster_clone), PG_TEST(test_raster_from_band), PG_TEST(test_raster_replace_band), CU_TEST_INFO_NULL }; CU_SuiteInfo raster_basics_suite = {"raster_basics", NULL, NULL, raster_basics_tests};
geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_ALL); area = lwgeom_area(geom); CU_ASSERT_DOUBLE_EQUAL(area, 0.0, 0.0001); lwgeom_free(geom); } static void test_misc_wkb(void) { static char *wkb = "010A0000000200000001080000000700000000000000000000C00000000000000000000000000000F0BF000000000000F0BF00000000000000000000000000000000000000000000F03F000000000000F0BF000000000000004000000000000000000000000000000000000000000000004000000000000000C00000000000000000010200000005000000000000000000F0BF00000000000000000000000000000000000000000000E03F000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F0BF0000000000000000"; LWGEOM *geom = lwgeom_from_hexwkb(wkb, LW_PARSER_CHECK_ALL); char *str = lwgeom_to_wkt(geom, WKB_ISO, 8, 0); CU_ASSERT_STRING_EQUAL(str, "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))"); lwfree(str); lwgeom_free(geom); } /* ** Used by the test harness to register the tests in this file. */ CU_TestInfo misc_tests[] = { PG_TEST(test_misc_force_2d), PG_TEST(test_misc_simplify), PG_TEST(test_misc_count_vertices), PG_TEST(test_misc_area), PG_TEST(test_misc_wkb), CU_TEST_INFO_NULL }; CU_SuiteInfo misc_suite = {"Misc Suite", NULL, NULL, misc_tests };
CU_ASSERT(gexp != NULL); gout = lwgeom_buildarea(gin); CU_ASSERT(gout != NULL); check_geom_equal(gout, gexp); lwgeom_free(gout); lwgeom_free(gexp); lwgeom_free(gin); } /* ** Used by test harness to register the tests in this file. */ static CU_TestInfo buildarea_tests[] = { PG_TEST(buildarea1), PG_TEST(buildarea2), PG_TEST(buildarea3), PG_TEST(buildarea4), PG_TEST(buildarea4b), PG_TEST(buildarea5), PG_TEST(buildarea6), PG_TEST(buildarea7), CU_TEST_INFO_NULL }; CU_SuiteInfo buildarea_suite = {"buildarea", NULL, NULL, buildarea_tests};
static void test_wkb_out_multisurface(void) {} static void test_wkb_out_polyhedralsurface(void) { // cu_wkb("POLYHEDRALSURFACE(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))"); // CU_ASSERT_STRING_EQUAL(s, t); // printf("\nnew: %s\nold: %s\n",s,t); } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo wkb_out_tests[] = { PG_TEST(test_wkb_out_point), PG_TEST(test_wkb_out_linestring), PG_TEST(test_wkb_out_polygon), PG_TEST(test_wkb_out_multipoint), PG_TEST(test_wkb_out_multilinestring), PG_TEST(test_wkb_out_multipolygon), PG_TEST(test_wkb_out_collection), PG_TEST(test_wkb_out_circularstring), PG_TEST(test_wkb_out_compoundcurve), PG_TEST(test_wkb_out_curvpolygon), PG_TEST(test_wkb_out_multicurve), PG_TEST(test_wkb_out_multisurface), PG_TEST(test_wkb_out_polyhedralsurface), CU_TEST_INFO_NULL }; CU_SuiteInfo wkb_out_suite = {"WKB Out Suite", init_wkb_out_suite, clean_wkb_out_suite, wkb_out_tests};
LW_PARSER_CHECK_NONE); CU_ASSERT(gin != NULL); gout = lwgeom_make_valid(gin); CU_ASSERT(gout != NULL); ewkt = lwgeom_to_ewkt(gout); /* printf("c = %s\n", ewkt); */ CU_ASSERT_STRING_EQUAL(ewkt, "MULTIPOINT(0 0,1 1,2 2)"); lwfree(ewkt); lwgeom_free(gout); lwgeom_free(gin); #endif /* POSTGIS_GEOS_VERSION >= 33 */ } /* TODO: add more tests ! */ /* ** Used by test harness to register the tests in this file. */ static CU_TestInfo clean_tests[] = { PG_TEST(test_lwgeom_make_valid), CU_TEST_INFO_NULL }; CU_SuiteInfo clean_suite = {"clean", NULL, NULL, clean_tests};
"SRID=4326;LINESTRING(1 2,3 4)"); do_geom_test("SRID=4326;MULTILINESTRING((1 2,3 4),(5 6,7 8))", "SRID=4326;MULTILINESTRING((1 2,3 4),(5 6,7 8))"); /* 3D and 4D */ do_geom_test("POINT(1 2 3)", "POINT(1 2 3)"); do_geom_test("POINTM(1 2 3)", "POINTM(1 2 3)"); do_geom_test("POINT(1 2 3 4)", "POINT(1 2 3 4)"); } /* ** Used by test harness to register the tests in this file. */ CU_TestInfo homogenize_tests[] = { PG_TEST(test_coll_point), PG_TEST(test_coll_line), PG_TEST(test_coll_poly), PG_TEST(test_coll_coll), PG_TEST(test_geom), PG_TEST(test_coll_curve), CU_TEST_INFO_NULL }; CU_SuiteInfo homogenize_suite = {"homogenize", NULL, NULL, homogenize_tests};