From 5758a451a8d0c8f279c95e3959bd49ebe230b226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Tue, 12 Jul 2022 15:49:36 +0200 Subject: [PATCH] Common test: Granular test (#364) Signed-off-by: ahcorde --- test/common_test/construct_empty_world.cc | 294 +++++++++++++++++++--- 1 file changed, 253 insertions(+), 41 deletions(-) diff --git a/test/common_test/construct_empty_world.cc b/test/common_test/construct_empty_world.cc index 7af116ecc..f49e3eeec 100644 --- a/test/common_test/construct_empty_world.cc +++ b/test/common_test/construct_empty_world.cc @@ -29,23 +29,7 @@ #include "gz/physics/BoxShape.hh" -// The features that an engine must have to be loaded by this loader. -using Features = gz::physics::FeatureList< - gz::physics::GetEngineInfo, - gz::physics::GetWorldFromEngine, - gz::physics::ConstructEmptyWorldFeature, - gz::physics::ConstructEmptyModelFeature, - gz::physics::GetModelFromWorld, - gz::physics::GetLinkFromModel, - gz::physics::ConstructEmptyLinkFeature, - gz::physics::AttachBoxShapeFeature, - gz::physics::GetShapeFromLink, - gz::physics::GetBoxShapeProperties, - gz::physics::RemoveEntities, - gz::physics::GetNestedModelFromModel, - gz::physics::ConstructEmptyNestedModelFeature ->; - +template class ConstructEmptyWorldTest: public testing::Test, public gz::physics::TestLibLoader { @@ -58,7 +42,7 @@ class ConstructEmptyWorldTest: // TODO(ahcorde): We should also run the 3f, 2d, and 2f variants of // FindFeatures - pluginNames = gz::physics::FindFeatures3d::From(loader); + pluginNames = gz::physics::FindFeatures3d::From(loader); if (pluginNames.empty()) { std::cerr << "No plugins with required features found in " @@ -71,15 +55,134 @@ class ConstructEmptyWorldTest: public: gz::plugin::Loader loader; }; +using FeaturesUpToEmptyWorld = gz::physics::FeatureList< + gz::physics::GetEngineInfo, + gz::physics::ConstructEmptyWorldFeature +>; + +using ConstructEmptyWorldTestUpToEmptyWorldTypes = + ::testing::Types; +TYPED_TEST_SUITE(ConstructEmptyWorldTest, ConstructEmptyWorldTestUpToEmptyWorldTypes); + ///////////////////////////////////////////////// -TEST_F(ConstructEmptyWorldTest, ConstructEmptyWorld) +TYPED_TEST(ConstructEmptyWorldTest, ConstructUpToEmptyWorld) { - for (const std::string &name : pluginNames) + for (const std::string &name : this->pluginNames) { std::cout << "Testing plugin: " << name << std::endl; - gz::plugin::PluginPtr plugin = loader.Instantiate(name); + gz::plugin::PluginPtr plugin = this->loader.Instantiate(name); - auto engine = gz::physics::RequestEngine3d::From(plugin); + auto engine = + gz::physics::RequestEngine3d::From(plugin); + ASSERT_NE(nullptr, engine); + + auto world = engine->ConstructEmptyWorld("empty world"); + ASSERT_NE(nullptr, world); + } +} + +using FeaturesUpToGetWorldFromEngine = gz::physics::FeatureList< + gz::physics::GetEngineInfo, + gz::physics::ConstructEmptyWorldFeature, + gz::physics::GetWorldFromEngine +>; + +template +class ConstructEmptyWorldTestUpToGetWorldFromEngine : + public ConstructEmptyWorldTest{}; + +using ConstructEmptyWorldTestUpToGetWorldFromEngineTypes = + ::testing::Types; +TYPED_TEST_SUITE(ConstructEmptyWorldTestUpToGetWorldFromEngine, + ConstructEmptyWorldTestUpToGetWorldFromEngineTypes); + +///////////////////////////////////////////////// +TYPED_TEST(ConstructEmptyWorldTestUpToGetWorldFromEngine, + ConstructUpToEmptyWorld) +{ + for (const std::string &name : this->pluginNames) + { + std::cout << "Testing plugin: " << name << std::endl; + gz::plugin::PluginPtr plugin = this->loader.Instantiate(name); + + auto engine = + gz::physics::RequestEngine3d::From( + plugin); + ASSERT_NE(nullptr, engine); + + auto world = engine->ConstructEmptyWorld("empty world"); + ASSERT_NE(nullptr, world); + EXPECT_EQ("empty world", world->GetName()); + EXPECT_EQ(engine, world->GetEngine()); + } +} + +using FeaturesUpToEmptyModelFeature = gz::physics::FeatureList< + gz::physics::GetEngineInfo, + gz::physics::ConstructEmptyWorldFeature, + gz::physics::GetWorldFromEngine, + gz::physics::ConstructEmptyModelFeature +>; + +template +class ConstructEmptyWorldTestUpToEmptyModelFeature : + public ConstructEmptyWorldTest{}; +using ConstructEmptyWorldTestUpToEmptyModelFeatureTypes = + ::testing::Types; +TYPED_TEST_SUITE(ConstructEmptyWorldTestUpToEmptyModelFeature, + ConstructEmptyWorldTestUpToEmptyModelFeatureTypes); + +///////////////////////////////////////////////// +TYPED_TEST(ConstructEmptyWorldTestUpToEmptyModelFeature, + ConstructUpToEmptyWorld) +{ + for (const std::string &name : this->pluginNames) + { + std::cout << "Testing plugin: " << name << std::endl; + gz::plugin::PluginPtr plugin = this->loader.Instantiate(name); + + auto engine = + gz::physics::RequestEngine3d::From(plugin); + ASSERT_NE(nullptr, engine); + + auto world = engine->ConstructEmptyWorld("empty world"); + ASSERT_NE(nullptr, world); + EXPECT_EQ("empty world", world->GetName()); + EXPECT_EQ(engine, world->GetEngine()); + + auto model = world->ConstructEmptyModel("empty model"); + ASSERT_NE(nullptr, model); + EXPECT_NE(model, world->ConstructEmptyModel("dummy")); + } +} + +using FeaturesUpToGetModelFromWorld = gz::physics::FeatureList< + gz::physics::GetEngineInfo, + gz::physics::ConstructEmptyWorldFeature, + gz::physics::GetWorldFromEngine, + gz::physics::ConstructEmptyModelFeature, + gz::physics::GetModelFromWorld +>; + +template +class ConstructEmptyWorldTestUpToGetModelFromWorld : + public ConstructEmptyWorldTest{}; +using ConstructEmptyWorldTestUpToGetModelFromWorldTypes = + ::testing::Types; +TYPED_TEST_SUITE(ConstructEmptyWorldTestUpToGetModelFromWorld, + ConstructEmptyWorldTestUpToGetModelFromWorldTypes); + +///////////////////////////////////////////////// +TYPED_TEST(ConstructEmptyWorldTestUpToGetModelFromWorld, + ConstructUpToEmptyWorld) +{ + for (const std::string &name : this->pluginNames) + { + std::cout << "Testing plugin: " << name << std::endl; + gz::plugin::PluginPtr plugin = this->loader.Instantiate(name); + + auto engine = + gz::physics::RequestEngine3d::From(plugin); ASSERT_NE(nullptr, engine); auto world = engine->ConstructEmptyWorld("empty world"); @@ -92,6 +195,42 @@ TEST_F(ConstructEmptyWorldTest, ConstructEmptyWorld) EXPECT_EQ("empty model", model->GetName()); EXPECT_EQ(world, model->GetWorld()); EXPECT_NE(model, world->ConstructEmptyModel("dummy")); + } +} + +using FeaturesUpToEmptyNestedModelFeature = gz::physics::FeatureList< + gz::physics::GetEngineInfo, + gz::physics::ConstructEmptyWorldFeature, + gz::physics::GetWorldFromEngine, + gz::physics::ConstructEmptyModelFeature, + gz::physics::GetModelFromWorld, + gz::physics::ConstructEmptyNestedModelFeature, + gz::physics::GetNestedModelFromModel +>; + +template +class ConstructEmptyWorldTestUpToEmptyNestedModelFeature : + public ConstructEmptyWorldTest{}; +using ConstructEmptyWorldTestUpToEmptyNestedModelFeatureTypes = + ::testing::Types; +TYPED_TEST_SUITE(ConstructEmptyWorldTestUpToEmptyNestedModelFeature, + ConstructEmptyWorldTestUpToEmptyNestedModelFeatureTypes); + +///////////////////////////////////////////////// +TYPED_TEST(ConstructEmptyWorldTestUpToEmptyNestedModelFeature, + ConstructUpToEmptyWorld) +{ + for (const std::string &name : this->pluginNames) + { + std::cout << "Testing plugin: " << name << std::endl; + gz::plugin::PluginPtr plugin = this->loader.Instantiate(name); + + auto engine = gz::physics::RequestEngine3d::From(plugin); + ASSERT_NE(nullptr, engine); + + auto world = engine->ConstructEmptyWorld("empty world"); + ASSERT_NE(nullptr, world); + auto model = world->ConstructEmptyModel("empty model"); auto nestedModel = model->ConstructEmptyNestedModel("empty nested model"); ASSERT_NE(nullptr, nestedModel); @@ -105,6 +244,44 @@ TEST_F(ConstructEmptyWorldTest, ConstructEmptyWorld) // in `model`. EXPECT_EQ(1u, model->GetNestedModelCount()); EXPECT_EQ(1u, nestedModel->GetNestedModelCount()); + } +} + +using FeaturesUpToEmptyLink = gz::physics::FeatureList< + gz::physics::GetEngineInfo, + gz::physics::ConstructEmptyWorldFeature, + gz::physics::GetWorldFromEngine, + gz::physics::ConstructEmptyModelFeature, + gz::physics::GetLinkFromModel, + gz::physics::ConstructEmptyLinkFeature +>; + +template +class ConstructEmptyWorldTestUpToEmptyLink : + public ConstructEmptyWorldTest{}; +using ConstructEmptyWorldTestUpToEmptyLinkTypes = + ::testing::Types; +TYPED_TEST_SUITE(ConstructEmptyWorldTestUpToEmptyLink, + ConstructEmptyWorldTestUpToEmptyLinkTypes); + +///////////////////////////////////////////////// +TYPED_TEST(ConstructEmptyWorldTestUpToEmptyLink, ConstructUpToEmptyWorld) +{ + for (const std::string &name : this->pluginNames) + { + std::cout << "Testing plugin: " << name << std::endl; + gz::plugin::PluginPtr plugin = this->loader.Instantiate(name); + + auto engine = + gz::physics::RequestEngine3d::From(plugin); + ASSERT_NE(nullptr, engine); + + auto world = engine->ConstructEmptyWorld("empty world"); + ASSERT_NE(nullptr, world); + EXPECT_EQ("empty world", world->GetName()); + EXPECT_EQ(engine, world->GetEngine()); + + auto model = world->ConstructEmptyModel("empty model"); auto link = model->ConstructEmptyLink("empty link"); ASSERT_NE(nullptr, link); @@ -115,28 +292,39 @@ TEST_F(ConstructEmptyWorldTest, ConstructEmptyWorld) auto child = model->ConstructEmptyLink("child link"); EXPECT_EQ(model, child->GetModel()); - - const std::string boxName = "box"; - const Eigen::Vector3d boxSize(0.1, 0.2, 0.3); - auto box = link->AttachBoxShape(boxName, boxSize); - EXPECT_EQ(boxName, box->GetName()); - EXPECT_NEAR((boxSize - box->GetSize()).norm(), 0.0, 1e-6); - - EXPECT_EQ(1u, link->GetShapeCount()); - auto boxCopy = link->GetShape(0u); - EXPECT_EQ(box, boxCopy); } } +using FeaturesUpToRemove = gz::physics::FeatureList< + gz::physics::GetEngineInfo, + gz::physics::ConstructEmptyWorldFeature, + gz::physics::GetWorldFromEngine, + gz::physics::ConstructEmptyModelFeature, + gz::physics::GetModelFromWorld, + gz::physics::GetLinkFromModel, + gz::physics::ConstructEmptyLinkFeature, + gz::physics::ConstructEmptyNestedModelFeature, + gz::physics::GetNestedModelFromModel, + gz::physics::RemoveEntities +>; + +template +class ConstructEmptyWorldTestUpToRemove : public ConstructEmptyWorldTest{}; +using ConstructEmptyWorldTestUpToRemoveTypes = + ::testing::Types; +TYPED_TEST_SUITE(ConstructEmptyWorldTestUpToRemove, + ConstructEmptyWorldTestUpToRemoveTypes); + ///////////////////////////////////////////////// -TEST_F(ConstructEmptyWorldTest, RemoveEntities) +TYPED_TEST(ConstructEmptyWorldTestUpToRemove, ConstructUpToEmptyWorld) { - for (const std::string &name : pluginNames) + for (const std::string &name : this->pluginNames) { std::cout << "Testing plugin: " << name << std::endl; - gz::plugin::PluginPtr plugin = loader.Instantiate(name); + gz::plugin::PluginPtr plugin = this->loader.Instantiate(name); - auto engine = gz::physics::RequestEngine3d::From(plugin); + auto engine = + gz::physics::RequestEngine3d::From(plugin); ASSERT_NE(nullptr, engine); auto world = engine->ConstructEmptyWorld("empty world"); @@ -203,14 +391,37 @@ TEST_F(ConstructEmptyWorldTest, RemoveEntities) } } -TEST_F(ConstructEmptyWorldTest, ModelByIndexWithNestedModels) +using FeaturesUpToEmptyNestedModelFeature2 = gz::physics::FeatureList< + gz::physics::GetEngineInfo, + gz::physics::ConstructEmptyWorldFeature, + gz::physics::GetWorldFromEngine, + gz::physics::ConstructEmptyModelFeature, + gz::physics::GetModelFromWorld, + gz::physics::ConstructEmptyNestedModelFeature, + gz::physics::GetNestedModelFromModel, + gz::physics::RemoveEntities +>; + +template +class ConstructEmptyWorldTestUpToEmptyNestedModelFeature2 : + public ConstructEmptyWorldTest{}; +using ConstructEmptyWorldTestUpToEmptyNestedModelFeature2Types = + ::testing::Types; +TYPED_TEST_SUITE(ConstructEmptyWorldTestUpToEmptyNestedModelFeature2, + FeaturesUpToEmptyNestedModelFeature2); + +///////////////////////////////////////////////// +TYPED_TEST(ConstructEmptyWorldTestUpToEmptyNestedModelFeature2, + ModelByIndexWithNestedModels) { - for (const std::string &name : pluginNames) + for (const std::string &name : this->pluginNames) { std::cout << "Testing plugin: " << name << std::endl; - gz::plugin::PluginPtr plugin = loader.Instantiate(name); + gz::plugin::PluginPtr plugin = this->loader.Instantiate(name); - auto engine = gz::physics::RequestEngine3d::From(plugin); + auto engine = + gz::physics::RequestEngine3d::From( + plugin); ASSERT_NE(nullptr, engine); auto world = engine->ConstructEmptyWorld("empty world"); @@ -242,7 +453,8 @@ TEST_F(ConstructEmptyWorldTest, ModelByIndexWithNestedModels) int main(int argc, char *argv[]) { ::testing::InitGoogleTest(&argc, argv); - if (!ConstructEmptyWorldTest::init(argc, argv)) + if (!ConstructEmptyWorldTest::init( + argc, argv)) return -1; return RUN_ALL_TESTS(); }