|
| 1 | +/** |
| 2 | + * SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | + * |
| 4 | + * This file is part of osm2pgsql (https://osm2pgsql.org/). |
| 5 | + * |
| 6 | + * Copyright (C) 2006-2022 by the osm2pgsql developer community. |
| 7 | + * For a full list of authors see the git log. |
| 8 | + */ |
| 9 | + |
| 10 | +#include <catch.hpp> |
| 11 | + |
| 12 | +#include "geom-output.hpp" |
| 13 | + |
| 14 | +#include <sstream> |
| 15 | + |
| 16 | +TEST_CASE("nullgeom_t output", "[NoDB]") |
| 17 | +{ |
| 18 | + geom::nullgeom_t g; |
| 19 | + std::stringstream ss1; |
| 20 | + ss1 << g; |
| 21 | + CHECK(ss1.str() == "NULL"); |
| 22 | + |
| 23 | + geom::geometry_t geom; |
| 24 | + std::stringstream ss2; |
| 25 | + ss2 << geom; |
| 26 | + CHECK(ss2.str() == "NULL(NULL)"); |
| 27 | +} |
| 28 | + |
| 29 | +TEST_CASE("point_t output", "[NoDB]") |
| 30 | +{ |
| 31 | + geom::point_t g{1, 2}; |
| 32 | + std::stringstream ss1; |
| 33 | + ss1 << g; |
| 34 | + CHECK(ss1.str() == "1 2"); |
| 35 | + |
| 36 | + geom::geometry_t geom{std::move(g)}; |
| 37 | + std::stringstream ss2; |
| 38 | + ss2 << geom; |
| 39 | + CHECK(ss2.str() == "POINT(1 2)"); |
| 40 | +} |
| 41 | + |
| 42 | +TEST_CASE("linestring_t output", "[NoDB]") |
| 43 | +{ |
| 44 | + geom::linestring_t g{{1, 2}, {2, 2}}; |
| 45 | + std::stringstream ss1; |
| 46 | + ss1 << g; |
| 47 | + CHECK(ss1.str() == "1 2,2 2"); |
| 48 | + |
| 49 | + geom::geometry_t geom{std::move(g)}; |
| 50 | + std::stringstream ss2; |
| 51 | + ss2 << geom; |
| 52 | + CHECK(ss2.str() == "LINESTRING(1 2,2 2)"); |
| 53 | +} |
| 54 | + |
| 55 | +TEST_CASE("polygon_t with no inner rings output", "[NoDB]") |
| 56 | +{ |
| 57 | + geom::polygon_t g{geom::ring_t{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}}; |
| 58 | + std::stringstream ss1; |
| 59 | + ss1 << g; |
| 60 | + CHECK(ss1.str() == "(0 0,1 0,1 1,0 1,0 0)"); |
| 61 | + |
| 62 | + geom::geometry_t geom{std::move(g)}; |
| 63 | + std::stringstream ss2; |
| 64 | + ss2 << geom; |
| 65 | + CHECK(ss2.str() == "POLYGON((0 0,1 0,1 1,0 1,0 0))"); |
| 66 | +} |
| 67 | + |
| 68 | +TEST_CASE("polygon_t with inner ring output", "[NoDB]") |
| 69 | +{ |
| 70 | + geom::polygon_t g{geom::ring_t{{0, 0}, {3, 0}, {3, 3}, {0, 3}, {0, 0}}}; |
| 71 | + g.add_inner_ring(geom::ring_t{{1, 1}, {1, 2}, {2, 2}, {2, 1}, {1, 1}}); |
| 72 | + std::stringstream ss1; |
| 73 | + ss1 << g; |
| 74 | + CHECK(ss1.str() == "(0 0,3 0,3 3,0 3,0 0),(1 1,1 2,2 2,2 1,1 1)"); |
| 75 | + |
| 76 | + geom::geometry_t geom{std::move(g)}; |
| 77 | + std::stringstream ss2; |
| 78 | + ss2 << geom; |
| 79 | + CHECK(ss2.str() == "POLYGON((0 0,3 0,3 3,0 3,0 0),(1 1,1 2,2 2,2 1,1 1))"); |
| 80 | +} |
| 81 | + |
| 82 | +TEST_CASE("multipoint_t output", "[NoDB]") |
| 83 | +{ |
| 84 | + geom::multipoint_t g; |
| 85 | + g.add_geometry({1, 2}); |
| 86 | + g.add_geometry({4, 3}); |
| 87 | + std::stringstream ss1; |
| 88 | + ss1 << g; |
| 89 | + CHECK(ss1.str() == "(1 2),(4 3)"); |
| 90 | + |
| 91 | + geom::geometry_t geom{std::move(g)}; |
| 92 | + std::stringstream ss2; |
| 93 | + ss2 << geom; |
| 94 | + CHECK(ss2.str() == "MULTIPOINT((1 2),(4 3))"); |
| 95 | +} |
| 96 | + |
| 97 | +TEST_CASE("multilinestring_t output", "[NoDB]") |
| 98 | +{ |
| 99 | + geom::multilinestring_t g; |
| 100 | + g.add_geometry({{1, 2}, {2, 2}}); |
| 101 | + g.add_geometry({{4, 3}, {1, 1}}); |
| 102 | + std::stringstream ss1; |
| 103 | + ss1 << g; |
| 104 | + CHECK(ss1.str() == "(1 2,2 2),(4 3,1 1)"); |
| 105 | + |
| 106 | + geom::geometry_t geom{std::move(g)}; |
| 107 | + std::stringstream ss2; |
| 108 | + ss2 << geom; |
| 109 | + CHECK(ss2.str() == "MULTILINESTRING((1 2,2 2),(4 3,1 1))"); |
| 110 | +} |
| 111 | + |
| 112 | +TEST_CASE("multipolygon_t output", "[NoDB]") |
| 113 | +{ |
| 114 | + geom::multipolygon_t g; |
| 115 | + g.add_geometry(geom::polygon_t{geom::ring_t{{0, 0}, {0, 1}, {1, 1}}}); |
| 116 | + g.add_geometry(geom::polygon_t{geom::ring_t{{2, 2}, {2, 3}, {3, 2}}}); |
| 117 | + std::stringstream ss1; |
| 118 | + ss1 << g; |
| 119 | + CHECK(ss1.str() == "((0 0,0 1,1 1)),((2 2,2 3,3 2))"); |
| 120 | + |
| 121 | + geom::geometry_t geom{std::move(g)}; |
| 122 | + std::stringstream ss2; |
| 123 | + ss2 << geom; |
| 124 | + CHECK(ss2.str() == "MULTIPOLYGON(((0 0,0 1,1 1)),((2 2,2 3,3 2)))"); |
| 125 | +} |
| 126 | + |
| 127 | +TEST_CASE("collection_t output", "[NoDB]") |
| 128 | +{ |
| 129 | + geom::collection_t g; |
| 130 | + g.add_geometry(geom::geometry_t{ |
| 131 | + geom::polygon_t{geom::ring_t{{0, 0}, {0, 1}, {1, 1}}}}); |
| 132 | + g.add_geometry(geom::geometry_t{geom::point_t{2, 3}}); |
| 133 | + std::stringstream ss1; |
| 134 | + ss1 << g; |
| 135 | + CHECK(ss1.str() == "POLYGON((0 0,0 1,1 1)),POINT(2 3)"); |
| 136 | + |
| 137 | + geom::geometry_t geom{std::move(g)}; |
| 138 | + std::stringstream ss2; |
| 139 | + ss2 << geom; |
| 140 | + CHECK(ss2.str() == "GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 1)),POINT(2 3))"); |
| 141 | +} |
0 commit comments