Skip to content

Commit

Permalink
Use centralized library and constants
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Jan 9, 2024
1 parent d1091f7 commit 96c86a4
Show file tree
Hide file tree
Showing 36 changed files with 172 additions and 184 deletions.
1 change: 1 addition & 0 deletions dartsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ gz_build_tests(
LIB_DEPS
${features}
${dartsim_plugin}
gz-physics-test
gz-plugin${GZ_PLUGIN_VER}::loader
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
gz-common${GZ_COMMON_VER}::geospatial
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ endif()
gz_build_tests(
TYPE UNIT
SOURCES ${gtest_sources}
LIB_DEPS
gz-physics-test
ENVIRONMENT
GZ_PHYSICS_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
INCLUDE_DIRS
Expand Down
2 changes: 1 addition & 1 deletion src/Cloneable_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <gtest/gtest.h>

#include "gz/physics/Cloneable.hh"
#include "TestDataTypes.hh"
#include "test/TestDataTypes.hh"

using namespace gz;
using physics::Cloneable;
Expand Down
2 changes: 1 addition & 1 deletion src/CompositeData_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <gtest/gtest.h>

#include "gz/physics/CompositeData.hh"
#include "TestDataTypes.hh"
#include "test/TestDataTypes.hh"

using namespace gz;

Expand Down
4 changes: 2 additions & 2 deletions src/FindFeatures_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <gz/plugin/Loader.hh>

#include "TestUtilities.hh"
#include "test/Utils.hh"

using namespace gz;

Expand Down Expand Up @@ -59,7 +59,7 @@ TEST(FindFeatures_TEST, ForwardStep)
TEST(FindFeatures_TEST, Unimplemented)
{
using TestFeatures =
physics::FeatureList<test::UnimplementedFeature>;
physics::FeatureList<physics::test::UnimplementedFeature>;

plugin::Loader loader;
PrimeTheLoader(loader);
Expand Down
2 changes: 1 addition & 1 deletion src/SpecifyData_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#define GZ_UNITTEST_EXPECTDATA_ACCESS

#include "TestDataTypes.hh"
#include "test/TestDataTypes.hh"
#include "gz/physics/SpecifyData.hh"
#include "gz/math/Vector3.hh"

Expand Down
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ ExternalProject_Add(
"-DCMAKE_INSTALL_PREFIX=${FAKE_INSTALL_PREFIX}"
)

set(GZ_PHYSICS_RESOURCE_DIR "${CMAKE_SOURCE_DIR}/resources")
add_library(gz-physics-test INTERFACE)
target_include_directories(gz-physics-test INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions(gz-physics-test INTERFACE
"GZ_PHYSICS_RESOURCE_DIR=\"${GZ_PHYSICS_RESOURCE_DIR}\""
"TESTING_PROJECT_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\""
)
target_link_libraries(gz-physics-test INTERFACE
gz-plugin${GZ_PLUGIN_VER}::loader
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
gz-common${GZ_COMMON_VER}::testing
)

add_subdirectory(gtest_vendor)
add_subdirectory(benchmark)
add_subdirectory(common_test)
Expand Down
3 changes: 1 addition & 2 deletions test/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ set(tests
ExpectData.cc
)

gz_add_benchmarks(SOURCES ${tests}
INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/test)
gz_add_benchmarks(SOURCES ${tests} LIB_DEPS gz-physics-test)
2 changes: 1 addition & 1 deletion test/benchmark/ExpectData.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <benchmark/benchmark.h>

#include "TestDataTypes.hh"
#include "test/TestDataTypes.hh"

std::size_t gNumTests = 100000;

Expand Down
15 changes: 2 additions & 13 deletions test/common_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,24 @@ function(configure_common_test PHYSICS_ENGINE_NAME test_name)
endif()
endfunction()

set(GZ_PHYSICS_RESOURCE_DIR "${CMAKE_SOURCE_DIR}/resources")

foreach(test ${tests})
set(test_executable "${TEST_TYPE}_${test}")
add_executable(${test_executable} ${test}.cc)

target_link_libraries(${test_executable}
PUBLIC
gz-plugin${GZ_PLUGIN_VER}::loader
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
gz-common${GZ_COMMON_VER}::testing
gz-physics-test
${PROJECT_LIBRARY_TARGET_NAME}
${PROJECT_LIBRARY_TARGET_NAME}-sdf
${PROJECT_LIBRARY_TARGET_NAME}-mesh
gtest
gtest_main
)

target_include_directories(${test_executable}
PUBLIC
${PROJECT_SOURCE_DIR}/test)

target_compile_definitions(${test_executable} PRIVATE
"GZ_PHYSICS_RESOURCE_DIR=\"${GZ_PHYSICS_RESOURCE_DIR}\""
"TESTING_PROJECT_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\""
)
target_include_directories(${test_executable} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

install(TARGETS ${test_executable} DESTINATION ${TEST_INSTALL_DIR})

configure_common_test("bullet" ${test_executable})
configure_common_test("bullet-featherstone" ${test_executable})
configure_common_test("dartsim" ${test_executable})
Expand Down
10 changes: 4 additions & 6 deletions test/common_test/added_mass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include <gtest/gtest.h>

#include <gz/common/Console.hh>
#include <gz/common/testing/TestPaths.hh>

#include <gz/plugin/Loader.hh>

#include "TestLibLoader.hh"
#include "../Utils.hh"
#include "test/TestLibLoader.hh"
#include "test/Utils.hh"
#include "worlds/Worlds.hh"

#include <gz/physics/AddedMass.hh>
#include <gz/physics/FindFeatures.hh>
Expand Down Expand Up @@ -87,10 +87,8 @@ TEST_F(AddedMassFeaturesTest, Gravity)
EXPECT_TRUE(engine->GetName().find(this->PhysicsEngineName(name)) !=
std::string::npos);

const auto worldPath =
gz::common::testing::TestFile("common_test", "worlds", "falling_added_mass.world");
sdf::Root root;
const sdf::Errors errors = root.Load(worldPath);
const sdf::Errors errors = root.Load(worlds::kFallingAddedMassWorld);
EXPECT_TRUE(errors.empty()) << errors;
const sdf::World *sdfWorld = root.WorldByIndex(0);
EXPECT_NE(nullptr, sdfWorld);
Expand Down
12 changes: 4 additions & 8 deletions test/common_test/addexternalforcetorque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#include <gz/math/Vector3.hh>
#include <gz/math/eigen3/Conversions.hh>

#include "TestLibLoader.hh"
#include "Utils.hh"
#include "test/TestLibLoader.hh"
#include "test/Utils.hh"
#include "worlds/Worlds.hh"

#include <gz/physics/FindFeatures.hh>
#include <gz/physics/GetEntities.hh>
Expand All @@ -45,8 +46,6 @@
#include <sdf/Root.hh>
#include <sdf/Sphere.hh>

#include <gz/common/testing/TestPaths.hh>

template <class T>
class LinkFeaturesTest:
public testing::Test, public gz::physics::TestLibLoader
Expand Down Expand Up @@ -110,10 +109,7 @@ TYPED_TEST(LinkFeaturesTest, JointSetCommand)
ASSERT_NE(nullptr, engine);

sdf::Root root;

const auto worldPath =
gz::common::testing::TestFile("common_test", "worlds", "sphere.sdf");
const sdf::Errors errors = root.Load(worldPath);
const sdf::Errors errors = root.Load(worlds::kSphereSdf);
ASSERT_TRUE(errors.empty()) << errors.front();

const std::string modelName{"sphere"};
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "TestLibLoader.hh"
#include "test/TestLibLoader.hh"

#include <gz/physics/FindFeatures.hh>
#include <gz/physics/GetEntities.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/collisions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "TestLibLoader.hh"
#include "test/TestLibLoader.hh"

#include <gz/physics/FindFeatures.hh>
#include <gz/physics/RequestEngine.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/construct_empty_world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "TestLibLoader.hh"
#include "test/TestLibLoader.hh"

#include <gz/physics/ConstructEmpty.hh>
#include <gz/physics/FindFeatures.hh>
Expand Down
9 changes: 4 additions & 5 deletions test/common_test/detachable_joint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#include <gz/math/Helpers.hh>
#include <gz/math/eigen3/Conversions.hh>

#include "TestLibLoader.hh"
#include "../Utils.hh"
#include "test/TestLibLoader.hh"
#include "test/Utils.hh"
#include "worlds/Worlds.hh"

#include "gz/physics/FrameSemantics.hh"
#include <gz/physics/FindFeatures.hh>
Expand Down Expand Up @@ -110,10 +111,8 @@ TYPED_TEST(DetachableJointTest, CorrectAttachmentPoints)
gz::physics::RequestEngine3d<DetachableJointFeatureList>::From(plugin);
ASSERT_NE(nullptr, engine);

const auto worldPath =
gz::common::testing::TestFile("common_test", "worlds", "detachable_joint.world");
sdf::Root root;
const sdf::Errors errors = root.Load(worldPath);
const sdf::Errors errors = root.Load(worlds::kDetachableJointWorld);
ASSERT_TRUE(errors.empty()) << errors.front();

auto world = engine->ConstructWorld(*root.WorldByIndex(0));
Expand Down
13 changes: 4 additions & 9 deletions test/common_test/free_joint_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

#include <tuple>

#include "TestLibLoader.hh"
#include "worlds/Worlds.hh"
#include "test/TestLibLoader.hh"

#include <gz/common/Console.hh>
#include <gz/common/Util.hh>
Expand All @@ -37,8 +38,6 @@
#include "gz/physics/sdf/ConstructNestedModel.hh"
#include "gz/physics/sdf/ConstructWorld.hh"

#include <gz/common/testing/TestPaths.hh>

struct TestFeatureList : gz::physics::FeatureList<
gz::physics::GetEngineInfo,
gz::physics::sdf::ConstructSdfWorld,
Expand Down Expand Up @@ -113,9 +112,7 @@ TEST_F(FreeGroupFeaturesTest, NestedFreeGroup)
ASSERT_NE(nullptr, engine);

sdf::Root root;
const auto worldPath =
gz::common::testing::TestFile("common_test", "worlds", "world_with_nested_model.sdf");
const sdf::Errors &errors = root.Load(worldPath);
const sdf::Errors &errors = root.Load(worlds::kWorldWithNestedModelSdf);
EXPECT_EQ(0u, errors.size()) << errors;

EXPECT_EQ(1u, root.WorldCount());
Expand Down Expand Up @@ -166,9 +163,7 @@ TEST_F(FreeGroupFeaturesTest, NestedFreeGroupSetWorldPose)
ASSERT_NE(nullptr, engine);

sdf::Root root;
const auto worldPath =
gz::common::testing::TestFile("common_test", "worlds", "world_with_nested_model.sdf");
const sdf::Errors &errors = root.Load(worldPath);
const sdf::Errors &errors = root.Load(worlds::kWorldWithNestedModelSdf);
EXPECT_EQ(0u, errors.size()) << errors;

EXPECT_EQ(1u, root.WorldCount());
Expand Down
Loading

0 comments on commit 96c86a4

Please sign in to comment.