From ae02884e06b7df3167ee9ad775f95f016f465d9e Mon Sep 17 00:00:00 2001 From: Greg Knisely Date: Mon, 11 Mar 2024 14:10:35 -0400 Subject: [PATCH] more cleanup --- test/graphparser.cc | 199 ++++++++++++++------------------------------ 1 file changed, 63 insertions(+), 136 deletions(-) diff --git a/test/graphparser.cc b/test/graphparser.cc index 0e85f43c2f..5c9498d24b 100644 --- a/test/graphparser.cc +++ b/test/graphparser.cc @@ -28,6 +28,16 @@ namespace { const std::string config_file = "test/test_config_gp"; +std::string ways_file = "test_ways.bin"; +std::string way_nodes_file = "test_way_nodes.bin"; +std::string nodes_file = "test_nodes.bin"; +std::string edges_file = "test_edges.bin"; +std::string access_file = "test_access.bin"; +std::string from_restriction_file = "test_from_complex_restrictions.bin"; +std::string to_restriction_file = "test_to_complex_restrictions.bin"; +std::string bss_nodes_file = "test_bss_nodes.bin"; +std::string linguistic_node_file = "test_linguistic_node.bin"; + const auto node_predicate = [](const OSMWayNode& a, const OSMWayNode& b) { return a.node.osmid_ < b.node.osmid_; }; @@ -48,18 +58,55 @@ OSMWay GetWay(uint32_t way_id, sequence& ways) { return *found; } +void DoConfig() { + std::ofstream file; + try { + file.open(config_file, std::ios_base::trunc); + file << "{ \ + \"mjolnir\": { \ + \"id_table_size\": 1000, \ + \"tile_dir\": \"test/data/graph_parser_tiles\" \ + } \ + }"; + } catch (...) {} + file.close(); +} + +// must do clean up here vs TearDown() as we are building data +// in the same directory multiple times +void CleanUp() { + if (filesystem::exists(ways_file)) + filesystem::remove(ways_file); + + if (filesystem::exists(way_nodes_file)) + filesystem::remove(way_nodes_file); + + if (filesystem::exists(nodes_file)) + filesystem::remove(nodes_file); + + if (filesystem::exists(edges_file)) + filesystem::remove(edges_file); + + if (filesystem::exists(access_file)) + filesystem::remove(access_file); + + if (filesystem::exists(from_restriction_file)) + filesystem::remove(from_restriction_file); + + if (filesystem::exists(to_restriction_file)) + filesystem::remove(to_restriction_file); + + if (filesystem::exists(bss_nodes_file)) + filesystem::remove(bss_nodes_file); + + if (filesystem::exists(linguistic_node_file)) + filesystem::remove(linguistic_node_file); +} + void BollardsGatesAndAccess(const std::string& config_file) { boost::property_tree::ptree conf; rapidjson::read_json(config_file, conf); - std::string ways_file = "test_ways.bin"; - std::string way_nodes_file = "test_way_nodes.bin"; - std::string access_file = "test_access.bin"; - std::string from_restriction_file = "test_from_complex_restrictions.bin"; - std::string to_restriction_file = "test_to_complex_restrictions.bin"; - std::string bss_nodes_file = "test_bss_nodes.bin"; - std::string linguistic_node_file = "test_linguistic_node.bin"; - auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/liechtenstein-latest.osm.pbf"}, @@ -206,27 +253,13 @@ void BollardsGatesAndAccess(const std::string& config_file) { EXPECT_TRUE((bike_network & kMcn) && (bike_network & kRcn) && way_75786176.bike_network() == 0) << "rcn and mtb not marked on way 75786176."; - filesystem::remove(ways_file); - filesystem::remove(way_nodes_file); - filesystem::remove(access_file); - filesystem::remove(from_restriction_file); - filesystem::remove(to_restriction_file); - filesystem::remove(bss_nodes_file); - filesystem::remove(linguistic_node_file); + CleanUp(); } void RemovableBollards(const std::string& config_file) { boost::property_tree::ptree conf; rapidjson::read_json(config_file, conf); - std::string ways_file = "test_ways.bin"; - std::string way_nodes_file = "test_way_nodes.bin"; - std::string access_file = "test_access.bin"; - std::string from_restriction_file = "test_from_complex_restrictions.bin"; - std::string to_restriction_file = "test_to_complex_restrictions.bin"; - std::string bss_nodes_file = "test_bss_nodes.bin"; - std::string linguistic_node_file = "test_linguistic_node.bin"; - auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/rome.osm.pbf"}, ways_file, way_nodes_file, access_file); @@ -250,27 +283,13 @@ void RemovableBollards(const std::string& config_file) { kEmergencyAccess | kPedestrianAccess | kWheelchairAccess | kBicycleAccess | kMopedAccess | kMotorcycleAccess); - filesystem::remove(ways_file); - filesystem::remove(way_nodes_file); - filesystem::remove(access_file); - filesystem::remove(from_restriction_file); - filesystem::remove(to_restriction_file); - filesystem::remove(bss_nodes_file); - filesystem::remove(linguistic_node_file); + CleanUp(); } void Exits(const std::string& config_file) { boost::property_tree::ptree conf; rapidjson::read_json(config_file, conf); - std::string ways_file = "test_ways.bin"; - std::string way_nodes_file = "test_way_nodes.bin"; - std::string access_file = "test_access.bin"; - std::string from_restriction_file = "test_from_complex_restrictions.bin"; - std::string to_restriction_file = "test_to_complex_restrictions.bin"; - std::string bss_nodes_file = "test_bss_nodes.bin"; - std::string linguistic_node_file = "test_linguistic_node.bin"; - auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/harrisburg.osm.pbf"}, ways_file, way_nodes_file, access_file); @@ -302,27 +321,13 @@ void Exits(const std::string& config_file) { EXPECT_EQ(osmdata.node_names.name(node.exit_to_index()), "PA441") << "node exit_to not set correctly ."; - filesystem::remove(ways_file); - filesystem::remove(way_nodes_file); - filesystem::remove(access_file); - filesystem::remove(from_restriction_file); - filesystem::remove(to_restriction_file); - filesystem::remove(bss_nodes_file); - filesystem::remove(linguistic_node_file); + CleanUp(); } void Baltimore(const std::string& config_file) { boost::property_tree::ptree conf; rapidjson::read_json(config_file, conf); - std::string ways_file = "test_ways.bin"; - std::string way_nodes_file = "test_way_nodes.bin"; - std::string access_file = "test_access.bin"; - std::string from_restriction_file = "test_from_complex_restrictions.bin"; - std::string to_restriction_file = "test_to_complex_restrictions.bin"; - std::string bss_nodes_file = "test_bss_nodes.bin"; - std::string linguistic_node_file = "test_linguistic_node.bin"; - auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/baltimore.osm.pbf"}, ways_file, way_nodes_file, access_file); @@ -430,27 +435,13 @@ void Baltimore(const std::string& config_file) { FAIL() << "98040438 restriction test failed."; } - filesystem::remove(ways_file); - filesystem::remove(way_nodes_file); - filesystem::remove(access_file); - filesystem::remove(from_restriction_file); - filesystem::remove(to_restriction_file); - filesystem::remove(bss_nodes_file); - filesystem::remove(linguistic_node_file); + CleanUp(); } void Bike(const std::string& config_file) { boost::property_tree::ptree conf; rapidjson::read_json(config_file, conf); - std::string ways_file = "test_ways.bin"; - std::string way_nodes_file = "test_way_nodes.bin"; - std::string access_file = "test_access.bin"; - std::string from_restriction_file = "test_from_complex_restrictions.bin"; - std::string to_restriction_file = "test_to_complex_restrictions.bin"; - std::string bss_nodes_file = "test_bss_nodes.bin"; - std::string linguistic_node_file = "test_linguistic_node.bin"; - auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/bike.osm.pbf"}, ways_file, way_nodes_file, access_file); @@ -528,27 +519,13 @@ void Bike(const std::string& config_file) { EXPECT_TRUE(way_156539491.moped_forward()); EXPECT_TRUE(way_156539491.bike_backward()); - filesystem::remove(ways_file); - filesystem::remove(way_nodes_file); - filesystem::remove(access_file); - filesystem::remove(from_restriction_file); - filesystem::remove(to_restriction_file); - filesystem::remove(bss_nodes_file); - filesystem::remove(linguistic_node_file); + CleanUp(); } void Bus(const std::string& config_file) { boost::property_tree::ptree conf; rapidjson::read_json(config_file, conf); - std::string ways_file = "test_ways.bin"; - std::string way_nodes_file = "test_way_nodes.bin"; - std::string access_file = "test_access.bin"; - std::string from_restriction_file = "test_from_complex_restrictions.bin"; - std::string to_restriction_file = "test_to_complex_restrictions.bin"; - std::string bss_nodes_file = "test_bss_nodes.bin"; - std::string linguistic_node_file = "test_linguistic_node.bin"; - auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/bus.osm.pbf"}, ways_file, way_nodes_file, access_file); @@ -611,27 +588,13 @@ void Bus(const std::string& config_file) { EXPECT_FALSE(way_225895737.bus_backward()); EXPECT_FALSE(way_225895737.bike_backward()); - filesystem::remove(ways_file); - filesystem::remove(way_nodes_file); - filesystem::remove(access_file); - filesystem::remove(from_restriction_file); - filesystem::remove(to_restriction_file); - filesystem::remove(bss_nodes_file); - filesystem::remove(linguistic_node_file); + CleanUp(); } void BicycleTrafficSignals(const std::string& config_file) { boost::property_tree::ptree conf; rapidjson::read_json(config_file, conf); - std::string ways_file = "test_ways.bin"; - std::string way_nodes_file = "test_way_nodes.bin"; - std::string access_file = "test_access.bin"; - std::string from_restriction_file = "test_from_complex_restrictions.bin"; - std::string to_restriction_file = "test_to_complex_restrictions.bin"; - std::string bss_nodes_file = "test_bss_nodes.bin"; - std::string linguistic_node_file = "test_linguistic_node.bin"; - auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/nyc.osm.pbf"}, ways_file, way_nodes_file, access_file); @@ -662,27 +625,7 @@ void BicycleTrafficSignals(const std::string& config_file) { << "Bike rental at a shop not marked as intersection." */ - filesystem::remove(ways_file); - filesystem::remove(way_nodes_file); - filesystem::remove(access_file); - filesystem::remove(from_restriction_file); - filesystem::remove(to_restriction_file); - filesystem::remove(bss_nodes_file); - filesystem::remove(linguistic_node_file); -} - -void DoConfig() { - std::ofstream file; - try { - file.open(config_file, std::ios_base::trunc); - file << "{ \ - \"mjolnir\": { \ - \"id_table_size\": 1000, \ - \"tile_dir\": \"test/data/graph_parser_tiles\" \ - } \ - }"; - } catch (...) {} - file.close(); + CleanUp(); } TEST(GraphParser, TestBollardsGatesAndAccess) { @@ -727,16 +670,6 @@ TEST(GraphParser, TestImportBssNode) { conf.put("mjolnir.import_bike_share_stations", true); - std::string ways_file = "test_ways.bin"; - std::string way_nodes_file = "test_way_nodes.bin"; - std::string nodes_file = "test_nodes.bin"; - std::string edges_file = "test_edges.bin"; - std::string access_file = "test_access.bin"; - std::string from_restriction_file = "test_from_complex_restrictions.bin"; - std::string to_restriction_file = "test_to_complex_restrictions.bin"; - std::string bss_nodes_file = "test_bss_nodes.bin"; - std::string linguistic_node_file = "test_linguistic_node.bin"; - auto osmdata = PBFGraphParser::ParseWays(conf.get_child("mjolnir"), {VALHALLA_SOURCE_DIR "test/data/rome.osm.pbf"}, ways_file, way_nodes_file, access_file); @@ -827,13 +760,7 @@ TEST(GraphParser, TestImportBssNode) { check_edge_attribute(local_tile->directededge(edge_idx_2 + count_2 - 2), kPedestrianAccess, kBicycleAccess); - filesystem::remove(ways_file); - filesystem::remove(way_nodes_file); - filesystem::remove(access_file); - filesystem::remove(from_restriction_file); - filesystem::remove(to_restriction_file); - filesystem::remove(bss_nodes_file); - filesystem::remove(linguistic_node_file); + CleanUp(); } } // namespace