diff --git a/tests/camera/CMakeLists.txt b/tests/camera/CMakeLists.txt index f135120..7232e9d 100644 --- a/tests/camera/CMakeLists.txt +++ b/tests/camera/CMakeLists.txt @@ -13,3 +13,5 @@ list(APPEND _env_vars "LIBGL_ALWAYS_SOFTWARE=1") set_tests_properties(CameraTest PROPERTIES ENVIRONMENT "${_env_vars}") + +target_compile_definitions(CameraTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/tests/camera/CameraTest.cc b/tests/camera/CameraTest.cc index 002aa62..f15f32b 100644 --- a/tests/camera/CameraTest.cc +++ b/tests/camera/CameraTest.cc @@ -1,8 +1,19 @@ #include + +#include +#include +#include +#include + +#include #include + #include +#include #include #include +#include +#include TEST(CameraTest, PluginTest) { @@ -12,7 +23,8 @@ TEST(CameraTest, PluginTest) gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/camera/model.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf"; + gz::sim::TestFixture fixture(modelPath); int iterations = 1000; @@ -80,7 +92,8 @@ TEST(CameraTest, HorizontalFlip) gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/camera/model_hor_flip.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_hor_flip.sdf"; + gz::sim::TestFixture fixture(modelPath); int iterations = 1000; fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false); @@ -147,7 +160,8 @@ TEST(CameraTest, VerticalFlip) gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/camera/model_ver_flip.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_ver_flip.sdf"; + gz::sim::TestFixture fixture(modelPath); int iterations = 1000; fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false); @@ -214,7 +228,8 @@ TEST(CameraTest, HorizontalVerticalFlip) gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/camera/model_hor_ver_flip.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_hor_ver_flip.sdf"; + gz::sim::TestFixture fixture(modelPath); int iterations = 1000; fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false); diff --git a/tests/clock/CMakeLists.txt b/tests/clock/CMakeLists.txt index 2f10b57..1995a33 100644 --- a/tests/clock/CMakeLists.txt +++ b/tests/clock/CMakeLists.txt @@ -13,3 +13,5 @@ list(APPEND _env_vars "GZ_SIM_SYSTEM_PLUGIN_PATH=$ + +#include +#include +#include + +#include #include + #include #include #include @@ -11,7 +18,9 @@ TEST(ClockTest, GetSimulationTimeFromClockPort) // Maximum verbosity helps with debugging gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/clock/model.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf"; + gz::sim::TestFixture fixture(modelPath); + const int iterations = 1000; const int deltaTns = 1e6; // 1ms const int tolerance = 1e6; // 1ms diff --git a/tests/commons/CMakeLists.txt b/tests/commons/CMakeLists.txt index 48485ed..da65abd 100644 --- a/tests/commons/CMakeLists.txt +++ b/tests/commons/CMakeLists.txt @@ -69,3 +69,7 @@ set_tests_properties(ConfigurationParsingFromStringTest PROPERTIES set_tests_properties(ConcurrentInstancesTest PROPERTIES ENVIRONMENT "${_env_vars}") + +target_compile_definitions(ConfigurationParsingFromFileTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") +target_compile_definitions(ConfigurationParsingFromStringTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") +target_compile_definitions(ConcurrentInstancesTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/tests/commons/ConcurrentInstancesTest.cc b/tests/commons/ConcurrentInstancesTest.cc index 3e93527..43e8209 100644 --- a/tests/commons/ConcurrentInstancesTest.cc +++ b/tests/commons/ConcurrentInstancesTest.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -12,10 +13,10 @@ TEST(ConcurrentInstancesTest, StartConcurrentGazeboInstancesOfDifferentModels) { auto plannedIterations = 1'000; - gz::sim::TestFixture fixture1("../../../tests/commons/" - "dummy_sphere.sdf"); - gz::sim::TestFixture fixture2("../../../tests/commons/" - "dummy_box.sdf"); + gz::sim::TestFixture fixture1(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "dummy_sphere.sdf"); + gz::sim::TestFixture fixture2(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "dummy_box.sdf"); gz::common::Console::SetVerbosity(4); fixture1.Finalize(); diff --git a/tests/commons/ConfigurationParsingFromFileTest.cc b/tests/commons/ConfigurationParsingFromFileTest.cc index 17c3f85..04b1e4b 100644 --- a/tests/commons/ConfigurationParsingFromFileTest.cc +++ b/tests/commons/ConfigurationParsingFromFileTest.cc @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -26,14 +27,14 @@ TEST(ConfigurationParsingTest, LoadPluginsWithYarpConfigurationFile) { using namespace std::chrono_literals; - std::string modelSdfName = "model_configuration_file.sdf"; - std::string sdfPath = std::string("../../../tests/commons/") + modelSdfName; + auto modelPath + = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_configuration_file.sdf"; + gz::sim::TestFixture testFixture(modelPath); + yarp::os::NetworkBase::setLocalMode(true); gz::common::Console::SetVerbosity(4); gz::sim::EntityComponentManager* ecm; - gz::sim::TestFixture testFixture{sdfPath}; - testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity, const std::shared_ptr& /*_sdf*/, gz::sim::EntityComponentManager& _ecm, diff --git a/tests/commons/ConfigurationParsingFromStringTest.cc b/tests/commons/ConfigurationParsingFromStringTest.cc index b63a0e8..83bc409 100644 --- a/tests/commons/ConfigurationParsingFromStringTest.cc +++ b/tests/commons/ConfigurationParsingFromStringTest.cc @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -23,15 +24,14 @@ TEST(ConfigurationParsingTest, LoadPluginsWithYarpConfigurationString) { - std::string modelSdfName = "model_configuration_string.sdf"; - std::string sdfPath = std::string("../../../tests/commons/") + modelSdfName; + auto modelPath + = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_configuration_string.sdf"; + gz::sim::TestFixture testFixture(modelPath); yarp::os::NetworkBase::setLocalMode(true); gz::common::Console::SetVerbosity(4); gz::sim::EntityComponentManager* ecm; - gz::sim::TestFixture testFixture{sdfPath}; - testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity, const std::shared_ptr& /*_sdf*/, gz::sim::EntityComponentManager& _ecm, diff --git a/tests/controlboard/CMakeLists.txt b/tests/controlboard/CMakeLists.txt index 97f3a17..52d2761 100644 --- a/tests/controlboard/CMakeLists.txt +++ b/tests/controlboard/CMakeLists.txt @@ -33,5 +33,8 @@ foreach(TEST ${TESTS}) set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "${_env_vars}") + + target_compile_definitions(${TEST} PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") + endforeach() diff --git a/tests/controlboard/ControlBoardCommonsTest.cc b/tests/controlboard/ControlBoardCommonsTest.cc index f294ba7..cba2ca4 100644 --- a/tests/controlboard/ControlBoardCommonsTest.cc +++ b/tests/controlboard/ControlBoardCommonsTest.cc @@ -4,9 +4,7 @@ #include -#include -#include -#include +#include #include #include #include @@ -15,9 +13,12 @@ #include #include +#include +#include #include #include #include +#include #include #include @@ -35,9 +36,10 @@ namespace test // Checks that the control board can be configured without initial conditions TEST(ControlBoardCommonsTest, ConfigureControlBoardWithoutInitialCondition) { - std::string modelSdfName = "pendulum_no_initial_configuration.sdf"; + auto modelPath + = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "pendulum_no_initial_configuration.sdf"; + gz::sim::TestFixture testFixture(modelPath); - gz::sim::TestFixture testFixture{"../../../tests/controlboard/" + modelSdfName}; gz::common::Console::SetVerbosity(4); testFixture.Finalize(); @@ -46,9 +48,10 @@ TEST(ControlBoardCommonsTest, ConfigureControlBoardWithoutInitialCondition) // Checks that the control board can be configured without initial conditions TEST(ControlBoardCommonsTest, ConfigureControlBoardWithInitialCondition) { - std::string modelSdfName = "pendulum_with_initial_configuration.sdf"; + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "pendulum_with_initial_configuration.sdf"; + gz::sim::TestFixture testFixture(modelPath); - gz::sim::TestFixture testFixture{"../../../tests/controlboard/" + modelSdfName}; gz::common::Console::SetVerbosity(4); testFixture.Finalize(); @@ -57,15 +60,15 @@ TEST(ControlBoardCommonsTest, ConfigureControlBoardWithInitialCondition) // Check that multiple control board can be congfigured for the same robot model TEST(ControlBoardCommonsTest, ConfigureMultipleControlBoards) { - std::string modelSdfName = "coupled_pendulum_two_controlboards.sdf"; - std::string sdfPath = std::string("../../../tests/controlboard/") + modelSdfName; + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "coupled_pendulum_two_controlboards.sdf"; + gz::sim::TestFixture testFixture(modelPath); bool configured = false; std::vector deviceIds; std::vector controlBoards; gz::common::Console::SetVerbosity(4); - gz::sim::TestFixture testFixture{sdfPath}; testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity, const std::shared_ptr& /*_sdf*/, @@ -102,15 +105,16 @@ TEST(ControlBoardCommonsTest, ConfigureMultipleControlBoards) // Check that joint position limits are read correctly from yarp configuration TEST(ControlBoardCommonsTest, JointPositionLimitsForMultipleJoints) { - std::string modelSdfName = "coupled_pendulum_two_joints_single_controlboard.sdf"; - std::string sdfPath = std::string("../../../tests/controlboard/") + modelSdfName; + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "coupled_pendulum_two_joints_single_controlboard.sdf"; + gz::sim::TestFixture testFixture(modelPath); + std::string deviceScopedName = "model/coupled_pendulum/controlboard_plugin_device"; yarp::dev::PolyDriver* driver; yarp::dev::IControlLimits* iControlLimits = nullptr; IControlBoardData* iControlBoardData = nullptr; gz::common::Console::SetVerbosity(4); - gz::sim::TestFixture testFixture{sdfPath}; testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity, const std::shared_ptr& /*_sdf*/, diff --git a/tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc b/tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc index 717a136..f7db15c 100644 --- a/tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc +++ b/tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -59,10 +60,10 @@ TEST(ControlBoardOnMultipleGazeboInstances, StartConcurrentGazeboInstances) unsigned int iterationsToCompleteMotion1 = 0; unsigned int iterationsToCompleteMotion2 = 0; - gz::sim::TestFixture fixture1("../../../tests/controlboard/" - "pendulum_multiple_gz_instances.sdf"); - gz::sim::TestFixture fixture2("../../../tests/controlboard/" - "pendulum_multiple_gz_instances.sdf"); + gz::sim::TestFixture fixture1(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "pendulum_multiple_gz_instances.sdf"); + gz::sim::TestFixture fixture2(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "pendulum_multiple_gz_instances.sdf"); gz::common::Console::SetVerbosity(4); fixture1 diff --git a/tests/controlboard/ControlBoardPositionControlTest.cc b/tests/controlboard/ControlBoardPositionControlTest.cc index 1ceee8d..4d99e8d 100644 --- a/tests/controlboard/ControlBoardPositionControlTest.cc +++ b/tests/controlboard/ControlBoardPositionControlTest.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -45,7 +46,8 @@ class ControlBoardPositionFixture : public testing::Test protected: // void SetUp() override ControlBoardPositionFixture() - : testFixture{"../../../tests/controlboard/pendulum_joint_relative_to_parent_link.sdf"} + : testFixture{std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "pendulum_joint_relative_to_parent_link.sdf"} { gz::common::Console::SetVerbosity(4); diff --git a/tests/controlboard/ControlBoardPositionDirectControlTest.cc b/tests/controlboard/ControlBoardPositionDirectControlTest.cc index feae5c9..970dd61 100644 --- a/tests/controlboard/ControlBoardPositionDirectControlTest.cc +++ b/tests/controlboard/ControlBoardPositionDirectControlTest.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -48,7 +49,8 @@ class ControlBoardPositionDirectFixture : public ::testing::Test protected: // void SetUp() override ControlBoardPositionDirectFixture() - : testFixture{"../../../tests/controlboard/pendulum_joint_relative_to_parent_link.sdf"} + : testFixture{std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) + / "pendulum_joint_relative_to_parent_link.sdf"} { gz::common::Console::SetVerbosity(4); diff --git a/tests/controlboard/ControlBoardTorqueControlTest.cc b/tests/controlboard/ControlBoardTorqueControlTest.cc index bf894d0..884618f 100644 --- a/tests/controlboard/ControlBoardTorqueControlTest.cc +++ b/tests/controlboard/ControlBoardTorqueControlTest.cc @@ -40,7 +40,7 @@ class ControlBoardTorqueControlFixture : public testing::TestWithParam #include +#include #include #include @@ -22,7 +23,8 @@ TEST(ForceTorqueTest, PluginTest) gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/forcetorque/model.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf"; + gz::sim::TestFixture fixture(modelPath); int iterations = 1000; fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false); diff --git a/tests/imu/CMakeLists.txt b/tests/imu/CMakeLists.txt index 183a68c..475b4ea 100644 --- a/tests/imu/CMakeLists.txt +++ b/tests/imu/CMakeLists.txt @@ -19,3 +19,5 @@ list(APPEND _env_vars "GZ_SIM_SYSTEM_PLUGIN_PATH=$ #include +#include #include #include #include @@ -26,7 +27,7 @@ class ImuFixture : public testing::Test { protected: ImuFixture() - : testFixture{"../../../tests/imu/model.sdf"} + : testFixture{std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf"} { gz::common::Console::SetVerbosity(4); diff --git a/tests/laser/CMakeLists.txt b/tests/laser/CMakeLists.txt index ce50f92..892529b 100644 --- a/tests/laser/CMakeLists.txt +++ b/tests/laser/CMakeLists.txt @@ -14,3 +14,5 @@ list(APPEND _env_vars "LIBGL_ALWAYS_SOFTWARE=1") set_tests_properties(LaserTest PROPERTIES ENVIRONMENT "${_env_vars}") + +target_compile_definitions(LaserTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/tests/laser/LaserTest.cc b/tests/laser/LaserTest.cc index 3e813b7..11af2a4 100644 --- a/tests/laser/LaserTest.cc +++ b/tests/laser/LaserTest.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,8 @@ TEST(LaserTest, PluginTest) gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/laser/model.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf"; + gz::sim::TestFixture fixture(modelPath); int iterations = 1000; fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false);