From 91d2bbe55fb1dfbe4aaa08882c785a3b9ae72411 Mon Sep 17 00:00:00 2001 From: "M.X. Grey" Date: Wed, 11 Feb 2015 14:24:11 -0500 Subject: [PATCH] fixed naming issues for Skeletons in World and created regression tests --- dart/simulation/World.cpp | 7 +++++-- unittests/testWorld.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dart/simulation/World.cpp b/dart/simulation/World.cpp index 06fce7e0cb8ea..61f2a5e856fe3 100644 --- a/dart/simulation/World.cpp +++ b/dart/simulation/World.cpp @@ -231,7 +231,8 @@ std::string World::addSkeleton(dynamics::Skeleton* _skeleton) } mSkeletons.push_back(_skeleton); - mNameMgrForSkeletons.issueNewNameAndAdd(_skeleton->getName(), _skeleton); + _skeleton->setName(mNameMgrForSkeletons.issueNewNameAndAdd( + _skeleton->getName(), _skeleton)); _skeleton->init(mTimeStep, mGravity); mIndices.push_back(mIndices.back() + _skeleton->getNumDofs()); mConstraintSolver->addSkeleton(_skeleton); @@ -270,7 +271,6 @@ void World::removeSkeleton(dynamics::Skeleton* _skeleton) mIndices.pop_back(); // Remove _skeleton from constraint handler. -// mConstraintHandler->removeSkeleton(_skeleton); mConstraintSolver->removeSkeleton(_skeleton); // Remove _skeleton in mSkeletons and delete it. @@ -280,6 +280,9 @@ void World::removeSkeleton(dynamics::Skeleton* _skeleton) // Update recording mRecording->updateNumGenCoords(mSkeletons); + // Remove from NameManager + mNameMgrForSkeletons.removeName(_skeleton->getName()); + delete _skeleton; } diff --git a/unittests/testWorld.cpp b/unittests/testWorld.cpp index 04c0e301eebdd..1874d28e72a86 100644 --- a/unittests/testWorld.cpp +++ b/unittests/testWorld.cpp @@ -101,12 +101,21 @@ TEST(WORLD, ADDING_AND_REMOVING_SKELETONS) for (int i = 0; i < nSteps; ++i) world->step(); + std::string s1name = skeleton1->getName(); + std::string s2name = skeleton2->getName(); + EXPECT_TRUE(skeleton1 == world->getSkeleton(s1name)); + EXPECT_TRUE(skeleton2 == world->getSkeleton(s2name)); + // Remove skeleton2 world->removeSkeleton(skeleton2); EXPECT_TRUE(world->getNumSkeletons() == 1); for (int i = 0; i < nSteps; ++i) world->step(); + EXPECT_TRUE(skeleton1 == world->getSkeleton(s1name)); + EXPECT_FALSE(skeleton2 == world->getSkeleton(s2name)); + EXPECT_TRUE(world->getSkeleton(s2name) == NULL); + // Add skeleton3, skeleton4 world->addSkeleton(skeleton3); world->addSkeleton(skeleton4); @@ -114,18 +123,34 @@ TEST(WORLD, ADDING_AND_REMOVING_SKELETONS) for (int i = 0; i < nSteps; ++i) world->step(); + std::string s3name = skeleton3->getName(); + std::string s4name = skeleton4->getName(); + + EXPECT_TRUE(s3name == s2name); + EXPECT_TRUE(skeleton3 == world->getSkeleton(s3name)); + EXPECT_TRUE(skeleton4 == world->getSkeleton(s4name)); + // Remove skeleton1 world->removeSkeleton(skeleton1); EXPECT_TRUE(world->getNumSkeletons() == 2); for (int i = 0; i < nSteps; ++i) world->step(); + EXPECT_FALSE(skeleton1 == world->getSkeleton(s1name)); + EXPECT_TRUE(world->getSkeleton(s1name) == NULL); + // Remove all the skeletons world->removeAllSkeletons(); EXPECT_EQ(world->getNumSkeletons(), 0); for (int i = 0; i < nSteps; ++i) world->step(); + EXPECT_FALSE(skeleton3 == world->getSkeleton(s3name)); + EXPECT_TRUE(world->getSkeleton(s3name) == NULL); + + EXPECT_FALSE(skeleton4 == world->getSkeleton(s4name)); + EXPECT_TRUE(world->getSkeleton(s4name) == NULL); + delete world; }