Add unit tests for xodr files
This commit is contained in:
parent
56fc5f97de
commit
424441d72c
|
@ -64,10 +64,17 @@ if (LIBCARLA_BUILD_DEBUG)
|
|||
set_target_properties(libcarla_test_${carla_config}_debug PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
|
||||
target_link_libraries(libcarla_test_${carla_config}_debug "carla_${carla_config}_debug")
|
||||
target_compile_definitions(libcarla_test_${carla_config}_debug PUBLIC -DBOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Client")
|
||||
target_link_libraries(libcarla_test_${carla_config}_debug "${BOOST_LIB_PATH}/libboost_filesystem.a")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (LIBCARLA_BUILD_RELEASE)
|
||||
# Specific options for release.
|
||||
set_target_properties(libcarla_test_${carla_config}_release PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_RELEASE})
|
||||
target_link_libraries(libcarla_test_${carla_config}_release "carla_${carla_config}")
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Client")
|
||||
target_link_libraries(libcarla_test_${carla_config}_release "${BOOST_LIB_PATH}/libboost_filesystem.a")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
|
|
@ -6,12 +6,16 @@
|
|||
|
||||
#include "carla/FileSystem.h"
|
||||
|
||||
#include "carla/Exception.h"
|
||||
#include "carla/StringUtil.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
namespace carla {
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
void FileSystem::ValidateFilePath(std::string &filepath, const std::string &ext) {
|
||||
namespace fs = boost::filesystem;
|
||||
fs::path path(filepath);
|
||||
if (path.extension().empty() && !ext.empty()) {
|
||||
if (ext[0] != '.') {
|
||||
|
@ -26,4 +30,25 @@ namespace carla {
|
|||
filepath = path.string();
|
||||
}
|
||||
|
||||
std::vector<std::string> FileSystem::ListFolder(
|
||||
const std::string &folder_path,
|
||||
const std::string &wildcard_pattern) {
|
||||
fs::path root(folder_path);
|
||||
if (!fs::exists(root) || !fs::is_directory(root)) {
|
||||
throw_exception(std::invalid_argument(folder_path + ": not such folder"));
|
||||
}
|
||||
|
||||
std::vector<std::string> results;
|
||||
fs::directory_iterator end;
|
||||
for (fs::directory_iterator it(root); it != end; ++it) {
|
||||
if (fs::is_regular_file(*it)) {
|
||||
const std::string filename = it->path().filename().string();
|
||||
if (StringUtil::Match(filename, wildcard_pattern)) {
|
||||
results.emplace_back(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
} // namespace carla
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace carla {
|
||||
|
||||
|
@ -24,6 +25,10 @@ namespace carla {
|
|||
static void ValidateFilePath(
|
||||
std::string &filepath,
|
||||
const std::string &default_extension = "");
|
||||
|
||||
static std::vector<std::string> ListFolder(
|
||||
const std::string &folder_path,
|
||||
const std::string &wildcard_pattern);
|
||||
};
|
||||
|
||||
} // namespace carla
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "OpenDrive.h"
|
||||
|
||||
#ifndef LIBCARLA_TEST_CONTENT_FOLDER
|
||||
# error Please define LIBCARLA_TEST_CONTENT_FOLDER.
|
||||
#endif
|
||||
|
||||
#include <carla/FileSystem.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
|
||||
namespace util {
|
||||
|
||||
std::vector<std::string> OpenDrive::GetAvailableFiles() {
|
||||
return carla::FileSystem::ListFolder(
|
||||
LIBCARLA_TEST_CONTENT_FOLDER "/OpenDrive/",
|
||||
"*.xodr");
|
||||
}
|
||||
|
||||
std::string OpenDrive::Load(const std::string &filename) {
|
||||
const std::string opendrive_folder = LIBCARLA_TEST_CONTENT_FOLDER "/OpenDrive/";
|
||||
std::ifstream file(opendrive_folder + filename);
|
||||
return std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
}
|
||||
|
||||
} // namespace util
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace util {
|
||||
|
||||
/// Helper for loading Test OpenDrive files.
|
||||
class OpenDrive {
|
||||
public:
|
||||
|
||||
static std::vector<std::string> GetAvailableFiles();
|
||||
|
||||
static std::string Load(const std::string &filename);
|
||||
};
|
||||
|
||||
} // namespace util
|
|
@ -5,35 +5,26 @@
|
|||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "test.h"
|
||||
#include "OpenDrive.h"
|
||||
|
||||
#include <carla/road/MapBuilder.h>
|
||||
#include <carla/geom/Location.h>
|
||||
#include <carla/geom/Math.h>
|
||||
#include <carla/road/element/RoadInfoVisitor.h>
|
||||
#include <carla/opendrive/OpenDriveParser.h>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace carla::road;
|
||||
using namespace carla::road::element;
|
||||
using namespace carla::geom;
|
||||
using namespace carla::opendrive;
|
||||
|
||||
TEST(road, parse_file) {
|
||||
|
||||
// read
|
||||
std::ostringstream content;
|
||||
std::ifstream file;
|
||||
file.open("opentest.xodr", std::ios::in);
|
||||
content << file.rdbuf();
|
||||
file.close();
|
||||
|
||||
auto map = OpenDriveParser::Load(content.str());
|
||||
|
||||
|
||||
ASSERT_TRUE(map.has_value());
|
||||
|
||||
TEST(road, parse_files) {
|
||||
for (const auto &file : util::OpenDrive::GetAvailableFiles()) {
|
||||
auto map = OpenDriveParser::Load(util::OpenDrive::Load(file));
|
||||
ASSERT_TRUE(map.has_value());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
TEST(road, add_geometry) {
|
||||
|
||||
|
@ -62,4 +53,4 @@ TEST(road, geom_spiral) {
|
|||
TEST(road, get_information) {
|
||||
|
||||
}
|
||||
*/
|
||||
*/
|
|
@ -101,6 +101,28 @@ if ! { ${LIBCARLA_RELEASE} || ${LIBCARLA_DEBUG} || ${PYTHON_API_2} || ${PYTHON_A
|
|||
fatal_error "Nothing selected to be done."
|
||||
fi
|
||||
|
||||
# ==============================================================================
|
||||
# -- Download Content need it by the tests -------------------------------------
|
||||
# ==============================================================================
|
||||
|
||||
if { ${LIBCARLA_RELEASE} || ${LIBCARLA_DEBUG}; }; then
|
||||
|
||||
CONTENT_TAG=0.1.0
|
||||
|
||||
mkdir -p ${LIBCARLA_TEST_CONTENT_FOLDER}
|
||||
pushd "${LIBCARLA_TEST_CONTENT_FOLDER}" >/dev/null
|
||||
|
||||
if [ "$(get_git_repository_version)" != "${CONTENT_TAG}" ]; then
|
||||
pushd .. >/dev/null
|
||||
rm -Rf ${LIBCARLA_TEST_CONTENT_FOLDER}
|
||||
git clone -b ${CONTENT_TAG} https://github.com/carla-simulator/opendrive-test-files.git ${LIBCARLA_TEST_CONTENT_FOLDER}
|
||||
popd >/dev/null
|
||||
fi
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
fi
|
||||
|
||||
# ==============================================================================
|
||||
# -- Run LibCarla tests --------------------------------------------------------
|
||||
# ==============================================================================
|
||||
|
|
|
@ -32,7 +32,7 @@ else
|
|||
|
||||
fi
|
||||
|
||||
function get_carla_version {
|
||||
function get_git_repository_version {
|
||||
git describe --tags --dirty --always
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ fi
|
|||
# -- Package project -----------------------------------------------------------
|
||||
# ==============================================================================
|
||||
|
||||
REPOSITORY_TAG=$(get_carla_version)
|
||||
REPOSITORY_TAG=$(get_git_repository_version)
|
||||
|
||||
BUILD_FOLDER=${OUTPUT_DIRECTORY}
|
||||
|
||||
|
@ -136,4 +136,4 @@ rm -Rf ${BUILD_FOLDER}/Cooked
|
|||
# ==============================================================================
|
||||
|
||||
log "ExportedMaps created at ${DESTINATION}"
|
||||
log "Success!"
|
||||
log "Success!"
|
||||
|
|
|
@ -46,7 +46,7 @@ done
|
|||
# -- Package project -----------------------------------------------------------
|
||||
# ==============================================================================
|
||||
|
||||
REPOSITORY_TAG=$(get_carla_version)
|
||||
REPOSITORY_TAG=$(get_git_repository_version)
|
||||
|
||||
BUILD_FOLDER=${CARLA_DIST_FOLDER}/${REPOSITORY_TAG}
|
||||
|
||||
|
|
|
@ -284,7 +284,7 @@ unset GTEST_BASENAME
|
|||
# -- Generate Version.h --------------------------------------------------------
|
||||
# ==============================================================================
|
||||
|
||||
CARLA_VERSION=$(get_carla_version)
|
||||
CARLA_VERSION=$(get_git_repository_version)
|
||||
|
||||
log "CARLA version ${CARLA_VERSION}."
|
||||
|
||||
|
@ -350,6 +350,8 @@ endif ()
|
|||
# add_definitions(-DLIBCARLA_IMAGE_WITH_JPEG_SUPPORT)
|
||||
# add_definitions(-DLIBCARLA_IMAGE_WITH_TIFF_SUPPORT)
|
||||
|
||||
add_definitions(-DLIBCARLA_TEST_CONTENT_FOLDER="${LIBCARLA_TEST_CONTENT_FOLDER}")
|
||||
|
||||
set(BOOST_INCLUDE_PATH "${BOOST_INCLUDE}")
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Server")
|
||||
|
|
|
@ -21,3 +21,5 @@ CARLAUE4_PLUGIN_DEPS_FOLDER=${CARLAUE4_PLUGIN_ROOT_FOLDER}/CarlaDependencies
|
|||
LIBSTDCPP_TOOLCHAIN_FILE=${CARLA_BUILD_FOLDER}/LibStdCppToolChain.cmake
|
||||
LIBCPP_TOOLCHAIN_FILE=${CARLA_BUILD_FOLDER}/LibCppToolChain.cmake
|
||||
CMAKE_CONFIG_FILE=${CARLA_BUILD_FOLDER}/CMakeLists.txt.in
|
||||
|
||||
LIBCARLA_TEST_CONTENT_FOLDER=${CARLA_BUILD_FOLDER}/test-content
|
||||
|
|
Loading…
Reference in New Issue