Skip to content

Commit 36d698b

Browse files
authored
Merge pull request #1245 from joto/more-tests
More tests
2 parents 2f27a3a + 7038163 commit 36d698b

9 files changed

+793
-0
lines changed

tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ if (HAVE_LUA)
7878
set_test(test-output-flex-invalid-geom)
7979
set_test(test-output-flex-line)
8080
set_test(test-output-flex-lua-fail)
81+
set_test(test-output-flex-nodes)
8182
set_test(test-output-flex-nogeom)
8283
set_test(test-output-flex-uni)
84+
set_test(test-output-flex-relations)
85+
set_test(test-output-flex-relation-changes)
86+
set_test(test-output-flex-relation-combinations)
8387
set_test(test-output-flex-stage2)
8488
set_test(test-output-flex-tablespace LABELS Tablespace)
8589
set_test(test-output-flex-types)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
local tables = {}
3+
4+
tables.t1 = osm2pgsql.define_node_table('osm2pgsql_test_t1', {
5+
{ column = 'tags', type = 'hstore' },
6+
{ column = 'geom', type = 'point' },
7+
})
8+
9+
tables.t2 = osm2pgsql.define_node_table('osm2pgsql_test_t2', {
10+
{ column = 'tags', type = 'hstore' },
11+
{ column = 'geom', type = 'point' },
12+
})
13+
14+
function osm2pgsql.process_node(object)
15+
if object.tags.t1 then
16+
tables.t1:add_row({
17+
tags = object.tags
18+
})
19+
end
20+
if object.tags.t2 then
21+
tables.t2:add_row({
22+
tags = object.tags
23+
})
24+
end
25+
end
26+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
local rel_table = osm2pgsql.define_area_table('osm2pgsql_test_relations', {
3+
{ column = 'tags', type = 'hstore' },
4+
{ column = 'geom', type = 'geometry' }
5+
})
6+
7+
function osm2pgsql.process_relation(object)
8+
if object.tags.type == 'multipolygon' then
9+
rel_table:add_row{
10+
tags = object.tags,
11+
geom = { create = 'area' }
12+
}
13+
end
14+
end
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
local rel_table = osm2pgsql.define_relation_table('osm2pgsql_test_relations', {
3+
{ column = 'tags', type = 'hstore' }
4+
})
5+
6+
function osm2pgsql.select_relation_members(relation)
7+
return { ways = osm2pgsql.way_member_ids(relation) }
8+
end
9+
10+
function osm2pgsql.process_relation(object)
11+
rel_table:add_row({
12+
tags = object.tags
13+
})
14+
end
15+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
local tables = {}
3+
4+
tables.t1 = osm2pgsql.define_relation_table('osm2pgsql_test_t1', {
5+
{ column = 'tags', type = 'hstore' }
6+
})
7+
8+
tables.t2 = osm2pgsql.define_relation_table('osm2pgsql_test_t2', {
9+
{ column = 'tags', type = 'hstore' }
10+
})
11+
12+
function osm2pgsql.process_relation(object)
13+
if object.tags.t1 then
14+
tables.t1:add_row({
15+
tags = object.tags
16+
})
17+
end
18+
if object.tags.t2 then
19+
tables.t2:add_row({
20+
tags = object.tags
21+
})
22+
end
23+
end
24+

