Skip to content

Commit

Permalink
Deduplicate common tests part1 (#448)
Browse files Browse the repository at this point in the history
* Reference FeatureLists recursively
* Add helper function for making an empty world

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Nov 22, 2022
1 parent 619625d commit 48acd7a
Showing 1 changed file with 49 additions and 84 deletions.
133 changes: 49 additions & 84 deletions test/common_test/construct_empty_world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,29 @@ class ConstructEmptyWorldTest:
}
}

using FeaturePolicy3d = gz::physics::FeaturePolicy3d;

public: void MakeEmptyWorld(
const std::string &_pluginName,
gz::physics::EnginePtr<FeaturePolicy3d, T> &_engine,
gz::physics::WorldPtr<FeaturePolicy3d, T> &_world)
{
std::cout << "Testing plugin: " << _pluginName << std::endl;
gz::plugin::PluginPtr plugin = this->loader.Instantiate(_pluginName);

_engine = gz::physics::RequestEngine3d<T>::From(plugin);
ASSERT_NE(nullptr, _engine);

_world = _engine->ConstructEmptyWorld("empty world");
ASSERT_NE(nullptr, _world);
}

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

using gz::physics::FeaturePolicy3d;

using FeaturesUpToEmptyWorld = gz::physics::FeatureList<
gz::physics::GetEngineInfo,
gz::physics::ConstructEmptyWorldFeature
Expand All @@ -69,21 +88,15 @@ TYPED_TEST(ConstructEmptyWorldTest, ConstructUpToEmptyWorld)
{
for (const std::string &name : this->pluginNames)
{
std::cout << "Testing plugin: " << name << std::endl;
gz::plugin::PluginPtr plugin = this->loader.Instantiate(name);
gz::physics::EnginePtr<FeaturePolicy3d, TypeParam> engine;
gz::physics::WorldPtr<FeaturePolicy3d, TypeParam> world;

auto engine =
gz::physics::RequestEngine3d<FeaturesUpToEmptyWorld>::From(plugin);
ASSERT_NE(nullptr, engine);

auto world = engine->ConstructEmptyWorld("empty world");
ASSERT_NE(nullptr, world);
this->MakeEmptyWorld(name, engine, world);
}
}

using FeaturesUpToGetWorldFromEngine = gz::physics::FeatureList<
gz::physics::GetEngineInfo,
gz::physics::ConstructEmptyWorldFeature,
FeaturesUpToEmptyWorld,
gz::physics::GetWorldFromEngine
>;

Expand All @@ -92,7 +105,7 @@ class ConstructEmptyWorldTestUpToGetWorldFromEngine :
public ConstructEmptyWorldTest<T>{};

using ConstructEmptyWorldTestUpToGetWorldFromEngineTypes =
::testing::Types<FeaturesUpToEmptyWorld>;
::testing::Types<FeaturesUpToGetWorldFromEngine>;
TYPED_TEST_SUITE(ConstructEmptyWorldTestUpToGetWorldFromEngine,
ConstructEmptyWorldTestUpToGetWorldFromEngineTypes);

