From 509e9d9353b1ed5b9c20ea1e1648a303be12c490 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 23 Oct 2024 10:35:08 +0900 Subject: [PATCH 1/3] set isset flag even if the parent is null --- .../Core/src/sofa/core/objectmodel/BaseData.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp index 3d16511118f..25dd10ba254 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp @@ -128,9 +128,14 @@ bool BaseData::setParent(BaseData* parent, const std::string& path) addInput(parent); BaseData::setDirtyValue(); m_counter++; - m_isSet = true; - }else if (!path.empty()) + } + // the referenced parent data has not been created yet but a path has been given + else if (!path.empty()) + { parentData.setPath(path); + } + + m_isSet = true; return true; } From 840bdb0fc5c9bc480f3aa77194259aaa87e604d4 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 23 Oct 2024 12:06:43 +0900 Subject: [PATCH 2/3] add tests --- .../src/sofa/core/objectmodel/BaseData.cpp | 2 +- .../SimpleApi/test/SimpleApi_test.cpp | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp index 25dd10ba254..d449b0b7a7e 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseData.cpp @@ -130,7 +130,7 @@ bool BaseData::setParent(BaseData* parent, const std::string& path) m_counter++; } // the referenced parent data has not been created yet but a path has been given - else if (!path.empty()) + else if (!path.empty()) { parentData.setPath(path); } diff --git a/Sofa/framework/SimpleApi/test/SimpleApi_test.cpp b/Sofa/framework/SimpleApi/test/SimpleApi_test.cpp index dc5ae56c599..a1226dc8614 100644 --- a/Sofa/framework/SimpleApi/test/SimpleApi_test.cpp +++ b/Sofa/framework/SimpleApi/test/SimpleApi_test.cpp @@ -90,3 +90,45 @@ TEST_F(SimpleApi_test, createParamString ) { ASSERT_TRUE( testParamString() ); } + +TEST(SimpleApi_test_solo, testIsSetWithDataLink) +{ + const Simulation::SPtr simu = createSimulation("DAG"); + const Node::SPtr root = createRootNode(simu, "root"); + + // test not set + const auto obj1 = createObject(root, "DefaultAnimationLoop", { + {"name", "loop1"} + }); + auto* objdata1 = obj1->findData("printLog"); + ASSERT_FALSE(objdata1->isSet()); + + // test set + const auto obj2 = createObject(root, "DefaultAnimationLoop", { + {"name", "loop2"}, + {"printLog", "false"} + }); + auto* objdata2 = obj2->findData("printLog"); + ASSERT_TRUE(objdata2->isSet()); + + // test set through a link of a already created object + const auto obj3 = createObject(root, "DefaultAnimationLoop", { + {"name", "loop3"}, + {"printLog", "@/loop2.printLog"} + }); + auto* objdata3 = obj3->findData("printLog"); + ASSERT_TRUE(objdata3->isSet()); + + // test set through a link of a not yet created object (deferred linking) + const auto obj4 = createObject(root, "DefaultAnimationLoop", { + {"name", "loop4"}, + {"printLog", "@/loop5.printLog"} + }); + const auto obj5 = createObject(root, "DefaultAnimationLoop", { + {"name", "loop5"}, + {"printLog", "true"} + }); + auto* objdata4 = obj4->findData("printLog"); + ASSERT_TRUE(objdata4->isSet()); + +} From 01a7922e119a0db284762928a53ce6e34dcd3ecb Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 13 Nov 2024 09:31:26 +0900 Subject: [PATCH 3/3] add test with a bogus link path --- Sofa/framework/SimpleApi/test/SimpleApi_test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sofa/framework/SimpleApi/test/SimpleApi_test.cpp b/Sofa/framework/SimpleApi/test/SimpleApi_test.cpp index a1226dc8614..f9c26dfccd7 100644 --- a/Sofa/framework/SimpleApi/test/SimpleApi_test.cpp +++ b/Sofa/framework/SimpleApi/test/SimpleApi_test.cpp @@ -130,5 +130,15 @@ TEST(SimpleApi_test_solo, testIsSetWithDataLink) }); auto* objdata4 = obj4->findData("printLog"); ASSERT_TRUE(objdata4->isSet()); + + // test link with a wrong path (or non existent parent) + const auto obj6 = createObject(root, "DefaultAnimationLoop", { + {"name", "loop6"}, + {"printLog", "@/loop7.printLog"} + }); + + auto* objdata6 = obj6->findData("printLog"); + ASSERT_TRUE(objdata6->isSet()); + ASSERT_EQ(objdata6->getParent(), nullptr); }