Skip to content

Commit

Permalink
[SofaGraphComponent] Update the tests & runSofa to use the new SceneC…
Browse files Browse the repository at this point in the history
…hecker.
  • Loading branch information
damienmarchal committed Sep 7, 2017
1 parent b281f15 commit a473d5a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 26 deletions.
3 changes: 3 additions & 0 deletions applications/sofa/gui/qt/RealGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,9 @@ void RealGUI::setSceneWithoutMonitor (Node::SPtr root, const char* filename, boo
/// We want to warn user that there is component that are implemented in specific plugin
/// and that there is no RequiredPlugin in their scene.
SceneCheckerVisitor checker(ExecParams::defaultInstance()) ;
checker.addCheck(simulation::SceneCheckAPIChange::newSPtr());
checker.addCheck(simulation::SceneCheckDuplicatedName::newSPtr());
checker.addCheck(simulation::SceneCheckMissingRequiredPlugin::newSPtr());
checker.validate(root.get()) ;

mSimulation = root;
Expand Down
4 changes: 3 additions & 1 deletion modules/SofaGraphComponent/SceneCheckerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ void SceneCheckerVisitor::validate(Node* node)
for(SceneCheck::SPtr& check : m_checkset)
{
tmp << "- " << check->getName() << msgendl ;
check->doInit(node) ;
}

msg_info("SceneChecker") << "Validating '"<< node->getName() << "' with: " << msgendl
msg_info("SceneChecker") << "Validating node '"<< node->getPathName() << "'. " << msgendl
<< "Activate checkers: " << msgendl
<< tmp.str() ;

execute(node) ;
Expand Down
6 changes: 2 additions & 4 deletions modules/SofaGraphComponent/SceneChecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ void SceneCheckMissingRequiredPlugin::doInit(Node* node)
m_requiredPlugins[plugin->getName()] = true ;
}


const std::string SceneCheckAPIChange::getName()
{
return "SceneCheckAPIChange";
Expand All @@ -148,9 +149,6 @@ void SceneCheckAPIChange::doInit(Node* node)
version << SOFA_VERSION / 10000 << "." << SOFA_VERSION / 100 % 100;
m_currentApiLevel = version.str();

m_changesets.clear() ;
installChangeSets() ;

APIVersion* apiversion {nullptr} ;
/// 1. Find if there is an APIVersion component in the scene. If there is none, warn the user and set
/// the version to 17.06 (the last version before it was introduced). If there is one...use
Expand Down Expand Up @@ -181,7 +179,7 @@ void SceneCheckAPIChange::doCheckOn(Node* node)
}
}

void SceneCheckAPIChange::installChangeSets()
void SceneCheckAPIChange::installDefaultChangeSets()
{
addHookInChangeSet("17.06", [](Base* o){
if(o->getClassName() == "RestShapeSpringsForceField" && o->findData("external_rest_shape")->isSet())
Expand Down
10 changes: 9 additions & 1 deletion modules/SofaGraphComponent/SceneChecks.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SceneCheckAPIChange : public SceneCheck
virtual void doInit(Node* node) override ;
virtual void doCheckOn(Node* node) override ;

void installChangeSets() ;
void installDefaultChangeSets() ;
void addHookInChangeSet(const std::string& version, ChangeSetHookFunction fct) ;
private:
std::string m_currentApiLevel;
Expand All @@ -101,6 +101,14 @@ using _scenechecks_::SceneCheckDuplicatedName ;
using _scenechecks_::SceneCheckMissingRequiredPlugin ;
using _scenechecks_::SceneCheckAPIChange ;

namespace scenecheckers
{
using _scenechecks_::SceneCheck ;
using _scenechecks_::SceneCheckDuplicatedName ;
using _scenechecks_::SceneCheckMissingRequiredPlugin ;
using _scenechecks_::SceneCheckAPIChange ;
} /// checkers

} /// namespace simulation

} /// namespace sofa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using sofa::Sofa_test;
using sofa::simulation::SceneCheckerVisitor ;

#include <SofaGraphComponent/SceneChecks.h>
using sofa::simulation::SceneCheckAPIChange ;
using namespace sofa::simulation::scenecheckers ;

#include <sofa/helper/system/PluginManager.h>
using sofa::helper::system::PluginManager ;
Expand Down Expand Up @@ -63,18 +63,71 @@ struct SceneChecker_test : public Sofa_test<>
ASSERT_NE(root.get(), nullptr) ;
root->init(ExecParams::defaultInstance()) ;

SceneCheckerVisitor checker(ExecParams::defaultInstance());
checker.addCheck( SceneCheckMissingRequiredPlugin::newSPtr() );

if(missing)
{
EXPECT_MSG_EMIT(Warning);
SceneCheckerVisitor checker(ExecParams::defaultInstance());
checker.validate(root.get()) ;
}else{
EXPECT_MSG_NOEMIT(Warning);
SceneCheckerVisitor checker(ExecParams::defaultInstance());
checker.validate(root.get()) ;
}
}

