diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5850e2db6763d74e6385f16417ed48102091ba5b..98a0a0b38d009fc22d8df5292bd2ccbb15816436 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,16 +8,22 @@ add_subdirectory(gtest) # # ########################################################### +# capture_inertial_kinematics test wolf_add_gtest(gtest_capture_inertial_kinematics gtest_capture_inertial_kinematics.cpp) +# capture_leg_odom test wolf_add_gtest(gtest_capture_leg_odom gtest_capture_leg_odom.cpp) -wolf_add_gtest(gtest_feature_inertial_kinematics gtest_feature_inertial_kinematics.cpp) - +# factor_inertial_kinematics test wolf_add_gtest(gtest_factor_inertial_kinematics gtest_factor_inertial_kinematics.cpp) +# factor_force_torque test wolf_add_gtest(gtest_factor_force_torque gtest_factor_force_torque.cpp) +# feature_inertial_kinematics test +wolf_add_gtest(gtest_feature_inertial_kinematics gtest_feature_inertial_kinematics.cpp) + +# force_torque_delta_tools test wolf_add_gtest(gtest_force_torque_delta_tools gtest_force_torque_delta_tools.cpp) # TODO: revive those @@ -25,9 +31,15 @@ wolf_add_gtest(gtest_force_torque_delta_tools gtest_force_torque_delta_tools.cpp # wolf_add_gtest(gtest_processor_inertial_kinematics gtest_processor_inertial_kinematics.cpp) # wolf_add_gtest(gtest_processor_force_torque_preint gtest_processor_force_torque_preint.cpp) +# processor_point_feet_nomove test wolf_add_gtest(gtest_processor_point_feet_nomove gtest_processor_point_feet_nomove.cpp) +# schema test +wolf_add_gtest(gtest_schema gtest_schema.cpp) + +# sensor_force_torque test wolf_add_gtest(gtest_sensor_force_torque gtest_sensor_force_torque.cpp) +# sensor_inertial_kinematics test wolf_add_gtest(gtest_sensor_inertial_kinematics gtest_sensor_inertial_kinematics.cpp) diff --git a/test/gtest_schema.cpp b/test/gtest_schema.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc568bdac9acf93f26116eafa91092af79908080 --- /dev/null +++ b/test/gtest_schema.cpp @@ -0,0 +1,126 @@ +// WOLF - Copyright (C) 2020,2021,2022,2023 +// Institut de Robòtica i Informà tica Industrial, CSIC-UPC. +// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and +// Joan Vallvé Navarro (jvallve@iri.upc.edu) +// All rights reserved. +// +// This file is part of WOLF: http://www.iri.upc.edu/wolf +// WOLF is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +#include "bodydynamics/common/bodydynamics.h" +#include "core/utils/utils_gtest.h" +#include "core/map/map_base.h" +#include "core/sensor/sensor_base.h" +#include "core/solver/solver_manager.h" +#include "core/processor/processor_base.h" +#include "core/tree_manager/tree_manager_base.h" + +#include "yaml-schema-cpp/yaml_schema.hpp" + +using namespace wolf; +using namespace yaml_schema_cpp; +using namespace Eigen; + +std::string wolf_schema_dir = _WOLF_SCHEMA_DIR; +std::string plugin_dir = _WOLF_BODYDYNAMICS_CODE_DIR; + +// just force the plugin .so library to be loaded +WOLF_LOAD_CORE; +WOLF_LOAD_BODYDYNAMICS; + +bool existsSchema(std::string name_schema) +{ + // Check extension + if (filesystem::extension(name_schema).empty()) + { + name_schema += SCHEMA_EXTENSION; + } + else if (filesystem::extension(name_schema) != SCHEMA_EXTENSION) + { + WOLF_ERROR("Wrong schema file extension ", name_schema, ", it should be '", SCHEMA_EXTENSION, "'"); + return false; + } + + // Find schema file + try + { + filesystem::path path_schema = findFileRecursive(name_schema, {plugin_dir + "/schema", wolf_schema_dir}); + } + catch (const std::exception& e) + { + WOLF_ERROR(name_schema, " was NOT found."); + return false; + } + WOLF_INFO(name_schema, " found!"); + return true; +} + +TEST(Schema, check_schema_existence) +{ + // Check that there is an schema file for each of the registered creators of all Factories from yaml nodes/files + // (all except FactoryStateBlock) + + // FactoryLandmark + auto registered_landmarks = FactoryLandmark::getRegisteredKeys(); + for (auto key : registered_landmarks) + { + EXPECT_TRUE(existsSchema(key)); + } + + // FactoryMapNode + auto registered_maps = FactoryMapNode::getRegisteredKeys(); + for (auto key : registered_maps) + { + EXPECT_TRUE(existsSchema(key)); + } + + // FactoryProcessorNode + auto registered_processors = FactoryProcessorNode::getRegisteredKeys(); + for (auto key : registered_processors) + { + EXPECT_TRUE(existsSchema(key)); + } + + // FactorySensorNode + auto registered_sensors = FactorySensorNode::getRegisteredKeys(); + for (auto key : registered_sensors) + { + EXPECT_TRUE(existsSchema(key)); + } + + // FactorySolverNode + auto registered_solvers = FactorySolverNode::getRegisteredKeys(); + for (auto key : registered_solvers) + { + EXPECT_TRUE(existsSchema(key)); + } + + // FactoryTreeManagerNode + auto registered_tree_managers = FactoryTreeManagerNode::getRegisteredKeys(); + for (auto key : registered_tree_managers) + { + EXPECT_TRUE(existsSchema(key)); + } +} + +TEST(Schema, validate_all_schemas) +{ + ASSERT_TRUE(validateAllSchemas({plugin_dir + "/schema", wolf_schema_dir}, true)); +} + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/processor_imu.yaml b/test/yaml/processor_imu.yaml similarity index 100% rename from test/processor_imu.yaml rename to test/yaml/processor_imu.yaml diff --git a/test/sensor_imu.yaml b/test/yaml/sensor_imu.yaml similarity index 100% rename from test/sensor_imu.yaml rename to test/yaml/sensor_imu.yaml