CanDeleteJackEntity.cpp 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <AzCore/Component/ComponentApplicationBus.h>
  9. #include <AzCore/UserSettings/UserSettingsComponent.h>
  10. #include <AzCore/std/smart_ptr/unique_ptr.h>
  11. #include <AzFramework/Components/TransformComponent.h>
  12. #include <AzToolsFramework/Component/EditorComponentAPIComponent.h>
  13. #include <Component/EditorComponentAPIBus.h>
  14. #include <Entity/EditorEntityActionComponent.h>
  15. #include <EMotionFX/Source/MotionSet.h>
  16. #include <Integration/Editor/Components/EditorActorComponent.h>
  17. #include <Integration/Editor/Components/EditorAnimGraphComponent.h>
  18. #include <UI/PropertyEditor/PropertyManagerComponent.h>
  19. #include <Tests/SystemComponentFixture.h>
  20. #include <Tests/TestAssetCode/ActorFactory.h>
  21. #include <Tests/TestAssetCode/AnimGraphFactory.h>
  22. #include <Tests/TestAssetCode/TestActorAssets.h>
  23. #include <Tests/TestAssetCode/JackActor.h>
  24. namespace EMotionFX
  25. {
  26. using CanDeleteJackEntityFixture = ComponentFixture<
  27. AZ::AssetManagerComponent,
  28. AZ::JobManagerComponent,
  29. AZ::StreamerComponent,
  30. AZ::UserSettingsComponent,
  31. AzToolsFramework::Components::PropertyManagerComponent,
  32. AzToolsFramework::Components::EditorEntityActionComponent,
  33. AzToolsFramework::Components::EditorComponentAPIComponent,
  34. EMotionFX::Integration::SystemComponent
  35. >;
  36. TEST_F(CanDeleteJackEntityFixture, CanDeleteJackEntity)
  37. {
  38. // C1559174: Automate P1 Test - Simple_JackLocomotion - Jack can be removed from the scene
  39. RecordProperty("test_case_id", "C1559174");
  40. m_app.RegisterComponentDescriptor(Integration::ActorComponent::CreateDescriptor());
  41. m_app.RegisterComponentDescriptor(Integration::AnimGraphComponent::CreateDescriptor());
  42. m_app.RegisterComponentDescriptor(Integration::EditorActorComponent::CreateDescriptor());
  43. m_app.RegisterComponentDescriptor(Integration::EditorAnimGraphComponent::CreateDescriptor());
  44. m_app.RegisterComponentDescriptor(AzFramework::TransformComponent::CreateDescriptor());
  45. AZ::Entity* entity = aznew AZ::Entity(AZ::EntityId(83502341));
  46. entity->CreateComponent<AzFramework::TransformComponent>();
  47. Integration::EditorActorComponent* editorActorComponent = entity->CreateComponent<Integration::EditorActorComponent>();
  48. Integration::EditorAnimGraphComponent* editorAnimGraphComponent = entity->CreateComponent<Integration::EditorAnimGraphComponent>();
  49. // Load Jack actor asset
  50. AZ::Data::AssetId actorAssetId("{5060227D-B6F4-422E-BF82-41AAC5F228A5}");
  51. AZStd::unique_ptr<Actor> actor = ActorFactory::CreateAndInit<JackNoMeshesActor>();
  52. AZ::Data::Asset<Integration::ActorAsset> actorAsset = TestActorAssets::GetAssetFromActor(actorAssetId, AZStd::move(actor));
  53. entity->Init();
  54. entity->Activate();
  55. editorActorComponent->SetActorAsset(actorAsset);
  56. // Load anim graph asset
  57. AZ::Data::AssetId animGraphAssetId("{37629818-5166-4B96-83F5-5818B6A1F449}");
  58. editorAnimGraphComponent->SetAnimGraphAssetId(animGraphAssetId);
  59. AZ::Data::Asset<Integration::AnimGraphAsset> animGraphAsset = AZ::Data::AssetManager::Instance().CreateAsset<Integration::AnimGraphAsset>(animGraphAssetId, AZ::Data::AssetLoadBehavior::Default);
  60. AZStd::unique_ptr<TwoMotionNodeAnimGraph> animGraphPtr = AnimGraphFactory::Create<TwoMotionNodeAnimGraph>();
  61. AnimGraph* animGraph = animGraphPtr.get();
  62. animGraphPtr.release();
  63. animGraphAsset.GetAs<Integration::AnimGraphAsset>()->SetData(animGraph);
  64. editorAnimGraphComponent->OnAssetReady(animGraphAsset);
  65. // Load motion set asset.
  66. AZ::Data::AssetId motionSetAssetId("{224BFF5F-D0AD-4216-9CEF-42F419CC6265}");
  67. editorAnimGraphComponent->SetMotionSetAssetId(motionSetAssetId);
  68. AZ::Data::Asset<Integration::MotionSetAsset> motionSetAsset = AZ::Data::AssetManager::Instance().CreateAsset<Integration::MotionSetAsset>(motionSetAssetId);
  69. motionSetAsset.GetAs<Integration::MotionSetAsset>()->SetData(new MotionSet());
  70. editorAnimGraphComponent->OnAssetReady(motionSetAsset);
  71. // Make sure the entity exist before deletion.
  72. const AZ::EntityId entityID = entity->GetId();
  73. AZ::Entity* foundEntity{};
  74. AZ::ComponentApplicationBus::BroadcastResult(foundEntity, &AZ::ComponentApplicationRequests::FindEntity, entityID);
  75. EXPECT_TRUE(foundEntity) << "Entity should be founded after initialized and activated.";
  76. // Delete the entity.
  77. AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationRequests::DeleteEntity, entityID);
  78. // Make sure the entity is gone after deletion.
  79. foundEntity = nullptr;
  80. AZ::ComponentApplicationBus::BroadcastResult(foundEntity, &AZ::ComponentApplicationRequests::FindEntity, entityID);
  81. EXPECT_FALSE(foundEntity) << "Entity should NOT be founded after calling delete.";
  82. }
  83. } // namespace EMotionFX