Skip to content

Commit 8911739

Browse files
committed
Cleanup base tests
This also removes some tests which don't really have anything to do with the flex backend so don't fit here.
1 parent 2fe8f89 commit 8911739

File tree

2 files changed

+47
-102
lines changed

2 files changed

+47
-102
lines changed

tests/data/test_output_flex.lua

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,6 @@ tables.route = osm2pgsql.define_table{
3636
}
3737
}
3838

39-
function is_empty(some_table)
40-
return next(some_table) == nil
41-
end
42-
43-
function clean_tags(tags)
44-
tags.odbl = nil
45-
tags.created_by = nil
46-
tags.source = nil
47-
tags['source:ref'] = nil
48-
tags['source:name'] = nil
49-
end
50-
5139
function is_polygon(tags)
5240
if tags.aeroway
5341
or tags.amenity
@@ -83,55 +71,60 @@ function is_polygon(tags)
8371
end
8472
end
8573

86-
function osm2pgsql.process_node(data)
87-
clean_tags(data.tags)
88-
if is_empty(data.tags) then
74+
local delete_keys = {
75+
'odbl',
76+
'created_by',
77+
'source'
78+
}
79+
80+
local clean_tags = osm2pgsql.make_clean_tags_func(delete_keys)
81+
82+
function osm2pgsql.process_node(object)
83+
if clean_tags(object.tags) then
8984
return
9085
end
9186

9287
tables.point:add_row({
93-
tags = data.tags
88+
tags = object.tags
9489
})
9590
end
9691

97-
function osm2pgsql.process_way(data)
98-
clean_tags(data.tags)
99-
if is_empty(data.tags) then
92+
function osm2pgsql.process_way(object)
93+
if clean_tags(object.tags) then
10094
return
10195
end
10296

103-
if is_polygon(data.tags) then
97+
if is_polygon(object.tags) then
10498
tables.polygon:add_row({
105-
tags = data.tags,
106-
name = data.tags.name,
99+
tags = object.tags,
100+
name = object.tags.name,
107101
geom = { create = 'area' }
108102
})
109103
else
110104
tables.line:add_row({
111-
tags = data.tags,
112-
name = data.tags.name
105+
tags = object.tags,
106+
name = object.tags.name
113107
})
114108
end
115109
end
116110

117-
function osm2pgsql.process_relation(data)
118-
clean_tags(data.tags)
119-
if is_empty(data.tags) then
111+
function osm2pgsql.process_relation(object)
112+
if clean_tags(object.tags) then
120113
return
121114
end
122115

123-
if data.tags.type == 'multipolygon' or data.tags.type == 'boundary' then
116+
if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then
124117
tables.polygon:add_row({
125-
tags = data.tags,
126-
name = data.tags.name,
118+
tags = object.tags,
119+
name = object.tags.name,
127120
geom = { create = 'area', multi = false }
128121
})
129122
return
130123
end
131124

132-
if data.tags.type == 'route' then
125+
if object.tags.type == 'route' then
133126
tables.route:add_row({
134-
tags = data.tags,
127+
tags = object.tags,
135128
geom = { create = 'line' }
136129
})
137130
end

tests/test-output-flex.cpp

Lines changed: 22 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,86 +7,38 @@ static testing::db::import_t db;
77

88
static char const *const conf_file = "test_output_flex.lua";
99

10-
static void require_tables(pg::conn_t const &conn)
10+
struct options_slim_default
1111
{
12-
conn.require_has_table("osm2pgsql_test_point");
13-
conn.require_has_table("osm2pgsql_test_line");
14-
conn.require_has_table("osm2pgsql_test_polygon");
15-
conn.require_has_table("osm2pgsql_test_route");
16-
}
12+
static options_t options()
13+
{
14+
return testing::opt_t().slim().flex(conf_file);
15+
}
16+
};
1717

