Skip to content

Commit

Permalink
Added basic architecture for common tests with cmd arguments
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde committed Jun 17, 2022
1 parent 1f48f3a commit d2c8b1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
11 changes: 5 additions & 6 deletions test/common_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ set(tests
link_directories(${PROJECT_BINARY_DIR}/test)

function(configure_common_test PHYSICS_ENGINE_NAME test_name)
set(_env_vars)
add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME} COMMAND ${test_name})
list(APPEND _env_vars "LIB_TO_TEST=${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_LIBRARY_TARGET_NAME}-${PHYSICS_ENGINE_NAME}-plugin${CMAKE_SHARED_LIBRARY_SUFFIX}")
set_tests_properties(${test_name}_${PHYSICS_ENGINE_NAME}
PROPERTIES
ENVIRONMENT "${_env_vars}")
add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME}
COMMAND
${test_name}
${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_LIBRARY_TARGET_NAME}-${PHYSICS_ENGINE_NAME}-plugin${CMAKE_SHARED_LIBRARY_SUFFIX}
)
endfunction()

foreach(test ${tests})
Expand Down
33 changes: 25 additions & 8 deletions test/common_test/basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,30 @@ class EntityManagementFeaturesTest:
public testing::Test,
public testing::WithParamInterface<const char *>
{
public: static void init(int argc, char *argv[])
{
if (argc != 2)
FAIL() << "Please provide the path to an engine plugin.\n"
<< "Usage COMMON_TEST_basic_test <physics engine path>\n";
libToTest = argv[1];
}

static std::string GetLibToTest()
{
return libToTest;
}

// Documentation inherited
public: void SetUp() override
{
gz::common::Console::SetVerbosity(4);

std::string libToTest;
if (!gz::common::env("LIB_TO_TEST", libToTest))
{
FAIL();
}

auto plugins = loader.LoadLib(libToTest);
auto plugins = loader.LoadLib(EntityManagementFeaturesTest::GetLibToTest());

pluginNames = gz::physics::FindFeatures3d<Features>::From(loader);
if (pluginNames.empty())
{
FAIL() << "No plugins with required features found in " << libToTest;
FAIL() << "No plugins with required features found in " << GetLibToTest();
}
}

Expand All @@ -73,10 +80,13 @@ class EntityManagementFeaturesTest:
return "";
}

public: static std::string libToTest;
public: gz::plugin::Loader loader;
public: std::set<std::string> pluginNames;
};

std::string EntityManagementFeaturesTest::libToTest = std::string("");

/////////////////////////////////////////////////
TEST_F(EntityManagementFeaturesTest, ConstructEmptyWorld)
{
Expand All @@ -91,3 +101,10 @@ TEST_F(EntityManagementFeaturesTest, ConstructEmptyWorld)
std::string::npos);
}
}

int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);
EntityManagementFeaturesTest::init(argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit d2c8b1f

Please sign in to comment.