SkeletonNodeSearchTests.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <EMotionFX/Source/Actor.h>
  9. #include <EMotionFX/Source/ActorInstance.h>
  10. #include <EMotionFX/Source/Node.h>
  11. #include <EMotionFX/Source/Skeleton.h>
  12. #include <gtest/gtest.h>
  13. #include <Tests/SystemComponentFixture.h>
  14. #include <Tests/TestAssetCode/SimpleActors.h>
  15. #include <Tests/TestAssetCode/ActorFactory.h>
  16. namespace EMotionFX
  17. {
  18. class SkeletonNodeSearchTests
  19. : public SystemComponentFixture
  20. {
  21. public:
  22. void SetUpActor(int numJoint)
  23. {
  24. /*
  25. * This creates an Actor with following hierarchy.
  26. *
  27. * 0("rootJoint")-----1-----2-----3-----4
  28. *
  29. */
  30. m_actor = ActorFactory::CreateAndInit<SimpleJointChainActor>(numJoint);
  31. m_skeleton = m_actor->GetSkeleton();
  32. }
  33. void TearDown() override
  34. {
  35. m_actor.reset();
  36. SystemComponentFixture::TearDown();
  37. }
  38. public:
  39. AZStd::unique_ptr<SimpleJointChainActor> m_actor = nullptr;
  40. Skeleton* m_skeleton = nullptr;
  41. };
  42. TEST_F(SkeletonNodeSearchTests, FindNode)
  43. {
  44. SetUpActor(5);
  45. // Try to find all 5 nodes by name.
  46. Node* testNode = m_skeleton->FindNodeByName("rootJoint");
  47. EXPECT_TRUE(testNode) << "rootJoint should be found in skeleton.";
  48. testNode = m_skeleton->FindNodeByName("joint1");
  49. EXPECT_TRUE(testNode) << "joint1 should be found in skeleton.";
  50. testNode = m_skeleton->FindNodeByName("joint2");
  51. EXPECT_TRUE(testNode) << "joint2 should be found in skeleton.";
  52. testNode = m_skeleton->FindNodeByName("joint3");
  53. EXPECT_TRUE(testNode) << "joint3 should be found in skeleton.";
  54. testNode = m_skeleton->FindNodeByName("joint4");
  55. EXPECT_TRUE(testNode) << "joint4 should be found in skeleton.";
  56. }
  57. TEST_F(SkeletonNodeSearchTests, RemoveNode)
  58. {
  59. SetUpActor(5);
  60. Node* testNode = nullptr;
  61. // Try to find rootJoint by name after deleting other nodes.
  62. for (AZ::u32 i = 0; i < 5; ++i)
  63. {
  64. const AZStd::string nodeName = m_skeleton->GetNode(0)->GetNameString();
  65. m_skeleton->RemoveNode(0);
  66. testNode = m_skeleton->FindNodeByName(nodeName);
  67. EXPECT_FALSE(testNode) << nodeName.c_str() << " should not be found in skeleton after being removed.";
  68. }
  69. EXPECT_EQ(m_skeleton->GetNumNodes(), 0) << "Skeleton should have zero nodes.";
  70. }
  71. TEST_F(SkeletonNodeSearchTests, SetNode)
  72. {
  73. SetUpActor(6);
  74. Node* testNode = Node::Create("testNode", m_skeleton);
  75. m_skeleton->SetNode(5, testNode);
  76. Node* nodeFound = m_skeleton->FindNodeByName("testNode");
  77. EXPECT_EQ(testNode, nodeFound) << "testNode should be found in skeleton.";
  78. nodeFound = m_skeleton->FindNodeByName("joint5");
  79. EXPECT_FALSE(nodeFound) << "joint5 should be replaced and could not be found in skeleton.";
  80. }
  81. } // namespace EMotionFX