18-
TEST_CASE("liechtenstein slim regression simple")
18+
struct options_slim_latlon
1919
{
20-
options_t const options = testing::opt_t().slim().flex(conf_file);
20+
static options_t options()
21+
{
22+
return testing::opt_t().slim().flex(conf_file).srs(PROJ_LATLONG);
23+
}
24+
};
25+
26+
TEMPLATE_TEST_CASE("liechtenstein regression", "", options_slim_default,
27+
options_slim_latlon)
28+
{
29+
options_t options = TestType::options();
2130

2231
REQUIRE_NOTHROW(db.run_file(options, "liechtenstein-2013-08-03.osm.pbf"));
2332

2433
auto conn = db.db().connect();
25-
require_tables(conn);
34+
35+
conn.require_has_table("osm2pgsql_test_point");
36+
conn.require_has_table("osm2pgsql_test_line");
37+
conn.require_has_table("osm2pgsql_test_polygon");
38+
conn.require_has_table("osm2pgsql_test_route");
2639

2740
CHECK(1362 == conn.get_count("osm2pgsql_test_point"));
2841
CHECK(2932 == conn.get_count("osm2pgsql_test_line"));
2942
CHECK(4136 == conn.get_count("osm2pgsql_test_polygon"));
3043
CHECK(35 == conn.get_count("osm2pgsql_test_route"));
3144
}
32-
33-
TEST_CASE("liechtenstein slim latlon")
34-
{
35-
options_t const options =
36-
testing::opt_t().slim().flex(conf_file).srs(PROJ_LATLONG);
37-
38-
REQUIRE_NOTHROW(db.run_file(options, "liechtenstein-2013-08-03.osm.pbf"));
39-
40-
auto conn = db.db().connect();
41-
require_tables(conn);
42-
43-
REQUIRE(1362 == conn.get_count("osm2pgsql_test_point"));
44-
REQUIRE(2932 == conn.get_count("osm2pgsql_test_line"));
45-
REQUIRE(4136 == conn.get_count("osm2pgsql_test_polygon"));
46-
}
47-
48-
TEST_CASE("way area slim flatnode")
49-
{
50-
options_t const options =
51-
testing::opt_t().slim().flex(conf_file).flatnodes();
52-
53-
REQUIRE_NOTHROW(db.run_file(options, "test_output_pgsql_way_area.osm"));
54-
55-
auto conn = db.db().connect();
56-
require_tables(conn);
57-
58-
REQUIRE(0 == conn.get_count("osm2pgsql_test_point"));
59-
REQUIRE(0 == conn.get_count("osm2pgsql_test_line"));
60-
REQUIRE(1 == conn.get_count("osm2pgsql_test_polygon"));
61-
}
62-
63-
TEST_CASE("route relation slim flatnode")
64-
{
65-
options_t const options =
66-
testing::opt_t().slim().flex(conf_file).flatnodes();
67-
68-
REQUIRE_NOTHROW(db.run_file(options, "test_output_pgsql_route_rel.osm"));
69-
70-
auto conn = db.db().connect();
71-
require_tables(conn);
72-
73-
REQUIRE(0 == conn.get_count("osm2pgsql_test_point"));
74-
REQUIRE(1 == conn.get_count("osm2pgsql_test_line"));
75-
REQUIRE(0 == conn.get_count("osm2pgsql_test_polygon"));
76-
REQUIRE(1 == conn.get_count("osm2pgsql_test_route"));
77-
}
78-
79-
TEST_CASE("liechtenstein slim bz2 parsing regression")
80-
{
81-
options_t const options = testing::opt_t().slim().flex(conf_file);
82-
83-
REQUIRE_NOTHROW(db.run_file(options, "liechtenstein-2013-08-03.osm.bz2"));
84-
85-
auto conn = db.db().connect();
86-
require_tables(conn);
87-
88-
REQUIRE(1362 == conn.get_count("osm2pgsql_test_point"));
89-
REQUIRE(2932 == conn.get_count("osm2pgsql_test_line"));
90-
REQUIRE(4136 == conn.get_count("osm2pgsql_test_polygon"));
91-
REQUIRE(35 == conn.get_count("osm2pgsql_test_route"));
92-
}

0 commit comments

Comments
 (0)