Skip to content

Commit 787a306

Browse files
committed
Clean flex-attr tests
1 parent 30fc3ed commit 787a306

File tree

2 files changed

+61
-65
lines changed

2 files changed

+61
-65
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
table = osm2pgsql.define_table{
3-
name = 'osm2pgsql_test_ways_attr',
2+
local attr_table = osm2pgsql.define_table{
3+
name = 'osm2pgsql_test_attr',
44
ids = { type = 'way', id_column = 'way_id' },
55
columns = {
66
{ column = 'tags', type = 'hstore' },
@@ -13,8 +13,8 @@ table = osm2pgsql.define_table{
1313
}
1414
}
1515

16-
function osm2pgsql.process_way(data)
17-
data.geom = { create = 'line' }
18-
table:add_row(data)
16+
function osm2pgsql.process_way(object)
17+
object.geom = { create = 'line' }
18+
attr_table:add_row(object)
1919
end
2020

tests/test-output-flex-attr.cpp

Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,74 @@
55

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

8-
TEST_CASE("no extra_attributes")
8+
static char const *const conf_file = "test_output_flex_attr.lua";
9+
static char const *const table = "osm2pgsql_test_attr";
10+
11+
TEST_CASE("without extra_attributes")
912
{
13+
options_t options = testing::opt_t().slim().flex(conf_file);
14+
1015
REQUIRE_NOTHROW(
11-
db.run_import(testing::opt_t().slim().flex("test_output_flex_attr.lua"),
12-
"n10 v1 dV x10.0 y10.0\n"
13-
"n11 v1 dV x10.0 y10.2\n"
14-
"n12 v1 dV x10.2 y10.2\n"
15-
"w20 v1 dV c31 t2020-01-12T12:34:56Z i17 utest "
16-
"Thighway=primary Nn10,n11,n12\n"));
16+
db.run_import(options, "n10 v1 dV x10.0 y10.0\n"
17+
"n11 v1 dV x10.0 y10.2\n"
18+
"n12 v1 dV x10.2 y10.2\n"
19+
"w20 v1 dV c31 t2020-01-12T12:34:56Z i17 utest "
20+
"Thighway=primary Nn10,n11,n12\n"));
1721

1822
auto conn = db.db().connect();
1923

20-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr"));
21-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr",
22-
"tags->'highway' = 'primary'"));
23-
CHECK(0 == conn.get_count("osm2pgsql_test_ways_attr", "version = 1"));
24-
CHECK(0 == conn.get_count("osm2pgsql_test_ways_attr", "changeset = 31"));
25-
CHECK(0 ==
26-
conn.get_count("osm2pgsql_test_ways_attr", "timestamp = 1578832496"));
27-
CHECK(0 == conn.get_count("osm2pgsql_test_ways_attr", "uid = 17"));
28-
CHECK(0 == conn.get_count("osm2pgsql_test_ways_attr", "\"user\" = 'test'"));
29-
30-
REQUIRE_NOTHROW(db.run_import(
31-
testing::opt_t().slim().append().flex("test_output_flex_attr.lua"),
32-
"n10 v2 dV x11.0 y11.0\n"));
33-
34-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr"));
35-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr",
36-
"tags->'highway' = 'primary'"));
37-
CHECK(0 == conn.get_count("osm2pgsql_test_ways_attr", "version = 1"));
38-
CHECK(0 == conn.get_count("osm2pgsql_test_ways_attr", "changeset = 31"));
39-
CHECK(0 ==
40-
conn.get_count("osm2pgsql_test_ways_attr", "timestamp = 1578832496"));
41-
CHECK(0 == conn.get_count("osm2pgsql_test_ways_attr", "uid = 17"));
42-
CHECK(0 == conn.get_count("osm2pgsql_test_ways_attr", "\"user\" = 'test'"));
24+
CHECK(1 == conn.get_count(table));
25+
CHECK(1 == conn.get_count(table, "tags->'highway' = 'primary'"));
26+
CHECK(0 == conn.get_count(table, "version = 1"));
27+
CHECK(0 == conn.get_count(table, "changeset = 31"));
28+
CHECK(0 == conn.get_count(table, "timestamp = 1578832496"));
29+
CHECK(0 == conn.get_count(table, "uid = 17"));
30+
CHECK(0 == conn.get_count(table, "\"user\" = 'test'"));
31+
32+
options.append = true;
33+
34+
REQUIRE_NOTHROW(db.run_import(options, "n10 v2 dV x11.0 y11.0\n"));
35+
36+
CHECK(1 == conn.get_count(table));
37+
CHECK(1 == conn.get_count(table, "tags->'highway' = 'primary'"));
38+
CHECK(0 == conn.get_count(table, "version = 1"));
39+
CHECK(0 == conn.get_count(table, "changeset = 31"));
40+
CHECK(0 == conn.get_count(table, "timestamp = 1578832496"));
41+
CHECK(0 == conn.get_count(table, "uid = 17"));
42+
CHECK(0 == conn.get_count(table, "\"user\" = 'test'"));
4343
}
4444

