|
| 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