File: test-output-pgsql-style-file.cpp

package info (click to toggle)
osm2pgsql 2.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,772 kB
  • sloc: cpp: 60,940; python: 1,115; ansic: 763; sh: 25; makefile: 14
file content (229 lines) | stat: -rw-r--r-- 7,597 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * This file is part of osm2pgsql (https://osm2pgsql.org/).
 *
 * Copyright (C) 2006-2025 by the osm2pgsql developer community.
 * For a full list of authors see the git log.
 */

#include <catch.hpp>

#include "common-import.hpp"
#include "common-options.hpp"

TEST_CASE("Parse default style file")
{
    export_list_t exlist;
    auto const enable_way_area =
        read_style_file(OSM2PGSQLDATA_DIR "default.style", &exlist);

    REQUIRE(enable_way_area);

    REQUIRE(exlist.get(osmium::item_type::node).size() == 98);
    REQUIRE(exlist.get(osmium::item_type::way).size() == 104);
}

TEST_CASE("Parse empty style file")
{
    export_list_t exlist;

    REQUIRE_THROWS_WITH(
        read_style_file(OSM2PGSQLDATA_DIR "tests/style/empty.style", &exlist),
        "Unable to parse any valid columns from the style file. Aborting.");
}

TEST_CASE("Parse style file with invalid osm type")
{
    export_list_t exlist;

    REQUIRE_THROWS(read_style_file(
        OSM2PGSQLDATA_DIR "tests/style/invalid-osm-type.style", &exlist));
}

TEST_CASE("Parse style file with comments only")
{
    export_list_t exlist;

    REQUIRE_THROWS_WITH(
        read_style_file(OSM2PGSQLDATA_DIR "tests/style/comments.style",
                        &exlist),
        "Unable to parse any valid columns from the style file. Aborting.");
}

TEST_CASE("Parse style file with single node entry")
{
    export_list_t exlist;
    auto const enable_way_area =
        read_style_file(OSM2PGSQLDATA_DIR "tests/style/node.style", &exlist);

    REQUIRE(enable_way_area);

    REQUIRE(exlist.get(osmium::item_type::node).size() == 1);
    REQUIRE(exlist.get(osmium::item_type::way).empty());

    auto const &ex = exlist.get(osmium::item_type::node).front();
    REQUIRE(ex.name == "access");
    REQUIRE(ex.type == "text");
    REQUIRE(ex.flags == column_flags::FLAG_LINEAR);
    REQUIRE(ex.column_type() == column_type_t::TEXT);
}

TEST_CASE("Parse style file with a few valid entries")
{
    export_list_t exlist;
    auto const enable_way_area =
        read_style_file(OSM2PGSQLDATA_DIR "tests/style/valid.style", &exlist);

    REQUIRE(enable_way_area);

    REQUIRE(exlist.get(osmium::item_type::node).size() == 6);
    REQUIRE(exlist.get(osmium::item_type::way).size() == 6);

    auto const &nodes = exlist.get(osmium::item_type::node);
    auto const &ways = exlist.get(osmium::item_type::way);

    for (auto const &node : nodes) {
        REQUIRE(node.type == "text");
        REQUIRE(node.column_type() == column_type_t::TEXT);
    }

    for (auto const &way : ways) {
        REQUIRE(way.type == "text");
        REQUIRE(way.column_type() == column_type_t::TEXT);
    }

    REQUIRE(nodes[0].flags == column_flags::FLAG_LINEAR);
    REQUIRE(nodes[1].flags == column_flags::FLAG_LINEAR);
    REQUIRE(nodes[2].flags == column_flags::FLAG_POLYGON);
    REQUIRE(nodes[3].flags == column_flags::FLAG_POLYGON);
    REQUIRE(nodes[4].flags == column_flags::FLAG_NOCOLUMN);
    REQUIRE(nodes[5].flags == column_flags::FLAG_DELETE);
    REQUIRE(ways[0].flags == column_flags::FLAG_LINEAR);
    REQUIRE(ways[1].flags == column_flags::FLAG_LINEAR);
    REQUIRE(ways[2].flags == column_flags::FLAG_POLYGON);
    REQUIRE(ways[3].flags == column_flags::FLAG_POLYGON);
    REQUIRE(ways[4].flags == column_flags::FLAG_NOCOLUMN);
    REQUIRE(ways[5].flags == column_flags::FLAG_DELETE);
}

TEST_CASE("Parse style file with missing fields")
{
    export_list_t exlist;
    auto const enable_way_area =
        read_style_file(OSM2PGSQLDATA_DIR "tests/style/missing.style", &exlist);

    REQUIRE(enable_way_area);

    REQUIRE(exlist.get(osmium::item_type::node).size() == 2);
    REQUIRE(exlist.get(osmium::item_type::way).size() == 2);

    auto const &nodes = exlist.get(osmium::item_type::node);
    auto const &ways = exlist.get(osmium::item_type::way);

    for (auto const &node : nodes) {
        REQUIRE(node.type == "text");
        REQUIRE(node.column_type() == column_type_t::TEXT);
    }
    REQUIRE(nodes[0].flags == column_flags::FLAG_LINEAR);
    REQUIRE(nodes[1].flags == 0);

    for (auto const &way : ways) {
        REQUIRE(way.type == "text");
        REQUIRE(way.column_type() == column_type_t::TEXT);
    }
    REQUIRE(ways[0].flags == column_flags::FLAG_POLYGON);
    REQUIRE(ways[1].flags == 0);
}

TEST_CASE("Parse style file with way_area")
{
    export_list_t exlist;
    auto const enable_way_area = read_style_file(
        OSM2PGSQLDATA_DIR "tests/style/way-area.style", &exlist);

    REQUIRE(enable_way_area);

    REQUIRE(exlist.get(osmium::item_type::node).size() == 1);
    REQUIRE(exlist.get(osmium::item_type::way).size() == 2);

    auto const &nodes = exlist.get(osmium::item_type::node);
    auto const &ways = exlist.get(osmium::item_type::way);

    REQUIRE(nodes[0].type == "text");
    REQUIRE(nodes[0].flags ==
            (column_flags::FLAG_POLYGON | column_flags::FLAG_NOCOLUMN));
    REQUIRE(nodes[0].column_type() == column_type_t::TEXT);

    REQUIRE(ways[0].type == "text");
    REQUIRE(ways[0].flags ==
            (column_flags::FLAG_POLYGON | column_flags::FLAG_NOCOLUMN));
    REQUIRE(ways[0].column_type() == column_type_t::TEXT);

    REQUIRE(ways[1].type == "real");
    REQUIRE(ways[1].flags == 0);
    REQUIRE(ways[1].column_type() ==
            column_type_t::TEXT); // Special case for way_area!
}

TEST_CASE("Parse style file with different data types")
{
    export_list_t exlist;
    auto const enable_way_area = read_style_file(
        OSM2PGSQLDATA_DIR "tests/style/data-types.style", &exlist);

    REQUIRE(enable_way_area);

    REQUIRE(exlist.get(osmium::item_type::node).size() == 2);
    REQUIRE(exlist.get(osmium::item_type::way).size() == 3);

    auto const &nodes = exlist.get(osmium::item_type::node);
    auto const &ways = exlist.get(osmium::item_type::way);

    REQUIRE(nodes[0].name == "name");
    REQUIRE(nodes[0].type == "text");
    REQUIRE(nodes[0].flags == column_flags::FLAG_LINEAR);
    REQUIRE(nodes[0].column_type() == column_type_t::TEXT);

    REQUIRE(nodes[1].name == "population");
    REQUIRE(nodes[1].type == "integer");
    REQUIRE(nodes[1].flags ==
            (column_flags::FLAG_POLYGON | column_flags::FLAG_INT_TYPE));
    REQUIRE(nodes[1].column_type() == column_type_t::INT);

    REQUIRE(ways[0].name == "name");
    REQUIRE(ways[0].type == "text");
    REQUIRE(ways[0].flags == column_flags::FLAG_LINEAR);
    REQUIRE(ways[0].column_type() == column_type_t::TEXT);

    REQUIRE(ways[1].name == "width");
    REQUIRE(ways[1].type == "real");
    REQUIRE(ways[1].flags ==
            (column_flags::FLAG_LINEAR | column_flags::FLAG_REAL_TYPE));
    REQUIRE(ways[1].column_type() == column_type_t::REAL);

    REQUIRE(ways[2].name == "population");
    REQUIRE(ways[2].type == "integer");
    REQUIRE(ways[2].flags ==
            (column_flags::FLAG_POLYGON | column_flags::FLAG_INT_TYPE));
    REQUIRE(ways[2].column_type() == column_type_t::INT);
}

TEST_CASE("Parse style file with invalid data types")
{
    export_list_t exlist;
    auto const enable_way_area = read_style_file(
        OSM2PGSQLDATA_DIR "tests/style/invalid-data-type.style", &exlist);

    REQUIRE(enable_way_area);

    REQUIRE(exlist.get(osmium::item_type::node).empty());
    REQUIRE(exlist.get(osmium::item_type::way).size() == 1);

    auto const &ways = exlist.get(osmium::item_type::way);

    REQUIRE(ways[0].name == "highway");
    REQUIRE(ways[0].type == "foo");
    REQUIRE(ways[0].flags == column_flags::FLAG_LINEAR);
    REQUIRE(ways[0].column_type() == column_type_t::TEXT);
}