4545
TEST_CASE("with extra_attributes")
4646
{
47+
options_t options =
48+
testing::opt_t().extra_attributes().slim().flex(conf_file);
49+
4750
REQUIRE_NOTHROW(
48-
db.run_import(testing::opt_t().extra_attributes().slim().flex(
49-
"test_output_flex_attr.lua"),
50-
"n10 v1 dV x10.0 y10.0\n"
51-
"n11 v1 dV x10.0 y10.2\n"
52-
"n12 v1 dV x10.2 y10.2\n"
53-
"w20 v1 dV c31 t2020-01-12T12:34:56Z i17 utest "
54-
"Thighway=primary Nn10,n11,n12\n"));
51+
db.run_import(options, "n10 v1 dV x10.0 y10.0\n"
52+
"n11 v1 dV x10.0 y10.2\n"
53+
"n12 v1 dV x10.2 y10.2\n"
54+
"w20 v1 dV c31 t2020-01-12T12:34:56Z i17 utest "
55+
"Thighway=primary Nn10,n11,n12\n"));
5556

5657
auto conn = db.db().connect();
5758

58-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr"));
59-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr",
60-
"tags->'highway' = 'primary'"));
61-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr", "version = 1"));
62-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr", "changeset = 31"));
63-
CHECK(1 ==
64-
conn.get_count("osm2pgsql_test_ways_attr", "timestamp = 1578832496"));
65-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr", "uid = 17"));
66-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr", "\"user\" = 'test'"));
59+
CHECK(1 == conn.get_count(table));
60+
CHECK(1 == conn.get_count(table, "tags->'highway' = 'primary'"));
61+
CHECK(1 == conn.get_count(table, "version = 1"));
62+
CHECK(1 == conn.get_count(table, "changeset = 31"));
63+
CHECK(1 == conn.get_count(table, "timestamp = 1578832496"));
64+
CHECK(1 == conn.get_count(table, "uid = 17"));
65+
CHECK(1 == conn.get_count(table, "\"user\" = 'test'"));
6766

68-
REQUIRE_NOTHROW(
69-
db.run_import(testing::opt_t().extra_attributes().slim().append().flex(
70-
"test_output_flex_attr.lua"),
71-
"n10 v2 dV x11.0 y11.0\n"));
72-
73-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr"));
74-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr",
75-
"tags->'highway' = 'primary'"));
76-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr", "version = 1"));
77-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr", "changeset = 31"));
78-
CHECK(1 ==
79-
conn.get_count("osm2pgsql_test_ways_attr", "timestamp = 1578832496"));
80-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr", "uid = 17"));
81-
CHECK(1 == conn.get_count("osm2pgsql_test_ways_attr", "\"user\" = 'test'"));
67+
options.append = true;
68+
69+
REQUIRE_NOTHROW(db.run_import(options, "n10 v2 dV x11.0 y11.0\n"));
70+
71+
CHECK(1 == conn.get_count(table));
72+
CHECK(1 == conn.get_count(table, "tags->'highway' = 'primary'"));
73+
CHECK(1 == conn.get_count(table, "version = 1"));
74+
CHECK(1 == conn.get_count(table, "changeset = 31"));
75+
CHECK(1 == conn.get_count(table, "timestamp = 1578832496"));
76+
CHECK(1 == conn.get_count(table, "uid = 17"));
77+
CHECK(1 == conn.get_count(table, "\"user\" = 'test'"));
8278
}

0 commit comments

Comments
 (0)