Expand All @@ -102,25 +115,17 @@ TYPED_TEST(ConstructEmptyWorldTestUpToGetWorldFromEngine,
{
for (const std::string &name : this->pluginNames)
{
std::cout << "Testing plugin: " << name << std::endl;
gz::plugin::PluginPtr plugin = this->loader.Instantiate(name);
gz::physics::EnginePtr<FeaturePolicy3d, TypeParam> engine;
gz::physics::WorldPtr<FeaturePolicy3d, TypeParam> world;
this->MakeEmptyWorld(name, engine, world);

auto engine =
gz::physics::RequestEngine3d<FeaturesUpToGetWorldFromEngine>::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,
FeaturesUpToGetWorldFromEngine,
gz::physics::ConstructEmptyModelFeature
>;

Expand All @@ -138,15 +143,10 @@ TYPED_TEST(ConstructEmptyWorldTestUpToEmptyModelFeature,
{
for (const std::string &name : this->pluginNames)
{
std::cout << "Testing plugin: " << name << std::endl;
gz::plugin::PluginPtr plugin = this->loader.Instantiate(name);
gz::physics::EnginePtr<FeaturePolicy3d, TypeParam> engine;
gz::physics::WorldPtr<FeaturePolicy3d, TypeParam> world;
this->MakeEmptyWorld(name, engine, world);

auto engine =
gz::physics::RequestEngine3d<FeaturesUpToEmptyModelFeature>::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());

Expand All @@ -157,10 +157,7 @@ TYPED_TEST(ConstructEmptyWorldTestUpToEmptyModelFeature,
}

using FeaturesUpToGetModelFromWorld = gz::physics::FeatureList<
gz::physics::GetEngineInfo,
gz::physics::ConstructEmptyWorldFeature,
gz::physics::GetWorldFromEngine,
gz::physics::ConstructEmptyModelFeature,
FeaturesUpToEmptyModelFeature,
gz::physics::GetModelFromWorld
>;

Expand All @@ -178,15 +175,10 @@ TYPED_TEST(ConstructEmptyWorldTestUpToGetModelFromWorld,
{
for (const std::string &name : this->pluginNames)
{
std::cout << "Testing plugin: " << name << std::endl;
gz::plugin::PluginPtr plugin = this->loader.Instantiate(name);
gz::physics::EnginePtr<FeaturePolicy3d, TypeParam> engine;
gz::physics::WorldPtr<FeaturePolicy3d, TypeParam> world;
this->MakeEmptyWorld(name, engine, world);

auto engine =
gz::physics::RequestEngine3d<FeaturesUpToGetModelFromWorld>::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());

Expand All @@ -199,11 +191,7 @@ TYPED_TEST(ConstructEmptyWorldTestUpToGetModelFromWorld,
}

using FeaturesUpToEmptyNestedModelFeature = gz::physics::FeatureList<
gz::physics::GetEngineInfo,
gz::physics::ConstructEmptyWorldFeature,
gz::physics::GetWorldFromEngine,
gz::physics::ConstructEmptyModelFeature,
gz::physics::GetModelFromWorld,
FeaturesUpToGetModelFromWorld,
gz::physics::ConstructEmptyNestedModelFeature,
gz::physics::GetNestedModelFromModel
>;
Expand All @@ -222,14 +210,10 @@ TYPED_TEST(ConstructEmptyWorldTestUpToEmptyNestedModelFeature,
{
for (const std::string &name : this->pluginNames)
{
std::cout << "Testing plugin: " << name << std::endl;
gz::plugin::PluginPtr plugin = this->loader.Instantiate(name);
gz::physics::EnginePtr<FeaturePolicy3d, TypeParam> engine;
gz::physics::WorldPtr<FeaturePolicy3d, TypeParam> world;
this->MakeEmptyWorld(name, engine, world);

auto engine = gz::physics::RequestEngine3d<FeaturesUpToEmptyNestedModelFeature>::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");
Expand All @@ -248,10 +232,7 @@ TYPED_TEST(ConstructEmptyWorldTestUpToEmptyNestedModelFeature,
}

using FeaturesUpToEmptyLink = gz::physics::FeatureList<
gz::physics::GetEngineInfo,
gz::physics::ConstructEmptyWorldFeature,
gz::physics::GetWorldFromEngine,
gz::physics::ConstructEmptyModelFeature,
FeaturesUpToEmptyModelFeature,
gz::physics::GetLinkFromModel,
gz::physics::ConstructEmptyLinkFeature
>;
Expand All @@ -269,15 +250,10 @@ 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<FeaturesUpToEmptyLink>::From(plugin);
ASSERT_NE(nullptr, engine);
gz::physics::EnginePtr<FeaturePolicy3d, TypeParam> engine;
gz::physics::WorldPtr<FeaturePolicy3d, TypeParam> world;
this->MakeEmptyWorld(name, engine, world);

auto world = engine->ConstructEmptyWorld("empty world");
ASSERT_NE(nullptr, world);
EXPECT_EQ("empty world", world->GetName());
EXPECT_EQ(engine, world->GetEngine());

Expand Down Expand Up @@ -320,15 +296,10 @@ TYPED_TEST(ConstructEmptyWorldTestUpToRemove, ConstructUpToEmptyWorld)
{
for (const std::string &name : this->pluginNames)
{
std::cout << "Testing plugin: " << name << std::endl;
gz::plugin::PluginPtr plugin = this->loader.Instantiate(name);
gz::physics::EnginePtr<FeaturePolicy3d, TypeParam> engine;
gz::physics::WorldPtr<FeaturePolicy3d, TypeParam> world;
this->MakeEmptyWorld(name, engine, world);

auto engine =
gz::physics::RequestEngine3d<FeaturesUpToRemove>::From(plugin);
ASSERT_NE(nullptr, engine);

auto world = engine->ConstructEmptyWorld("empty world");
ASSERT_NE(nullptr, world);
auto model = world->ConstructEmptyModel("empty model");
ASSERT_NE(nullptr, model);
auto modelAlias = world->GetModel(0);
Expand Down Expand Up @@ -416,16 +387,10 @@ TYPED_TEST(ConstructEmptyWorldTestUpToEmptyNestedModelFeature2,
{
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<FeaturesUpToEmptyNestedModelFeature2>::From(
plugin);
ASSERT_NE(nullptr, engine);
gz::physics::EnginePtr<FeaturePolicy3d, TypeParam> engine;
gz::physics::WorldPtr<FeaturePolicy3d, TypeParam> world;
this->MakeEmptyWorld(name, engine, world);

auto world = engine->ConstructEmptyWorld("empty world");
ASSERT_NE(nullptr, world);
auto model1 = world->ConstructEmptyModel("model1");
ASSERT_NE(nullptr, model1);
EXPECT_EQ(0ul, model1->GetIndex());
Expand Down

0 comments on commit 48acd7a

Please sign in to comment.