3
0

hydra_AtomEditorComponents_CubeMapCaptureAdded.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. class Tests:
  7. cubemap_capture_creation = (
  8. "CubeMap Capture Entity successfully created",
  9. "P0: CubeMap Capture Entity failed to be created")
  10. cubemap_capture_component = (
  11. "Entity has a CubeMap Capture component",
  12. "P0: Entity failed to find CubeMap Capture component")
  13. cubemap_capture_component_removal = (
  14. "UNDO CubeMap Capture Entity success",
  15. "P0: UNDO CubeMap Capture Entity failed")
  16. removal_undo = (
  17. "REDO CubeMap Capture Entity success",
  18. "P0: REDO CubeMap Capture Entity failed")
  19. capture_type_property_set_to_Diffuse_ibl = (
  20. "Capture Type property set to Diffuse_IBL on CubeMap Capture Component",
  21. "P1: Couldn't set Capture Type property to Diffuse_IBL on CubeMap Capture Component")
  22. exposure_property_set = (
  23. "Exposure property set on CubeMap Capture Component",
  24. "P1: Coudn't set Exposure property on CubeMap Capture Component")
  25. entity_deleted = (
  26. "Entity deleted",
  27. "P0: Entity was not deleted")
  28. deletion_undo = (
  29. "UNDO Entity deletion success",
  30. "P0: UNDO Entity deletion failed")
  31. deletion_redo = (
  32. "REDO Entity deletion success",
  33. "P0: REDO Entity deletion failed")
  34. def AtomEditorComponents_CubeMapCapture_AddedToEntity():
  35. """
  36. Summary:
  37. Tests the Cubemap Capture component can be added to an entity and has the expected functionality.
  38. Test setup:
  39. - Wait for Editor idle loop.
  40. - Open the "Base" level.
  41. Expected Behavior:
  42. The component can be added, and deleted.
  43. Creation and deletion undo/redo should also work.
  44. Test Steps:
  45. 1) Create a Cubemap_Capture entity with no components.
  46. 2) Add Cubemap_Capture component to Cubemap_Capture entity.
  47. 3) Remove the Cubemap_Capture component.
  48. 4) UNDO the Cubemap_Capture component removal.
  49. 5) Test the Specular IBL property values.
  50. 6) Set Capture type property to Diffuse_IBL.
  51. 7) Set Exposure property.
  52. 8) Delete the Cubemap_Capture entity.
  53. 9) UNDO deletion.
  54. 10) REDO deletion.
  55. 11) Look for errors.
  56. :return: None
  57. """
  58. import azlmbr.legacy.general as general
  59. from editor_python_test_tools.editor_entity_utils import EditorEntity
  60. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  61. from Atom.atom_utils.atom_constants import (AtomComponentProperties, CUBEMAP_CAPTURE_TYPE, SPECULAR_IBL_QUALITY)
  62. with Tracer() as error_tracer:
  63. # Test setup begins.
  64. # Setup: Wait for Editor idle loop before executing Python hydra scripts then open "Base" level.
  65. TestHelper.init_idle()
  66. TestHelper.open_level("Graphics", "base_empty")
  67. # Test steps begin.
  68. # 1. Create a Cubemap_Capture entity with no components.
  69. cubemap_capture_entity = EditorEntity.create_editor_entity(AtomComponentProperties.cube_map_capture())
  70. Report.critical_result(Tests.cubemap_capture_creation, cubemap_capture_entity.exists())
  71. # 2. Add Cubemap_Capture component to Cubemap_Capture entity.
  72. cubemap_capture_component = cubemap_capture_entity.add_component(AtomComponentProperties.cube_map_capture())
  73. Report.critical_result(Tests.cubemap_capture_component, cubemap_capture_entity.has_component(AtomComponentProperties.cube_map_capture()))
  74. # 3. Remove the Cubemap_Capture component.
  75. cubemap_capture_component.remove()
  76. general.idle_wait_frames(1)
  77. Report.critical_result(Tests.cubemap_capture_component_removal,
  78. not cubemap_capture_entity.has_component(AtomComponentProperties.cube_map_capture()))
  79. # 4. Undo Cubemap_Capture component removal.
  80. general.undo()
  81. general.idle_wait_frames(1)
  82. Report.result(Tests.removal_undo, cubemap_capture_entity.has_component(AtomComponentProperties.cube_map_capture()))
  83. # 5. Test Specular IBL CubeMap Quality values
  84. for quality in SPECULAR_IBL_QUALITY:
  85. test_quality = (
  86. f"Specular IBL quality set too {quality}",
  87. f"P1: failed to set 'Specular IBL quality' to {quality}")
  88. cubemap_capture_component.set_component_property_value(
  89. AtomComponentProperties.cube_map_capture('Specular IBL CubeMap Quality'), SPECULAR_IBL_QUALITY[quality])
  90. Report.result(test_quality, cubemap_capture_component.get_component_property_value(
  91. AtomComponentProperties.cube_map_capture('Specular IBL CubeMap Quality')) == SPECULAR_IBL_QUALITY[quality])
  92. # 6. Set Exposure property
  93. cubemap_capture_component.set_component_property_value(AtomComponentProperties.cube_map_capture('Exposure'), 16.0)
  94. get_exposure_property = cubemap_capture_component.get_component_property_value(AtomComponentProperties.cube_map_capture('Exposure'))
  95. Report.result(Tests.exposure_property_set, get_exposure_property == 16.0)
  96. # 7. Set Capture Type property: Diffuse IBL
  97. cubemap_capture_component.set_component_property_value(
  98. AtomComponentProperties.cube_map_capture('Capture Type'),
  99. value=CUBEMAP_CAPTURE_TYPE['Diffuse ILB'])
  100. Report.result(
  101. Tests.capture_type_property_set_to_Diffuse_ibl, cubemap_capture_component.get_component_property_value(
  102. AtomComponentProperties.cube_map_capture('Capture Type')) == CUBEMAP_CAPTURE_TYPE['Diffuse ILB'])
  103. # 8. Delete Cubemap_Capture entity.
  104. cubemap_capture_entity.delete()
  105. general.idle_wait_frames(1)
  106. Report.result(Tests.entity_deleted, not cubemap_capture_entity.exists())
  107. # 9. UNDO deletion.
  108. general.undo()
  109. general.idle_wait_frames(1)
  110. Report.result(Tests.deletion_undo, cubemap_capture_entity.exists())
  111. # 10. REDO deletion.
  112. general.redo()
  113. general.idle_wait_frames(1)
  114. Report.result(Tests.deletion_redo, not cubemap_capture_entity.exists())
  115. # 11. Look for errors and asserts.
  116. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  117. for error_info in error_tracer.errors:
  118. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  119. for assert_info in error_tracer.asserts:
  120. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  121. if __name__ == "__main__":
  122. from editor_python_test_tools.utils import Report
  123. Report.start_test(AtomEditorComponents_CubeMapCapture_AddedToEntity)