tests/test-output-flex-nodes.cpp

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#include <catch.hpp>
2+
3+
#include "common-import.hpp"
4+
#include "common-options.hpp"
5+
6+
static testing::db::import_t db;
7+
8+
static char const *const conf_file = "test_output_flex_nodes.lua";
9+
10+
TEST_CASE("add nodes")
11+
{
12+
options_t options = testing::opt_t().slim().flex(conf_file);
13+
14+
REQUIRE_NOTHROW(db.run_import(options,
15+
"n10 v1 dV x10.0 y10.0\n"
16+
"n11 v1 dV Tt1=yes x10.0 y10.1\n"
17+
"n12 v1 dV Tt2=yes x10.0 y10.2\n"
18+
"n13 v1 dV Tt1=yes,t2=yes x10.0 y10.2\n"));
19+
20+
auto conn = db.db().connect();
21+
22+
CHECK(2 == conn.get_count("osm2pgsql_test_t1"));
23+
CHECK(2 == conn.get_count("osm2pgsql_test_t2"));
24+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 11"));
25+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 13"));
26+
27+
options.append = true;
28+
29+
REQUIRE_NOTHROW(db.run_import(options,
30+
"n14 v1 dV x11.0 y10.0\n"
31+
"n15 v1 dV Tt1=yes x11.0 y10.1\n"
32+
"n16 v1 dV Tt2=yes x11.0 y10.2\n"
33+
"n17 v1 dV Tt1=yes,t2=yes x11.0 y10.2\n"));
34+
35+
CHECK(4 == conn.get_count("osm2pgsql_test_t1"));
36+
CHECK(4 == conn.get_count("osm2pgsql_test_t2"));
37+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 11"));
38+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 13"));
39+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 15"));
40+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 17"));
41+
}
42+
43+
enum class node_relationship
44+
{
45+
none,
46+
in_way,
47+
in_relation
48+
};
49+
50+
template <node_relationship R>
51+
struct node_rel
52+
{
53+
static constexpr const node_relationship rs = R;
54+
};
55+
56+
using node_rel_none = node_rel<node_relationship::none>;
57+
using node_rel_in_way = node_rel<node_relationship::in_way>;
58+
using node_rel_in_relation = node_rel<node_relationship::in_relation>;
59+
60+
TEMPLATE_TEST_CASE("change nodes", "", node_rel_none, node_rel_in_way,
61+
node_rel_in_relation)
62+
{
63+
options_t options = testing::opt_t().slim().flex(conf_file);
64+
65+
REQUIRE_NOTHROW(db.run_import(options,
66+
"n10 v1 dV x10.0 y10.0\n"
67+
"n11 v1 dV Tt1=yes x10.0 y10.1\n"
68+
"n12 v1 dV Tt2=yes x10.0 y10.2\n"
69+
"n13 v1 dV Tt1=yes,t2=yes x10.0 y10.2\n"
70+
71+
"n14 v1 dV x11.0 y10.0\n"
72+
"n15 v1 dV Tt1=yes x11.0 y10.1\n"
73+
"n16 v1 dV Tt1=yes,t2=yes x11.0 y10.2\n"));
74+
75+
options.append = true;
76+
77+
if (TestType{}.rs == node_relationship::in_way) {
78+
REQUIRE_NOTHROW(db.run_import(options, "w20 v1 dV Nn14,n15,n16\n"));
79+
} else if (TestType{}.rs == node_relationship::in_relation) {
80+
REQUIRE_NOTHROW(db.run_import(options, "r30 v1 dV Mn14@,n15@,n16@\n"));
81+
}
82+
83+
auto conn = db.db().connect();
84+
85+
CHECK(4 == conn.get_count("osm2pgsql_test_t1"));
86+
CHECK(3 == conn.get_count("osm2pgsql_test_t2"));
87+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 11"));
88+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 13"));
89+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 15"));
90+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 16"));
91+
92+
SECTION("no tag, add tag t1")
93+
{
94+
REQUIRE_NOTHROW(
95+
db.run_import(options, "n14 v2 dV Tt1=yes x11.0 y10.0\n"));
96+
CHECK(5 == conn.get_count("osm2pgsql_test_t1"));
97+
CHECK(3 == conn.get_count("osm2pgsql_test_t2"));
98+
}
99+
100+
SECTION("no tag, add tag t1, t2")
101+
{
102+
REQUIRE_NOTHROW(
103+
db.run_import(options, "n14 v2 dV Tt1=yes,t2=yes x11.0 y10.0\n"));
104+
CHECK(5 == conn.get_count("osm2pgsql_test_t1"));
105+
CHECK(4 == conn.get_count("osm2pgsql_test_t2"));
106+
}
107+
108+
SECTION("one tag, remove tag t1")
109+
{
110+
REQUIRE_NOTHROW(db.run_import(options, "n15 v2 dV x11.0 y10.0\n"));
111+
CHECK(3 == conn.get_count("osm2pgsql_test_t1"));
112+
CHECK(3 == conn.get_count("osm2pgsql_test_t2"));
113+
}
114+
115+
SECTION("one tag, change tag t1 to t2")
116+
{
117+
REQUIRE_NOTHROW(
118+
db.run_import(options, "n15 v2 dV Tt2=yes x11.0 y10.0\n"));
119+
CHECK(3 == conn.get_count("osm2pgsql_test_t1"));
120+
CHECK(4 == conn.get_count("osm2pgsql_test_t2"));
121+
}
122+
123+
SECTION("one tag, add tag t2")
124+
{
125+
REQUIRE_NOTHROW(
126+
db.run_import(options, "n15 v2 dV Tt1=yes,t2=yes x11.0 y10.0\n"));
127+
CHECK(4 == conn.get_count("osm2pgsql_test_t1"));
128+
CHECK(4 == conn.get_count("osm2pgsql_test_t2"));
129+
}
130+
131+
SECTION("two tags, remove tag t1 and t2")
132+
{
133+
REQUIRE_NOTHROW(db.run_import(options, "n16 v2 dV x11.0 y10.0\n"));
134+
CHECK(3 == conn.get_count("osm2pgsql_test_t1"));
135+
CHECK(2 == conn.get_count("osm2pgsql_test_t2"));
136+
}
137+
138+
SECTION("two tags, remove only tag t1 not t2")
139+
{
140+
REQUIRE_NOTHROW(
141+
db.run_import(options, "n16 v2 dV Tt2=yes x11.0 y10.0\n"));
142+
CHECK(3 == conn.get_count("osm2pgsql_test_t1"));
143+
CHECK(3 == conn.get_count("osm2pgsql_test_t2"));
144+
}
145+
}
146+
147+
TEMPLATE_TEST_CASE("delete nodes", "", node_rel_none, node_rel_in_way,
148+
node_rel_in_relation)
149+
{
150+
options_t options = testing::opt_t().slim().flex(conf_file);
151+
152+
REQUIRE_NOTHROW(db.run_import(options,
153+
"n10 v1 dV x10.0 y10.0\n"
154+
"n11 v1 dV Tt1=yes x10.0 y10.1\n"
155+
"n12 v1 dV Tt2=yes x10.0 y10.2\n"
156+
"n13 v1 dV Tt1=yes,t2=yes x10.0 y10.2\n"
157+
158+
"n14 v1 dV x11.0 y10.0\n"
159+
"n15 v1 dV Tt1=yes x11.0 y10.1\n"
160+
"n16 v1 dV Tt1=yes,t2=yes x11.0 y10.2\n"));
161+
162+
options.append = true;
163+
164+
if (TestType{}.rs == node_relationship::in_way) {
165+
REQUIRE_NOTHROW(db.run_import(options, "w20 v1 dV Nn14,n15,n16\n"));
166+
} else if (TestType{}.rs == node_relationship::in_relation) {
167+
REQUIRE_NOTHROW(db.run_import(options, "r30 v1 dV Mn14@,n15@,n16@\n"));
168+
}
169+
170+
auto conn = db.db().connect();
171+
172+
CHECK(4 == conn.get_count("osm2pgsql_test_t1"));
173+
CHECK(3 == conn.get_count("osm2pgsql_test_t2"));
174+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 11"));
175+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 13"));
176+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 15"));
177+
CHECK(1 == conn.get_count("osm2pgsql_test_t1", "node_id = 16"));
178+
179+
REQUIRE_NOTHROW(db.run_import(options, "n14 v2 dD\n"
180+
"n15 v2 dD\n"
181+
"n16 v2 dD\n"));
182+
183+
CHECK(2 == conn.get_count("osm2pgsql_test_t1"));
184+
CHECK(2 == conn.get_count("osm2pgsql_test_t2"));
185+
}

0 commit comments

Comments
 (0)