SpawnableRemoveEditorInfoTestFixture.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #pragma once
  9. #include <AzCore/Component/Entity.h>
  10. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  11. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  12. #include <Prefab/Spawnable/EditorInfoRemover.h>
  13. #include <Prefab/Spawnable/PrefabProcessorContext.h>
  14. #include <Prefab/PrefabSystemComponent.h>
  15. #include <Prefab/PrefabDomTypes.h>
  16. namespace UnitTest
  17. {
  18. using namespace AzToolsFramework::Prefab;
  19. class TestExportRuntimeComponentWithCallback
  20. : public AZ::Component
  21. {
  22. public:
  23. AZ_COMPONENT(TestExportRuntimeComponentWithCallback, "{BD30EBBB-74DA-473C-9C68-7077AAE8C0B1}", AZ::Component);
  24. TestExportRuntimeComponentWithCallback() = default;
  25. TestExportRuntimeComponentWithCallback(bool returnPointerToSelf, bool exportHandled);
  26. void Activate() override {}
  27. void Deactivate() override {}
  28. static void Reflect(AZ::ReflectContext* context);
  29. AZ::ExportedComponent ExportComponent(AZ::Component* thisComponent, const AZ::PlatformTagSet& /*platformTags*/);
  30. const bool m_exportHandled{ false };
  31. const bool m_returnPointerToSelf{ false };
  32. };
  33. class TestExportRuntimeComponentWithoutCallback
  34. : public AZ::Component
  35. {
  36. public:
  37. AZ_COMPONENT(TestExportRuntimeComponentWithoutCallback, "{44216269-2BAB-48E4-864F-F8D4CCFF60BB}", AZ::Component);
  38. void Activate() override {}
  39. void Deactivate() override {}
  40. static void Reflect(AZ::ReflectContext* context);
  41. };
  42. class TestExportEditorComponent
  43. : public AzToolsFramework::Components::EditorComponentBase
  44. {
  45. public:
  46. AZ_COMPONENT(TestExportEditorComponent, "{60EE7F0E-1C89-433A-AA7C-20F64BA1F470}", AzToolsFramework::Components::EditorComponentBase);
  47. enum class ExportComponentType
  48. {
  49. ExportEditorComponent,
  50. ExportRuntimeComponentWithCallBack,
  51. ExportRuntimeComponentWithoutCallBack,
  52. ExportNullComponent,
  53. };
  54. TestExportEditorComponent() = default;
  55. TestExportEditorComponent(ExportComponentType exportType, bool exportHandled);
  56. void Activate() override {}
  57. void Deactivate() override {}
  58. static void Reflect(AZ::ReflectContext* context);
  59. AZ::ExportedComponent ExportComponent(AZ::Component* thisComponent, const AZ::PlatformTagSet& /*platformTags*/);
  60. void BuildGameEntity(AZ::Entity* gameEntity) override;
  61. ExportComponentType m_exportType{ ExportComponentType::ExportNullComponent };
  62. bool m_exportHandled{ false };
  63. };
  64. class SpawnableRemoveEditorInfoTestFixture
  65. : public ToolsApplicationFixture<>
  66. {
  67. protected:
  68. void SetUpEditorFixtureImpl() override;
  69. void TearDownEditorFixtureImpl() override;
  70. // create entity containing the EditorOnly component to be processed
  71. void CreateSourceEntity(const char* name, bool editorOnly);
  72. // create entity containing the non editor-only component to be processed
  73. void CreateSourceTestExportRuntimeEntity(const char* name, bool returnPointerToSelf, bool exportHandled);
  74. // create entity containing the editor-only component to be processed
  75. void CreateSourceTestExportEditorEntity(
  76. const char* name,
  77. TestExportEditorComponent::ExportComponentType exportType,
  78. bool exportHandled);
  79. // Locate and return an entity from the exported entities
  80. AZ::Entity* GetRuntimeEntity(const char* entityName);
  81. void ConvertSourceEntitiesToPrefab();
  82. void ConvertRuntimePrefab(bool expectedResult = true);
  83. AZStd::vector<AZ::Entity*> m_sourceEntities;
  84. AZStd::vector<AZ::Entity*> m_runtimeEntities;
  85. AZ::SerializeContext* m_serializeContext{ nullptr };
  86. PrefabSystemComponent* m_prefabSystemComponent{ nullptr };
  87. PrefabConversionUtils::EditorInfoRemover m_editorInfoRemover;
  88. PrefabConversionUtils::PrefabProcessorContext m_prefabProcessorContext{ AZ::Uuid::CreateRandom() };
  89. PrefabDom m_prefabDom;
  90. };
  91. }