ActorInstanceCommandTests.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 <Tests/ActorFixture.h>
  9. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  10. #include <EMotionFX/CommandSystem/Source/ActorInstanceCommands.h>
  11. #include <EMotionFX/Source/ActorInstance.h>
  12. #include <EMotionFX/Source/ActorManager.h>
  13. namespace EMotionFX
  14. {
  15. TEST_F(ActorFixture, CloneActorInstanceCommand)
  16. {
  17. ActorManager* actorManager = GetEMotionFX().GetActorManager();
  18. CommandSystem::CommandManager commandManager;
  19. EXPECT_EQ(actorManager->GetNumActorInstances(), 1);
  20. CommandSystem::CloneActorInstance(m_actorInstance);
  21. EXPECT_EQ(actorManager->GetNumActorInstances(), 2);
  22. actorManager->GetActorInstance(1)->Destroy();
  23. EXPECT_EQ(actorManager->GetNumActorInstances(), 1);
  24. }
  25. TEST_F(ActorFixture, CloneActorInstanceCommandGroup)
  26. {
  27. ActorManager* actorManager = GetEMotionFX().GetActorManager();
  28. CommandSystem::CommandManager commandManager;
  29. MCore::CommandGroup commandGroup;
  30. AZStd::string result;
  31. EXPECT_EQ(actorManager->GetNumActorInstances(), 1);
  32. CommandSystem::CloneActorInstance(m_actorInstance, &commandGroup);
  33. EXPECT_TRUE(commandManager.ExecuteCommandGroup(commandGroup, result)) << result.c_str();
  34. EXPECT_EQ(actorManager->GetNumActorInstances(), 2);
  35. actorManager->GetActorInstance(1)->Destroy();
  36. EXPECT_EQ(actorManager->GetNumActorInstances(), 1);
  37. }
  38. TEST_F(ActorFixture, CreateActorInstancesAndUndo)
  39. {
  40. ActorManager* actorManager = GetEMotionFX().GetActorManager();
  41. CommandSystem::CommandManager commandManager;
  42. MCore::CommandGroup commandGroup;
  43. AZStd::string result;
  44. // 1. Clone the actor instance, now we have two actor instances.
  45. EXPECT_EQ(actorManager->GetNumActorInstances(), 1);
  46. CommandSystem::CloneActorInstance(m_actorInstance, &commandGroup);
  47. EXPECT_TRUE(commandManager.ExecuteCommandGroup(commandGroup, result)) << result.c_str();
  48. EXPECT_EQ(actorManager->GetNumActorInstances(), 2);
  49. // 2. Delete the two actor instances using commands.
  50. commandGroup.Clear();
  51. commandGroup.AddCommandString(AZStd::string::format("RemoveActorInstance -actorInstanceID %i", actorManager->GetActorInstance(0)->GetID()));
  52. commandGroup.AddCommandString(AZStd::string::format("RemoveActorInstance -actorInstanceID %i", actorManager->GetActorInstance(1)->GetID()));
  53. EXPECT_TRUE(commandManager.ExecuteCommandGroup(commandGroup, result)) << result.c_str();
  54. EXPECT_EQ(actorManager->GetNumActorInstances(), 0);
  55. // 3. Undo step 2
  56. EXPECT_TRUE(commandManager.Undo(result));
  57. EXPECT_EQ(actorManager->GetNumActorInstances(), 2);
  58. // 4. Delete both actor instances, and free up the pointer to prevent double deletion.
  59. actorManager->GetActorInstance(1)->Destroy();
  60. actorManager->GetActorInstance(0)->Destroy();
  61. m_actorInstance = nullptr;
  62. }
  63. } // namespace EMotionFX