Skip to content

Commit 30fc3ed

Browse files
committed
Cleanup flex-area test: Use minimal config file for this test
1 parent b8af2b2 commit 30fc3ed

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
local polygons = osm2pgsql.define_table{
3+
name = 'osm2pgsql_test_polygon',
4+
ids = { type = 'area', id_column = 'osm_id' },
5+
columns = {
6+
{ column = 'name', type = 'text' },
7+
{ column = 'geom', type = 'geometry' },
8+
{ column = 'area', type = 'area' },
9+
}
10+
}
11+
12+
function is_empty(some_table)
13+
return next(some_table) == nil
14+
end
15+
16+
function osm2pgsql.process_way(object)
17+
if is_empty(object.tags) then
18+
return
19+
end
20+
21+
polygons:add_row({
22+
name = object.tags.name,
23+
geom = { create = 'area' }
24+
})
25+
end
26+
27+
function osm2pgsql.process_relation(object)
28+
polygons:add_row({
29+
name = object.tags.name,
30+
geom = { create = 'area', multi = false }
31+
})
32+
end
33+

tests/test-output-flex-area.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
static testing::db::import_t db;
77

8-
TEST_CASE("default projection")
8+
static char const *const conf_file = "test_output_flex_area.lua";
9+
static char const *const data_file = "test_output_pgsql_area.osm";
10+
11+
TEST_CASE("area calculation in default projection")
912
{
10-
options_t const options =
11-
testing::opt_t().slim().flex("test_output_flex.lua");
13+
options_t const options = testing::opt_t().flex(conf_file);
1214

13-
REQUIRE_NOTHROW(db.run_file(options, "test_output_pgsql_area.osm"));
15+
REQUIRE_NOTHROW(db.run_file(options, data_file));
1416

1517
auto conn = db.db().connect();
1618

@@ -23,29 +25,28 @@ TEST_CASE("default projection")
2325
"SELECT area FROM osm2pgsql_test_polygon WHERE name='multi'");
2426
}
2527

26-
TEST_CASE("latlon projection")
28+
TEST_CASE("area calculation in latlon projection")
2729
{
2830
options_t const options =
29-
testing::opt_t().slim().flex("test_output_flex.lua").srs(PROJ_LATLONG);
31+
testing::opt_t().flex(conf_file).srs(PROJ_LATLONG);
3032

31-
REQUIRE_NOTHROW(db.run_file(options, "test_output_pgsql_area.osm"));
33+
REQUIRE_NOTHROW(db.run_file(options, data_file));
3234

3335
auto conn = db.db().connect();
3436

3537
REQUIRE(2 == conn.get_count("osm2pgsql_test_polygon"));
3638
conn.assert_double(
37-
1, "SELECT area FROM osm2pgsql_test_polygon WHERE name='poly'");
39+
1.0, "SELECT area FROM osm2pgsql_test_polygon WHERE name='poly'");
3840
conn.assert_double(
39-
8, "SELECT area FROM osm2pgsql_test_polygon WHERE name='multi'");
41+
8.0, "SELECT area FROM osm2pgsql_test_polygon WHERE name='multi'");
4042
}
4143

42-
TEST_CASE("latlon projection with way area reprojection")
44+
TEST_CASE("area calculation in latlon projection with way area reprojection")
4345
{
44-
options_t options =
45-
testing::opt_t().slim().flex("test_output_flex.lua").srs(PROJ_LATLONG);
46+
options_t options = testing::opt_t().flex(conf_file).srs(PROJ_LATLONG);
4647
options.reproject_area = true;
4748

48-
REQUIRE_NOTHROW(db.run_file(options, "test_output_pgsql_area.osm"));
49+
REQUIRE_NOTHROW(db.run_file(options, data_file));
4950

5051
auto conn = db.db().connect();
5152

0 commit comments

Comments
 (0)