Skip to content

Commit 4fbc113

Browse files
committed
Extract flex get_bbox() tests into their own file
1 parent b7ca67c commit 4fbc113

File tree

5 files changed

+84
-16
lines changed

5 files changed

+84
-16
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ if (HAVE_LUA)
7474
set_test(test-output-flex)
7575
set_test(test-output-flex-area)
7676
set_test(test-output-flex-attr)
77+
set_test(test-output-flex-bbox)
7778
set_test(test-output-flex-extra)
7879
set_test(test-output-flex-invalid-geom)
7980
set_test(test-output-flex-lua-fail)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
local points = osm2pgsql.define_node_table('osm2pgsql_test_points', {
3+
{ column = 'tags', type = 'hstore' },
4+
{ column = 'min_x', type = 'real' },
5+
{ column = 'min_y', type = 'real' },
6+
{ column = 'max_x', type = 'real' },
7+
{ column = 'max_y', type = 'real' },
8+
{ column = 'geom', type = 'point' },
9+
})
10+
11+
local highways = osm2pgsql.define_way_table('osm2pgsql_test_highways', {
12+
{ column = 'tags', type = 'hstore' },
13+
{ column = 'min_x', type = 'real' },
14+
{ column = 'min_y', type = 'real' },
15+
{ column = 'max_x', type = 'real' },
16+
{ column = 'max_y', type = 'real' },
17+
{ column = 'geom', type = 'linestring' },
18+
})
19+
20+
function osm2pgsql.process_node(object)
21+
local row = {
22+
tags = object.tags,
23+
}
24+
25+
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
26+
27+
points:add_row(row)
28+
end
29+
30+
function osm2pgsql.process_way(object)
31+
local row = {
32+
tags = object.tags,
33+
geom = { create = 'line' }
34+
}
35+
36+
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
37+
38+
highways:add_row(row)
39+
end
40+

tests/data/test_output_flex_extra.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ tables.highways = osm2pgsql.define_table{
77
columns = {
88
{ column = 'tags', type = 'hstore' },
99
{ column = 'refs', type = 'text' },
10-
{ column = 'min_x', type = 'real' },
11-
{ column = 'min_y', type = 'real' },
12-
{ column = 'max_x', type = 'real' },
13-
{ column = 'max_y', type = 'real' },
1410
{ column = 'geom', type = 'linestring' },
1511
}
1612
}
@@ -38,8 +34,6 @@ function osm2pgsql.process_way(object)
3834
geom = { create = 'line' }
3935
}
4036

41-
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
42-
4337
-- if there is any data from relations, add it in
4438
local d = by_way_id[object.id]
4539
if d then

tests/test-output-flex-bbox.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
TEST_CASE("bbox on nodes and ways")
9+
{
10+
testing::opt_t options = testing::opt_t()
11+
.flex("test_output_flex_bbox.lua")
12+
.srs(PROJ_LATLONG);
13+
14+
REQUIRE_NOTHROW(db.run_import(options,
15+
"n10 v1 dV Ta=b x10.0 y10.0\n"
16+
"n11 v1 dV Ta=b x10.0 y10.2\n"
17+
"n12 v1 dV Ta=b x10.2 y10.2\n"
18+
"w20 v1 dV Thighway=primary Nn10,n11,n12\n"));
19+
20+
auto conn = db.db().connect();
21+
22+
CHECK(3 == conn.get_count("osm2pgsql_test_points"));
23+
24+
CHECK(1 == conn.get_count("osm2pgsql_test_points",
25+
"ST_AsText(geom) = 'POINT(10 10)'"));
26+
27+
CHECK(1 == conn.get_count(
28+
"osm2pgsql_test_points",
29+
"abs(min_x - 10.0) < 0.01 AND abs(min_y - 10.0) < 0.01 AND "
30+
"abs(max_x - 10.0) < 0.01 AND abs(max_y - 10.0) < 0.01"));
31+
32+
CHECK(1 == conn.get_count("osm2pgsql_test_highways"));
33+
34+
CHECK(1 == conn.get_count(
35+
"osm2pgsql_test_highways",
36+
"ST_AsText(geom) = 'LINESTRING(10 10,10 10.2,10.2 10.2)'"));
37+
38+
CHECK(1 == conn.get_count(
39+
"osm2pgsql_test_highways",
40+
"abs(min_x - 10.0) < 0.01 AND abs(min_y - 10.0) < 0.01 AND "
41+
"abs(max_x - 10.2) < 0.01 AND abs(max_y - 10.2) < 0.01"));
42+
}
43+

tests/test-output-flex-extra.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ TEST_CASE("relation data on ways")
117117
CHECK(2 == conn.get_count("osm2pgsql_test_highways", "refs = 'X11'"));
118118
CHECK(1 == conn.get_count("osm2pgsql_test_highways", "refs IS NULL"));
119119

120-
CHECK(1 == conn.get_count(
121-
"osm2pgsql_test_highways",
122-
"abs(min_x - 10.0) < 0.01 AND abs(min_y - 10.0) < 0.01 AND "
123-
"abs(max_x - 10.2) < 0.01 AND abs(max_y - 10.2) < 0.01"));
124-
125120
CHECK(1 == conn.get_count("osm2pgsql_test_routes", "members = '20,21'"));
126121

127122
// move node in way in the relation
@@ -138,11 +133,6 @@ TEST_CASE("relation data on ways")
138133
CHECK(2 == conn.get_count("osm2pgsql_test_highways", "refs = 'X11'"));
139134
CHECK(1 == conn.get_count("osm2pgsql_test_highways", "refs IS NULL"));
140135

141-
CHECK(1 == conn.get_count(
142-
"osm2pgsql_test_highways",
143-
"abs(min_x - 10.0) < 0.01 AND abs(min_y - 10.0) < 0.01 AND "
144-
"abs(max_x - 10.2) < 0.01 AND abs(max_y - 10.2) < 0.01"));
145-
146136
CHECK(1 == conn.get_count("osm2pgsql_test_routes", "members = '20,21'"));
147137

148138
// add the third way to the relation

0 commit comments

Comments
 (0)