adding tests

This commit is contained in:
Manish 2019-03-20 18:51:22 +01:00
parent 4e194a5a44
commit 38244345aa
2 changed files with 154 additions and 42 deletions

View File

@ -10,8 +10,10 @@
#include <carla/road/MapBuilder.h>
#include <carla/geom/Location.h>
#include <carla/geom/Math.h>
#include <carla/road/element/RoadInfoGeometry.h>
#include <carla/road/element/RoadInfoVisitor.h>
#include <carla/opendrive/OpenDriveParser.h>
#include <carla/opendrive/parser/pugixml/pugixml.hpp>
#include <fstream>
using namespace carla::road;
@ -19,6 +21,113 @@ using namespace carla::road::element;
using namespace carla::geom;
using namespace carla::opendrive;
const std::string BASE_PATH = LIBCARLA_TEST_CONTENT_FOLDER "/OpenDrive/";
// Geometry
void test_geometry(const pugi::xml_document &xml, boost::optional<Map>& map)
{
pugi::xml_node open_drive_node = xml.child("OpenDRIVE");
for (pugi::xml_node road_node : open_drive_node.children("road")) {
RoadId road_id = road_node.attribute("id").as_int();
for (pugi::xml_node plan_view_nodes : road_node.children("planView")) {
auto geometries_parser = plan_view_nodes.children("geometry");
size_t total_geometries_parser = std::distance(geometries_parser.begin(), geometries_parser.end());
size_t total_geometries = 0;
for (pugi::xml_node geometry_node : plan_view_nodes.children("geometry")){
float s = geometry_node.attribute("s").as_float();
auto geometry = map->_data.GetRoad(road_id)->GetInfo<RoadInfoGeometry>(s);
if (geometry != nullptr)
++total_geometries;
}
ASSERT_EQ(total_geometries, total_geometries_parser);
}
}
}
void test_roads(const pugi::xml_document &xml, boost::optional<Map>& map)
{
pugi::xml_node open_drive_node = xml.child("OpenDRIVE");
// Check total Roads
auto roads_parser = open_drive_node.children("road");
size_t total_roads_parser = std::distance(roads_parser.begin(), roads_parser.end());
size_t total_roads = map->_data.GetRoads().size();
ASSERT_EQ(total_roads, total_roads_parser);
for (pugi::xml_node road_node : roads_parser) {
RoadId road_id = road_node.attribute("id").as_int();
for (pugi::xml_node lanes_node : road_node.children("lanes")) {
// Check total Lane Sections
auto lane_sections_parser = lanes_node.children("laneSection");
size_t total_lane_sections_parser = std::distance(lane_sections_parser.begin(), lane_sections_parser.end());
size_t total_lane_sections = map->_data.GetRoad(road_id)->GetLaneSections().size();
ASSERT_EQ(total_lane_sections, total_lane_sections_parser);
for (pugi::xml_node lane_section_node : lane_sections_parser) {
// Check total Lanes
float s = lane_section_node.attribute("s").as_float();
auto ls_begin = map->_data.GetRoad(road_id)->GetLaneSectionsAt(s).begin();
auto ls_end = map->_data.GetRoad(road_id)->GetLaneSectionsAt(s).end();
size_t total_lanes = 0u;
for (auto& it = ls_begin; it != ls_end; ++it) {
total_lanes = it->GetLanes().size();
}
auto left_nodes = lane_section_node.child("left").children("lane");
auto right_nodes = lane_section_node.child("right").children("lane");
size_t total_lanes_parser = std::distance(left_nodes.begin(), left_nodes.end());
total_lanes_parser += std::distance(right_nodes.begin(), right_nodes.end());
ASSERT_EQ(total_lanes, total_lanes_parser);
}
}
}
}
// Junctions
void test_junctions(const pugi::xml_document &xml, boost::optional<Map>& map)
{
pugi::xml_node open_drive_node = xml.child("OpenDRIVE");
// Check total number of junctions
auto& junctions = map->_data.GetJunctions();
size_t total_junctions_parser = std::distance(open_drive_node.children("junction").begin(), open_drive_node.children("junction").end());
ASSERT_EQ(junctions.size(), total_junctions_parser);
for (pugi::xml_node junction_node : open_drive_node.children("junction")) {
// Check total number of connections
size_t total_connections_parser = std::distance(junction_node.children("connection").begin(), junction_node.children("connection").end());
JuncId junction_id = junction_node.attribute("id").as_int();
auto& junction = junctions.find(junction_id)->second;
auto& connections = junction.GetConnections();
ASSERT_EQ(connections.size(), total_connections_parser);
for (pugi::xml_node connection_node : junction_node.children("connection")) {
size_t total_lane_links_parser = std::distance(connection_node.children("laneLink").begin(), connection_node.children("laneLink").end());
ConId connection_id = connection_node.attribute("id").as_uint();
auto& connection = connections.find(connection_id)->second;
auto& lane_links = connection.lane_links;
ASSERT_EQ(lane_links.size(), total_lane_links_parser);
}
}
}
void print_roads(boost::optional<Map>& map) {
std::ofstream file;
file.open("roads.txt", std::ios::out | std::ios::trunc);
@ -89,13 +198,55 @@ void test_junctions(boost::optional<Map>& map) {
TEST(road, parse_files) {
for (const auto &file : util::OpenDrive::GetAvailableFiles()) {
std::cerr << file << std::endl;
auto map = OpenDriveParser::Load(util::OpenDrive::Load(file));
ASSERT_TRUE(map);
}
}
TEST(road, parse_junctions) {
for (const auto& file : util::OpenDrive::GetAvailableFiles()) {
auto map = OpenDriveParser::Load(util::OpenDrive::Load(file));
ASSERT_TRUE(map.has_value());
// Test junctions
// print_roads(map);
test_junctions(map);
const std::string full_path = BASE_PATH + file;
pugi::xml_document xml;
pugi::xml_parse_result result = xml.load_file( full_path.c_str());
ASSERT_TRUE(result);
test_junctions(xml, map);
}
}
TEST(road, parse_lanes) {
for (const auto& file : util::OpenDrive::GetAvailableFiles()) {
auto map = OpenDriveParser::Load(util::OpenDrive::Load(file));
ASSERT_TRUE(map.has_value());
const std::string full_path = BASE_PATH + file;
pugi::xml_document xml;
pugi::xml_parse_result result = xml.load_file( full_path.c_str());
ASSERT_TRUE(result);
test_roads(xml, map);
}
}
TEST(road, parse_geometry) {
for (const auto& file : util::OpenDrive::GetAvailableFiles()) {
auto map = OpenDriveParser::Load(util::OpenDrive::Load(file));
ASSERT_TRUE(map.has_value());
const std::string full_path = BASE_PATH + file;
pugi::xml_document xml;
pugi::xml_parse_result result = xml.load_file( full_path.c_str());
ASSERT_TRUE(result);
test_geometry(xml, map);
}
}
/*

39
t.txt
View File

@ -1,39 +0,0 @@
Setup.sh: llvm-6.0-ex already installed.
Setup.sh: boost-1.69.0 already installed.
Setup.sh: rpclib-v2.2.1_c1 already installed.
Setup.sh: googletest-1.8.0-ex already installed.
Setup.sh: CARLA version 0.9.4-153-g47119f9-dirty.
Setup.sh: Generating CMake configuration files.
Setup.sh: Success!
BuildLibCarla.sh: Building LibCarla "Server.Debug" configuration.
ninja: no work to do.
[1/1] Install the project...
-- Install configuration: "Server"
BuildLibCarla.sh: Success!
BuildLibCarla.sh: Building LibCarla "Client.Debug" configuration.
[1/2] Building CXX object LibCarla/cmake/test/CMakeFiles/libcarla_test_client_debug.dir/__/__/source/test/client/test_road.cpp.o
[2/2] Linking CXX executable LibCarla/cmake/test/libcarla_test_client_debug
[1/1] Install the project...
-- Install configuration: "Client"
-- Installing: /media/bernat/SSD/linux/carla/PythonAPI/dependencies/include/carla/road/MapBuilder.cpp
-- Installing: /media/bernat/SSD/linux/carla/PythonAPI/dependencies/include/carla/road/MapBuilder.h
-- Installing: /media/bernat/SSD/linux/carla/PythonAPI/dependencies/lib/libcarla_client_debug.a
-- Installing: /media/bernat/SSD/linux/carla/PythonAPI/dependencies/test/libcarla_test_client_debug
-- Set runtime path of "/media/bernat/SSD/linux/carla/PythonAPI/dependencies/test/libcarla_test_client_debug" to ""
BuildLibCarla.sh: Success!
Check.sh: Running LibCarla.server unit tests (debug).
Running: libcarla_test_server_debug --gtest_filter=road*
Running main() from gtest_main.cc
Note: Google Test filter = road*
[==========] Running 0 tests from 0 test cases.
[==========] 0 tests from 0 test cases ran. (0 ms total)
[ PASSED ] 0 tests.
Check.sh: Running LibCarla.client unit tests (debug).
Running: libcarla_test_client_debug --gtest_filter=road*
Running main() from gtest_main.cc
Note: Google Test filter = road*
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from road
[ RUN ] road.parse_files
Util/BuildTools/Linux.mk:48: recipe for target 'check.LibCarla.debug' failed