File tree Expand file tree Collapse file tree 5 files changed +31
-25
lines changed
Component/Engine/Select/tests
framework/Testing/src/sofa/testing Expand file tree Collapse file tree 5 files changed +31
-25
lines changed Original file line number Diff line number Diff line change @@ -70,11 +70,12 @@ struct BoxROITest : public sofa::testing::BaseTest
7070 Node::SPtr m_node;
7171 typename TheBoxROI::SPtr m_boxroi;
7272
73- void SetUp () override
73+ void onSetUp () override
7474 {
75- sofa::simpleapi::importPlugin (" Sofa.Component.StateContainer" );
76- sofa::simpleapi::importPlugin (" Sofa.Component.Topology.Container.Dynamic" );
77- sofa::simpleapi::importPlugin (" Sofa.Component.Engine.Select" );
75+ this ->loadPlugins ({
76+ " Sofa.Component.StateContainer" ,
77+ " Sofa.Component.Topology.Container.Dynamic" ,
78+ " Sofa.Component.Engine.Select" });
7879
7980 m_simu = sofa::simulation::getSimulation ();
8081 ASSERT_NE (m_simu, nullptr );
@@ -86,7 +87,7 @@ struct BoxROITest : public sofa::testing::BaseTest
8687 m_node->addObject (m_boxroi);
8788 }
8889
89- void TearDown () override
90+ void onTearDown () override
9091 {
9192 if (m_root != nullptr ){
9293 sofa::simulation::node::unload (m_root);
Original file line number Diff line number Diff line change @@ -93,13 +93,20 @@ BaseTest::BaseTest() :
9393
9494BaseTest::~BaseTest () {}
9595
96+ void BaseTest::loadPlugins (
97+ const std::initializer_list<std::string>& pluginNames)
98+ {
99+ m_loadedPlugins = makeScopedPlugin (pluginNames);
100+ }
101+
96102void BaseTest::SetUp ()
97103{
98104 onSetUp ();
99105}
100106
101107void BaseTest::TearDown ()
102108{
109+ m_loadedPlugins.reset ();
103110 onTearDown ();
104111}
105112
Original file line number Diff line number Diff line change 2525
2626#include < gtest/gtest.h>
2727#include < sofa/testing/TestMessageHandler.h>
28+ #include < sofa/testing/ScopedPlugin.h>
2829
2930namespace sofa ::testing
3031{
@@ -51,9 +52,13 @@ class SOFA_TESTING_API BaseTest : public ::testing::Test
5152 // / Seed value
5253 static int seed;
5354
55+ void loadPlugins (const std::initializer_list<std::string>& pluginNames);
56+
5457private:
5558 void SetUp () override ;
5659 void TearDown () override ;
60+
61+ std::unique_ptr<sofa::testing::ScopedPlugin> m_loadedPlugins;
5762};
5863
5964} // namespace sofa::testing
Original file line number Diff line number Diff line change 2525namespace sofa ::testing
2626{
2727
28- ScopedPlugin::ScopedPlugin (const std::string& pluginName, const bool unloadAllPlugins,
28+ ScopedPlugin::ScopedPlugin (const std::string& pluginName,
2929 helper::system::PluginManager* pluginManager)
30- : m_pluginManager(pluginManager), m_unloadAllPlugins(unloadAllPlugins)
30+ : m_pluginManager(pluginManager)
3131{
3232 addPlugin (pluginName);
3333}
@@ -36,22 +36,12 @@ ScopedPlugin::~ScopedPlugin()
3636{
3737 if (m_pluginManager)
3838 {
39- if (m_unloadAllPlugins )
39+ for ( const auto & pluginName : m_loadedPlugins )
4040 {
41- for (const auto & [loadedPath, loadedPlugin] : m_pluginManager->getPluginMap ())
41+ const auto [path, isLoaded] = m_pluginManager->isPluginLoaded (pluginName);
42+ if (isLoaded)
4243 {
43- m_pluginManager->unloadPlugin (loadedPath);
44- }
45- }
46- else
47- {
48- for (const auto & pluginName : m_loadedPlugins)
49- {
50- const auto [path, isLoaded] = m_pluginManager->isPluginLoaded (pluginName);
51- if (isLoaded)
52- {
53- m_pluginManager->unloadPlugin (path);
54- }
44+ m_pluginManager->unloadPlugin (path);
5545 }
5646 }
5747 }
Original file line number Diff line number Diff line change @@ -34,15 +34,13 @@ struct SOFA_TESTING_API ScopedPlugin
3434
3535 explicit ScopedPlugin (
3636 const std::string& pluginName,
37- bool unloadAllPlugins = true ,
3837 helper::system::PluginManager* pluginManager = &helper::system::PluginManager::getInstance ());
3938
4039 template <class InputIt >
4140 ScopedPlugin (
4241 InputIt first, InputIt last,
43- bool unloadAllPlugins = true ,
4442 helper::system::PluginManager* pluginManager = &helper::system::PluginManager::getInstance ())
45- : m_pluginManager(pluginManager), m_unloadAllPlugins(unloadAllPlugins)
43+ : m_pluginManager(pluginManager)
4644 {
4745 while (first != last)
4846 {
@@ -54,12 +52,17 @@ struct SOFA_TESTING_API ScopedPlugin
5452
5553private:
5654 helper::system::PluginManager* m_pluginManager { nullptr };
57- bool m_unloadAllPlugins { true };
5855
5956 std::set<std::string> m_loadedPlugins;
6057
6158 void addPlugin (const std::string& pluginName);
6259};
6360
6461
62+ inline std::unique_ptr<ScopedPlugin> makeScopedPlugin (const std::initializer_list<std::string>& pluginNames)
63+ {
64+ return std::make_unique<ScopedPlugin>(pluginNames.begin (), pluginNames.end ());
65+ }
66+
67+
6568}
You can’t perform that action at this time.
0 commit comments