void checkDuplicatedNames()
{
EXPECT_MSG_EMIT(Error) ;
EXPECT_MSG_NOEMIT(Warning);

std::stringstream scene ;
scene << "<?xml version='1.0'?>"
<< "<Node name='Root' gravity='0 -9.81 0' time='0' animate='0' > \n"
<< " <Node name='nodeCheck'> \n"
<< " <Node name='nodeA' /> \n"
<< " <Node name='nodeA' /> \n"
<< " </Node> \n"
<< " <Node name='objectCheck'> \n"
<< " <OglModel name='objectA' /> \n"
<< " <OglModel name='objectA' /> \n"
<< " </Node> \n"
<< " <Node name='mixCheck'> \n"
<< " <Node name='mixA' /> \n"
<< " <OglModel name='mixA' /> \n"
<< " </Node> \n"
<< " <Node name='nothingCheck'> \n"
<< " <Node name='nodeA' /> \n"
<< " <OglModel name='objectA' /> \n"
<< " </Node> \n"
<< "</Node> \n" ;

Node::SPtr root = SceneLoaderXML::loadFromMemory ("testscene",
scene.str().c_str(),
scene.str().size()) ;

ASSERT_NE(root.get(), nullptr) ;
root->init(ExecParams::defaultInstance()) ;

SceneCheckerVisitor checker(ExecParams::defaultInstance());
checker.addCheck( SceneCheckDuplicatedName::newSPtr() );

std::vector<std::string> nodenames = {"nodeCheck", "objectCheck", "mixCheck"} ;
for( auto& nodename : nodenames )
{
EXPECT_MSG_EMIT(Warning);
ASSERT_NE(root->getChild(nodename), nullptr) ;
checker.validate(root->getChild(nodename)) ;
}

{
EXPECT_MSG_NOEMIT(Warning);
ASSERT_NE(root->getChild("nothingCheck"), nullptr) ;
checker.validate(root->getChild("nothingCheck")) ;
}

}

void checkAPIVersion(bool shouldWarn)
{
EXPECT_MSG_NOEMIT(Error) ;
Expand All @@ -85,7 +138,7 @@ struct SceneChecker_test : public Sofa_test<>
std::stringstream scene ;
scene << "<?xml version='1.0'?>"
<< "<Node name='Root' gravity='0 -9.81 0' time='0' animate='0' > \n"
<< " <APIVersion level='"<< lvl <<"'/> \n"
<< " <APIVersion level='"<< lvl <<"'/> \n"
<< " <ComponentDeprecated /> \n"
<< "</Node> \n" ;

Expand All @@ -97,29 +150,20 @@ struct SceneChecker_test : public Sofa_test<>
root->init(ExecParams::defaultInstance()) ;

SceneCheckerVisitor checker(ExecParams::defaultInstance());
SceneCheckAPIChange::SPtr apichange = SceneCheckAPIChange::newSPtr() ;
apichange->installDefaultChangeSets() ;
apichange->addHookInChangeSet("17.06", [](Base* o){
if(o->getClassName() == "ComponentDeprecated")
msg_warning(o) << "ComponentDeprecated have changed since 17.06." ;
}) ;
checker.addCheck(apichange) ;

if(shouldWarn){
/// We check that running a scene set to 17.12 generate a warning on a 17.06 component
EXPECT_MSG_EMIT(Warning) ;
SceneCheckAPIChange::SPtr apichange = SceneCheckAPIChange::newSPtr() ;

apichange->addHookInChangeSet("17.06", [](Base* o){
if(o->getClassName() == "ComponentDeprecated")
msg_warning(o) << "ComponentDeprecated have changed since 17.06." ;
}) ;
checker.addCheck(apichange) ;
checker.validate(root.get()) ;
}
else {
SceneCheckAPIChange::SPtr apichange = SceneCheckAPIChange::newSPtr() ;

/// We check that running a scene set to 17.12 generate a warning on a 17.06 component
apichange->addHookInChangeSet("17.06", [](Base* o){
if(o->getClassName() == "ComponentDeprecated")
msg_warning(o) << "RestShapeSpringsForceField have changed since 17.06." ;
}) ;

checker.addCheck(apichange) ;
checker.validate(root.get()) ;
}
}
Expand Down Expand Up @@ -149,3 +193,8 @@ TEST_F(SceneChecker_test, checkAPIVersionDeprecated )
{
checkAPIVersion(true) ;
}

TEST_F(SceneChecker_test, checkDuplicatedNames )
{
checkDuplicatedNames() ;
}

0 comments on commit a473d5a

Please sign in to comment.