-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Simulation] Trigger error when Node already contains component
- Loading branch information
Showing
3 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
* * | ||
* Contact information: [email protected] * | ||
******************************************************************************/ | ||
#include <sofa/core/behavior/BaseMechanicalState.h> | ||
#include <sofa/simulation/MechanicalVisitor.h> | ||
#include <sofa/testing/BaseSimulationTest.h> | ||
using sofa::testing::BaseSimulationTest ; | ||
|
||
|
@@ -33,6 +35,9 @@ namespace sofa | |
|
||
TEST( Node_test, getPathName) | ||
{ | ||
// required to be able to use EXPECT_MSG_NOEMIT and EXPECT_MSG_EMIT | ||
sofa::helper::logging::MessageDispatcher::addHandler(sofa::testing::MainGtestMessageHandler::getInstance() ) ; | ||
|
||
/* create trivial DAG : | ||
* | ||
* A | ||
|
@@ -90,6 +95,9 @@ TEST(Node_test, addObjectAtFront) | |
|
||
TEST(Node_test, addObjectPreventingSharedContext) | ||
{ | ||
// required to be able to use EXPECT_MSG_NOEMIT and EXPECT_MSG_EMIT | ||
sofa::helper::logging::MessageDispatcher::addHandler(sofa::testing::MainGtestMessageHandler::getInstance() ) ; | ||
|
||
const sofa::core::sptr<Node> root = sofa::simpleapi::createNode("root"); | ||
|
||
const BaseObject::SPtr A = core::objectmodel::New<Dummy>("A"); | ||
|
@@ -177,6 +185,53 @@ TEST(Node_test, getObjectsStdUnorderedSet) | |
EXPECT_NE(objects.find(B.get()), objects.end()); | ||
} | ||
|
||
class CounterVisitor : public simulation::MechanicalVisitor | ||
{ | ||
public: | ||
using MechanicalVisitor::MechanicalVisitor; | ||
|
||
Result fwdMechanicalState(simulation::Node* node, sofa::core::behavior::BaseMechanicalState* state) override | ||
{ | ||
SOFA_UNUSED(node); | ||
SOFA_UNUSED(state); | ||
m_counter++; | ||
return Result::RESULT_CONTINUE; | ||
} | ||
|
||
Result fwdMappedMechanicalState(simulation::Node* node, sofa::core::behavior::BaseMechanicalState* state) override | ||
{ | ||
SOFA_UNUSED(node); | ||
SOFA_UNUSED(state); | ||
++m_counter; | ||
return Result::RESULT_CONTINUE; | ||
} | ||
|
||
std::size_t m_counter = 0; | ||
}; | ||
|
||
TEST(Node_test, twoMechanicalStatesInTheSameNode) | ||
{ | ||
// required to be able to use EXPECT_MSG_NOEMIT and EXPECT_MSG_EMIT | ||
sofa::helper::logging::MessageDispatcher::addHandler(sofa::testing::MainGtestMessageHandler::getInstance() ) ; | ||
|
||
const sofa::core::sptr<Node> root = sofa::simpleapi::createNode("root"); | ||
|
||
const auto plugins = testing::makeScopedPlugin({Sofa.Component.StateContainer}); | ||
sofa::simpleapi::createObject(root, "MechanicalObject", {{"template", "Vec3"}, {"name", "A"}}); | ||
|
||
EXPECT_MSG_EMIT(Error); | ||
sofa::simpleapi::createObject(root, "MechanicalObject", {{"template", "Vec3"}, {"name", "B"}}); | ||
|
||
//the last added state is the one in Node | ||
EXPECT_EQ(root->mechanicalState->getName(), "B"); | ||
|
||
CounterVisitor visitor(core::MechanicalParams::defaultInstance()); | ||
root->executeVisitor(&visitor); | ||
|
||
//only one of the two added states is visited | ||
EXPECT_EQ(visitor.m_counter, 1); | ||
} | ||
|
||
}// namespace sofa | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters